| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // Since we don't have a real certificate anyway, the value here doesn't | 158 // Since we don't have a real certificate anyway, the value here doesn't |
| 159 // really matter. | 159 // really matter. |
| 160 return "example.com"; | 160 return "example.com"; |
| 161 } | 161 } |
| 162 | 162 |
| 163 const std::string& GetReceivedData() const { | 163 const std::string& GetReceivedData() const { |
| 164 return data_; | 164 return data_; |
| 165 } | 165 } |
| 166 | 166 |
| 167 int Send(const std::string& message) { | 167 int Send(const std::string& message) { |
| 168 if (ssl_stream_adapter_ == NULL | 168 if (ssl_stream_adapter_ == nullptr || |
| 169 || ssl_stream_adapter_->GetState() != rtc::SS_OPEN) { | 169 ssl_stream_adapter_->GetState() != rtc::SS_OPEN) { |
| 170 // No connection yet. | 170 // No connection yet. |
| 171 return -1; | 171 return -1; |
| 172 } | 172 } |
| 173 | 173 |
| 174 LOG(LS_INFO) << "Server sending '" << message << "'"; | 174 LOG(LS_INFO) << "Server sending '" << message << "'"; |
| 175 | 175 |
| 176 size_t written; | 176 size_t written; |
| 177 int error; | 177 int error; |
| 178 | 178 |
| 179 rtc::StreamResult r = ssl_stream_adapter_->Write(message.data(), | 179 rtc::StreamResult r = ssl_stream_adapter_->Write(message.data(), |
| 180 message.length(), &written, &error); | 180 message.length(), &written, &error); |
| 181 if (r == rtc::SR_SUCCESS) { | 181 if (r == rtc::SR_SUCCESS) { |
| 182 return written; | 182 return written; |
| 183 } else { | 183 } else { |
| 184 return -1; | 184 return -1; |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 void AcceptConnection(const rtc::SocketAddress& address) { | 188 void AcceptConnection(const rtc::SocketAddress& address) { |
| 189 // Only a single connection is supported. | 189 // Only a single connection is supported. |
| 190 ASSERT_TRUE(ssl_stream_adapter_ == NULL); | 190 ASSERT_TRUE(ssl_stream_adapter_ == nullptr); |
| 191 | 191 |
| 192 // This is only for DTLS. | 192 // This is only for DTLS. |
| 193 ASSERT_EQ(rtc::SSL_MODE_DTLS, ssl_mode_); | 193 ASSERT_EQ(rtc::SSL_MODE_DTLS, ssl_mode_); |
| 194 | 194 |
| 195 // Transfer ownership of the socket to the SSLStreamAdapter object. | 195 // Transfer ownership of the socket to the SSLStreamAdapter object. |
| 196 rtc::AsyncSocket* socket = server_socket_.release(); | 196 rtc::AsyncSocket* socket = server_socket_.release(); |
| 197 | 197 |
| 198 socket->Connect(address); | 198 socket->Connect(address); |
| 199 | 199 |
| 200 DoHandshake(socket); | 200 DoHandshake(socket); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void OnServerSocketReadEvent(rtc::AsyncSocket* socket) { | 203 void OnServerSocketReadEvent(rtc::AsyncSocket* socket) { |
| 204 // Only a single connection is supported. | 204 // Only a single connection is supported. |
| 205 ASSERT_TRUE(ssl_stream_adapter_ == NULL); | 205 ASSERT_TRUE(ssl_stream_adapter_ == nullptr); |
| 206 | 206 |
| 207 DoHandshake(server_socket_->Accept(NULL)); | 207 DoHandshake(server_socket_->Accept(nullptr)); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void OnSSLStreamAdapterEvent(rtc::StreamInterface* stream, int sig, int err) { | 210 void OnSSLStreamAdapterEvent(rtc::StreamInterface* stream, int sig, int err) { |
| 211 if (sig & rtc::SE_READ) { | 211 if (sig & rtc::SE_READ) { |
| 212 char buffer[4096] = ""; | 212 char buffer[4096] = ""; |
| 213 | 213 |
| 214 size_t read; | 214 size_t read; |
| 215 int error; | 215 int error; |
| 216 | 216 |
| 217 // Read data received from the client and store it in our internal | 217 // Read data received from the client and store it in our internal |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 267 |
| 268 std::string data_; | 268 std::string data_; |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 class SSLAdapterTestBase : public testing::Test, | 271 class SSLAdapterTestBase : public testing::Test, |
| 272 public sigslot::has_slots<> { | 272 public sigslot::has_slots<> { |
| 273 public: | 273 public: |
| 274 explicit SSLAdapterTestBase(const rtc::SSLMode& ssl_mode, | 274 explicit SSLAdapterTestBase(const rtc::SSLMode& ssl_mode, |
| 275 const rtc::KeyParams& key_params) | 275 const rtc::KeyParams& key_params) |
| 276 : ssl_mode_(ssl_mode), | 276 : ssl_mode_(ssl_mode), |
| 277 ss_scope_(new rtc::VirtualSocketServer(NULL)), | 277 ss_scope_(new rtc::VirtualSocketServer(nullptr)), |
| 278 server_(new SSLAdapterTestDummyServer(ssl_mode_, key_params)), | 278 server_(new SSLAdapterTestDummyServer(ssl_mode_, key_params)), |
| 279 client_(new SSLAdapterTestDummyClient(ssl_mode_)), | 279 client_(new SSLAdapterTestDummyClient(ssl_mode_)), |
| 280 handshake_wait_(kTimeout) {} | 280 handshake_wait_(kTimeout) {} |
| 281 | 281 |
| 282 void SetHandshakeWait(int wait) { | 282 void SetHandshakeWait(int wait) { |
| 283 handshake_wait_ = wait; | 283 handshake_wait_ = wait; |
| 284 } | 284 } |
| 285 | 285 |
| 286 void TestHandshake(bool expect_success) { | 286 void TestHandshake(bool expect_success) { |
| 287 int rv; | 287 int rv; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 TEST_F(SSLAdapterTestDTLS_RSA, TestDTLSTransfer) { | 410 TEST_F(SSLAdapterTestDTLS_RSA, TestDTLSTransfer) { |
| 411 TestHandshake(true); | 411 TestHandshake(true); |
| 412 TestTransfer("Hello, world!"); | 412 TestTransfer("Hello, world!"); |
| 413 } | 413 } |
| 414 | 414 |
| 415 // Test transfer between client and server, using ECDSA | 415 // Test transfer between client and server, using ECDSA |
| 416 TEST_F(SSLAdapterTestDTLS_ECDSA, TestDTLSTransfer) { | 416 TEST_F(SSLAdapterTestDTLS_ECDSA, TestDTLSTransfer) { |
| 417 TestHandshake(true); | 417 TestHandshake(true); |
| 418 TestTransfer("Hello, world!"); | 418 TestTransfer("Hello, world!"); |
| 419 } | 419 } |
| OLD | NEW |