mirror of
https://github.com/XTLS/REALITY.git
synced 2026-09-22 23:08:01 +03:00
crypto/tls: replace custom intern cache with weak cache
Uses the new weak package to replace the existing custom intern cache with a map of weak.Pointers instead. This simplifies the cache, and means we don't need to store a slice of handles on the Conn anymore. Change-Id: I5c2bf6ef35fac4255e140e184f4e48574b34174c Reviewed-on: https://go-review.googlesource.com/c/go/+/644176 TryBot-Bypass: Roland Shoemaker <roland@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Roland Shoemaker <roland@golang.org>
This commit is contained in:
+3
-7
@@ -949,7 +949,6 @@ func (hs *clientHandshakeState) processServerHello() (bool, error) {
|
||||
hs.masterSecret = hs.session.secret
|
||||
c.extMasterSecret = hs.session.extMasterSecret
|
||||
c.peerCertificates = hs.session.peerCertificates
|
||||
c.activeCertHandles = hs.c.activeCertHandles
|
||||
c.verifiedChains = hs.session.verifiedChains
|
||||
c.ocspResponse = hs.session.ocspResponse
|
||||
// Let the ServerHello SCTs override the session SCTs from the original
|
||||
@@ -1100,7 +1099,6 @@ func checkKeySize(n int) (max int, ok bool) {
|
||||
// verifyServerCertificate parses and verifies the provided chain, setting
|
||||
// c.verifiedChains and c.peerCertificates or sending the appropriate alert.
|
||||
func (c *Conn) verifyServerCertificate(certificates [][]byte) error {
|
||||
activeHandles := make([]*activeCert, len(certificates))
|
||||
certs := make([]*x509.Certificate, len(certificates))
|
||||
for i, asn1Data := range certificates {
|
||||
cert, err := globalCertCache.newCert(asn1Data)
|
||||
@@ -1108,15 +1106,14 @@ func (c *Conn) verifyServerCertificate(certificates [][]byte) error {
|
||||
c.sendAlert(alertDecodeError)
|
||||
return errors.New("tls: failed to parse certificate from server: " + err.Error())
|
||||
}
|
||||
if cert.cert.PublicKeyAlgorithm == x509.RSA {
|
||||
n := cert.cert.PublicKey.(*rsa.PublicKey).N.BitLen()
|
||||
if cert.PublicKeyAlgorithm == x509.RSA {
|
||||
n := cert.PublicKey.(*rsa.PublicKey).N.BitLen()
|
||||
if max, ok := checkKeySize(n); !ok {
|
||||
c.sendAlert(alertBadCertificate)
|
||||
return fmt.Errorf("tls: server sent certificate containing RSA key larger than %d bits", max)
|
||||
}
|
||||
}
|
||||
activeHandles[i] = cert
|
||||
certs[i] = cert.cert
|
||||
certs[i] = cert
|
||||
}
|
||||
|
||||
echRejected := c.config.EncryptedClientHelloConfigList != nil && !c.echAccepted
|
||||
@@ -1181,7 +1178,6 @@ func (c *Conn) verifyServerCertificate(certificates [][]byte) error {
|
||||
return fmt.Errorf("tls: server's certificate contains an unsupported type of public key: %T", certs[0].PublicKey)
|
||||
}
|
||||
|
||||
c.activeCertHandles = activeHandles
|
||||
c.peerCertificates = certs
|
||||
|
||||
if c.config.VerifyPeerCertificate != nil && !echRejected {
|
||||
|
||||
Reference in New Issue
Block a user