1
0
mirror of https://github.com/golang/go synced 2024-11-20 09:04:44 -07:00

crypto/x509: fix names in certificate generation.

I had a brain fart in af84b15fbae2 and messed up the names in
generated certificates.

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/5315046
This commit is contained in:
Adam Langley 2011-10-19 12:19:13 -04:00
parent 314afb417a
commit ec0b5533c9
2 changed files with 12 additions and 3 deletions

View File

@ -928,11 +928,11 @@ func CreateCertificate(rand io.Reader, template, parent *Certificate, pub *rsa.P
return
}
asn1Issuer, err := asn1.Marshal(parent.Issuer.ToRDNSequence())
asn1Issuer, err := asn1.Marshal(parent.Subject.ToRDNSequence())
if err != nil {
return
}
asn1Subject, err := asn1.Marshal(parent.Subject.ToRDNSequence())
asn1Subject, err := asn1.Marshal(template.Subject.ToRDNSequence())
if err != nil {
return
}

View File

@ -243,10 +243,11 @@ func TestCreateSelfSignedCertificate(t *testing.T) {
return
}
commonName := "test.example.com"
template := Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{
CommonName: "test.example.com",
CommonName: commonName,
Organization: []string{"Acme Co"},
},
NotBefore: time.SecondsToUTC(1000),
@ -283,6 +284,14 @@ func TestCreateSelfSignedCertificate(t *testing.T) {
t.Errorf("Failed to parse name constraints: %#v", cert.PermittedDNSDomains)
}
if cert.Subject.CommonName != commonName {
t.Errorf("Subject wasn't correctly copied from the template. Got %s, want %s", cert.Subject.CommonName, commonName)
}
if cert.Issuer.CommonName != commonName {
t.Errorf("Issuer wasn't correctly copied from the template. Got %s, want %s", cert.Issuer.CommonName, commonName)
}
err = cert.CheckSignatureFrom(cert)
if err != nil {
t.Errorf("Signature verification failed: %s", err)