Skip to content

Commit 895dbdf

Browse files
authored
pkcs5: allow empty algId prf parameter for PBES2 params (#1521)
1 parent 6bbfc46 commit 895dbdf

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

pkcs5/src/pbes2/kdf.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,6 @@ impl TryFrom<AlgorithmIdentifierRef<'_>> for Pbkdf2Prf {
336336
if !params.is_null() {
337337
return Err(params.tag().value_error());
338338
}
339-
} else {
340-
// TODO(tarcieri): support OPTIONAL parameters?
341-
return Err(Tag::Null.value_error());
342339
}
343340

344341
match alg.oid {
Binary file not shown.

pkcs5/tests/pbes2.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ const PBES2_PBKDF2_SHA256_AES256CBC_ALG_ID: &[u8] = &hex!(
2424
4801650304012a0410b2d02d78b2efd9dff694cf8e0af40925"
2525
);
2626

27+
/// PBES2 + PBKDF2-SHA256 + AES-256-CBC `AlgorithmIdentifier` example without PRF NULL parameter.
28+
///
29+
/// Generated by Smallstep CLI: `step certificate p12 out.p12 in.crt in.key`, extracted from PKCS#12.
30+
/// `tests/examples/pbes2_aes-256-cbc_hmacWithSHA256_algid-no-param.der` test vector.
31+
const PBES2_PBKDF2_SHA256_AES256CBC_ALG_ID_NO_NULL_PARAM: &[u8] = &hex!(
32+
"305d06092a864886f70d01050d3050302f06092a864886f70d01050c30220410
33+
0c12aa39d743d1633ddbb615a5ec1b6a02020800300a06082a864886f70d0209
34+
301d060960864801650304012a0410baba52272b5a30263d62f81ae27ad768"
35+
);
36+
2737
/// PBES2 + scrypt + AES-256-CBC `AlgorithmIdentifier` example.
2838
///
2939
/// Generated by OpenSSL and extracted from the `pkcs8` crate's
@@ -96,6 +106,31 @@ fn decode_pbes2_pbkdf2_sha256_aes256cbc() {
96106
}
97107
}
98108

109+
/// Decoding test for PBES2 + PBKDF2-SHA256 + AES-256-CBC `AlgorithmIdentifier` without NULL prf parameter
110+
#[test]
111+
fn decode_pbes2_pbkdf2_sha256_aes256cbc_without_null_parameter() {
112+
let scheme =
113+
pkcs5::EncryptionScheme::try_from(PBES2_PBKDF2_SHA256_AES256CBC_ALG_ID_NO_NULL_PARAM)
114+
.unwrap();
115+
let params = scheme.pbes2().unwrap();
116+
117+
let pbkdf2_params = params.kdf.pbkdf2().unwrap();
118+
assert_eq!(
119+
pbkdf2_params.salt.as_bytes(),
120+
&hex!("0C12AA39D743D1633DDBB615A5EC1B6A")
121+
);
122+
assert_eq!(pbkdf2_params.iteration_count, 2048);
123+
assert_eq!(pbkdf2_params.key_length, None);
124+
assert_eq!(pbkdf2_params.prf, pbes2::Pbkdf2Prf::HmacWithSha256);
125+
126+
match params.encryption {
127+
pbes2::EncryptionScheme::Aes256Cbc { iv } => {
128+
assert_eq!(iv, hex!("BABA52272B5A30263D62F81AE27AD768"));
129+
}
130+
other => panic!("unexpected encryption scheme: {:?}", other),
131+
}
132+
}
133+
99134
/// Decoding test for PBES2 + scrypt + AES-256-CBC `AlgorithmIdentifier`
100135
#[test]
101136
fn decode_pbes2_scrypt_aes256cbc() {

0 commit comments

Comments
 (0)