diff --git a/matrix_sdk_crypto/src/device.rs b/matrix_sdk_crypto/src/identities/device.rs similarity index 99% rename from matrix_sdk_crypto/src/device.rs rename to matrix_sdk_crypto/src/identities/device.rs index 687401aa..925b7f83 100644 --- a/matrix_sdk_crypto/src/device.rs +++ b/matrix_sdk_crypto/src/identities/device.rs @@ -36,12 +36,12 @@ use serde_json::{json, Value}; use tracing::warn; #[cfg(test)] -use super::{Account, OlmMachine}; +use crate::{Account, OlmMachine}; use crate::{ error::{EventError, OlmError, OlmResult, SignatureError}, + identities::{OwnUserIdentity, UserIdentities}, store::Result as StoreResult, - user_identity::{OwnUserIdentity, UserIdentities}, verification::VerificationMachine, verify_json, ReadOnlyUserDevices, Sas, }; @@ -444,7 +444,7 @@ pub(crate) mod test { use serde_json::json; use std::convert::TryFrom; - use crate::device::{LocalTrust, ReadOnlyDevice}; + use crate::identities::{LocalTrust, ReadOnlyDevice}; use matrix_sdk_common::{ encryption::DeviceKeys, identifiers::{user_id, DeviceKeyAlgorithm}, diff --git a/matrix_sdk_crypto/src/identities/mod.rs b/matrix_sdk_crypto/src/identities/mod.rs new file mode 100644 index 00000000..853447dc --- /dev/null +++ b/matrix_sdk_crypto/src/identities/mod.rs @@ -0,0 +1,50 @@ +// Copyright 2020 The Matrix.org Foundation C.I.C. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Collection of public identities used in Matrix. +//! +//! Matrix supports two main types of identities, a per-device identity and a +//! per-user identity. +//! +//! ## Device +//! +//! Every E2EE capable Matrix client will create a new Olm account and upload +//! the public keys of the Olm account to the server. This is represented as a +//! `ReadOnlyDevice`. +//! +//! Devices can have a local trust state which is needs to be saved in our +//! `CryptoStore`, to avoid reference cycles a wrapper for the `ReadOnlyDevice` +//! exists which adds methods to manipulate the local trust state. +//! +//! ## User +//! +//! Cross-signing capable devices will upload 3 additional (master, self-signing, +//! user-signing) public keys which represent the user identity owning all the +//! devices. This is represented in two ways, as a `UserIdentity` for other +//! users and as `OwnUserIdentity` for our own user. +//! +//! This is done because the server will only give us access to 2 of the 3 +//! additional public keys for other users, while it will give us access to all +//! 3 for our own user. +//! +//! Both identity sets need to reqularly fetched from the server using the +//! `/keys/query` API call. +pub(crate) mod device; +mod user; + +pub use device::{Device, LocalTrust, ReadOnlyDevice, UserDevices}; +pub use user::{ + MasterPubkey, OwnUserIdentity, SelfSigningPubkey, UserIdentities, UserIdentity, + UserSigningPubkey, +}; diff --git a/matrix_sdk_crypto/src/user_identity.rs b/matrix_sdk_crypto/src/identities/user.rs similarity index 99% rename from matrix_sdk_crypto/src/user_identity.rs rename to matrix_sdk_crypto/src/identities/user.rs index 2c15ef09..a1cd66aa 100644 --- a/matrix_sdk_crypto/src/user_identity.rs +++ b/matrix_sdk_crypto/src/identities/user.rs @@ -510,7 +510,7 @@ mod test { }; use crate::{ - device::{Device, ReadOnlyDevice}, + identities::{Device, ReadOnlyDevice}, machine::test::response_from_file, olm::Account, store::memorystore::MemoryStore, diff --git a/matrix_sdk_crypto/src/lib.rs b/matrix_sdk_crypto/src/lib.rs index 451d5f4a..675e5668 100644 --- a/matrix_sdk_crypto/src/lib.rs +++ b/matrix_sdk_crypto/src/lib.rs @@ -27,19 +27,19 @@ )] #![cfg_attr(feature = "docs", feature(doc_cfg))] -mod device; mod error; +mod identities; mod machine; pub mod memory_stores; pub mod olm; mod requests; mod store; -#[allow(dead_code)] -mod user_identity; mod verification; -pub use device::{Device, LocalTrust, ReadOnlyDevice, UserDevices}; pub use error::{MegolmError, OlmError}; +pub use identities::{ + Device, LocalTrust, OwnUserIdentity, ReadOnlyDevice, UserDevices, UserIdentities, UserIdentity, +}; pub use machine::OlmMachine; pub use memory_stores::ReadOnlyUserDevices; pub(crate) use olm::Account; @@ -48,7 +48,6 @@ pub use requests::{IncomingResponse, OutgoingRequest, OutgoingRequests}; #[cfg(feature = "sqlite_cryptostore")] pub use store::sqlite::SqliteStore; pub use store::{CryptoStore, CryptoStoreError}; -pub use user_identity::{OwnUserIdentity, UserIdentities, UserIdentity}; pub use verification::Sas; use error::SignatureError; diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 77fbd492..0d9a8987 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -53,18 +53,17 @@ use matrix_sdk_common::{ #[cfg(feature = "sqlite_cryptostore")] use super::store::sqlite::SqliteStore; use super::{ - device::{Device, ReadOnlyDevice, UserDevices}, error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult}, + identities::{ + Device, MasterPubkey, OwnUserIdentity, ReadOnlyDevice, SelfSigningPubkey, UserDevices, + UserIdentities, UserIdentity, UserSigningPubkey, + }, olm::{ Account, EncryptionSettings, GroupSessionKey, IdentityKeys, InboundGroupSession, OlmMessage, OutboundGroupSession, }, requests::{IncomingResponse, OutgoingRequest}, store::{memorystore::MemoryStore, Result as StoreResult}, - user_identity::{ - MasterPubkey, OwnUserIdentity, SelfSigningPubkey, UserIdentities, UserIdentity, - UserSigningPubkey, - }, verification::{Sas, VerificationMachine}, CryptoStore, }; diff --git a/matrix_sdk_crypto/src/memory_stores.rs b/matrix_sdk_crypto/src/memory_stores.rs index 5fcf71f3..83ee06fb 100644 --- a/matrix_sdk_crypto/src/memory_stores.rs +++ b/matrix_sdk_crypto/src/memory_stores.rs @@ -26,7 +26,7 @@ use matrix_sdk_common::{ }; use super::{ - device::ReadOnlyDevice, + identities::ReadOnlyDevice, olm::{InboundGroupSession, Session}, }; @@ -208,7 +208,7 @@ impl DeviceStore { #[cfg(test)] mod test { use crate::{ - device::test::get_device, + identities::device::test::get_device, memory_stores::{DeviceStore, GroupSessionStore, SessionStore}, olm::{test::get_account_and_session, InboundGroupSession}, }; diff --git a/matrix_sdk_crypto/src/olm/account.rs b/matrix_sdk_crypto/src/olm/account.rs index 0292afdd..e46c7142 100644 --- a/matrix_sdk_crypto/src/olm/account.rs +++ b/matrix_sdk_crypto/src/olm/account.rs @@ -47,7 +47,7 @@ pub use olm_rs::{ }; use super::{EncryptionSettings, InboundGroupSession, OutboundGroupSession, Session}; -use crate::{device::ReadOnlyDevice, error::SessionCreationError}; +use crate::{error::SessionCreationError, identities::ReadOnlyDevice}; /// Account holding identity keys for which sessions can be created. /// diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index 087f720a..d43ee531 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -23,9 +23,8 @@ use matrix_sdk_common_macros::async_trait; use super::{Account, CryptoStore, InboundGroupSession, Result, Session}; use crate::{ - device::ReadOnlyDevice, + identities::{ReadOnlyDevice, UserIdentities}, memory_stores::{DeviceStore, GroupSessionStore, ReadOnlyUserDevices, SessionStore}, - user_identity::UserIdentities, }; #[derive(Debug, Clone)] pub struct MemoryStore { @@ -153,7 +152,7 @@ impl CryptoStore for MemoryStore { #[cfg(test)] mod test { use crate::{ - device::test::get_device, + identities::device::test::get_device, olm::{test::get_account_and_session, InboundGroupSession}, store::{memorystore::MemoryStore, CryptoStore}, }; diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index edd044cb..9fc1dc04 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -28,10 +28,9 @@ use thiserror::Error; use url::ParseError; use super::{ - device::ReadOnlyDevice, + identities::{ReadOnlyDevice, UserIdentities}, memory_stores::ReadOnlyUserDevices, olm::{Account, InboundGroupSession, Session}, - user_identity::UserIdentities, }; use crate::error::SessionUnpicklingError; diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index 4cd905f8..f29a4ce4 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -35,14 +35,13 @@ use zeroize::Zeroizing; use super::{CryptoStore, CryptoStoreError, Result}; use crate::{ - device::{LocalTrust, ReadOnlyDevice}, + identities::{LocalTrust, ReadOnlyDevice, UserIdentities}, memory_stores::{DeviceStore, GroupSessionStore, ReadOnlyUserDevices, SessionStore}, olm::{ Account, AccountPickle, IdentityKeys, InboundGroupSession, InboundGroupSessionPickle, PickledAccount, PickledInboundGroupSession, PickledSession, PicklingMode, Session, SessionPickle, }, - user_identity::UserIdentities, }; #[derive(Clone)] @@ -920,7 +919,7 @@ impl std::fmt::Debug for SqliteStore { #[cfg(test)] mod test { use crate::{ - device::test::get_device, + identities::device::test::get_device, olm::{Account, GroupSessionKey, InboundGroupSession, Session}, }; use matrix_sdk_common::{ diff --git a/matrix_sdk_crypto/src/verification/sas/helpers.rs b/matrix_sdk_crypto/src/verification/sas/helpers.rs index 259248e1..848d37ef 100644 --- a/matrix_sdk_crypto/src/verification/sas/helpers.rs +++ b/matrix_sdk_crypto/src/verification/sas/helpers.rs @@ -30,7 +30,10 @@ use matrix_sdk_common::{ uuid::Uuid, }; -use crate::{user_identity::UserIdentities, Account, ReadOnlyDevice}; +use crate::{ + identities::{ReadOnlyDevice, UserIdentities}, + Account, +}; #[derive(Clone, Debug)] pub struct SasIds { diff --git a/matrix_sdk_crypto/src/verification/sas/mod.rs b/matrix_sdk_crypto/src/verification/sas/mod.rs index 3e4db5e3..dde0f1c6 100644 --- a/matrix_sdk_crypto/src/verification/sas/mod.rs +++ b/matrix_sdk_crypto/src/verification/sas/mod.rs @@ -35,8 +35,8 @@ use matrix_sdk_common::{ }; use crate::{ - user_identity::UserIdentities, Account, CryptoStore, CryptoStoreError, LocalTrust, - ReadOnlyDevice, + identities::{LocalTrust, ReadOnlyDevice, UserIdentities}, + Account, CryptoStore, CryptoStoreError, }; pub use helpers::content_to_request; diff --git a/matrix_sdk_crypto/src/verification/sas/sas_state.rs b/matrix_sdk_crypto/src/verification/sas/sas_state.rs index 85201fa9..8d6ede7f 100644 --- a/matrix_sdk_crypto/src/verification/sas/sas_state.rs +++ b/matrix_sdk_crypto/src/verification/sas/sas_state.rs @@ -43,7 +43,10 @@ use matrix_sdk_common::{ use super::helpers::{get_decimal, get_emoji, get_mac_content, receive_mac_event, SasIds}; -use crate::{user_identity::UserIdentities, Account, ReadOnlyDevice}; +use crate::{ + identities::{ReadOnlyDevice, UserIdentities}, + Account, +}; const KEY_AGREEMENT_PROTOCOLS: &[KeyAgreementProtocol] = &[KeyAgreementProtocol::Curve25519HkdfSha256];