crypto/x509, crypto/tls: improve root matching and observe CA flag.
The key/value format of X.500 names means that it's possible to encode a name with multiple values for, say, organisation. RFC5280 doesn't seem to consider this, but there are Verisign root certificates which do this and, in order to find the correct root certificate in some cases, we need to handle it. Also, CA certificates should set the CA flag and we now check this. After looking at the other X.509 extensions it appears that they are universally ignored/bit rotted away so we ignore them. R=rsc CC=golang-dev https://golang.org/cl/2249042
This commit is contained in:
parent
ed8da7bff6
commit
f4b6e2236c
@ -7,6 +7,7 @@ package tls
|
||||
import (
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// A CASet is a set of certificates.
|
||||
@ -23,7 +24,7 @@ func NewCASet() *CASet {
|
||||
}
|
||||
|
||||
func nameToKey(name *x509.Name) string {
|
||||
return name.Country + "/" + name.Organization + "/" + name.OrganizationalUnit + "/" + name.CommonName
|
||||
return strings.Join(name.Country, ",") + "/" + strings.Join(name.Organization, ",") + "/" + strings.Join(name.OrganizationalUnit, ",") + "/" + name.CommonName
|
||||
}
|
||||
|
||||
// FindParent attempts to find the certificate in s which signs the given
|
||||
|
@ -84,8 +84,30 @@ func (c *Conn) clientHandshake() os.Error {
|
||||
certs[i] = cert
|
||||
}
|
||||
|
||||
// TODO(agl): do better validation of certs: max path length, name restrictions etc.
|
||||
for i := 1; i < len(certs); i++ {
|
||||
if !certs[i].BasicConstraintsValid || !certs[i].IsCA {
|
||||
return c.sendAlert(alertBadCertificate)
|
||||
}
|
||||
// KeyUsage status flags are ignored. From Engineering
|
||||
// Security, Peter Gutmann:
|
||||
// A European government CA marked its signing certificates as
|
||||
// being valid for encryption only, but no-one noticed. Another
|
||||
// European CA marked its signature keys as not being valid for
|
||||
// signatures. A different CA marked its own trusted root
|
||||
// certificate as being invalid for certificate signing.
|
||||
// Another national CA distributed a certificate to be used to
|
||||
// encrypt data for the country’s tax authority that was marked
|
||||
// as only being usable for digital signatures but not for
|
||||
// encryption. Yet another CA reversed the order of the bit
|
||||
// flags in the keyUsage due to confusion over encoding
|
||||
// endianness, essentially setting a random keyUsage in
|
||||
// certificates that it issued. Another CA created a
|
||||
// self-invalidating certificate by adding a certificate policy
|
||||
// statement stipulating that the certificate had to be used
|
||||
// strictly as specified in the keyUsage, and a keyUsage
|
||||
// containing a flag indicating that the RSA encryption key
|
||||
// could only be used for Diffie-Hellman key agreement.
|
||||
|
||||
if err := certs[i-1].CheckSignatureFrom(certs[i]); err != nil {
|
||||
return c.sendAlert(alertBadCertificate)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user