Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use x509-cert certificate builder #495

Merged
merged 6 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
279 changes: 58 additions & 221 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ rust-version = "1.65"
[workspace]
members = [".", "cli"]

[workspace.dependencies]
x509-cert = { version = "0.2.3", features = [ "builder", "hazmat" ] }

[dependencies]
chrono = "0.4.23"
cookie-factory = "0.3"
der-parser = "8"
der = "0.7.1"
des = "0.8"
elliptic-curve = "0.13"
hex = { package = "base16ct", version = "0.2", features = ["alloc"] }
Expand All @@ -32,19 +34,20 @@ nom = "7"
num-bigint-dig = { version = "0.8", features = ["rand"] }
num-traits = "0.2"
num-integer = "0.1"
ecdsa = { version = "0.16.7", features = ["digest", "pem"] }
p256 = "0.13"
p384 = "0.13"
pbkdf2 = { version = "0.12", default-features = false, features = ["hmac"] }
pcsc = "2.3.1"
rand_core = { version = "0.6", features = ["std"] }
rsa = "0.9"
rsa = { version = "0.9.2", features = ["sha2"] }
secrecy = "0.8"
sha1 = { version = "0.10", features = ["oid"] }
sha2 = { version = "0.10", features = ["oid"] }
signature = "2.0.0"
subtle = "2"
uuid = { version = "1.2", features = ["v4"] }
x509 = "0.2"
x509-parser = "0.14"
x509-cert.workspace = true
zeroize = "1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ log = "0.4"
once_cell = "1"
sha2 = "0.10"
termcolor = "1"
x509-parser = "0.14"
x509-cert.workspace = true
yubikey = { version = "0.8.0-pre.0", path = ".." }
72 changes: 25 additions & 47 deletions cli/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
sync::Mutex,
};
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, StandardStreamLock, WriteColor};
use x509_parser::parse_x509_certificate;
use x509_cert::der::Encode;
use yubikey::{certificate::Certificate, piv::*, YubiKey};

/// Print a success status message (in green if colors are enabled)
Expand Down Expand Up @@ -180,52 +180,30 @@ pub fn print_cert_info(
return Ok(());
}
};
let buf = cert.into_buffer();

if !buf.is_empty() {
let fingerprint = Sha256::digest(&buf);
let slot_id: u8 = slot.into();
print_cert_attr(stream, "Slot", format!("{:x}", slot_id))?;
match parse_x509_certificate(&buf) {
Ok((_rem, cert)) => {
print_cert_attr(
stream,
"Algorithm",
cert.tbs_certificate.subject_pki.algorithm.algorithm,
)?;

print_cert_attr(stream, "Subject", cert.tbs_certificate.subject)?;
print_cert_attr(stream, "Issuer", cert.tbs_certificate.issuer)?;
print_cert_attr(
stream,
"Fingerprint",
&hex::upper::encode_string(&fingerprint),
)?;
print_cert_attr(
stream,
"Not Before",
cert.tbs_certificate
.validity
.not_before
.to_rfc2822()
.unwrap(),
)?;
print_cert_attr(
stream,
"Not After",
cert.tbs_certificate
.validity
.not_after
.to_rfc2822()
.unwrap(),
)?;
}
_ => {
println!("Failed to parse certificate");
return Ok(());
}
};
}
let cert = &cert.cert;

let fingerprint = Sha256::digest(&cert.to_der().unwrap());
let slot_id: u8 = slot.into();
print_cert_attr(stream, "Slot", format!("{:x}", slot_id))?;
print_cert_attr(
stream,
"Algorithm",
cert.tbs_certificate.subject_public_key_info.algorithm.oid,
)?;

print_cert_attr(stream, "Subject", &cert.tbs_certificate.subject)?;
print_cert_attr(stream, "Issuer", &cert.tbs_certificate.issuer)?;
print_cert_attr(
stream,
"Fingerprint",
&hex::upper::encode_string(&fingerprint),
)?;
print_cert_attr(
stream,
"Not Before",
cert.tbs_certificate.validity.not_before,
)?;
print_cert_attr(stream, "Not After", cert.tbs_certificate.validity.not_after)?;

Ok(())
}
Expand Down
Loading