From 935ef4fc26c628809f693d9cb4e2aca80ebf7428 Mon Sep 17 00:00:00 2001 From: Christian Krakau-Louis Date: Tue, 18 Feb 2025 16:49:18 +0100 Subject: [PATCH] added /cert.cer mux to download certificate for Windows --- main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.go b/main.go index 7ee257a..46d888b 100644 --- a/main.go +++ b/main.go @@ -274,6 +274,17 @@ func caHandler(w http.ResponseWriter, r *http.Request) { w.Write(caData) } +// caDERHandler serves the CA certificate in DER format. +func caDERHandler(w http.ResponseWriter, r *http.Request) { + if caCert == nil { + http.Error(w, "CA not loaded", http.StatusInternalServerError) + return + } + // The DER-encoded certificate is available as caCert.Raw. + w.Header().Set("Content-Type", "application/x-x509-ca-cert") + w.Write(caCert.Raw) +} + // blockHandler serves the block page. func blockHandler(w http.ResponseWriter, r *http.Request) { log.Printf("Serving block page for %s", r.URL.String()) @@ -322,6 +333,8 @@ func main() { mux.Handle("/webroot/", http.StripPrefix("/webroot/", http.FileServer(http.Dir("webroot")))) // All other requests show the block page. mux.HandleFunc("/", blockHandler) + // Route to serve the CA certificate in DER format. + mux.HandleFunc("/cert.cer", caDERHandler) // Create a TLS configuration with our dynamic certificate callback. tlsConfig := &tls.Config{