encryption: Use Signatures for the key types
This commit is contained in:
parent
eb57bb2797
commit
0d1d549cf6
@ -39,6 +39,10 @@ Breaking changes:
|
|||||||
- `(Owned)DeviceKeyId` is now a type alias of `(Owned)KeyId`.
|
- `(Owned)DeviceKeyId` is now a type alias of `(Owned)KeyId`.
|
||||||
- Remove the `(owned_)device_key_id` macro, instead use
|
- Remove the `(owned_)device_key_id` macro, instead use
|
||||||
`DeviceKeyId::from_parts`.
|
`DeviceKeyId::from_parts`.
|
||||||
|
- Use `CrossSigningOrDeviceSignatures` for the `signatures` of `DeviceKeys`.
|
||||||
|
- Remove `SignedKeySignatures` and replace it with `DeviceSignatures`.
|
||||||
|
- Remove `CrossSigningKeySignatures` and replace it with
|
||||||
|
`CrossSigningOrDeviceSignatures`.
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
serde::{Base64, StringEnum},
|
serde::{Base64, StringEnum},
|
||||||
EventEncryptionAlgorithm, OwnedCrossSigningKeyId, OwnedCrossSigningOrDeviceSigningKeyId,
|
CrossSigningOrDeviceSignatures, DeviceSignatures, EventEncryptionAlgorithm,
|
||||||
OwnedDeviceId, OwnedDeviceKeyId, OwnedDeviceSigningKeyId, OwnedUserId, PrivOwnedStr,
|
OwnedCrossSigningKeyId, OwnedDeviceId, OwnedDeviceKeyId, OwnedUserId, PrivOwnedStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Identity keys for a device.
|
/// Identity keys for a device.
|
||||||
@ -33,7 +33,7 @@ pub struct DeviceKeys {
|
|||||||
pub keys: BTreeMap<OwnedDeviceKeyId, String>,
|
pub keys: BTreeMap<OwnedDeviceKeyId, String>,
|
||||||
|
|
||||||
/// Signatures for the device key object.
|
/// Signatures for the device key object.
|
||||||
pub signatures: BTreeMap<OwnedUserId, BTreeMap<OwnedCrossSigningOrDeviceSigningKeyId, String>>,
|
pub signatures: CrossSigningOrDeviceSignatures,
|
||||||
|
|
||||||
/// Additional data added to the device key information by intermediate servers, and
|
/// Additional data added to the device key information by intermediate servers, and
|
||||||
/// not covered by the signatures.
|
/// not covered by the signatures.
|
||||||
@ -49,7 +49,7 @@ impl DeviceKeys {
|
|||||||
device_id: OwnedDeviceId,
|
device_id: OwnedDeviceId,
|
||||||
algorithms: Vec<EventEncryptionAlgorithm>,
|
algorithms: Vec<EventEncryptionAlgorithm>,
|
||||||
keys: BTreeMap<OwnedDeviceKeyId, String>,
|
keys: BTreeMap<OwnedDeviceKeyId, String>,
|
||||||
signatures: BTreeMap<OwnedUserId, BTreeMap<OwnedCrossSigningOrDeviceSigningKeyId, String>>,
|
signatures: CrossSigningOrDeviceSignatures,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { user_id, device_id, algorithms, keys, signatures, unsigned: Default::default() }
|
Self { user_id, device_id, algorithms, keys, signatures, unsigned: Default::default() }
|
||||||
}
|
}
|
||||||
@ -76,9 +76,6 @@ impl UnsignedDeviceInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Signatures for a `SignedKey` object.
|
|
||||||
pub type SignedKeySignatures = BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceSigningKeyId, String>>;
|
|
||||||
|
|
||||||
/// A key for the SignedCurve25519 algorithm
|
/// A key for the SignedCurve25519 algorithm
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
@ -87,7 +84,7 @@ pub struct SignedKey {
|
|||||||
pub key: Base64,
|
pub key: Base64,
|
||||||
|
|
||||||
/// Signatures for the key object.
|
/// Signatures for the key object.
|
||||||
pub signatures: SignedKeySignatures,
|
pub signatures: DeviceSignatures,
|
||||||
|
|
||||||
/// Is this key considered to be a fallback key, defaults to false.
|
/// Is this key considered to be a fallback key, defaults to false.
|
||||||
#[serde(default, skip_serializing_if = "crate::serde::is_default")]
|
#[serde(default, skip_serializing_if = "crate::serde::is_default")]
|
||||||
@ -96,12 +93,12 @@ pub struct SignedKey {
|
|||||||
|
|
||||||
impl SignedKey {
|
impl SignedKey {
|
||||||
/// Creates a new `SignedKey` with the given key and signatures.
|
/// Creates a new `SignedKey` with the given key and signatures.
|
||||||
pub fn new(key: Base64, signatures: SignedKeySignatures) -> Self {
|
pub fn new(key: Base64, signatures: DeviceSignatures) -> Self {
|
||||||
Self { key, signatures, fallback: false }
|
Self { key, signatures, fallback: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new fallback `SignedKey` with the given key and signatures.
|
/// Creates a new fallback `SignedKey` with the given key and signatures.
|
||||||
pub fn new_fallback(key: Base64, signatures: SignedKeySignatures) -> Self {
|
pub fn new_fallback(key: Base64, signatures: DeviceSignatures) -> Self {
|
||||||
Self { key, signatures, fallback: true }
|
Self { key, signatures, fallback: true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,10 +115,6 @@ pub enum OneTimeKey {
|
|||||||
Key(String),
|
Key(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Signatures for a `CrossSigningKey` object.
|
|
||||||
pub type CrossSigningKeySignatures =
|
|
||||||
BTreeMap<OwnedUserId, BTreeMap<OwnedCrossSigningOrDeviceSigningKeyId, String>>;
|
|
||||||
|
|
||||||
/// A [cross-signing] key.
|
/// A [cross-signing] key.
|
||||||
///
|
///
|
||||||
/// [cross-signing]: https://spec.matrix.org/latest/client-server-api/#cross-signing
|
/// [cross-signing]: https://spec.matrix.org/latest/client-server-api/#cross-signing
|
||||||
@ -147,7 +140,7 @@ pub struct CrossSigningKey {
|
|||||||
///
|
///
|
||||||
/// Only optional for the master key.
|
/// Only optional for the master key.
|
||||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||||
pub signatures: CrossSigningKeySignatures,
|
pub signatures: CrossSigningOrDeviceSignatures,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CrossSigningKey {
|
impl CrossSigningKey {
|
||||||
@ -156,7 +149,7 @@ impl CrossSigningKey {
|
|||||||
user_id: OwnedUserId,
|
user_id: OwnedUserId,
|
||||||
usage: Vec<KeyUsage>,
|
usage: Vec<KeyUsage>,
|
||||||
keys: BTreeMap<OwnedCrossSigningKeyId, String>,
|
keys: BTreeMap<OwnedCrossSigningKeyId, String>,
|
||||||
signatures: CrossSigningKeySignatures,
|
signatures: CrossSigningOrDeviceSignatures,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { user_id, usage, keys, signatures }
|
Self { user_id, usage, keys, signatures }
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,10 @@ pub use self::{
|
|||||||
server_name::{OwnedServerName, ServerName},
|
server_name::{OwnedServerName, ServerName},
|
||||||
server_signing_key_version::{OwnedServerSigningKeyVersion, ServerSigningKeyVersion},
|
server_signing_key_version::{OwnedServerSigningKeyVersion, ServerSigningKeyVersion},
|
||||||
session_id::{OwnedSessionId, SessionId},
|
session_id::{OwnedSessionId, SessionId},
|
||||||
signatures::{DeviceSignatures, EntitySignatures, ServerSignatures, Signatures},
|
signatures::{
|
||||||
|
CrossSigningOrDeviceSignatures, DeviceSignatures, EntitySignatures, ServerSignatures,
|
||||||
|
Signatures,
|
||||||
|
},
|
||||||
transaction_id::{OwnedTransactionId, TransactionId},
|
transaction_id::{OwnedTransactionId, TransactionId},
|
||||||
user_id::{OwnedUserId, UserId},
|
user_id::{OwnedUserId, UserId},
|
||||||
voip_id::{OwnedVoipId, VoipId},
|
voip_id::{OwnedVoipId, VoipId},
|
||||||
|
@ -6,7 +6,8 @@ use std::{
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
DeviceId, KeyName, OwnedServerName, OwnedSigningKeyId, OwnedUserId, ServerSigningKeyVersion,
|
Base64PublicKeyOrDeviceId, DeviceId, KeyName, OwnedServerName, OwnedSigningKeyId, OwnedUserId,
|
||||||
|
ServerSigningKeyVersion,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Map of key identifier to signature values.
|
/// Map of key identifier to signature values.
|
||||||
@ -58,6 +59,9 @@ pub type ServerSignatures = Signatures<OwnedServerName, ServerSigningKeyVersion>
|
|||||||
/// Map of device signatures, grouped by user.
|
/// Map of device signatures, grouped by user.
|
||||||
pub type DeviceSignatures = Signatures<OwnedUserId, DeviceId>;
|
pub type DeviceSignatures = Signatures<OwnedUserId, DeviceId>;
|
||||||
|
|
||||||
|
/// Map of cross-signing or device signatures, grouped by user.
|
||||||
|
pub type CrossSigningOrDeviceSignatures = Signatures<OwnedUserId, Base64PublicKeyOrDeviceId>;
|
||||||
|
|
||||||
impl<E, K> Clone for Signatures<E, K>
|
impl<E, K> Clone for Signatures<E, K>
|
||||||
where
|
where
|
||||||
E: Ord + Clone,
|
E: Ord + Clone,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user