Description
What would you like to see added?
Better support for high entropy secrets
Additional Context
Proper keys for symmetric cryptographic algorithms are produced by a cryptographically secure pseudorandom number generator (CSPRNG) or a key derivation function (KDF). CSPRNGs and KDFs do not typically output character strings. They produce streams of bytes (or bits).
This is the reason why the OpenSSL functions take arrays of unsigned char
as input. Note the unsigned qualifier. This is OpenSSL's way of saying "these are not characters". (uint8_t
was not available when SSLeay was originally designed.)
While an array of bytes could be turned into a character string using hexadecimal encoding or base64, this is not convenient.
Moreover, accepting a character string as input gives the wrong impression to users lacking the relevant cryptography knowledge. They are likely to use low entropy secrets (AKA passwords) instead of high entropy secrets (AKA keys). This introduces a vulnerability since using a low entropy secret as HMAC key makes brute force attacks against the JWTs possible.
(Whenever a password is used in a properly designed cryptographic system, it is always passed first to a password-based key derivation function such as Argon2. Only then are keys produced by the KDF used with symmetric algorithms such as ciphers or MACs.)
Finally, supporting symmetric JWK keys (with "kty" set to "oct") requires decoding the base64url encoded key, which yields an array of octets, not a character string. (See https://datatracker.ietf.org/doc/html/rfc7518#section-6.4)
Now that I am done with the explanations, here is what I suggest:
- Support arrays of bytes as the HMAC keys.
- Find ways to warn users that they are probably doing something wrong if they use a string as the key.