Skip to content

Commit 78aaa81

Browse files
committed
Fix daemon regenerating certs and breaking trust store CA match
load_or_create_bundle was identical to ensure_bundle — both called generate_bundle, so the daemon process regenerated CA+server certs after helper_start already installed the original CA to the trust store. The mismatch caused ERR_CERT_AUTHORITY_INVALID in browsers. Refactor: split into ensure_bundle (generates, used by setup paths) and load_bundle (read-only, used by daemon). Extract bundle_paths to deduplicate path construction.
1 parent 4f48107 commit 78aaa81

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

src/certs.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::hash::{Hash, Hasher};
44
use std::io::ErrorKind;
55
use std::path::{Path, PathBuf};
66

7-
use anyhow::{Context, Result, anyhow};
7+
use anyhow::{Context, Result, anyhow, bail};
88
use rcgen::{
99
BasicConstraints, Certificate, CertificateParams, DistinguishedName, DnType,
1010
ExtendedKeyUsagePurpose, IsCa, KeyUsagePurpose,
@@ -28,20 +28,31 @@ pub fn ensure_bundle(config: &AppConfig, root: &Path) -> Result<CertificateBundl
2828
generate_bundle(config, root)
2929
}
3030

31-
pub fn load_or_create_bundle(config: &AppConfig, root: &Path) -> Result<CertificateBundle> {
32-
generate_bundle(config, root)
31+
pub fn load_bundle(root: &Path) -> Result<CertificateBundle> {
32+
let bundle = bundle_paths(root);
33+
if !bundle_all_exist(&bundle) {
34+
bail!(
35+
"certificate files not found in {}; run setup first",
36+
root.display()
37+
);
38+
}
39+
Ok(bundle)
40+
}
41+
42+
fn bundle_paths(root: &Path) -> CertificateBundle {
43+
CertificateBundle {
44+
ca_cert_path: root.join("linuxdo-accelerator-root-ca.crt"),
45+
server_cert_path: root.join("linuxdo-accelerator-server.crt"),
46+
server_key_path: root.join("linuxdo-accelerator-server.key"),
47+
}
3348
}
3449

3550
fn generate_bundle(config: &AppConfig, root: &Path) -> Result<CertificateBundle> {
3651
let cert_dir = root.to_path_buf();
3752
fs::create_dir_all(&cert_dir)
3853
.with_context(|| format!("failed to create {}", cert_dir.display()))?;
3954

40-
let bundle = CertificateBundle {
41-
ca_cert_path: cert_dir.join("linuxdo-accelerator-root-ca.crt"),
42-
server_cert_path: cert_dir.join("linuxdo-accelerator-server.crt"),
43-
server_key_path: cert_dir.join("linuxdo-accelerator-server.key"),
44-
};
55+
let bundle = bundle_paths(&cert_dir);
4556

4657
let domains_hash_path = cert_dir.join("linuxdo-accelerator-domains.sha256");
4758
let current_hash = domains_hash(&config.certificate_domains);

src/service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
1010
use anyhow::{Result, bail};
1111
use tokio::sync::watch;
1212

13-
use crate::certs::{ensure_bundle, load_or_create_bundle};
13+
use crate::certs::{ensure_bundle, load_bundle};
1414
use crate::config::AppConfig;
1515
use crate::hosts::{
1616
apply_hosts, backup_hosts_file, remove_hosts, restore_hosts_file,
@@ -97,7 +97,7 @@ pub async fn run_foreground(config_path: Option<PathBuf>, with_setup: bool) -> R
9797
let bundle = if with_setup {
9898
ensure_bundle(&config, &paths.cert_dir)?
9999
} else {
100-
load_or_create_bundle(&config, &paths.cert_dir)?
100+
load_bundle(&paths.cert_dir)?
101101
};
102102
if with_setup {
103103
install_ca(&bundle.ca_cert_path, &config.ca_common_name)?;

0 commit comments

Comments
 (0)