Commit e7fae685 authored by Adam Langley's avatar Adam Langley

crypto/x509: allow wildcards only as the first label.

RFC 6125 now specifies that wildcards are only allowed for the leftmost
label in a pattern: https://tools.ietf.org/html/rfc6125#section-6.4.3.

This change updates Go to match the behaviour of major browsers in this
respect.

Fixes #9834.

Change-Id: I37c10a35177133624568f2e0cf2767533926b04a
Reviewed-on: https://go-review.googlesource.com/5691Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 8f8d066b
...@@ -337,7 +337,7 @@ func matchHostnames(pattern, host string) bool { ...@@ -337,7 +337,7 @@ func matchHostnames(pattern, host string) bool {
} }
for i, patternPart := range patternParts { for i, patternPart := range patternParts {
if patternPart == "*" { if i == 0 && patternPart == "*" {
continue continue
} }
if patternPart != hostParts[i] { if patternPart != hostParts[i] {
......
...@@ -163,11 +163,14 @@ var matchHostnamesTests = []matchHostnamesTest{ ...@@ -163,11 +163,14 @@ var matchHostnamesTests = []matchHostnamesTest{
{"example.com", "example.com", true}, {"example.com", "example.com", true},
{"example.com", "example.com.", true}, {"example.com", "example.com.", true},
{"example.com", "www.example.com", false}, {"example.com", "www.example.com", false},
{"*.example.com", "example.com", false},
{"*.example.com", "www.example.com", true}, {"*.example.com", "www.example.com", true},
{"*.example.com", "www.example.com.", true}, {"*.example.com", "www.example.com.", true},
{"*.example.com", "xyz.www.example.com", false}, {"*.example.com", "xyz.www.example.com", false},
{"*.*.example.com", "xyz.www.example.com", true}, {"*.*.example.com", "xyz.www.example.com", false},
{"*.www.*.com", "xyz.www.example.com", true}, {"*.www.*.com", "xyz.www.example.com", false},
{"*bar.example.com", "foobar.example.com", false},
{"f*.example.com", "foobar.example.com", false},
{"", ".", false}, {"", ".", false},
{".", "", false}, {".", "", false},
{".", ".", false}, {".", ".", false},
...@@ -177,7 +180,7 @@ func TestMatchHostnames(t *testing.T) { ...@@ -177,7 +180,7 @@ func TestMatchHostnames(t *testing.T) {
for i, test := range matchHostnamesTests { for i, test := range matchHostnamesTests {
r := matchHostnames(test.pattern, test.host) r := matchHostnames(test.pattern, test.host)
if r != test.ok { if r != test.ok {
t.Errorf("#%d mismatch got: %t want: %t", i, r, test.ok) t.Errorf("#%d mismatch got: %t want: %t when matching '%s' against '%s'", i, r, test.ok, test.host, test.pattern)
} }
} }
} }
......
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