Replies: 9 comments
-
Are you sure the signed_data is correctly formatted, using json.dumps gives no guarantee whatsoever that the keys of a dictionary are in the same order, or that spacing/indntation or what not is the same. At the very least both signer and verifier should use json.dumps(data, sort_keys=True), but probably better make sure that also indent and separators are defined explicitly. Can you print(repr(jws.veryfylog))? Maybe there is some clue about what is the cause of the failure. |
Beta Was this translation helpful? Give feedback.
-
Thinking of it, probably better if you do not use json.dumps at all, base base64 the request_body as it comes, this will eliminate many potential sources of error. Finally it is not clear to me why you do .encode("ascii") when you compose signed_data, what's the intent here? |
Beta Was this translation helpful? Give feedback.
-
Thx for your quick response. Unfortunately, nothing more from verifylog
Which leads to this, but still it's not working with the same InvalidJWSSignature error. import jwcrypto.jws as jws
import jwcrypto.jwk as jwk
try:
jws_body = base64url_encode(str(json_body).encode("utf-8"))
signed_data = b64_signature_header + "." + jws_body
jwkey = jwk.JWK.from_json(json.dumps(<key_as_dict>))
signature = jws.JWS.from_jose_token(<base64-jws-exemple>)
signature.verify(key=jwkey, detached_payload=signed_data)
except jws.InvalidJWSSignature:
import traceback
print(traceback.format_exc())
return False Since the signer is a third party, i can only suppose that they have follow the RFC they joined in their documentation. |
Beta Was this translation helpful? Give feedback.
-
You need to ask the signer how exactly they format the body, you can't just guess it. Although it is not your case (I checked the headers, with detached payloads there isn't even a requirement to base64 them. Can you reveal who is the signer? |
Beta Was this translation helpful? Give feedback.
-
The signer is Universign (see following documentation, section Webhook authentication) I can read I'm currently waiting a response from them. |
Beta Was this translation helpful? Give feedback.
-
I think I know where the error is. |
Beta Was this translation helpful? Give feedback.
-
Hi @ahourlier, Based on your example code below I see that you try to get the public key used to sign the data in the received header, but it was not. Only the key id is included, so you need to get the key from the url provided in the documentation (check the last chapter "How to verify the webhook signature"). Does it solve your problem ? Best regards |
Beta Was this translation helpful? Give feedback.
-
I think this is clearly not an issue in JWCrypto at this point, so I moved this issue into a discussion which is more appropriate to discuss how to deal with particular endpoints or other programming issues. |
Beta Was this translation helpful? Give feedback.
-
Hi @gboucherie, I didn't shared the code, but indeed the <key_as_dict>, which is the public key, is retrieved from their server, then i build a jwk from this dict. After some discussion with the signer, it seems that the 3rd step of their documentation was not necessary (it depends according to the lib used). Replacing the concatenation with the raw payload (not b64 encoded) was indeed the problem, thanks @simo5 for you time ! |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm desperately trying to validate a JWS Signature send from a webhook event on my API.
Here is the JWS I receive
Anyway i'm still having InvalidJWSSignature error (Verification failed for all signatures), whatever i try to pass to the function. Any idea on what i could have miss or misunderstood?
Beta Was this translation helpful? Give feedback.
All reactions