-
Notifications
You must be signed in to change notification settings - Fork 13
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
Read SignatureAlgorithm from X509Certificate if available #557
Comments
Playing around with this, the only ones I am able to infer are: private static SignatureAlgorithm? TryReadSignatureAlgorithmFromCertificate(X509Certificate2 certificate)
{
switch (certificate.SignatureAlgorithm.Value)
{
case Oids.RsaPkcs1Sha256:
return SignatureAlgorithm.RsaSha256;
case Oids.RsaPkcs1Sha384:
return SignatureAlgorithm.RsaSha384;
case Oids.RsaPkcs1Sha512:
return SignatureAlgorithm.RsaSha512;
case Oids.ECDsaWithSha256:
return SignatureAlgorithm.EcdsaSha256;
case Oids.ECDsaWithSha384:
return SignatureAlgorithm.EcdsaSha384;
case Oids.ECDsaWithSha512:
return SignatureAlgorithm.EcdsaSha512;
case Oids.RsaPss:
// no means to easily retrieve this from X509Certificate2 as the Parameters of the
// signature algorithm are not exposed.
default:
return null;
}
} Oids.cs from https://github.com/dotnet/runtime/blob/main/src/libraries/Common/src/System/Security/Cryptography/Oids.cs |
Here is the very rough experiment (against v1.9.2): |
I am not really confident with the usage of the signatureAlgorithm for populating the SignatureAlgorithm of the JWK.
I've played with some test vectors. For example the www.google.com certificate, the signature algorithm is The signatureAlgorithm of the certificate is the algorithm used for signing the certificate, not the algorithm that can be used with the certificate key. |
Interesting, I had not tried altering the signature algorithm from what the certificate states. I guess I should have included our motivation: Jwk's alg is private, and when I use FromCertificate I cannot stipulate which signing algorithm I want to enforce with the use of the key. |
I'll check if there is a reason for keeping the algorithm as init-only, but I think it is just by laziness. |
Two options:
|
I would be happy with a new parameter on FromX509Certificate. Maybe it helps to know what we're doing, we're using JWKS to assist in JWT certificate rotation:
|
What is the usage of the |
With the following (test) JWKS via
Given the following token:
Running the following code gives var policy = GetBasicValidationPolicyBuilder(options)
.RequireSignature(_jwks)
.RequireIssuer(safeIssuer)
.Build();
return reader.TryReadToken(tokenRaw, out token); If I include the signature algorithm in either (a) the JWKS or, (b) the |
Minimal reproduction on v1.9.2: https://gist.github.com/watfordgnf/771f882bab8233e4def8345ad89c52ad |
OK I understand now the issue: In v2.X, the |
Being able to define the algorithm with FromX509Certificate would work well for us (allows our JWKS to interoperate with Vault), however, I believe we will still want to pass the algorithm to |
The |
The version 1.9.3 introduce the |
We're using X509 certs to sign and verify JWTs, and we have come across an issue where we have to explicitly state the signature algorithm in our policy because
Jwk.Alg
is null.I believe this could instead be read from the X509 cert and added to the JWK in FromX509Certificate:
Basically supporting RFC 3279 and family (https://tools.ietf.org/html/rfc3279#section-2.2).
The text was updated successfully, but these errors were encountered: