-
Notifications
You must be signed in to change notification settings - Fork 417
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
Wrong decryption key for ECDH with keywrap #1951
Comments
@max4t thanks for reporting this issue. |
I'm also running into this issue and agree with @max4t In ECDH - the TokenDecryptionKey should be your private key. The public key needs to resolve to EPK. There are other issues in this code as well. If there are multiple keys resolved and we drop to the "brute force" approach of trying them all, the exception messages are appended It's hard to guess the original intent here. On the one hand, brute forcing multiple keys was definitely noted in the comments. However, the if statement checking the FWIW, I was able to hack around these issues and get ECDH unwrap working using the following: var jwt = new JsonWebToken(encodedToken);
// Work around EPK not being resolved
var epk = new JsonWebKey(jwt.GetHeaderValue<string>(JwtHeaderParameterNames.Epk));
// Code expects both keys to be ECDsaSecurityKeys and not JsonWebKeys
var ecdsa = ECDsa.Create(new ECParameters()
{
Curve = Constants.Curve,
Q = new ECPoint()
{
X = WebEncoders.Base64UrlDecode(epk.X),
Y = WebEncoders.Base64UrlDecode(epk.Y)
}
});
var ecdsaSK = new ECDsaSecurityKey(ecdsa);
var tokenValidationParameters = new TokenValidationParameters
{
// Setting a resolver will force the key to be the private key
TokenDecryptionKeyResolver = (_, _, _, _) => new [] { new ECDsaSecurityKey(decryptKey) },
// Decryption key is used as the public key
TokenDecryptionKey = ecdsaSK
};
var result = new JsonWebTokenHandler().ValidateToken(request, tokenValidationParameters); |
It would also really be nice if on the flip side, if |
Hey, just ran into this issue and worked around it by manually setting EPK in AdditionalHeaderClaims and reading it in TokenDecryptionKeyResolver. Will there be an update? Saw the already open pull request. |
@GregDomzalski @inf9144 looking into this now. |
@GregDomzalski the PR 2120 looks good one comments about back compat. |
Hello,
I believe there's an error in the implementation.
azure-activedirectory-identitymodel-extensions-for-dotnet/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.cs
Lines 982 to 986 in 59ec62e
The second argument of
EcdhKeyExchangeProvider
should be the public key taken from theepk
in the token's header (as the comment said).The text was updated successfully, but these errors were encountered: