Skip to content

Commit

Permalink
single method for openssl
Browse files Browse the repository at this point in the history
  • Loading branch information
dkijania committed Jul 10, 2020
1 parent 845aade commit 58ce16c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/lib.rs
Expand Up @@ -2,6 +2,7 @@ pub mod archive;
pub mod github;
pub mod measurement;
pub mod openssl;
pub mod predicates;
pub mod process;
pub mod web;

Expand All @@ -15,6 +16,7 @@ pub mod prelude {
EnduranceBenchmarkFinish, EnduranceBenchmarkRun, NamedProcess, ResourcesUsage, Speed,
SpeedBenchmarkDef, SpeedBenchmarkFinish, SpeedBenchmarkRun, Thresholds, Timestamp,
};
pub use crate::openssl::Openssl;
pub use crate::openssl::{generate_keys, Openssl};
pub use crate::predicates::*;
pub use crate::web::download_file;
}
41 changes: 37 additions & 4 deletions src/openssl/mod.rs
@@ -1,10 +1,13 @@
use assert_fs::fixture::ChildPath;
use crate::prelude::file_exists_and_not_empty;
use assert_fs::{
assert::PathAssert,
fixture::{ChildPath, PathChild},
TempDir,
};
use bawawa::{Command, Error, Process, Program, StandardError, StandardOutput};
use futures::stream::Stream;
use tokio_codec::LinesCodec;

use std::path::PathBuf;

use tokio_codec::LinesCodec;
pub struct Openssl {
program: Program,
}
Expand Down Expand Up @@ -126,3 +129,33 @@ fn path_to_str(path: &ChildPath) -> String {
let path_buf: PathBuf = path.path().into();
path_buf.as_os_str().to_owned().into_string().unwrap()
}

pub fn generate_keys(temp_dir: &TempDir) -> (PathBuf, PathBuf) {
let openssl = Openssl::new().expect("no openssla installed.");
let prv_key_file = temp_dir.child("prv.key");
let pk8_key_file = temp_dir.child("prv.pk8");
let csr_cert_file = temp_dir.child("cert.csr");
let cert_file = temp_dir.child("cert.crt");
let der_file = temp_dir.child("cert.der");

openssl
.genrsa(2048, &prv_key_file)
.expect("cannot generate private key.");
openssl
.pkcs8(&prv_key_file, &pk8_key_file)
.expect("cannot wrap private key in PKC8");
openssl
.req(&prv_key_file, &csr_cert_file)
.expect("cannot register a self-signed certificate for private key");
openssl
.x509(&prv_key_file, &csr_cert_file, &cert_file)
.expect("cannot generate a self-signed certificate for private key");
openssl
.convert_to_der(&cert_file, &der_file)
.expect("cannot convert cert file to der file");

prv_key_file.assert(file_exists_and_not_empty());
cert_file.assert(file_exists_and_not_empty());

(prv_key_file.path().into(), cert_file.path().into())
}

0 comments on commit 58ce16c

Please sign in to comment.