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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 rtc::scoped_ptr<rtc::SSLAdapter> ssl_adapter_; | 125 rtc::scoped_ptr<rtc::SSLAdapter> ssl_adapter_; |
126 | 126 |
127 std::string data_; | 127 std::string data_; |
128 }; | 128 }; |
129 | 129 |
130 class SSLAdapterTestDummyServer : public sigslot::has_slots<> { | 130 class SSLAdapterTestDummyServer : public sigslot::has_slots<> { |
131 public: | 131 public: |
132 explicit SSLAdapterTestDummyServer(const rtc::SSLMode& ssl_mode) | 132 explicit SSLAdapterTestDummyServer(const rtc::SSLMode& ssl_mode) |
133 : ssl_mode_(ssl_mode) { | 133 : ssl_mode_(ssl_mode) { |
134 // Generate a key pair and a certificate for this host. | 134 // Generate a key pair and a certificate for this host. |
135 ssl_identity_.reset(rtc::SSLIdentity::Generate(GetHostname())); | 135 ssl_certificate_ = webrtc::DtlsCertificate::Create( |
| 136 rtc::scoped_ptr<rtc::SSLIdentity>( |
| 137 rtc::SSLIdentity::Generate(GetHostname())).Pass()); |
136 | 138 |
137 server_socket_.reset(CreateSocket(ssl_mode_)); | 139 server_socket_.reset(CreateSocket(ssl_mode_)); |
138 | 140 |
139 if (ssl_mode_ == rtc::SSL_MODE_TLS) { | 141 if (ssl_mode_ == rtc::SSL_MODE_TLS) { |
140 server_socket_->SignalReadEvent.connect(this, | 142 server_socket_->SignalReadEvent.connect(this, |
141 &SSLAdapterTestDummyServer::OnServerSocketReadEvent); | 143 &SSLAdapterTestDummyServer::OnServerSocketReadEvent); |
142 | 144 |
143 server_socket_->Listen(1); | 145 server_socket_->Listen(1); |
144 } | 146 } |
145 | 147 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 ssl_stream_adapter_->SetMode(ssl_mode_); | 236 ssl_stream_adapter_->SetMode(ssl_mode_); |
235 ssl_stream_adapter_->SetServerRole(); | 237 ssl_stream_adapter_->SetServerRole(); |
236 | 238 |
237 // SSLStreamAdapter is normally used for peer-to-peer communication, but | 239 // SSLStreamAdapter is normally used for peer-to-peer communication, but |
238 // here we're testing communication between a client and a server | 240 // here we're testing communication between a client and a server |
239 // (e.g. a WebRTC-based application and an RFC 5766 TURN server), where | 241 // (e.g. a WebRTC-based application and an RFC 5766 TURN server), where |
240 // clients are not required to provide a certificate during handshake. | 242 // clients are not required to provide a certificate during handshake. |
241 // Accordingly, we must disable client authentication here. | 243 // Accordingly, we must disable client authentication here. |
242 ssl_stream_adapter_->set_client_auth_enabled(false); | 244 ssl_stream_adapter_->set_client_auth_enabled(false); |
243 | 245 |
244 ssl_stream_adapter_->SetIdentity(ssl_identity_->GetReference()); | 246 ssl_stream_adapter_->SetCertificate(ssl_certificate_); |
245 | 247 |
246 // Set a bogus peer certificate digest. | 248 // Set a bogus peer certificate digest. |
247 unsigned char digest[20]; | 249 unsigned char digest[20]; |
248 size_t digest_len = sizeof(digest); | 250 size_t digest_len = sizeof(digest); |
249 ssl_stream_adapter_->SetPeerCertificateDigest(rtc::DIGEST_SHA_1, digest, | 251 ssl_stream_adapter_->SetPeerCertificateDigest(rtc::DIGEST_SHA_1, digest, |
250 digest_len); | 252 digest_len); |
251 | 253 |
252 ssl_stream_adapter_->StartSSLWithPeer(); | 254 ssl_stream_adapter_->StartSSLWithPeer(); |
253 | 255 |
254 ssl_stream_adapter_->SignalEvent.connect(this, | 256 ssl_stream_adapter_->SignalEvent.connect(this, |
255 &SSLAdapterTestDummyServer::OnSSLStreamAdapterEvent); | 257 &SSLAdapterTestDummyServer::OnSSLStreamAdapterEvent); |
256 } | 258 } |
257 | 259 |
258 const rtc::SSLMode ssl_mode_; | 260 const rtc::SSLMode ssl_mode_; |
259 | 261 |
260 rtc::scoped_ptr<rtc::AsyncSocket> server_socket_; | 262 rtc::scoped_ptr<rtc::AsyncSocket> server_socket_; |
261 rtc::scoped_ptr<rtc::SSLStreamAdapter> ssl_stream_adapter_; | 263 rtc::scoped_ptr<rtc::SSLStreamAdapter> ssl_stream_adapter_; |
262 | 264 |
263 rtc::scoped_ptr<rtc::SSLIdentity> ssl_identity_; | 265 rtc::scoped_refptr<webrtc::DtlsCertificate> ssl_certificate_; |
264 | 266 |
265 std::string data_; | 267 std::string data_; |
266 }; | 268 }; |
267 | 269 |
268 class SSLAdapterTestBase : public testing::Test, | 270 class SSLAdapterTestBase : public testing::Test, |
269 public sigslot::has_slots<> { | 271 public sigslot::has_slots<> { |
270 public: | 272 public: |
271 explicit SSLAdapterTestBase(const rtc::SSLMode& ssl_mode) | 273 explicit SSLAdapterTestBase(const rtc::SSLMode& ssl_mode) |
272 : ssl_mode_(ssl_mode), | 274 : ssl_mode_(ssl_mode), |
273 ss_scope_(new rtc::VirtualSocketServer(NULL)), | 275 ss_scope_(new rtc::VirtualSocketServer(NULL)), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 } | 378 } |
377 | 379 |
378 // Test transfer between client and server | 380 // Test transfer between client and server |
379 TEST_F(SSLAdapterTestDTLS, TestDTLSTransfer) { | 381 TEST_F(SSLAdapterTestDTLS, TestDTLSTransfer) { |
380 TestHandshake(true); | 382 TestHandshake(true); |
381 TestTransfer("Hello, world!"); | 383 TestTransfer("Hello, world!"); |
382 } | 384 } |
383 | 385 |
384 #endif // SSL_USE_OPENSSL | 386 #endif // SSL_USE_OPENSSL |
385 | 387 |
OLD | NEW |