Update
This commit is contained in:
parent
1bb22db692
commit
7d629e38d8
14 changed files with 478 additions and 58 deletions
60
src/symbols/tls/key.rs
Normal file
60
src/symbols/tls/key.rs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
use std::borrow::Cow;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
use command_runner::CommandRunner;
|
||||
use symbols::Symbol;
|
||||
|
||||
pub struct TlsKey<'a> {
|
||||
domain: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner
|
||||
}
|
||||
|
||||
impl<'a> TlsKey<'a> {
|
||||
pub fn new(domain: Cow<'a, str>, command_runner: &'a CommandRunner) -> TlsKey<'a> {
|
||||
TlsKey {
|
||||
domain: domain,
|
||||
command_runner: command_runner
|
||||
}
|
||||
}
|
||||
|
||||
fn get_path(&self) -> String {
|
||||
format!("/etc/ssl/private/{}.key", self.domain)
|
||||
}
|
||||
|
||||
fn get_bytes(&self) -> u32 {
|
||||
4096
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for TlsKey<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "TlsKey {}", self.domain)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for TlsKey<'a> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
let result = self.command_runner.run_with_args("openssl", &["rsa", "-in", &self.get_path(), "-noout", "-check", "-text"]);
|
||||
match result {
|
||||
Err(e) => Err(Box::new(e)),
|
||||
Ok(output) => match output.status.code() {
|
||||
Some(0) => Ok(output.stdout.starts_with(format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes())),
|
||||
Some(_) => Ok(false),
|
||||
_ => Err("Didn't work".to_string().into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn execute(&self) -> Result<(), Box<Error>> {
|
||||
let output = self.command_runner.run_with_args("openssl", &["genrsa", "-out", &self.get_path(), &self.get_bytes().to_string()]);
|
||||
match output {
|
||||
Err(e) => Err(Box::new(e)),
|
||||
Ok(_) => Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue