Skip to content

Commit

Permalink
More review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Mar 22, 2024
1 parent 883da06 commit dbec47f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 2 additions & 7 deletions rust/agama-server/src/agama-web-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ impl ServeArgs {

tls_builder.set_private_key(&key)?;
tls_builder.set_certificate(&cert)?;

// for debugging you might dump the certificate to a file:
// use std::io::Write;
// let mut cert_file = std::fs::File::create("agama_cert.pem").unwrap();
// let mut key_file = std::fs::File::create("agama_key.pem").unwrap();
// cert_file.write_all(cert.to_pem().unwrap().as_ref()).unwrap();
// key_file.write_all(key.private_key_to_pem_pkcs8().unwrap().as_ref()).unwrap();
} else {
tracing::info!("Loading PEM certificate: {}", self.cert);
tls_builder.set_certificate_file(PathBuf::from(self.cert.clone()), SslFiletype::PEM)?;
Expand Down Expand Up @@ -280,6 +273,8 @@ async fn serve_command(args: ServeArgs) -> anyhow::Result<()> {
let dbus = connection_to(&args.dbus_address).await?;
let service = web::service(config, tx, dbus).await?;

// TODO: Move elsewhere? Use a singleton? (It would be nice to use the same
// generated self-signed certificate on both ports.)
let ssl_acceptor = if let Ok(ssl_acceptor) = args.ssl_acceptor() {
ssl_acceptor
} else {
Expand Down
7 changes: 7 additions & 0 deletions rust/agama-server/src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,12 @@ pub fn create_certificate() -> Result<(X509, PKey<Private>), ErrorStack> {
builder.sign(&key, MessageDigest::sha256())?;
let cert = builder.build();

// for debugging you might dump the certificate to a file:
// use std::io::Write;
// let mut cert_file = std::fs::File::create("agama_cert.pem").unwrap();
// let mut key_file = std::fs::File::create("agama_key.pem").unwrap();
// cert_file.write_all(cert.to_pem().unwrap().as_ref()).unwrap();
// key_file.write_all(key.private_key_to_pem_pkcs8().unwrap().as_ref()).unwrap();

Ok((cert, key))
}

0 comments on commit dbec47f

Please sign in to comment.