Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/cert/internal/name_constraints.h" | 5 #include "net/cert/internal/name_constraints.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "net/base/ip_address.h" | 9 #include "net/base/ip_address.h" |
| 10 #include "net/cert/internal/test_helpers.h" | 10 #include "net/cert/internal/test_helpers.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 // Wildcard hostnames only match a single label, so cannot match excluded | 179 // Wildcard hostnames only match a single label, so cannot match excluded |
| 180 // which has two labels before .com. | 180 // which has two labels before .com. |
| 181 EXPECT_TRUE(name_constraints->IsPermittedDNSName("*.com")); | 181 EXPECT_TRUE(name_constraints->IsPermittedDNSName("*.com")); |
| 182 | 182 |
| 183 // Partial match of foo.bar.com. | 183 // Partial match of foo.bar.com. |
| 184 EXPECT_FALSE(name_constraints->IsPermittedDNSName("*.bar.com")); | 184 EXPECT_FALSE(name_constraints->IsPermittedDNSName("*.bar.com")); |
| 185 // All expansions of wildcard are within excluded. | 185 // All expansions of wildcard are within excluded. |
| 186 EXPECT_FALSE(name_constraints->IsPermittedDNSName("*.foo.bar.com")); | 186 EXPECT_FALSE(name_constraints->IsPermittedDNSName("*.foo.bar.com")); |
| 187 } | 187 } |
| 188 | 188 |
| 189 TEST_P(ParseNameConstraints, DNSNamesWithLeadingDot) { | 189 TEST_P(ParseNameConstraints, DNSNamesPermittedWithLeadingDot) { |
| 190 std::string a; | 190 std::string a; |
| 191 ASSERT_TRUE( | 191 ASSERT_TRUE( |
| 192 LoadTestNameConstraint("dnsname-permitted_with_leading_dot.pem", &a)); | 192 LoadTestNameConstraint("dnsname-permitted_with_leading_dot.pem", &a)); |
| 193 std::unique_ptr<NameConstraints> name_constraints( | 193 std::unique_ptr<NameConstraints> name_constraints( |
| 194 NameConstraints::Create(der::Input(&a), is_critical())); | 194 NameConstraints::Create(der::Input(&a), is_critical())); |
| 195 ASSERT_TRUE(name_constraints); | 195 ASSERT_TRUE(name_constraints); |
| 196 | 196 |
| 197 // dNSName constraints should be specified as a host. A dNSName constraint | 197 // A permitted dNSName constraint of ".bar.com" should only match subdomains |
|
eroman
2016/11/22 23:34:15
If we don't already, might be good to have a test
mattm
2016/11/24 00:08:50
Done.
| |
| 198 // with a leading "." doesn't make sense, though some certs include it | 198 // of .bar.com, but not bar.com itself. |
| 199 // (probably confusing it with the rules for uniformResourceIdentifier | |
| 200 // constraints). It should not match anything. | |
| 201 EXPECT_FALSE(name_constraints->IsPermittedDNSName("com")); | 199 EXPECT_FALSE(name_constraints->IsPermittedDNSName("com")); |
| 202 EXPECT_FALSE(name_constraints->IsPermittedDNSName("bar.com")); | 200 EXPECT_FALSE(name_constraints->IsPermittedDNSName("bar.com")); |
| 201 EXPECT_FALSE(name_constraints->IsPermittedDNSName("foobar.com")); | |
| 202 EXPECT_TRUE(name_constraints->IsPermittedDNSName("foo.bar.com")); | |
| 203 EXPECT_TRUE(name_constraints->IsPermittedDNSName("*.bar.com")); | |
| 204 } | |
| 205 | |
| 206 TEST_P(ParseNameConstraints, DNSNamesExcludedWithLeadingDot) { | |
| 207 std::string a; | |
| 208 ASSERT_TRUE( | |
| 209 LoadTestNameConstraint("dnsname-excluded_with_leading_dot.pem", &a)); | |
| 210 std::unique_ptr<NameConstraints> name_constraints( | |
| 211 NameConstraints::Create(der::Input(&a), is_critical())); | |
| 212 ASSERT_TRUE(name_constraints); | |
| 213 | |
| 214 // An excluded dNSName constraint of ".bar.com" should only match subdomains | |
| 215 // of .bar.com, but not bar.com itself. | |
| 216 EXPECT_TRUE(name_constraints->IsPermittedDNSName("com")); | |
| 217 EXPECT_TRUE(name_constraints->IsPermittedDNSName("bar.com")); | |
| 218 EXPECT_TRUE(name_constraints->IsPermittedDNSName("foobar.com")); | |
| 203 EXPECT_FALSE(name_constraints->IsPermittedDNSName("foo.bar.com")); | 219 EXPECT_FALSE(name_constraints->IsPermittedDNSName("foo.bar.com")); |
| 220 EXPECT_FALSE(name_constraints->IsPermittedDNSName("*.bar.com")); | |
| 204 } | 221 } |
| 205 | 222 |
| 206 TEST_P(ParseNameConstraints, DNSNamesExcludeOnly) { | 223 TEST_P(ParseNameConstraints, DNSNamesExcludeOnly) { |
| 207 std::string a; | 224 std::string a; |
| 208 ASSERT_TRUE(LoadTestNameConstraint("dnsname-excluded.pem", &a)); | 225 ASSERT_TRUE(LoadTestNameConstraint("dnsname-excluded.pem", &a)); |
| 209 | 226 |
| 210 std::unique_ptr<NameConstraints> name_constraints( | 227 std::unique_ptr<NameConstraints> name_constraints( |
| 211 NameConstraints::Create(der::Input(&a), is_critical())); | 228 NameConstraints::Create(der::Input(&a), is_critical())); |
| 212 ASSERT_TRUE(name_constraints); | 229 ASSERT_TRUE(name_constraints); |
| 213 | 230 |
| (...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1106 | 1123 |
| 1107 TEST_P(ParseNameConstraints, | 1124 TEST_P(ParseNameConstraints, |
| 1108 GeneralNamesCreateFailsOnInvalidIpInSubjectAltName) { | 1125 GeneralNamesCreateFailsOnInvalidIpInSubjectAltName) { |
| 1109 std::string invalid_san_der; | 1126 std::string invalid_san_der; |
| 1110 ASSERT_TRUE(LoadTestSubjectAltNameData("san-invalid-ipaddress.pem", | 1127 ASSERT_TRUE(LoadTestSubjectAltNameData("san-invalid-ipaddress.pem", |
| 1111 &invalid_san_der)); | 1128 &invalid_san_der)); |
| 1112 EXPECT_FALSE(GeneralNames::Create(der::Input(&invalid_san_der))); | 1129 EXPECT_FALSE(GeneralNames::Create(der::Input(&invalid_san_der))); |
| 1113 } | 1130 } |
| 1114 | 1131 |
| 1115 } // namespace net | 1132 } // namespace net |
| OLD | NEW |