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.
100100Reject an in-progress verification due to mismatched Emoji.
101101.It Sy ":verify request [user id]"
102102Request 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.
103105.El
104106
105107.Sh "MESSAGE COMMANDS"
src/base.rs +11
@@ -598,6 +598,9 @@ pub enum IambAction {
598598 /// Request a new verification with the specified user.
599599 VerifyRequest(String),
600600
601 /// Recover the encryption secrets for this session with the given recovery key.
602 Recover(String),
603
601604 /// Toggle the focus within the focused room.
602605 ToggleScrollbackFocus,
603606
@@ -656,6 +659,7 @@ impl ApplicationAction for IambAction {
656659 IambAction::ToggleScrollbackFocus => SequenceStatus::Break,
657660 IambAction::Verify(..) => SequenceStatus::Break,
658661 IambAction::VerifyRequest(..) => SequenceStatus::Break,
662 IambAction::Recover(..) => SequenceStatus::Break,
659663 }
660664 }
661665
@@ -672,6 +676,7 @@ impl ApplicationAction for IambAction {
672676 IambAction::ToggleScrollbackFocus => SequenceStatus::Atom,
673677 IambAction::Verify(..) => SequenceStatus::Atom,
674678 IambAction::VerifyRequest(..) => SequenceStatus::Atom,
679 IambAction::Recover(..) => SequenceStatus::Atom,
675680 }
676681 }
677682
@@ -688,6 +693,7 @@ impl ApplicationAction for IambAction {
688693 IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore,
689694 IambAction::Verify(..) => SequenceStatus::Ignore,
690695 IambAction::VerifyRequest(..) => SequenceStatus::Ignore,
696 IambAction::Recover(..) => SequenceStatus::Ignore,
691697 }
692698 }
693699
@@ -704,6 +710,7 @@ impl ApplicationAction for IambAction {
704710 IambAction::ToggleScrollbackFocus => false,
705711 IambAction::Verify(..) => false,
706712 IambAction::VerifyRequest(..) => false,
713 IambAction::Recover(..) => false,
707714 }
708715 }
709716}
@@ -861,6 +868,10 @@ pub enum IambError {
861868 #[error("Verification request error: {0}")]
862869 VerificationRequestError(#[from] matrix_sdk::encryption::identities::RequestVerificationError),
863870
871 /// A failure occurred while recovering the encryption secrets.
872 #[error("Recovery error: {0}")]
873 RecoveryError(#[from] matrix_sdk::encryption::recovery::RecoveryError),
874
864875 #[error("Notification setting error: {0}")]
865876 NotificationSettingError(#[from] matrix_sdk::NotificationSettingsError),
866877
src/commands.rs +24
@@ -179,6 +179,19 @@ fn iamb_knock(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
179179fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
180180 let mut args = desc.arg.strings()?;
181181
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
182195 match args.len() {
183196 0 => {
184197 let open = ctx.switch(OpenTarget::Application(IambId::VerifyList));
@@ -1204,6 +1217,17 @@ mod tests {
12041217 let act = IambAction::Verify(VerifyAction::Confirm, "@user4:example.com/GOODDEV".into());
12051218 assert_eq!(res, vec![(act.into(), ctx.clone())]);
12061219
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
12071231 let res = cmds.input_cmd(":verify confirm", ctx.clone());
12081232 assert_eq!(res, Err(CommandError::InvalidArgument));
12091233
src/completions.rs +2
@@ -371,10 +371,12 @@ fn complete_iamb_verify(args: Vec<String>, store: &ChatStore) -> Vec<String> {
371371 "cancel",
372372 "missmatch",
373373 "emoji",
374 "recover",
374375 ];
375376 match args.len() {
376377 1 => complete_choices(&args[0], &subcmds),
377378 2 if args[0] == "request" => complete_users(&args[1], store),
379 2 if args[0] == "recover" => vec![],
378380 2 if subcmds.contains(&args[0].as_str()) => complete_verification(&args[1], store),
379381 _ => vec![],
380382 }
src/main.rs +3
@@ -679,6 +679,9 @@ impl Application {
679679
680680 return verifications::iamb_verify_request(user_id, store).await;
681681 },
682 IambAction::Recover(key) => {
683 return verifications::iamb_recover(key, store).await;
684 },
682685 };
683686
684687 Ok(info)
src/verifications.rs +34
@@ -218,3 +218,37 @@ pub async fn iamb_verify_request(
218218 let info = format!("Sent verification request to {user_id}");
219219 Ok(Some(InfoMessage::from(info)))
220220}
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:
3030- `:verify confirm USERNAME/DEVICE` will confirm a verification
3131- `:verify mismatch USERNAME/DEVICE` will cancel a verification where the Emoji don't match
3232- `:verify cancel USERNAME/DEVICE` will cancel a verification
33- `:verify recover RECOVERYKEY` will recover your encryption secrets and verify this session
3334
3435## Other Useful Commands
3536