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