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 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 EXPECT_FALSE(sock->IsConnected()); | 809 EXPECT_FALSE(sock->IsConnected()); |
810 EXPECT_TRUE( | 810 EXPECT_TRUE( |
811 test_server.host_port_pair().Equals(request_info->host_and_port)); | 811 test_server.host_port_pair().Equals(request_info->host_and_port)); |
812 | 812 |
813 return request_info; | 813 return request_info; |
814 } | 814 } |
815 }; | 815 }; |
816 | 816 |
817 class SSLClientSocketFalseStartTest : public SSLClientSocketTest { | 817 class SSLClientSocketFalseStartTest : public SSLClientSocketTest { |
818 protected: | 818 protected: |
819 // Creates an SSLClientSocket with |client_config| attached to a | 819 // Creates an SSLClientSocket with |client_config| to a series of modifier |
820 // FakeBlockingStreamSocket, returning both in |*out_raw_transport| and | 820 // sockets: a SynchronousErrorStreamSocket which wraps a |
821 // |*out_sock|. The FakeBlockingStreamSocket is owned by the SSLClientSocket, | 821 // FakeBlockingStreamSocket which wraps the real connection to the test |
822 // so |*out_raw_transport| is a raw pointer. | 822 // server. These are returned in |*out_sock|, |*out_raw_error_socket|, and |
823 // |*out_raw_blocking_socket|, respectively. Note that the last two are raw | |
824 // pointers owned by |*out_sock|. | |
823 // | 825 // |
824 // The client socket will begin a connect using |callback| but stop before the | 826 // The client socket will begin a connect using |callback| but stop before the |
825 // server's finished message is received. The finished message will be blocked | 827 // server's finished message is received. The finished message will be blocked |
826 // in |*out_raw_transport|. To complete the handshake and successfully read | 828 // in |*out_raw_transport|. To complete the handshake and successfully read |
827 // data, the caller must unblock reads on |*out_raw_transport|. (Note that, if | 829 // data, the caller must unblock reads on |*out_raw_transport|. (Note that, if |
828 // the client successfully false started, |callback.WaitForResult()| will | 830 // the client successfully false started, |callback.WaitForResult()| will |
829 // return OK without unblocking transport reads. But Read() will still block.) | 831 // return OK without unblocking transport reads. But Read() will still block.) |
830 // | 832 // |
833 // |*out_raw_error_socket| may be used to cause reading the Finished to fail. | |
834 // | |
831 // Must be called after StartTestServer is called. | 835 // Must be called after StartTestServer is called. |
832 void CreateAndConnectUntilServerFinishedReceived( | 836 void CreateAndConnectUntilServerFinishedReceived( |
833 const SSLConfig& client_config, | 837 const SSLConfig& client_config, |
834 TestCompletionCallback* callback, | 838 TestCompletionCallback* callback, |
835 FakeBlockingStreamSocket** out_raw_transport, | 839 FakeBlockingStreamSocket** out_raw_blocking_socket, |
840 SynchronousErrorStreamSocket** out_raw_error_socket, | |
836 scoped_ptr<SSLClientSocket>* out_sock) { | 841 scoped_ptr<SSLClientSocket>* out_sock) { |
837 CHECK(test_server()); | 842 CHECK(test_server()); |
838 | 843 |
839 scoped_ptr<StreamSocket> real_transport( | 844 scoped_ptr<StreamSocket> real_transport( |
840 new TCPClientSocket(addr(), NULL, NetLog::Source())); | 845 new TCPClientSocket(addr(), NULL, NetLog::Source())); |
841 scoped_ptr<FakeBlockingStreamSocket> transport( | 846 scoped_ptr<FakeBlockingStreamSocket> blocking_socket( |
842 new FakeBlockingStreamSocket(real_transport.Pass())); | 847 new FakeBlockingStreamSocket(real_transport.Pass())); |
843 int rv = callback->GetResult(transport->Connect(callback->callback())); | 848 FakeBlockingStreamSocket* raw_blocking_socket = blocking_socket.get(); |
849 scoped_ptr<SynchronousErrorStreamSocket> error_socket( | |
850 new SynchronousErrorStreamSocket(blocking_socket.Pass())); | |
851 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); | |
852 int rv = callback->GetResult(error_socket->Connect(callback->callback())); | |
844 EXPECT_EQ(OK, rv); | 853 EXPECT_EQ(OK, rv); |
845 | 854 |
846 FakeBlockingStreamSocket* raw_transport = transport.get(); | |
847 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket( | 855 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket( |
848 transport.Pass(), test_server()->host_port_pair(), client_config); | 856 error_socket.Pass(), test_server()->host_port_pair(), client_config); |
849 | 857 |
850 // Connect. Stop before the client processes the first server leg | 858 // Connect. Stop before the client processes the first server leg |
851 // (ServerHello, etc.) | 859 // (ServerHello, etc.) |
852 raw_transport->BlockReadResult(); | 860 raw_blocking_socket->BlockReadResult(); |
853 rv = sock->Connect(callback->callback()); | 861 rv = sock->Connect(callback->callback()); |
854 EXPECT_EQ(ERR_IO_PENDING, rv); | 862 EXPECT_EQ(ERR_IO_PENDING, rv); |
855 raw_transport->WaitForReadResult(); | 863 raw_blocking_socket->WaitForReadResult(); |
856 | 864 |
857 // Release the ServerHello and wait for the client to write | 865 // Release the ServerHello and wait for the client to write |
858 // ClientKeyExchange, etc. (A proxy for waiting for the entirety of the | 866 // ClientKeyExchange, etc. (A proxy for waiting for the entirety of the |
859 // server's leg to complete, since it may span multiple reads.) | 867 // server's leg to complete, since it may span multiple reads.) |
860 EXPECT_FALSE(callback->have_result()); | 868 EXPECT_FALSE(callback->have_result()); |
861 raw_transport->BlockWrite(); | 869 raw_blocking_socket->BlockWrite(); |
862 raw_transport->UnblockReadResult(); | 870 raw_blocking_socket->UnblockReadResult(); |
863 raw_transport->WaitForWrite(); | 871 raw_blocking_socket->WaitForWrite(); |
864 | 872 |
865 // And, finally, release that and block the next server leg | 873 // And, finally, release that and block the next server leg |
866 // (ChangeCipherSpec, Finished). | 874 // (ChangeCipherSpec, Finished). |
867 raw_transport->BlockReadResult(); | 875 raw_blocking_socket->BlockReadResult(); |
868 raw_transport->UnblockWrite(); | 876 raw_blocking_socket->UnblockWrite(); |
869 | 877 |
870 *out_raw_transport = raw_transport; | 878 *out_raw_error_socket = raw_error_socket; |
879 *out_raw_blocking_socket = raw_blocking_socket; | |
871 *out_sock = sock.Pass(); | 880 *out_sock = sock.Pass(); |
872 } | 881 } |
873 | 882 |
874 void TestFalseStart(const SpawnedTestServer::SSLOptions& server_options, | 883 void TestFalseStart(const SpawnedTestServer::SSLOptions& server_options, |
875 const SSLConfig& client_config, | 884 const SSLConfig& client_config, |
876 bool expect_false_start) { | 885 bool expect_false_start) { |
877 ASSERT_TRUE(StartTestServer(server_options)); | 886 ASSERT_TRUE(StartTestServer(server_options)); |
878 | 887 |
879 TestCompletionCallback callback; | 888 TestCompletionCallback callback; |
880 FakeBlockingStreamSocket* raw_transport = NULL; | 889 FakeBlockingStreamSocket* raw_blocking_socket = nullptr; |
890 SynchronousErrorStreamSocket* raw_error_socket = nullptr; | |
881 scoped_ptr<SSLClientSocket> sock; | 891 scoped_ptr<SSLClientSocket> sock; |
882 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( | 892 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( |
883 client_config, &callback, &raw_transport, &sock)); | 893 client_config, &callback, &raw_blocking_socket, &raw_error_socket, |
894 &sock)); | |
884 | 895 |
885 if (expect_false_start) { | 896 if (expect_false_start) { |
886 // When False Starting, the handshake should complete before receiving the | 897 // When False Starting, the handshake should complete before receiving the |
887 // Change Cipher Spec and Finished messages. | 898 // Change Cipher Spec and Finished messages. |
888 // | 899 // |
889 // Note: callback.have_result() may not be true without waiting. The NSS | 900 // Note: callback.have_result() may not be true without waiting. The NSS |
890 // state machine sometimes lives on a separate thread, so this thread may | 901 // state machine sometimes lives on a separate thread, so this thread may |
891 // not yet have processed the signal that the handshake has completed. | 902 // not yet have processed the signal that the handshake has completed. |
892 int rv = callback.WaitForResult(); | 903 int rv = callback.WaitForResult(); |
893 EXPECT_EQ(OK, rv); | 904 EXPECT_EQ(OK, rv); |
(...skipping 10 matching lines...) Expand all Loading... | |
904 kRequestTextSize, | 915 kRequestTextSize, |
905 callback.callback())); | 916 callback.callback())); |
906 EXPECT_EQ(kRequestTextSize, rv); | 917 EXPECT_EQ(kRequestTextSize, rv); |
907 | 918 |
908 // The read will hang; it's waiting for the peer to complete the | 919 // The read will hang; it's waiting for the peer to complete the |
909 // handshake, and the handshake is still blocked. | 920 // handshake, and the handshake is still blocked. |
910 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); | 921 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); |
911 rv = sock->Read(buf.get(), 4096, callback.callback()); | 922 rv = sock->Read(buf.get(), 4096, callback.callback()); |
912 | 923 |
913 // After releasing reads, the connection proceeds. | 924 // After releasing reads, the connection proceeds. |
914 raw_transport->UnblockReadResult(); | 925 raw_blocking_socket->UnblockReadResult(); |
915 rv = callback.GetResult(rv); | 926 rv = callback.GetResult(rv); |
916 EXPECT_LT(0, rv); | 927 EXPECT_LT(0, rv); |
917 } else { | 928 } else { |
918 // False Start is not enabled, so the handshake will not complete because | 929 // False Start is not enabled, so the handshake will not complete because |
919 // the server second leg is blocked. | 930 // the server second leg is blocked. |
920 base::RunLoop().RunUntilIdle(); | 931 base::RunLoop().RunUntilIdle(); |
921 EXPECT_FALSE(callback.have_result()); | 932 EXPECT_FALSE(callback.have_result()); |
922 } | 933 } |
923 } | 934 } |
924 }; | 935 }; |
(...skipping 1872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2797 EXPECT_TRUE(sock->WasEverUsed()); | 2808 EXPECT_TRUE(sock->WasEverUsed()); |
2798 | 2809 |
2799 // TODO(davidben): Read one byte to ensure the test server has responded and | 2810 // TODO(davidben): Read one byte to ensure the test server has responded and |
2800 // then assert IsConnectedAndIdle is false. This currently doesn't work | 2811 // then assert IsConnectedAndIdle is false. This currently doesn't work |
2801 // because neither SSLClientSocketNSS nor SSLClientSocketOpenSSL check their | 2812 // because neither SSLClientSocketNSS nor SSLClientSocketOpenSSL check their |
2802 // SSL implementation's internal buffers. Either call PR_Available and | 2813 // SSL implementation's internal buffers. Either call PR_Available and |
2803 // SSL_pending, although the former isn't actually implemented or perhaps | 2814 // SSL_pending, although the former isn't actually implemented or perhaps |
2804 // attempt to read one byte extra. | 2815 // attempt to read one byte extra. |
2805 } | 2816 } |
2806 | 2817 |
2818 // Tests that basic session resumption works. | |
2819 TEST_F(SSLClientSocketTest, SessionResumption) { | |
2820 SpawnedTestServer::SSLOptions ssl_options; | |
2821 ASSERT_TRUE(StartTestServer(ssl_options)); | |
2822 | |
2823 // First, perform a full handshake. | |
2824 SSLConfig ssl_config; | |
2825 TestCompletionCallback callback; | |
2826 scoped_ptr<StreamSocket> transport( | |
2827 new TCPClientSocket(addr(), &log_, NetLog::Source())); | |
2828 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); | |
2829 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | |
2830 transport.Pass(), test_server()->host_port_pair(), ssl_config)); | |
2831 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); | |
2832 SSLInfo ssl_info; | |
2833 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info)); | |
2834 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); | |
2835 | |
2836 // The next connection should resume. | |
2837 transport.reset(new TCPClientSocket(addr(), &log_, NetLog::Source())); | |
2838 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); | |
2839 sock = CreateSSLClientSocket(transport.Pass(), | |
2840 test_server()->host_port_pair(), ssl_config); | |
2841 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); | |
2842 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info)); | |
2843 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type); | |
2844 | |
2845 // Using a different HostPortPair uses a different session cache key. | |
2846 transport.reset(new TCPClientSocket(addr(), &log_, NetLog::Source())); | |
2847 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); | |
2848 sock = CreateSSLClientSocket(transport.Pass(), | |
2849 HostPortPair("example.com", 443), ssl_config); | |
2850 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); | |
2851 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info)); | |
2852 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); | |
2853 | |
2854 SSLClientSocket::ClearSessionCache(); | |
2855 | |
2856 // After clearing the session cache, the next handshake doesn't resume. | |
2857 transport.reset(new TCPClientSocket(addr(), &log_, NetLog::Source())); | |
2858 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); | |
2859 sock = CreateSSLClientSocket(transport.Pass(), | |
2860 test_server()->host_port_pair(), ssl_config); | |
2861 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); | |
2862 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info)); | |
2863 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); | |
2864 } | |
2865 | |
2866 // Tests that connections with certificate errors do not add entries to the | |
2867 // session cache. | |
2868 TEST_F(SSLClientSocketTest, CertificateErrorNoResume) { | |
2869 SpawnedTestServer::SSLOptions ssl_options; | |
2870 ASSERT_TRUE(StartTestServer(ssl_options)); | |
2871 | |
2872 cert_verifier_->set_default_result(ERR_CERT_COMMON_NAME_INVALID); | |
2873 | |
2874 SSLConfig ssl_config; | |
2875 TestCompletionCallback callback; | |
2876 scoped_ptr<StreamSocket> transport( | |
2877 new TCPClientSocket(addr(), &log_, NetLog::Source())); | |
2878 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); | |
2879 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | |
2880 transport.Pass(), test_server()->host_port_pair(), ssl_config)); | |
2881 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, | |
2882 callback.GetResult(sock->Connect(callback.callback()))); | |
2883 | |
2884 cert_verifier_->set_default_result(OK); | |
2885 | |
2886 // The next connection should perform a full handshake. | |
2887 transport.reset(new TCPClientSocket(addr(), &log_, NetLog::Source())); | |
2888 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); | |
2889 sock = CreateSSLClientSocket(transport.Pass(), | |
2890 test_server()->host_port_pair(), ssl_config); | |
2891 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); | |
2892 SSLInfo ssl_info; | |
2893 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info)); | |
2894 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); | |
2895 } | |
2896 | |
2807 // Tests that session caches are sharded by max_version. | 2897 // Tests that session caches are sharded by max_version. |
2808 TEST_F(SSLClientSocketTest, FallbackShardSessionCache) { | 2898 TEST_F(SSLClientSocketTest, FallbackShardSessionCache) { |
2809 SpawnedTestServer::SSLOptions ssl_options; | 2899 SpawnedTestServer::SSLOptions ssl_options; |
2810 ASSERT_TRUE(StartTestServer(ssl_options)); | 2900 ASSERT_TRUE(StartTestServer(ssl_options)); |
2811 | 2901 |
2812 // Prepare a normal and fallback SSL config. | 2902 // Prepare a normal and fallback SSL config. |
2813 SSLConfig ssl_config; | 2903 SSLConfig ssl_config; |
2814 SSLConfig fallback_ssl_config; | 2904 SSLConfig fallback_ssl_config; |
2815 fallback_ssl_config.version_max = SSL_PROTOCOL_VERSION_TLS1; | 2905 fallback_ssl_config.version_max = SSL_PROTOCOL_VERSION_TLS1; |
2816 fallback_ssl_config.version_fallback = true; | 2906 fallback_ssl_config.version_fallback = true; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2974 transport2.Pass(), test_server()->host_port_pair(), client_config); | 3064 transport2.Pass(), test_server()->host_port_pair(), client_config); |
2975 ASSERT_TRUE(sock2.get()); | 3065 ASSERT_TRUE(sock2.get()); |
2976 EXPECT_EQ(OK, callback.GetResult(sock2->Connect(callback.callback()))); | 3066 EXPECT_EQ(OK, callback.GetResult(sock2->Connect(callback.callback()))); |
2977 | 3067 |
2978 // It should resume the session. | 3068 // It should resume the session. |
2979 SSLInfo ssl_info; | 3069 SSLInfo ssl_info; |
2980 EXPECT_TRUE(sock2->GetSSLInfo(&ssl_info)); | 3070 EXPECT_TRUE(sock2->GetSSLInfo(&ssl_info)); |
2981 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type); | 3071 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type); |
2982 } | 3072 } |
2983 | 3073 |
2984 // Test that sessions are not resumable before receiving the server Finished | 3074 // Test that False Started sessions are not resumable before receiving the |
2985 // message. | 3075 // server Finished message. |
2986 TEST_F(SSLClientSocketFalseStartTest, NoSessionResumptionBeforeFinish) { | 3076 TEST_F(SSLClientSocketFalseStartTest, NoSessionResumptionBeforeFinish) { |
2987 if (!SupportsAESGCM()) { | 3077 if (!SupportsAESGCM()) { |
2988 LOG(WARNING) << "Skipping test because AES-GCM is not supported."; | 3078 LOG(WARNING) << "Skipping test because AES-GCM is not supported."; |
2989 return; | 3079 return; |
2990 } | 3080 } |
2991 | 3081 |
2992 // Start a server. | 3082 // Start a server. |
2993 SpawnedTestServer::SSLOptions server_options; | 3083 SpawnedTestServer::SSLOptions server_options; |
2994 server_options.key_exchanges = | 3084 server_options.key_exchanges = |
2995 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; | 3085 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; |
2996 server_options.bulk_ciphers = | 3086 server_options.bulk_ciphers = |
2997 SpawnedTestServer::SSLOptions::BULK_CIPHER_AES128GCM; | 3087 SpawnedTestServer::SSLOptions::BULK_CIPHER_AES128GCM; |
2998 server_options.enable_npn = true; | 3088 server_options.enable_npn = true; |
2999 ASSERT_TRUE(StartTestServer(server_options)); | 3089 ASSERT_TRUE(StartTestServer(server_options)); |
3000 | 3090 |
3001 SSLConfig client_config; | 3091 SSLConfig client_config; |
3002 client_config.next_protos.push_back(kProtoHTTP11); | 3092 client_config.next_protos.push_back(kProtoHTTP11); |
3003 | 3093 |
3004 // Start a handshake up to the server Finished message. | 3094 // Start a handshake up to the server Finished message. |
3005 TestCompletionCallback callback; | 3095 TestCompletionCallback callback; |
3006 FakeBlockingStreamSocket* raw_transport1 = NULL; | 3096 FakeBlockingStreamSocket* raw_blocking_socket1 = nullptr; |
3097 SynchronousErrorStreamSocket* raw_error_socket1 = nullptr; | |
3007 scoped_ptr<SSLClientSocket> sock1; | 3098 scoped_ptr<SSLClientSocket> sock1; |
3008 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( | 3099 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( |
3009 client_config, &callback, &raw_transport1, &sock1)); | 3100 client_config, &callback, &raw_blocking_socket1, &raw_error_socket1, |
3010 // Although raw_transport1 has the server Finished blocked, the handshake | 3101 &sock1)); |
3011 // still completes. | 3102 // Although |raw_blocking_socket1| has the server Finished blocked, the |
3103 // handshake still completes. | |
3012 EXPECT_EQ(OK, callback.WaitForResult()); | 3104 EXPECT_EQ(OK, callback.WaitForResult()); |
3013 | 3105 |
3014 // Continue to block the client (|sock1|) from processing the Finished | 3106 // Continue to block the client (|sock1|) from processing the Finished |
3015 // message, but allow it to arrive on the socket. This ensures that, from the | 3107 // message, but allow it to arrive on the socket. This ensures that, from the |
3016 // server's point of view, it has completed the handshake and added the | 3108 // server's point of view, it has completed the handshake and added the |
3017 // session to its session cache. | 3109 // session to its session cache. |
3018 // | 3110 // |
3019 // The actual read on |sock1| will not complete until the Finished message is | 3111 // The actual read on |sock1| will not complete until the Finished message is |
3020 // processed; however, pump the underlying transport so that it is read from | 3112 // processed; however, pump the underlying transport so that it is read from |
3021 // the socket. This still has the potential to race, but is generally unlikely | 3113 // the socket. This still has the potential to race, but is generally unlikely |
3022 // due to socket buffer sizes. | 3114 // due to socket buffer sizes. |
3023 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); | 3115 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); |
3024 int rv = sock1->Read(buf.get(), 4096, callback.callback()); | 3116 int rv = sock1->Read(buf.get(), 4096, callback.callback()); |
3025 EXPECT_EQ(ERR_IO_PENDING, rv); | 3117 EXPECT_EQ(ERR_IO_PENDING, rv); |
3026 raw_transport1->WaitForReadResult(); | 3118 raw_blocking_socket1->WaitForReadResult(); |
3027 | 3119 |
3028 // Drop the old socket. This is needed because the Python test server can't | 3120 // Drop the old socket. This is needed because the Python test server can't |
3029 // service two sockets in parallel. | 3121 // service two sockets in parallel. |
3122 sock1.reset(); | |
3123 | |
3124 // Start a second connection. | |
3125 scoped_ptr<StreamSocket> transport2( | |
3126 new TCPClientSocket(addr(), &log_, NetLog::Source())); | |
3127 EXPECT_EQ(OK, callback.GetResult(transport2->Connect(callback.callback()))); | |
3128 scoped_ptr<SSLClientSocket> sock2 = CreateSSLClientSocket( | |
3129 transport2.Pass(), test_server()->host_port_pair(), client_config); | |
3130 EXPECT_EQ(OK, callback.GetResult(sock2->Connect(callback.callback()))); | |
3131 | |
3132 // No session resumption because the first connection never received a server | |
3133 // Finished message. | |
3134 SSLInfo ssl_info; | |
3135 EXPECT_TRUE(sock2->GetSSLInfo(&ssl_info)); | |
3136 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); | |
3137 } | |
3138 | |
3139 // Test that False Started sessions are not resumable if reading the server | |
3140 // Finished message failed. | |
Ryan Sleevi
2015/04/02 20:00:14
I didn't mean reading the server finished failed -
davidben
2015/04/03 00:37:11
Switched it to that. That was actually somewhat le
| |
3141 TEST_F(SSLClientSocketFalseStartTest, NoSessionResumptionBadFinish) { | |
3142 if (!SupportsAESGCM()) { | |
3143 LOG(WARNING) << "Skipping test because AES-GCM is not supported."; | |
3144 return; | |
3145 } | |
3146 | |
3147 // Start a server. | |
3148 SpawnedTestServer::SSLOptions server_options; | |
3149 server_options.key_exchanges = | |
3150 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; | |
3151 server_options.bulk_ciphers = | |
3152 SpawnedTestServer::SSLOptions::BULK_CIPHER_AES128GCM; | |
3153 server_options.enable_npn = true; | |
3154 ASSERT_TRUE(StartTestServer(server_options)); | |
3155 | |
3156 SSLConfig client_config; | |
3157 client_config.next_protos.push_back(kProtoHTTP11); | |
3158 | |
3159 // Start a handshake up to the server Finished message. | |
3160 TestCompletionCallback callback; | |
3161 FakeBlockingStreamSocket* raw_blocking_socket1 = nullptr; | |
3162 SynchronousErrorStreamSocket* raw_error_socket1 = nullptr; | |
3163 scoped_ptr<SSLClientSocket> sock1; | |
3164 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( | |
3165 client_config, &callback, &raw_blocking_socket1, &raw_error_socket1, | |
3166 &sock1)); | |
3167 // Although |raw_blocking_socket1| has the server Finished blocked, the | |
3168 // handshake still completes. | |
3169 EXPECT_EQ(OK, callback.WaitForResult()); | |
3170 | |
3171 // Fail to read the Finished. | |
3172 raw_error_socket1->SetNextReadError(ERR_CONNECTION_RESET); | |
3173 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); | |
3174 EXPECT_EQ(ERR_CONNECTION_RESET, callback.GetResult(sock1->Read( | |
3175 buf.get(), 4096, callback.callback()))); | |
3176 | |
3177 // Drop the old socket. This is needed because the Python test server can't | |
3178 // service two sockets in parallel. | |
3030 sock1.reset(); | 3179 sock1.reset(); |
3031 | 3180 |
3032 // Start a second connection. | 3181 // Start a second connection. |
3033 scoped_ptr<StreamSocket> transport2( | 3182 scoped_ptr<StreamSocket> transport2( |
3034 new TCPClientSocket(addr(), &log_, NetLog::Source())); | 3183 new TCPClientSocket(addr(), &log_, NetLog::Source())); |
3035 EXPECT_EQ(OK, callback.GetResult(transport2->Connect(callback.callback()))); | 3184 EXPECT_EQ(OK, callback.GetResult(transport2->Connect(callback.callback()))); |
3036 scoped_ptr<SSLClientSocket> sock2 = CreateSSLClientSocket( | 3185 scoped_ptr<SSLClientSocket> sock2 = CreateSSLClientSocket( |
3037 transport2.Pass(), test_server()->host_port_pair(), client_config); | 3186 transport2.Pass(), test_server()->host_port_pair(), client_config); |
3038 EXPECT_EQ(OK, callback.GetResult(sock2->Connect(callback.callback()))); | 3187 EXPECT_EQ(OK, callback.GetResult(sock2->Connect(callback.callback()))); |
3039 | 3188 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3099 ssl_config.channel_id_enabled = true; | 3248 ssl_config.channel_id_enabled = true; |
3100 | 3249 |
3101 int rv; | 3250 int rv; |
3102 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 3251 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
3103 | 3252 |
3104 EXPECT_EQ(ERR_UNEXPECTED, rv); | 3253 EXPECT_EQ(ERR_UNEXPECTED, rv); |
3105 EXPECT_FALSE(sock_->IsConnected()); | 3254 EXPECT_FALSE(sock_->IsConnected()); |
3106 } | 3255 } |
3107 | 3256 |
3108 } // namespace net | 3257 } // namespace net |
OLD | NEW |