Skip to content

Commit

Permalink
Fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Jun 4, 2024
1 parent f742a1c commit 5ca6a82
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
21 changes: 7 additions & 14 deletions rust/agama-server/src/agama-web-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,14 @@ struct ServeArgs {
#[arg(long, default_value = None)]
address2: Option<String>,

#[arg(
long,
default_value = "/etc/agama.d/ssl/key.pem",
)]
#[arg(long, default_value = "/etc/agama.d/ssl/key.pem")]
key: Option<PathBuf>,

#[arg(
long,
default_value = "/etc/agama.d/ssl/cert.pem",
)]
#[arg(long, default_value = "/etc/agama.d/ssl/cert.pem")]
cert: Option<PathBuf>,

// Agama D-Bus address
#[arg(
long,
default_value = "unix:path=/run/agama/bus",
)]
#[arg(long, default_value = "unix:path=/run/agama/bus")]
dbus_address: String,

// Directory containing the web UI code
Expand Down Expand Up @@ -135,12 +126,14 @@ impl ServeArgs {
let _ = certificate.write();

Ok(certificate)
}
};
}
}

/// Builds an SSL acceptor using a provided SSL certificate or generates a self-signed one
fn ssl_acceptor(certificate: &agama_server::cert::Certificate) -> Result<SslAcceptor, openssl::error::ErrorStack> {
fn ssl_acceptor(
certificate: &agama_server::cert::Certificate,
) -> Result<SslAcceptor, openssl::error::ErrorStack> {
let mut tls_builder = SslAcceptor::mozilla_modern_v5(SslMethod::tls_server())?;

tls_builder.set_private_key(&certificate.key)?;
Expand Down
15 changes: 7 additions & 8 deletions rust/agama-server/src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Certificate {
/// Writes cert, key to (for now well known) location(s)
pub fn write(&self) -> anyhow::Result<()> {
// check and create default dir if needed
if ! Path::new(DEFAULT_CERT_DIR).is_dir() {
if !Path::new(DEFAULT_CERT_DIR).is_dir() {
std::fs::create_dir_all(DEFAULT_CERT_DIR)?;
}

Expand All @@ -42,11 +42,8 @@ impl Certificate {
let cert = X509::from_pem(&cert_bytes.as_slice());
let key = PKey::private_key_from_pem(&key_bytes.as_slice());

if let (Ok(c),Ok(k)) = (cert, key) {
Ok(Certificate {
cert: c,
key: k,
})
if let (Ok(c), Ok(k)) = (cert, key) {
Ok(Certificate { cert: c, key: k })
} else {
Err(anyhow::anyhow!("Failed to read certificate"))
}
Expand All @@ -57,7 +54,9 @@ impl Certificate {
let rsa = Rsa::generate(2048)?;
let key = PKey::from_rsa(rsa)?;

let hostname = gethostname().into_string().unwrap_or(String::from("localhost"));
let hostname = gethostname()
.into_string()
.unwrap_or(String::from("localhost"));
let mut x509_name = X509NameBuilder::new()?;
x509_name.append_entry_by_text("O", "Agama")?;
x509_name.append_entry_by_text("CN", hostname.as_str())?;
Expand Down Expand Up @@ -103,7 +102,7 @@ impl Certificate {

Ok(Certificate {
cert: cert,
key: key
key: key,
})
}
}

0 comments on commit 5ca6a82

Please sign in to comment.