Skip to content

Commit 79afe96

Browse files
committed
WIP
1 parent 6ecefd6 commit 79afe96

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ use vodozemac::{
3838
};
3939

4040
use super::{
41-
BackedUpRoomKey, ExportedRoomKey, OutboundGroupSession, SessionCreationError, SessionKey,
41+
inbound_group_session_sender_data::InboundGroupSessionSenderData, BackedUpRoomKey,
42+
ExportedRoomKey, OutboundGroupSession, SessionCreationError, SessionKey,
4243
};
4344
use crate::{
4445
error::{EventError, MegolmResult},
@@ -123,6 +124,12 @@ pub struct InboundGroupSession {
123124
/// on how the session was received.
124125
pub(crate) creator_info: SessionCreatorInfo,
125126

127+
/// Information about the sender of this session and how much we trust that
128+
/// information. Holds the information we have about the device that created
129+
/// the session, or, if we can use that device information to find the
130+
/// sender's cross-signing identity, holds the user ID and cross-signing key.
131+
pub(crate) sender_data: InboundGroupSessionSenderData,
132+
126133
/// The Room this GroupSession belongs to
127134
pub room_id: OwnedRoomId,
128135

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2022 The Matrix.org Foundation C.I.C.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use std::time::SystemTime;
16+
17+
use ruma::OwnedUserId;
18+
use vodozemac::Ed25519PublicKey;
19+
20+
use crate::types::DeviceKeys;
21+
22+
/// Information on the device and user that sent the megolm session data to us
23+
///
24+
/// Sessions start off in `UnknownDevice` state, and progress into `DeviceInfo`
25+
/// state when we get the device info. Finally, if we can look up the sender
26+
/// using the device info, the session can be moved into `SenderKnown` state.
27+
#[derive(Clone)]
28+
pub(crate) enum InboundGroupSessionSenderData {
29+
/// We have not yet found the (signed) device info for the sending device
30+
UnknownDevice {
31+
// TODO: we may need to handle unsigned and unknown devices separately, which
32+
// probably necessitates a flag here
33+
/// When we will next try again to find device info for this session,
34+
/// and how many times we have tried
35+
retry_details: RetryDetails,
36+
37+
/// Was this session created before we started collecting trust
38+
/// information about sessions? If so, we may choose to display its
39+
/// messages even though trust info is missing.
40+
legacy_session: bool,
41+
},
42+
43+
/// We have the signed device info for the sending device, but not yet the
44+
/// cross-signing key that it was signed with.
45+
DeviceInfo {
46+
/// Information about the device that sent the to-device message creating
47+
/// this session.
48+
device_keys: DeviceKeys,
49+
/// When we will next try again to find a cross-signing key that signed
50+
/// the device information, and how many times we have tried.
51+
retry_details: RetryDetails,
52+
53+
/// Was this session created before we started collecting trust
54+
/// information about sessions? If so, we may choose to display its
55+
/// messages even though trust info is missing.
56+
legacy_session: bool,
57+
},
58+
59+
/// We have found proof that this user, with this cross-signing key, sent
60+
/// the to-device message that established this session.
61+
SenderKnown {
62+
/// The user ID of the user who established this session.
63+
user_id: OwnedUserId,
64+
65+
/// The cross-signing key of the user who established this session.
66+
msk: Ed25519PublicKey,
67+
68+
/// Whether, at the time we checked the signature on the device,
69+
/// we had actively verified that `msk` belongs to the user.
70+
/// If false, we had simply accepted the key as this user's latest
71+
/// key.
72+
msk_verified: bool,
73+
},
74+
}
75+
76+
/// Tracking information about when we need to try again fetching device or
77+
/// user information, and how many times we have already tried.
78+
#[derive(Clone)]
79+
pub(crate) struct RetryDetails {
80+
retry_count: u8,
81+
next_retry_time: SystemTime,
82+
}

crates/matrix-sdk-crypto/src/olm/group_sessions/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use ruma::{DeviceKeyAlgorithm, OwnedRoomId};
1616
use serde::{Deserialize, Serialize};
1717

1818
mod inbound;
19+
mod inbound_group_session_sender_data;
1920
mod outbound;
2021

2122
pub use inbound::{InboundGroupSession, PickledInboundGroupSession};

0 commit comments

Comments
 (0)