1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/security_interstitials/content/ssl_error_assistant.h"
#include <memory>
#include "components/security_interstitials/content/ssl_error_assistant.pb.h"
#include "content/public/test/test_renderer_host.h"
#include "crypto/sha2.h"
#include "net/cert/asn1_util.h"
#include "net/test/cert_test_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/test_certificate_data.h"
#include "net/test/test_data_directory.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const net::SHA256HashValue kCertPublicKeyHashValue = {{0x01, 0x02}};
const uint32_t kLargeVersionId = 0xFFFFFFu;
// These certificates are self signed certificates with relevant issuer common
// names generated using the following openssl command:
// openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
// Common name: "Misconfig Software"
// Organization name: "Test Company"
const char kMisconfigSoftwareCert[] =
"-----BEGIN CERTIFICATE-----\n"
"MIIC5DCCAk2gAwIBAgIJAPYPMpr0AIDBMA0GCSqGSIb3DQEBBQUAMFYxCzAJBgNV\n"
"BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMRUwEwYDVQQKEwxUZXN0IENvbXBh\n"
"bnkxGzAZBgNVBAMTEk1pc2NvbmZpZyBTb2Z0d2FyZTAeFw0xNzEwMTcxOTQyMzFa\n"
"Fw0xODEwMTcxOTQyMzFaMFYxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0\n"
"YXRlMRUwEwYDVQQKEwxUZXN0IENvbXBhbnkxGzAZBgNVBAMTEk1pc2NvbmZpZyBT\n"
"b2Z0d2FyZTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAyZWnLvuD19iG5PSi\n"
"8dSVhLeuZDBtwcWBOMzga3hx7HDMd+395gstRLc1VhpMePmxUdyEpStHDiYjNF/k\n"
"GRsIXfXWpO82L7r+Fm6eym4BOw2sjX1aounljETYasREvXhEB/8WaLJfMcstUwsT\n"
"PoXgUWYkIBi/76EiWHXvYEiXV2kCAwEAAaOBuTCBtjAdBgNVHQ4EFgQUtakrb0wU\n"
"gZVXyus1vlj6T5aDEnYwgYYGA1UdIwR/MH2AFLWpK29MFIGVV8rrNb5Y+k+WgxJ2\n"
"oVqkWDBWMQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEVMBMGA1UE\n"
"ChMMVGVzdCBDb21wYW55MRswGQYDVQQDExJNaXNjb25maWcgU29mdHdhcmWCCQD2\n"
"DzKa9ACAwTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAFAFlPO3HEWQ\n"
"0XdRbeIQPVva72VFyF+ESFC6ky7GLDoaSAwRlE1i5qWfxnLbEA0b7CWjyO1tC8Uw\n"
"OMB5U9qmQouAqf5medr2pECSDimb7qBCz3kKjgZWt1Xv8w0PsW6lFVPmMsO4Zv7F\n"
"Podf1biETWgaYoT6PrUTtWG3jeSU2r9M\n"
"-----END CERTIFICATE-----";
// Common name: "ijklmn opqrs"
// Organization name: "abc defgh co"
const char kMisconfigSoftwareRegexCheckCert[] =
"-----BEGIN CERTIFICATE-----\n"
"MIIC0jCCAjugAwIBAgIJAOyyORCXGxvDMA0GCSqGSIb3DQEBBQUAMFAxCzAJBgNV\n"
"BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMRUwEwYDVQQKEwxhYmMgZGVmZ2gg\n"
"Y28xFTATBgNVBAMTDGlqa2xtbiBvcHFyczAeFw0xNzEwMTcyMjM4MzJaFw0xODEw\n"
"MTcyMjM4MzJaMFAxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMRUw\n"
"EwYDVQQKEwxhYmMgZGVmZ2ggY28xFTATBgNVBAMTDGlqa2xtbiBvcHFyczCBnzAN\n"
"BgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAsnuBPW2k4+eFazC8lq7rLRNjpZ5yqEwX\n"
"LBE8fxbvjXSSZAaJz/iTn+Zg/UMJz9IpulbcA/xf36JuhFYv7aClFrtg5DHaqrPf\n"
"kt7g9AM3hEIjGsdHtyAqFp/+CpySGzVpTLyT1NtHkqtkiD6HCSpWqL+m/6ibpUhy\n"
"oy9y/ZV1vVUCAwEAAaOBszCBsDAdBgNVHQ4EFgQUBk+vtSjNipTcWh3NIbtsjVN0\n"
"uJswgYAGA1UdIwR5MHeAFAZPr7UozYqU3FodzSG7bI1TdLiboVSkUjBQMQswCQYD\n"
"VQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEVMBMGA1UEChMMYWJjIGRlZmdo\n"
"IGNvMRUwEwYDVQQDEwxpamtsbW4gb3BxcnOCCQDssjkQlxsbwzAMBgNVHRMEBTAD\n"
"AQH/MA0GCSqGSIb3DQEBBQUAA4GBACv8KnNmaOqHD8QsmvaD2Yvc7dAFkCgsdQb/\n"
"Tkyw0sJN8ZH+bummkgGZLw4gzdmhVg8kGIbiDvCYgOVaIg+2H3PtkdIrW2KhyXrN\n"
"2qIa9nBvuv8LC1TAdB65DDheLh0PuTGcIwfJ7kcKi+Eo8fPbYYdyHGRw+rVWXVPz\n"
"SgZO4ZYq\n"
"-----END CERTIFICATE-----";
} // namespace
class SSLErrorAssistantTest : public content::RenderViewHostTestHarness {
public:
SSLErrorAssistantTest(const SSLErrorAssistantTest&) = delete;
SSLErrorAssistantTest& operator=(const SSLErrorAssistantTest&) = delete;
void SetUp() override {
content::RenderViewHostTestHarness::SetUp();
error_assistant_ = std::make_unique<SSLErrorAssistant>();
ssl_info_.cert = net::ImportCertFromFile(
net::GetTestCertsDirectory(), "subjectAltName_www_example_com.pem");
ssl_info_.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
ssl_info_.public_key_hashes.push_back(
net::HashValue(kCertPublicKeyHashValue));
}
void TearDown() override {
error_assistant_.reset();
content::RenderViewHostTestHarness::TearDown();
}
void TestMITMSoftwareMatchFromString(const std::string& cert,
const std::string& match_result) {
net::CertificateList certs =
net::X509Certificate::CreateCertificateListFromBytes(
base::as_byte_span(cert), net::X509Certificate::FORMAT_AUTO);
ASSERT_FALSE(certs.empty());
EXPECT_EQ(match_result,
error_assistant()->MatchKnownMITMSoftware(certs[0]));
}
protected:
SSLErrorAssistantTest() {
embedded_test_server_ = std::make_unique<net::EmbeddedTestServer>();
}
~SSLErrorAssistantTest() override = default;
SSLErrorAssistant* error_assistant() const { return error_assistant_.get(); }
net::EmbeddedTestServer* embedded_test_server() const {
return embedded_test_server_.get();
}
const net::SSLInfo& ssl_info() const { return ssl_info_; }
const std::string& issuer_common_name() const {
return ssl_info_.cert->issuer().common_name;
}
const std::string& issuer_organization_name() const {
DCHECK(!ssl_info_.cert->issuer().organization_names.empty());
return ssl_info_.cert->issuer().organization_names.front();
}
private:
net::SSLInfo ssl_info_;
std::unique_ptr<SSLErrorAssistant> error_assistant_;
std::unique_ptr<net::EmbeddedTestServer> embedded_test_server_;
};
// Test to see if IsKnownCaptivePortalCertificate() returns the correct value.
TEST_F(SSLErrorAssistantTest, CaptivePortalCertificateList) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
// Test without the known captive portal certificate in config_proto.
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
config_proto->add_captive_portal_cert()->set_sha256_hash("sha256/boxfish");
config_proto->add_captive_portal_cert()->set_sha256_hash(
"sha256/treecreeper");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
EXPECT_FALSE(error_assistant()->IsKnownCaptivePortalCertificate(ssl_info()));
error_assistant()->ResetForTesting();
// Test with the known captive portal certificate in config_proto.
config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
config_proto->add_captive_portal_cert()->set_sha256_hash("sha256/boxfish");
config_proto->add_captive_portal_cert()->set_sha256_hash(
ssl_info().public_key_hashes[0].ToString());
config_proto->add_captive_portal_cert()->set_sha256_hash(
"sha256/treecreeper");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
EXPECT_TRUE(error_assistant()->IsKnownCaptivePortalCertificate(ssl_info()));
}
// Test to see if the MitM Software gets matched correctly.
TEST_F(SSLErrorAssistantTest, MitMSoftwareMatching) {
ASSERT_TRUE(embedded_test_server()->Start());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
// Tests for a basic and more complex regex match.
chrome_browser_ssl::MITMSoftware* filter = config_proto->add_mitm_software();
filter->set_name("Basic Check");
filter->set_issuer_common_name_regex("Misconfig Software");
filter->set_issuer_organization_regex("Test Company");
filter = config_proto->add_mitm_software();
filter->set_name("Regex Check");
filter->set_issuer_common_name_regex("ij[a-z]+n opqrs");
filter->set_issuer_organization_regex("abc de[a-z0-9]gh [a-z]+");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
TestMITMSoftwareMatchFromString(kMisconfigSoftwareCert, "Basic Check");
TestMITMSoftwareMatchFromString(kMisconfigSoftwareRegexCheckCert,
"Regex Check");
error_assistant()->ResetForTesting();
// Tests for no matches.
config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
filter = config_proto->add_mitm_software();
filter->set_name("Incorrect common name");
filter->set_issuer_common_name_regex("Misconfig Sotware");
filter->set_issuer_organization_regex("Test Company");
filter = config_proto->add_mitm_software();
filter->set_name("Incorrect company name");
filter->set_issuer_common_name_regex("Misconfig Software");
filter->set_issuer_organization_regex("Tst Company");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
TestMITMSoftwareMatchFromString(kMisconfigSoftwareCert, "");
}
// Test to see if the dynamic interstitial is matched with more complex regex
// fields.
TEST_F(SSLErrorAssistantTest, DynamicInterstitialListMatch) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
// Add a dynamic interstitial that will mismatch.
chrome_browser_ssl::DynamicInterstitial* filter =
config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(chrome_browser_ssl::DynamicInterstitial::
INTERSTITIAL_PAGE_CAPTIVE_PORTAL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::UNKNOWN_CERT_ERROR);
filter->add_sha256_hash("sha256/nightjar");
filter->add_sha256_hash("sha256/frogmouth");
filter->add_sha256_hash("sha256/poorwill");
filter->set_mitm_software_name("UwS");
filter->set_issuer_common_name_regex("whippoorwill");
// Add a matching dynamic interstitial.
filter = config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(
chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::ERR_CERT_COMMON_NAME_INVALID);
filter->add_sha256_hash("sha256/nuthatch");
filter->add_sha256_hash(ssl_info().public_key_hashes[0].ToString());
filter->add_sha256_hash("sha256/treecreeper");
filter->set_mitm_software_name("UwS");
filter->set_issuer_common_name_regex(issuer_common_name());
filter->set_issuer_organization_regex(issuer_organization_name());
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
std::optional<DynamicInterstitialInfo> dynamic_interstitial =
error_assistant()->MatchDynamicInterstitial(ssl_info());
ASSERT_TRUE(dynamic_interstitial);
EXPECT_EQ(chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL,
dynamic_interstitial->interstitial_type);
}
// Test to see if the dynamic interstitial is matched.
TEST_F(SSLErrorAssistantTest, DynamicInterstitialListComplexRegexMatch) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
// Add a dynamic interstitial that will mismatch.
chrome_browser_ssl::DynamicInterstitial* filter =
config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(chrome_browser_ssl::DynamicInterstitial::
INTERSTITIAL_PAGE_CAPTIVE_PORTAL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::UNKNOWN_CERT_ERROR);
filter->add_sha256_hash("sha256/nightjar");
filter->add_sha256_hash("sha256/frogmouth");
filter->add_sha256_hash("sha256/poorwill");
filter->set_mitm_software_name("UwS");
filter->set_issuer_common_name_regex("whippoorwill");
// Add a dynamic interstitial that will match.
filter = config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(
chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::ERR_CERT_COMMON_NAME_INVALID);
filter->add_sha256_hash("sha256/nuthatch");
filter->add_sha256_hash(ssl_info().public_key_hashes[0].ToString());
filter->add_sha256_hash("sha256/treecreeper");
filter->set_mitm_software_name("UwS");
filter->set_issuer_common_name_regex("[0-9]+.0.[0-9]+.1");
filter->set_issuer_organization_regex("T[a-z]+t CA");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
std::optional<DynamicInterstitialInfo> dynamic_interstitial =
error_assistant()->MatchDynamicInterstitial(ssl_info());
ASSERT_TRUE(dynamic_interstitial);
EXPECT_EQ(chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL,
dynamic_interstitial->interstitial_type);
}
// Test to see if the dynamic interstitial is matched when the certificate
// error is set to UNKNOWN_CERT_ERROR.
TEST_F(SSLErrorAssistantTest, DynamicInterstitialListMatchUnknownCertError) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
// Add a dynamic interstitial that will mismatch.
chrome_browser_ssl::DynamicInterstitial* filter =
config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(chrome_browser_ssl::DynamicInterstitial::
INTERSTITIAL_PAGE_CAPTIVE_PORTAL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::UNKNOWN_CERT_ERROR);
filter->add_sha256_hash("sha256/nightjar");
filter->add_sha256_hash("sha256/frogmouth");
filter->add_sha256_hash("sha256/poorwill");
// Add a dynamic interstitial that will match.
filter = config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(
chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::UNKNOWN_CERT_ERROR);
filter->add_sha256_hash("sha256/nuthatch");
filter->add_sha256_hash(ssl_info().public_key_hashes[0].ToString());
filter->add_sha256_hash("sha256/treecreeper");
filter->set_issuer_common_name_regex(issuer_common_name());
filter->set_issuer_organization_regex(issuer_organization_name());
filter->set_mitm_software_name("UwS");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
std::optional<DynamicInterstitialInfo> dynamic_interstitial =
error_assistant()->MatchDynamicInterstitial(ssl_info());
EXPECT_TRUE(dynamic_interstitial);
EXPECT_EQ(chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL,
dynamic_interstitial->interstitial_type);
}
// Test to see if the dynamic interstitial is matched if an empty issuer
// common name regex is set.
TEST_F(SSLErrorAssistantTest, DynamicInterstitialListNoCommonName) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
// Add a dynamic interstitial that will mismatch.
chrome_browser_ssl::DynamicInterstitial* filter =
config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(chrome_browser_ssl::DynamicInterstitial::
INTERSTITIAL_PAGE_CAPTIVE_PORTAL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::UNKNOWN_CERT_ERROR);
filter->add_sha256_hash("sha256/nightjar");
filter->add_sha256_hash("sha256/frogmouth");
filter->add_sha256_hash("sha256/poorwill");
// Add a matching dynamic interstitial with an empty issuer common name
// regex.
filter = config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(
chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::ERR_CERT_COMMON_NAME_INVALID);
filter->add_sha256_hash("sha256/nuthatch");
filter->add_sha256_hash(ssl_info().public_key_hashes[0].ToString());
filter->add_sha256_hash("sha256/treecreeper");
filter->set_issuer_common_name_regex(std::string());
filter->set_issuer_organization_regex(issuer_organization_name());
filter->set_mitm_software_name("UwS");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
std::optional<DynamicInterstitialInfo> dynamic_interstitial =
error_assistant()->MatchDynamicInterstitial(ssl_info());
ASSERT_TRUE(dynamic_interstitial);
EXPECT_EQ(chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL,
dynamic_interstitial->interstitial_type);
}
// Test to see if the dynamic interstitial is matched if no issuer
// organization name regex is set.
TEST_F(SSLErrorAssistantTest, DynamicInterstitialListNoOrganizationRegex) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
// Add a dynamic interstitial that will mismatch.
chrome_browser_ssl::DynamicInterstitial* filter =
config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(chrome_browser_ssl::DynamicInterstitial::
INTERSTITIAL_PAGE_CAPTIVE_PORTAL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::UNKNOWN_CERT_ERROR);
filter->add_sha256_hash("sha256/nightjar");
filter->add_sha256_hash("sha256/frogmouth");
filter->add_sha256_hash("sha256/poorwill");
// Add a matching dynamic interstitial with an empty issuer organization
// name regex.
filter = config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(
chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::ERR_CERT_COMMON_NAME_INVALID);
filter->add_sha256_hash("sha256/nuthatch");
filter->add_sha256_hash(ssl_info().public_key_hashes[0].ToString());
filter->add_sha256_hash("sha256/treecreeper");
filter->set_issuer_common_name_regex(issuer_common_name());
filter->set_issuer_organization_regex(std::string());
filter->set_mitm_software_name("UwS");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
std::optional<DynamicInterstitialInfo> dynamic_interstitial =
error_assistant()->MatchDynamicInterstitial(ssl_info());
ASSERT_TRUE(dynamic_interstitial);
EXPECT_EQ(chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL,
dynamic_interstitial->interstitial_type);
}
// Test to see if the dynamic interstitial is matched if no certificate hash is
// provided.
TEST_F(SSLErrorAssistantTest, DynamicInterstitialListNoCertHashes) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
// Add a dynamic interstitial that will mismatch.
chrome_browser_ssl::DynamicInterstitial* filter =
config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(chrome_browser_ssl::DynamicInterstitial::
INTERSTITIAL_PAGE_CAPTIVE_PORTAL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::UNKNOWN_CERT_ERROR);
filter->add_sha256_hash("sha256/nightjar");
filter->add_sha256_hash("sha256/frogmouth");
filter->add_sha256_hash("sha256/poorwill");
// Add a dynamic interstitial that will match.
filter = config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(
chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::ERR_CERT_COMMON_NAME_INVALID);
filter->set_issuer_common_name_regex(issuer_common_name());
filter->set_issuer_organization_regex(issuer_organization_name());
filter->set_mitm_software_name("UwS");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
std::optional<DynamicInterstitialInfo> dynamic_interstitial =
error_assistant()->MatchDynamicInterstitial(ssl_info());
ASSERT_TRUE(dynamic_interstitial);
EXPECT_EQ(chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL,
dynamic_interstitial->interstitial_type);
}
// Test to see if the dynamic interstitial is matched if no certificate hash,
// cert error or regexes is provided.
TEST_F(SSLErrorAssistantTest, DynamicInterstitialListMatchBlank) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
// Add a dynamic interstitial that will mismatch.
chrome_browser_ssl::DynamicInterstitial* filter =
config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(
chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL);
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
std::optional<DynamicInterstitialInfo> dynamic_interstitial =
error_assistant()->MatchDynamicInterstitial(ssl_info());
ASSERT_TRUE(dynamic_interstitial);
EXPECT_EQ(chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL,
dynamic_interstitial->interstitial_type);
}
// Test for a dynamic interstitial mismatch in the cert error.
TEST_F(SSLErrorAssistantTest, DynamicInterstitialListCertErrorMismatch) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
chrome_browser_ssl::DynamicInterstitial* filter =
config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(
chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::ERR_CERT_DATE_INVALID);
filter->add_sha256_hash("sha256/nuthatch");
filter->add_sha256_hash(ssl_info().public_key_hashes[0].ToString());
filter->add_sha256_hash("sha256/treecreeper");
filter->set_issuer_common_name_regex(issuer_common_name());
filter->set_issuer_organization_regex(issuer_organization_name());
filter->set_mitm_software_name("UwS");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
EXPECT_FALSE(error_assistant()->MatchDynamicInterstitial(ssl_info()));
}
// Test for a dynamic interstitial mismatch in the certificate hashes.
TEST_F(SSLErrorAssistantTest, DynamicInterstitialListHashesMismatch) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
chrome_browser_ssl::DynamicInterstitial* filter =
config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(
chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::UNKNOWN_CERT_ERROR);
filter->add_sha256_hash("sha256/yellowlegs");
filter->add_sha256_hash("sha256/killdeer");
filter->set_issuer_common_name_regex(issuer_common_name());
filter->set_issuer_organization_regex(issuer_organization_name());
filter->set_mitm_software_name("UwS");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
EXPECT_FALSE(error_assistant()->MatchDynamicInterstitial(ssl_info()));
}
// Test for a dynamic interstitial with an issuer common name regex mismatch.
TEST_F(SSLErrorAssistantTest, DynamicInterstitialListCommonNameMismatch) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
chrome_browser_ssl::DynamicInterstitial* filter =
config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(
chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::UNKNOWN_CERT_ERROR);
filter->add_sha256_hash("sha256/nuthatch");
filter->add_sha256_hash(ssl_info().public_key_hashes[0].ToString());
filter->add_sha256_hash("sha256/treecreeper");
filter->set_issuer_common_name_regex("beeeater");
filter->set_issuer_organization_regex(issuer_organization_name());
filter->set_mitm_software_name("UwS");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
EXPECT_FALSE(error_assistant()->MatchDynamicInterstitial(ssl_info()));
}
// Test for a dynamic interstitial with an issuer organization regex mismatch.
TEST_F(SSLErrorAssistantTest, DynamicInterstitialListOrganizationMismatch) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
chrome_browser_ssl::DynamicInterstitial* filter =
config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(
chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::UNKNOWN_CERT_ERROR);
filter->add_sha256_hash("sha256/nuthatch");
filter->add_sha256_hash(ssl_info().public_key_hashes[0].ToString());
filter->add_sha256_hash("sha256/treecreeper");
filter->set_issuer_common_name_regex(issuer_common_name());
filter->set_issuer_organization_regex("beeeater");
filter->set_mitm_software_name("UwS");
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
EXPECT_FALSE(error_assistant()->MatchDynamicInterstitial(ssl_info()));
}
// Tests that a dynamic interstitial is not triggered if the error thrown
// is overridable and the show_only_for_nonoverridable_errors flag is set.
TEST_F(SSLErrorAssistantTest, DynamicInterstitialListOverridable) {
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
auto config_proto =
std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
config_proto->set_version_id(kLargeVersionId);
// Add a dynamic interstitial that would match, except that the
// show_only_for_nonoverridable_errors flag is set.
chrome_browser_ssl::DynamicInterstitial* filter =
config_proto->add_dynamic_interstitial();
filter->set_interstitial_type(
chrome_browser_ssl::DynamicInterstitial::INTERSTITIAL_PAGE_SSL);
filter->set_cert_error(
chrome_browser_ssl::DynamicInterstitial::ERR_CERT_COMMON_NAME_INVALID);
filter->add_sha256_hash("sha256/nuthatch");
filter->add_sha256_hash(ssl_info().public_key_hashes[0].ToString());
filter->add_sha256_hash("sha256/treecreeper");
filter->set_mitm_software_name("UwS");
filter->set_issuer_common_name_regex("[0-9]+.0.[0-9]+.1");
filter->set_issuer_organization_regex("T[a-z]+t CA");
filter->set_show_only_for_nonoverridable_errors(true);
error_assistant()->SetErrorAssistantProto(std::move(config_proto));
EXPECT_FALSE(error_assistant()->MatchDynamicInterstitial(ssl_info(), true));
}
|