Open michaelpaliy opened 1 year ago
This is something I'm not familiar with. Let me try pulling in some crypto experts.
Based on https://crypto.stackexchange.com/a/3113
Only the Fermat primes 3,5,17,257,65537 have both properties, and all are common choices of 𝑒
Are you sure e
can be any non-negative number?
In theory, e can be any non-negative number that is coprime to the Euler totient of n. In practice, the exponent should always be 65537, and even 3 should be discouraged, given Coppersmith attacks, and I don't think allowing different exponents is a good idea.
I agree that 65537 is the best practice. But this library is used for JWT validation, and I think it should accept all the valid exponent values (even if they are not the best practice/not secured enough). In my case, the Idp service (external provider) uses different values for the exponent, which prevents us from using istio authentication. As the exponent is not 65537 or 3, we get the following error: Jwks RSA [n] or [e] field is missing or has a parse error.
Supporting arbitrary values of e
is also a DoS risk. BoringSSL won't accept any e
over 33 bits for this reason. We're stuck being a bit more permissive than just 3 and 65537, but the constraints in this library are sound. I don't think it makes sense to change it.
Were RSA standardized correctly, we'd have just picked the one value of e
as part of a parameter set and moved on with life.
As raised in https://github.com/istio/istio/issues/41729
If a JWK has an exponent different from 65537 or 3, the parsing fails with the following error: "Jwks RSA [n] or [e] field is missing or has a parse error"
For example, parsing will fail for the following valid JWK:
I couldn't find any reference that the exponent must be 65537 or 3, even though 65537 is commonly used.
opened PR https://github.com/google/jwt_verify_lib/pull/95, which should fix the JWK validation. I'd appreciate if you could review it.