Skip to content

Commit 55c728f

Browse files
committed
Use fixed test vector for derive_dh_secret stability test
Replace the test that compared against rcgen's live output with a hardcoded test vector. This ensures the test catches encoding regressions even if rcgen changes its PKCS#8 output in future versions.
1 parent a0424b6 commit 55c728f

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

ra-tls/src/kdf.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,33 @@ mod tests {
116116
}
117117

118118
#[test]
119-
fn test_derive_dh_secret_compatible_with_previous_encoding() {
120-
let root_key = KeyPair::generate_for(&PKCS_ECDSA_P256_SHA256).unwrap();
119+
fn test_derive_dh_secret_stable_output() {
120+
// Fixed test vector generated from the original rcgen-based implementation.
121+
// If this test fails after a dependency upgrade, the PKCS#8 encoding has
122+
// changed and deployed secrets would be silently broken.
123+
// Do NOT update the expected value — fix the encoding instead.
124+
let root_der = hex::decode(
125+
"308187020100301306072a8648ce3d020106082a8648ce3d030107046d306b02\
126+
01010420f57527cea4ab7ffb49af99b158cdc0e3ec06398f528349ea236b7d2a\
127+
fe19cec1a1440342000491f50522407ce29dce3ed7d31a15d80c1c42f13a2355\
128+
2d2b33a0ce09ee11e47bce95936f3e7f80d195f879e28e1b144ef37ac9ab8e36\
129+
a690cbf930b775897b27",
130+
)
131+
.unwrap();
132+
let expected_secret = "663afd58820be8ad645f9c035e93199d114ab16f738db62393bc1d7d623e8813";
133+
134+
let root_key = KeyPair::from_der_and_sign_algo(
135+
&PrivateKeyDer::try_from(root_der.as_slice()).unwrap(),
136+
&PKCS_ECDSA_P256_SHA256,
137+
)
138+
.unwrap();
121139
let context = [b"context one".as_ref(), b"context two".as_ref()];
140+
let secret = derive_dh_secret(&root_key, &context).unwrap();
122141

123-
// New implementation under test.
124-
let new_secret = derive_dh_secret(&root_key, &context).unwrap();
125-
126-
// Previous behaviour: derive P-256 key pair with HKDF, then hash PKCS#8 DER.
127-
let old_key_pair = derive_p256_key_pair(&root_key, &context).unwrap();
128-
let old_secret = sha256(old_key_pair.serialized_der());
129-
130-
assert_eq!(new_secret, old_secret);
142+
assert_eq!(
143+
hex::encode(secret),
144+
expected_secret,
145+
"derive_dh_secret output changed — this would break existing deployments"
146+
);
131147
}
132148
}

0 commit comments

Comments
 (0)