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

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

Issue 2382983002: Remove the last of the TLS fallback code. (Closed)
Patch Set: mmenke comments 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
« no previous file with comments | « net/socket/ssl_client_socket_impl.cc ('k') | net/ssl/openssl_ssl_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 // Number of bytes received on the network after the handshake should be 1246 // Number of bytes received on the network after the handshake should be
1247 // higher than the number of encrypted bytes read. 1247 // higher than the number of encrypted bytes read.
1248 EXPECT_GE(sock->GetTotalReceivedBytes() - network_bytes_read_during_handshake, 1248 EXPECT_GE(sock->GetTotalReceivedBytes() - network_bytes_read_during_handshake,
1249 unencrypted_bytes_read); 1249 unencrypted_bytes_read);
1250 1250
1251 // The peer should have cleanly closed the connection with a close_notify. 1251 // The peer should have cleanly closed the connection with a close_notify.
1252 EXPECT_EQ(0, rv); 1252 EXPECT_EQ(0, rv);
1253 } 1253 }
1254 1254
1255 // Tests that SSLClientSocket properly handles when the underlying transport 1255 // Tests that SSLClientSocket properly handles when the underlying transport
1256 // synchronously fails a transport read in during the handshake. The error code 1256 // synchronously fails a transport read in during the handshake.
1257 // should be preserved so SSLv3 fallback logic can condition on it.
1258 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) { 1257 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) {
1259 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 1258 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
1260 1259
1261 TestCompletionCallback callback; 1260 TestCompletionCallback callback;
1262 std::unique_ptr<StreamSocket> real_transport( 1261 std::unique_ptr<StreamSocket> real_transport(
1263 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); 1262 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source()));
1264 std::unique_ptr<SynchronousErrorStreamSocket> transport( 1263 std::unique_ptr<SynchronousErrorStreamSocket> transport(
1265 new SynchronousErrorStreamSocket(std::move(real_transport))); 1264 new SynchronousErrorStreamSocket(std::move(real_transport)));
1266 int rv = callback.GetResult(transport->Connect(callback.callback())); 1265 int rv = callback.GetResult(transport->Connect(callback.callback()));
1267 EXPECT_THAT(rv, IsOk()); 1266 EXPECT_THAT(rv, IsOk());
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after
2646 cert_verifier_->set_default_result(OK); 2645 cert_verifier_->set_default_result(OK);
2647 2646
2648 // The next connection should perform a full handshake. 2647 // The next connection should perform a full handshake.
2649 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); 2648 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv));
2650 ASSERT_THAT(rv, IsOk()); 2649 ASSERT_THAT(rv, IsOk());
2651 SSLInfo ssl_info; 2650 SSLInfo ssl_info;
2652 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); 2651 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info));
2653 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); 2652 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type);
2654 } 2653 }
2655 2654
2656 // Tests that session caches are sharded by max_version.
2657 TEST_F(SSLClientSocketTest, FallbackShardSessionCache) {
2658 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
2659
2660 // Prepare a normal and fallback SSL config.
2661 SSLConfig ssl_config;
2662 SSLConfig fallback_ssl_config;
2663 fallback_ssl_config.version_max = SSL_PROTOCOL_VERSION_TLS1;
2664 fallback_ssl_config.version_fallback_min = SSL_PROTOCOL_VERSION_TLS1;
2665 fallback_ssl_config.version_fallback = true;
2666
2667 // Connect with a fallback config from the test server to add an entry to the
2668 // session cache.
2669 int rv;
2670 ASSERT_TRUE(CreateAndConnectSSLClientSocket(fallback_ssl_config, &rv));
2671 EXPECT_THAT(rv, IsOk());
2672 SSLInfo ssl_info;
2673 EXPECT_TRUE(sock_->GetSSLInfo(&ssl_info));
2674 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type);
2675 EXPECT_EQ(SSL_CONNECTION_VERSION_TLS1,
2676 SSLConnectionStatusToVersion(ssl_info.connection_status));
2677
2678 // A non-fallback connection needs a full handshake.
2679 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv));
2680 EXPECT_THAT(rv, IsOk());
2681 EXPECT_TRUE(sock_->GetSSLInfo(&ssl_info));
2682 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type);
2683 EXPECT_EQ(SSL_CONNECTION_VERSION_TLS1_2,
2684 SSLConnectionStatusToVersion(ssl_info.connection_status));
2685
2686 // Note: if the server (correctly) declines to resume a TLS 1.0 session at TLS
2687 // 1.2, the above test would not be sufficient to prove the session caches are
2688 // sharded. Implementations vary here, so, to avoid being sensitive to this,
2689 // attempt to resume with two more connections.
2690
2691 // The non-fallback connection added a > TLS 1.0 entry to the session cache.
2692 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv));
2693 EXPECT_THAT(rv, IsOk());
2694 EXPECT_TRUE(sock_->GetSSLInfo(&ssl_info));
2695 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type);
2696 // This does not check for equality because TLS 1.2 support is conditional on
2697 // system NSS features.
2698 EXPECT_LT(SSL_CONNECTION_VERSION_TLS1,
2699 SSLConnectionStatusToVersion(ssl_info.connection_status));
2700
2701 // The fallback connection still resumes from its session cache. It cannot
2702 // offer the > TLS 1.0 session, so this must have been the session from the
2703 // first fallback connection.
2704 ASSERT_TRUE(CreateAndConnectSSLClientSocket(fallback_ssl_config, &rv));
2705 EXPECT_THAT(rv, IsOk());
2706 EXPECT_TRUE(sock_->GetSSLInfo(&ssl_info));
2707 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type);
2708 EXPECT_EQ(SSL_CONNECTION_VERSION_TLS1,
2709 SSLConnectionStatusToVersion(ssl_info.connection_status));
2710 }
2711
2712 // Test that DHE is removed but gives a dedicated error. Also test that the 2655 // Test that DHE is removed but gives a dedicated error. Also test that the
2713 // dhe_enabled option can restore it. 2656 // dhe_enabled option can restore it.
2714 TEST_F(SSLClientSocketTest, DHE) { 2657 TEST_F(SSLClientSocketTest, DHE) {
2715 SpawnedTestServer::SSLOptions ssl_options; 2658 SpawnedTestServer::SSLOptions ssl_options;
2716 ssl_options.key_exchanges = 2659 ssl_options.key_exchanges =
2717 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; 2660 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA;
2718 ASSERT_TRUE(StartTestServer(ssl_options)); 2661 ASSERT_TRUE(StartTestServer(ssl_options));
2719 2662
2720 // Normal handshakes with DHE do not work, with or without DHE enabled. 2663 // Normal handshakes with DHE do not work, with or without DHE enabled.
2721 SSLConfig ssl_config; 2664 SSLConfig ssl_config;
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after
3725 // Replace it with an alert. 3668 // Replace it with an alert.
3726 raw_transport->ReplaceReadResult( 3669 raw_transport->ReplaceReadResult(
3727 FormatTLS12Alert(49 /* AlertDescription.access_denied */)); 3670 FormatTLS12Alert(49 /* AlertDescription.access_denied */));
3728 raw_transport->UnblockReadResult(); 3671 raw_transport->UnblockReadResult();
3729 3672
3730 rv = callback.GetResult(rv); 3673 rv = callback.GetResult(rv);
3731 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); 3674 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT));
3732 } 3675 }
3733 3676
3734 } // namespace net 3677 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_impl.cc ('k') | net/ssl/openssl_ssl_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698