Skip to content

Commit e0d95fb

Browse files
Ensure acme server is stopped when challenge fails (#275)
1 parent 3547183 commit e0d95fb

1 file changed

Lines changed: 34 additions & 28 deletions

File tree

src/acme.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -243,50 +243,56 @@ pub async fn run_acme_http01(
243243
}
244244
});
245245

246-
// Now populate the challenge map and notify LE - server is already up.
247-
let mut authorizations = order.authorizations();
246+
let validation_result = async {
247+
// Now populate the challenge map and notify LE - server is already up.
248+
let mut authorizations = order.authorizations();
248249

249-
while let Some(result) = authorizations.next().await {
250-
let mut authz = result.context("Failed to retrieve ACME authorization")?;
251-
let mut challenge = authz
252-
.challenge(ChallengeType::Http01)
253-
.ok_or_else(|| anyhow!("ACME server did not offer HTTP-01 challenge"))?;
250+
while let Some(result) = authorizations.next().await {
251+
let mut authz = result.context("Failed to retrieve ACME authorization")?;
252+
let mut challenge = authz
253+
.challenge(ChallengeType::Http01)
254+
.ok_or_else(|| anyhow!("ACME server did not offer HTTP-01 challenge"))?;
254255

255-
let token = challenge.token.clone();
256-
let key_auth = challenge.key_authorization().as_str().to_owned();
256+
let token = challenge.token.clone();
257+
let key_auth = challenge.key_authorization().as_str().to_owned();
257258

258-
info!("Preparing HTTP-01 challenge for domain: {domain} (token: {token})");
259+
info!("Preparing HTTP-01 challenge for domain: {domain} (token: {token})");
259260

260-
{
261-
let mut map = challenge_map.lock().unwrap();
262-
map.insert(token, key_auth);
261+
{
262+
let mut map = challenge_map.lock().unwrap();
263+
map.insert(token, key_auth);
264+
}
265+
266+
challenge
267+
.set_ready()
268+
.await
269+
.context("Failed to signal ACME challenge as ready")?;
270+
info!("HTTP-01 challenge signalled as ready; waiting for Let's Encrypt to validate");
263271
}
264272

265-
challenge
266-
.set_ready()
273+
// LE will now attempt HTTP-01 validation against our challenge server.
274+
let _ = progress_tx.send(AcmeStep::ValidatingDomain);
275+
info!("Polling Let's Encrypt for domain validation result...");
276+
277+
// Wait for the order to become ready for finalization.
278+
order
279+
.poll_ready(&RetryPolicy::default())
267280
.await
268-
.context("Failed to signal ACME challenge as ready")?;
269-
info!("HTTP-01 challenge signalled as ready; waiting for Let's Encrypt to validate");
281+
.context("ACME order did not become ready")
270282
}
271-
272-
// LE will now attempt HTTP-01 validation against our challenge server.
273-
let _ = progress_tx.send(AcmeStep::ValidatingDomain);
274-
info!("Polling Let's Encrypt for domain validation result...");
275-
276-
// Wait for the order to become ready for finalization.
277-
let status = order
278-
.poll_ready(&RetryPolicy::default())
279-
.await
280-
.context("ACME order did not become ready")?;
281-
info!("Domain validation complete, order status: {status:?}");
283+
.await;
282284

283285
server_handle.abort();
286+
let _ = server_handle.await;
284287
info!("ACME challenge server shut down; port 80 released");
285288

286289
if let Some(done_tx) = port80_permit {
287290
let _ = done_tx.send(());
288291
}
289292

293+
let status = validation_result?;
294+
info!("Domain validation complete, order status: {status:?}");
295+
290296
// Domain validated; finalizing order and retrieving the certificate.
291297
let _ = progress_tx.send(AcmeStep::IssuingCertificate);
292298
info!("Finalizing ACME order and requesting certificate issuance...");

0 commit comments

Comments
 (0)