1
0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2025-09-07 05:51:58 +02:00

server: Don't always assume TLS is used

This commit is contained in:
adnano 2020-12-18 01:02:04 -05:00
parent e6f6366708
commit 956c4bb5e4

@ -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,
}
}
}