Reject overlaps with wildcards. (#3542)

Requesting a certificate with "*.example.com" and "www.example.com" as
separate SANs doesn't make sense, because "www.example.com" is covered
by the wildcard.

#3524
This commit is contained in:
Jacob Hoffman-Andrews 2018-03-09 22:49:36 -08:00 committed by Roland Bracewell Shoemaker
parent 687ab5722b
commit c621cbd33f
2 changed files with 50 additions and 0 deletions

View File

@ -1708,6 +1708,10 @@ func (ra *RegistrationAuthorityImpl) NewOrder(ctx context.Context, req *rapb.New
}
}
if err := wildcardOverlap(order.Names); err != nil {
return nil, err
}
// See if there is an existing, pending, unexpired order that can be reused
// for this account
existingOrder, err := ra.SA.GetOrderForNames(ctx, &sapb.GetOrderForNamesRequest{
@ -1910,3 +1914,23 @@ func (ra *RegistrationAuthorityImpl) authzValidChallengeEnabled(authz *core.Auth
}
return false
}
// wildcardOverlap takes a slice of domain names and returns an error if any of
// them is a non-wildcard FQDN that overlaps with a wildcard domain in the map.
func wildcardOverlap(dnsNames []string) error {
nameMap := make(map[string]bool, len(dnsNames))
for _, v := range dnsNames {
nameMap[v] = true
}
for name := range nameMap {
if name[0] == '*' {
continue
}
labels := strings.Split(name, ".")
labels[0] = "*"
if nameMap[strings.Join(labels, ".")] {
return fmt.Errorf("Domain name %q is redundant with a wildcard domain in the same request. Remove one or the other from the certificate request.", name)
}
}
return nil
}

View File

@ -3345,6 +3345,32 @@ func TestCTPolicyMeasurements(t *testing.T) {
test.AssertEquals(t, test.CountHistogramSamples(ra.ctpolicyResults.With(prometheus.Labels{"result": "failure"})), 1)
}
func TestWildcardOverlap(t *testing.T) {
err := wildcardOverlap([]string{
"*.example.com",
"*.example.net",
})
if err != nil {
t.Errorf("Got error %q, expected none", err)
}
err = wildcardOverlap([]string{
"*.example.com",
"*.example.net",
"www.example.com",
})
if err == nil {
t.Errorf("Got no error, expected one")
}
err = wildcardOverlap([]string{
"*.foo.example.com",
"*.example.net",
"www.example.com",
})
if err != nil {
t.Errorf("Got error %q, expected none", err)
}
}
var CAkeyPEM = `
-----BEGIN RSA PRIVATE KEY-----
MIIJKQIBAAKCAgEAqmM0dEf/J9MCk2ItzevL0dKJ84lVUtf/vQ7AXFi492vFXc3b