Compare commits
No commits in common. "4a6e3687c2bf38d3b68cdfdd4f3d67652694ad70" and "e3e7f0bf447e80d6566866c70736b1e73b473b81" have entirely different histories.
4a6e3687c2
...
e3e7f0bf44
|
@ -1065,11 +1065,9 @@ dependencies = [
|
|||
"keyfork-mnemonic-util",
|
||||
"keyfork-plumbing",
|
||||
"keyfork-shard",
|
||||
"keyforkd",
|
||||
"serde",
|
||||
"smex",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1275,9 +1273,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.151"
|
||||
version = "0.2.147"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
|
||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
|
@ -1367,9 +1365,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.8.10"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09"
|
||||
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
|
@ -2192,9 +2190,9 @@ version = "0.1.0"
|
|||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.5.5"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
|
||||
checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.48.0",
|
||||
|
@ -2373,9 +2371,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.35.1"
|
||||
version = "1.32.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104"
|
||||
checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"bytes",
|
||||
|
@ -2392,9 +2390,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.2.0"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
||||
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{
|
||||
env,
|
||||
io::stdin,
|
||||
io::{stdin, stdout},
|
||||
path::PathBuf,
|
||||
process::ExitCode,
|
||||
};
|
||||
|
@ -40,17 +40,13 @@ fn run() -> Result<()> {
|
|||
.pop_front()
|
||||
.expect("any pgp encrypted message");
|
||||
|
||||
let mut bytes = vec![];
|
||||
|
||||
combine(
|
||||
cert_list,
|
||||
&encrypted_metadata,
|
||||
encrypted_messages.into(),
|
||||
&mut bytes,
|
||||
stdout(),
|
||||
)?;
|
||||
|
||||
print!("{}", smex::encode(&bytes));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -559,7 +559,7 @@ pub fn combine(
|
|||
}
|
||||
|
||||
output
|
||||
.write_all(&secret)
|
||||
.write_all(smex::encode(&secret).as_bytes())
|
||||
.map_err(Error::Io)?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -14,5 +14,3 @@ smex = { version = "0.1.0", path = "../smex" }
|
|||
keyfork-plumbing = { version = "0.1.0", path = "../keyfork-plumbing" }
|
||||
keyfork-shard = { version = "0.1.0", path = "../keyfork-shard" }
|
||||
serde = { version = "1.0.192", features = ["derive"] }
|
||||
keyforkd = { version = "0.1.0", path = "../keyforkd", features = ["tracing"] }
|
||||
tokio = { version = "1.35.1", default-features = false, features = ["rt-multi-thread"] }
|
||||
|
|
|
@ -3,7 +3,6 @@ use clap::{Parser, Subcommand};
|
|||
mod mnemonic;
|
||||
mod provision;
|
||||
mod shard;
|
||||
mod recover;
|
||||
|
||||
/// The Kitchen Sink of Entropy.
|
||||
#[derive(Parser, Clone, Debug)]
|
||||
|
@ -26,8 +25,8 @@ pub enum KeyforkCommands {
|
|||
#[command(subcommand_negates_reqs(true))]
|
||||
Provision(provision::Provision),
|
||||
|
||||
/// Recover a seed using a recovery mechanism and begin the Keyfork daemon.
|
||||
Recover(recover::Recover),
|
||||
/// Keyforkd background daemon to manage derivation.
|
||||
Daemon,
|
||||
}
|
||||
|
||||
impl KeyforkCommands {
|
||||
|
@ -44,8 +43,8 @@ impl KeyforkCommands {
|
|||
KeyforkCommands::Provision(p) => {
|
||||
p.handle(keyfork)?;
|
||||
}
|
||||
KeyforkCommands::Recover(r) => {
|
||||
r.handle(keyfork)?;
|
||||
KeyforkCommands::Daemon => {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
use super::Keyfork;
|
||||
use clap::{builder::PossibleValue, Parser, Subcommand, ValueEnum};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use keyfork_mnemonic_util::Mnemonic;
|
||||
use keyfork_shard::openpgp::{combine, discover_certs, parse_messages};
|
||||
|
||||
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)]
|
||||
pub enum RecoverSubcommands {
|
||||
/// Decrypt a shard file using keys available on the local system.
|
||||
Shard {
|
||||
shard_file: PathBuf,
|
||||
key_discovery: Option<PathBuf>,
|
||||
},
|
||||
|
||||
/// Combine remotely decrypted shards.
|
||||
RemoteShard {},
|
||||
}
|
||||
|
||||
impl RecoverSubcommands {
|
||||
fn handle(&self) -> Result<Vec<u8>> {
|
||||
match self {
|
||||
RecoverSubcommands::Shard {
|
||||
shard_file,
|
||||
key_discovery,
|
||||
} => {
|
||||
let content = std::fs::read_to_string(shard_file)?;
|
||||
if content.contains("BEGIN PGP MESSAGE") {
|
||||
let certs = key_discovery
|
||||
.as_ref()
|
||||
.map(discover_certs)
|
||||
.transpose()?
|
||||
.unwrap_or(vec![]);
|
||||
let mut messages = parse_messages(content.as_bytes())?;
|
||||
let metadata = messages.pop_front().expect("any pgp encrypted message");
|
||||
let mut seed = vec![];
|
||||
combine(certs, &metadata, messages.into(), &mut seed)?;
|
||||
return Ok(seed);
|
||||
}
|
||||
}
|
||||
RecoverSubcommands::RemoteShard {} => todo!(),
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
pub struct Recover {
|
||||
#[command(subcommand)]
|
||||
command: RecoverSubcommands,
|
||||
}
|
||||
|
||||
impl Recover {
|
||||
pub fn handle(&self, _k: &Keyfork) -> Result<()> {
|
||||
let seed = self.command.handle()?;
|
||||
let mnemonic = Mnemonic::from_entropy(&seed, Default::default())?;
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(async {
|
||||
keyforkd::setup_registry();
|
||||
keyforkd::start_and_run_server(mnemonic).await
|
||||
})
|
||||
}
|
||||
}
|
|
@ -86,17 +86,13 @@ impl ShardExec for OpenPGP {
|
|||
.pop_front()
|
||||
.expect("any pgp encrypted message");
|
||||
|
||||
let mut bytes = vec![];
|
||||
|
||||
keyfork_shard::openpgp::combine(
|
||||
certs,
|
||||
&encrypted_metadata,
|
||||
encrypted_messages.into(),
|
||||
&mut bytes,
|
||||
output,
|
||||
)?;
|
||||
|
||||
write!(output, "{}", smex::encode(&bytes))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,14 +9,6 @@ pub use tower::ServiceBuilder;
|
|||
#[cfg(feature = "tracing")]
|
||||
use tracing::debug;
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
use tracing_subscriber::{
|
||||
filter::{EnvFilter, LevelFilter},
|
||||
fmt::{format::FmtSpan, layer},
|
||||
prelude::*,
|
||||
registry,
|
||||
};
|
||||
|
||||
pub mod error;
|
||||
pub mod middleware;
|
||||
pub mod server;
|
||||
|
@ -25,18 +17,6 @@ pub use error::Keyforkd as KeyforkdError;
|
|||
pub use server::UnixServer;
|
||||
pub use service::Keyforkd;
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
pub fn setup_registry() {
|
||||
let envfilter = EnvFilter::builder()
|
||||
.with_default_directive(LevelFilter::DEBUG.into())
|
||||
.from_env_lossy();
|
||||
registry()
|
||||
.with(envfilter)
|
||||
.with(layer().with_span_events(FmtSpan::CLOSE))
|
||||
.with(tracing_error::ErrorLayer::default())
|
||||
.init();
|
||||
}
|
||||
|
||||
pub async fn start_and_run_server_on(
|
||||
mnemonic: Mnemonic,
|
||||
socket_path: &Path,
|
||||
|
|
|
@ -4,6 +4,13 @@ use tokio::io::{self, AsyncBufReadExt, BufReader};
|
|||
|
||||
#[cfg(feature = "tracing")]
|
||||
use tracing::debug;
|
||||
#[cfg(feature = "tracing")]
|
||||
use tracing_subscriber::{
|
||||
filter::{EnvFilter, LevelFilter},
|
||||
fmt::{format::FmtSpan, layer},
|
||||
prelude::*,
|
||||
registry,
|
||||
};
|
||||
|
||||
type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
|
||||
|
||||
|
@ -14,11 +21,23 @@ async fn load_mnemonic() -> Result<Mnemonic> {
|
|||
Ok(line.parse()?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
fn setup_registry() {
|
||||
let envfilter = EnvFilter::builder()
|
||||
.with_default_directive(LevelFilter::DEBUG.into())
|
||||
.from_env_lossy();
|
||||
registry()
|
||||
.with(envfilter)
|
||||
.with(layer().with_span_events(FmtSpan::CLOSE))
|
||||
.with(tracing_error::ErrorLayer::default())
|
||||
.init();
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "multithread", tokio::main)]
|
||||
#[cfg_attr(not(feature = "multithread"), tokio::main(flavor = "current_thread"))]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
#[cfg(feature = "tracing")]
|
||||
keyforkd::setup_registry();
|
||||
setup_registry();
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
debug!("reading mnemonic from standard input");
|
||||
|
|
Loading…
Reference in New Issue