encryption: Use Signatures for the key types

This commit is contained in:
Kévin Commaille 2024-10-26 16:26:22 +02:00 committed by strawberry
parent eb57bb2797
commit 0d1d549cf6
4 changed files with 22 additions and 18 deletions

View File

@ -39,6 +39,10 @@ Breaking changes:
- `(Owned)DeviceKeyId` is now a type alias of `(Owned)KeyId`.
- Remove the `(owned_)device_key_id` macro, instead use
`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:

View File

@ -8,8 +8,8 @@ use serde::{Deserialize, Serialize};
use crate::{
serde::{Base64, StringEnum},
EventEncryptionAlgorithm, OwnedCrossSigningKeyId, OwnedCrossSigningOrDeviceSigningKeyId,
OwnedDeviceId, OwnedDeviceKeyId, OwnedDeviceSigningKeyId, OwnedUserId, PrivOwnedStr,
CrossSigningOrDeviceSignatures, DeviceSignatures, EventEncryptionAlgorithm,
OwnedCrossSigningKeyId, OwnedDeviceId, OwnedDeviceKeyId, OwnedUserId, PrivOwnedStr,
};
/// Identity keys for a device.
@ -33,7 +33,7 @@ pub struct DeviceKeys {
pub keys: BTreeMap<OwnedDeviceKeyId, String>,
/// 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
/// not covered by the signatures.
@ -49,7 +49,7 @@ impl DeviceKeys {
device_id: OwnedDeviceId,
algorithms: Vec<EventEncryptionAlgorithm>,
keys: BTreeMap<OwnedDeviceKeyId, String>,
signatures: BTreeMap<OwnedUserId, BTreeMap<OwnedCrossSigningOrDeviceSigningKeyId, String>>,
signatures: CrossSigningOrDeviceSignatures,
) -> Self {
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
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
@ -87,7 +84,7 @@ pub struct SignedKey {
pub key: Base64,
/// Signatures for the key object.
pub signatures: SignedKeySignatures,
pub signatures: DeviceSignatures,
/// Is this key considered to be a fallback key, defaults to false.
#[serde(default, skip_serializing_if = "crate::serde::is_default")]
@ -96,12 +93,12 @@ pub struct SignedKey {
impl SignedKey {
/// 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 }
}
/// 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 }
}
}
@ -118,10 +115,6 @@ pub enum OneTimeKey {
Key(String),
}
/// Signatures for a `CrossSigningKey` object.
pub type CrossSigningKeySignatures =
BTreeMap<OwnedUserId, BTreeMap<OwnedCrossSigningOrDeviceSigningKeyId, String>>;
/// A [cross-signing] key.
///
/// [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.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub signatures: CrossSigningKeySignatures,
pub signatures: CrossSigningOrDeviceSignatures,
}
impl CrossSigningKey {
@ -156,7 +149,7 @@ impl CrossSigningKey {
user_id: OwnedUserId,
usage: Vec<KeyUsage>,
keys: BTreeMap<OwnedCrossSigningKeyId, String>,
signatures: CrossSigningKeySignatures,
signatures: CrossSigningOrDeviceSignatures,
) -> Self {
Self { user_id, usage, keys, signatures }
}

View File

@ -42,7 +42,10 @@ pub use self::{
server_name::{OwnedServerName, ServerName},
server_signing_key_version::{OwnedServerSigningKeyVersion, ServerSigningKeyVersion},
session_id::{OwnedSessionId, SessionId},
signatures::{DeviceSignatures, EntitySignatures, ServerSignatures, Signatures},
signatures::{
CrossSigningOrDeviceSignatures, DeviceSignatures, EntitySignatures, ServerSignatures,
Signatures,
},
transaction_id::{OwnedTransactionId, TransactionId},
user_id::{OwnedUserId, UserId},
voip_id::{OwnedVoipId, VoipId},

View File

@ -6,7 +6,8 @@ use std::{
use serde::{Deserialize, Serialize};
use super::{
DeviceId, KeyName, OwnedServerName, OwnedSigningKeyId, OwnedUserId, ServerSigningKeyVersion,
Base64PublicKeyOrDeviceId, DeviceId, KeyName, OwnedServerName, OwnedSigningKeyId, OwnedUserId,
ServerSigningKeyVersion,
};
/// Map of key identifier to signature values.
@ -58,6 +59,9 @@ pub type ServerSignatures = Signatures<OwnedServerName, ServerSigningKeyVersion>
/// Map of device signatures, grouped by user.
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>
where
E: Ord + Clone,