From cd310d52d45af5e09af0f5ef1153fdb3f11e7dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 26 Sep 2023 12:52:42 +0200 Subject: [PATCH] Add a convenience method to check if we have all cross-signing keys --- .../matrix-sdk-crypto/src/olm/signing/mod.rs | 7 +++ crates/matrix-sdk/tests/integration/client.rs | 49 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/crates/matrix-sdk-crypto/src/olm/signing/mod.rs b/crates/matrix-sdk-crypto/src/olm/signing/mod.rs index b36130cbd..b5489f007 100644 --- a/crates/matrix-sdk-crypto/src/olm/signing/mod.rs +++ b/crates/matrix-sdk-crypto/src/olm/signing/mod.rs @@ -109,6 +109,13 @@ pub struct CrossSigningStatus { pub has_user_signing: bool, } +impl CrossSigningStatus { + /// Do we have all the cross signing keys locally stored. + pub fn is_complete(&self) -> bool { + self.has_master && self.has_user_signing && self.has_self_signing + } +} + impl PrivateCrossSigningIdentity { /// Get the user id that this identity belongs to. pub fn user_id(&self) -> &UserId { diff --git a/crates/matrix-sdk/tests/integration/client.rs b/crates/matrix-sdk/tests/integration/client.rs index d9bd27298..558c40a29 100644 --- a/crates/matrix-sdk/tests/integration/client.rs +++ b/crates/matrix-sdk/tests/integration/client.rs @@ -526,3 +526,52 @@ async fn get_own_device() { "The device ID of the client and our own device should match" ); } + +#[cfg(feature = "e2e-encryption")] +#[async_test] +async fn cross_signing_status() { + let (client, server) = logged_in_client().await; + + Mock::given(method("POST")) + .and(path("/_matrix/client/unstable/keys/device_signing/upload")) + .respond_with(ResponseTemplate::new(200).set_body_json(json!({}))) + .expect(1) + .mount(&server) + .await; + + Mock::given(method("POST")) + .and(path("/_matrix/client/unstable/keys/signatures/upload")) + .respond_with(ResponseTemplate::new(200).set_body_json(json!({ + "failures": {} + }))) + .mount(&server) + .await; + + let status = client + .encryption() + .cross_signing_status() + .await + .expect("We should be able to fetch our cross-signing status"); + + assert!( + !status.has_master && !status.has_self_signing && !status.has_user_signing, + "Initially we shouldn't have any cross-signing keys" + ); + + client.encryption().bootstrap_cross_signing(None).await.unwrap(); + + client + .encryption() + .cross_signing_status() + .await + .expect("We should be able to fetch our cross-signing status"); + + let status = client + .encryption() + .cross_signing_status() + .await + .expect("We should have the private cross-signing keys after the bootstrap process"); + assert!(status.is_complete(), "We should have all the private cross-signing keys locally"); + + server.verify().await; +}