Skip to content

Commit 33debc8

Browse files
rochaportosdelicata
authored andcommitted
Add output of client certificate
When used with cert/key pair, make sure we request the client certificate and display the subject as part of the whoami output.
1 parent b49779d commit 33debc8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

app.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ func main() {
8585
}
8686

8787
server := &http.Server{
88-
Addr: ":" + port,
89-
Handler: mux,
88+
Addr: ":" + port,
89+
TLSConfig: &tls.Config{ClientAuth: tls.RequestClientCert},
90+
Handler: mux,
9091
}
9192

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

232233
_, _ = fmt.Fprintln(w, "RemoteAddr:", r.RemoteAddr)
234+
235+
if r.TLS != nil {
236+
for i, cert := range r.TLS.PeerCertificates {
237+
fmt.Fprintf(w, "Certificate[%d] Subject: %v\n", i, cert.Subject)
238+
}
239+
}
240+
233241
if err := r.Write(w); err != nil {
234242
http.Error(w, err.Error(), http.StatusInternalServerError)
235243
return

0 commit comments

Comments
 (0)