Compare commits

..

3 Commits

Author SHA1 Message Date
Ryan Heywood 98baaed81c
cargo fmt 2023-08-25 04:28:47 -05:00
Ryan Heywood da96ea94bd
keyforkd: extract DerivablePath 2023-08-25 04:27:16 -05:00
Ryan Heywood a9209ee36a
keyforkd: swap minicbor for serde + bincode 2023-08-25 02:47:54 -05:00
9 changed files with 96 additions and 76 deletions

77
Cargo.lock generated
View File

@ -41,6 +41,15 @@ dependencies = [
"rustc-demangle",
]
[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde",
]
[[package]]
name = "bip39"
version = "2.0.0"
@ -244,6 +253,13 @@ version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]]
name = "keyfork-derive-util"
version = "0.1.0"
dependencies = [
"serde",
]
[[package]]
name = "keyfork-frame"
version = "0.1.0"
@ -276,10 +292,12 @@ dependencies = [
name = "keyforkd"
version = "0.1.0"
dependencies = [
"bincode",
"dirs",
"keyfork-derive-util",
"keyfork-frame",
"keyfork-mnemonic-util",
"minicbor",
"serde",
"thiserror",
"tokio",
"tower",
@ -327,26 +345,6 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "minicbor"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7005aaf257a59ff4de471a9d5538ec868a21586534fff7f85dd97d4043a6139"
dependencies = [
"minicbor-derive",
]
[[package]]
name = "minicbor-derive"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1154809406efdb7982841adb6311b3d095b46f78342dd646736122fe6b19e267"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "miniz_oxide"
version = "0.7.1"
@ -431,7 +429,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.29",
"syn",
]
[[package]]
@ -542,9 +540,23 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "serde"
version = "1.0.183"
version = "1.0.186"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c"
checksum = "9f5db24220c009de9bd45e69fb2938f4b6d2df856aa9304ce377b3180f83b7c1"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.186"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ad697f7e0b65af4983a4ce8f56ed5b357e8d3c36651bf6a7e13639c17b8e670"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
@ -608,17 +620,6 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.29"
@ -647,7 +648,7 @@ checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.29",
"syn",
]
[[package]]
@ -702,7 +703,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.29",
"syn",
]
[[package]]
@ -754,7 +755,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.29",
"syn",
]
[[package]]

View File

@ -3,6 +3,7 @@
members = [
"keyfork-mnemonic-generate",
"keyfork-mnemonic-util",
"keyfork-derive-util",
"keyforkd",
"keyfork-frame"
]

View File

@ -0,0 +1,9 @@
[package]
name = "keyfork-derive-util"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { version = "1.0.186", features = ["derive"] }

View File

@ -0,0 +1,23 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct DerivablePath {
pub(crate) path: Vec<u32>,
}
// TODO: move DerivablePath into a models crate for clients to produce?
/*
impl DerivablePath {
pub fn new(input: &[&[u8]]) -> DerivablePath {
DerivablePath {
path: input
.iter()
.map(|&word| {
// perform path validation
word.to_vec()
})
.collect(),
}
}
}
*/

View File

@ -116,7 +116,7 @@ pub fn try_decode(data: &[u8]) -> Result<Vec<u8>, DecodeError> {
#[cfg(test)]
mod tests {
use super::{try_encode, try_decode, DecodeError};
use super::{try_decode, try_encode, DecodeError};
#[test]
fn stable_interface() {

View File

@ -11,10 +11,12 @@ tracing = ["tower/tracing", "tokio/tracing", "dep:tracing", "dep:tracing-subscri
multithread = ["tokio/rt-multi-thread"]
[dependencies]
bincode = "1.3.3"
dirs = "5.0.1"
keyfork-derive-util = { version = "0.1.0", path = "../keyfork-derive-util" }
keyfork-frame = { version = "0.1.0", path = "../keyfork-frame" }
keyfork-mnemonic-util = { version = "0.1.0", path = "../keyfork-mnemonic-util" }
minicbor = { version = "0.19.1", features = ["derive", "std"] }
serde = { version = "1.0.186", features = ["derive"] }
thiserror = "1.0.47"
tokio = { version = "1.32.0", features = ["io-util", "macros", "rt", "io-std", "net", "fs", "signal"] }
tower = { version = "0.4.13", features = ["tokio", "util"] }

View File

@ -13,11 +13,11 @@ use tracing_subscriber::{
};
mod error;
mod service;
mod server;
mod service;
use error::KeycloakdError;
use service::Keyforkd;
use server::UnixServer;
use service::Keyforkd;
type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;

View File

@ -1,6 +1,10 @@
use crate::service::{DerivablePath, DerivationError, Keyforkd};
use crate::service::{DerivationError, Keyforkd};
use keyfork_derive_util::DerivablePath;
use keyfork_frame::asyncext::{try_decode_from, try_encode_to};
use std::{io::Error, path::{Path, PathBuf}};
use std::{
io::Error,
path::{Path, PathBuf},
};
use tokio::net::{UnixListener, UnixStream};
use tower::{Service, ServiceExt};
@ -11,7 +15,7 @@ async fn read_path_from_socket(
socket: &mut UnixStream,
) -> Result<DerivablePath, Box<dyn std::error::Error + Send>> {
let data = try_decode_from(socket).await.unwrap();
let path: DerivablePath = minicbor::decode(&data[..]).unwrap();
let path: DerivablePath = bincode::deserialize(&data[..]).unwrap();
Ok(path)
}
@ -31,7 +35,10 @@ impl UnixServer {
tokio::spawn(async move {
let result = tokio::signal::ctrl_c().await;
#[cfg(feature = "tracing")]
debug!(?result, "encountered ctrl-c, performing cleanup and exiting");
debug!(
?result,
"encountered ctrl-c, performing cleanup and exiting"
);
let result = tokio::fs::remove_file(&path).await;
#[cfg(feature = "tracing")]
if let Err(error) = result {
@ -86,7 +93,6 @@ impl UnixServer {
#[cfg(feature = "tracing")]
debug!(%e, "Error sending response to client");
}
});
}
}

View File

@ -1,32 +1,9 @@
use std::{future::Future, pin::Pin, task::Poll, sync::Arc};
use std::{future::Future, pin::Pin, sync::Arc, task::Poll};
use keyfork_derive_util::DerivablePath;
use keyfork_mnemonic_util::Mnemonic;
use minicbor::{Decode, Encode};
use tower::Service;
use thiserror::Error;
#[derive(Encode, Decode, Clone, Debug)]
pub struct DerivablePath {
#[n(0)]
path: Vec<Vec<u8>>,
}
// TODO: move DerivablePath into a models crate for clients to produce?
/*
impl DerivablePath {
pub fn new(input: &[&[u8]]) -> DerivablePath {
DerivablePath {
path: input
.iter()
.map(|&word| {
// perform path validation
word.to_vec()
})
.collect(),
}
}
}
*/
use tower::Service;
#[derive(Clone, Debug)]
pub struct Keyforkd {
@ -35,12 +12,13 @@ pub struct Keyforkd {
// Currently, this can't be instantiated, therefore it is a never-type
#[derive(Debug, Error)]
pub enum DerivationError {
}
pub enum DerivationError {}
impl Keyforkd {
pub fn new(mnemonic: Mnemonic) -> Self {
Self { mnemonic: Arc::new(mnemonic) }
Self {
mnemonic: Arc::new(mnemonic),
}
}
}