|
| 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 | +} |
0 commit comments