Repository navigation
Read privateKey and decryptionPvk at construction, and refuse a key the option can't use #507
Description
privateKey and decryptionPvk are read the first time they are used. privateKey is read when a request, a logout message or metadata is signed, and decryptionPvk when an encrypted assertion or NameID arrives. A key that is malformed, or of a kind the option can't use, constructs without complaint and fails on the first request that needs it. For most such keys the error is OpenSSL's, and it doesn't name the option. With #447 merged, on Node 26:
| Value | Option | Fails | Error |
|---|---|---|---|
| an EC private key, PEM or Base64 | decryptionPvk |
at the first encrypted message | error:03000096:digital envelope routines::operation not supported for this keytype |
| a certificate or a public key, PEM | decryptionPvk |
at the first encrypted message | error:020000B3:rsa routines::missing private key |
| a certificate or a public key, PEM | privateKey |
at the first signing, on both bindings | error:1E08010C:DECODER routines::unsupported |
| Base64 that is no private key | either | at first use | … is not a valid PEM or Base64 private key: Invalid PEM format. |
In the next major, constructing a SAML with either option set to a value it can't use throws a TypeError naming the option, as a missing callbackUrl, issuer or idpCert already does.
Scope
initialize()readsprivateKeyanddecryptionPvkthe way they are read at use, throughprivateKeyToPem()anddecryptionPvkToPem(). A value those refuse is refused at construction, with the same message.- Each must then hold a private key of a type the option can use. The type comes from Node's
crypto.createPrivateKey().asymmetricKeyType. FordecryptionPvkthat is RSA, because xml-encryption unwraps the content key only withrsa-oaep-mgf1porrsa-1_5. ForprivateKeyit is RSA, because everysignatureAlgorithmvalue is an RSA signature. Whether the data fits its PEM label stays with xml-crypto'stoPem(). - A PEM
decryptionPvkis still handed to Node as given, so text around the message, such asBag Attributes, stays accepted. The check at construction reads it the same way. README.md: theprivateKeyanddecryptionPvksections say that the key is checked at construction, and which key types each option takes.
Why the next major
A configuration that holds an unusable key and never uses it works today, and would throw at startup. Examples are a decryptionPvk set although the IdP never encrypts, and a placeholder key in a test suite.
Decide first
- Keep the check at use, or keep what construction read.
SAML.optionsis public and can be changed after construction, so the check at use stays unlessoptionsbecomes read-only. Keeping the PEM that construction produced would also stop every request from reading the key again. idpCert,publicCertanddecryptionCert. A plain value of each could be read at construction too. AnidpCertcallback can only be read when it runs, at verification.rsa-psskeys. Node types an RSA-PSS keyrsa-pss, notrsa. Decide whetherprivateKeymay be one whensignatureAlgorithmissha256-mgf1.
Related: #422 requires signatureAlgorithm when signing, so the privateKey check can rely on it.
🤖 Generated with Claude Code
Activity