crypto: Add a method to check the state of our private cross signing keys
parent
1157594530
commit
b540b8df62
|
@ -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,
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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<S>(instant: &Instant, serializer: S) -> Result<S::Ok, S::Error>
|
||||
|
|
|
@ -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<MasterPubkey> {
|
||||
self.master_key.lock().await.as_ref().map(|m| m.public_key.to_owned())
|
||||
|
|
|
@ -78,6 +78,7 @@ use crate::{
|
|||
ReadOnlyAccount, Session,
|
||||
},
|
||||
verification::VerificationMachine,
|
||||
CrossSigningStatus,
|
||||
};
|
||||
|
||||
/// A `CryptoStore` specific result type.
|
||||
|
|
Loading…
Reference in New Issue