Skip to content

Commit

Permalink
[CLI] fixup shared recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
AureliaDolo committed Dec 19, 2024
1 parent 8c7c0ee commit 28dfa32
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
23 changes: 11 additions & 12 deletions cli/src/commands/invite/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::{path::PathBuf, sync::Arc};

use anyhow::anyhow;
use libparsec::{
internal::{
claimer_retrieve_info, AnyClaimRetrievedInfoCtx, DeviceClaimFinalizeCtx,
Expand All @@ -20,7 +21,7 @@ use libparsec_client::{
};

use crate::utils::*;
use dialoguer::Select;
use dialoguer::{Input, Select};

crate::clap_parser_with_shared_opts_builder!(
#[with = config_dir, data_dir, password_stdin]
Expand Down Expand Up @@ -246,18 +247,17 @@ async fn step2_device(ctx: DeviceClaimInProgress1Ctx) -> anyhow::Result<DeviceCl
async fn step2_shamir(
ctx: ShamirRecoveryClaimInProgress1Ctx,
) -> anyhow::Result<ShamirRecoveryClaimInProgress2Ctx> {
let mut input = String::new();
let sas_codes = ctx.generate_greeter_sas_choices(3);

for (i, sas_code) in sas_codes.iter().enumerate() {
println!(" {i} - {YELLOW}{sas_code}{RESET}")
let selected_sas = Select::new()
.items(&sas_codes)
.with_prompt("Select code provided by greeter")
.interact()?;
if &sas_codes[selected_sas] != ctx.greeter_sas() {
Err(anyhow!("Invalid SAS code"))
} else {
Ok(ctx.do_signify_trust().await?)
}

println!("Select code provided by greeter (0, 1, 2)");

choose_sas_code(&mut input, &sas_codes, ctx.greeter_sas())?;

Ok(ctx.do_signify_trust().await?)
}

/// Step 3: wait peer trust
Expand Down Expand Up @@ -356,8 +356,7 @@ async fn step4_shamir(
async fn step5_shamir(
ctx: ShamirRecoveryClaimRecoverDeviceCtx,
) -> anyhow::Result<ShamirRecoveryClaimMaybeFinalizeCtx> {
let mut input = String::new();
let device_label = choose_device_label(&mut input)?;
let device_label = Input::new().with_prompt("Enter device label").interact()?;

let mut handle = start_spinner("Waiting for greeter".into());

Expand Down
19 changes: 10 additions & 9 deletions cli/src/commands/invite/greet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS

use anyhow::Context;
use dialoguer::Select;
use libparsec::{
authenticated_cmds::latest::invite_list::InviteListItem,
internal::{
Expand Down Expand Up @@ -83,6 +84,7 @@ async fn step0(
let invitation = match invitations.into_iter().find(|invitation| match invitation {
InviteListItem::User { token, .. } if *token == invitation_token => true,
InviteListItem::Device { token, .. } if *token == invitation_token => true,
InviteListItem::ShamirRecovery { token, .. } if *token == invitation_token => true,
_ => false,
}) {
Some(invitation) => invitation,
Expand Down Expand Up @@ -213,17 +215,16 @@ async fn step3_device(ctx: DeviceGreetInProgress2Ctx) -> anyhow::Result<DeviceGr
async fn step3_shamir(
ctx: ShamirRecoveryGreetInProgress2Ctx,
) -> anyhow::Result<ShamirRecoveryGreetInProgress3Ctx> {
let mut input = String::new();
let sas_codes = ctx.generate_claimer_sas_choices(3);
for (i, sas_code) in sas_codes.iter().enumerate() {
println!(" {i} - {YELLOW}{sas_code}{RESET}")
let selected_sas = Select::new()
.items(&sas_codes)
.with_prompt("Select code provided by claimer")
.interact()?;
if &sas_codes[selected_sas] != ctx.claimer_sas() {
Err(anyhow::anyhow!("Invalid SAS code"))
} else {
Ok(ctx.do_signify_trust().await?)
}

println!("Select code provided by claimer (0, 1, 2)");

choose_sas_code(&mut input, &sas_codes, ctx.claimer_sas())?;

Ok(ctx.do_signify_trust().await?)
}

/// Step 4: get claim requests
Expand Down

0 comments on commit 28dfa32

Please sign in to comment.