Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: net/base/x509_openssl_util_unittest.cc

Issue 4184004: Add support for certificate name checking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wtc & rsleevi comments Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/base/x509_openssl_util.h"
6
7 #include <algorithm>
8
9 #include "base/string_split.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace net {
13
14 namespace x509_openssl_util {
15
16 namespace {
17
18 struct CertificateNameVerifyTestData {
19 // true iff we expect hostname to match an entry in cert_names.
20 const bool expected;
21 // The hostname to match.
22 const char* const hostname;
23 // '/' separated list of certificate names to match against. Any occurrence
24 // of '#' will be replaced with a null character before processing.
25 const char* const cert_names;
26 };
27
28 CertificateNameVerifyTestData kNameVerifyTestData[] = {
29 { true, "foo.com", "foo.com" },
30 { true, "foo.com", "foo.com." },
31 { true, "f", "f" },
32 { true, "f", "f." },
33 { true, "bar.foo.com", "*.foo.com" },
34 { true, "www-3.bar.foo.com", "*.bar.foo.com." },
35 { true, "www.test.fr", "*.test.com/*.test.co.uk/*.test.de/*.test.fr" },
36 { true, "wwW.tESt.fr", "//*.*/*.test.de/*.test.FR/www" },
37 { false, "foo.com", "*.com" },
38 { false, "f.uk", ".uk" },
39 { true, "h.co.uk", "*.co.uk" },
40 { false, "192.168.1.11", "*.168.1.11" },
41 { false, "foo.us", "*.us" },
42 { false, "www.bar.foo.com",
43 "*.foo.com/*.*.foo.com/*.*.bar.foo.com/*w*.bar.foo.com/*..bar.foo.com" },
44 { false, "w.bar.foo.com", "?.bar.foo.com" },
45 { false, "www.foo.com", "(www|ftp).foo.com" },
46 { false, "www.foo.com", "www.foo.com#*.foo.com/#" }, // # = null char.
47 { false, "foo", "*" },
48 { false, "foo.", "*." },
49 { false, "test.org", "www.test.org/*.test.org/*.org" },
50 { false, "1.2.3.4.5.6", "*.2.3.4.5.6" },
51 // IDN tests
52 { true, "xn--poema-9qae5a.com.br", "xn--poema-9qae5a.com.br" },
53 { true, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br" },
54 { false, "xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br" },
55 // The following are adapted from the examples in http://tools.ietf.org/html /draft-saintandre-tls-server-id-check-09#section-4.4.3
56 { true, "foo.example.com", "*.example.com" },
57 { false, "bar.foo.example.com", "*.example.com" },
58 { false, "example.com", "*.example.com" },
59 { false, "baz1.example.net", "baz*.example.net" },
60 { false, "baz2.example.net", "baz*.example.net" },
61 { false, "bar.*.example.net", "bar.*.example.net" },
62 { false, "bar.f*o.example.net", "bar.f*o.example.net" },
63 // IP addresses currently not supported.
64 { false, "192.168.1.1", "192.168.1.1" },
65 { false, "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210",
66 "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210" },
67 { false, "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210", "*.]" },
68 { false, "::192.9.5.5", "::192.9.5.5" },
69 { false, "::192.9.5.5", "*.9.5.5" },
70 { false, "2010:836B:4179::836B:4179", "*:836B:4179::836B:4179" },
71 // Invalid host names.
72 { false, "www%26.foo.com", "www%26.foo.com" },
73 { false, "www.*.com", "www.*.com" },
74 { false, "w$w.f.com", "w$w.f.com" },
75 { false, "www-1.[::FFFF:129.144.52.38]", "*.[::FFFF:129.144.52.38]" },
76 };
77
78 class X509CertificateNameVerifyTest
79 : public testing::TestWithParam<CertificateNameVerifyTestData> {
80 };
81
82 TEST_P(X509CertificateNameVerifyTest, VerifyHostname) {
83 CertificateNameVerifyTestData test_data(GetParam());
84
85 std::string cert_name_line(test_data.cert_names);
86 std::replace(cert_name_line.begin(), cert_name_line.end(), '#', '\0');
87 std::vector<std::string> cert_names;
88 base::SplitString(cert_name_line, '/', &cert_names);
89
90 EXPECT_EQ(test_data.expected, VerifyHostname(test_data.hostname, cert_names))
91 << "Host [" << test_data.hostname
92 << "], cert name [" << test_data.cert_names << "]";
93 }
94
95 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
96 testing::ValuesIn(kNameVerifyTestData));
97
98 } // namespace
99
100 } // namespace x509_openssl_util
101
102 } // namespace net
OLDNEW
« net/base/x509_openssl_util.cc ('K') | « net/base/x509_openssl_util.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698