Add output of client certificate

This commit is contained in:
Ricardo Rocha
2025-02-17 15:12:04 +01:00
committed by GitHub
parent b49779da68
commit 7e57190724

8
app.go
View File

@ -86,6 +86,7 @@ func main() {
server := &http.Server{ server := &http.Server{
Addr: ":" + port, Addr: ":" + port,
TLSConfig: &tls.Config{ClientAuth: tls.RequestClientCert},
Handler: mux, Handler: mux,
} }
@ -230,6 +231,13 @@ func whoamiHandler(w http.ResponseWriter, r *http.Request) {
} }
_, _ = fmt.Fprintln(w, "RemoteAddr:", r.RemoteAddr) _, _ = fmt.Fprintln(w, "RemoteAddr:", r.RemoteAddr)
if r.TLS != nil {
for i, cert := range r.TLS.PeerCertificates {
_, _ = fmt.Fprintf(w, "Certificate[%d] Subject: %v\n", i, cert.Subject)
}
}
if err := r.Write(w); err != nil { if err := r.Write(w); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return