federation-api: Improve get_keys
This commit is contained in:
parent
0ea3fee8a0
commit
a238a0dda5
@ -1,9 +1,9 @@
|
|||||||
//! Endpoints for key management
|
//! Endpoints for key management
|
||||||
|
|
||||||
use std::{collections::BTreeMap, fmt::Debug};
|
pub use ruma_common::encryption::{
|
||||||
|
CrossSigningKey, CrossSigningKeySignatures, KeyUsage, OneTimeKey, SignedKey,
|
||||||
use ruma_identifiers::{DeviceKeyId, UserId};
|
SignedKeySignatures,
|
||||||
use serde::{Deserialize, Serialize};
|
};
|
||||||
|
|
||||||
pub mod claim_keys;
|
pub mod claim_keys;
|
||||||
pub mod get_key_changes;
|
pub mod get_key_changes;
|
||||||
@ -16,85 +16,3 @@ pub mod upload_signatures;
|
|||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
pub mod upload_signing_keys;
|
pub mod upload_signing_keys;
|
||||||
|
|
||||||
/// Signatures for a `SignedKey` object.
|
|
||||||
pub type SignedKeySignatures = BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>;
|
|
||||||
|
|
||||||
/// A key for the SignedCurve25519 algorithm
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
|
||||||
pub struct SignedKey {
|
|
||||||
/// Base64-encoded 32-byte Curve25519 public key.
|
|
||||||
pub key: String,
|
|
||||||
|
|
||||||
/// Signatures for the key object.
|
|
||||||
pub signatures: SignedKeySignatures,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SignedKey {
|
|
||||||
/// Creates a new `SignedKey` with the given key and signatures.
|
|
||||||
pub fn new(key: String, signatures: SignedKeySignatures) -> Self {
|
|
||||||
Self { key, signatures }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A one-time public key for "pre-key" messages.
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
|
||||||
#[serde(untagged)]
|
|
||||||
pub enum OneTimeKey {
|
|
||||||
/// A key containing signatures, for the SignedCurve25519 algorithm.
|
|
||||||
SignedKey(SignedKey),
|
|
||||||
|
|
||||||
/// A string-valued key, for the Ed25519 and Curve25519 algorithms.
|
|
||||||
Key(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Signatures for a `CrossSigningKey` object.
|
|
||||||
pub type CrossSigningKeySignatures = BTreeMap<UserId, BTreeMap<String, String>>;
|
|
||||||
|
|
||||||
/// A cross signing key.
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
|
||||||
pub struct CrossSigningKey {
|
|
||||||
/// The ID of the user the key belongs to.
|
|
||||||
pub user_id: UserId,
|
|
||||||
|
|
||||||
/// What the key is used for.
|
|
||||||
pub usage: Vec<KeyUsage>,
|
|
||||||
|
|
||||||
/// The public key. The object must have exactly one property.
|
|
||||||
pub keys: BTreeMap<String, String>,
|
|
||||||
|
|
||||||
/// Signatures of the key. Only optional for master key.
|
|
||||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
|
||||||
pub signatures: CrossSigningKeySignatures,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CrossSigningKey {
|
|
||||||
/// Creates a new `CrossSigningKey` with the given user ID, usage, keys and
|
|
||||||
/// signatures.
|
|
||||||
pub fn new(
|
|
||||||
user_id: UserId,
|
|
||||||
usage: Vec<KeyUsage>,
|
|
||||||
keys: BTreeMap<String, String>,
|
|
||||||
signatures: CrossSigningKeySignatures,
|
|
||||||
) -> Self {
|
|
||||||
Self { user_id, usage, keys, signatures }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The usage of a cross signing key.
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
|
||||||
#[serde(rename_all = "snake_case")]
|
|
||||||
pub enum KeyUsage {
|
|
||||||
/// Master key.
|
|
||||||
Master,
|
|
||||||
|
|
||||||
/// Self-signing key.
|
|
||||||
SelfSigning,
|
|
||||||
|
|
||||||
/// User-signing key.
|
|
||||||
UserSigning,
|
|
||||||
}
|
|
||||||
|
@ -3,11 +3,10 @@
|
|||||||
use std::{collections::BTreeMap, time::Duration};
|
use std::{collections::BTreeMap, time::Duration};
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_common::encryption::OneTimeKey;
|
||||||
use ruma_identifiers::{DeviceIdBox, DeviceKeyAlgorithm, DeviceKeyId, UserId};
|
use ruma_identifiers::{DeviceIdBox, DeviceKeyAlgorithm, DeviceKeyId, UserId};
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
use super::OneTimeKey;
|
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
description: "Claims one-time keys for use in pre-key messages.",
|
description: "Claims one-time keys for use in pre-key messages.",
|
||||||
|
@ -8,7 +8,7 @@ use ruma_identifiers::{DeviceIdBox, UserId};
|
|||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use super::CrossSigningKey;
|
use ruma_common::encryption::CrossSigningKey;
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
|
@ -4,11 +4,9 @@ use std::collections::BTreeMap;
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_common::encryption::DeviceKeys;
|
use ruma_common::encryption::{DeviceKeys, OneTimeKey};
|
||||||
use ruma_identifiers::{DeviceKeyAlgorithm, DeviceKeyId};
|
use ruma_identifiers::{DeviceKeyAlgorithm, DeviceKeyId};
|
||||||
|
|
||||||
use super::OneTimeKey;
|
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
description: "Publishes end-to-end encryption keys for the device.",
|
description: "Publishes end-to-end encryption keys for the device.",
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
//! Defined in [MSC 1756](https://github.com/matrix-org/matrix-doc/blob/master/proposals/1756-cross-signing.md#uploading-signing-keys)
|
//! Defined in [MSC 1756](https://github.com/matrix-org/matrix-doc/blob/master/proposals/1756-cross-signing.md#uploading-signing-keys)
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_common::encryption::CrossSigningKey;
|
||||||
|
|
||||||
use super::CrossSigningKey;
|
|
||||||
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
|
@ -66,3 +66,85 @@ impl UnsignedDeviceInfo {
|
|||||||
self.device_display_name.is_none()
|
self.device_display_name.is_none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Signatures for a `SignedKey` object.
|
||||||
|
pub type SignedKeySignatures = BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>;
|
||||||
|
|
||||||
|
/// A key for the SignedCurve25519 algorithm
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
pub struct SignedKey {
|
||||||
|
/// Base64-encoded 32-byte Curve25519 public key.
|
||||||
|
pub key: String,
|
||||||
|
|
||||||
|
/// Signatures for the key object.
|
||||||
|
pub signatures: SignedKeySignatures,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SignedKey {
|
||||||
|
/// Creates a new `SignedKey` with the given key and signatures.
|
||||||
|
pub fn new(key: String, signatures: SignedKeySignatures) -> Self {
|
||||||
|
Self { key, signatures }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A one-time public key for "pre-key" messages.
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum OneTimeKey {
|
||||||
|
/// A key containing signatures, for the SignedCurve25519 algorithm.
|
||||||
|
SignedKey(SignedKey),
|
||||||
|
|
||||||
|
/// A string-valued key, for the Ed25519 and Curve25519 algorithms.
|
||||||
|
Key(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Signatures for a `CrossSigningKey` object.
|
||||||
|
pub type CrossSigningKeySignatures = BTreeMap<UserId, BTreeMap<String, String>>;
|
||||||
|
|
||||||
|
/// A cross signing key.
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
pub struct CrossSigningKey {
|
||||||
|
/// The ID of the user the key belongs to.
|
||||||
|
pub user_id: UserId,
|
||||||
|
|
||||||
|
/// What the key is used for.
|
||||||
|
pub usage: Vec<KeyUsage>,
|
||||||
|
|
||||||
|
/// The public key. The object must have exactly one property.
|
||||||
|
pub keys: BTreeMap<String, String>,
|
||||||
|
|
||||||
|
/// Signatures of the key. Only optional for master key.
|
||||||
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||||
|
pub signatures: CrossSigningKeySignatures,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CrossSigningKey {
|
||||||
|
/// Creates a new `CrossSigningKey` with the given user ID, usage, keys and
|
||||||
|
/// signatures.
|
||||||
|
pub fn new(
|
||||||
|
user_id: UserId,
|
||||||
|
usage: Vec<KeyUsage>,
|
||||||
|
keys: BTreeMap<String, String>,
|
||||||
|
signatures: CrossSigningKeySignatures,
|
||||||
|
) -> Self {
|
||||||
|
Self { user_id, usage, keys, signatures }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The usage of a cross signing key.
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum KeyUsage {
|
||||||
|
/// Master key.
|
||||||
|
Master,
|
||||||
|
|
||||||
|
/// Self-signing key.
|
||||||
|
SelfSigning,
|
||||||
|
|
||||||
|
/// User-signing key.
|
||||||
|
UserSigning,
|
||||||
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
# [unreleased]
|
# [unreleased]
|
||||||
|
|
||||||
|
Improvements:
|
||||||
|
|
||||||
|
* Add master_keys and self_signing keys to keys::get_keys::v1 response
|
||||||
|
|
||||||
# 0.1.0
|
# 0.1.0
|
||||||
|
|
||||||
Breaking Changes:
|
Breaking Changes:
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
use ruma_common::encryption::CrossSigningKey;
|
||||||
use ruma_common::encryption::DeviceKeys;
|
use ruma_common::encryption::DeviceKeys;
|
||||||
use ruma_identifiers::{DeviceIdBox, UserId};
|
use ruma_identifiers::{DeviceIdBox, UserId};
|
||||||
|
|
||||||
@ -22,9 +24,22 @@ ruma_api! {
|
|||||||
pub device_keys: BTreeMap<UserId, Vec<DeviceIdBox>>,
|
pub device_keys: BTreeMap<UserId, Vec<DeviceIdBox>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
response: {
|
response: {
|
||||||
/// Keys from the queried devices.
|
/// Keys from the queried devices.
|
||||||
pub device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeys>>,
|
pub device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeys>>,
|
||||||
|
|
||||||
|
/// Information on the master cross-signing keys of the queried users.
|
||||||
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||||
|
pub master_keys: BTreeMap<UserId, CrossSigningKey>,
|
||||||
|
|
||||||
|
/// Information on the self-signing keys of the queried users.
|
||||||
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||||
|
pub self_signing_keys: BTreeMap<UserId, CrossSigningKey>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +53,6 @@ impl Request {
|
|||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given device keys.
|
/// Creates a new `Response` with the given device keys.
|
||||||
pub fn new(device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeys>>) -> Self {
|
pub fn new(device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeys>>) -> Self {
|
||||||
Self { device_keys }
|
Self { device_keys, ..Default::default() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user