Repository navigation
polyjose 0.2.0
RSA private keys: RSA signing, RSA-OAEP-256 decryption and RSA private-key import, in the Rust crate and in every binding. This is a minor release because, on 0.x, behaviour changes to the public API bump the minor version: inputs that 0.1 refused now work, some error codes changed, and the Rust RSA key type has a new name. No binding function, type or signature changed (bindings/api-inventory.txt is the same as in 0.1.2).
Added
- RSA signing:
RS256,RS384,RS512,PS256,PS384andPS512sign with an RSA private key, in compact and JSON JWS and when issuing a JWT (RFC 7518 §3.3, §3.5).RS*signatures are deterministic and match RFC 7515 Appendix A.2 exactly. - RSA-OAEP-256 decryption (RFC 7518 §4.3), in compact and JSON JWE, with one or more recipients. A bad Encrypted Key is never reported as one: a random content key is used instead and the result is
DecryptionFailed, like any other failure (RFC 7516 §11.5). - RSA private keys: import from a JWK (all of
d,p,q,dp,dqandqi; RFC 7518 §6.3.2), from PKCS#8 (PRIVATE KEY) and from PKCS#1 (RSA PRIVATE KEYandKeyFormat::Pkcs1DER); export as a JWK and as PKCS#8. The private members must belong to the key ofnande, the modulus must be 2048 to 8192 bits, and the key is wiped on drop and redacted inDebug.RsaKey::is_privatetells a private RSA key from a public one, andJwk::to_publicdrops the private members. - JWK Sets keep an RSA private member as imported, as they already did for EC and OKP private keys, so a set can hold RSA-OAEP-256 decryption keys. Call
to_publicon each key before you publish a set.
Changed
- Behaviour change: an RSA private JWK, PEM or DER key used to fail with
UnsupportedAlgorithm; it now imports. A JWK Set with an RSA private member used to fail as a whole; it now keeps the member. Signing with RS*/PS* or decrypting RSA-OAEP-256 used to fail withUnsupportedAlgorithm; with a public key, both now fail withKeyAlgorithmMismatch. - Behaviour change: a PKCS#1 RSAPrivateKey passed as PKCS#8 or SEC1 (by
KeyFormator by PEM label) is nowInvalidKey, because the structure is wrong for the format. It used to beUnsupportedAlgorithm. - Behaviour change: PKCS#1 export of an RSA private key fails with
InvalidKey, in both DER and PEM, with the message "pkcs1 export writes the public key; call to_public first". PKCS#1 export always writes the RSAPublicKey (RFC 8017 Appendix A.1.1), so polyjose refuses rather than silently dropping the private part. A public key still exports as before. To export a private key, use PKCS#8 or a JWK. - Rust:
jwk::RsaPublicKeyis renamedjwk::RsaKey, because it now also holds private keys.RsaPublicKeystays as a deprecated alias ofRsaKey(#[deprecated(since = "0.2.0")]), so 0.1 code still compiles, with a warning.- Migration: replace
RsaPublicKeywithRsaKey.
- Migration: replace
- Rust: the
rsadependency is now=0.10.0, with only itspkcs1v15feature.crypto-bigintis now0.7.11. - Release builds: every published artifact is the exact build that the release candidate run built and smoke-tested. The tag run no longer rebuilds anything: it signs, attests and drafts those bytes (ADR 0068).
Security
-
Marvin (RUSTSEC-2023-0071) is patched.
rsa0.10.0 is the first release the advisory lists as patched, and thecargo denyignore for it is gone. RSA private-key operations go only throughrsa's blinded entry points, with randomness from the OS CSPRNG. Build checks (check-deps.shand a symbol check on the compiled library) keep key generation,RSA1_5, unblinded paths andrsa'shazmatAPI out, and they requirersa's blinded core to be present wherever private-key code is. -
Constant-time evidence:
- upstream's BINSEC verification (
cargo checkct) ofrsa's constant-time code; - polyjose's own dudect-style Welch t-test, run natively and on wasm32. It compares valid with invalid RSA-OAEP-256 ciphertexts, and signing different messages, and has a positive control that must detect a known public-input difference.
The signing test shows only that timing does not depend on the message. Both of its classes use the same key, so independence from the private key rests on
rsa's blinding. There is no Marvin-toolkit run, and thersa0.10 rewrite has no published independent audit. - upstream's BINSEC verification (
-
Residual risk: zeroization inside
rsa0.10.0. polyjose wipes its own copies of RSA private members, andrsa's private key wipes itself on drop. Butrsa's big integers (BoxedUint) areZeroize, notZeroizeOnDrop. On the error paths ofPrivateKey::from_components(a key that fails validation), and in some of its intermediate values, secret limbs may be freed without being wiped. This touches only rejected keys and transient values insidersa. The fix belongs upstream. -
Known deviations of
rsa0.10.0 (see SECURITY.md):- RSA-OAEP decryption does not check that the first octet of the encoded message is zero (RFC 8017 §7.1.2 step 3.g). This cannot help an attacker in JWE.
- A private key whose two primes differ in size by more than the half-modulus width is refused on import with
InvalidKey.
-
Bounded decryption cost: each candidate RSA-OAEP-256 recipient costs one private-key build (validation and CRT precomputation) and one blinded private-key operation. A decrypt call tries at most
DecryptPolicy::max_recipientsof them, and there is no separate RSA budget. With keys of 4096 bits or more, give the key and the recipients akid, which narrows the candidates (RFC 7516 §4.1.6), or lowermax_recipients. -
Multi-prime RSA keys (
oth, PKCS#1 versionmulti) areUnsupportedAlgorithm, and an RSA private JWK without its CRT members isInvalidKey. RSA key generation,RSA-OAEP(SHA-1) andRSA1_5are still not implemented, and no feature flag turns them on.
API by platform
No binding adds, removes or changes a function, type or signature. In every binding, these existing entry points now accept RSA private keys, and their error codes change as described under Changed: key import and export, JWS and JWT signing, JWE decryption, and JWK Sets.
- Rust (
polyjose):jwk::RsaKeyis the new name ofjwk::RsaPublicKey, which stays as a deprecated alias.RsaKey::is_privateis new. RS*/PS* signing, RSA-OAEP-256 decryption and RSA private import work through the existingjws,jwt,jweandjwkfunctions. - Node.js (
@polyjose/node): no change toindex.d.tsor theexportsmap. Behaviour changes as above. - Web (
@polyjose/wasm): no change to the TypeScript declarations. Behaviour changes as above. - Android and the JVM (
dev.polyjose:polyjose,polyjose-jvm): no change to the Kotlin API. Behaviour changes as above. - Swift (
Polyjose): no change to the Swift API; only doc comments are regenerated. Behaviour changes as above.Package.swiftpoints at the 0.2.0 XCFramework.
Every asset is listed in SHA256SUMS, signed in SHA256SUMS.asc by the release key
(https://github.com/bharathkontham/polyjose/blob/v0.2.0/.github/keys/polyjose-release.asc), and has a
build-provenance attestation (https://github.com/bharathkontham/polyjose/attestations):
gh attestation verify <asset> --repo bharathkontham/polyjose.