Commit cca24034ed

cca24034ed0c2589727569c354e401833be82b9a

parent: 2641eaa915

Unregistered key

whiteye <62688683+maskjelly@users.noreply.github.com> · 2026-09-16 21:55 UTC
committer: <noreply@github.com>

Add `:verify recover` to verify with a recovery key (#706)

Co-authored-by: vaw <git@nlih.de>

Layout: unified · split

docs/iamb.1 +2
@@ -100,6 +100,8 @@ Confirm an in-progress verification.
100Reject an in-progress verification due to mismatched Emoji. 100Reject an in-progress verification due to mismatched Emoji.
101.It Sy ":verify request [user id]" 101.It Sy ":verify request [user id]"
102Request a new verification with the specified user. 102Request a new verification with the specified user.
103.It Sy ":verify recover [recovery key]"
104Recover the encryption secrets from the backup on your homeserver, verifying this session.
103.El 105.El
104 106
105.Sh "MESSAGE COMMANDS" 107.Sh "MESSAGE COMMANDS"
src/base.rs +11
@@ -598,6 +598,9 @@ pub enum IambAction {
598 /// Request a new verification with the specified user. 598 /// Request a new verification with the specified user.
599 VerifyRequest(String), 599 VerifyRequest(String),
600 600
601 /// Recover the encryption secrets for this session with the given recovery key.
602 Recover(String),
603
601 /// Toggle the focus within the focused room. 604 /// Toggle the focus within the focused room.
602 ToggleScrollbackFocus, 605 ToggleScrollbackFocus,
603 606
@@ -656,6 +659,7 @@ impl ApplicationAction for IambAction {
656 IambAction::ToggleScrollbackFocus => SequenceStatus::Break, 659 IambAction::ToggleScrollbackFocus => SequenceStatus::Break,
657 IambAction::Verify(..) => SequenceStatus::Break, 660 IambAction::Verify(..) => SequenceStatus::Break,
658 IambAction::VerifyRequest(..) => SequenceStatus::Break, 661 IambAction::VerifyRequest(..) => SequenceStatus::Break,
662 IambAction::Recover(..) => SequenceStatus::Break,
659 } 663 }
660 } 664 }
661 665
@@ -672,6 +676,7 @@ impl ApplicationAction for IambAction {
672 IambAction::ToggleScrollbackFocus => SequenceStatus::Atom, 676 IambAction::ToggleScrollbackFocus => SequenceStatus::Atom,
673 IambAction::Verify(..) => SequenceStatus::Atom, 677 IambAction::Verify(..) => SequenceStatus::Atom,
674 IambAction::VerifyRequest(..) => SequenceStatus::Atom, 678 IambAction::VerifyRequest(..) => SequenceStatus::Atom,
679 IambAction::Recover(..) => SequenceStatus::Atom,
675 } 680 }
676 } 681 }
677 682
@@ -688,6 +693,7 @@ impl ApplicationAction for IambAction {
688 IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore, 693 IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore,
689 IambAction::Verify(..) => SequenceStatus::Ignore, 694 IambAction::Verify(..) => SequenceStatus::Ignore,
690 IambAction::VerifyRequest(..) => SequenceStatus::Ignore, 695 IambAction::VerifyRequest(..) => SequenceStatus::Ignore,
696 IambAction::Recover(..) => SequenceStatus::Ignore,
691 } 697 }
692 } 698 }
693 699
@@ -704,6 +710,7 @@ impl ApplicationAction for IambAction {
704 IambAction::ToggleScrollbackFocus => false, 710 IambAction::ToggleScrollbackFocus => false,
705 IambAction::Verify(..) => false, 711 IambAction::Verify(..) => false,
706 IambAction::VerifyRequest(..) => false, 712 IambAction::VerifyRequest(..) => false,
713 IambAction::Recover(..) => false,
707 } 714 }
708 } 715 }
709} 716}
@@ -861,6 +868,10 @@ pub enum IambError {
861 #[error("Verification request error: {0}")] 868 #[error("Verification request error: {0}")]
862 VerificationRequestError(#[from] matrix_sdk::encryption::identities::RequestVerificationError), 869 VerificationRequestError(#[from] matrix_sdk::encryption::identities::RequestVerificationError),
863 870
871 /// A failure occurred while recovering the encryption secrets.
872 #[error("Recovery error: {0}")]
873 RecoveryError(#[from] matrix_sdk::encryption::recovery::RecoveryError),
874
864 #[error("Notification setting error: {0}")] 875 #[error("Notification setting error: {0}")]
865 NotificationSettingError(#[from] matrix_sdk::NotificationSettingsError), 876 NotificationSettingError(#[from] matrix_sdk::NotificationSettingsError),
866 877
src/commands.rs +24
@@ -179,6 +179,19 @@ fn iamb_knock(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
179fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { 179fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
180 let mut args = desc.arg.strings()?; 180 let mut args = desc.arg.strings()?;
181 181
182 // Recovery keys are displayed in space-separated groups, so rejoin any
183 // arguments that follow the subcommand to reconstruct the key.
184 if args.first().is_some_and(|arg| arg == "recover") {
185 if args.len() < 2 {
186 return Result::Err(CommandError::InvalidArgument);
187 }
188
189 let iact = IambAction::Recover(args[1..].join(" "));
190 let step = CommandStep::Continue(iact.into(), ctx.context.clone());
191
192 return Ok(step);
193 }
194
182 match args.len() { 195 match args.len() {
183 0 => { 196 0 => {
184 let open = ctx.switch(OpenTarget::Application(IambId::VerifyList)); 197 let open = ctx.switch(OpenTarget::Application(IambId::VerifyList));
@@ -1204,6 +1217,17 @@ mod tests {
1204 let act = IambAction::Verify(VerifyAction::Confirm, "@user4:example.com/GOODDEV".into()); 1217 let act = IambAction::Verify(VerifyAction::Confirm, "@user4:example.com/GOODDEV".into());
1205 assert_eq!(res, vec![(act.into(), ctx.clone())]); 1218 assert_eq!(res, vec![(act.into(), ctx.clone())]);
1206 1219
1220 let res = cmds.input_cmd(":verify recover", ctx.clone());
1221 assert_eq!(res, Err(CommandError::InvalidArgument));
1222
1223 let res = cmds.input_cmd(":verify recover SOMESINGLEKEY", ctx.clone()).unwrap();
1224 let act = IambAction::Recover("SOMESINGLEKEY".into());
1225 assert_eq!(res, vec![(act.into(), ctx.clone())]);
1226
1227 let res = cmds.input_cmd(":verify recover AAAA BBBB CCCC", ctx.clone()).unwrap();
1228 let act = IambAction::Recover("AAAA BBBB CCCC".into());
1229 assert_eq!(res, vec![(act.into(), ctx.clone())]);
1230
1207 let res = cmds.input_cmd(":verify confirm", ctx.clone()); 1231 let res = cmds.input_cmd(":verify confirm", ctx.clone());
1208 assert_eq!(res, Err(CommandError::InvalidArgument)); 1232 assert_eq!(res, Err(CommandError::InvalidArgument));
1209 1233
src/completions.rs +2
@@ -371,10 +371,12 @@ fn complete_iamb_verify(args: Vec<String>, store: &ChatStore) -> Vec<String> {
371 "cancel", 371 "cancel",
372 "missmatch", 372 "missmatch",
373 "emoji", 373 "emoji",
374 "recover",
374 ]; 375 ];
375 match args.len() { 376 match args.len() {
376 1 => complete_choices(&args[0], &subcmds), 377 1 => complete_choices(&args[0], &subcmds),
377 2 if args[0] == "request" => complete_users(&args[1], store), 378 2 if args[0] == "request" => complete_users(&args[1], store),
379 2 if args[0] == "recover" => vec![],
378 2 if subcmds.contains(&args[0].as_str()) => complete_verification(&args[1], store), 380 2 if subcmds.contains(&args[0].as_str()) => complete_verification(&args[1], store),
379 _ => vec![], 381 _ => vec![],
380 } 382 }
src/main.rs +3
@@ -679,6 +679,9 @@ impl Application {
679 679
680 return verifications::iamb_verify_request(user_id, store).await; 680 return verifications::iamb_verify_request(user_id, store).await;
681 }, 681 },
682 IambAction::Recover(key) => {
683 return verifications::iamb_recover(key, store).await;
684 },
682 }; 685 };
683 686
684 Ok(info) 687 Ok(info)
src/verifications.rs +34
@@ -218,3 +218,37 @@ pub async fn iamb_verify_request(
218 let info = format!("Sent verification request to {user_id}"); 218 let info = format!("Sent verification request to {user_id}");
219 Ok(Some(InfoMessage::from(info))) 219 Ok(Some(InfoMessage::from(info)))
220} 220}
221
222pub async fn iamb_recover(key: String, store: &ProgramStore) -> IambResult<EditInfo> {
223 let client = &store.application.worker.client;
224
225 client
226 .encryption()
227 .recovery()
228 .recover(&key)
229 .await
230 .map_err(IambError::from)?;
231
232 // Recovering imports whatever secrets the account's secret storage holds;
233 // it is the self-signing key that signs this device and marks it verified,
234 // and not every account stores one, so read the result back rather than
235 // assume it.
236 match client.encryption().get_own_device().await {
237 Ok(Some(device)) if device.is_verified_with_cross_signing() => {
238 tracing::info!("recovered encryption secrets; this session is now verified");
239 Ok(Some(InfoMessage::from(
240 "Recovered encryption secrets; this session is now verified",
241 )))
242 },
243 Ok(_) => {
244 tracing::info!("recovered encryption secrets; this session is not cross-signed");
245 Ok(Some(InfoMessage::from(
246 "Recovered encryption secrets, but this session is not verified (no self-signing key in secret storage)",
247 )))
248 },
249 Err(err) => {
250 tracing::warn!("recovered encryption secrets; could not read the device back: {err}");
251 Ok(Some(InfoMessage::from("Recovered encryption secrets")))
252 },
253 }
254}
src/windows/welcome.md +1
@@ -30,6 +30,7 @@ The different subcommands are:
30- `:verify confirm USERNAME/DEVICE` will confirm a verification 30- `:verify confirm USERNAME/DEVICE` will confirm a verification
31- `:verify mismatch USERNAME/DEVICE` will cancel a verification where the Emoji don't match 31- `:verify mismatch USERNAME/DEVICE` will cancel a verification where the Emoji don't match
32- `:verify cancel USERNAME/DEVICE` will cancel a verification 32- `:verify cancel USERNAME/DEVICE` will cancel a verification
33- `:verify recover RECOVERYKEY` will recover your encryption secrets and verify this session
33 34
34## Other Useful Commands 35## Other Useful Commands
35 36