crypto: Move the device and user identities under one module.

master
Damir Jelić 2020-09-04 10:49:11 +02:00
parent d86c05efb3
commit 7b3dfe2f27
13 changed files with 80 additions and 29 deletions

View File

@ -36,12 +36,12 @@ use serde_json::{json, Value};
use tracing::warn; use tracing::warn;
#[cfg(test)] #[cfg(test)]
use super::{Account, OlmMachine}; use crate::{Account, OlmMachine};
use crate::{ use crate::{
error::{EventError, OlmError, OlmResult, SignatureError}, error::{EventError, OlmError, OlmResult, SignatureError},
identities::{OwnUserIdentity, UserIdentities},
store::Result as StoreResult, store::Result as StoreResult,
user_identity::{OwnUserIdentity, UserIdentities},
verification::VerificationMachine, verification::VerificationMachine,
verify_json, ReadOnlyUserDevices, Sas, verify_json, ReadOnlyUserDevices, Sas,
}; };
@ -444,7 +444,7 @@ pub(crate) mod test {
use serde_json::json; use serde_json::json;
use std::convert::TryFrom; use std::convert::TryFrom;
use crate::device::{LocalTrust, ReadOnlyDevice}; use crate::identities::{LocalTrust, ReadOnlyDevice};
use matrix_sdk_common::{ use matrix_sdk_common::{
encryption::DeviceKeys, encryption::DeviceKeys,
identifiers::{user_id, DeviceKeyAlgorithm}, identifiers::{user_id, DeviceKeyAlgorithm},

View 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,
};

View File

@ -510,7 +510,7 @@ mod test {
}; };
use crate::{ use crate::{
device::{Device, ReadOnlyDevice}, identities::{Device, ReadOnlyDevice},
machine::test::response_from_file, machine::test::response_from_file,
olm::Account, olm::Account,
store::memorystore::MemoryStore, store::memorystore::MemoryStore,

View File

@ -27,19 +27,19 @@
)] )]
#![cfg_attr(feature = "docs", feature(doc_cfg))] #![cfg_attr(feature = "docs", feature(doc_cfg))]
mod device;
mod error; mod error;
mod identities;
mod machine; mod machine;
pub mod memory_stores; pub mod memory_stores;
pub mod olm; pub mod olm;
mod requests; mod requests;
mod store; mod store;
#[allow(dead_code)]
mod user_identity;
mod verification; mod verification;
pub use device::{Device, LocalTrust, ReadOnlyDevice, UserDevices};
pub use error::{MegolmError, OlmError}; pub use error::{MegolmError, OlmError};
pub use identities::{
Device, LocalTrust, OwnUserIdentity, ReadOnlyDevice, UserDevices, UserIdentities, UserIdentity,
};
pub use machine::OlmMachine; pub use machine::OlmMachine;
pub use memory_stores::ReadOnlyUserDevices; pub use memory_stores::ReadOnlyUserDevices;
pub(crate) use olm::Account; pub(crate) use olm::Account;
@ -48,7 +48,6 @@ pub use requests::{IncomingResponse, OutgoingRequest, OutgoingRequests};
#[cfg(feature = "sqlite_cryptostore")] #[cfg(feature = "sqlite_cryptostore")]
pub use store::sqlite::SqliteStore; pub use store::sqlite::SqliteStore;
pub use store::{CryptoStore, CryptoStoreError}; pub use store::{CryptoStore, CryptoStoreError};
pub use user_identity::{OwnUserIdentity, UserIdentities, UserIdentity};
pub use verification::Sas; pub use verification::Sas;
use error::SignatureError; use error::SignatureError;

View File

@ -53,18 +53,17 @@ use matrix_sdk_common::{
#[cfg(feature = "sqlite_cryptostore")] #[cfg(feature = "sqlite_cryptostore")]
use super::store::sqlite::SqliteStore; use super::store::sqlite::SqliteStore;
use super::{ use super::{
device::{Device, ReadOnlyDevice, UserDevices},
error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult}, error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult},
identities::{
Device, MasterPubkey, OwnUserIdentity, ReadOnlyDevice, SelfSigningPubkey, UserDevices,
UserIdentities, UserIdentity, UserSigningPubkey,
},
olm::{ olm::{
Account, EncryptionSettings, GroupSessionKey, IdentityKeys, InboundGroupSession, Account, EncryptionSettings, GroupSessionKey, IdentityKeys, InboundGroupSession,
OlmMessage, OutboundGroupSession, OlmMessage, OutboundGroupSession,
}, },
requests::{IncomingResponse, OutgoingRequest}, requests::{IncomingResponse, OutgoingRequest},
store::{memorystore::MemoryStore, Result as StoreResult}, store::{memorystore::MemoryStore, Result as StoreResult},
user_identity::{
MasterPubkey, OwnUserIdentity, SelfSigningPubkey, UserIdentities, UserIdentity,
UserSigningPubkey,
},
verification::{Sas, VerificationMachine}, verification::{Sas, VerificationMachine},
CryptoStore, CryptoStore,
}; };

View File

