| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http/transport_security_state.h" | 5 #include "net/http/transport_security_state.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 // Checks the following hold for |report| such that it is a valid Expect-Staple | 251 // Checks the following hold for |report| such that it is a valid Expect-Staple |
| 252 // report: | 252 // report: |
| 253 // 1. |report| is a JSON dictionary. | 253 // 1. |report| is a JSON dictionary. |
| 254 // 2. The "hostname" and "port" fields match |host_port_pair|. | 254 // 2. The "hostname" and "port" fields match |host_port_pair|. |
| 255 // 3. The "response-status" field matches |response_status| | 255 // 3. The "response-status" field matches |response_status| |
| 256 // 4. The "ocsp-response" field is a base64-encoded verson of |ocsp_response|, | 256 // 4. The "ocsp-response" field is a base64-encoded verson of |ocsp_response|, |
| 257 // and is not present when |ocsp_response| is empty. | 257 // and is not present when |ocsp_response| is empty. |
| 258 // 5. The "cert-status" field matches |cert_status|, and is not present when | 258 // 5. The "cert-status" field matches |cert_status|, and is not present when |
| 259 // |cert_status| is empty. | 259 // |cert_status| is empty. |
| 260 // 6. The "validated-chain" and "serverd-chain" fields match those in | 260 // 6. The "validated-chain" and "serverd-chain" fields match those in |
| 261 // |ssl_info|, and are only present when |ssl_info.is_issued_by_known_root| | 261 // |ssl_info|. |
| 262 // is true. | |
| 263 void CheckSerializedExpectStapleReport(const std::string& report, | 262 void CheckSerializedExpectStapleReport(const std::string& report, |
| 264 const HostPortPair& host_port_pair, | 263 const HostPortPair& host_port_pair, |
| 265 const SSLInfo& ssl_info, | 264 const SSLInfo& ssl_info, |
| 266 const std::string& ocsp_response, | 265 const std::string& ocsp_response, |
| 267 const std::string& response_status, | 266 const std::string& response_status, |
| 268 const std::string& cert_status) { | 267 const std::string& cert_status) { |
| 269 std::unique_ptr<base::Value> value(base::JSONReader::Read(report)); | 268 std::unique_ptr<base::Value> value(base::JSONReader::Read(report)); |
| 270 ASSERT_TRUE(value); | 269 ASSERT_TRUE(value); |
| 271 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); | 270 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); |
| 272 | 271 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 310 } |
| 312 | 311 |
| 313 base::ListValue* report_served_certificate_chain; | 312 base::ListValue* report_served_certificate_chain; |
| 314 bool has_served_chain = report_dict->GetList( | 313 bool has_served_chain = report_dict->GetList( |
| 315 "served-certificate-chain", &report_served_certificate_chain); | 314 "served-certificate-chain", &report_served_certificate_chain); |
| 316 | 315 |
| 317 base::ListValue* report_validated_certificate_chain; | 316 base::ListValue* report_validated_certificate_chain; |
| 318 bool has_validated_chain = report_dict->GetList( | 317 bool has_validated_chain = report_dict->GetList( |
| 319 "validated-certificate-chain", &report_validated_certificate_chain); | 318 "validated-certificate-chain", &report_validated_certificate_chain); |
| 320 | 319 |
| 321 if (ssl_info.is_issued_by_known_root) { | 320 EXPECT_TRUE(has_served_chain); |
| 322 EXPECT_TRUE(has_served_chain); | 321 EXPECT_NO_FATAL_FAILURE(CompareCertificateChainWithList( |
| 323 EXPECT_NO_FATAL_FAILURE(CompareCertificateChainWithList( | 322 ssl_info.unverified_cert, report_served_certificate_chain)); |
| 324 ssl_info.unverified_cert, report_served_certificate_chain)); | |
| 325 | 323 |
| 326 EXPECT_TRUE(has_validated_chain); | 324 EXPECT_TRUE(has_validated_chain); |
| 327 EXPECT_NO_FATAL_FAILURE(CompareCertificateChainWithList( | 325 EXPECT_NO_FATAL_FAILURE(CompareCertificateChainWithList( |
| 328 ssl_info.cert, report_validated_certificate_chain)); | 326 ssl_info.cert, report_validated_certificate_chain)); |
| 329 } else { | |
| 330 EXPECT_FALSE(has_served_chain); | |
| 331 EXPECT_FALSE(has_validated_chain); | |
| 332 } | |
| 333 } | 327 } |
| 334 | 328 |
| 335 // Set up |state| for ExpectStaple, call CheckExpectStaple(), and verify the | 329 // Set up |state| for ExpectStaple, call CheckExpectStaple(), and verify the |
| 336 // serialized report caught by |reporter|. | 330 // serialized report caught by |reporter|. |
| 337 void CheckExpectStapleReport(TransportSecurityState* state, | 331 void CheckExpectStapleReport(TransportSecurityState* state, |
| 338 MockCertificateReportSender* reporter, | 332 MockCertificateReportSender* reporter, |
| 339 const SSLInfo& ssl_info, | 333 const SSLInfo& ssl_info, |
| 340 const std::string& ocsp_response, | 334 const std::string& ocsp_response, |
| 341 const std::string& response_status, | 335 const std::string& response_status, |
| 342 const std::string& cert_status) { | 336 const std::string& cert_status) { |
| 343 // Expect-Staple is preload list based, so we use the baked-in test hostname | 337 // Expect-Staple is preload list based, so we use the baked-in test hostname |
| 344 // from the list ("preloaded-expect-staple.badssl.com"). | 338 // from the list ("preloaded-expect-staple.badssl.com"). |
| 345 HostPortPair host_port(kExpectStapleStaticHostname, 443); | 339 HostPortPair host_port(kExpectStapleStaticHostname, 443); |
| 346 state->SetReportSender(reporter); | 340 state->SetReportSender(reporter); |
| 347 state->CheckExpectStaple(host_port, ssl_info, ocsp_response); | 341 state->CheckExpectStaple(host_port, ssl_info, ocsp_response); |
| 342 if (!ssl_info.is_issued_by_known_root) { |
| 343 EXPECT_EQ(GURL(), reporter->latest_report_uri()); |
| 344 EXPECT_EQ(std::string(), reporter->latest_report()); |
| 345 return; |
| 346 } |
| 348 EXPECT_EQ(GURL(kExpectStapleStaticReportURI), reporter->latest_report_uri()); | 347 EXPECT_EQ(GURL(kExpectStapleStaticReportURI), reporter->latest_report_uri()); |
| 349 EXPECT_EQ("application/json; charset=utf-8", reporter->latest_content_type()); | 348 EXPECT_EQ("application/json; charset=utf-8", reporter->latest_content_type()); |
| 350 std::string serialized_report = reporter->latest_report(); | 349 std::string serialized_report = reporter->latest_report(); |
| 351 EXPECT_NO_FATAL_FAILURE(CheckSerializedExpectStapleReport( | 350 EXPECT_NO_FATAL_FAILURE(CheckSerializedExpectStapleReport( |
| 352 serialized_report, host_port, ssl_info, ocsp_response, response_status, | 351 serialized_report, host_port, ssl_info, ocsp_response, response_status, |
| 353 cert_status)); | 352 cert_status)); |
| 354 } | 353 } |
| 355 | 354 |
| 356 } // namespace | 355 } // namespace |
| 357 | 356 |
| (...skipping 1702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2060 scoped_refptr<X509Certificate> cert1 = | 2059 scoped_refptr<X509Certificate> cert1 = |
| 2061 ImportCertFromFile(GetTestCertsDirectory(), "test_mail_google_com.pem"); | 2060 ImportCertFromFile(GetTestCertsDirectory(), "test_mail_google_com.pem"); |
| 2062 scoped_refptr<X509Certificate> cert2 = | 2061 scoped_refptr<X509Certificate> cert2 = |
| 2063 ImportCertFromFile(GetTestCertsDirectory(), "expired_cert.pem"); | 2062 ImportCertFromFile(GetTestCertsDirectory(), "expired_cert.pem"); |
| 2064 | 2063 |
| 2065 SSLInfo ssl_info; | 2064 SSLInfo ssl_info; |
| 2066 ssl_info.cert = cert1; | 2065 ssl_info.cert = cert1; |
| 2067 ssl_info.unverified_cert = cert2; | 2066 ssl_info.unverified_cert = cert2; |
| 2068 ssl_info.ocsp_result.response_status = test.response_status; | 2067 ssl_info.ocsp_result.response_status = test.response_status; |
| 2069 | 2068 |
| 2070 // Certificate chains should only be included when |is_issued_by_known_root| | 2069 // Reports should only be sent when |is_issued_by_known_root| is true. |
| 2071 // is true. | |
| 2072 ssl_info.is_issued_by_known_root = true; | 2070 ssl_info.is_issued_by_known_root = true; |
| 2073 ASSERT_NO_FATAL_FAILURE( | 2071 ASSERT_NO_FATAL_FAILURE( |
| 2074 CheckExpectStapleReport(&state, &reporter, ssl_info, ocsp_response, | 2072 CheckExpectStapleReport(&state, &reporter, ssl_info, ocsp_response, |
| 2075 test.response_status_string, std::string())); | 2073 test.response_status_string, std::string())); |
| 2074 reporter.Clear(); |
| 2076 | 2075 |
| 2077 // No certificate chains should be included in the report. | 2076 // No report should be sent. |
| 2078 ssl_info.is_issued_by_known_root = false; | 2077 ssl_info.is_issued_by_known_root = false; |
| 2079 ASSERT_NO_FATAL_FAILURE( | 2078 ASSERT_NO_FATAL_FAILURE( |
| 2080 CheckExpectStapleReport(&state, &reporter, ssl_info, ocsp_response, | 2079 CheckExpectStapleReport(&state, &reporter, ssl_info, ocsp_response, |
| 2081 test.response_status_string, std::string())); | 2080 test.response_status_string, std::string())); |
| 2082 } | 2081 } |
| 2083 | 2082 |
| 2084 INSTANTIATE_TEST_CASE_P(ExpectStaple, | 2083 INSTANTIATE_TEST_CASE_P(ExpectStaple, |
| 2085 ExpectStapleErrorResponseTest, | 2084 ExpectStapleErrorResponseTest, |
| 2086 testing::ValuesIn(kExpectStapleReportData)); | 2085 testing::ValuesIn(kExpectStapleReportData)); |
| 2087 | 2086 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2115 ImportCertFromFile(GetTestCertsDirectory(), "expired_cert.pem"); | 2114 ImportCertFromFile(GetTestCertsDirectory(), "expired_cert.pem"); |
| 2116 | 2115 |
| 2117 SSLInfo ssl_info; | 2116 SSLInfo ssl_info; |
| 2118 ssl_info.cert = cert1; | 2117 ssl_info.cert = cert1; |
| 2119 ssl_info.unverified_cert = cert2; | 2118 ssl_info.unverified_cert = cert2; |
| 2120 // |response_status| must be set to PROVIDED for |revocation_status| to have | 2119 // |response_status| must be set to PROVIDED for |revocation_status| to have |
| 2121 // meaning. | 2120 // meaning. |
| 2122 ssl_info.ocsp_result.response_status = OCSPVerifyResult::PROVIDED; | 2121 ssl_info.ocsp_result.response_status = OCSPVerifyResult::PROVIDED; |
| 2123 ssl_info.ocsp_result.revocation_status = test.revocation_status; | 2122 ssl_info.ocsp_result.revocation_status = test.revocation_status; |
| 2124 | 2123 |
| 2125 // Certificate chains should only be included when |is_issued_by_known_root| | 2124 // Reports should only be sent when |is_issued_by_known_root| is true. |
| 2126 // is true. | |
| 2127 ssl_info.is_issued_by_known_root = true; | 2125 ssl_info.is_issued_by_known_root = true; |
| 2128 ASSERT_NO_FATAL_FAILURE(CheckExpectStapleReport(&state, &reporter, ssl_info, | 2126 ASSERT_NO_FATAL_FAILURE(CheckExpectStapleReport(&state, &reporter, ssl_info, |
| 2129 ocsp_response, "PROVIDED", | 2127 ocsp_response, "PROVIDED", |
| 2130 test.cert_status_string)); | 2128 test.cert_status_string)); |
| 2129 reporter.Clear(); |
| 2131 | 2130 |
| 2132 // No certificate chains should be included in the report. | |
| 2133 ssl_info.is_issued_by_known_root = false; | 2131 ssl_info.is_issued_by_known_root = false; |
| 2134 ASSERT_NO_FATAL_FAILURE(CheckExpectStapleReport(&state, &reporter, ssl_info, | 2132 ASSERT_NO_FATAL_FAILURE(CheckExpectStapleReport(&state, &reporter, ssl_info, |
| 2135 ocsp_response, "PROVIDED", | 2133 ocsp_response, "PROVIDED", |
| 2136 test.cert_status_string)); | 2134 test.cert_status_string)); |
| 2137 }; | 2135 }; |
| 2138 | 2136 |
| 2139 INSTANTIATE_TEST_CASE_P(ExpectStaple, | 2137 INSTANTIATE_TEST_CASE_P(ExpectStaple, |
| 2140 ExpectStapleErrorCertStatusTest, | 2138 ExpectStapleErrorCertStatusTest, |
| 2141 testing::ValuesIn(kExpectStapleErrorCertStatusData)); | 2139 testing::ValuesIn(kExpectStapleErrorCertStatusData)); |
| 2142 | 2140 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2337 base::FieldTrialList::CreateFieldTrial("EnforceCTForProblematicRoots", | 2335 base::FieldTrialList::CreateFieldTrial("EnforceCTForProblematicRoots", |
| 2338 "disabled"); | 2336 "disabled"); |
| 2339 | 2337 |
| 2340 EXPECT_FALSE( | 2338 EXPECT_FALSE( |
| 2341 state.ShouldRequireCT("www.example.com", before_cert.get(), hashes)); | 2339 state.ShouldRequireCT("www.example.com", before_cert.get(), hashes)); |
| 2342 EXPECT_FALSE( | 2340 EXPECT_FALSE( |
| 2343 state.ShouldRequireCT("www.example.com", after_cert.get(), hashes)); | 2341 state.ShouldRequireCT("www.example.com", after_cert.get(), hashes)); |
| 2344 } | 2342 } |
| 2345 | 2343 |
| 2346 } // namespace net | 2344 } // namespace net |
| OLD | NEW |