Skip to content

Commit

Permalink
Add output of client certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
rochaporto authored Feb 17, 2025
1 parent b49779d commit 7e57190
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ func main() {
}

server := &http.Server{
Addr: ":" + port,
Handler: mux,
Addr: ":" + port,
TLSConfig: &tls.Config{ClientAuth: tls.RequestClientCert},
Handler: mux,
}

if ca != "" {
Expand Down Expand Up @@ -230,6 +231,13 @@ func whoamiHandler(w http.ResponseWriter, r *http.Request) {
}

_, _ = 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 {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down

0 comments on commit 7e57190

Please sign in to comment.