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

Side by Side Diff: net/socket/ssl_client_socket_unittest.cc

Issue 2382983002: Remove the last of the TLS fallback code. (Closed)
Patch Set: Created 4 years, 2 months 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
OLDNEW
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 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 // Number of bytes received on the network after the handshake should be 1220 // Number of bytes received on the network after the handshake should be
1221 // higher than the number of encrypted bytes read. 1221 // higher than the number of encrypted bytes read.
1222 EXPECT_GE(sock->GetTotalReceivedBytes() - network_bytes_read_during_handshake, 1222 EXPECT_GE(sock->GetTotalReceivedBytes() - network_bytes_read_during_handshake,
1223 unencrypted_bytes_read); 1223 unencrypted_bytes_read);
1224 1224
1225 // The peer should have cleanly closed the connection with a close_notify. 1225 // The peer should have cleanly closed the connection with a close_notify.
1226 EXPECT_EQ(0, rv); 1226 EXPECT_EQ(0, rv);
1227 } 1227 }
1228 1228
1229 // Tests that SSLClientSocket properly handles when the underlying transport 1229 // Tests that SSLClientSocket properly handles when the underlying transport
1230 // synchronously fails a transport read in during the handshake. The error code 1230 // synchronously fails a transport read in during the handshake.
1231 // should be preserved so SSLv3 fallback logic can condition on it.
1232 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) { 1231 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) {
1233 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1232 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1234 1233
1235 TestCompletionCallback callback; 1234 TestCompletionCallback callback;
1236 std::unique_ptr<StreamSocket> real_transport( 1235 std::unique_ptr<StreamSocket> real_transport(
1237 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); 1236 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1238 std::unique_ptr<SynchronousErrorStreamSocket> transport( 1237 std::unique_ptr<SynchronousErrorStreamSocket> transport(
1239 new SynchronousErrorStreamSocket(std::move(real_transport))); 1238 new SynchronousErrorStreamSocket(std::move(real_transport)));
1240 int rv = callback.GetResult(transport->Connect(callback.callback())); 1239 int rv = callback.GetResult(transport->Connect(callback.callback()));
1241 EXPECT_THAT(rv, IsOk()); 1240 EXPECT_THAT(rv, IsOk());
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after
2620 cert_verifier_->set_default_result(OK); 2619 cert_verifier_->set_default_result(OK);
2621 2620
2622 // The next connection should perform a full handshake. 2621 // The next connection should perform a full handshake.
2623 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); 2622 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv));
2624 ASSERT_THAT(rv, IsOk()); 2623 ASSERT_THAT(rv, IsOk());
2625 SSLInfo ssl_info; 2624 SSLInfo ssl_info;
2626 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); 2625 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info));
2627 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); 2626 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type);
2628 } 2627 }
2629 2628
2630 // Tests that session caches are sharded by max_version.
2631 TEST_F(SSLClientSocketTest, FallbackShardSessionCache) {
2632 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
2633
2634 // Prepare a normal and fallback SSL config.
2635 SSLConfig ssl_config;
2636 SSLConfig fallback_ssl_config;
2637 fallback_ssl_config.version_max = SSL_PROTOCOL_VERSION_TLS1;
2638 fallback_ssl_config.version_fallback_min = SSL_PROTOCOL_VERSION_TLS1;
2639 fallback_ssl_config.version_fallback = true;
2640
2641 // Connect with a fallback config from the test server to add an entry to the
2642 // session cache.
2643 int rv;
2644 ASSERT_TRUE(CreateAndConnectSSLClientSocket(fallback_ssl_config, &rv));
2645 EXPECT_THAT(rv, IsOk());
2646 SSLInfo ssl_info;
2647 EXPECT_TRUE(sock_->GetSSLInfo(&ssl_info));
2648 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type);
2649 EXPECT_EQ(SSL_CONNECTION_VERSION_TLS1,
2650 SSLConnectionStatusToVersion(ssl_info.connection_status));
2651
2652 // A non-fallback connection needs a full handshake.
2653 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv));
2654 EXPECT_THAT(rv, IsOk());
2655 EXPECT_TRUE(sock_->GetSSLInfo(&ssl_info));
2656 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type);
2657 EXPECT_EQ(SSL_CONNECTION_VERSION_TLS1_2,
2658 SSLConnectionStatusToVersion(ssl_info.connection_status));
2659
2660 // Note: if the server (correctly) declines to resume a TLS 1.0 session at TLS
2661 // 1.2, the above test would not be sufficient to prove the session caches are
2662 // sharded. Implementations vary here, so, to avoid being sensitive to this,
2663 // attempt to resume with two more connections.
2664
2665 // The non-fallback connection added a > TLS 1.0 entry to the session cache.
2666 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv));
2667 EXPECT_THAT(rv, IsOk());
2668 EXPECT_TRUE(sock_->GetSSLInfo(&ssl_info));
2669 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type);
2670 // This does not check for equality because TLS 1.2 support is conditional on
2671 // system NSS features.
2672 EXPECT_LT(SSL_CONNECTION_VERSION_TLS1,
2673 SSLConnectionStatusToVersion(ssl_info.connection_status));
2674
2675 // The fallback connection still resumes from its session cache. It cannot
2676 // offer the > TLS 1.0 session, so this must have been the session from the
2677 // first fallback connection.
2678 ASSERT_TRUE(CreateAndConnectSSLClientSocket(fallback_ssl_config, &rv));
2679 EXPECT_THAT(rv, IsOk());
2680 EXPECT_TRUE(sock_->GetSSLInfo(&ssl_info));
2681 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type);
2682 EXPECT_EQ(SSL_CONNECTION_VERSION_TLS1,
2683 SSLConnectionStatusToVersion(ssl_info.connection_status));
2684 }
2685
2686 // Test that DHE is removed but gives a dedicated error. Also test that the 2629 // Test that DHE is removed but gives a dedicated error. Also test that the
2687 // dhe_enabled option can restore it. 2630 // dhe_enabled option can restore it.
2688 TEST_F(SSLClientSocketTest, DHE) { 2631 TEST_F(SSLClientSocketTest, DHE) {
2689 SpawnedTestServer::SSLOptions ssl_options; 2632 SpawnedTestServer::SSLOptions ssl_options;
2690 ssl_options.key_exchanges = 2633 ssl_options.key_exchanges =
2691 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; 2634 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA;
2692 ASSERT_TRUE(StartTestServer(ssl_options)); 2635 ASSERT_TRUE(StartTestServer(ssl_options));
2693 2636
2694 // Normal handshakes with DHE do not work, with or without DHE enabled. 2637 // Normal handshakes with DHE do not work, with or without DHE enabled.
2695 SSLConfig ssl_config; 2638 SSLConfig ssl_config;
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
3427 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); 3370 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info));
3428 3371
3429 EXPECT_THAT(rv, IsError(ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN)); 3372 EXPECT_THAT(rv, IsError(ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN));
3430 EXPECT_TRUE(ssl_info.cert_status & CERT_STATUS_PINNED_KEY_MISSING); 3373 EXPECT_TRUE(ssl_info.cert_status & CERT_STATUS_PINNED_KEY_MISSING);
3431 EXPECT_TRUE(ssl_info.cert_status & 3374 EXPECT_TRUE(ssl_info.cert_status &
3432 CERT_STATUS_CERTIFICATE_TRANSPARENCY_REQUIRED); 3375 CERT_STATUS_CERTIFICATE_TRANSPARENCY_REQUIRED);
3433 EXPECT_TRUE(sock_->IsConnected()); 3376 EXPECT_TRUE(sock_->IsConnected());
3434 } 3377 }
3435 3378
3436 } // namespace net 3379 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698