Skip to content

Bound PKCS#1 modulus sizes before bigint conversion - #793

Merged
tarcieri merged 1 commit into
masterfrom
bound-pkcs1-private-key-modulus-size
Nov 9, 2026
Merged

tarcieri merged 1 commit into
masterfrom
bound-pkcs1-private-key-modulus-size

Conversation

@tarcieri

@tarcieri tarcieri commented Nov 9, 2026

Copy link
Copy Markdown
Member

Reject moduli from pkcs1::{RsaPublicKey, RsaPrivateKey} (which are stored as der::asn1::UintRef) which exceed rsa::PublicKey::MAX_SIZE prior to allocating a BoxedUint on the heap.

Eagerly rejecting these inputs prevents potential DoS from malicious PKCS#1 and PKCS#8 (which wraps PKCS#1) inputs.

Thanks to @AlexxcelerateDev for reporting this.

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.77419% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.14%. Comparing base (cd070bd) to head (be663c9).

Files with missing lines Patch % Lines
src/encoding.rs 96.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #793      +/-   ##
==========================================
+ Coverage   93.13%   93.14%   +0.01%     
==========================================
  Files          29       29              
  Lines        4091     4097       +6     
==========================================
+ Hits         3810     3816       +6     
  Misses        281      281              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Reject moduli from `pkcs1::{RsaPublicKey, RsaPrivateKey}` (which are
stored as `der::asn1::UintRef`) which exceed `rsa::PublicKey::MAX_SIZE`
prior to allocating a `BoxedUint` on the heap.

Eagerly rejecting these inputs prevents potential DoS from malicious
PKCS#1 and PKCS#8 (which wraps PKCS#1) inputs.

Thanks to @AlexxcelerateDev for reporting this.
@tarcieri
tarcieri force-pushed the bound-pkcs1-private-key-modulus-size branch from 5035d73 to be663c9 Compare November 9, 2026 05:08
@tarcieri
tarcieri merged commit 90fb187 into master Nov 9, 2026
15 checks passed
@tarcieri
tarcieri deleted the bound-pkcs1-private-key-modulus-size branch November 9, 2026 05:30
tarcieri added a commit to RustCrypto/SSH that referenced this pull request Nov 9, 2026
OpenSSH enforces the following limit on the size of `mpint`:

https://github.com/openssh/openssh-portable/blob/e416edf/sshbuf.h#L41

This commit enforces the same limit for the standard `Mpint`
constructors. Unfortunately we support infallible `From<Uint>` impls
that can't enforce the size limit, which are currently TODOs.

Perhaps before the next `ssh-key` release we can consider making another
breaking release of `ssh-encoding` to address those TODOs properly.

See also: RustCrypto/RSA#793
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant