Adrian Heine
5 years ago
5 changed files with 165 additions and 72 deletions
-
43src/symbols/acme/cert.rs
-
23src/symbols/acme/chain.rs
-
92src/symbols/acme/mod.rs
-
28src/symbols/acme/user.rs
-
51src/symbols/factory.rs
@ -1,9 +1,97 @@ |
|||
use std::borrow::Cow;
|
|||
use std::path::{Path, PathBuf};
|
|||
|
|||
use crate::command_runner::CommandRunner;
|
|||
use crate::command_runner::SetuidCommandRunner;
|
|||
use crate::symbols::dir::Dir;
|
|||
use crate::symbols::file::File;
|
|||
use crate::symbols::list::List;
|
|||
use crate::symbols::owner::Owner;
|
|||
use crate::symbols::Symbol;
|
|||
|
|||
mod account_key;
|
|||
mod cert;
|
|||
mod chain;
|
|||
mod user;
|
|||
|
|||
pub use self::account_key::AcmeAccountKey;
|
|||
pub use self::cert::AcmeCert;
|
|||
pub use self::chain::AcmeCertChain;
|
|||
pub use self::user::new as newAcmeUser;
|
|||
|
|||
const ROOT_CERT_FILE_NAME: &str = "lets_encrypt_x3_cross_signed.pem";
|
|||
const ACCOUNT_KEY_FILE_NAME: &str = "account.key";
|
|||
|
|||
pub struct Factory<'a, U: AsRef<str>, H: AsRef<Path>, C: AsRef<str>, R: CommandRunner> {
|
|||
user_name: U,
|
|||
home_dir: H,
|
|||
cert: C,
|
|||
command_runner: &'a R,
|
|||
acme_command_runner: SetuidCommandRunner<'a, U, R>,
|
|||
}
|
|||
|
|||
impl<'a, U: Clone + AsRef<str>, H: AsRef<Path>, C: AsRef<str>, R: CommandRunner>
|
|||
Factory<'a, U, H, C, R>
|
|||
{
|
|||
pub fn new(user_name: U, home_dir: H, cert: C, command_runner: &'a R) -> Self {
|
|||
let acme_command_runner = SetuidCommandRunner::new(user_name.clone(), command_runner);
|
|||
Self {
|
|||
user_name,
|
|||
home_dir,
|
|||
cert,
|
|||
command_runner,
|
|||
acme_command_runner,
|
|||
}
|
|||
}
|
|||
pub fn get_challenges_dir(&'a self) -> Cow<Path> {
|
|||
[self.home_dir.as_ref(), "challenges".as_ref()]
|
|||
.iter()
|
|||
.collect::<PathBuf>()
|
|||
.into()
|
|||
}
|
|||
pub fn get_init(&'a self) -> impl Symbol + 'a {
|
|||
let root_cert_path: PathBuf = [self.home_dir.as_ref(), ROOT_CERT_FILE_NAME.as_ref()]
|
|||
.iter()
|
|||
.collect();
|
|||
let account_key_file: PathBuf = [self.home_dir.as_ref(), ACCOUNT_KEY_FILE_NAME.as_ref()]
|
|||
.iter()
|
|||
.collect();
|
|||
List::from((
|
|||
AcmeAccountKey::new(account_key_file.clone(), self.command_runner),
|
|||
Owner::new(
|
|||
account_key_file,
|
|||
self.user_name.clone(),
|
|||
self.command_runner,
|
|||
),
|
|||
Dir::new(self.get_challenges_dir()),
|
|||
Owner::new(
|
|||
self.get_challenges_dir(),
|
|||
self.user_name.clone(),
|
|||
self.command_runner,
|
|||
),
|
|||
Dir::new("/etc/ssl/local_certs"),
|
|||
Owner::new(
|
|||
"/etc/ssl/local_certs",
|
|||
self.user_name.clone(),
|
|||
self.command_runner,
|
|||
),
|
|||
File::new(root_cert_path, self.cert.as_ref()),
|
|||
))
|
|||
}
|
|||
pub fn get_cert<HOST: 'a + Clone + AsRef<str>>(&'a self, host: HOST) -> impl Symbol + 'a {
|
|||
let root_cert_path: PathBuf = [self.home_dir.as_ref(), ROOT_CERT_FILE_NAME.as_ref()]
|
|||
.iter()
|
|||
.collect();
|
|||
let account_key_path: PathBuf = [self.home_dir.as_ref(), ACCOUNT_KEY_FILE_NAME.as_ref()]
|
|||
.iter()
|
|||
.collect();
|
|||
List::from((
|
|||
AcmeCert::new(
|
|||
host.clone(),
|
|||
&self.acme_command_runner,
|
|||
root_cert_path.clone(),
|
|||
account_key_path,
|
|||
self.get_challenges_dir(),
|
|||
),
|
|||
AcmeCertChain::new(host, &self.acme_command_runner, root_cert_path),
|
|||
))
|
|||
}
|
|||
}
|
@ -1,28 +0,0 @@ |
|||
use std::path::{Path, PathBuf};
|
|||
|
|||
use crate::command_runner::CommandRunner;
|
|||
use crate::symbols::acme::AcmeAccountKey;
|
|||
use crate::symbols::dir::Dir;
|
|||
use crate::symbols::file::File;
|
|||
use crate::symbols::list::List;
|
|||
use crate::symbols::owner::Owner;
|
|||
use crate::symbols::Symbol;
|
|||
|
|||
pub fn new<'a, R: CommandRunner, C: 'a + AsRef<str>, U: 'a + AsRef<str> + Clone, H: AsRef<Path>>(
|
|||
command_runner: &'a R,
|
|||
cert: C,
|
|||
user_name: U,
|
|||
home: H,
|
|||
) -> impl Symbol + 'a {
|
|||
let path = |rel: &str| [home.as_ref(), rel.as_ref()].iter().collect::<PathBuf>();
|
|||
let account_key_file = path("account.key");
|
|||
List::from((
|
|||
AcmeAccountKey::new(account_key_file.clone(), command_runner),
|
|||
Owner::new(account_key_file, user_name.clone(), command_runner),
|
|||
Dir::new(path("challenges")),
|
|||
Owner::new(path("challenges"), user_name.clone(), command_runner),
|
|||
Dir::new("/etc/ssl/local_certs"),
|
|||
Owner::new("/etc/ssl/local_certs", user_name, command_runner),
|
|||
File::new(path("lets_encrypt_x3_cross_signed.pem"), cert),
|
|||
))
|
|||
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue