Repository navigation
Description
Summary
Crypt::OpenSSL::RSA->generate_key($bits) passes the caller-provided bit length directly to Java's KeyPairGenerator.initialize(bits). The adapter does not validate a minimum or supported range before asking the provider to generate the key. A caller can therefore request RSA keys below current security guidance, and extremely large values can cause expensive provider work.
CodeQL reports a high-severity “Use of a cryptographic algorithm with insufficient key size” alert at CryptOpenSSLRSA.java:203. This finding is outside PR #1938's changed files, but it currently fails that PR's CodeQL check: run 130520292751.
Current implementation and compatibility constraint
In CryptOpenSSLRSA.generate_key, the method reads $bits and calls kpg.initialize(bits) without a policy check.
The project-owned crypt_openssl_rsa_pkcs1_padding.t calls generate_key(1024). Simply enforcing a 2048-bit minimum would break that existing compatibility test. The implementation needs an explicit compatibility decision; silently clamping a requested size would also change the API's behavior without telling the caller.
For approved RSA key-establishment schemes, NIST SP 800-56B Rev. 2 specifies modulus lengths providing at least 112 bits of security strength, beginning at 2048 bits. See NIST SP 800-56B Rev. 2 and the NIST SP 800-131A Rev. 2 transition guidance. That key-establishment guidance is relevant context; the adapter's supported signing and verification behavior also needs to be checked against the applicable RSA signature guidance before selecting one policy for the whole API.
Questions to resolve
- Should
generate_keyreject keys below 2048 bits by default, or must it preserve upstream acceptance of explicitly requested 1024-bit keys? - If secure-by-default generation is adopted, what explicit compatibility path should support callers that still require legacy keys without making insecure generation implicit?
- What upper bound should be enforced to avoid unbounded key-generation cost from an unusually large caller-supplied value?
- Should importing and verifying existing legacy keys remain supported independently of the generation policy? It should unless a separate compatibility decision says otherwise.
Acceptance criteria
- Define and document the minimum and maximum accepted generation sizes before calling the Java provider.
- Reject invalid, out-of-range, and policy-disallowed values with a clear Perl exception; do not silently round, clamp, or downgrade a request.
- Resolve the existing 1024-bit compatibility test without deleting or weakening it.
- Add focused coverage for invalid/undersized requests, the selected supported minimum, valid key generation and sign/verify behavior, and any explicit legacy opt-in if one is chosen.
- Preserve parsing and operations on legacy keys unless separately specified.
- Verify that the CodeQL alert is either eliminated by the chosen policy or explicitly documented as an intentional compatibility exception with a narrowly scoped, reviewable rationale.
Related work
- PR Remove memory sweeps through explicit Perl owner slots (#2043) #1938 has an unrelated CodeQL finding at this unchanged source location: Remove memory sweeps through explicit Perl owner slots (#2043) #1938
- #1220: port the CryptX cryptographic toolkit covers a separate cryptography distribution and does not resolve this
Crypt::OpenSSL::RSAbehavior.
Activity
fglock commentedon Nov 11, 2026
State: handed-off
Agent/session: codex-rsa-2031-20261111
Scope: #2031, bounded RSA key generation and preserve the existing 1024-bit compatibility test.
Work: feature/bundled-api-import-compat, commit 002914e, PR #2029.
Checkpoint: 2026-11-11 11:34 UTC; implementation and regression coverage are on the open PR.
Evidence:
nice -n 19 makeandmake check-linkspassed; focused new policy and unchanged legacy test passed on JVM and interpreter. PR Linux/Windows builds passed; Java CodeQL analysis is pending. Thejava/insufficient-key-sizecompatibility exception is narrowly scoped with a source suppression comment and rationale.Blocked by: none.
Next: PR reviewers can assess the explicit 1024-bit legacy-generation exception and CodeQL result.
fix: bound RSA key generation sizes
fix: preserve package context when requiring modules