]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/x509: fix names in certificate generation.
authorAdam Langley <agl@golang.org>
Wed, 19 Oct 2011 16:19:13 +0000 (12:19 -0400)
committerAdam Langley <agl@golang.org>
Wed, 19 Oct 2011 16:19:13 +0000 (12:19 -0400)
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

src/pkg/crypto/x509/x509.go
src/pkg/crypto/x509/x509_test.go

index 4b8ecc56c5e18441dee80d118907bd8e430304d3..73b32e7d586e38fc602bd33ce2411c23e9b14300 100644 (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
        }
index dbc5273ca1244dcf0d8b259b0b39348bf402c8ae..e8449786c27dc54886a12b9e94a557a77ac18d13 100644 (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)