pkcs12: PBKDF2-params prf is DEFAULT algid-hmacWithSHA1 - #2469
Open
yuxi-liu-wired wants to merge 1 commit into
Open
yuxi-liu-wired wants to merge 1 commit into
yuxi-liu-wired wants to merge 1 commit into
Conversation
RFC 8018 defines `prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT
algid-hmacWithSHA1`, and DER omits a DEFAULT value, so PBKDF2 with
HMAC-SHA1 is encoded without prf (e.g. `openssl pkcs8 -v2prf
hmacWithSHA1`, and older PKCS#12 tools). pkcs12::pbe_params::Pbkdf2Params
declared prf as a required field, so such params failed to decode
("ASN.1 DER message is incomplete"). pkcs5::pbes2::Pbkdf2Params already
handles this.
Decode an absent prf as algid-hmacWithSHA1 and omit it when encoding
that value. The derive's `default` only supports Copy fields, so the
DecodeValue/EncodeValue impls are written out, as in pkcs5.
This branch has not been deployed
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.
RFC 8018 (quoted in the type's doc comment) defines
and DER omits a DEFAULT value, so PBKDF2 with HMAC-SHA1 is encoded without
prf.openssl pkcs8 -v2prf hmacWithSHA1produces this, as do older PKCS#12 tools.pkcs12::pbe_params::Pbkdf2Paramsdeclaresprfas a required field, so these params fail to decode:The fix decodes an absent
prfasalgid-hmacWithSHA1({ id-hmacWithSHA1, NULL }, RFC 8018 B.1.1) and omits it when encoding that value. The derive'sdefaultattribute only works forCopyfields (AlgorithmIdentifierOwnedisn't), soDecodeValue/EncodeValueare written out, aspkcs5::pbes2::Pbkdf2Paramsalready does. The public struct is unchanged.Test:
tests/pbe_params.rsdecodes the OpenSSL params above, checksprfis HMAC-SHA1, and re-encodes byte for byte. It fails on master. Thepkcs12.ymlmatrix passed locally: powerset tests on stable and 1.85, thumbv7em powerset build, fmt, clippy.This PR was produced by AI agents (Claude) and reviewed by me before submission.