diff --git a/src/piv.rs b/src/piv.rs index 01281bc..9ab11e1 100644 --- a/src/piv.rs +++ b/src/piv.rs @@ -15,11 +15,14 @@ impl Command for CommandImpl { fn name(&self) -> &str { "piv" } fn subcommand<'a>(&self) -> App<'a, 'a> { - SubCommand::with_name(self.name()).about("OpenPGP Card List subcommand") - .arg(Arg::with_name("json").long("json").help("JSON output")) + SubCommand::with_name(self.name()).about("PIV subcommand") + .arg(Arg::with_name("detail").long("detail").help("Detail output")) + .arg(Arg::with_name("show-config").long("show-config").help("Show config output")) + // .arg(Arg::with_name("json").long("json").help("JSON output")) } - fn run(&self, _arg_matches: &ArgMatches, _sub_arg_matches: &ArgMatches) -> CommandError { + fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { + let detail_output = sub_arg_matches.is_present("detail"); let mut yk = YubiKey::open()?; success!("Name: {}", yk.name()); success!("Version: {}", yk.version()); @@ -36,14 +39,19 @@ impl Command for CommandImpl { Ok(pin_retries) => success!("PIN retries: {}",pin_retries), Err(e) => warning!("PIN retries: {}", e), } + if sub_arg_matches.is_present("show-config") { + let cofnig = yk.config(); + information!("Config: {:#?}", cofnig); + } + for slot in yubikey::piv::SLOTS.iter().cloned() { - print_cert_info(&mut yk, slot).ok(); + print_cert_info(&mut yk, slot, detail_output).ok(); } Ok(()) } } -fn print_cert_info(yubikey: &mut YubiKey, slot: SlotId) -> XResult<()> { +fn print_cert_info(yubikey: &mut YubiKey, slot: SlotId, detail_output: bool) -> XResult<()> { let cert = match Certificate::read(yubikey, slot) { Ok(c) => c, Err(e) => { @@ -55,18 +63,23 @@ fn print_cert_info(yubikey: &mut YubiKey, slot: SlotId) -> XResult<()> { let buf = cert.into_buffer(); if !buf.is_empty() { + information!("{}", "-".repeat(88)); let fingerprint_sha256 = Sha256::digest(&buf); let slot_id: u8 = slot.into(); success!("Slot: {:?}, id: {:x}", slot, slot_id); - rust_util::util_msg::when(MessageType::DEBUG, || { - let cert_pem_obj = Pem { - tag: String::from("CERTIFICATE"), - contents: buf.to_vec(), - }; - debugging!("{}", pem::encode(&cert_pem_obj).trim()); - }); + let cert_pem_obj = Pem { + tag: String::from("CERTIFICATE"), + contents: buf.to_vec(), + }; + if detail_output { + information!("{}", pem::encode(&cert_pem_obj).trim()); + } else { + rust_util::util_msg::when(MessageType::DEBUG, || { + debugging!("{}", pem::encode(&cert_pem_obj).trim()); + }); + } match parse_x509_certificate(&buf) { Ok((_rem, cert)) => {