Skip to main content

postrust_proxy/saas/handlers/
wellknown.rs

1//! Well-known endpoint handlers for domain verification.
2
3use crate::saas::handlers::SaasState;
4use axum::{
5    extract::{Path, State},
6    http::StatusCode,
7    response::IntoResponse,
8};
9
10/// Handle HTTP verification challenge.
11///
12/// This endpoint serves the verification content for HTTP domain verification.
13/// It responds at `/.well-known/postrust-verification/{token}` with the expected
14/// verification content.
15pub async fn handle_verification_challenge(
16    State(_state): State<SaasState>,
17    Path(token): Path<String>,
18) -> impl IntoResponse {
19    // Note: We need direct pool access, which isn't available through domain_manager
20    // For now, return a placeholder. In production, this would query the challenge.
21
22    // For HTTP verification, the challenge expected_value is: postrust-verify={token}
23    // We need to verify the token exists and is valid
24
25    // Simplified implementation - in production you'd look up the challenge in DB
26    let expected_content = format!("postrust-verify={}", token);
27
28    // Return the verification content
29    // In a real implementation, you'd verify the token exists in the database first
30    (StatusCode::OK, expected_content)
31}
32
33/// Handle ACME HTTP-01 challenge.
34///
35/// This endpoint serves ACME HTTP-01 challenges for automatic certificate provisioning.
36/// It responds at `/.well-known/acme-challenge/{token}`.
37pub async fn handle_acme_challenge(
38    State(_state): State<SaasState>,
39    Path(_token): Path<String>,
40) -> impl IntoResponse {
41    // ACME challenges would be handled by the ACME module
42    // This is a placeholder for integration
43    (StatusCode::NOT_FOUND, "ACME challenge not found")
44}