-
Notifications
You must be signed in to change notification settings - Fork 74
Description
The key derivation path in dstack/kms/src/main_service.rs feeds a DER-encoded public key into the HKDF info field. Since DER is not a canonical encoding for all key types, semantically identical keys with different DER encodings would derive different secrets.
Root Cause
The derive_dh_secret function computes SHA-256 over the full PKCS#8 DER encoding of a private key, which includes ASN.1 structure metadata (OIDs, sequence wrappers, version numbers) in addition to the raw key material. If a library upgrade changes the DER encoding format (e.g., different ASN.1 version, different optional field inclusion), the hash changes silently, breaking all derived secrets.
// kdf.rs:69-73
let dh_secret = sha2::Sha256::digest(&private_key.to_pkcs8_der()?);Attack Path
- dstack upgrades the
p256orpkcs8crate dependency - The new version produces a slightly different DER encoding (e.g., adds or removes optional fields)
derive_dh_secretproduces a different hash from the same underlying key- All RA-TLS connections using DH-derived keys break silently
- Existing disk encryption keys or other secrets derived from DH secrets become unreachable
Impact
Silent breakage of all DH-derived secrets after a library upgrade. This could cause data loss if disk encryption keys are derived through this path, or communication failures if RA-TLS session keys change unexpectedly.
Suggested Fix
Hash only the raw key bytes instead of the full DER encoding:
let scalar_bytes = private_key.to_bytes();
let dh_secret = sha2::Sha256::digest(&scalar_bytes);SecretKey::to_bytes() returns the raw 32-byte scalar value, which is stable across library upgrades since it represents the mathematical key itself rather than an encoding format.
Note: This issue was created automatically. The vulnerability report was generated by Claude and has not been verified by a human.