Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call MakeAssertionAsync() function and get error: " trailing garbage ". #268

Closed
holiday1228 opened this issue Dec 1, 2021 · 4 comments
Closed

Comments

@holiday1228
Copy link

Hi Sirs,

I implement a Web API services with version=2.0.2.0, but I meet a problem when I call MakeAssertionAsync() function in my code and always get error message " trailing garbage ".
I try to trace by myself and it seems with something wrong during verifying signature by public key.
I need some suggestions to resolve this problem for me, could you help?

The signature return from browser is
304402205cfa0302023a989a6f6d2a6693c2512bd7c2b99c45ab960f938d54670c24b95102200cdd2e17344814f3f4fecee3c3da1b7c42bcc1cf4cf7d40956e8df249c55e2a4

AuthenticatorData is
vBOPJxfou_mSSUwH_dHQftsCIU6COZhuxt6dw9e5PKgBAAAACA

ClientData is
eyJ0eXBlIjoid2ViYXV0aG4uZ2V0IiwiY2hhbGxlbmdlIjoiNUNqMjlid2tjOFhmckFSYVNabTVqUSIsIm9yaWdpbiI6Imh0dHBzOi8vcHR3ZG4wNC5wZWdhdHJvbmNvcnAuY29tOjQ0NDMiLCJjcm9zc09yaWdpbiI6ZmFsc2V9

Public key is
pQECAyYgASFYIBDiyG/IEegVjpEDRBFk/FlB1nQUalKXcnYL6U1DyoXuIlggYEZpTnxxF9AyAihWAvvv2GJbm3NW8/cu13+Eu1wKr5A=

@abergs
Copy link
Collaborator

abergs commented Dec 1, 2021

I have not encountered this error myself, but it sounds like an encoding issue?
Found this while googling, seems to be a similar issue https://devblogs.microsoft.com/oldnewthing/20210923-00/?p=105723

@aseigler
Copy link
Collaborator

aseigler commented Dec 2, 2021

Data formats are all over the place, but the signature is good.

[Fact]
public void TestHoliday1228Data()
{
    byte[] clientData = Convert.FromBase64String("eyJ0eXBlIjoid2ViYXV0aG4uZ2V0IiwiY2hhbGxlbmdlIjoiNUNqMjlid2tjOFhmckFSYVNabTVqUSIsIm9yaWdpbiI6Imh0dHBzOi8vcHR3ZG4wNC5wZWdhdHJvbmNvcnAuY29tOjQ0NDMiLCJjcm9zc09yaWdpbiI6ZmFsc2V9");
    byte[] hashedClientDataJson = System.Security.Cryptography.SHA256.HashData(clientData);
    byte[] sig = Convert.FromHexString("304402205cfa0302023a989a6f6d2a6693c2512bd7c2b99c45ab960f938d54670c24b95102200cdd2e17344814f3f4fecee3c3da1b7c42bcc1cf4cf7d40956e8df249c55e2a4");
    byte[] ad = Base64Url.Decode("vBOPJxfou_mSSUwH_dHQftsCIU6COZhuxt6dw9e5PKgBAAAACA");
    byte[] cpkBytes = Convert.FromBase64String("pQECAyYgASFYIBDiyG/IEegVjpEDRBFk/FlB1nQUalKXcnYL6U1DyoXuIlggYEZpTnxxF9AyAihWAvvv2GJbm3NW8/cu13+Eu1wKr5A=");
    CredentialPublicKey cpk = new CredentialPublicKey(cpkBytes);
    byte[] data = DataHelper.Concat(ad, hashedClientDataJson);
    Assert.True(cpk.Verify(data, sig));
}
        

@holiday1228
Copy link
Author

@abergs , @aseigler
Thanks for your help and info, I'll try it.
If I resolved, I'll feedback to you.

@abergs abergs closed this as completed Dec 2, 2021
@holiday1228
Copy link
Author

Update.
I've resolve this problem. Before doing verify, I convert the hex string to byte array which receive from client.
The test case make a grate help for me. Thanks your guys a lots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants