Explicit reject non-DNS names in CN.
diff --git a/csr/csr.go b/csr/csr.go index 60e5833..9eef015 100644 --- a/csr/csr.go +++ b/csr/csr.go
@@ -5,6 +5,7 @@ "crypto" "crypto/x509" "errors" + "github.com/letsencrypt/boulder/policy" "strings" "github.com/letsencrypt/boulder/core" @@ -68,6 +69,12 @@ return invalidURIPresent } + if csr.Subject.CommonName != "" { + err := policy.ValidDomain(csr.Subject.CommonName) + if err != nil { + return berrors.BadCSRError("CSR contains invalid CommonName %q (must match a DNS subjectAlternativeName)", csr.Subject.CommonName) + } + } // FromCSR also performs normalization, returning values that may not match // the literal CSR contents. idents := identifier.FromCSR(csr)
diff --git a/test/integration/issuance_test.go b/test/integration/issuance_test.go index 619e755..6aabc79 100644 --- a/test/integration/issuance_test.go +++ b/test/integration/issuance_test.go
@@ -7,7 +7,9 @@ "crypto/elliptic" "crypto/rand" "crypto/x509" + "crypto/x509/pkix" "fmt" + "net" "os" "strings" "testing" @@ -231,3 +233,79 @@ } } } + +// TestIPCNRejected verifies that we will reject IP address identifiers when +// they occur in the Subject CommonName. +func TestIPCNIgnored(t *testing.T) { + if os.Getenv("BOULDER_CONFIG_DIR") != "test/config-next" { + t.Skip() + } + t.Parallel() + + // Create an account. + client, err := makeClient("mailto:example@letsencrypt.org") + if err != nil { + t.Fatalf("creating acme client: %s", err) + } + + // Create an IP address identifier to request. + ip := "64.112.117.122" + ipParsed := net.ParseIP(ip) + idents := []acme.Identifier{ + {Type: "ip", Value: ip}, + } + + order, err := client.Client.NewOrderExtension(client.Account, idents, acme.OrderExtension{Profile: "shortlived"}) + if err != nil { + t.Fatalf("creating order: %s", err) + } + + if len(order.Authorizations) != 1 { + t.Fatalf("Got %d authorizations, expected 1", len(order.Authorizations)) + } + auth, err := client.Client.FetchAuthorization(client.Account, order.Authorizations[0]) + chal, ok := auth.ChallengeMap[acme.ChallengeTypeHTTP01] + if !ok { + t.Fatalf("no HTTP challenge at %s", order.Authorizations[0]) + } + + _, err = testSrvClient.AddHTTP01Response(chal.Token, chal.KeyAuthorization) + if err != nil { + t.Fatalf("adding HTTP challenge response: %s", err) + } + defer testSrvClient.RemoveHTTP01Response(chal.Token) + + chal, err = client.Client.UpdateChallenge(client.Account, chal) + if err != nil { + t.Fatalf("updating challenge: %s", err) + } + + key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + t.Fatalf("creating random cert key: %s", err) + } + csrTemplate := &x509.CertificateRequest{ + Subject: pkix.Name{CommonName: ip}, + SignatureAlgorithm: x509.ECDSAWithSHA256, + PublicKeyAlgorithm: x509.ECDSA, + PublicKey: key.Public(), + IPAddresses: []net.IP{ipParsed}, + } + csrDer, err := x509.CreateCertificateRequest(rand.Reader, csrTemplate, key) + if err != nil { + t.Fatalf("making csr: %s", err) + } + csr, err := x509.ParseCertificateRequest(csrDer) + if err != nil { + t.Fatalf("parsing csr: %s", err) + } + + _, err = client.Client.FinalizeOrder(client.Account, order, csr) + if err == nil { + t.Errorf("Finalizing order with IP in CN: got nil error, want badCSR error") + } + if !strings.Contains(err.Error(), "CSR contains invalid CommonNamx") { + t.Errorf("issuing with IP in CN failed for the wrong reason: %s", err) + } + +}