From 6af079eb6b54bab0437be1e445980dc8db2d2885 Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Tue, 21 May 2024 10:12:06 +0200 Subject: [PATCH] Modified and improved default way how to store self generated cert --- rust/agama-server/src/cert.rs | 12 ++++++++---- service/Gemfile.lock | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/rust/agama-server/src/cert.rs b/rust/agama-server/src/cert.rs index 17e2d2e8c6..e5ad924bd0 100644 --- a/rust/agama-server/src/cert.rs +++ b/rust/agama-server/src/cert.rs @@ -27,16 +27,20 @@ use openssl::x509::{X509NameBuilder, X509}; // pub write(...) // } -const DEFAULT_CERT_FILE: &str = "/run/agama/cert.pem"; -const DEFAULT_KEY_FILE: &str = "/run/agama/key.pem"; +const DEFAULT_CERT_DIR: &str = "/run/agama/ssl"; /// Writes the certificate and the key to the well known location pub fn write_certificate(cert: X509, key: PKey) -> anyhow::Result<()> { + // check and create default dir if needed + if ! Path::new(DEFAULT_CERT_DIR).is_dir() { + std::fs::create_dir_all(DEFAULT_CERT_DIR)?; + } + if let Ok(bytes) = cert.to_pem() { - fs::write(Path::new(DEFAULT_CERT_FILE), bytes)?; + fs::write(Path::new(DEFAULT_CERT_DIR).join("cert.pem"), bytes)?; } if let Ok(bytes) = key.public_key_to_pem() { - fs::write(Path::new(DEFAULT_KEY_FILE), bytes)?; + fs::write(Path::new(DEFAULT_CERT_DIR).join("key.pem"), bytes)?; } Ok(()) diff --git a/service/Gemfile.lock b/service/Gemfile.lock index 9f8554476d..bd4caece52 100755 --- a/service/Gemfile.lock +++ b/service/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - agama-yast (7.devel737) + agama-yast (7.devel1132) cfa (~> 1.0.2) cfa_grub2 (~> 2.0.0) cheetah (~> 1.0.0) @@ -75,4 +75,4 @@ DEPENDENCIES yard (~> 0.9.0) BUNDLED WITH - 2.4.22 + 2.5.3