diff --git a/app/main.py b/app/main.py index db9d932..974235d 100644 --- a/app/main.py +++ b/app/main.py @@ -5,6 +5,7 @@ from pathlib import Path from secrets import token_urlsafe from typing import cast +import httpx from cryptography import x509 from cryptography.hazmat.primitives import hashes, serialization from cryptography.hazmat.primitives.asymmetric.types import ( @@ -18,7 +19,7 @@ from app.types import CSR, CertificateChainResponse CONFIG_DIR = Path("config") if not path.exists(CONFIG_DIR): raise RuntimeError( - f"Configuration directory '{CONFIG_DIR}' does not exist. Please create it and add the necessary files." + f"Configuration directory '{CONFIG_DIR}' does not exist. Please create it using ./init.sh" ) CA_PRIVATE_KEY = cast( @@ -77,20 +78,20 @@ async def finalize_order(order_id: str, req: FinalizeRequest): ) order = orders[order_id] - # try: - # well_known_url = f"http://{order.domain}:{order.port}/.well-known/acme-challenge/{order.authorization}" - # async with httpx.AsyncClient() as client: - # resp = await client.get(well_known_url, timeout=5) - # if resp.status_code != 200 or resp.text.strip() != order.authorization: - # raise HTTPException( - # status_code=status.HTTP_400_BAD_REQUEST, - # detail="Invalid challenge", - # ) - # except httpx.RequestError: - # raise HTTPException( - # status_code=status.HTTP_400_BAD_REQUEST, - # detail="Challenge request failed", - # ) + try: + well_known_url = f"http://{order.domain}:{order.port}/.well-known/acme-challenge/{order.authorization}" + async with httpx.AsyncClient() as client: + resp = await client.get(well_known_url, timeout=5) + if resp.status_code != 200 or resp.text.strip() != order.authorization: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="Invalid challenge", + ) + except httpx.RequestError: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="Challenge request failed", + ) cert_builder = ( x509.CertificateBuilder() diff --git a/init.sh b/init.sh old mode 100644 new mode 100755