From b773cc4e3e63dd90a4f38aa4f35bc6d1d0ac942d Mon Sep 17 00:00:00 2001 From: kartikohlan Date: Thu, 9 Jan 2025 13:01:03 -0500 Subject: [PATCH] Remove unnecessary file package main.go --- modules/caddyhttp/package main.go | 59 ------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 modules/caddyhttp/package main.go diff --git a/modules/caddyhttp/package main.go b/modules/caddyhttp/package main.go deleted file mode 100644 index 773f6491d..000000000 --- a/modules/caddyhttp/package main.go +++ /dev/null @@ -1,59 +0,0 @@ -package main - -import ( - "crypto/sha256" - "encoding/pem" - "fmt" - "net/http" - "os" - "strconv" -) - -func populateEnvFromClientCert(req *http.Request) { - if req.TLS == nil || len(req.TLS.VerifiedChains) == 0 { - fmt.Println("No client certificate provided") - return - } - - // Extract the client certificate - clientCert := req.TLS.VerifiedChains[0][0] - - // Populate environment variables - os.Setenv("SSL_CLIENT_CERT", string(pem.EncodeToMemory(&pem.Block{ - Type: "CERTIFICATE", - Bytes: clientCert.Raw, - }))) - os.Setenv("SSL_CLIENT_SUBJECT", clientCert.Subject.String()) - os.Setenv("SSL_CLIENT_ISSUER", clientCert.Issuer.String()) - os.Setenv("SSL_CLIENT_SERIAL", clientCert.SerialNumber.String()) - - // SANs (Subject Alternative Names) - for i, dns := range clientCert.DNSNames { - os.Setenv("SSL_CLIENT_SAN_DNS_"+strconv.Itoa(i), dns) - } - for i, email := range clientCert.EmailAddresses { - os.Setenv("SSL_CLIENT_SAN_EMAIL_"+strconv.Itoa(i), email) - } - for i, ip := range clientCert.IPAddresses { - os.Setenv("SSL_CLIENT_SAN_IP_"+strconv.Itoa(i), ip.String()) - } - for i, uri := range clientCert.URIs { - os.Setenv("SSL_CLIENT_SAN_URI_"+strconv.Itoa(i), uri.String()) - } - - // Example: Fingerprint - fingerprint := sha256.Sum256(clientCert.Raw) - os.Setenv("SSL_CLIENT_FINGERPRINT", fmt.Sprintf("%x", fingerprint)) -} - -func handler(w http.ResponseWriter, r *http.Request) { - // Populate environment variables - populateEnvFromClientCert(r) - - // Respond with the environment variables for testing - fmt.Fprintf(w, "SSL_CLIENT_CERT: %s\n", os.Getenv("SSL_CLIENT_CERT")) - fmt.Fprintf(w, "SSL_CLIENT_SUBJECT: %s\n", os.Getenv("SSL_CLIENT_SUBJECT")) - fmt.Fprintf(w, "SSL_CLIENT_ISSUER: %s\n", os.Getenv("SSL_CLIENT_ISSUER")) - fmt.Fprintf(w, "SSL_CLIENT_SERIAL: %s\n", os.Getenv("SSL_CLIENT_SERIAL")) - fmt.Fprintf(w, "SSL_CLIENT_FINGERPRINT: %s\n", os.Getenv("SSL_CLIENT_FINGERPRINT")) -}