Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
hatoo committed Jan 13, 2024
1 parent 6e50632 commit 7e477a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
#[clap(requires("cert"))]
private_key: Option<PathBuf>,
}
fn make_root_cert() -> rcgen::Certificate {
let mut param = rcgen::CertificateParams::default();
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions examples/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 7e477a6

Please sign in to comment.