keyfork: impl `recover remote-shard`

This commit is contained in:
Ryan Heywood 2024-01-07 00:44:59 -05:00
parent 4a6e3687c2
commit d548276bc3
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
3 changed files with 16 additions and 50 deletions

View File

@ -16,7 +16,9 @@ fn run() -> Result<()> {
_ => panic!("Usage: {program_name}"), _ => panic!("Usage: {program_name}"),
}; };
remote_decrypt()?; let mut bytes = vec![];
remote_decrypt(&mut bytes)?;
print!("{}", smex::encode(&bytes));
Ok(()) Ok(())
} }

View File

@ -1,5 +1,5 @@
use std::{ use std::{
io::{stdin, stdout}, io::{stdin, stdout, Write},
str::FromStr, str::FromStr,
}; };
@ -39,7 +39,7 @@ pub(crate) const HUNK_OFFSET: usize = 2;
/// ///
/// The function may panic if it is given payloads generated using a version of Keyfork that is /// The function may panic if it is given payloads generated using a version of Keyfork that is
/// incompatible with the currently running version. /// incompatible with the currently running version.
pub fn remote_decrypt() -> Result<(), Box<dyn std::error::Error>> { pub fn remote_decrypt(w: &mut impl Write) -> Result<(), Box<dyn std::error::Error>> {
let mut pm = PromptManager::new(stdin(), stdout())?; let mut pm = PromptManager::new(stdin(), stdout())?;
let wordlist = Wordlist::default(); let wordlist = Wordlist::default();
@ -143,7 +143,7 @@ pub fn remote_decrypt() -> Result<(), Box<dyn std::error::Error>> {
} }
*/ */
print!("{}", smex::encode(&secret)); w.write_all(&secret)?;
Ok(()) Ok(())
} }

View File

@ -1,53 +1,12 @@
use super::Keyfork; use super::Keyfork;
use clap::{builder::PossibleValue, Parser, Subcommand, ValueEnum}; use clap::{Parser, Subcommand};
use std::path::PathBuf; use std::path::PathBuf;
use keyfork_mnemonic_util::Mnemonic; use keyfork_mnemonic_util::Mnemonic;
use keyfork_shard::openpgp::{combine, discover_certs, parse_messages}; use keyfork_shard::{remote_decrypt, openpgp::{combine, discover_certs, parse_messages}};
type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>; type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
trait IntoSeed {
fn retrieve_seed(&self) -> Result<Vec<u8>>;
}
#[derive(Clone, Debug)]
pub struct Shard;
impl IntoSeed for Shard {
fn retrieve_seed(&self) -> Result<Vec<u8>> {
todo!()
}
}
#[derive(Clone, Debug)]
pub struct RemoteShard;
impl IntoSeed for RemoteShard {
fn retrieve_seed(&self) -> Result<Vec<u8>> {
todo!()
}
}
#[derive(Clone, Debug)]
pub enum SeedFormat {
Shard(Shard),
RemoteShard(RemoteShard),
}
impl ValueEnum for SeedFormat {
fn value_variants<'a>() -> &'a [Self] {
&[Self::Shard(Shard), Self::RemoteShard(RemoteShard)]
}
fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
Some(match self {
SeedFormat::Shard(_) => PossibleValue::new("shard"),
SeedFormat::RemoteShard(_) => PossibleValue::new("remote-shard"),
})
}
}
#[derive(Subcommand, Clone, Debug)] #[derive(Subcommand, Clone, Debug)]
pub enum RecoverSubcommands { pub enum RecoverSubcommands {
/// Decrypt a shard file using keys available on the local system. /// Decrypt a shard file using keys available on the local system.
@ -78,12 +37,17 @@ impl RecoverSubcommands {
let metadata = messages.pop_front().expect("any pgp encrypted message"); let metadata = messages.pop_front().expect("any pgp encrypted message");
let mut seed = vec![]; let mut seed = vec![];
combine(certs, &metadata, messages.into(), &mut seed)?; combine(certs, &metadata, messages.into(), &mut seed)?;
return Ok(seed); Ok(seed)
} else {
panic!("unknown format of shard file");
} }
} }
RecoverSubcommands::RemoteShard {} => todo!(), RecoverSubcommands::RemoteShard {} => {
let mut seed = vec![];
remote_decrypt(&mut seed)?;
Ok(seed)
},
} }
todo!()
} }
} }