Commit cca24034ed
Unregistered key
Layout: unified · split
docs/iamb.1 +2
| @@ -100,6 +100,8 @@ Confirm an in-progress verification. | ||
| 100 | 100 | Reject an in-progress verification due to mismatched Emoji. |
| 101 | 101 | .It Sy ":verify request [user id]" |
| 102 | 102 | Request a new verification with the specified user. |
| 103 | .It Sy ":verify recover [recovery key]" | |
| 104 | Recover the encryption secrets from the backup on your homeserver, verifying this session. | |
| 103 | 105 | .El |
| 104 | 106 | |
| 105 | 107 | .Sh "MESSAGE COMMANDS" |
src/base.rs +11
| @@ -598,6 +598,9 @@ pub enum IambAction { | ||
| 598 | 598 | /// Request a new verification with the specified user. |
| 599 | 599 | VerifyRequest(String), |
| 600 | 600 | |
| 601 | /// Recover the encryption secrets for this session with the given recovery key. | |
| 602 | Recover(String), | |
| 603 | ||
| 601 | 604 | /// Toggle the focus within the focused room. |
| 602 | 605 | ToggleScrollbackFocus, |
| 603 | 606 | |
| @@ -656,6 +659,7 @@ impl ApplicationAction for IambAction { | ||
| 656 | 659 | IambAction::ToggleScrollbackFocus => SequenceStatus::Break, |
| 657 | 660 | IambAction::Verify(..) => SequenceStatus::Break, |
| 658 | 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 | 676 | IambAction::ToggleScrollbackFocus => SequenceStatus::Atom, |
| 673 | 677 | IambAction::Verify(..) => SequenceStatus::Atom, |
| 674 | 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 | 693 | IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore, |
| 689 | 694 | IambAction::Verify(..) => SequenceStatus::Ignore, |
| 690 | 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 | 710 | IambAction::ToggleScrollbackFocus => false, |
| 705 | 711 | IambAction::Verify(..) => false, |
| 706 | 712 | IambAction::VerifyRequest(..) => false, |
| 713 | IambAction::Recover(..) => false, | |
| 707 | 714 | } |
| 708 | 715 | } |
| 709 | 716 | } |
| @@ -861,6 +868,10 @@ pub enum IambError { | ||
| 861 | 868 | #[error("Verification request error: {0}")] |
| 862 | 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 | 875 | #[error("Notification setting error: {0}")] |
| 865 | 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 { | ||
| 179 | 179 | fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 180 | 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 | 195 | match args.len() { |
| 183 | 196 | 0 => { |
| 184 | 197 | let open = ctx.switch(OpenTarget::Application(IambId::VerifyList)); |
| @@ -1204,6 +1217,17 @@ mod tests { | ||
| 1204 | 1217 | let act = IambAction::Verify(VerifyAction::Confirm, "@user4:example.com/GOODDEV".into()); |
| 1205 | 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 | 1231 | let res = cmds.input_cmd(":verify confirm", ctx.clone()); |
| 1208 | 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 | 371 | "cancel", |
| 372 | 372 | "missmatch", |
| 373 | 373 | "emoji", |
| 374 | "recover", | |
| 374 | 375 | ]; |
| 375 | 376 | match args.len() { |
| 376 | 377 | 1 => complete_choices(&args[0], &subcmds), |
| 377 | 378 | 2 if args[0] == "request" => complete_users(&args[1], store), |
| 379 | 2 if args[0] == "recover" => vec![], | |
| 378 | 380 | 2 if subcmds.contains(&args[0].as_str()) => complete_verification(&args[1], store), |
| 379 | 381 | _ => vec![], |
| 380 | 382 | } |
src/main.rs +3
| @@ -679,6 +679,9 @@ impl Application { | ||
| 679 | 679 | |
| 680 | 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 | 687 | Ok(info) |
src/verifications.rs +34
| @@ -218,3 +218,37 @@ pub async fn iamb_verify_request( | ||
| 218 | 218 | let info = format!("Sent verification request to {user_id}"); |
| 219 | 219 | Ok(Some(InfoMessage::from(info))) |
| 220 | 220 | } |
| 221 | ||
| 222 | pub 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 | 30 | - `:verify confirm USERNAME/DEVICE` will confirm a verification |
| 31 | 31 | - `:verify mismatch USERNAME/DEVICE` will cancel a verification where the Emoji don't match |
| 32 | 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 | 35 | ## Other Useful Commands |
| 35 | 36 | |