mirror of
https://github.com/XTLS/REALITY.git
synced 2026-09-22 23:08:01 +03:00
crypto/tls: add GODEBUG to control max RSA key size (set to default)
Add a new GODEBUG setting, tlsmaxrsasize, which allows controlling the maximum RSA key size we will accept during TLS handshakes. Change-Id: I52f060be132014d219f4cd438f59990011a35c96 Reviewed-on: https://go-review.googlesource.com/c/go/+/517495 Auto-Submit: Roland Shoemaker <roland@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
+22
-5
@@ -936,9 +936,23 @@ func (hs *clientHandshakeState) sendFinished(out []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// maxRSAKeySize is the maximum RSA key size in bits that we are willing
|
||||
// defaultMaxRSAKeySize is the maximum RSA key size in bits that we are willing
|
||||
// to verify the signatures of during a TLS handshake.
|
||||
const maxRSAKeySize = 8192
|
||||
const defaultMaxRSAKeySize = 8192
|
||||
|
||||
//var tlsmaxrsasize = godebug.New("tlsmaxrsasize")
|
||||
|
||||
func checkKeySize(n int) (max int, ok bool) {
|
||||
// if v := tlsmaxrsasize.Value(); v != "" {
|
||||
// if max, err := strconv.Atoi(v); err == nil {
|
||||
// if (n <= max) != (n <= defaultMaxRSAKeySize) {
|
||||
// tlsmaxrsasize.IncNonDefault()
|
||||
// }
|
||||
// return max, n <= max
|
||||
// }
|
||||
// }
|
||||
return defaultMaxRSAKeySize, n <= defaultMaxRSAKeySize
|
||||
}
|
||||
|
||||
// verifyServerCertificate parses and verifies the provided chain, setting
|
||||
// c.verifiedChains and c.peerCertificates or sending the appropriate alert.
|
||||
@@ -951,9 +965,12 @@ func (c *Conn) verifyServerCertificate(certificates [][]byte) error {
|
||||
c.sendAlert(alertBadCertificate)
|
||||
return errors.New("tls: failed to parse certificate from server: " + err.Error())
|
||||
}
|
||||
if cert.cert.PublicKeyAlgorithm == x509.RSA && cert.cert.PublicKey.(*rsa.PublicKey).N.BitLen() > maxRSAKeySize {
|
||||
c.sendAlert(alertBadCertificate)
|
||||
return fmt.Errorf("tls: server sent certificate containing RSA key larger than %d bits", maxRSAKeySize)
|
||||
if cert.cert.PublicKeyAlgorithm == x509.RSA {
|
||||
n := cert.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
|
||||
|
||||
Reference in New Issue
Block a user