feat: v0.3.7, yubikey is optional
This commit is contained in:
13
src/main.rs
13
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<Box<dyn Command>> = vec![
|
||||
Box::new(cli::CommandImpl),
|
||||
Box::new(serve::CommandImpl),
|
||||
#[cfg(feature = "yubikey")]
|
||||
Box::new(yubikey_init_master_key::CommandImpl),
|
||||
];
|
||||
let mut features: Vec<String> = 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 {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user