Repository navigation
PKCS#5 PBES2: reject iteration counts below 1 and mismatching keyLength - #918
Open
ManoharPaturi wants to merge 1 commit into
Open
ManoharPaturi wants to merge 1 commit into
ManoharPaturi wants to merge 1 commit into
Conversation
Signed-off-by: Manohar Paturi <manoharpaturi@users.noreply.github.com>
Contributor
|
fixes Mbed-TLS/mbedtls#10836 |
Contributor
Which already has a PR: #844 Though it looks like this PR is also addressing another issue (keylength) at the same time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
pkcs5_parse_pbkdf2_params()accepts anyiterationCountfrom the EncryptedPrivateKeyInfo, including zero, and the PBES2 path silently discards a mismatchingkeyLength:iterationCounthas no lower bound. RFC 8018 §4.2 requires at least 1. WithiterationCount = 0the PBKDF2 loop derives the key from a single HMAC block, so whoever supplies the encrypted key file chooses the KDF cost. Verified against currentdevelopment: patching the iteration INTEGER offramework/data_files/rsa_pkcs8_pbes2_pbkdf2_2048_aes128cbc.derfrom 2048 to 0 and callingmbedtls_pk_parse_key()runs the full decryption with the 0-iteration key (failing only later withPASSWORD_MISMATCH, i.e. the parameter was accepted and used).keyLengthis parsed then ignored ("we don't know if it was set or not"). RFC 8018 §A.2: when present it MUST equal the encryption key length. A hostile/misconfigured PBES2 parameter set is accepted instead of rejected.Fix
iterationCount < 1withMBEDTLS_ERR_PKCS5_INVALID_FORMAT.keylen == 0as the "absent" sentinel (the declaration is zero-initialized and the ASN.1 getter only writes on success) and reject a present-but-mismatchingkeyLength.Verification
Branch builds clean; the mutated-DER case above is now rejected at parse time. A
test_suite_pkparsedata entry with the modified DER makes this a regression test.