Skip to content

Commit dd73b31

Browse files
committed
clear ssl certs & restart server when "no certificates" is selected
1 parent b55ecd4 commit dd73b31

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

proto

src/grpc.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub(crate) struct ProxyServer {
5656
cert_dir: PathBuf,
5757
reset_tx: broadcast::Sender<()>,
5858
https_cert_tx: broadcast::Sender<(String, String)>,
59+
clear_https_tx: broadcast::Sender<()>,
5960
/// `Some` only when the main HTTP server is bound to port 80.
6061
/// Used to hand off port 80 gracefully during ACME HTTP-01 challenges.
6162
port80_pause_tx: Option<mpsc::Sender<(oneshot::Sender<()>, oneshot::Receiver<()>)>>,
@@ -73,6 +74,7 @@ impl ProxyServer {
7374
cert_dir: PathBuf,
7475
reset_tx: broadcast::Sender<()>,
7576
https_cert_tx: broadcast::Sender<(String, String)>,
77+
clear_https_tx: broadcast::Sender<()>,
7678
port80_pause_tx: Option<mpsc::Sender<(oneshot::Sender<()>, oneshot::Receiver<()>)>>,
7779
logs_rx: LogsReceiver,
7880
acme_staging: bool,
@@ -88,6 +90,7 @@ impl ProxyServer {
8890
cert_dir,
8991
reset_tx,
9092
https_cert_tx,
93+
clear_https_tx,
9194
port80_pause_tx,
9295
logs_rx,
9396
acme_staging,
@@ -213,6 +216,7 @@ impl Clone for ProxyServer {
213216
cert_dir: self.cert_dir.clone(),
214217
reset_tx: self.reset_tx.clone(),
215218
https_cert_tx: self.https_cert_tx.clone(),
219+
clear_https_tx: self.clear_https_tx.clone(),
216220
port80_pause_tx: self.port80_pause_tx.clone(),
217221
logs_rx: Arc::clone(&self.logs_rx),
218222
acme_staging: self.acme_staging,
@@ -267,6 +271,7 @@ impl proxy_server::Proxy for ProxyServer {
267271
let connected = Arc::clone(&self.connected);
268272
let cookie_key = Arc::clone(&self.cookie_key);
269273
let https_cert_tx = self.https_cert_tx.clone();
274+
let clear_https_tx = self.clear_https_tx.clone();
270275
tokio::spawn(
271276
async move {
272277
let mut stream = request.into_inner();
@@ -292,6 +297,12 @@ impl proxy_server::Proxy for ProxyServer {
292297
);
293298
}
294299
}
300+
core_response::Payload::ClearHttpsCerts(_) => {
301+
info!("Received ClearHttpsCerts from Core");
302+
if let Err(err) = clear_https_tx.send(()) {
303+
error!("Failed to broadcast ClearHttpsCerts: {err}");
304+
}
305+
}
295306
other => {
296307
let maybe_rx = results.write().expect("Failed to acquire lock on results hashmap when processing response").remove(&response.id);
297308
if let Some(rx) = maybe_rx {

src/http.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ pub async fn run_server(
316316
let cookie_key = Arc::default();
317317
let (reset_tx, mut reset_rx) = tokio::sync::broadcast::channel(1);
318318
let (https_cert_tx, https_cert_rx) = broadcast::channel::<(String, String)>(1);
319+
let (clear_https_tx, clear_https_rx) = broadcast::channel::<()>(1);
319320

320321
// When the main HTTP server is on port 80, create a channel so the ACME task can request
321322
// a graceful hand-off of port 80 before binding its temporary challenge listener.
@@ -337,6 +338,7 @@ pub async fn run_server(
337338
env_config.cert_dir.clone(),
338339
reset_tx,
339340
https_cert_tx,
341+
clear_https_tx,
340342
port80_pause_tx,
341343
Arc::clone(&logs_rx),
342344
env_config.acme_staging,
@@ -516,6 +518,7 @@ pub async fn run_server(
516518
);
517519
let mut current_tls: Option<(String, String)> = None;
518520
let mut https_cert_rx = https_cert_rx;
521+
let mut clear_https_rx = clear_https_rx;
519522
let mut port80_pause_rx = port80_pause_rx;
520523

521524
loop {
@@ -571,6 +574,23 @@ pub async fn run_server(
571574
}
572575
}
573576
}
577+
result = clear_https_rx.recv() => {
578+
match result {
579+
Ok(()) => {
580+
info!("Received ClearHttpsCerts, restarting web server without TLS");
581+
current_tls = None;
582+
handle.graceful_shutdown(Some(Duration::from_secs(30)));
583+
let _ = server_task.await;
584+
}
585+
Err(broadcast::error::RecvError::Lagged(_)) => {
586+
warn!("Missed ClearHttpsCerts update; will apply next one");
587+
}
588+
Err(broadcast::error::RecvError::Closed) => {
589+
error!("ClearHttpsCerts channel closed unexpectedly");
590+
break;
591+
}
592+
}
593+
}
574594
// An ACME task needs port 80: gracefully stop the current HTTP server,
575595
// signal the task that port 80 is free, wait until it's done, then let
576596
// the loop restart the server.

0 commit comments

Comments
 (0)