github.com/letsencrypt/boulder@v0.20251208.0/test/chall-test-srv/tlsalpnone.go (about) 1 package main 2 3 import "net/http" 4 5 // addTLSALPN01 handles an HTTP POST request to add a new TLS-ALPN-01 challenge 6 // response certificate for a given host. 7 // 8 // The POST body is expected to have two non-empty parameters: 9 // "host" - the hostname to add the challenge response certificate for. 10 // "content" - the key authorization value to use to construct the TLS-ALPN-01 11 // challenge response certificate. 12 // 13 // A successful POST will write http.StatusOK to the client. 14 func (srv *managementServer) addTLSALPN01(w http.ResponseWriter, r *http.Request) { 15 // Unmarshal the request body JSON as a request object 16 var request struct { 17 Host string 18 Content string 19 } 20 if err := mustParsePOST(&request, r); err != nil { 21 http.Error(w, err.Error(), http.StatusBadRequest) 22 return 23 } 24 25 // If the request has an empty host or content it's a bad request 26 if request.Host == "" || request.Content == "" { 27 w.WriteHeader(http.StatusBadRequest) 28 return 29 } 30 31 // Add the TLS-ALPN-01 challenge to the challenge server 32 srv.challSrv.AddTLSALPNChallenge(request.Host, request.Content) 33 srv.log.Printf("Added TLS-ALPN-01 challenge for host %q - key auth %q\n", 34 request.Host, request.Content) 35 w.WriteHeader(http.StatusOK) 36 } 37 38 // delTLSALPN01 handles an HTTP POST request to delete an existing TLS-ALPN-01 39 // challenge response for a given host. 40 // 41 // The POST body is expected to have one non-empty parameter: 42 // "host" - the hostname to remove the TLS-ALPN-01 challenge response for. 43 // 44 // A successful POST will write http.StatusOK to the client. 45 func (srv *managementServer) delTLSALPN01(w http.ResponseWriter, r *http.Request) { 46 // Unmarshal the request body JSON as a request object 47 var request struct { 48 Host string 49 } 50 if err := mustParsePOST(&request, r); err != nil { 51 http.Error(w, err.Error(), http.StatusBadRequest) 52 return 53 } 54 55 // If the request has an empty host it's a bad request 56 if request.Host == "" { 57 w.WriteHeader(http.StatusBadRequest) 58 return 59 } 60 61 // Delete the TLS-ALPN-01 challenge for the given host from the challenge server 62 srv.challSrv.DeleteTLSALPNChallenge(request.Host) 63 srv.log.Printf("Removed TLS-ALPN-01 challenge for host %q\n", request.Host) 64 w.WriteHeader(http.StatusOK) 65 }