Skip to content

Commit a985897

Browse files
rolandshoemakerFiloSottile
authored andcommitted
crypto/tls: test key type when casting
When casting the certificate public key in generateClientKeyExchange, check the type is appropriate. This prevents a panic when a server agrees to a RSA based key exchange, but then sends an ECDSA (or other) certificate. Fixes #47143 Fixes CVE-2021-34558 Thanks to Imre Rad for reporting this issue. Change-Id: Iabccacca6052769a605cccefa1216a9f7b7f6aea Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1116723 Reviewed-by: Filippo Valsorda <[email protected]> Reviewed-by: Katie Hockman <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/go/+/334031 Trust: Filippo Valsorda <[email protected]> Run-TryBot: Filippo Valsorda <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent cfbd73b commit a985897

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/crypto/tls/key_agreement.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ func (ka rsaKeyAgreement) generateClientKeyExchange(config *Config, clientHello
8686
return nil, nil, err
8787
}
8888

89-
encrypted, err := rsa.EncryptPKCS1v15(config.rand(), cert.PublicKey.(*rsa.PublicKey), preMasterSecret)
89+
rsaKey, ok := cert.PublicKey.(*rsa.PublicKey)
90+
if !ok {
91+
return nil, nil, errors.New("tls: server certificate contains incorrect key type for selected ciphersuite")
92+
}
93+
encrypted, err := rsa.EncryptPKCS1v15(config.rand(), rsaKey, preMasterSecret)
9094
if err != nil {
9195
return nil, nil, err
9296
}

0 commit comments

Comments
 (0)