You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.4 KiB
68 lines
1.4 KiB
use crate::command_runner::CommandRunner;
|
|
use crate::symbols::Symbol;
|
|
use async_trait::async_trait;
|
|
use std::borrow::Borrow;
|
|
use std::error::Error;
|
|
use std::path::Path;
|
|
|
|
#[derive(Debug)]
|
|
pub struct Csr<C, D, K, P> {
|
|
command_runner: C,
|
|
domain: D,
|
|
key_path: K,
|
|
csr_path: P,
|
|
}
|
|
|
|
impl<C, D, K, P> Csr<C, D, K, P> {
|
|
pub const fn new(command_runner: C, domain: D, key_path: K, csr_path: P) -> Self {
|
|
Self {
|
|
command_runner,
|
|
domain,
|
|
key_path,
|
|
csr_path,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[async_trait(?Send)]
|
|
impl<C: CommandRunner, D: Borrow<str>, K: Borrow<Path>, P: Borrow<Path>> Symbol
|
|
for Csr<C, D, K, P>
|
|
{
|
|
async fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
|
if !self.csr_path.borrow().exists() {
|
|
return Ok(false);
|
|
}
|
|
|
|
let output = self
|
|
.command_runner
|
|
.get_stderr(
|
|
"openssl",
|
|
args!["req", "-in", self.csr_path.borrow(), "-noout", "-verify",],
|
|
)
|
|
.await?;
|
|
Ok(output == b"verify OK\n")
|
|
}
|
|
|
|
async fn execute(&self) -> Result<(), Box<dyn Error>> {
|
|
self
|
|
.command_runner
|
|
.run_successfully(
|
|
"openssl",
|
|
args![
|
|
"req",
|
|
"-new",
|
|
"-sha256",
|
|
"-key",
|
|
self.key_path.borrow(),
|
|
"-out",
|
|
self.csr_path.borrow(),
|
|
"-subj",
|
|
format!("/CN={}", self.domain.borrow()),
|
|
],
|
|
)
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {}
|