]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/x509: test for negative RSA parameters.
authorAdam Langley <agl@golang.org>
Thu, 31 Jan 2013 17:54:37 +0000 (12:54 -0500)
committerAdam Langley <agl@golang.org>
Thu, 31 Jan 2013 17:54:37 +0000 (12:54 -0500)
Someone found software that generates negative numbers for the RSA
modulus in an X.509 certificate. Our error messages were very poor in
this case so this change improves that.

Update #4728
Return more helpful errors when RSA parameters are negative or zero.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7228072

src/pkg/crypto/x509/x509.go

index 7983217696e57cb2b09ba2449fe022c531f93275..005d36da88043a735f6ae5b48807b31a7d6d63b6 100644 (file)
@@ -660,6 +660,13 @@ func parsePublicKey(algo PublicKeyAlgorithm, keyData *publicKeyInfo) (interface{
                        return nil, err
                }
 
+               if p.N.Sign() <= 0 {
+                       return nil, errors.New("x509: RSA modulus is not a positive number")
+               }
+               if p.E <= 0 {
+                       return nil, errors.New("x509: RSA public exponent is not a positive number")
+               }
+
                pub := &rsa.PublicKey{
                        E: p.E,
                        N: p.N,