Repository navigation
feat(crypto): add legacy compat symmetric key envelope - #1515
Conversation
🔍 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 #1515 +/- ##
==========================================
- Coverage 87.62% 87.61% -0.02%
==========================================
Files 683 684 +1
Lines 105230 105498 +268
==========================================
+ Hits 92208 92431 +223
- Misses 13022 13067 +45 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| /// [EncString::Cose_Encrypt0_B64] carries one; [None] for all other variants, or if the COSE | ||
| /// message is malformed. | ||
| pub fn encrypted_by_key_id(&self) -> Option<KeyId> { | ||
| let EncString::Cose_Encrypt0_B64 { data } = self else { |
There was a problem hiding this comment.
Thought: It's a bit sucky that we have to re-parse the cose struct every time. But I also don't see a way around it, as long as we pass the encstring via FFI, because the FFI parsing MUST not fail.
🤖 Bitwarden Claude Code ReviewOverall Assessment: APPROVE This review covered the new |
|
Moving to draft, waiting for blocking PR to merge. |
cc14288 to
b3896b7
Compare
Replace hand-written wasm_bindgen ABI impls with the shared macro, so malformed strings surface as WireError::Parse and the type can also be returned to JS. The macro formats via ToString, so the String conversion becomes a ToString impl, matching EncString.
seal_legacy still writes an EncString for releases N to N+2, so the types do not only write the new format.
It duplicated the existing EncString::key_id() line for line, leaving two public accessors for the same value.
eligrubb
left a comment
There was a problem hiding this comment.
Glad to see this being added!
… legacy compat symmetric key envelope (bitwarden/sdk-internal#1515)
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-40810
📔 Objective
We want to migrate existing wrapped keys - currently represented as EncString - to SymmetricKeyEnvelope. SymmetricKeyEnvelope is a completely new format, and provides extra metadata: contained key id, encrypted by key id. It also provides the additional security property: Namespace, which prevents attacks based on the isomorphism between certain keys, and thus binds keys to a specific key slot. (For example, a 64 byte name field could previously be mapped to a 64 byte key. 64 byte keys could also be mapped onto one another by the server).
To migrate, we implement the LegacyCompatSymmetricKey. This essentially allows placing symmetrickeyenvelopes in place of encstrings that wrap symmetric keys. First, a client has to add decrypt support. If a symmetrickeyenvelope gets parsed, the namespace is validated, if an encstring comes back, the namespace is ignored. In the second phase, cilents start writing this value. At that point data will be migrated. This MAY be lazy, or MAY be eager.
For new key types, LegacyCompatSymmetricKey should NEVER be used, only old values:
should be replaced.
We will make follow-up tickets to migrate each of these.
There is an example provided for how a key is migrated.
Security Note
This opportunistically enhances the security. If an item is migrated, the server can do a rollback if there is a previously recorded state, or if there is another encstring with an isomorphism (or, encstring encrypted by the same key and parses to 32 or 64 bytes or to a valid cose key).
This MAY be prevented by other means in the future, either by fully dropping support for EncStrings (a breaking change), or by restricting the type in certain slots using other cryptographic means (the account security state).
🚨 Breaking Changes