-
Notifications
You must be signed in to change notification settings - Fork 0
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
Detached JWS do not match #1
Comments
I created a test which attempts to sign the same data, with the same keys: |
Per the cookbook @panva/jose requires the input be base64url encoded: https://tools.ietf.org/html/rfc7520#section-4.5.1 However, https://tools.ietf.org/html/rfc7797#section-8
I think the issue is with the crypto-ld sign library.... although the need to call .toString is a bit suspicious... For example:
|
After testing with:
I'm pretty sure the detached JWS implementation we have here is good, and the issue lies in the jsonld-signatures implementation. |
There's a bug in the panva/jose library. I don't have time to discuss much further or do a PR over at panva/jose for this so I'm just dropping this here: This code makes an incorrect assumption that the JWS payload is a string that has been utf-8 encoded into a buffer: https://github.com/panva/jose/blob/master/lib/jws/sign.js#L100 That https://github.com/panva/jose/blob/master/lib/help/base64url.js#L30 This is an incorrect assumption -- and node.js's https://github.com/panva/jose/blob/master/lib/jws/sign.js#L106 To correct this, instead of doing this: if (!joseHeader.protected.b64) {
i(this).payload = base64url.decode(i(this).payload)
}
// ...
recipient.signature = base64url.encodeBuffer(sign(alg, key, Buffer.from(`${recipient.protected}.${i(this).payload}`))) It should be doing something like this: if (!joseHeader.protected.b64) {
i(this).payload = base64url.decodeToBuffer(i(this).payload)
}
// ...
recipient.signature = base64url.encodeBuffer(sign(alg, key, Buffer.concat([
Buffer.from(`${recipient.protected}.`),
${i(this).payload}`)])) Of course, some other minor changes might be necessary to handle the case where You can see the problem by putting a https://gist.github.com/dlongley/b19f2723e11d99d2e39d36b6f8ae7e17#file-gistfile1-txt-L15 const data = new Uint8Array([128]); The signature won't match when you do this. If you use 127 (which will be valid utf-8) the signature will match. I assume a unit test of this sort could be added to panva/jose. |
I have opened an issue here: panva/jose#57 |
Proof the raw signatures match and the issue is one of encoding: https://gist.github.com/dlongley/b19f2723e11d99d2e39d36b6f8ae7e17 |
transmute-industries/linked-data-signature-starter-kit#1
I believe there may be an error with encoding before the data is passed to sign.
Its also possible that b64 option is not implemented correctly.
The text was updated successfully, but these errors were encountered: