crypto: Notify our users that a verification timed out on our end

master
Damir Jelić 2021-06-28 16:30:41 +02:00
parent ee6b804804
commit 113587247e
3 changed files with 26 additions and 10 deletions

View File

@ -789,7 +789,7 @@ impl OlmMachine {
one_time_keys_counts: &BTreeMap<DeviceKeyAlgorithm, UInt>, one_time_keys_counts: &BTreeMap<DeviceKeyAlgorithm, UInt>,
) -> OlmResult<ToDevice> { ) -> OlmResult<ToDevice> {
// Remove verification objects that have expired or are done. // Remove verification objects that have expired or are done.
self.verification_machine.garbage_collect(); let mut events = self.verification_machine.garbage_collect();
// Always save the account, a new session might get created which also // Always save the account, a new session might get created which also
// touches the account. // touches the account.
@ -804,8 +804,6 @@ impl OlmMachine {
} }
} }
let mut events = Vec::new();
for mut raw_event in to_device_events.events { for mut raw_event in to_device_events.events {
let event = match raw_event.deserialize() { let event = match raw_event.deserialize() {
Ok(e) => e, Ok(e) => e,

View File

@ -666,7 +666,8 @@ impl From<(RoomId, AnyMessageEventContent)> for OutgoingContent {
} }
#[cfg(test)] #[cfg(test)]
use crate::{OutgoingRequest, OutgoingVerificationRequest, RoomMessageRequest, ToDeviceRequest}; use crate::OutgoingVerificationRequest;
use crate::{OutgoingRequest, RoomMessageRequest, ToDeviceRequest};
#[cfg(test)] #[cfg(test)]
impl From<OutgoingVerificationRequest> for OutgoingContent { impl From<OutgoingVerificationRequest> for OutgoingContent {
@ -678,14 +679,12 @@ impl From<OutgoingVerificationRequest> for OutgoingContent {
} }
} }
#[cfg(test)]
impl From<RoomMessageRequest> for OutgoingContent { impl From<RoomMessageRequest> for OutgoingContent {
fn from(value: RoomMessageRequest) -> Self { fn from(value: RoomMessageRequest) -> Self {
(value.room_id, value.content).into() (value.room_id, value.content).into()
} }
} }
#[cfg(test)]
impl TryFrom<ToDeviceRequest> for OutgoingContent { impl TryFrom<ToDeviceRequest> for OutgoingContent {
type Error = String; type Error = String;
@ -736,7 +735,6 @@ impl TryFrom<ToDeviceRequest> for OutgoingContent {
} }
} }
#[cfg(test)]
impl TryFrom<OutgoingRequest> for OutgoingContent { impl TryFrom<OutgoingRequest> for OutgoingContent {
type Error = String; type Error = String;

View File

@ -12,11 +12,18 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::{convert::TryFrom, sync::Arc}; use std::{
convert::{TryFrom, TryInto},
sync::Arc,
};
use dashmap::DashMap; use dashmap::DashMap;
use matrix_sdk_common::{locks::Mutex, uuid::Uuid}; use matrix_sdk_common::{locks::Mutex, uuid::Uuid};
use ruma::{DeviceId, MilliSecondsSinceUnixEpoch, UserId}; use ruma::{
events::{AnyToDeviceEvent, AnyToDeviceEventContent, ToDeviceEvent},
serde::Raw,
DeviceId, MilliSecondsSinceUnixEpoch, UserId,
};
use tracing::{info, trace, warn}; use tracing::{info, trace, warn};
use super::{ use super::{
@ -165,15 +172,28 @@ impl VerificationMachine {
self.verifications.outgoing_requests() self.verifications.outgoing_requests()
} }
pub fn garbage_collect(&self) { pub fn garbage_collect(&self) -> Vec<Raw<AnyToDeviceEvent>> {
let mut events = vec![];
for user_verification in self.requests.iter() { for user_verification in self.requests.iter() {
user_verification.retain(|_, v| !(v.is_done() || v.is_cancelled())); user_verification.retain(|_, v| !(v.is_done() || v.is_cancelled()));
} }
self.requests.retain(|_, v| !v.is_empty()); self.requests.retain(|_, v| !v.is_empty());
for request in self.verifications.garbage_collect() { for request in self.verifications.garbage_collect() {
if let Ok(OutgoingContent::ToDevice(AnyToDeviceEventContent::KeyVerificationCancel(
content,
))) = request.clone().try_into()
{
let event = ToDeviceEvent { content, sender: self.account.user_id().to_owned() };
events.push(AnyToDeviceEvent::KeyVerificationCancel(event).into());
}
self.verifications.add_request(request) self.verifications.add_request(request)
} }
events
} }
async fn mark_sas_as_done( async fn mark_sas_as_done(