Commit ec0b5533 authored by Adam Langley's avatar Adam Langley

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
parent 314afb41
...@@ -928,11 +928,11 @@ func CreateCertificate(rand io.Reader, template, parent *Certificate, pub *rsa.P ...@@ -928,11 +928,11 @@ func CreateCertificate(rand io.Reader, template, parent *Certificate, pub *rsa.P
return return
} }
asn1Issuer, err := asn1.Marshal(parent.Issuer.ToRDNSequence()) asn1Issuer, err := asn1.Marshal(parent.Subject.ToRDNSequence())
if err != nil { if err != nil {
return return
} }
asn1Subject, err := asn1.Marshal(parent.Subject.ToRDNSequence()) asn1Subject, err := asn1.Marshal(template.Subject.ToRDNSequence())
if err != nil { if err != nil {
return return
} }
......
...@@ -243,10 +243,11 @@ func TestCreateSelfSignedCertificate(t *testing.T) { ...@@ -243,10 +243,11 @@ func TestCreateSelfSignedCertificate(t *testing.T) {
return return
} }
commonName := "test.example.com"
template := Certificate{ template := Certificate{
SerialNumber: big.NewInt(1), SerialNumber: big.NewInt(1),
Subject: pkix.Name{ Subject: pkix.Name{
CommonName: "test.example.com", CommonName: commonName,
Organization: []string{"Acme Co"}, Organization: []string{"Acme Co"},
}, },
NotBefore: time.SecondsToUTC(1000), NotBefore: time.SecondsToUTC(1000),
...@@ -283,6 +284,14 @@ func TestCreateSelfSignedCertificate(t *testing.T) { ...@@ -283,6 +284,14 @@ func TestCreateSelfSignedCertificate(t *testing.T) {
t.Errorf("Failed to parse name constraints: %#v", cert.PermittedDNSDomains) 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) err = cert.CheckSignatureFrom(cert)
if err != nil { if err != nil {
t.Errorf("Signature verification failed: %s", err) t.Errorf("Signature verification failed: %s", err)
......
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