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 "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 }; | 155 }; |
156 | 156 |
157 ReadBufferingStreamSocket::ReadBufferingStreamSocket( | 157 ReadBufferingStreamSocket::ReadBufferingStreamSocket( |
158 scoped_ptr<net::StreamSocket> transport) | 158 scoped_ptr<net::StreamSocket> transport) |
159 : WrappedStreamSocket(transport.Pass()), | 159 : WrappedStreamSocket(transport.Pass()), |
160 read_buffer_(new net::GrowableIOBuffer()), | 160 read_buffer_(new net::GrowableIOBuffer()), |
161 buffer_size_(0) { | 161 buffer_size_(0) { |
162 } | 162 } |
163 | 163 |
164 void ReadBufferingStreamSocket::SetBufferSize(int size) { | 164 void ReadBufferingStreamSocket::SetBufferSize(int size) { |
165 DCHECK(!user_read_buf_); | 165 DCHECK(!user_read_buf_.get()); |
166 buffer_size_ = size; | 166 buffer_size_ = size; |
167 read_buffer_->SetCapacity(size); | 167 read_buffer_->SetCapacity(size); |
168 } | 168 } |
169 | 169 |
170 int ReadBufferingStreamSocket::Read(net::IOBuffer* buf, | 170 int ReadBufferingStreamSocket::Read(net::IOBuffer* buf, |
171 int buf_len, | 171 int buf_len, |
172 const net::CompletionCallback& callback) { | 172 const net::CompletionCallback& callback) { |
173 if (buffer_size_ == 0) | 173 if (buffer_size_ == 0) |
174 return transport_->Read(buf, buf_len, callback); | 174 return transport_->Read(buf, buf_len, callback); |
175 | 175 |
(...skipping 27 matching lines...) Expand all Loading... |
203 NOTREACHED() << "Unexpected state: " << current_state; | 203 NOTREACHED() << "Unexpected state: " << current_state; |
204 rv = net::ERR_UNEXPECTED; | 204 rv = net::ERR_UNEXPECTED; |
205 break; | 205 break; |
206 } | 206 } |
207 } while (rv != net::ERR_IO_PENDING && state_ != STATE_NONE); | 207 } while (rv != net::ERR_IO_PENDING && state_ != STATE_NONE); |
208 return rv; | 208 return rv; |
209 } | 209 } |
210 | 210 |
211 int ReadBufferingStreamSocket::DoRead() { | 211 int ReadBufferingStreamSocket::DoRead() { |
212 state_ = STATE_READ_COMPLETE; | 212 state_ = STATE_READ_COMPLETE; |
213 int rv = transport_->Read( | 213 int rv = |
214 read_buffer_, | 214 transport_->Read(read_buffer_.get(), |
215 read_buffer_->RemainingCapacity(), | 215 read_buffer_->RemainingCapacity(), |
216 base::Bind(&ReadBufferingStreamSocket::OnReadCompleted, | 216 base::Bind(&ReadBufferingStreamSocket::OnReadCompleted, |
217 base::Unretained(this))); | 217 base::Unretained(this))); |
218 return rv; | 218 return rv; |
219 } | 219 } |
220 | 220 |
221 int ReadBufferingStreamSocket::DoReadComplete(int result) { | 221 int ReadBufferingStreamSocket::DoReadComplete(int result) { |
222 state_ = STATE_NONE; | 222 state_ = STATE_NONE; |
223 if (result <= 0) | 223 if (result <= 0) |
224 return result; | 224 return result; |
225 | 225 |
226 read_buffer_->set_offset(read_buffer_->offset() + result); | 226 read_buffer_->set_offset(read_buffer_->offset() + result); |
227 if (read_buffer_->RemainingCapacity() > 0) { | 227 if (read_buffer_->RemainingCapacity() > 0) { |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 if (rv == net::ERR_IO_PENDING) | 828 if (rv == net::ERR_IO_PENDING) |
829 rv = callback.WaitForResult(); | 829 rv = callback.WaitForResult(); |
830 EXPECT_EQ(net::OK, rv); | 830 EXPECT_EQ(net::OK, rv); |
831 EXPECT_TRUE(sock->IsConnected()); | 831 EXPECT_TRUE(sock->IsConnected()); |
832 | 832 |
833 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 833 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
834 scoped_refptr<net::IOBuffer> request_buffer( | 834 scoped_refptr<net::IOBuffer> request_buffer( |
835 new net::IOBuffer(arraysize(request_text) - 1)); | 835 new net::IOBuffer(arraysize(request_text) - 1)); |
836 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | 836 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); |
837 | 837 |
838 rv = sock->Write(request_buffer, arraysize(request_text) - 1, | 838 rv = sock->Write( |
839 callback.callback()); | 839 request_buffer.get(), arraysize(request_text) - 1, callback.callback()); |
840 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 840 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
841 | 841 |
842 if (rv == net::ERR_IO_PENDING) | 842 if (rv == net::ERR_IO_PENDING) |
843 rv = callback.WaitForResult(); | 843 rv = callback.WaitForResult(); |
844 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); | 844 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); |
845 | 845 |
846 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); | 846 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); |
847 for (;;) { | 847 for (;;) { |
848 rv = sock->Read(buf, 4096, callback.callback()); | 848 rv = sock->Read(buf.get(), 4096, callback.callback()); |
849 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 849 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
850 | 850 |
851 if (rv == net::ERR_IO_PENDING) | 851 if (rv == net::ERR_IO_PENDING) |
852 rv = callback.WaitForResult(); | 852 rv = callback.WaitForResult(); |
853 | 853 |
854 EXPECT_GE(rv, 0); | 854 EXPECT_GE(rv, 0); |
855 if (rv <= 0) | 855 if (rv <= 0) |
856 break; | 856 break; |
857 } | 857 } |
858 } | 858 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 EXPECT_EQ(net::OK, rv); | 890 EXPECT_EQ(net::OK, rv); |
891 EXPECT_TRUE(sock->IsConnected()); | 891 EXPECT_TRUE(sock->IsConnected()); |
892 | 892 |
893 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 893 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
894 static const int kRequestTextSize = | 894 static const int kRequestTextSize = |
895 static_cast<int>(arraysize(request_text) - 1); | 895 static_cast<int>(arraysize(request_text) - 1); |
896 scoped_refptr<net::IOBuffer> request_buffer( | 896 scoped_refptr<net::IOBuffer> request_buffer( |
897 new net::IOBuffer(kRequestTextSize)); | 897 new net::IOBuffer(kRequestTextSize)); |
898 memcpy(request_buffer->data(), request_text, kRequestTextSize); | 898 memcpy(request_buffer->data(), request_text, kRequestTextSize); |
899 | 899 |
900 rv = callback.GetResult(sock->Write(request_buffer, kRequestTextSize, | 900 rv = callback.GetResult( |
901 callback.callback())); | 901 sock->Write(request_buffer.get(), kRequestTextSize, callback.callback())); |
902 EXPECT_EQ(kRequestTextSize, rv); | 902 EXPECT_EQ(kRequestTextSize, rv); |
903 | 903 |
904 // Simulate an unclean/forcible shutdown. | 904 // Simulate an unclean/forcible shutdown. |
905 transport->SetNextReadError(net::ERR_CONNECTION_RESET); | 905 transport->SetNextReadError(net::ERR_CONNECTION_RESET); |
906 | 906 |
907 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); | 907 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); |
908 | 908 |
909 // Note: This test will hang if this bug has regressed. Simply checking that | 909 // Note: This test will hang if this bug has regressed. Simply checking that |
910 // rv != ERR_IO_PENDING is insufficient, as ERR_IO_PENDING is a legitimate | 910 // rv != ERR_IO_PENDING is insufficient, as ERR_IO_PENDING is a legitimate |
911 // result when using a dedicated task runner for NSS. | 911 // result when using a dedicated task runner for NSS. |
912 rv = callback.GetResult(sock->Read(buf, 4096, callback.callback())); | 912 rv = callback.GetResult(sock->Read(buf.get(), 4096, callback.callback())); |
913 | 913 |
914 #if !defined(USE_OPENSSL) | 914 #if !defined(USE_OPENSSL) |
915 // NSS records the error exactly | 915 // NSS records the error exactly |
916 EXPECT_EQ(net::ERR_CONNECTION_RESET, rv); | 916 EXPECT_EQ(net::ERR_CONNECTION_RESET, rv); |
917 #else | 917 #else |
918 // OpenSSL treats any errors as a simple EOF. | 918 // OpenSSL treats any errors as a simple EOF. |
919 EXPECT_EQ(0, rv); | 919 EXPECT_EQ(0, rv); |
920 #endif | 920 #endif |
921 } | 921 } |
922 | 922 |
(...skipping 22 matching lines...) Expand all Loading... |
945 kDefaultSSLConfig)); | 945 kDefaultSSLConfig)); |
946 | 946 |
947 rv = sock->Connect(callback.callback()); | 947 rv = sock->Connect(callback.callback()); |
948 if (rv == net::ERR_IO_PENDING) | 948 if (rv == net::ERR_IO_PENDING) |
949 rv = callback.WaitForResult(); | 949 rv = callback.WaitForResult(); |
950 EXPECT_EQ(net::OK, rv); | 950 EXPECT_EQ(net::OK, rv); |
951 EXPECT_TRUE(sock->IsConnected()); | 951 EXPECT_TRUE(sock->IsConnected()); |
952 | 952 |
953 // Issue a "hanging" Read first. | 953 // Issue a "hanging" Read first. |
954 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); | 954 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); |
955 rv = sock->Read(buf, 4096, callback.callback()); | 955 rv = sock->Read(buf.get(), 4096, callback.callback()); |
956 // We haven't written the request, so there should be no response yet. | 956 // We haven't written the request, so there should be no response yet. |
957 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 957 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
958 | 958 |
959 // Write the request. | 959 // Write the request. |
960 // The request is padded with a User-Agent header to a size that causes the | 960 // The request is padded with a User-Agent header to a size that causes the |
961 // memio circular buffer (4k bytes) in SSLClientSocketNSS to wrap around. | 961 // memio circular buffer (4k bytes) in SSLClientSocketNSS to wrap around. |
962 // This tests the fix for http://crbug.com/29815. | 962 // This tests the fix for http://crbug.com/29815. |
963 std::string request_text = "GET / HTTP/1.1\r\nUser-Agent: long browser name "; | 963 std::string request_text = "GET / HTTP/1.1\r\nUser-Agent: long browser name "; |
964 for (int i = 0; i < 3770; ++i) | 964 for (int i = 0; i < 3770; ++i) |
965 request_text.push_back('*'); | 965 request_text.push_back('*'); |
966 request_text.append("\r\n\r\n"); | 966 request_text.append("\r\n\r\n"); |
967 scoped_refptr<net::IOBuffer> request_buffer( | 967 scoped_refptr<net::IOBuffer> request_buffer( |
968 new net::StringIOBuffer(request_text)); | 968 new net::StringIOBuffer(request_text)); |
969 | 969 |
970 net::TestCompletionCallback callback2; // Used for Write only. | 970 net::TestCompletionCallback callback2; // Used for Write only. |
971 rv = sock->Write(request_buffer, request_text.size(), callback2.callback()); | 971 rv = sock->Write( |
| 972 request_buffer.get(), request_text.size(), callback2.callback()); |
972 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 973 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
973 | 974 |
974 if (rv == net::ERR_IO_PENDING) | 975 if (rv == net::ERR_IO_PENDING) |
975 rv = callback2.WaitForResult(); | 976 rv = callback2.WaitForResult(); |
976 EXPECT_EQ(static_cast<int>(request_text.size()), rv); | 977 EXPECT_EQ(static_cast<int>(request_text.size()), rv); |
977 | 978 |
978 // Now get the Read result. | 979 // Now get the Read result. |
979 rv = callback.WaitForResult(); | 980 rv = callback.WaitForResult(); |
980 EXPECT_GT(rv, 0); | 981 EXPECT_GT(rv, 0); |
981 } | 982 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 error_socket->SetNextWriteError(net::ERR_CONNECTION_RESET); | 1033 error_socket->SetNextWriteError(net::ERR_CONNECTION_RESET); |
1033 // ... but have those errors returned asynchronously. Because the Write() will | 1034 // ... but have those errors returned asynchronously. Because the Write() will |
1034 // return first, this will trigger the error. | 1035 // return first, this will trigger the error. |
1035 transport->SetNextReadShouldBlock(); | 1036 transport->SetNextReadShouldBlock(); |
1036 transport->SetNextWriteShouldBlock(); | 1037 transport->SetNextWriteShouldBlock(); |
1037 | 1038 |
1038 // Enqueue a Read() before calling Write(), which should "hang" due to | 1039 // Enqueue a Read() before calling Write(), which should "hang" due to |
1039 // the ERR_IO_PENDING caused by SetReadShouldBlock() and thus return. | 1040 // the ERR_IO_PENDING caused by SetReadShouldBlock() and thus return. |
1040 DeleteSocketCallback read_callback(sock); | 1041 DeleteSocketCallback read_callback(sock); |
1041 scoped_refptr<net::IOBuffer> read_buf(new net::IOBuffer(4096)); | 1042 scoped_refptr<net::IOBuffer> read_buf(new net::IOBuffer(4096)); |
1042 rv = sock->Read(read_buf, 4096, read_callback.callback()); | 1043 rv = sock->Read(read_buf.get(), 4096, read_callback.callback()); |
1043 | 1044 |
1044 // Ensure things didn't complete synchronously, otherwise |sock| is invalid. | 1045 // Ensure things didn't complete synchronously, otherwise |sock| is invalid. |
1045 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 1046 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
1046 ASSERT_FALSE(read_callback.have_result()); | 1047 ASSERT_FALSE(read_callback.have_result()); |
1047 | 1048 |
1048 #if !defined(USE_OPENSSL) | 1049 #if !defined(USE_OPENSSL) |
1049 // NSS follows a pattern where a call to PR_Write will only consume as | 1050 // NSS follows a pattern where a call to PR_Write will only consume as |
1050 // much data as it can encode into application data records before the | 1051 // much data as it can encode into application data records before the |
1051 // internal memio buffer is full, which should only fill if writing a large | 1052 // internal memio buffer is full, which should only fill if writing a large |
1052 // amount of data and the underlying transport is blocked. Once this happens, | 1053 // amount of data and the underlying transport is blocked. Once this happens, |
1053 // NSS will return (total size of all application data records it wrote) - 1, | 1054 // NSS will return (total size of all application data records it wrote) - 1, |
1054 // with the caller expected to resume with the remaining unsent data. | 1055 // with the caller expected to resume with the remaining unsent data. |
1055 // | 1056 // |
1056 // This causes SSLClientSocketNSS::Write to return that it wrote some data | 1057 // This causes SSLClientSocketNSS::Write to return that it wrote some data |
1057 // before it will return ERR_IO_PENDING, so make an extra call to Write() to | 1058 // before it will return ERR_IO_PENDING, so make an extra call to Write() to |
1058 // get the socket in the state needed for the test below. | 1059 // get the socket in the state needed for the test below. |
1059 // | 1060 // |
1060 // This is not needed for OpenSSL, because for OpenSSL, | 1061 // This is not needed for OpenSSL, because for OpenSSL, |
1061 // SSL_MODE_ENABLE_PARTIAL_WRITE is not specified - thus | 1062 // SSL_MODE_ENABLE_PARTIAL_WRITE is not specified - thus |
1062 // SSLClientSocketOpenSSL::Write() will not return until all of | 1063 // SSLClientSocketOpenSSL::Write() will not return until all of |
1063 // |request_buffer| has been written to the underlying BIO (although not | 1064 // |request_buffer| has been written to the underlying BIO (although not |
1064 // necessarily the underlying transport). | 1065 // necessarily the underlying transport). |
1065 rv = callback.GetResult(sock->Write(request_buffer, | 1066 rv = callback.GetResult(sock->Write(request_buffer.get(), |
1066 request_buffer->BytesRemaining(), | 1067 request_buffer->BytesRemaining(), |
1067 callback.callback())); | 1068 callback.callback())); |
1068 ASSERT_LT(0, rv); | 1069 ASSERT_LT(0, rv); |
1069 request_buffer->DidConsume(rv); | 1070 request_buffer->DidConsume(rv); |
1070 | 1071 |
1071 // Guard to ensure that |request_buffer| was larger than all of the internal | 1072 // Guard to ensure that |request_buffer| was larger than all of the internal |
1072 // buffers (transport, memio, NSS) along the way - otherwise the next call | 1073 // buffers (transport, memio, NSS) along the way - otherwise the next call |
1073 // to Write() will crash with an invalid buffer. | 1074 // to Write() will crash with an invalid buffer. |
1074 ASSERT_LT(0, request_buffer->BytesRemaining()); | 1075 ASSERT_LT(0, request_buffer->BytesRemaining()); |
1075 #endif | 1076 #endif |
1076 | 1077 |
1077 // Attempt to write the remaining data. NSS will not be able to consume the | 1078 // Attempt to write the remaining data. NSS will not be able to consume the |
1078 // application data because the internal buffers are full, while OpenSSL will | 1079 // application data because the internal buffers are full, while OpenSSL will |
1079 // return that its blocked because the underlying transport is blocked. | 1080 // return that its blocked because the underlying transport is blocked. |
1080 rv = sock->Write(request_buffer, request_buffer->BytesRemaining(), | 1081 rv = sock->Write(request_buffer.get(), |
| 1082 request_buffer->BytesRemaining(), |
1081 callback.callback()); | 1083 callback.callback()); |
1082 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 1084 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
1083 ASSERT_FALSE(callback.have_result()); | 1085 ASSERT_FALSE(callback.have_result()); |
1084 | 1086 |
1085 // Now unblock Write(), which will invoke OnSendComplete and (eventually) | 1087 // Now unblock Write(), which will invoke OnSendComplete and (eventually) |
1086 // call the Read() callback, deleting the socket and thus aborting calling | 1088 // call the Read() callback, deleting the socket and thus aborting calling |
1087 // the Write() callback. | 1089 // the Write() callback. |
1088 transport->UnblockWrite(); | 1090 transport->UnblockWrite(); |
1089 | 1091 |
1090 rv = read_callback.WaitForResult(); | 1092 rv = read_callback.WaitForResult(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 rv = sock->Connect(callback.callback()); | 1127 rv = sock->Connect(callback.callback()); |
1126 if (rv == net::ERR_IO_PENDING) | 1128 if (rv == net::ERR_IO_PENDING) |
1127 rv = callback.WaitForResult(); | 1129 rv = callback.WaitForResult(); |
1128 EXPECT_EQ(net::OK, rv); | 1130 EXPECT_EQ(net::OK, rv); |
1129 | 1131 |
1130 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 1132 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
1131 scoped_refptr<net::IOBuffer> request_buffer( | 1133 scoped_refptr<net::IOBuffer> request_buffer( |
1132 new net::IOBuffer(arraysize(request_text) - 1)); | 1134 new net::IOBuffer(arraysize(request_text) - 1)); |
1133 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | 1135 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); |
1134 | 1136 |
1135 rv = sock->Write(request_buffer, arraysize(request_text) - 1, | 1137 rv = sock->Write( |
1136 callback.callback()); | 1138 request_buffer.get(), arraysize(request_text) - 1, callback.callback()); |
1137 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 1139 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
1138 | 1140 |
1139 if (rv == net::ERR_IO_PENDING) | 1141 if (rv == net::ERR_IO_PENDING) |
1140 rv = callback.WaitForResult(); | 1142 rv = callback.WaitForResult(); |
1141 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); | 1143 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); |
1142 | 1144 |
1143 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(1)); | 1145 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(1)); |
1144 for (;;) { | 1146 for (;;) { |
1145 rv = sock->Read(buf, 1, callback.callback()); | 1147 rv = sock->Read(buf.get(), 1, callback.callback()); |
1146 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 1148 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
1147 | 1149 |
1148 if (rv == net::ERR_IO_PENDING) | 1150 if (rv == net::ERR_IO_PENDING) |
1149 rv = callback.WaitForResult(); | 1151 rv = callback.WaitForResult(); |
1150 | 1152 |
1151 EXPECT_GE(rv, 0); | 1153 EXPECT_GE(rv, 0); |
1152 if (rv <= 0) | 1154 if (rv <= 0) |
1153 break; | 1155 break; |
1154 } | 1156 } |
1155 } | 1157 } |
(...skipping 23 matching lines...) Expand all Loading... |
1179 rv = callback.GetResult(sock->Connect(callback.callback())); | 1181 rv = callback.GetResult(sock->Connect(callback.callback())); |
1180 ASSERT_EQ(net::OK, rv); | 1182 ASSERT_EQ(net::OK, rv); |
1181 ASSERT_TRUE(sock->IsConnected()); | 1183 ASSERT_TRUE(sock->IsConnected()); |
1182 | 1184 |
1183 const char request_text[] = "GET /ssl-many-small-records HTTP/1.0\r\n\r\n"; | 1185 const char request_text[] = "GET /ssl-many-small-records HTTP/1.0\r\n\r\n"; |
1184 scoped_refptr<net::IOBuffer> request_buffer( | 1186 scoped_refptr<net::IOBuffer> request_buffer( |
1185 new net::IOBuffer(arraysize(request_text) - 1)); | 1187 new net::IOBuffer(arraysize(request_text) - 1)); |
1186 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | 1188 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); |
1187 | 1189 |
1188 rv = callback.GetResult(sock->Write( | 1190 rv = callback.GetResult(sock->Write( |
1189 request_buffer, arraysize(request_text) - 1, callback.callback())); | 1191 request_buffer.get(), arraysize(request_text) - 1, callback.callback())); |
1190 ASSERT_GT(rv, 0); | 1192 ASSERT_GT(rv, 0); |
1191 ASSERT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); | 1193 ASSERT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); |
1192 | 1194 |
1193 // Note: This relies on SSLClientSocketNSS attempting to read up to 17K of | 1195 // Note: This relies on SSLClientSocketNSS attempting to read up to 17K of |
1194 // data (the max SSL record size) at a time. Ensure that at least 15K worth | 1196 // data (the max SSL record size) at a time. Ensure that at least 15K worth |
1195 // of SSL data is buffered first. The 15K of buffered data is made up of | 1197 // of SSL data is buffered first. The 15K of buffered data is made up of |
1196 // many smaller SSL records (the TestServer writes along 1350 byte | 1198 // many smaller SSL records (the TestServer writes along 1350 byte |
1197 // plaintext boundaries), although there may also be a few records that are | 1199 // plaintext boundaries), although there may also be a few records that are |
1198 // smaller or larger, due to timing and SSL False Start. | 1200 // smaller or larger, due to timing and SSL False Start. |
1199 // 15K was chosen because 15K is smaller than the 17K (max) read issued by | 1201 // 15K was chosen because 15K is smaller than the 17K (max) read issued by |
1200 // the SSLClientSocket implementation, and larger than the minimum amount | 1202 // the SSLClientSocket implementation, and larger than the minimum amount |
1201 // of ciphertext necessary to contain the 8K of plaintext requested below. | 1203 // of ciphertext necessary to contain the 8K of plaintext requested below. |
1202 transport->SetBufferSize(15000); | 1204 transport->SetBufferSize(15000); |
1203 | 1205 |
1204 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(8192)); | 1206 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(8192)); |
1205 rv = callback.GetResult(sock->Read(buffer, 8192, callback.callback())); | 1207 rv = callback.GetResult(sock->Read(buffer.get(), 8192, callback.callback())); |
1206 ASSERT_EQ(rv, 8192); | 1208 ASSERT_EQ(rv, 8192); |
1207 } | 1209 } |
1208 | 1210 |
1209 TEST_F(SSLClientSocketTest, Read_Interrupted) { | 1211 TEST_F(SSLClientSocketTest, Read_Interrupted) { |
1210 net::SpawnedTestServer test_server(net::SpawnedTestServer::TYPE_HTTPS, | 1212 net::SpawnedTestServer test_server(net::SpawnedTestServer::TYPE_HTTPS, |
1211 net::SpawnedTestServer::kLocalhost, | 1213 net::SpawnedTestServer::kLocalhost, |
1212 base::FilePath()); | 1214 base::FilePath()); |
1213 ASSERT_TRUE(test_server.Start()); | 1215 ASSERT_TRUE(test_server.Start()); |
1214 | 1216 |
1215 net::AddressList addr; | 1217 net::AddressList addr; |
(...skipping 14 matching lines...) Expand all Loading... |
1230 rv = sock->Connect(callback.callback()); | 1232 rv = sock->Connect(callback.callback()); |
1231 if (rv == net::ERR_IO_PENDING) | 1233 if (rv == net::ERR_IO_PENDING) |
1232 rv = callback.WaitForResult(); | 1234 rv = callback.WaitForResult(); |
1233 EXPECT_EQ(net::OK, rv); | 1235 EXPECT_EQ(net::OK, rv); |
1234 | 1236 |
1235 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 1237 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
1236 scoped_refptr<net::IOBuffer> request_buffer( | 1238 scoped_refptr<net::IOBuffer> request_buffer( |
1237 new net::IOBuffer(arraysize(request_text) - 1)); | 1239 new net::IOBuffer(arraysize(request_text) - 1)); |
1238 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | 1240 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); |
1239 | 1241 |
1240 rv = sock->Write(request_buffer, arraysize(request_text) - 1, | 1242 rv = sock->Write( |
1241 callback.callback()); | 1243 request_buffer.get(), arraysize(request_text) - 1, callback.callback()); |
1242 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 1244 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
1243 | 1245 |
1244 if (rv == net::ERR_IO_PENDING) | 1246 if (rv == net::ERR_IO_PENDING) |
1245 rv = callback.WaitForResult(); | 1247 rv = callback.WaitForResult(); |
1246 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); | 1248 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); |
1247 | 1249 |
1248 // Do a partial read and then exit. This test should not crash! | 1250 // Do a partial read and then exit. This test should not crash! |
1249 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(512)); | 1251 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(512)); |
1250 rv = sock->Read(buf, 512, callback.callback()); | 1252 rv = sock->Read(buf.get(), 512, callback.callback()); |
1251 EXPECT_TRUE(rv > 0 || rv == net::ERR_IO_PENDING); | 1253 EXPECT_TRUE(rv > 0 || rv == net::ERR_IO_PENDING); |
1252 | 1254 |
1253 if (rv == net::ERR_IO_PENDING) | 1255 if (rv == net::ERR_IO_PENDING) |
1254 rv = callback.WaitForResult(); | 1256 rv = callback.WaitForResult(); |
1255 | 1257 |
1256 EXPECT_GT(rv, 0); | 1258 EXPECT_GT(rv, 0); |
1257 } | 1259 } |
1258 | 1260 |
1259 TEST_F(SSLClientSocketTest, Read_FullLogging) { | 1261 TEST_F(SSLClientSocketTest, Read_FullLogging) { |
1260 net::SpawnedTestServer test_server(net::SpawnedTestServer::TYPE_HTTPS, | 1262 net::SpawnedTestServer test_server(net::SpawnedTestServer::TYPE_HTTPS, |
(...skipping 22 matching lines...) Expand all Loading... |
1283 if (rv == net::ERR_IO_PENDING) | 1285 if (rv == net::ERR_IO_PENDING) |
1284 rv = callback.WaitForResult(); | 1286 rv = callback.WaitForResult(); |
1285 EXPECT_EQ(net::OK, rv); | 1287 EXPECT_EQ(net::OK, rv); |
1286 EXPECT_TRUE(sock->IsConnected()); | 1288 EXPECT_TRUE(sock->IsConnected()); |
1287 | 1289 |
1288 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 1290 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
1289 scoped_refptr<net::IOBuffer> request_buffer( | 1291 scoped_refptr<net::IOBuffer> request_buffer( |
1290 new net::IOBuffer(arraysize(request_text) - 1)); | 1292 new net::IOBuffer(arraysize(request_text) - 1)); |
1291 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | 1293 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); |
1292 | 1294 |
1293 rv = sock->Write(request_buffer, arraysize(request_text) - 1, | 1295 rv = sock->Write( |
1294 callback.callback()); | 1296 request_buffer.get(), arraysize(request_text) - 1, callback.callback()); |
1295 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 1297 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
1296 | 1298 |
1297 if (rv == net::ERR_IO_PENDING) | 1299 if (rv == net::ERR_IO_PENDING) |
1298 rv = callback.WaitForResult(); | 1300 rv = callback.WaitForResult(); |
1299 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); | 1301 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); |
1300 | 1302 |
1301 net::CapturingNetLog::CapturedEntryList entries; | 1303 net::CapturingNetLog::CapturedEntryList entries; |
1302 log.GetEntries(&entries); | 1304 log.GetEntries(&entries); |
1303 size_t last_index = net::ExpectLogContainsSomewhereAfter( | 1305 size_t last_index = net::ExpectLogContainsSomewhereAfter( |
1304 entries, 5, net::NetLog::TYPE_SSL_SOCKET_BYTES_SENT, | 1306 entries, 5, net::NetLog::TYPE_SSL_SOCKET_BYTES_SENT, |
1305 net::NetLog::PHASE_NONE); | 1307 net::NetLog::PHASE_NONE); |
1306 | 1308 |
1307 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); | 1309 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); |
1308 for (;;) { | 1310 for (;;) { |
1309 rv = sock->Read(buf, 4096, callback.callback()); | 1311 rv = sock->Read(buf.get(), 4096, callback.callback()); |
1310 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 1312 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
1311 | 1313 |
1312 if (rv == net::ERR_IO_PENDING) | 1314 if (rv == net::ERR_IO_PENDING) |
1313 rv = callback.WaitForResult(); | 1315 rv = callback.WaitForResult(); |
1314 | 1316 |
1315 EXPECT_GE(rv, 0); | 1317 EXPECT_GE(rv, 0); |
1316 if (rv <= 0) | 1318 if (rv <= 0) |
1317 break; | 1319 break; |
1318 | 1320 |
1319 log.GetEntries(&entries); | 1321 log.GetEntries(&entries); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 temp_intermediates.push_back(certs[1]->os_cert_handle()); | 1572 temp_intermediates.push_back(certs[1]->os_cert_handle()); |
1571 temp_intermediates.push_back(certs[2]->os_cert_handle()); | 1573 temp_intermediates.push_back(certs[2]->os_cert_handle()); |
1572 | 1574 |
1573 net::CertVerifyResult verify_result; | 1575 net::CertVerifyResult verify_result; |
1574 verify_result.verified_cert = | 1576 verify_result.verified_cert = |
1575 net::X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 1577 net::X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
1576 temp_intermediates); | 1578 temp_intermediates); |
1577 | 1579 |
1578 // Add a rule that maps the server cert (A) to the chain of A->B->C2 | 1580 // Add a rule that maps the server cert (A) to the chain of A->B->C2 |
1579 // rather than A->B->C. | 1581 // rather than A->B->C. |
1580 cert_verifier_->AddResultForCert(certs[0], verify_result, net::OK); | 1582 cert_verifier_->AddResultForCert(certs[0].get(), verify_result, net::OK); |
1581 | 1583 |
1582 // Load and install the root for the validated chain. | 1584 // Load and install the root for the validated chain. |
1583 scoped_refptr<net::X509Certificate> root_cert = | 1585 scoped_refptr<net::X509Certificate> root_cert = |
1584 net::ImportCertFromFile(net::GetTestCertsDirectory(), | 1586 net::ImportCertFromFile(net::GetTestCertsDirectory(), |
1585 "redundant-validated-chain-root.pem"); | 1587 "redundant-validated-chain-root.pem"); |
1586 ASSERT_NE(static_cast<net::X509Certificate*>(NULL), root_cert); | 1588 ASSERT_NE(static_cast<net::X509Certificate*>(NULL), root_cert); |
1587 net::ScopedTestRoot scoped_root(root_cert); | 1589 net::ScopedTestRoot scoped_root(root_cert.get()); |
1588 | 1590 |
1589 // Set up a test server with CERT_CHAIN_WRONG_ROOT. | 1591 // Set up a test server with CERT_CHAIN_WRONG_ROOT. |
1590 net::SpawnedTestServer::SSLOptions ssl_options( | 1592 net::SpawnedTestServer::SSLOptions ssl_options( |
1591 net::SpawnedTestServer::SSLOptions::CERT_CHAIN_WRONG_ROOT); | 1593 net::SpawnedTestServer::SSLOptions::CERT_CHAIN_WRONG_ROOT); |
1592 net::SpawnedTestServer test_server( | 1594 net::SpawnedTestServer test_server( |
1593 net::SpawnedTestServer::TYPE_HTTPS, ssl_options, | 1595 net::SpawnedTestServer::TYPE_HTTPS, ssl_options, |
1594 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1596 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
1595 ASSERT_TRUE(test_server.Start()); | 1597 ASSERT_TRUE(test_server.Start()); |
1596 | 1598 |
1597 net::AddressList addr; | 1599 net::AddressList addr; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1685 | 1687 |
1686 return request_info; | 1688 return request_info; |
1687 } | 1689 } |
1688 }; | 1690 }; |
1689 | 1691 |
1690 TEST_F(SSLClientSocketCertRequestInfoTest, NoAuthorities) { | 1692 TEST_F(SSLClientSocketCertRequestInfoTest, NoAuthorities) { |
1691 net::SpawnedTestServer::SSLOptions ssl_options; | 1693 net::SpawnedTestServer::SSLOptions ssl_options; |
1692 ssl_options.request_client_certificate = true; | 1694 ssl_options.request_client_certificate = true; |
1693 scoped_refptr<net::SSLCertRequestInfo> request_info = | 1695 scoped_refptr<net::SSLCertRequestInfo> request_info = |
1694 GetCertRequest(ssl_options); | 1696 GetCertRequest(ssl_options); |
1695 ASSERT_TRUE(request_info); | 1697 ASSERT_TRUE(request_info.get()); |
1696 EXPECT_EQ(0u, request_info->cert_authorities.size()); | 1698 EXPECT_EQ(0u, request_info->cert_authorities.size()); |
1697 } | 1699 } |
1698 | 1700 |
1699 TEST_F(SSLClientSocketCertRequestInfoTest, TwoAuthorities) { | 1701 TEST_F(SSLClientSocketCertRequestInfoTest, TwoAuthorities) { |
1700 const base::FilePath::CharType kThawteFile[] = | 1702 const base::FilePath::CharType kThawteFile[] = |
1701 FILE_PATH_LITERAL("thawte.single.pem"); | 1703 FILE_PATH_LITERAL("thawte.single.pem"); |
1702 const unsigned char kThawteDN[] = { | 1704 const unsigned char kThawteDN[] = { |
1703 0x30, 0x4c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, | 1705 0x30, 0x4c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, |
1704 0x02, 0x5a, 0x41, 0x31, 0x25, 0x30, 0x23, 0x06, 0x03, 0x55, 0x04, 0x0a, | 1706 0x02, 0x5a, 0x41, 0x31, 0x25, 0x30, 0x23, 0x06, 0x03, 0x55, 0x04, 0x0a, |
1705 0x13, 0x1c, 0x54, 0x68, 0x61, 0x77, 0x74, 0x65, 0x20, 0x43, 0x6f, 0x6e, | 1707 0x13, 0x1c, 0x54, 0x68, 0x61, 0x77, 0x74, 0x65, 0x20, 0x43, 0x6f, 0x6e, |
(...skipping 20 matching lines...) Expand all Loading... |
1726 const size_t kDiginotarLen = sizeof(kDiginotarDN); | 1728 const size_t kDiginotarLen = sizeof(kDiginotarDN); |
1727 | 1729 |
1728 net::SpawnedTestServer::SSLOptions ssl_options; | 1730 net::SpawnedTestServer::SSLOptions ssl_options; |
1729 ssl_options.request_client_certificate = true; | 1731 ssl_options.request_client_certificate = true; |
1730 ssl_options.client_authorities.push_back( | 1732 ssl_options.client_authorities.push_back( |
1731 net::GetTestClientCertsDirectory().Append(kThawteFile)); | 1733 net::GetTestClientCertsDirectory().Append(kThawteFile)); |
1732 ssl_options.client_authorities.push_back( | 1734 ssl_options.client_authorities.push_back( |
1733 net::GetTestClientCertsDirectory().Append(kDiginotarFile)); | 1735 net::GetTestClientCertsDirectory().Append(kDiginotarFile)); |
1734 scoped_refptr<net::SSLCertRequestInfo> request_info = | 1736 scoped_refptr<net::SSLCertRequestInfo> request_info = |
1735 GetCertRequest(ssl_options); | 1737 GetCertRequest(ssl_options); |
1736 ASSERT_TRUE(request_info); | 1738 ASSERT_TRUE(request_info.get()); |
1737 ASSERT_EQ(2u, request_info->cert_authorities.size()); | 1739 ASSERT_EQ(2u, request_info->cert_authorities.size()); |
1738 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kThawteDN), kThawteLen), | 1740 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kThawteDN), kThawteLen), |
1739 request_info->cert_authorities[0]); | 1741 request_info->cert_authorities[0]); |
1740 EXPECT_EQ( | 1742 EXPECT_EQ( |
1741 std::string(reinterpret_cast<const char*>(kDiginotarDN), kDiginotarLen), | 1743 std::string(reinterpret_cast<const char*>(kDiginotarDN), kDiginotarLen), |
1742 request_info->cert_authorities[1]); | 1744 request_info->cert_authorities[1]); |
1743 } | 1745 } |
OLD | NEW |