From 7e477a6cdf7b141179c039cba8c8a8b0eb04314a Mon Sep 17 00:00:00 2001 From: hatoo Date: Sat, 13 Jan 2024 15:56:10 +0900 Subject: [PATCH] Update README --- README.md | 26 +++++++++++++++++++++++++- examples/proxy.rs | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6c2aa0..9a6ebe7 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,20 @@ A HTTP proxy server library intended to be a backend of application like Burp pr ## Usage ```rust, no_run +use std::path::PathBuf; + +use clap::Parser; use futures::StreamExt; use http_mitm_proxy::MitmProxy; +#[derive(Parser)] +struct Opt { + #[clap(requires("private_key"))] + cert: Option, + #[clap(requires("cert"))] + private_key: Option, +} + fn make_root_cert() -> rcgen::Certificate { let mut param = rcgen::CertificateParams::default(); @@ -32,7 +43,20 @@ fn make_root_cert() -> rcgen::Certificate { #[tokio::main] async fn main() { - let root_cert = make_root_cert(); + let opt = Opt::parse(); + + let root_cert = if let (Some(cert), Some(private_key)) = (opt.cert, opt.private_key) { + // Use existing key + let param = rcgen::CertificateParams::from_ca_cert_pem( + &std::fs::read_to_string(cert).unwrap(), + rcgen::KeyPair::from_pem(&std::fs::read_to_string(private_key).unwrap()).unwrap(), + ) + .unwrap(); + rcgen::Certificate::from_params(param).unwrap() + } else { + make_root_cert() + }; + let root_cert_pem = root_cert.serialize_pem().unwrap(); let proxy = MitmProxy::new( diff --git a/examples/proxy.rs b/examples/proxy.rs index 6b4be0c..25c3e3f 100644 --- a/examples/proxy.rs +++ b/examples/proxy.rs @@ -33,6 +33,7 @@ async fn main() { let opt = Opt::parse(); let root_cert = if let (Some(cert), Some(private_key)) = (opt.cert, opt.private_key) { + // Use existing key let param = rcgen::CertificateParams::from_ca_cert_pem( &std::fs::read_to_string(cert).unwrap(), rcgen::KeyPair::from_pem(&std::fs::read_to_string(private_key).unwrap()).unwrap(),