Skip to content

Commit bce7eaf

Browse files
committed
fix(pkcs12): pre-submission cleanups for RC2-CBC PR
- add #[deprecated] alias for renamed PKCS_12_PBEWITH_SHAAND40_BIT_RC2_CBC - clarify Zeroizing spare-capacity behavior in decrypt.rs comment - add non-BMP password rejection tests for both RC2 decrypt methods - remove redundant rc2 dev-dependency (covered by optional main dep)
1 parent ff81537 commit bce7eaf

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

pkcs12/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ cipher = "0.5"
3737
sha1 = "0.11.0"
3838
sha2 = "0.11"
3939
whirlpool = "0.11"
40-
rc2 = "0.9.0"
4140

4241
[features]
4342
default = ["pem"]

pkcs12/src/decrypt.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ fn decrypt_rc2(
195195
// plaintext *length* from decrypt_padded (dropping the borrow on buf),
196196
// then truncate buf to that length and return it directly. This avoids
197197
// a second allocation and memcpy compared to calling plaintext.to_vec().
198-
// The Zeroizing drop still zeroes the full buffer capacity on exit.
198+
// `Zeroizing` calls `Vec::zeroize()` on drop; since zeroize v1.6+
199+
// zeroes spare capacity in addition to [0..len], the PKCS#7 padding
200+
// bytes at [pt_len..] are zeroed on drop even though they are not
201+
// included in the returned slice.
199202
let mut buf = Zeroizing::new(ciphertext.to_vec());
200203
let pt_len = decryptor
201204
.decrypt_padded::<Pkcs7>(&mut buf)

pkcs12/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ pub const PKCS_12_PBE_WITH_SHAAND128_BIT_RC2_CBC: ObjectIdentifier =
7272
pub const PKCS_12_PBE_WITH_SHAAND40_BIT_RC2_CBC: ObjectIdentifier =
7373
ObjectIdentifier::new_unwrap("1.2.840.113549.1.12.1.6");
7474

75+
/// Deprecated: the previous name of [`PKCS_12_PBE_WITH_SHAAND40_BIT_RC2_CBC`].
76+
///
77+
/// The original constant name was missing an underscore between `PBE` and
78+
/// `WITH`. Renamed in 0.2.0; this alias exists for backward compatibility.
79+
#[deprecated(
80+
since = "0.2.0",
81+
note = "renamed to PKCS_12_PBE_WITH_SHAAND40_BIT_RC2_CBC"
82+
)]
83+
pub const PKCS_12_PBEWITH_SHAAND40_BIT_RC2_CBC: ObjectIdentifier =
84+
PKCS_12_PBE_WITH_SHAAND40_BIT_RC2_CBC;
85+
7586
// bag types
7687
/// `pkcs-12 keyBag` Object Identifier (OID).
7788
pub const PKCS_12_KEY_BAG_OID: ObjectIdentifier =

pkcs12/tests/decrypt_rc2.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,34 @@ fn decrypt_rc2_40_iter2048() {
168168
assert!(!pki.private_key.as_bytes().is_empty());
169169
}
170170

171+
// ── non-BMP password rejection ────────────────────────────────────────────────
172+
173+
/// Password containing a non-BMP character (U+1F525 FIRE, above U+FFFF) must
174+
/// return `Err` from both decrypt methods.
175+
///
176+
/// RFC 7292 §B.1 requires the password to be encoded as BMP (UTF-16BE without
177+
/// surrogate pairs). Code points above U+FFFF are not representable in BMP;
178+
/// `BmpString::from_utf8` rejects them, so both decrypt methods must return
179+
/// `Err` before any KDF work is done.
180+
#[test]
181+
fn decrypt_rc2_128_non_bmp_password_returns_err() {
182+
let epki = find_shrouded_key(include_bytes!("data/test-rc2-128-iter2048.p12"));
183+
assert!(
184+
epki.decrypt_rc2_128_cbc("🔥").is_err(),
185+
"decrypt_rc2_128_cbc must reject a non-BMP password"
186+
);
187+
}
188+
189+
/// RC2-40 variant of the non-BMP password rejection test.
190+
#[test]
191+
fn decrypt_rc2_40_non_bmp_password_returns_err() {
192+
let epki = find_shrouded_key(include_bytes!("data/test-rc2-40-iter2048.p12"));
193+
assert!(
194+
epki.decrypt_rc2_40_cbc("🔥").is_err(),
195+
"decrypt_rc2_40_cbc must reject a non-BMP password"
196+
);
197+
}
198+
171199
// ── RC2-40 error-path tests ────────────────────────────────────────────────────
172200

173201
/// Wrong password for RC2-40.

0 commit comments

Comments
 (0)