x/crypto/openpgp/packet: validate parsed rsa private keys

parseRSAPrivateKey calls rsa.PrivateKey.Precompute which triggers
divide-by-zero panic if either p or q is 1. Sanity check the parsed
values by calling rsa.PrivateKey.Validate.

Fixes golang/go#11505

Change-Id: Ia6c9eccca0cfa49aaa58716e708c557a788bb204
Reviewed-on: https://go-review.googlesource.com/12356
Reviewed-by: Adam Langley <agl@golang.org>
This commit is contained in:
Michael Gehring
2015-07-29 16:51:43 +00:00
committed by Adam Langley
parent 56474dfd62
commit f2c09b05fa
2 changed files with 8 additions and 0 deletions
+3
View File
@@ -263,6 +263,9 @@ func (pk *PrivateKey) parseRSAPrivateKey(data []byte) (err error) {
rsaPriv.Primes = make([]*big.Int, 2)
rsaPriv.Primes[0] = new(big.Int).SetBytes(p)
rsaPriv.Primes[1] = new(big.Int).SetBytes(q)
if err := rsaPriv.Validate(); err != nil {
return err
}
rsaPriv.Precompute()
pk.PrivateKey = rsaPriv
pk.Encrypted = false