Skip to content

Commit 33b198d

Browse files
committed
fix(crypto): Make sure we remove the unsigned object before signing
1 parent be70d38 commit 33b198d

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

crates/matrix-sdk-crypto/src/olm/signing/pk_signing.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,7 @@ impl SelfSigning {
272272
}
273273

274274
pub async fn sign_device(&self, device_keys: &mut DeviceKeys) -> Result<(), SignatureError> {
275-
// Create a copy of the device keys containing only fields that will
276-
// get signed.
277-
let json_device = json!({
278-
"user_id": device_keys.user_id,
279-
"device_id": device_keys.device_id,
280-
"algorithms": device_keys.algorithms,
281-
"keys": device_keys.keys,
282-
});
283-
284-
let signature = self.sign_device_helper(json_device).await?;
275+
let signature = self.sign_device_helper(serde_json::to_value(&device_keys)?).await?;
285276

286277
device_keys
287278
.signatures
@@ -419,8 +410,11 @@ impl Signing {
419410
pub async fn sign_json(&self, mut json: Value) -> Result<Signature, SignatureError> {
420411
let json_object = json.as_object_mut().ok_or(SignatureError::NotAnObject)?;
421412
let _ = json_object.remove("signatures");
413+
let _ = json_object.remove("unsigned");
414+
422415
let canonical_json: CanonicalJsonValue =
423416
json.try_into().expect("Can't canonicalize the json value");
417+
424418
Ok(self.sign(&canonical_json.to_string()).await)
425419
}
426420

0 commit comments

Comments
 (0)