Chromium Code Reviews| 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/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "base/trace_event/trace_event_argument.h" | 23 #include "base/trace_event/trace_event_argument.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "net/base/address_list.h" | 25 #include "net/base/address_list.h" |
| 26 #include "net/base/io_buffer.h" | 26 #include "net/base/io_buffer.h" |
| 27 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
| 28 #include "net/base/test_completion_callback.h" | 28 #include "net/base/test_completion_callback.h" |
| 29 #include "net/cert/asn1_util.h" | 29 #include "net/cert/asn1_util.h" |
| 30 #include "net/cert/ct_policy_enforcer.h" | 30 #include "net/cert/ct_policy_enforcer.h" |
| 31 #include "net/cert/ct_policy_status.h" | 31 #include "net/cert/ct_policy_status.h" |
| 32 #include "net/cert/ct_verifier.h" | 32 #include "net/cert/ct_verifier.h" |
| 33 #include "net/cert/do_nothing_ct_verifier.h" | |
| 33 #include "net/cert/mock_cert_verifier.h" | 34 #include "net/cert/mock_cert_verifier.h" |
| 34 #include "net/cert/signed_certificate_timestamp_and_status.h" | 35 #include "net/cert/signed_certificate_timestamp_and_status.h" |
| 35 #include "net/cert/test_root_certs.h" | 36 #include "net/cert/test_root_certs.h" |
| 36 #include "net/der/input.h" | 37 #include "net/der/input.h" |
| 37 #include "net/der/parser.h" | 38 #include "net/der/parser.h" |
| 38 #include "net/der/tag.h" | 39 #include "net/der/tag.h" |
| 39 #include "net/dns/host_resolver.h" | 40 #include "net/dns/host_resolver.h" |
| 40 #include "net/http/transport_security_state.h" | 41 #include "net/http/transport_security_state.h" |
| 41 #include "net/log/net_log_event_type.h" | 42 #include "net/log/net_log_event_type.h" |
| 42 #include "net/log/net_log_source.h" | 43 #include "net/log/net_log_source.h" |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 int GetChannelIDCount() override { return 0; } | 700 int GetChannelIDCount() override { return 0; } |
| 700 void SetForceKeepSessionState() override {} | 701 void SetForceKeepSessionState() override {} |
| 701 bool IsEphemeral() override { return true; } | 702 bool IsEphemeral() override { return true; } |
| 702 }; | 703 }; |
| 703 | 704 |
| 704 // A mock CTVerifier that records every call to Verify but doesn't verify | 705 // A mock CTVerifier that records every call to Verify but doesn't verify |
| 705 // anything. | 706 // anything. |
| 706 class MockCTVerifier : public CTVerifier { | 707 class MockCTVerifier : public CTVerifier { |
| 707 public: | 708 public: |
| 708 MOCK_METHOD5(Verify, | 709 MOCK_METHOD5(Verify, |
| 709 int(X509Certificate*, | 710 void(X509Certificate*, |
| 710 const std::string&, | 711 base::StringPiece, |
| 711 const std::string&, | 712 base::StringPiece, |
| 712 SignedCertificateTimestampAndStatusList*, | 713 SignedCertificateTimestampAndStatusList*, |
| 713 const NetLogWithSource&)); | 714 const NetLogWithSource&)); |
| 714 MOCK_METHOD1(SetObserver, void(CTVerifier::Observer*)); | 715 MOCK_METHOD1(SetObserver, void(CTVerifier::Observer*)); |
| 715 }; | 716 }; |
| 716 | 717 |
| 717 // A mock CTPolicyEnforcer that returns a custom verification result. | 718 // A mock CTPolicyEnforcer that returns a custom verification result. |
| 718 class MockCTPolicyEnforcer : public CTPolicyEnforcer { | 719 class MockCTPolicyEnforcer : public CTPolicyEnforcer { |
| 719 public: | 720 public: |
| 720 MOCK_METHOD3(DoesConformToCertPolicy, | 721 MOCK_METHOD3(DoesConformToCertPolicy, |
| 721 ct::CertPolicyCompliance(X509Certificate* cert, | 722 ct::CertPolicyCompliance(X509Certificate* cert, |
| 722 const ct::SCTList&, | 723 const ct::SCTList&, |
| 723 const NetLogWithSource&)); | 724 const NetLogWithSource&)); |
| 724 MOCK_METHOD4(DoesConformToCTEVPolicy, | 725 MOCK_METHOD4(DoesConformToCTEVPolicy, |
| 725 ct::EVPolicyCompliance(X509Certificate* cert, | 726 ct::EVPolicyCompliance(X509Certificate* cert, |
| 726 const ct::EVCertsWhitelist*, | 727 const ct::EVCertsWhitelist*, |
| 727 const ct::SCTList&, | 728 const ct::SCTList&, |
| 728 const NetLogWithSource&)); | 729 const NetLogWithSource&)); |
| 729 }; | 730 }; |
| 730 | 731 |
| 731 class MockRequireCTDelegate : public TransportSecurityState::RequireCTDelegate { | 732 class MockRequireCTDelegate : public TransportSecurityState::RequireCTDelegate { |
| 732 public: | 733 public: |
| 733 MOCK_METHOD1(IsCTRequiredForHost, | 734 MOCK_METHOD1(IsCTRequiredForHost, |
| 734 CTRequirementLevel(const std::string& host)); | 735 CTRequirementLevel(const std::string& host)); |
| 735 }; | 736 }; |
| 736 | 737 |
| 737 class SSLClientSocketTest : public PlatformTest { | 738 class SSLClientSocketTest : public PlatformTest { |
| 738 public: | 739 public: |
| 739 SSLClientSocketTest() | 740 SSLClientSocketTest() |
| 740 : socket_factory_(ClientSocketFactory::GetDefaultFactory()), | 741 : socket_factory_(ClientSocketFactory::GetDefaultFactory()), |
| 741 cert_verifier_(new MockCertVerifier), | 742 cert_verifier_(new MockCertVerifier), |
| 742 transport_security_state_(new TransportSecurityState), | 743 transport_security_state_(new TransportSecurityState), |
| 743 ct_verifier_(new MockCTVerifier), | 744 ct_verifier_(new DoNothingCTVerifier), |
| 744 ct_policy_enforcer_(new MockCTPolicyEnforcer) { | 745 ct_policy_enforcer_(new MockCTPolicyEnforcer) { |
| 745 cert_verifier_->set_default_result(OK); | 746 cert_verifier_->set_default_result(OK); |
| 746 context_.cert_verifier = cert_verifier_.get(); | 747 context_.cert_verifier = cert_verifier_.get(); |
| 747 context_.transport_security_state = transport_security_state_.get(); | 748 context_.transport_security_state = transport_security_state_.get(); |
| 748 context_.cert_transparency_verifier = ct_verifier_.get(); | 749 context_.cert_transparency_verifier = ct_verifier_.get(); |
| 749 context_.ct_policy_enforcer = ct_policy_enforcer_.get(); | 750 context_.ct_policy_enforcer = ct_policy_enforcer_.get(); |
| 750 | 751 |
| 751 EXPECT_CALL(*ct_verifier_, Verify(_, _, _, _, _)) | |
| 752 .WillRepeatedly(Return(OK)); | |
| 753 EXPECT_CALL(*ct_policy_enforcer_, DoesConformToCertPolicy(_, _, _)) | 752 EXPECT_CALL(*ct_policy_enforcer_, DoesConformToCertPolicy(_, _, _)) |
| 754 .WillRepeatedly( | 753 .WillRepeatedly( |
| 755 Return(ct::CertPolicyCompliance::CERT_POLICY_COMPLIES_VIA_SCTS)); | 754 Return(ct::CertPolicyCompliance::CERT_POLICY_COMPLIES_VIA_SCTS)); |
| 756 EXPECT_CALL(*ct_policy_enforcer_, DoesConformToCTEVPolicy(_, _, _, _)) | 755 EXPECT_CALL(*ct_policy_enforcer_, DoesConformToCTEVPolicy(_, _, _, _)) |
| 757 .WillRepeatedly( | 756 .WillRepeatedly( |
| 758 Return(ct::EVPolicyCompliance::EV_POLICY_COMPLIES_VIA_SCTS)); | 757 Return(ct::EVPolicyCompliance::EV_POLICY_COMPLIES_VIA_SCTS)); |
| 759 } | 758 } |
| 760 | 759 |
| 761 protected: | 760 protected: |
| 762 // The address of the spawned test server, after calling StartTestServer(). | 761 // The address of the spawned test server, after calling StartTestServer(). |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 // Get the MockCertVerifier to verify it as an EV cert. | 839 // Get the MockCertVerifier to verify it as an EV cert. |
| 841 CertVerifyResult verify_result; | 840 CertVerifyResult verify_result; |
| 842 verify_result.cert_status = status; | 841 verify_result.cert_status = status; |
| 843 verify_result.verified_cert = server_cert; | 842 verify_result.verified_cert = server_cert; |
| 844 cert_verifier_->AddResultForCert(server_cert.get(), verify_result, OK); | 843 cert_verifier_->AddResultForCert(server_cert.get(), verify_result, OK); |
| 845 } | 844 } |
| 846 | 845 |
| 847 ClientSocketFactory* socket_factory_; | 846 ClientSocketFactory* socket_factory_; |
| 848 std::unique_ptr<MockCertVerifier> cert_verifier_; | 847 std::unique_ptr<MockCertVerifier> cert_verifier_; |
| 849 std::unique_ptr<TransportSecurityState> transport_security_state_; | 848 std::unique_ptr<TransportSecurityState> transport_security_state_; |
| 850 std::unique_ptr<MockCTVerifier> ct_verifier_; | 849 std::unique_ptr<DoNothingCTVerifier> ct_verifier_; |
| 851 std::unique_ptr<MockCTPolicyEnforcer> ct_policy_enforcer_; | 850 std::unique_ptr<MockCTPolicyEnforcer> ct_policy_enforcer_; |
| 852 SSLClientSocketContext context_; | 851 SSLClientSocketContext context_; |
| 853 std::unique_ptr<SSLClientSocket> sock_; | 852 std::unique_ptr<SSLClientSocket> sock_; |
| 854 TestNetLog log_; | 853 TestNetLog log_; |
| 855 | 854 |
| 856 private: | 855 private: |
| 857 std::unique_ptr<SpawnedTestServer> spawned_test_server_; | 856 std::unique_ptr<SpawnedTestServer> spawned_test_server_; |
| 858 TestCompletionCallback callback_; | 857 TestCompletionCallback callback_; |
| 859 AddressList addr_; | 858 AddressList addr_; |
| 860 }; | 859 }; |
| (...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2296 ssl_options.client_cert_types.push_back(CLIENT_CERT_ECDSA_SIGN); | 2295 ssl_options.client_cert_types.push_back(CLIENT_CERT_ECDSA_SIGN); |
| 2297 scoped_refptr<SSLCertRequestInfo> request_info = GetCertRequest(ssl_options); | 2296 scoped_refptr<SSLCertRequestInfo> request_info = GetCertRequest(ssl_options); |
| 2298 ASSERT_TRUE(request_info.get()); | 2297 ASSERT_TRUE(request_info.get()); |
| 2299 ASSERT_EQ(2u, request_info->cert_key_types.size()); | 2298 ASSERT_EQ(2u, request_info->cert_key_types.size()); |
| 2300 EXPECT_EQ(CLIENT_CERT_RSA_SIGN, request_info->cert_key_types[0]); | 2299 EXPECT_EQ(CLIENT_CERT_RSA_SIGN, request_info->cert_key_types[0]); |
| 2301 EXPECT_EQ(CLIENT_CERT_ECDSA_SIGN, request_info->cert_key_types[1]); | 2300 EXPECT_EQ(CLIENT_CERT_ECDSA_SIGN, request_info->cert_key_types[1]); |
| 2302 } | 2301 } |
| 2303 | 2302 |
| 2304 TEST_F(SSLClientSocketTest, ConnectSignedCertTimestampsEnabledTLSExtension) { | 2303 TEST_F(SSLClientSocketTest, ConnectSignedCertTimestampsEnabledTLSExtension) { |
| 2305 // Encoding of SCT List containing 'test'. | 2304 // Encoding of SCT List containing 'test'. |
| 2306 std::string sct_ext("\x00\x06\x00\x04test", 8); | 2305 base::StringPiece sct_ext("\x00\x06\x00\x04test", 8); |
| 2307 | 2306 |
| 2308 SpawnedTestServer::SSLOptions ssl_options; | 2307 SpawnedTestServer::SSLOptions ssl_options; |
| 2309 ssl_options.signed_cert_timestamps_tls_ext = sct_ext; | 2308 ssl_options.signed_cert_timestamps_tls_ext = sct_ext.as_string(); |
| 2310 ASSERT_TRUE(StartTestServer(ssl_options)); | 2309 ASSERT_TRUE(StartTestServer(ssl_options)); |
| 2311 | 2310 |
| 2312 SSLConfig ssl_config; | 2311 SSLConfig ssl_config; |
| 2313 ssl_config.signed_cert_timestamps_enabled = true; | 2312 ssl_config.signed_cert_timestamps_enabled = true; |
| 2314 | 2313 |
| 2315 MockCTVerifier ct_verifier; | 2314 MockCTVerifier ct_verifier; |
| 2316 SetCTVerifier(&ct_verifier); | 2315 SetCTVerifier(&ct_verifier); |
| 2317 | 2316 |
| 2318 // Check that the SCT list is extracted as expected. | 2317 // Check that the SCT list is extracted as expected. |
| 2319 EXPECT_CALL(ct_verifier, Verify(_, "", sct_ext, _, _)) | 2318 EXPECT_CALL(ct_verifier, Verify(_, _, sct_ext, _, _)); |
|
eroman
2016/12/27 22:00:41
Shouldn't this also clear the sct list?
I am not
Ryan Sleevi
2016/12/27 22:17:19
It's supposed to be exclusively an assign-on-succe
| |
| 2320 .WillRepeatedly(Return(ERR_CT_NO_SCTS_VERIFIED_OK)); | |
| 2321 | 2319 |
| 2322 int rv; | 2320 int rv; |
| 2323 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 2321 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
| 2324 EXPECT_THAT(rv, IsOk()); | 2322 EXPECT_THAT(rv, IsOk()); |
| 2325 | 2323 |
| 2326 EXPECT_TRUE(sock_->signed_cert_timestamps_received_); | 2324 EXPECT_TRUE(sock_->signed_cert_timestamps_received_); |
| 2327 } | 2325 } |
| 2328 | 2326 |
| 2329 // Test that when an EV certificate is received, but no CT verifier | |
| 2330 // or certificate policy enforcer are defined, then the EV status | |
| 2331 // of the certificate is maintained. | |
| 2332 TEST_F(SSLClientSocketTest, EVCertStatusMaintainedNoCTVerifier) { | |
| 2333 SpawnedTestServer::SSLOptions ssl_options; | |
| 2334 ASSERT_TRUE(StartTestServer(ssl_options)); | |
| 2335 | |
| 2336 SSLConfig ssl_config; | |
| 2337 AddServerCertStatusToSSLConfig(CERT_STATUS_IS_EV, &ssl_config); | |
| 2338 | |
| 2339 // No verifier to skip CT and policy checks. | |
| 2340 int rv; | |
| 2341 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | |
| 2342 EXPECT_THAT(rv, IsOk()); | |
| 2343 | |
| 2344 SSLInfo result; | |
| 2345 ASSERT_TRUE(sock_->GetSSLInfo(&result)); | |
| 2346 | |
| 2347 EXPECT_TRUE(result.cert_status & CERT_STATUS_IS_EV); | |
| 2348 } | |
| 2349 | |
| 2350 // Test that when a CT verifier and a CTPolicyEnforcer are defined, and | 2327 // Test that when a CT verifier and a CTPolicyEnforcer are defined, and |
| 2351 // the EV certificate used conforms to the CT/EV policy, its EV status | 2328 // the EV certificate used conforms to the CT/EV policy, its EV status |
| 2352 // is maintained. | 2329 // is maintained. |
| 2353 TEST_F(SSLClientSocketTest, EVCertStatusMaintainedForCompliantCert) { | 2330 TEST_F(SSLClientSocketTest, EVCertStatusMaintainedForCompliantCert) { |
| 2354 SpawnedTestServer::SSLOptions ssl_options; | 2331 SpawnedTestServer::SSLOptions ssl_options; |
| 2355 ASSERT_TRUE(StartTestServer(ssl_options)); | 2332 ASSERT_TRUE(StartTestServer(ssl_options)); |
| 2356 | 2333 |
| 2357 SSLConfig ssl_config; | 2334 SSLConfig ssl_config; |
| 2358 AddServerCertStatusToSSLConfig(CERT_STATUS_IS_EV, &ssl_config); | 2335 AddServerCertStatusToSSLConfig(CERT_STATUS_IS_EV, &ssl_config); |
| 2359 | 2336 |
| 2360 // To activate the CT/EV policy enforcement non-null CTVerifier and | |
| 2361 // CTPolicyEnforcer are needed. | |
| 2362 MockCTVerifier ct_verifier; | |
| 2363 SetCTVerifier(&ct_verifier); | |
| 2364 EXPECT_CALL(ct_verifier, Verify(_, "", "", _, _)).WillRepeatedly(Return(OK)); | |
| 2365 | |
| 2366 // Emulate compliance of the certificate to the policy. | 2337 // Emulate compliance of the certificate to the policy. |
| 2367 MockCTPolicyEnforcer policy_enforcer; | 2338 MockCTPolicyEnforcer policy_enforcer; |
| 2368 SetCTPolicyEnforcer(&policy_enforcer); | 2339 SetCTPolicyEnforcer(&policy_enforcer); |
| 2369 EXPECT_CALL(policy_enforcer, DoesConformToCertPolicy(_, _, _)) | 2340 EXPECT_CALL(policy_enforcer, DoesConformToCertPolicy(_, _, _)) |
| 2370 .WillRepeatedly( | 2341 .WillRepeatedly( |
| 2371 Return(ct::CertPolicyCompliance::CERT_POLICY_COMPLIES_VIA_SCTS)); | 2342 Return(ct::CertPolicyCompliance::CERT_POLICY_COMPLIES_VIA_SCTS)); |
| 2372 EXPECT_CALL(policy_enforcer, DoesConformToCTEVPolicy(_, _, _, _)) | 2343 EXPECT_CALL(policy_enforcer, DoesConformToCTEVPolicy(_, _, _, _)) |
| 2373 .WillRepeatedly( | 2344 .WillRepeatedly( |
| 2374 Return(ct::EVPolicyCompliance::EV_POLICY_COMPLIES_VIA_SCTS)); | 2345 Return(ct::EVPolicyCompliance::EV_POLICY_COMPLIES_VIA_SCTS)); |
| 2375 | 2346 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2386 // Test that when a CT verifier and a CTPolicyEnforcer are defined, but | 2357 // Test that when a CT verifier and a CTPolicyEnforcer are defined, but |
| 2387 // the EV certificate used does not conform to the CT/EV policy, its EV status | 2358 // the EV certificate used does not conform to the CT/EV policy, its EV status |
| 2388 // is removed. | 2359 // is removed. |
| 2389 TEST_F(SSLClientSocketTest, EVCertStatusRemovedForNonCompliantCert) { | 2360 TEST_F(SSLClientSocketTest, EVCertStatusRemovedForNonCompliantCert) { |
| 2390 SpawnedTestServer::SSLOptions ssl_options; | 2361 SpawnedTestServer::SSLOptions ssl_options; |
| 2391 ASSERT_TRUE(StartTestServer(ssl_options)); | 2362 ASSERT_TRUE(StartTestServer(ssl_options)); |
| 2392 | 2363 |
| 2393 SSLConfig ssl_config; | 2364 SSLConfig ssl_config; |
| 2394 AddServerCertStatusToSSLConfig(CERT_STATUS_IS_EV, &ssl_config); | 2365 AddServerCertStatusToSSLConfig(CERT_STATUS_IS_EV, &ssl_config); |
| 2395 | 2366 |
| 2396 // To activate the CT/EV policy enforcement non-null CTVerifier and | |
| 2397 // CTPolicyEnforcer are needed. | |
| 2398 MockCTVerifier ct_verifier; | |
| 2399 SetCTVerifier(&ct_verifier); | |
| 2400 EXPECT_CALL(ct_verifier, Verify(_, "", "", _, _)).WillRepeatedly(Return(OK)); | |
| 2401 | |
| 2402 // Emulate non-compliance of the certificate to the policy. | 2367 // Emulate non-compliance of the certificate to the policy. |
| 2403 MockCTPolicyEnforcer policy_enforcer; | 2368 MockCTPolicyEnforcer policy_enforcer; |
| 2404 SetCTPolicyEnforcer(&policy_enforcer); | 2369 SetCTPolicyEnforcer(&policy_enforcer); |
| 2405 EXPECT_CALL(policy_enforcer, DoesConformToCertPolicy(_, _, _)) | 2370 EXPECT_CALL(policy_enforcer, DoesConformToCertPolicy(_, _, _)) |
| 2406 .WillRepeatedly( | 2371 .WillRepeatedly( |
| 2407 Return(ct::CertPolicyCompliance::CERT_POLICY_NOT_ENOUGH_SCTS)); | 2372 Return(ct::CertPolicyCompliance::CERT_POLICY_NOT_ENOUGH_SCTS)); |
| 2408 EXPECT_CALL(policy_enforcer, DoesConformToCTEVPolicy(_, _, _, _)) | 2373 EXPECT_CALL(policy_enforcer, DoesConformToCTEVPolicy(_, _, _, _)) |
| 2409 .WillRepeatedly( | 2374 .WillRepeatedly( |
| 2410 Return(ct::EVPolicyCompliance::EV_POLICY_NOT_ENOUGH_SCTS)); | 2375 Return(ct::EVPolicyCompliance::EV_POLICY_NOT_ENOUGH_SCTS)); |
| 2411 | 2376 |
| 2412 int rv; | 2377 int rv; |
| 2413 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 2378 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
| 2414 EXPECT_THAT(rv, IsOk()); | 2379 EXPECT_THAT(rv, IsOk()); |
| 2415 | 2380 |
| 2416 SSLInfo result; | 2381 SSLInfo result; |
| 2417 ASSERT_TRUE(sock_->GetSSLInfo(&result)); | 2382 ASSERT_TRUE(sock_->GetSSLInfo(&result)); |
| 2418 | 2383 |
| 2419 EXPECT_FALSE(result.cert_status & CERT_STATUS_IS_EV); | 2384 EXPECT_FALSE(result.cert_status & CERT_STATUS_IS_EV); |
| 2420 EXPECT_TRUE(result.cert_status & CERT_STATUS_CT_COMPLIANCE_FAILED); | 2385 EXPECT_TRUE(result.cert_status & CERT_STATUS_CT_COMPLIANCE_FAILED); |
| 2421 } | 2386 } |
| 2422 | 2387 |
| 2423 namespace { | |
| 2424 | |
| 2425 bool IsValidOCSPResponse(const base::StringPiece& input) { | |
| 2426 der::Parser parser((der::Input(input))); | |
| 2427 der::Parser sequence; | |
| 2428 return parser.ReadSequence(&sequence) && !parser.HasMore() && | |
| 2429 sequence.SkipTag(der::kEnumerated) && | |
| 2430 sequence.SkipTag(der::kTagContextSpecific | der::kTagConstructed | | |
| 2431 0) && | |
| 2432 !sequence.HasMore(); | |
| 2433 } | |
| 2434 | |
| 2435 } // namespace | |
| 2436 | |
| 2437 // Test that enabling Signed Certificate Timestamps enables OCSP stapling. | 2388 // Test that enabling Signed Certificate Timestamps enables OCSP stapling. |
| 2438 TEST_F(SSLClientSocketTest, ConnectSignedCertTimestampsEnabledOCSP) { | 2389 TEST_F(SSLClientSocketTest, ConnectSignedCertTimestampsEnabledOCSP) { |
| 2439 SpawnedTestServer::SSLOptions ssl_options; | 2390 SpawnedTestServer::SSLOptions ssl_options; |
| 2440 ssl_options.staple_ocsp_response = true; | 2391 ssl_options.staple_ocsp_response = true; |
| 2441 // The test server currently only knows how to generate OCSP responses | 2392 // The test server currently only knows how to generate OCSP responses |
| 2442 // for a freshly minted certificate. | 2393 // for a freshly minted certificate. |
| 2443 ssl_options.server_certificate = SpawnedTestServer::SSLOptions::CERT_AUTO; | 2394 ssl_options.server_certificate = SpawnedTestServer::SSLOptions::CERT_AUTO; |
| 2444 | 2395 |
| 2445 ASSERT_TRUE(StartTestServer(ssl_options)); | 2396 ASSERT_TRUE(StartTestServer(ssl_options)); |
| 2446 | 2397 |
| 2447 SSLConfig ssl_config; | 2398 SSLConfig ssl_config; |
| 2448 // Enabling Signed Cert Timestamps ensures we request OCSP stapling for | 2399 // Enabling Signed Cert Timestamps ensures we request OCSP stapling for |
| 2449 // Certificate Transparency verification regardless of whether the platform | 2400 // Certificate Transparency verification regardless of whether the platform |
| 2450 // is able to process the OCSP status itself. | 2401 // is able to process the OCSP status itself. |
| 2451 ssl_config.signed_cert_timestamps_enabled = true; | 2402 ssl_config.signed_cert_timestamps_enabled = true; |
| 2452 | 2403 |
| 2453 MockCTVerifier ct_verifier; | |
| 2454 SetCTVerifier(&ct_verifier); | |
| 2455 | |
| 2456 // Check that the OCSP response is extracted and well-formed. It should be the | |
| 2457 // DER encoding of an OCSPResponse (RFC 2560), so check that it consists of a | |
| 2458 // SEQUENCE of an ENUMERATED type and an element tagged with [0] EXPLICIT. In | |
| 2459 // particular, it should not include the overall two-byte length prefix from | |
| 2460 // TLS. | |
| 2461 EXPECT_CALL(ct_verifier, | |
| 2462 Verify(_, Truly(IsValidOCSPResponse), "", _, _)).WillRepeatedly( | |
| 2463 Return(ERR_CT_NO_SCTS_VERIFIED_OK)); | |
| 2464 | |
| 2465 int rv; | 2404 int rv; |
| 2466 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 2405 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
| 2467 EXPECT_THAT(rv, IsOk()); | 2406 EXPECT_THAT(rv, IsOk()); |
| 2468 | 2407 |
| 2469 EXPECT_TRUE(sock_->stapled_ocsp_response_received_); | 2408 EXPECT_TRUE(sock_->stapled_ocsp_response_received_); |
| 2470 } | 2409 } |
| 2471 | 2410 |
| 2472 TEST_F(SSLClientSocketTest, ConnectSignedCertTimestampsDisabled) { | 2411 TEST_F(SSLClientSocketTest, ConnectSignedCertTimestampsDisabled) { |
| 2473 SpawnedTestServer::SSLOptions ssl_options; | 2412 SpawnedTestServer::SSLOptions ssl_options; |
| 2474 ssl_options.signed_cert_timestamps_tls_ext = "test"; | 2413 ssl_options.signed_cert_timestamps_tls_ext = "test"; |
| (...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3732 if (dump_name.find("parent2/ssl_socket") != std::string::npos) { | 3671 if (dump_name.find("parent2/ssl_socket") != std::string::npos) { |
| 3733 did_dump[1] = true; | 3672 did_dump[1] = true; |
| 3734 // The read buffer is not released, so |buffer_size| can't be 0. | 3673 // The read buffer is not released, so |buffer_size| can't be 0. |
| 3735 ASSERT_NE("0", buffer_size); | 3674 ASSERT_NE("0", buffer_size); |
| 3736 } | 3675 } |
| 3737 } | 3676 } |
| 3738 EXPECT_THAT(did_dump, testing::ElementsAre(true, true)); | 3677 EXPECT_THAT(did_dump, testing::ElementsAre(true, true)); |
| 3739 } | 3678 } |
| 3740 | 3679 |
| 3741 } // namespace net | 3680 } // namespace net |
| OLD | NEW |