class

KemalIdentity::JWT::RSAPublicKey

Inherits Reference < Object

An RSA public key, held as a live EVP_PKEY.

Why the key is built as DER

A JWKS gives a modulus and an exponent as two base64url integers, and OpenSSL has no "assemble a key from these two numbers" call that survives 3.x: the RSA_new / RSA_set0_key route is deprecated there, and EVP_PKEY_fromdata is 3.0-only, which would make this shard refuse to build against 1.1.1. What is stable in both is d2i_PUBKEY, so the two integers are encoded into a DER SubjectPublicKeyInfo — about forty lines of ASN.1 — and parsed back by OpenSSL itself. OpenSSL validates the structure; this code only writes it.

Constants

MINIMUM_MODULUS_BYTES = 256

Smallest modulus accepted, in bytes.

2048 bits. Anything smaller is not a key an issuer should still be signing with, and accepting one means the weakest key in a rotating JWKS sets the security of the whole thing.

RSA_ALGORITHM_IDENTIFIER = Bytes[48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0]

DER for AlgorithmIdentifier { rsaEncryption, NULL }, which is the same bytes for every RSA key: SEQUENCE { OID 1.2.840.113549.1.1.1, NULL }.

Constructors

new(modulus : Bytes, exponent : Bytes)

Builds a key from a JWKS n and e, already base64url-decoded.

Raises ConfigurationError for anything OpenSSL will not accept, so a malformed JWKS entry is a loud failure at fetch time rather than a key that silently verifies nothing.

Source

Instance methods

finalize
Source
verify(data : String, signature : Bytes, digest : OpenSSL::Algorithm) : Bool

Whether signature is a PKCS#1 v1.5 signature over data under this key.

Returns false for anything that does not verify, including a malformed signature: everything reaching here is attacker-supplied, so nothing about it may raise.

Source