From ec7aaa9fca95ecd2dbbcb9c0efe83489768e0384 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 10 Nov 2024 18:38:56 +0800 Subject: [PATCH] feat: v0.3.7, yubikey is optional --- Cargo.lock | 2 +- Cargo.toml | 8 ++++++-- README.md | 6 ++++++ src/main.rs | 13 ++++++++++--- src/serve.rs | 3 +++ src/serve_init.rs | 2 ++ 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5520fd0..f8847e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -742,7 +742,7 @@ checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "local-mini-kms" -version = "0.3.6" +version = "0.3.7" dependencies = [ "base64 0.21.7", "clap", diff --git a/Cargo.toml b/Cargo.toml index 4695fa2..eac8e55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,14 @@ [package] name = "local-mini-kms" -version = "0.3.6" +version = "0.3.7" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["yubikey"] +yubikey = ["yubico_manager"] + [dependencies] zeroize = "1.8" clap = "2.34" @@ -22,7 +26,7 @@ rust_util = { version = "0.6", features = ["use_clap"] } tokio = { version = "1.37", features = ["full"] } hyper = { version = "0.14", features = ["client", "server", "tcp", "http1", "http2"] } rusqlite = "0.31" -yubico_manager = "0.9" +yubico_manager = { version = "0.9", optional = true } rpassword = "7.3" rand = "0.8" diff --git a/README.md b/README.md index 595d03e..c22572b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ Mini-KMS runs local written by Rust +## Build + +```shell +cargo build --release [--no-default-features] +``` + ## Init New random master key: diff --git a/src/main.rs b/src/main.rs index 913a8b3..682f0f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,20 @@ use clap::{App, AppSettings, ArgMatches}; -use rust_util::{failure_and_exit, information, success, warning}; use rust_util::util_clap::{Command, CommandError}; +use rust_util::{failure_and_exit, information, success, warning}; mod db; mod proc; mod jose; mod cli; -mod yubikey_hmac; mod serve; mod serve_common; mod serve_status; mod serve_init; mod serve_encrypt_decrypt; mod serve_read_write; +#[cfg(feature = "yubikey")] +mod yubikey_hmac; +#[cfg(feature = "yubikey")] mod yubikey_init_master_key; mod serve_datakey; @@ -48,12 +50,17 @@ fn inner_main() -> CommandError { let commands: Vec> = vec![ Box::new(cli::CommandImpl), Box::new(serve::CommandImpl), + #[cfg(feature = "yubikey")] Box::new(yubikey_init_master_key::CommandImpl), ]; + let mut features: Vec = vec![]; + #[cfg(feature = "yubikey")] + features.push("yubikey".to_string()); + let long_about = format!("Local mini KMS, features: [{}]", features.join(", ")); let mut app = App::new(env!("CARGO_PKG_NAME")) .version(env!("CARGO_PKG_VERSION")) .about(env!("CARGO_PKG_DESCRIPTION")) - .long_about("Local mini KMS") + .long_about(long_about.as_str()) .setting(AppSettings::ColoredHelp); app = DefaultCommandImpl::process_command(app); for command in &commands { diff --git a/src/serve.rs b/src/serve.rs index ce29172..967ea99 100644 --- a/src/serve.rs +++ b/src/serve.rs @@ -16,6 +16,7 @@ use crate::serve_init; use crate::serve_init::InitRequest; use crate::serve_read_write; use crate::serve_status; +#[cfg(feature = "yubikey")] use crate::yubikey_hmac; use crate::{db, jose, proc}; use crate::{do_response, serve_datakey}; @@ -42,6 +43,7 @@ impl Command for CommandImpl { } let rt = Runtime::new().expect("Create tokio runtime error"); + #[cfg(feature = "yubikey")] init_with_yubikey_challenge(&rt, sub_arg_matches); let listen = sub_arg_matches.value_of("listen").expect("Get argument listen error"); @@ -175,6 +177,7 @@ Supports commands: } } +#[cfg(feature = "yubikey")] fn init_with_yubikey_challenge(rt: &Runtime, sub_arg_matches: &ArgMatches) { let mut yubikey_challenge = sub_arg_matches.value_of("yubikey-challenge").map(ToString::to_string); let init_encrypted_master_key = sub_arg_matches.value_of("init-encrypted-master-key"); diff --git a/src/serve_init.rs b/src/serve_init.rs index 99c1106..4c892bf 100644 --- a/src/serve_init.rs +++ b/src/serve_init.rs @@ -11,6 +11,7 @@ use zeroize::Zeroize; use crate::db::Key; use crate::do_response; use crate::serve_common::{self, Result}; +#[cfg(feature = "yubikey")] use crate::yubikey_hmac; use crate::{db, jose}; @@ -81,6 +82,7 @@ pub async fn inner_init_request(init_request: InitRequest) -> XResult<(StatusCod } information!("Set master key success"); + #[cfg(feature = "yubikey")] if let Some(yubikey_challenge) = &init_request.yubikey_challenge { match yubikey_hmac::yubikey_challenge_as_32_bytes(yubikey_challenge.as_bytes()) { Err(e) => warning!("Yubikey challenge failed: {}", e),