diff --git a/matrix_sdk_crypto/src/identities/device.rs b/matrix_sdk_crypto/src/identities/device.rs index d7bd4463..f9af780d 100644 --- a/matrix_sdk_crypto/src/identities/device.rs +++ b/matrix_sdk_crypto/src/identities/device.rs @@ -438,7 +438,6 @@ impl ReadOnlyDevice { ) } - #[cfg(test)] pub(crate) fn as_device_keys(&self) -> DeviceKeys { DeviceKeys { user_id: self.user_id().clone(), diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index b9773993..3eccab14 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -389,10 +389,9 @@ impl OlmMachine { } else { info!("Trying to upload the existing cross signing identity"); let request = identity.as_upload_request().await; - let device_keys = self.account.unsigned_device_keys(); // TODO remove this expect. let signature_request = identity - .sign_device(device_keys) + .sign_account(&self.account) .await .expect("Can't sign device keys"); Ok((request, signature_request)) diff --git a/matrix_sdk_crypto/src/olm/signing/mod.rs b/matrix_sdk_crypto/src/olm/signing/mod.rs index 97a557a5..a0cf353b 100644 --- a/matrix_sdk_crypto/src/olm/signing/mod.rs +++ b/matrix_sdk_crypto/src/olm/signing/mod.rs @@ -32,7 +32,8 @@ use matrix_sdk_common::{ }; use crate::{ - error::SignatureError, requests::UploadSigningKeysRequest, ReadOnlyAccount, UserIdentity, + error::SignatureError, requests::UploadSigningKeysRequest, ReadOnlyAccount, ReadOnlyDevice, + UserIdentity, }; use pk_signing::{MasterSigning, PickledSignings, SelfSigning, Signing, SigningError, UserSigning}; @@ -118,7 +119,25 @@ impl PrivateCrossSigningIdentity { } /// Sign the given device keys with this identity. + #[allow(dead_code)] pub(crate) async fn sign_device( + &self, + device: &ReadOnlyDevice, + ) -> Result { + let device_keys = device.as_device_keys(); + self.sign_device_keys(device_keys).await + } + + /// Sign an Olm account with this private identity. + pub(crate) async fn sign_account( + &self, + account: &ReadOnlyAccount, + ) -> Result { + let device_keys = account.unsigned_device_keys(); + self.sign_device_keys(device_keys).await + } + + async fn sign_device_keys( &self, mut device_keys: DeviceKeys, ) -> Result { @@ -179,9 +198,8 @@ impl PrivateCrossSigningIdentity { }; let identity = Self::new_helper(account.user_id(), master).await; - let device_keys = account.unsigned_device_keys(); let signature_request = identity - .sign_device(device_keys) + .sign_account(account) .await .expect("Can't sign own device with new cross signign keys");