mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2026-02-04 08:18:34 +00:00
fix: don't panic if not given tls connection in pin checker
This commit is contained in:
@ -24,6 +24,7 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
@ -50,7 +51,12 @@ func newPinChecker(trustedPins []string) pinChecker {
|
|||||||
|
|
||||||
// checkCertificate returns whether the connection presents a known TLS certificate.
|
// checkCertificate returns whether the connection presents a known TLS certificate.
|
||||||
func (p *pinChecker) checkCertificate(conn net.Conn) error {
|
func (p *pinChecker) checkCertificate(conn net.Conn) error {
|
||||||
connState := conn.(*tls.Conn).ConnectionState()
|
tlsConn, ok := conn.(*tls.Conn)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("connection is not a TLS connection")
|
||||||
|
}
|
||||||
|
|
||||||
|
connState := tlsConn.ConnectionState()
|
||||||
|
|
||||||
for _, peerCert := range connState.PeerCertificates {
|
for _, peerCert := range connState.PeerCertificates {
|
||||||
fingerprint := certFingerprint(peerCert)
|
fingerprint := certFingerprint(peerCert)
|
||||||
|
|||||||
Reference in New Issue
Block a user