Compare commits
2 Commits
e3e7f0bf44
...
4a6e3687c2
Author | SHA1 | Date |
---|---|---|
Ryan Heywood | 4a6e3687c2 | |
Ryan Heywood | ac2cb3d8ca |
|
@ -1065,9 +1065,11 @@ dependencies = [
|
|||
"keyfork-mnemonic-util",
|
||||
"keyfork-plumbing",
|
||||
"keyfork-shard",
|
||||
"keyforkd",
|
||||
"serde",
|
||||
"smex",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1273,9 +1275,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.147"
|
||||
version = "0.2.151"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||
checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
|
@ -1365,9 +1367,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.8.8"
|
||||
version = "0.8.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
|
||||
checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
|
@ -2190,9 +2192,9 @@ version = "0.1.0"
|
|||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.5.3"
|
||||
version = "0.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877"
|
||||
checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.48.0",
|
||||
|
@ -2371,9 +2373,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.32.0"
|
||||
version = "1.35.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9"
|
||||
checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"bytes",
|
||||
|
@ -2390,9 +2392,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.1.0"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
|
||||
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{
|
||||
env,
|
||||
io::{stdin, stdout},
|
||||
io::stdin,
|
||||
path::PathBuf,
|
||||
process::ExitCode,
|
||||
};
|
||||
|
@ -40,13 +40,17 @@ fn run() -> Result<()> {
|
|||
.pop_front()
|
||||
.expect("any pgp encrypted message");
|
||||
|
||||
let mut bytes = vec![];
|
||||
|
||||
combine(
|
||||
cert_list,
|
||||
&encrypted_metadata,
|
||||
encrypted_messages.into(),
|
||||
stdout(),
|
||||
&mut bytes,
|
||||
)?;
|
||||
|
||||
print!("{}", smex::encode(&bytes));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -559,7 +559,7 @@ pub fn combine(
|
|||
}
|
||||
|
||||
output
|
||||
.write_all(smex::encode(&secret).as_bytes())
|
||||
.write_all(&secret)
|
||||
.map_err(Error::Io)?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -14,3 +14,5 @@ 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,6 +3,7 @@ use clap::{Parser, Subcommand};
|
|||
mod mnemonic;
|
||||
mod provision;
|
||||
mod shard;
|
||||
mod recover;
|
||||
|
||||
/// The Kitchen Sink of Entropy.
|
||||
#[derive(Parser, Clone, Debug)]
|
||||
|
@ -25,8 +26,8 @@ pub enum KeyforkCommands {
|
|||
#[command(subcommand_negates_reqs(true))]
|
||||
Provision(provision::Provision),
|
||||
|
||||
/// Keyforkd background daemon to manage derivation.
|
||||
Daemon,
|
||||
/// Recover a seed using a recovery mechanism and begin the Keyfork daemon.
|
||||
Recover(recover::Recover),
|
||||
}
|
||||
|
||||
impl KeyforkCommands {
|
||||
|
@ -43,8 +44,8 @@ impl KeyforkCommands {
|
|||
KeyforkCommands::Provision(p) => {
|
||||
p.handle(keyfork)?;
|
||||
}
|
||||
KeyforkCommands::Daemon => {
|
||||
todo!()
|
||||
KeyforkCommands::Recover(r) => {
|
||||
r.handle(keyfork)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
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,13 +86,17 @@ 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(),
|
||||
output,
|
||||
&mut bytes,
|
||||
)?;
|
||||
|
||||
write!(output, "{}", smex::encode(&bytes))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,14 @@ 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;
|
||||
|
@ -17,6 +25,18 @@ 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,13 +4,6 @@ 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>;
|
||||
|
||||
|
@ -21,23 +14,11 @@ 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")]
|
||||
setup_registry();
|
||||
keyforkd::setup_registry();
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
debug!("reading mnemonic from standard input");
|
||||
|
|
Loading…
Reference in New Issue