| 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 "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 2871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2882 } | 2882 } |
| 2883 | 2883 |
| 2884 TEST_F(SSLClientSocketFalseStartTest, | 2884 TEST_F(SSLClientSocketFalseStartTest, |
| 2885 HandshakeCallbackIsRun_WithFalseStartFailure) { | 2885 HandshakeCallbackIsRun_WithFalseStartFailure) { |
| 2886 // False Start requires NPN and a forward-secret cipher suite. | 2886 // False Start requires NPN and a forward-secret cipher suite. |
| 2887 SpawnedTestServer::SSLOptions server_options; | 2887 SpawnedTestServer::SSLOptions server_options; |
| 2888 server_options.key_exchanges = | 2888 server_options.key_exchanges = |
| 2889 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; | 2889 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; |
| 2890 server_options.enable_npn = true; | 2890 server_options.enable_npn = true; |
| 2891 SSLConfig client_config; | 2891 SSLConfig client_config; |
| 2892 client_config.next_protos.push_back("http/1.1"); | 2892 client_config.next_protos.push_back(kProtoHTTP11); |
| 2893 monitor_handshake_callback_ = true; | 2893 monitor_handshake_callback_ = true; |
| 2894 fail_handshake_after_false_start_ = true; | 2894 fail_handshake_after_false_start_ = true; |
| 2895 ASSERT_NO_FATAL_FAILURE(TestFalseStart(server_options, client_config, true)); | 2895 ASSERT_NO_FATAL_FAILURE(TestFalseStart(server_options, client_config, true)); |
| 2896 ASSERT_TRUE(ran_handshake_completion_callback_); | 2896 ASSERT_TRUE(ran_handshake_completion_callback_); |
| 2897 } | 2897 } |
| 2898 | 2898 |
| 2899 TEST_F(SSLClientSocketFalseStartTest, | 2899 TEST_F(SSLClientSocketFalseStartTest, |
| 2900 HandshakeCallbackIsRun_WithFalseStartSuccess) { | 2900 HandshakeCallbackIsRun_WithFalseStartSuccess) { |
| 2901 // False Start requires NPN and a forward-secret cipher suite. | 2901 // False Start requires NPN and a forward-secret cipher suite. |
| 2902 SpawnedTestServer::SSLOptions server_options; | 2902 SpawnedTestServer::SSLOptions server_options; |
| 2903 server_options.key_exchanges = | 2903 server_options.key_exchanges = |
| 2904 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; | 2904 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; |
| 2905 server_options.enable_npn = true; | 2905 server_options.enable_npn = true; |
| 2906 SSLConfig client_config; | 2906 SSLConfig client_config; |
| 2907 client_config.next_protos.push_back("http/1.1"); | 2907 client_config.next_protos.push_back(kProtoHTTP11); |
| 2908 monitor_handshake_callback_ = true; | 2908 monitor_handshake_callback_ = true; |
| 2909 ASSERT_NO_FATAL_FAILURE(TestFalseStart(server_options, client_config, true)); | 2909 ASSERT_NO_FATAL_FAILURE(TestFalseStart(server_options, client_config, true)); |
| 2910 ASSERT_TRUE(ran_handshake_completion_callback_); | 2910 ASSERT_TRUE(ran_handshake_completion_callback_); |
| 2911 } | 2911 } |
| 2912 #endif // defined(USE_OPENSSL) | 2912 #endif // defined(USE_OPENSSL) |
| 2913 | 2913 |
| 2914 TEST_F(SSLClientSocketFalseStartTest, FalseStartEnabled) { | 2914 TEST_F(SSLClientSocketFalseStartTest, FalseStartEnabled) { |
| 2915 // False Start requires NPN and a forward-secret cipher suite. | 2915 // False Start requires NPN and a forward-secret cipher suite. |
| 2916 SpawnedTestServer::SSLOptions server_options; | 2916 SpawnedTestServer::SSLOptions server_options; |
| 2917 server_options.key_exchanges = | 2917 server_options.key_exchanges = |
| 2918 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; | 2918 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; |
| 2919 server_options.enable_npn = true; | 2919 server_options.enable_npn = true; |
| 2920 SSLConfig client_config; | 2920 SSLConfig client_config; |
| 2921 client_config.next_protos.push_back("http/1.1"); | 2921 client_config.next_protos.push_back(kProtoHTTP11); |
| 2922 ASSERT_NO_FATAL_FAILURE( | 2922 ASSERT_NO_FATAL_FAILURE( |
| 2923 TestFalseStart(server_options, client_config, true)); | 2923 TestFalseStart(server_options, client_config, true)); |
| 2924 } | 2924 } |
| 2925 | 2925 |
| 2926 // Test that False Start is disabled without NPN. | 2926 // Test that False Start is disabled without NPN. |
| 2927 TEST_F(SSLClientSocketFalseStartTest, NoNPN) { | 2927 TEST_F(SSLClientSocketFalseStartTest, NoNPN) { |
| 2928 SpawnedTestServer::SSLOptions server_options; | 2928 SpawnedTestServer::SSLOptions server_options; |
| 2929 server_options.key_exchanges = | 2929 server_options.key_exchanges = |
| 2930 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; | 2930 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; |
| 2931 SSLConfig client_config; | 2931 SSLConfig client_config; |
| 2932 client_config.next_protos.clear(); | 2932 client_config.next_protos.clear(); |
| 2933 ASSERT_NO_FATAL_FAILURE( | 2933 ASSERT_NO_FATAL_FAILURE( |
| 2934 TestFalseStart(server_options, client_config, false)); | 2934 TestFalseStart(server_options, client_config, false)); |
| 2935 } | 2935 } |
| 2936 | 2936 |
| 2937 // Test that False Start is disabled without a forward-secret cipher suite. | 2937 // Test that False Start is disabled without a forward-secret cipher suite. |
| 2938 TEST_F(SSLClientSocketFalseStartTest, NoForwardSecrecy) { | 2938 TEST_F(SSLClientSocketFalseStartTest, NoForwardSecrecy) { |
| 2939 SpawnedTestServer::SSLOptions server_options; | 2939 SpawnedTestServer::SSLOptions server_options; |
| 2940 server_options.key_exchanges = | 2940 server_options.key_exchanges = |
| 2941 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_RSA; | 2941 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_RSA; |
| 2942 server_options.enable_npn = true; | 2942 server_options.enable_npn = true; |
| 2943 SSLConfig client_config; | 2943 SSLConfig client_config; |
| 2944 client_config.next_protos.push_back("http/1.1"); | 2944 client_config.next_protos.push_back(kProtoHTTP11); |
| 2945 ASSERT_NO_FATAL_FAILURE( | 2945 ASSERT_NO_FATAL_FAILURE( |
| 2946 TestFalseStart(server_options, client_config, false)); | 2946 TestFalseStart(server_options, client_config, false)); |
| 2947 } | 2947 } |
| 2948 | 2948 |
| 2949 // Test that sessions are resumable after receiving the server Finished message. | 2949 // Test that sessions are resumable after receiving the server Finished message. |
| 2950 TEST_F(SSLClientSocketFalseStartTest, SessionResumption) { | 2950 TEST_F(SSLClientSocketFalseStartTest, SessionResumption) { |
| 2951 // Start a server. | 2951 // Start a server. |
| 2952 SpawnedTestServer::SSLOptions server_options; | 2952 SpawnedTestServer::SSLOptions server_options; |
| 2953 server_options.key_exchanges = | 2953 server_options.key_exchanges = |
| 2954 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; | 2954 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; |
| 2955 server_options.enable_npn = true; | 2955 server_options.enable_npn = true; |
| 2956 SSLConfig client_config; | 2956 SSLConfig client_config; |
| 2957 client_config.next_protos.push_back("http/1.1"); | 2957 client_config.next_protos.push_back(kProtoHTTP11); |
| 2958 | 2958 |
| 2959 // Let a full handshake complete with False Start. | 2959 // Let a full handshake complete with False Start. |
| 2960 ASSERT_NO_FATAL_FAILURE( | 2960 ASSERT_NO_FATAL_FAILURE( |
| 2961 TestFalseStart(server_options, client_config, true)); | 2961 TestFalseStart(server_options, client_config, true)); |
| 2962 | 2962 |
| 2963 // Make a second connection. | 2963 // Make a second connection. |
| 2964 TestCompletionCallback callback; | 2964 TestCompletionCallback callback; |
| 2965 scoped_ptr<StreamSocket> transport2( | 2965 scoped_ptr<StreamSocket> transport2( |
| 2966 new TCPClientSocket(addr(), &log_, NetLog::Source())); | 2966 new TCPClientSocket(addr(), &log_, NetLog::Source())); |
| 2967 EXPECT_EQ(OK, callback.GetResult(transport2->Connect(callback.callback()))); | 2967 EXPECT_EQ(OK, callback.GetResult(transport2->Connect(callback.callback()))); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2980 // message. | 2980 // message. |
| 2981 TEST_F(SSLClientSocketFalseStartTest, NoSessionResumptionBeforeFinish) { | 2981 TEST_F(SSLClientSocketFalseStartTest, NoSessionResumptionBeforeFinish) { |
| 2982 // Start a server. | 2982 // Start a server. |
| 2983 SpawnedTestServer::SSLOptions server_options; | 2983 SpawnedTestServer::SSLOptions server_options; |
| 2984 server_options.key_exchanges = | 2984 server_options.key_exchanges = |
| 2985 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; | 2985 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; |
| 2986 server_options.enable_npn = true; | 2986 server_options.enable_npn = true; |
| 2987 ASSERT_TRUE(StartTestServer(server_options)); | 2987 ASSERT_TRUE(StartTestServer(server_options)); |
| 2988 | 2988 |
| 2989 SSLConfig client_config; | 2989 SSLConfig client_config; |
| 2990 client_config.next_protos.push_back("http/1.1"); | 2990 client_config.next_protos.push_back(kProtoHTTP11); |
| 2991 | 2991 |
| 2992 // Start a handshake up to the server Finished message. | 2992 // Start a handshake up to the server Finished message. |
| 2993 TestCompletionCallback callback; | 2993 TestCompletionCallback callback; |
| 2994 FakeBlockingStreamSocket* raw_transport1; | 2994 FakeBlockingStreamSocket* raw_transport1; |
| 2995 scoped_ptr<SSLClientSocket> sock1; | 2995 scoped_ptr<SSLClientSocket> sock1; |
| 2996 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( | 2996 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( |
| 2997 client_config, &callback, &raw_transport1, &sock1)); | 2997 client_config, &callback, &raw_transport1, &sock1)); |
| 2998 // Although raw_transport1 has the server Finished blocked, the handshake | 2998 // Although raw_transport1 has the server Finished blocked, the handshake |
| 2999 // still completes. | 2999 // still completes. |
| 3000 EXPECT_EQ(OK, callback.WaitForResult()); | 3000 EXPECT_EQ(OK, callback.WaitForResult()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3073 ssl_config.channel_id_enabled = true; | 3073 ssl_config.channel_id_enabled = true; |
| 3074 | 3074 |
| 3075 int rv; | 3075 int rv; |
| 3076 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 3076 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
| 3077 | 3077 |
| 3078 EXPECT_EQ(ERR_UNEXPECTED, rv); | 3078 EXPECT_EQ(ERR_UNEXPECTED, rv); |
| 3079 EXPECT_FALSE(sock_->IsConnected()); | 3079 EXPECT_FALSE(sock_->IsConnected()); |
| 3080 } | 3080 } |
| 3081 | 3081 |
| 3082 } // namespace net | 3082 } // namespace net |
| OLD | NEW |