diff options
-rw-r--r-- | Cargo.lock | 21 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | tester/Cargo.toml | 21 | ||||
-rw-r--r-- | tester/src/generate.rs | 37 | ||||
-rw-r--r-- | tester/src/main.rs | 67 |
5 files changed, 147 insertions, 0 deletions
@@ -2701,6 +2701,27 @@ dependencies = [ ] [[package]] +name = "tester" +version = "0.1.0" +dependencies = [ + "anyhow", + "base64 0.10.1", + "clap", + "fs2", + "hex", + "idna 0.1.5", + "indicatif", + "log 0.3.9", + "rand 0.6.5", + "sequoia-openpgp", + "serde", + "serde_derive", + "serde_json", + "time 0.1.45", + "url", +] + +[[package]] name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -10,6 +10,7 @@ edition = "2018" members = [ "database", "hagridctl", + "tester", ] [dependencies] diff --git a/tester/Cargo.toml b/tester/Cargo.toml new file mode 100644 index 0000000..4337b0e --- /dev/null +++ b/tester/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "tester" +version = "0.1.0" +authors = ["Vincent Breitmoser <look@my.amazin.horse>"] + +[dependencies] +anyhow = "1" +sequoia-openpgp = { version = "1", default-features = false, features = ["crypto-openssl"] } +log = "0" +rand = "0.6" +serde = { version = "1.0", features = ["derive"] } +serde_derive = "1" +serde_json = "1" +time = "0.1" +url = "1" +hex = "0.3" +base64 = "0.10" +idna = "0.1" +fs2 = "0.4" +clap = "2" +indicatif = "0.11" diff --git a/tester/src/generate.rs b/tester/src/generate.rs new file mode 100644 index 0000000..b75a325 --- /dev/null +++ b/tester/src/generate.rs @@ -0,0 +1,37 @@ +use std::{fs::File, path::Path, io::Write}; + +use anyhow::Result; + +use indicatif::{ProgressBar, ProgressStyle}; +use openpgp::{cert::CertBuilder, serialize::Serialize}; + +pub fn do_generate(count: u64, output_path: &Path, fprs_path: Option<&Path>) -> Result<()> { + let progress_bar = ProgressBar::new(count); + progress_bar.set_style( + ProgressStyle::default_bar() + .template("[{elapsed_precise}] {bar:40.cyan/blue} {pos}/{len} {msg}") + .progress_chars("##-"), + ); + progress_bar.set_draw_delta(count / 100); + + let mut output = File::create(output_path)?; + let mut output_fprs = if let Some(p) = fprs_path { + Some(File::create(p)?) + } else { + None + }; + for i in 0..count { + let (cert, _) = + CertBuilder::general_purpose(None, Some(format!("{:07}@hagrid.invalid", i))) + .generate()?; + cert.serialize(&mut output)?; + if let Some(ref mut output_fprs) = output_fprs { + writeln!(output_fprs, "{}", cert)?; + } + + progress_bar.inc(1); + } + progress_bar.finish(); + + Ok(()) +} diff --git a/tester/src/main.rs b/tester/src/main.rs new file mode 100644 index 0000000..a2de67c --- /dev/null +++ b/tester/src/main.rs @@ -0,0 +1,67 @@ +extern crate anyhow; +extern crate clap; +extern crate indicatif; +extern crate sequoia_openpgp as openpgp; +extern crate serde_derive; + +use std::path::PathBuf; + +use anyhow::Result; + +use clap::{App, Arg, SubCommand}; + +mod generate; + +fn main() -> Result<()> { + let matches = App::new("Hagrid Tester") + .version("0.1") + .about("Control hagrid database externally") + .arg( + Arg::with_name("config") + .short("c") + .long("config") + .value_name("FILE") + .help("Sets a custom config file") + .takes_value(true), + ) + .subcommand( + SubCommand::with_name("generate") + .about("Generate a test set of certificates") + .arg( + Arg::with_name("cert count") + .long("cert-count") + .default_value("100000") + .help("number of certifictes to generate"), + ) + .arg( + Arg::with_name("certs output file") + .long("output-file") + .default_value("keyring.pub.pgp") + .help("path to file to store the certificates in"), + ) + .arg( + Arg::with_name("fingerprints output file") + .long("fingerprints-file") + .default_value("fingerprints.txt") + .help("path to file to store fingerprints in"), + ), + ) + .get_matches(); + + if let Some(matches) = matches.subcommand_matches("generate") { + let count: u64 = matches.value_of("cert count").unwrap().parse().unwrap(); + let output_certs: PathBuf = matches + .value_of("certs output file") + .unwrap() + .parse() + .unwrap(); + let output_fprs: Option<PathBuf> = matches + .value_of("fingerprints output file") + .map(|s| s.parse().unwrap()); + generate::do_generate(count, output_certs.as_path(), output_fprs.as_ref().map(|f| f.as_path()))?; + } else { + println!("{}", matches.usage()); + } + + Ok(()) +} |