Commit ddc86791 authored by Adam Langley's avatar Adam Langley

crypto/x509: harmonise error prefixes.

crypto/x509 has ended up with a variety of error formats. This change makes them all start with "x509: ".

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/9736043
parent 650a1ef6
...@@ -52,7 +52,7 @@ func ParsePKCS1PrivateKey(der []byte) (key *rsa.PrivateKey, err error) { ...@@ -52,7 +52,7 @@ func ParsePKCS1PrivateKey(der []byte) (key *rsa.PrivateKey, err error) {
} }
if priv.N.Sign() <= 0 || priv.D.Sign() <= 0 || priv.P.Sign() <= 0 || priv.Q.Sign() <= 0 { if priv.N.Sign() <= 0 || priv.D.Sign() <= 0 || priv.P.Sign() <= 0 || priv.Q.Sign() <= 0 {
return nil, errors.New("private key contains zero or negative value") return nil, errors.New("x509: private key contains zero or negative value")
} }
key = new(rsa.PrivateKey) key = new(rsa.PrivateKey)
...@@ -67,7 +67,7 @@ func ParsePKCS1PrivateKey(der []byte) (key *rsa.PrivateKey, err error) { ...@@ -67,7 +67,7 @@ func ParsePKCS1PrivateKey(der []byte) (key *rsa.PrivateKey, err error) {
key.Primes[1] = priv.Q key.Primes[1] = priv.Q
for i, a := range priv.AdditionalPrimes { for i, a := range priv.AdditionalPrimes {
if a.Prime.Sign() <= 0 { if a.Prime.Sign() <= 0 {
return nil, errors.New("private key contains zero or negative prime") return nil, errors.New("x509: private key contains zero or negative prime")
} }
key.Primes[i+2] = a.Prime key.Primes[i+2] = a.Prime
// We ignore the other two values because rsa will calculate // We ignore the other two values because rsa will calculate
......
...@@ -32,7 +32,7 @@ func ParsePKCS8PrivateKey(der []byte) (key interface{}, err error) { ...@@ -32,7 +32,7 @@ func ParsePKCS8PrivateKey(der []byte) (key interface{}, err error) {
case privKey.Algo.Algorithm.Equal(oidPublicKeyRSA): case privKey.Algo.Algorithm.Equal(oidPublicKeyRSA):
key, err = ParsePKCS1PrivateKey(privKey.PrivateKey) key, err = ParsePKCS1PrivateKey(privKey.PrivateKey)
if err != nil { if err != nil {
return nil, errors.New("crypto/x509: failed to parse RSA private key embedded in PKCS#8: " + err.Error()) return nil, errors.New("x509: failed to parse RSA private key embedded in PKCS#8: " + err.Error())
} }
return key, nil return key, nil
...@@ -44,11 +44,11 @@ func ParsePKCS8PrivateKey(der []byte) (key interface{}, err error) { ...@@ -44,11 +44,11 @@ func ParsePKCS8PrivateKey(der []byte) (key interface{}, err error) {
} }
key, err = parseECPrivateKey(namedCurveOID, privKey.PrivateKey) key, err = parseECPrivateKey(namedCurveOID, privKey.PrivateKey)
if err != nil { if err != nil {
return nil, errors.New("crypto/x509: failed to parse EC private key embedded in PKCS#8: " + err.Error()) return nil, errors.New("x509: failed to parse EC private key embedded in PKCS#8: " + err.Error())
} }
return key, nil return key, nil
default: default:
return nil, fmt.Errorf("crypto/x509: PKCS#8 wrapping contained private key with unknown algorithm: %v", privKey.Algo.Algorithm) return nil, fmt.Errorf("x509: PKCS#8 wrapping contained private key with unknown algorithm: %v", privKey.Algo.Algorithm)
} }
} }
...@@ -40,10 +40,10 @@ func ParseECPrivateKey(der []byte) (key *ecdsa.PrivateKey, err error) { ...@@ -40,10 +40,10 @@ func ParseECPrivateKey(der []byte) (key *ecdsa.PrivateKey, err error) {
func parseECPrivateKey(namedCurveOID *asn1.ObjectIdentifier, der []byte) (key *ecdsa.PrivateKey, err error) { func parseECPrivateKey(namedCurveOID *asn1.ObjectIdentifier, der []byte) (key *ecdsa.PrivateKey, err error) {
var privKey ecPrivateKey var privKey ecPrivateKey
if _, err := asn1.Unmarshal(der, &privKey); err != nil { if _, err := asn1.Unmarshal(der, &privKey); err != nil {
return nil, errors.New("crypto/x509: failed to parse EC private key: " + err.Error()) return nil, errors.New("x509: failed to parse EC private key: " + err.Error())
} }
if privKey.Version != ecPrivKeyVersion { if privKey.Version != ecPrivKeyVersion {
return nil, fmt.Errorf("crypto/x509: unknown EC private key version %d", privKey.Version) return nil, fmt.Errorf("x509: unknown EC private key version %d", privKey.Version)
} }
var curve elliptic.Curve var curve elliptic.Curve
...@@ -53,12 +53,12 @@ func parseECPrivateKey(namedCurveOID *asn1.ObjectIdentifier, der []byte) (key *e ...@@ -53,12 +53,12 @@ func parseECPrivateKey(namedCurveOID *asn1.ObjectIdentifier, der []byte) (key *e
curve = namedCurveFromOID(privKey.NamedCurveOID) curve = namedCurveFromOID(privKey.NamedCurveOID)
} }
if curve == nil { if curve == nil {
return nil, errors.New("crypto/x509: unknown elliptic curve") return nil, errors.New("x509: unknown elliptic curve")
} }
k := new(big.Int).SetBytes(privKey.PrivateKey) k := new(big.Int).SetBytes(privKey.PrivateKey)
if k.Cmp(curve.Params().N) >= 0 { if k.Cmp(curve.Params().N) >= 0 {
return nil, errors.New("crypto/x509: invalid elliptic curve private key value") return nil, errors.New("x509: invalid elliptic curve private key value")
} }
priv := new(ecdsa.PrivateKey) priv := new(ecdsa.PrivateKey)
priv.Curve = curve priv.Curve = curve
......
...@@ -40,7 +40,7 @@ func ParsePKIXPublicKey(derBytes []byte) (pub interface{}, err error) { ...@@ -40,7 +40,7 @@ func ParsePKIXPublicKey(derBytes []byte) (pub interface{}, err error) {
} }
algo := getPublicKeyAlgorithmFromOID(pki.Algorithm.Algorithm) algo := getPublicKeyAlgorithmFromOID(pki.Algorithm.Algorithm)
if algo == UnknownPublicKeyAlgorithm { if algo == UnknownPublicKeyAlgorithm {
return nil, errors.New("ParsePKIXPublicKey: unknown public key algorithm") return nil, errors.New("x509: unknown public key algorithm")
} }
return parsePublicKey(algo, &pki) return parsePublicKey(algo, &pki)
} }
...@@ -56,7 +56,7 @@ func MarshalPKIXPublicKey(pub interface{}) ([]byte, error) { ...@@ -56,7 +56,7 @@ func MarshalPKIXPublicKey(pub interface{}) ([]byte, error) {
E: pub.E, E: pub.E,
}) })
default: default:
return nil, errors.New("MarshalPKIXPublicKey: unknown public key type") return nil, errors.New("x509: unknown public key type")
} }
pkix := pkixPublicKey{ pkix := pkixPublicKey{
...@@ -477,7 +477,7 @@ type Certificate struct { ...@@ -477,7 +477,7 @@ type Certificate struct {
// ErrUnsupportedAlgorithm results from attempting to perform an operation that // ErrUnsupportedAlgorithm results from attempting to perform an operation that
// involves algorithms that are not currently implemented. // involves algorithms that are not currently implemented.
var ErrUnsupportedAlgorithm = errors.New("crypto/x509: cannot verify signature: algorithm unimplemented") var ErrUnsupportedAlgorithm = errors.New("x509: cannot verify signature: algorithm unimplemented")
// ConstraintViolationError results when a requested usage is not permitted by // ConstraintViolationError results when a requested usage is not permitted by
// a certificate. For example: checking a signature when the public key isn't a // a certificate. For example: checking a signature when the public key isn't a
...@@ -485,7 +485,7 @@ var ErrUnsupportedAlgorithm = errors.New("crypto/x509: cannot verify signature: ...@@ -485,7 +485,7 @@ var ErrUnsupportedAlgorithm = errors.New("crypto/x509: cannot verify signature:
type ConstraintViolationError struct{} type ConstraintViolationError struct{}
func (ConstraintViolationError) Error() string { func (ConstraintViolationError) Error() string {
return "crypto/x509: invalid signature: parent certificate cannot sign this kind of certificate" return "x509: invalid signature: parent certificate cannot sign this kind of certificate"
} }
func (c *Certificate) Equal(other *Certificate) bool { func (c *Certificate) Equal(other *Certificate) bool {
...@@ -604,10 +604,10 @@ func (c *Certificate) CheckSignature(algo SignatureAlgorithm, signed, signature ...@@ -604,10 +604,10 @@ func (c *Certificate) CheckSignature(algo SignatureAlgorithm, signed, signature
return err return err
} }
if dsaSig.R.Sign() <= 0 || dsaSig.S.Sign() <= 0 { if dsaSig.R.Sign() <= 0 || dsaSig.S.Sign() <= 0 {
return errors.New("DSA signature contained zero or negative values") return errors.New("x509: DSA signature contained zero or negative values")
} }
if !dsa.Verify(pub, digest, dsaSig.R, dsaSig.S) { if !dsa.Verify(pub, digest, dsaSig.R, dsaSig.S) {
return errors.New("DSA verification failure") return errors.New("x509: DSA verification failure")
} }
return return
case *ecdsa.PublicKey: case *ecdsa.PublicKey:
...@@ -616,10 +616,10 @@ func (c *Certificate) CheckSignature(algo SignatureAlgorithm, signed, signature ...@@ -616,10 +616,10 @@ func (c *Certificate) CheckSignature(algo SignatureAlgorithm, signed, signature
return err return err
} }
if ecdsaSig.R.Sign() <= 0 || ecdsaSig.S.Sign() <= 0 { if ecdsaSig.R.Sign() <= 0 || ecdsaSig.S.Sign() <= 0 {
return errors.New("crypto/x509: ECDSA signature contained zero or negative values") return errors.New("x509: ECDSA signature contained zero or negative values")
} }
if !ecdsa.Verify(pub, digest, ecdsaSig.R, ecdsaSig.S) { if !ecdsa.Verify(pub, digest, ecdsaSig.R, ecdsaSig.S) {
return errors.New("crypto/x509: ECDSA verification failure") return errors.New("x509: ECDSA verification failure")
} }
return return
} }
...@@ -635,7 +635,7 @@ func (c *Certificate) CheckCRLSignature(crl *pkix.CertificateList) (err error) { ...@@ -635,7 +635,7 @@ func (c *Certificate) CheckCRLSignature(crl *pkix.CertificateList) (err error) {
type UnhandledCriticalExtension struct{} type UnhandledCriticalExtension struct{}
func (h UnhandledCriticalExtension) Error() string { func (h UnhandledCriticalExtension) Error() string {
return "unhandled critical extension" return "x509: unhandled critical extension"
} }
type basicConstraints struct { type basicConstraints struct {
...@@ -694,7 +694,7 @@ func parsePublicKey(algo PublicKeyAlgorithm, keyData *publicKeyInfo) (interface{ ...@@ -694,7 +694,7 @@ func parsePublicKey(algo PublicKeyAlgorithm, keyData *publicKeyInfo) (interface{
return nil, err return nil, err
} }
if p.Sign() <= 0 || params.P.Sign() <= 0 || params.Q.Sign() <= 0 || params.G.Sign() <= 0 { if p.Sign() <= 0 || params.P.Sign() <= 0 || params.Q.Sign() <= 0 || params.G.Sign() <= 0 {
return nil, errors.New("zero or negative DSA parameter") return nil, errors.New("x509: zero or negative DSA parameter")
} }
pub := &dsa.PublicKey{ pub := &dsa.PublicKey{
Parameters: dsa.Parameters{ Parameters: dsa.Parameters{
...@@ -714,11 +714,11 @@ func parsePublicKey(algo PublicKeyAlgorithm, keyData *publicKeyInfo) (interface{ ...@@ -714,11 +714,11 @@ func parsePublicKey(algo PublicKeyAlgorithm, keyData *publicKeyInfo) (interface{
} }
namedCurve := namedCurveFromOID(*namedCurveOID) namedCurve := namedCurveFromOID(*namedCurveOID)
if namedCurve == nil { if namedCurve == nil {
return nil, errors.New("crypto/x509: unsupported elliptic curve") return nil, errors.New("x509: unsupported elliptic curve")
} }
x, y := elliptic.Unmarshal(namedCurve, asn1Data) x, y := elliptic.Unmarshal(namedCurve, asn1Data)
if x == nil { if x == nil {
return nil, errors.New("crypto/x509: failed to unmarshal elliptic curve point") return nil, errors.New("x509: failed to unmarshal elliptic curve point")
} }
pub := &ecdsa.PublicKey{ pub := &ecdsa.PublicKey{
Curve: namedCurve, Curve: namedCurve,
...@@ -752,7 +752,7 @@ func parseCertificate(in *certificate) (*Certificate, error) { ...@@ -752,7 +752,7 @@ func parseCertificate(in *certificate) (*Certificate, error) {
} }
if in.TBSCertificate.SerialNumber.Sign() < 0 { if in.TBSCertificate.SerialNumber.Sign() < 0 {
return nil, errors.New("negative serial number") return nil, errors.New("x509: negative serial number")
} }
out.Version = in.TBSCertificate.Version + 1 out.Version = in.TBSCertificate.Version + 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment