diff --git a/Cargo.lock b/Cargo.lock index 3101b88..7ca4947 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,6 +67,12 @@ version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bytes" version = "1.10.0" @@ -424,6 +430,7 @@ name = "scep_req_parser" version = "0.1.0" dependencies = [ "anyhow", + "base64", "clap", "env_logger", "http", diff --git a/Cargo.toml b/Cargo.toml index ae9abff..ebe16aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,5 @@ env_logger = "0.11.6" clap = { version = "4.5.31", features = ["derive", "env"] } http = { version = "1.2.0" } anyhow = "1.0.97" -url = "2.5.4" \ No newline at end of file +url = "2.5.4" +base64 = "0.22.1" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 069c896..c7ffb89 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,11 @@ use clap::Parser; use http::StatusCode; use std::collections::HashMap; use std::str::FromStr; +use base64::alphabet::STANDARD; use url::Url; +use base64::prelude::*; +use base64::Engine as _; +use base64::engine::general_purpose::URL_SAFE as BASE64_URL_URL_SAFE; /// Simple SCEP parser program #[derive(Parser, Debug)] @@ -102,7 +106,7 @@ fn parse_response(req: &[u8]) -> anyhow::Result>> { } } -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] enum Operation { GetCACaps, GetCACert, @@ -136,4 +140,13 @@ fn main() { println!("{} - {} - {op:?}", response.headers().get("Date").unwrap().to_str().unwrap(), response.status().as_u16()); + + // Parse details about PKIOperation request + // https://www.rfc-editor.org/rfc/rfc8894.html#section-4.3 + if op == Operation::PKIOperation { + let req_b64 = BASE64_URL_URL_SAFE.encode(&request.body()); + let res_b64 = BASE64_URL_URL_SAFE.encode(&response.body()); + println!("https://lapo.it/asn1js/#{req_b64}"); + println!("https://lapo.it/asn1js/#{res_b64}"); + } }