-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add a test case to illustrate a256gcm decipher fail #34
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: David Mulder <[email protected]>
I went through this test and the associated code and I don't see anything wrong in compact_jwt. We get the jwec with direct + aes256gcm, which you then correct attempt to deserialise with the direct key. The decryption fails in the "decrypted.finalise" step which indicates that the authentication tag didn't match. The most likely explanation is that the aes key you are using isn't correct for the payload. |
Ok, that was my belief as well after analyzing things. I just don't understand why this would have failed. Unless I'm formatting the public key incorrectly in the previous request (so it's encrypted using the wrong public key)? This could be. I've seen MS accept garbage before for the public key. |
Yeah, it could be something like that. It's hard when you're trying to poke at a black box to work out what's going on :( |
I think I've finally tracked down this issue (maybe). When I examine traffic from a MS application, I see that in the request for this un-decryptable PRT, I'm supposed to send a {"e":"AQAB","kty":"RSA","n":"AMBIy7nfnekGD74imrS6Y3teAg5pDX4Z1iVptx-krTQok-X_NAUOptdVS-5dphlz9MSV32tEsnle8oexXPSrfAuGLJD0MmMD4-FSVSnquXElZRKoLcWBWH7wABSRRGRwU15dUq93b1Q6lvgTNKSO0xe7BjmLivzlPqDZI4dhp6oUffHcWF0wX3YVvvwYB--IjJCA9F5ynpLas8vdHYrge6C-ZD4ufItfDSbbin5gq-uftvUOK8B04-cyQxZivZu7Fo3Q_G4PdnOlLf5NG9_ROTBBXXD0RdpAP9rYh3EUB6p9BOctbcdnLUUPOnqu7WhsW5RE9HLQIeyiKUNdL_HQwn0"} So in order to request an initial PRTv3, I have to supply an RSA public key in the request. We've been trying to decrypt this PRTv3 with the AES256GCM session key. Looking around, some Entra Id error message refers to the stk_jwk as the 'session transport key'. So, perhaps the transport key, or some other RSA key entirely? So here's what I think is expected:
|
This so-called 'initial' response has a header of |
A sample 'initial' session_key_jwe looks like this:
|
Right, so from your messages/outputs I think:
So in that case, don't we have all the parts in place here to solve this? The only concern I'd have is about exporting the publickey here as a jwk, since we aren't setting the kty field https://github.com/kanidm/compact-jwt/blob/main/src/crypto/rs256.rs#L141 It looks like it's valid from https://www.rfc-editor.org/rfc/rfc7517#section-4.1 so I don't see a reason we couldn't add it. My final concern would be that we also are adding in extra fields MS may not like, so we may need an "azure optimised" jwk function. |
I need to investigate more. After some more testing, I think my assumptions here might be incorrect. |
This is a real access token response from MS, using their oauth2 version 2 protocol and PRT version 3 request (and the encrypted token is no longer valid, as the enrolled object has been deleted).