From 306738f894b491f9723605f41fce77505ed0a751 Mon Sep 17 00:00:00 2001 From: Philip Tricca Date: Thu, 8 Feb 2024 09:17:48 -0800 Subject: [PATCH] dice-mfg: replace pem crate w/ pem-rfc7468 --- Cargo.lock | 20 ++------------------ Cargo.toml | 1 - dice-mfg/Cargo.toml | 2 +- dice-mfg/src/lib.rs | 21 ++++++++------------- 4 files changed, 11 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 07e8139..022043f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -143,12 +143,6 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - [[package]] name = "base64ct" version = "1.5.3" @@ -488,7 +482,7 @@ dependencies = [ "dice-mfg-msgs", "env_logger", "log", - "pem", + "pem-rfc7468", "rpassword", "serde_json", "serialport", @@ -968,16 +962,6 @@ dependencies = [ "hmac", ] -[[package]] -name = "pem" -version = "3.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8fcc794035347fb64beda2d3b462595dd2753e3f268d89c5aae77e8cf2c310" -dependencies = [ - "base64 0.21.7", - "serde", -] - [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -1111,7 +1095,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "300a51053b1cb55c80b7a9fde4120726ddf25ca241a1cbb926626f62fb136bff" dependencies = [ - "base64 0.13.1", + "base64", "bitflags 1.3.2", "serde", ] diff --git a/Cargo.toml b/Cargo.toml index c26b1dc..cac28e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ hex.version = "0.4" hubpack = "0.1" log = { version = "0.4", features = ["std"] } p384 = { version = "0.13", default-features = false } -pem = { version = "3", default-features = false } pem-rfc7468 = { version = "0.7.0", default-features = false } ron = "0.8" rpassword = "7.3.1" diff --git a/dice-mfg/Cargo.toml b/dice-mfg/Cargo.toml index a980470..109efa9 100644 --- a/dice-mfg/Cargo.toml +++ b/dice-mfg/Cargo.toml @@ -14,7 +14,7 @@ corncobs.workspace = true dice-mfg-msgs = { path = "../dice-mfg-msgs", features = ["std"] } env_logger.workspace = true log.workspace = true -pem = { workspace = true, features = ["std"] } +pem-rfc7468 = { workspace = true, features = ["alloc", "std"] } rpassword.workspace = true serde_json.workspace = true serialport.workspace = true diff --git a/dice-mfg/src/lib.rs b/dice-mfg/src/lib.rs index 6ce22c7..580f5af 100644 --- a/dice-mfg/src/lib.rs +++ b/dice-mfg/src/lib.rs @@ -619,25 +619,20 @@ impl CertSigner { } fn sized_blob_from_pem_path(p: &PathBuf) -> Result { - let cert = fs::read_to_string(p)?; - let cert = pem::parse(cert)?; + let cert = fs::read(p)?; + let (_, cert) = pem_rfc7468::decode_vec(&cert)?; - // Error type doesn't implement std Error - Ok(SizedBlob::try_from(cert.contents())?) + Ok(SizedBlob::try_from(&cert[..])?) } pub fn save_csr(mut w: W, csr: SizedBlob) -> Result<()> { let size = usize::from(csr.size); - // encode as PEM - let pem = pem::Pem::new( - String::from("CERTIFICATE REQUEST"), - csr.as_bytes()[..size].to_vec(), - ); - let csr_pem = pem::encode_config( - &pem, - pem::EncodeConfig::new().set_line_ending(pem::LineEnding::LF), - ); + let csr_pem = pem_rfc7468::encode_string( + "CERTIFICATE REQUEST", + pem_rfc7468::LineEnding::LF, + &csr.as_bytes()[..size], + )?; Ok(w.write_all(csr_pem.as_bytes())?) }