diff --git a/matrix_sdk_crypto/src/lib.rs b/matrix_sdk_crypto/src/lib.rs index 7f88fb7e..a598ddbe 100644 --- a/matrix_sdk_crypto/src/lib.rs +++ b/matrix_sdk_crypto/src/lib.rs @@ -50,8 +50,8 @@ pub use identities::{ }; pub use machine::OlmMachine; pub use matrix_qrcode; -pub use olm::EncryptionSettings; pub(crate) use olm::ReadOnlyAccount; +pub use olm::{CrossSigningStatus, EncryptionSettings}; pub use requests::{ IncomingResponse, KeysQueryRequest, OutgoingRequest, OutgoingRequests, OutgoingVerificationRequest, RoomMessageRequest, ToDeviceRequest, diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 2cb94211..78780053 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -51,9 +51,9 @@ use crate::{ gossiping::GossipMachine, identities::{user::UserIdentities, Device, IdentityManager, UserDevices}, olm::{ - Account, EncryptionSettings, ExportedRoomKey, GroupSessionKey, IdentityKeys, - InboundGroupSession, OlmDecryptionInfo, PrivateCrossSigningIdentity, ReadOnlyAccount, - SessionType, + Account, CrossSigningStatus, EncryptionSettings, ExportedRoomKey, GroupSessionKey, + IdentityKeys, InboundGroupSession, OlmDecryptionInfo, PrivateCrossSigningIdentity, + ReadOnlyAccount, SessionType, }, requests::{IncomingResponse, OutgoingRequest, UploadSigningKeysRequest}, session_manager::{GroupSessionManager, SessionManager}, @@ -1254,6 +1254,14 @@ impl OlmMachine { Ok(exported) } + + /// Get the status of the private cross signing keys. + /// + /// This can be used to check which private cross signing keys we have + /// stored locally. + pub async fn cross_signing_status(&self) -> CrossSigningStatus { + self.user_identity.lock().await.status().await + } } #[cfg(test)] diff --git a/matrix_sdk_crypto/src/olm/mod.rs b/matrix_sdk_crypto/src/olm/mod.rs index 799f58ff..9814cf06 100644 --- a/matrix_sdk_crypto/src/olm/mod.rs +++ b/matrix_sdk_crypto/src/olm/mod.rs @@ -34,7 +34,7 @@ use matrix_sdk_common::instant::{Duration, Instant}; pub use olm_rs::{account::IdentityKeys, PicklingMode}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; pub use session::{PickledSession, Session, SessionPickle}; -pub use signing::{PickledCrossSigningIdentity, PrivateCrossSigningIdentity}; +pub use signing::{CrossSigningStatus, PickledCrossSigningIdentity, PrivateCrossSigningIdentity}; pub(crate) use utility::Utility; pub(crate) fn serialize_instant(instant: &Instant, serializer: S) -> Result diff --git a/matrix_sdk_crypto/src/olm/signing/mod.rs b/matrix_sdk_crypto/src/olm/signing/mod.rs index abf8c9d8..3850d5c2 100644 --- a/matrix_sdk_crypto/src/olm/signing/mod.rs +++ b/matrix_sdk_crypto/src/olm/signing/mod.rs @@ -70,6 +70,20 @@ pub struct PickledCrossSigningIdentity { pub pickle: String, } +/// Struct representing the state of our private cross signing keys, it shows +/// which private cross signing keys we have locally stored. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CrossSigningStatus { + /// Do we have the master key. + pub has_master: bool, + /// Do we have the self signing key, this one is necessary to sign our own + /// devices. + pub has_self_signing: bool, + /// Do we have the user signing key, this one is necessary to sign other + /// users. + pub has_user_signing: bool, +} + impl PrivateCrossSigningIdentity { /// Get the user id that this identity belongs to. pub fn user_id(&self) -> &UserId { @@ -108,6 +122,16 @@ impl PrivateCrossSigningIdentity { self.master_key.lock().await.is_some() } + /// Get the status of our private cross signing keys, i.e. if we have the + /// master key and the subkeys. + pub async fn status(&self) -> CrossSigningStatus { + CrossSigningStatus { + has_master: self.has_master_key().await, + has_self_signing: self.can_sign_devices().await, + has_user_signing: self.can_sign_users().await, + } + } + /// Get the public part of the master key, if we have one. pub async fn master_public_key(&self) -> Option { self.master_key.lock().await.as_ref().map(|m| m.public_key.to_owned()) diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index 2bd86651..819f1e79 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -78,6 +78,7 @@ use crate::{ ReadOnlyAccount, Session, }, verification::VerificationMachine, + CrossSigningStatus, }; /// A `CryptoStore` specific result type.