bump ruma
fixes for key type changes Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
14fce38403
commit
cc86feded3
5 changed files with 402 additions and 119 deletions
|
@ -16,7 +16,7 @@ use ruma::{
|
|||
federation,
|
||||
},
|
||||
serde::Raw,
|
||||
DeviceKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId,
|
||||
OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
|
@ -36,13 +36,12 @@ use crate::{
|
|||
pub(crate) async fn upload_keys_route(
|
||||
State(services): State<crate::State>, body: Ruma<upload_keys::v3::Request>,
|
||||
) -> Result<upload_keys::v3::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||
let (sender_user, sender_device) = body.sender();
|
||||
|
||||
for (key_key, key_value) in &body.one_time_keys {
|
||||
for (key_id, one_time_key) in &body.one_time_keys {
|
||||
services
|
||||
.users
|
||||
.add_one_time_key(sender_user, sender_device, key_key, key_value)
|
||||
.add_one_time_key(sender_user, sender_device, key_id, one_time_key)
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
@ -400,16 +399,16 @@ where
|
|||
|
||||
while let Some((server, response)) = futures.next().await {
|
||||
if let Ok(Ok(response)) = response {
|
||||
for (user, masterkey) in response.master_keys {
|
||||
let (master_key_id, mut master_key) = parse_master_key(&user, &masterkey)?;
|
||||
for (user, master_key) in response.master_keys {
|
||||
let (master_key_id, mut master_key) = parse_master_key(&user, &master_key)?;
|
||||
|
||||
if let Ok(our_master_key) = services
|
||||
.users
|
||||
.get_key(&master_key_id, sender_user, &user, &allowed_signatures)
|
||||
.await
|
||||
{
|
||||
let (_, our_master_key) = parse_master_key(&user, &our_master_key)?;
|
||||
master_key.signatures.extend(our_master_key.signatures);
|
||||
let (_, mut our_master_key) = parse_master_key(&user, &our_master_key)?;
|
||||
master_key.signatures.append(&mut our_master_key.signatures);
|
||||
}
|
||||
let json = serde_json::to_value(master_key).expect("to_value always works");
|
||||
let raw = serde_json::from_value(json).expect("Raw::from_value always works");
|
||||
|
@ -467,7 +466,7 @@ fn add_unsigned_device_display_name(
|
|||
}
|
||||
|
||||
pub(crate) async fn claim_keys_helper(
|
||||
services: &Services, one_time_keys_input: &BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, DeviceKeyAlgorithm>>,
|
||||
services: &Services, one_time_keys_input: &BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, OneTimeKeyAlgorithm>>,
|
||||
) -> Result<claim_keys::v3::Response> {
|
||||
let mut one_time_keys = BTreeMap::new();
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use std::{
|
||||
collections::BTreeMap,
|
||||
mem::take,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
@ -12,7 +11,7 @@ use ruma::{
|
|||
OutgoingResponse,
|
||||
},
|
||||
serde::Raw,
|
||||
MilliSecondsSinceUnixEpoch,
|
||||
MilliSecondsSinceUnixEpoch, Signatures,
|
||||
};
|
||||
|
||||
/// # `GET /_matrix/key/v2/server`
|
||||
|
@ -42,7 +41,7 @@ pub(crate) async fn get_server_keys_route(State(services): State<crate::State>)
|
|||
old_verify_keys,
|
||||
server_name: server_name.to_owned(),
|
||||
valid_until_ts: valid_until_ts(),
|
||||
signatures: BTreeMap::new(),
|
||||
signatures: Signatures::new(),
|
||||
};
|
||||
|
||||
let server_key = Raw::new(&server_key)?;
|
||||
|
|
|
@ -12,8 +12,8 @@ use ruma::{
|
|||
encryption::{CrossSigningKey, DeviceKeys, OneTimeKey},
|
||||
events::{ignored_user_list::IgnoredUserListEvent, AnyToDeviceEvent, GlobalAccountDataEventType},
|
||||
serde::Raw,
|
||||
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedDeviceKeyId,
|
||||
OwnedMxcUri, OwnedUserId, RoomId, UInt, UserId,
|
||||
DeviceId, KeyId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OneTimeKeyId, OneTimeKeyName, OwnedDeviceId,
|
||||
OwnedKeyId, OwnedMxcUri, OwnedUserId, RoomId, UInt, UserId,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
|
@ -341,9 +341,9 @@ impl Service {
|
|||
}
|
||||
|
||||
pub async fn add_one_time_key(
|
||||
&self, user_id: &UserId, device_id: &DeviceId, one_time_key_key: &DeviceKeyId,
|
||||
&self, user_id: &UserId, device_id: &DeviceId, one_time_key_key: &KeyId<OneTimeKeyAlgorithm, OneTimeKeyName>,
|
||||
one_time_key_value: &Raw<OneTimeKey>,
|
||||
) -> Result<()> {
|
||||
) -> Result {
|
||||
// All devices have metadata
|
||||
// Only existing devices should be able to call this, but we shouldn't assert
|
||||
// either...
|
||||
|
@ -388,8 +388,8 @@ impl Service {
|
|||
}
|
||||
|
||||
pub async fn take_one_time_key(
|
||||
&self, user_id: &UserId, device_id: &DeviceId, key_algorithm: &DeviceKeyAlgorithm,
|
||||
) -> Result<(OwnedDeviceKeyId, Raw<OneTimeKey>)> {
|
||||
&self, user_id: &UserId, device_id: &DeviceId, key_algorithm: &OneTimeKeyAlgorithm,
|
||||
) -> Result<(OwnedKeyId<OneTimeKeyAlgorithm, OneTimeKeyName>, Raw<OneTimeKey>)> {
|
||||
let count = self.services.globals.next_count()?.to_be_bytes();
|
||||
self.db.userid_lastonetimekeyupdate.insert(user_id, count);
|
||||
|
||||
|
@ -433,23 +433,23 @@ impl Service {
|
|||
|
||||
pub async fn count_one_time_keys(
|
||||
&self, user_id: &UserId, device_id: &DeviceId,
|
||||
) -> BTreeMap<DeviceKeyAlgorithm, UInt> {
|
||||
) -> BTreeMap<OneTimeKeyAlgorithm, UInt> {
|
||||
type KeyVal<'a> = ((Ignore, Ignore, &'a Unquoted), Ignore);
|
||||
|
||||
let mut algorithm_counts = BTreeMap::<DeviceKeyAlgorithm, UInt>::new();
|
||||
let mut algorithm_counts = BTreeMap::<OneTimeKeyAlgorithm, _>::new();
|
||||
let query = (user_id, device_id);
|
||||
self.db
|
||||
.onetimekeyid_onetimekeys
|
||||
.stream_prefix(&query)
|
||||
.ignore_err()
|
||||
.ready_for_each(|((Ignore, Ignore, device_key_id), Ignore): KeyVal<'_>| {
|
||||
let device_key_id: &DeviceKeyId = device_key_id
|
||||
let one_time_key_id: &OneTimeKeyId = device_key_id
|
||||
.as_str()
|
||||
.try_into()
|
||||
.expect("Invalid DeviceKeyID in database");
|
||||
|
||||
let count: &mut UInt = algorithm_counts
|
||||
.entry(device_key_id.algorithm())
|
||||
.entry(one_time_key_id.algorithm())
|
||||
.or_default();
|
||||
|
||||
*count = count.saturating_add(1_u32.into());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue