Repository navigation
[PM-40815] feat: Support AES-256-CBC-HMAC wrapping keys in SymmetricKeyEnvelope - #1616
Conversation
…eyEnvelope Replace KeyEncryptionKey::is_key_algorithm_valid with get_cose_key_view, which returns the wrapping key as a CoseKeyView when it is an XAES-256-GCM or AES-256-CBC-HMAC key. seal and unseal both get the wrapping key through it and take the algorithm, key bytes and key ID from the view instead of hard-coding XAES-256-GCM. Add AES-256-CBC-HMAC tests and a test vector.
🤖 Bitwarden Claude Code ReviewOverall Assessment: APPROVE This PR lets |
🔍 SDK Breaking Change DetectionSDK Version:
Breaking change detection uses the build of the SDK from this branch, including any incompatibities pre-existing on or merged into this branch. Check the workflow logs to confirm. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1616 +/- ##
==========================================
+ Coverage 87.60% 87.62% +0.01%
==========================================
Files 682 682
Lines 105107 105194 +87
==========================================
+ Hits 92080 92172 +92
+ Misses 13027 13022 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The Android breaking-change failure is already on |
mzieniukbw
left a comment
There was a problem hiding this comment.
I have few concerns about docs and tests and it's placement
| @@ -324,12 +315,21 @@ impl ContentNamespace for SymmetricKeyEnvelopeNamespace {} | |||
| #[cfg(test)] | |||
| mod tests { | |||
There was a problem hiding this comment.
❓ I wonder whether we should rename existing tests that asserts XAes256Gcm to say they test this key type ?
Alternatively (my preference), we would have one test function, for every algorithm, since they are identical compared to existing ones, like so:
fn test_x() {
for sealing_key in [
SymmetricKeyAlgorithm::Aes256CbcHmac,
SymmetricKeyAlgorithm::XAes256Gcm,
] {
...
}
}
Thoughts from @bitwarden/team-key-management-dev ?
There was a problem hiding this comment.
Update: This is discouraged, because of concerns over slow builds due to costly macro generation.
Other idea: Bring rstest dependency:
#[rstest]
#[case::aes256_cbc_hmac(SymmetricKeyAlgorithm::Aes256CbcHmac)]
#[case::xaes256_gcm(SymmetricKeyAlgorithm::XAes256Gcm)]
fn test_wrong_key(#[case] sealing_key: SymmetricKeyAlgorithm) {
(also supports passing the test vectors)
There was a problem hiding this comment.
I think combining tests into such a loop makes sense, and we've done so in the past.
There was a problem hiding this comment.
Done, thanks. The round-trip, key-ID, wrong-key and test-vector tests now loop over both key types with plain for loops. The round trip also loops over the key being sealed (a COSE key and a legacy 64-byte key), since the legacy format had no envelope test. Tests that don't depend on the key type are unchanged. This needed Clone, Copy on SymmetricKeyAlgorithm.
There was a problem hiding this comment.
legacy 64-byte key
It's legacy encoding (format). The symmetric key itself is not legacy.
- Loop the round-trip, key ID, wrong key and test vector tests over both wrapping key types instead of keeping separate AES-256-CBC-HMAC copies. The round trip also covers a COSE key and a legacy 64-byte key as the key being sealed. - Remove the redundant AES-256-CBC-HMAC wrong-namespace and cross-algorithm tests. - Split the missing wrapping key test into separate seal and unseal tests. - Rename the XAES-256-GCM test vector constants, the key-to-seal variable and the key ID test. - Move the AES-256-CBC-HMAC KEK rationale into the KeyEncryptionKey docs. - Derive Clone and Copy for SymmetricKeyAlgorithm.
|
Thanks for the reviews. Pushed |
| @@ -324,12 +315,21 @@ impl ContentNamespace for SymmetricKeyEnvelopeNamespace {} | |||
| #[cfg(test)] | |||
| mod tests { | |||
There was a problem hiding this comment.
legacy 64-byte key
It's legacy encoding (format). The symmetric key itself is not legacy.
…overage - Describe AES-256-CBC-HMAC keys as using the legacy (non-COSE) encoding rather than as legacy keys. - Seal every symmetric key algorithm in the round-trip test, including AES-256-GCM and XAES-256-GCM. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-key-envelope-cbc-hmac-aead
|
@jlf0dev I went ahead and merged this so the blocked PR can be rebased. |
…Support AES-256-CBC-HMAC wrapping keys in SymmetricKeyEnvelope (bitwarden/sdk-internal#1616)
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-40815
📔 Objective
Allow
SymmetricKeyEnvelopeto seal and unseal with an AES-256-CBC-HMAC wrapping key, using theAES-256-CBC-HMAC-SHA256-AEAD COSE construction from #1376. Many keys that act as
key-encryption-keys today, such as V1 user keys and cipher keys, are AES-256-CBC-HMAC keys. This
lets them adopt safe envelopes before they are rotated, as planned in the SAFE adoption RFC.
Changes:
KeyEncryptionKey::is_key_algorithm_valid, which returned abool, is replaced byKeyEncryptionKey::get_cose_key_view. It returns the key as aCoseKeyViewif it is anXAES-256-GCM or AES-256-CBC-HMAC key, and a
KeyEncryptionKeyErrorotherwise.sealandunsealboth get the wrapping key through it, so neither can use a key without the check.Previously
unsealdidn't call the KEK check and relied on its own XAES-onlymatch.sealandunsealtake the algorithm, key bytes and key ID from theCoseKeyViewinstead ofhard-coding XAES-256-GCM.
KeyEncryptionKey::makestill generates only XAES-256-GCM keys. The key hierarchy README nownotes that existing AES-256-CBC-HMAC keys are also accepted as KEKs.
Behavior change
sealwith a missing wrapping key now returnsSymmetricKeyEnvelopeError::KeyMissinginstead ofWrongKeyType, matchingunseal. No code in this repository matches on these variants.Tests
algheader), derived key IDs, wrong key,wrong namespace, and an envelope sealed with one wrapping key algorithm failing to unseal with
the other, in both directions.
test_missing_wrapping_keycovers theKeyMissingbehavior.user key and cipher key case. The existing XAES-256-GCM test vector is unchanged and still
decrypts.
🚨 Breaking Changes
None.
get_cose_key_viewandKeyEncryptionKeyErrorare crate-private, as was the removedis_key_algorithm_valid. The public API ofSymmetricKeyEnvelopeis unchanged.