@ -26,7 +26,7 @@ use matrix_sdk_common::{
}; };
use super::{ use super::{
device::ReadOnlyDevice, identities::ReadOnlyDevice,
olm::{InboundGroupSession, Session}, olm::{InboundGroupSession, Session},
}; };
@ -208,7 +208,7 @@ impl DeviceStore {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::{ use crate::{
device::test::get_device, identities::device::test::get_device,
memory_stores::{DeviceStore, GroupSessionStore, SessionStore}, memory_stores::{DeviceStore, GroupSessionStore, SessionStore},
olm::{test::get_account_and_session, InboundGroupSession}, olm::{test::get_account_and_session, InboundGroupSession},
}; };

View File

@ -47,7 +47,7 @@ pub use olm_rs::{
}; };
use super::{EncryptionSettings, InboundGroupSession, OutboundGroupSession, Session}; 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. /// Account holding identity keys for which sessions can be created.
/// ///

View File

@ -23,9 +23,8 @@ use matrix_sdk_common_macros::async_trait;
use super::{Account, CryptoStore, InboundGroupSession, Result, Session}; use super::{Account, CryptoStore, InboundGroupSession, Result, Session};
use crate::{ use crate::{
device::ReadOnlyDevice, identities::{ReadOnlyDevice, UserIdentities},
memory_stores::{DeviceStore, GroupSessionStore, ReadOnlyUserDevices, SessionStore}, memory_stores::{DeviceStore, GroupSessionStore, ReadOnlyUserDevices, SessionStore},
user_identity::UserIdentities,
}; };
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct MemoryStore { pub struct MemoryStore {
@ -153,7 +152,7 @@ impl CryptoStore for MemoryStore {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::{ use crate::{
device::test::get_device, identities::device::test::get_device,
olm::{test::get_account_and_session, InboundGroupSession}, olm::{test::get_account_and_session, InboundGroupSession},
store::{memorystore::MemoryStore, CryptoStore}, store::{memorystore::MemoryStore, CryptoStore},
}; };

View File

@ -28,10 +28,9 @@ use thiserror::Error;
use url::ParseError; use url::ParseError;
use super::{ use super::{
device::ReadOnlyDevice, identities::{ReadOnlyDevice, UserIdentities},
memory_stores::ReadOnlyUserDevices, memory_stores::ReadOnlyUserDevices,
olm::{Account, InboundGroupSession, Session}, olm::{Account, InboundGroupSession, Session},
user_identity::UserIdentities,
}; };
use crate::error::SessionUnpicklingError; use crate::error::SessionUnpicklingError;

View File

@ -35,14 +35,13 @@ use zeroize::Zeroizing;
use super::{CryptoStore, CryptoStoreError, Result}; use super::{CryptoStore, CryptoStoreError, Result};
use crate::{ use crate::{
device::{LocalTrust, ReadOnlyDevice}, identities::{LocalTrust, ReadOnlyDevice, UserIdentities},
memory_stores::{DeviceStore, GroupSessionStore, ReadOnlyUserDevices, SessionStore}, memory_stores::{DeviceStore, GroupSessionStore, ReadOnlyUserDevices, SessionStore},
olm::{ olm::{
Account, AccountPickle, IdentityKeys, InboundGroupSession, InboundGroupSessionPickle, Account, AccountPickle, IdentityKeys, InboundGroupSession, InboundGroupSessionPickle,
PickledAccount, PickledInboundGroupSession, PickledSession, PicklingMode, Session, PickledAccount, PickledInboundGroupSession, PickledSession, PicklingMode, Session,
SessionPickle, SessionPickle,
}, },
user_identity::UserIdentities,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -920,7 +919,7 @@ impl std::fmt::Debug for SqliteStore {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::{ use crate::{
device::test::get_device, identities::device::test::get_device,
olm::{Account, GroupSessionKey, InboundGroupSession, Session}, olm::{Account, GroupSessionKey, InboundGroupSession, Session},
}; };
use matrix_sdk_common::{ use matrix_sdk_common::{

View File

@ -30,7 +30,10 @@ use matrix_sdk_common::{
uuid::Uuid, uuid::Uuid,
}; };
use crate::{user_identity::UserIdentities, Account, ReadOnlyDevice}; use crate::{
identities::{ReadOnlyDevice, UserIdentities},
Account,
};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SasIds { pub struct SasIds {

View File

@ -35,8 +35,8 @@ use matrix_sdk_common::{
}; };
use crate::{ use crate::{
user_identity::UserIdentities, Account, CryptoStore, CryptoStoreError, LocalTrust, identities::{LocalTrust, ReadOnlyDevice, UserIdentities},
ReadOnlyDevice, Account, CryptoStore, CryptoStoreError,
}; };
pub use helpers::content_to_request; pub use helpers::content_to_request;

View File

@ -43,7 +43,10 @@ use matrix_sdk_common::{
use super::helpers::{get_decimal, get_emoji, get_mac_content, receive_mac_event, SasIds}; 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] = const KEY_AGREEMENT_PROTOCOLS: &[KeyAgreementProtocol] =
&[KeyAgreementProtocol::Curve25519HkdfSha256]; &[KeyAgreementProtocol::Curve25519HkdfSha256];