From c329a2487e4fde2a0a2401708afc23dfbafcce38 Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Fri, 18 Dec 2020 01:02:04 -0500 Subject: [PATCH] server: Don't always assume TLS is used --- server.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/server.go b/server.go index 9058aea..93b3d13 100644 --- a/server.go +++ b/server.go @@ -204,14 +204,17 @@ func (s *Server) respond(conn net.Conn) { w.WriteStatus(StatusBadRequest) } else { // Store information about the TLS connection - connState := conn.(*tls.Conn).ConnectionState() + var connState tls.ConnectionState var cert *tls.Certificate - if len(connState.PeerCertificates) > 0 { - peerCert := connState.PeerCertificates[0] - // Store the TLS certificate - cert = &tls.Certificate{ - Certificate: [][]byte{peerCert.Raw}, - Leaf: peerCert, + if tlsConn, ok := conn.(*tls.Conn); ok { + connState = tlsConn.ConnectionState() + if len(connState.PeerCertificates) > 0 { + peerCert := connState.PeerCertificates[0] + // Store the TLS certificate + cert = &tls.Certificate{ + Certificate: [][]byte{peerCert.Raw}, + Leaf: peerCert, + } } }