crypto: Move the device and user identities under one module.
This commit is contained in:
parent
d86c05efb3
commit
7b3dfe2f27
13 changed files with 80 additions and 29 deletions
|
@ -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},
|
50
matrix_sdk_crypto/src/identities/mod.rs
Normal file
50
matrix_sdk_crypto/src/identities/mod.rs
Normal file
|
@ -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,
|
||||
};
|
|
@ -510,7 +510,7 @@ mod test {
|
|||
};
|
||||
|
||||
use crate::{
|
||||
device::{Device, ReadOnlyDevice},
|
||||
identities::{Device, ReadOnlyDevice},
|
||||
machine::test::response_from_file,
|
||||
olm::Account,
|
||||
store::memorystore::MemoryStore,
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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},
|
||||
};
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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},
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in a new issue