Commit 3354fdaa25

3354fdaa259c9a95cdfcb7a41c56050a56c02864

parent: f1c62aeb19

Unregistered key

vaw <git@nlih.de> · 2026-11-21 18:12 UTC

Warn when cryptographic identity of a user is reset

Layout: unified · split

docs/iamb.1 +5
@@ -117,6 +117,11 @@ Confirm an in-progress verification.
117117Reject an in-progress verification due to mismatched Emoji.
118118.It Sy ":verify request [user id]"
119119Request a new verification with the specified user.
120.It Sy ":verify withdraw [user id]"
121Withdraw the verification of the specified user.
122This is necessary when they have reset their cryptographic identity.
123.It Sy ":verify pin [user id]"
124Acknowledge that a user has reset their cryptographic identity.
120125.It Sy ":verify recover [recovery key]"
121126Recover the encryption secrets from the backup on your homeserver, verifying this session.
122127.El
src/base.rs +27 −6
@@ -108,6 +108,19 @@ pub enum VerifyAction {
108108 Emoji,
109109}
110110
111/// An action taken against an ongoing verification request.
112#[derive(Clone, Debug, Eq, PartialEq)]
113pub enum VerifyUserAction {
114 /// Request a new verification with a user.
115 Request,
116
117 /// Withdraw the verification of a user.
118 Withdraw,
119
120 /// Pin the changed identity of a user.
121 Pin,
122}
123
111124/// An action taken against a room's timeline.
112125#[derive(Clone, Debug, Eq, PartialEq)]
113126pub enum TimelineAction {
@@ -748,8 +761,8 @@ pub enum IambAction {
748761 /// Perform an action for an in-progress verification.
749762 Verify(VerifyAction, String),
750763
751 /// Request a new verification with the specified user.
752 VerifyRequest(String),
764 /// Perform a verification action against the specified user.
765 VerifyUser(VerifyUserAction, OwnedUserId),
753766
754767 /// Recover the encryption secrets for this session with the given recovery key.
755768 Recover(String),
@@ -828,7 +841,7 @@ impl ApplicationAction for IambAction {
828841 IambAction::Timeline(..) => SequenceStatus::Break,
829842 IambAction::ToggleScrollbackFocus => SequenceStatus::Break,
830843 IambAction::Verify(..) => SequenceStatus::Break,
831 IambAction::VerifyRequest(..) => SequenceStatus::Break,
844 IambAction::VerifyUser(..) => SequenceStatus::Break,
832845 IambAction::Recover(..) => SequenceStatus::Break,
833846 IambAction::Join(..) => SequenceStatus::Break,
834847 }
@@ -848,7 +861,7 @@ impl ApplicationAction for IambAction {
848861 IambAction::Timeline(..) => SequenceStatus::Atom,
849862 IambAction::ToggleScrollbackFocus => SequenceStatus::Atom,
850863 IambAction::Verify(..) => SequenceStatus::Atom,
851 IambAction::VerifyRequest(..) => SequenceStatus::Atom,
864 IambAction::VerifyUser(..) => SequenceStatus::Atom,
852865 IambAction::Recover(..) => SequenceStatus::Atom,
853866 IambAction::Join(..) => SequenceStatus::Atom,
854867 }
@@ -868,7 +881,7 @@ impl ApplicationAction for IambAction {
868881 IambAction::Timeline(..) => SequenceStatus::Ignore,
869882 IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore,
870883 IambAction::Verify(..) => SequenceStatus::Ignore,
871 IambAction::VerifyRequest(..) => SequenceStatus::Ignore,
884 IambAction::VerifyUser(..) => SequenceStatus::Ignore,
872885 IambAction::Recover(..) => SequenceStatus::Ignore,
873886 IambAction::Join(..) => SequenceStatus::Ignore,
874887 }
@@ -888,7 +901,7 @@ impl ApplicationAction for IambAction {
888901 IambAction::Timeline(..) => false,
889902 IambAction::ToggleScrollbackFocus => false,
890903 IambAction::Verify(..) => false,
891 IambAction::VerifyRequest(..) => false,
904 IambAction::VerifyUser(..) => false,
892905 IambAction::Recover(..) => false,
893906 IambAction::Join(..) => false,
894907 }
@@ -1464,6 +1477,13 @@ pub struct RoomInfo {
14641477 /// filter out values when iterating over it, depending on the use case.
14651478 pub memberships: HashMap<OwnedUserId, MemberSummary>,
14661479
1480 /// List of all users with problematic identity state.
1481 ///
1482 /// This only tracks [`PinViolation`](`IdentityState::PinViolation`) and
1483 /// [`VerificationViolation`](`IdentityState::VerificationViolation`). The normal states don't
1484 /// need to be tracked.
1485 pub identity_violations: BTreeMap<OwnedUserId, IdentityState>,
1486
14671487 /// The last time the room was rendered, used to detect if it is currently open.
14681488 pub draw_last: Option<Instant>,
14691489
@@ -1500,6 +1520,7 @@ impl Default for RoomInfo {
15001520 users_typing: Default::default(),
15011521 display_names: Default::default(),
15021522 memberships: Default::default(),
1523 identity_violations: Default::default(),
15031524 draw_last: Default::default(),
15041525 pinned_events: Default::default(),
15051526 pinned_previews: Default::default(),
src/commands.rs +33 −4
@@ -19,6 +19,7 @@ use crate::base::{
1919 ProgramCommands,
2020 RoomField,
2121 VerifyAction,
22 VerifyUserAction,
2223};
2324use crate::prelude::*;
2425
@@ -247,8 +248,20 @@ fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
247248 "confirm" => VerifyAction::Confirm,
248249 "mismatch" => VerifyAction::Mismatch,
249250 "emoji" => VerifyAction::Emoji,
250 "request" => {
251 let iact = IambAction::VerifyRequest(args.remove(1));
251 "request" | "withdraw" | "pin" => {
252 let user_id = match OwnedUserId::try_from(args.remove(1)) {
253 Ok(user_id) => user_id,
254 Err(err) => return Err(CommandError::ParseFailed(err.to_string())),
255 };
256
257 let act = match args[0].as_str() {
258 "request" => VerifyUserAction::Request,
259 "withdraw" => VerifyUserAction::Withdraw,
260 "pin" => VerifyUserAction::Pin,
261 _ => unreachable!(),
262 };
263
264 let iact = IambAction::VerifyUser(act, user_id);
252265 let step = CommandStep::Continue(iact.into(), ctx.context.clone());
253266
254267 return Ok(step);
@@ -1351,7 +1364,7 @@ pub fn setup_commands(aliases: &Aliases) -> Result<ProgramCommands, CommandError
13511364mod tests {
13521365 use super::*;
13531366
1354 use matrix_sdk::ruma::{owned_room_id, user_id};
1367 use matrix_sdk::ruma::{owned_room_id, owned_user_id, user_id};
13551368 use modalkit::actions::WindowAction;
13561369 use modalkit::editing::context::EditContext;
13571370
@@ -1387,7 +1400,20 @@ mod tests {
13871400 assert_eq!(res, vec![(act.into(), ctx.clone())]);
13881401
13891402 let res = cmds.input_cmd(":verify request @user1:example.com", ctx.clone()).unwrap();
1390 let act = IambAction::VerifyRequest("@user1:example.com".into());
1403 let act =
1404 IambAction::VerifyUser(VerifyUserAction::Request, owned_user_id!("@user1:example.com"));
1405 assert_eq!(res, vec![(act.into(), ctx.clone())]);
1406
1407 let res = cmds.input_cmd(":verify withdraw @user1:example.com", ctx.clone()).unwrap();
1408 let act = IambAction::VerifyUser(
1409 VerifyUserAction::Withdraw,
1410 owned_user_id!("@user1:example.com"),
1411 );
1412 assert_eq!(res, vec![(act.into(), ctx.clone())]);
1413
1414 let res = cmds.input_cmd(":verify pin @user1:example.com", ctx.clone()).unwrap();
1415 let act =
1416 IambAction::VerifyUser(VerifyUserAction::Pin, owned_user_id!("@user1:example.com"));
13911417 assert_eq!(res, vec![(act.into(), ctx.clone())]);
13921418
13931419 let res = cmds
@@ -1433,6 +1459,9 @@ mod tests {
14331459
14341460 let res = cmds.input_cmd(":verify mismatch a b c d e f", ctx.clone());
14351461 assert_eq!(res, Err(CommandError::InvalidArgument));
1462
1463 let res = cmds.input_cmd(":verify request foobar", ctx.clone());
1464 assert!(matches!(res, Err(CommandError::ParseFailed(_))));
14361465 }
14371466
14381467 #[test]
src/completions.rs +4 −1
@@ -362,8 +362,11 @@ fn complete_iamb_keys(
362362
363363/// Tab completion for `:verify`
364364fn complete_iamb_verify(args: Vec<String>, store: &ChatStore) -> Vec<String> {
365 let user_subcmds = ["request", "withdraw", "pin"];
365366 let subcmds = [
366367 "request",
368 "withdraw",
369 "pin",
367370 "accept",
368371 "confirm",
369372 "cancel",
@@ -373,7 +376,7 @@ fn complete_iamb_verify(args: Vec<String>, store: &ChatStore) -> Vec<String> {
373376 ];
374377 match args.len() {
375378 1 => complete_choices(&args[0], &subcmds),
376 2 if args[0] == "request" => complete_users(&args[1], store),
379 2 if user_subcmds.contains(&args[0].as_str()) => complete_users(&args[1], store),
377380 2 if args[0] == "recover" => vec![],
378381 2 if subcmds.contains(&args[0].as_str()) => complete_verification(&args[1], store),
379382 _ => vec![],
src/main.rs +2 −6
@@ -687,12 +687,8 @@ impl Application {
687687 IambAction::Verify(act, flow_id) => {
688688 return verifications::iamb_verify(act, flow_id, store).await;
689689 },
690 IambAction::VerifyRequest(user_id) => {
691 let Ok(user_id) = <&UserId>::try_from(user_id.as_str()) else {
692 return Err(IambError::InvalidUserId(user_id).into());
693 };
694
695 return verifications::iamb_verify_request(user_id, store).await;
690 IambAction::VerifyUser(act, user_id) => {
691 return verifications::iamb_verify_user(act, &user_id, store).await;
696692 },
697693 IambAction::Recover(key) => {
698694 return verifications::iamb_recover(key, store).await;
src/prelude.rs +1
@@ -46,6 +46,7 @@ pub use matrix_sdk::{
4646 encryption::verification::VerificationRequest,
4747 room::Room as MatrixRoom,
4848};
49pub use matrix_sdk_crypto::IdentityState;
4950pub use modalkit::actions::{
5051 Action,
5152 Editable,
src/verifications.rs +25 −8
@@ -2,7 +2,7 @@ use matrix_sdk::encryption::verification::{Verification, VerificationRequestStat
22use matrix_sdk::ruma::OwnedDeviceId;
33use matrix_sdk::ruma::events::key::verification::VerificationMethod;
44
5use crate::base::VerifyAction;
5use crate::base::{VerifyAction, VerifyUserAction};
66use crate::prelude::*;
77
88const SUPPORTED_METHODS: [VerificationMethod; 3] = [
@@ -197,7 +197,8 @@ pub async fn iamb_verify(
197197 }
198198}
199199
200pub async fn iamb_verify_request(
200pub async fn iamb_verify_user(
201 act: VerifyUserAction,
201202 user_id: &UserId,
202203 store: &mut ProgramStore,
203204) -> IambResult<EditInfo> {
@@ -209,14 +210,30 @@ pub async fn iamb_verify_request(
209210 return Err(err);
210211 };
211212
212 let request = identity.request_verification_with_methods(SUPPORTED_METHODS.into());
213 let request = request.await.map_err(IambError::from)?;
213 match act {
214 VerifyUserAction::Request => {
215 let request = identity.request_verification_with_methods(SUPPORTED_METHODS.into());
216 let request = request.await.map_err(IambError::from)?;
217
218 let flow_id = request.flow_id().to_owned();
219 store.application.verifications.insert(flow_id, request);
214220
215 let flow_id = request.flow_id().to_owned();
216 store.application.verifications.insert(flow_id, request);
221 let info = format!("Sent verification request to {user_id}");
222 Ok(Some(InfoMessage::from(info)))
223 },
224 VerifyUserAction::Withdraw => {
225 identity.withdraw_verification().await.map_err(IambError::from)?;
217226
218 let info = format!("Sent verification request to {user_id}");
219 Ok(Some(InfoMessage::from(info)))
227 let info = format!("Withdrawn verification of {user_id}");
228 Ok(Some(InfoMessage::from(info)))
229 },
230 VerifyUserAction::Pin => {
231 identity.pin().await.map_err(IambError::from)?;
232
233 let info = format!("Pinned identity of {user_id}");
234 Ok(Some(InfoMessage::from(info)))
235 },
236 }
220237}
221238
222239pub async fn iamb_recover(key: String, store: &ProgramStore) -> IambResult<EditInfo> {
src/windows/room/chat.rs +42 −8
@@ -1313,11 +1313,14 @@ impl StatefulWidget for Chat<'_> {
13131313 fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
13141314 state.complete_pending_jump(self.store);
13151315
1316 let info = self.store.application.rooms.get_or_default(state.id().to_owned());
13161317 let settings = &self.store.application.settings;
13171318 let theme = &settings.theme;
1319 let mut msgbar_style = theme.msgbar.default;
1320 let mut msgbar_readonly = false;
13181321
13191322 // Determine whether we have a description to show for the message bar.
1320 let desc_spans = match (&state.editing, &state.reply_to, state.thread()) {
1323 let mut desc_spans = match (&state.editing, &state.reply_to, state.thread()) {
13211324 (None, None, None) => {
13221325 if state.room.is_tombstoned() {
13231326 Some(
@@ -1337,26 +1340,51 @@ impl StatefulWidget for Chat<'_> {
13371340 (Some(_), None, None) => Some(Line::from("Editing message")),
13381341 (Some(_), None, Some(_)) => Some(Line::from("Editing message in thread")),
13391342 (editing, Some(_), thread) => {
1340 self.store.application.rooms.get(state.id()).and_then(|room| {
1341 let msg = state.get_reply_to(room)?;
1343 state.get_reply_to(info).map(|msg| {
13421344 let user = self
13431345 .store
13441346 .application
13451347 .settings
1346 .get_user_span(msg.sender.as_ref(), room.display_names.get(&msg.sender));
1348 .get_user_span(msg.sender.as_ref(), info.display_names.get(&msg.sender));
13471349 let prefix = match (editing.is_some(), thread.is_some()) {
13481350 (true, false) => Span::from("Editing reply to "),
13491351 (true, true) => Span::from("Editing reply in thread to "),
13501352 (false, false) => Span::from("Replying to "),
13511353 (false, true) => Span::from("Replying in thread to "),
13521354 };
1353 let spans = Line::from(vec![prefix, user]);
1354
1355 spans.into()
1355 Line::from(vec![prefix, user])
13561356 })
13571357 },
13581358 };
13591359
1360 if desc_spans.is_none() &&
1361 let Some((user_id, _)) = info
1362 .identity_violations
1363 .iter()
1364 .find(|(_, state)| **state == IdentityState::PinViolation)
1365 {
1366 let text1 = Span::from("Cryptographic identity of ");
1367 let user = self
1368 .store
1369 .application
1370 .settings
1371 .get_user_span(user_id, info.display_names.get(user_id));
1372 let text2 =
1373 Span::from(format!(" has changed. Use `:verify pin {user_id}` to acknowledge."));
1374
1375 desc_spans = Some(Line::from(vec![text1, user, text2]));
1376 }
1377
1378 if let Some((user_id, _)) = info
1379 .identity_violations
1380 .iter()
1381 .find(|(_, state)| **state == IdentityState::VerificationViolation)
1382 {
1383 state.tbox.set_text(format!("Cryptographic identity of {user_id} was reset. Use `:verify withdraw {user_id}` to acknowledge"));
1384 msgbar_readonly = true;
1385 msgbar_style = theme.cmdbar.error;
1386 }
1387
13601388 // Determine the region to show each UI element.
13611389 let lines = state.tbox.has_lines(5).max(1) as u16;
13621390 let drawh = area.height;
@@ -1402,11 +1430,17 @@ impl StatefulWidget for Chat<'_> {
14021430 (true, None, None) => Line::from("> "),
14031431 };
14041432
1405 let tbox = TextBox::new().style(theme.msgbar.default).prompt(prompt);
1433 let tbox = TextBox::new().style(msgbar_style).prompt(prompt);
1434 state.tbox.set_readonly(msgbar_readonly);
14061435 state
14071436 .tbox
14081437 .set_ignorecase(self.store.application.settings.tunables.ignorecase);
14091438 tbox.render(textarea, buf, &mut state.tbox);
1439 if msgbar_readonly {
1440 // Clear the msgbar here. If it is still readonly on the next render, the content will
1441 // be overwritten anyway and if not the content would stay.
1442 state.tbox.reset();
1443 }
14101444
14111445 // Render the message scrollback.
14121446 let scrollback_style = self.store.application.settings.theme.timeline.default;
src/worker.rs +49 −16
@@ -641,9 +641,10 @@ fn members_insert(
641641pub(crate) async fn subscribe_room_updates(
642642 room: MatrixRoom,
643643 store: AsyncProgramStore,
644) -> Result<JoinHandle<()>, matrix_sdk::event_cache::EventCacheError> {
644) -> Result<JoinHandle<()>, MatrixError> {
645645 let (cache, drop_handle) = room.client().event_cache().room(room.room_id()).await?;
646646 let (initial_events, mut events_sub) = cache.subscribe().await?;
647 let identity_changes = room.subscribe_to_identity_status_changes().await?;
647648
648649 Ok(tokio::spawn(async move {
649650 let _drop_handle = drop_handle;
@@ -658,24 +659,56 @@ pub(crate) async fn subscribe_room_updates(
658659 insert_msgs_and_receipts(msgs, info, presences, previews, settings);
659660 }
660661
661 while let Ok(update) = events_sub.recv().await {
662 match update {
663 RoomEventCacheUpdate::UpdateTimelineEvents(diffs) => {
664 handle_timeline_update(diffs, &room, &store).await;
665 },
666 RoomEventCacheUpdate::AddReadReceiptEvent { event } => {
667 handle_receipt_update(event, &room, &store).await;
668 },
669 RoomEventCacheUpdate::MoveReadMarkerTo { .. } => {
670 // XXX: Support the fully_read marker
671 },
672 RoomEventCacheUpdate::UpdateMembers { ambiguity_changes, .. } => {
662 futures::pin_mut!(identity_changes);
663 loop {
664 tokio::select! {
665 update = events_sub.recv() => {
666 let Ok(update) = update else {
667 // The sender side has gone away, so just exit the loop.
668 return
669 };
670 match update {
671 RoomEventCacheUpdate::UpdateTimelineEvents(diffs) => {
672 handle_timeline_update(diffs, &room, &store).await;
673 },
674 RoomEventCacheUpdate::AddReadReceiptEvent { event } => {
675 handle_receipt_update(event, &room, &store).await;
676 },
677 RoomEventCacheUpdate::MoveReadMarkerTo { .. } => {
678 // XXX: Support the fully_read marker
679 },
680 RoomEventCacheUpdate::UpdateMembers { ambiguity_changes, .. } => {
681 let mut locked = store.lock().await;
682 let info = locked.application.rooms.get_or_default(room.room_id().to_owned());
683 for (_, change) in ambiguity_changes.into_iter() {
684 info.display_names.apply_ambiguity_change(change);
685 }
686 },
687 }
688 }
689
690 update = identity_changes.next() => {
691 let Some(update) = update else {
692 // The sender side has gone away, so just exit the loop.
693 return
694 };
695
673696 let mut locked = store.lock().await;
674697 let info = locked.application.rooms.get_or_default(room.room_id().to_owned());
675 for (_, change) in ambiguity_changes.into_iter() {
676 info.display_names.apply_ambiguity_change(change);
698
699 for change in update {
700 match change.changed_to {
701 IdentityState::Verified |
702 IdentityState::Pinned => {
703 info.identity_violations.remove(&change.user_id);
704 }
705 IdentityState::PinViolation |
706 IdentityState::VerificationViolation => {
707 info.identity_violations.insert(change.user_id, change.changed_to);
708 }
709 }
677710 }
678 },
711 }
679712 }
680713 }
681714 }))