Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: webrtc/p2p/base/fakesession.h

Issue 1269843005: Added DtlsCertificate, a ref counted object owning an SSLIdentity (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Merge with master Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 public rtc::MessageHandler { 42 public rtc::MessageHandler {
43 public: 43 public:
44 explicit FakeTransportChannel(Transport* transport, 44 explicit FakeTransportChannel(Transport* transport,
45 const std::string& content_name, 45 const std::string& content_name,
46 int component) 46 int component)
47 : TransportChannelImpl(content_name, component), 47 : TransportChannelImpl(content_name, component),
48 transport_(transport), 48 transport_(transport),
49 dest_(NULL), 49 dest_(NULL),
50 state_(STATE_INIT), 50 state_(STATE_INIT),
51 async_(false), 51 async_(false),
52 identity_(NULL), 52 certificate_(nullptr),
53 do_dtls_(false), 53 do_dtls_(false),
54 role_(ICEROLE_UNKNOWN), 54 role_(ICEROLE_UNKNOWN),
55 tiebreaker_(0), 55 tiebreaker_(0),
56 ice_proto_(ICEPROTO_HYBRID), 56 ice_proto_(ICEPROTO_HYBRID),
57 remote_ice_mode_(ICEMODE_FULL), 57 remote_ice_mode_(ICEMODE_FULL),
58 dtls_fingerprint_("", NULL, 0), 58 dtls_fingerprint_("", NULL, 0),
59 ssl_role_(rtc::SSL_CLIENT), 59 ssl_role_(rtc::SSL_CLIENT),
60 connection_count_(0) { 60 connection_count_(0) {
61 } 61 }
62 ~FakeTransportChannel() { 62 ~FakeTransportChannel() {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 146
147 void SetWritable(bool writable) { 147 void SetWritable(bool writable) {
148 set_writable(writable); 148 set_writable(writable);
149 } 149 }
150 150
151 void SetDestination(FakeTransportChannel* dest) { 151 void SetDestination(FakeTransportChannel* dest) {
152 if (state_ == STATE_CONNECTING && dest) { 152 if (state_ == STATE_CONNECTING && dest) {
153 // This simulates the delivery of candidates. 153 // This simulates the delivery of candidates.
154 dest_ = dest; 154 dest_ = dest;
155 dest_->dest_ = this; 155 dest_->dest_ = this;
156 if (identity_ && dest_->identity_) { 156 if (certificate_ && dest_->certificate_) {
157 do_dtls_ = true; 157 do_dtls_ = true;
158 dest_->do_dtls_ = true; 158 dest_->do_dtls_ = true;
159 NegotiateSrtpCiphers(); 159 NegotiateSrtpCiphers();
160 } 160 }
161 state_ = STATE_CONNECTED; 161 state_ = STATE_CONNECTED;
162 dest_->state_ = STATE_CONNECTED; 162 dest_->state_ = STATE_CONNECTED;
163 set_writable(true); 163 set_writable(true);
164 dest_->set_writable(true); 164 dest_->set_writable(true);
165 } else if (state_ == STATE_CONNECTED && !dest) { 165 } else if (state_ == STATE_CONNECTED && !dest) {
166 // Simulates loss of connectivity, by asymmetrically forgetting dest_. 166 // Simulates loss of connectivity, by asymmetrically forgetting dest_.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 217 }
218 218
219 virtual void OnMessage(rtc::Message* msg) { 219 virtual void OnMessage(rtc::Message* msg) {
220 PacketMessageData* data = static_cast<PacketMessageData*>( 220 PacketMessageData* data = static_cast<PacketMessageData*>(
221 msg->pdata); 221 msg->pdata);
222 dest_->SignalReadPacket(dest_, data->packet.data<char>(), 222 dest_->SignalReadPacket(dest_, data->packet.data<char>(),
223 data->packet.size(), rtc::CreatePacketTime(0), 0); 223 data->packet.size(), rtc::CreatePacketTime(0), 0);
224 delete data; 224 delete data;
225 } 225 }
226 226
227 bool SetLocalIdentity(rtc::SSLIdentity* identity) { 227 bool SetLocalCertificate(
228 identity_ = identity; 228 const rtc::scoped_refptr<webrtc::DtlsCertificate>& certificate) override {
229 certificate_ = certificate;
229 return true; 230 return true;
230 } 231 }
231 232
232 233
233 void SetRemoteCertificate(rtc::FakeSSLCertificate* cert) { 234 void SetRemoteCertificate(rtc::FakeSSLCertificate* cert) {
234 remote_cert_ = cert; 235 remote_cert_ = cert;
235 } 236 }
236 237
237 virtual bool IsDtlsActive() const { 238 virtual bool IsDtlsActive() const {
238 return do_dtls_; 239 return do_dtls_;
239 } 240 }
240 241
241 virtual bool SetSrtpCiphers(const std::vector<std::string>& ciphers) { 242 virtual bool SetSrtpCiphers(const std::vector<std::string>& ciphers) {
242 srtp_ciphers_ = ciphers; 243 srtp_ciphers_ = ciphers;
243 return true; 244 return true;
244 } 245 }
245 246
246 virtual bool GetSrtpCipher(std::string* cipher) { 247 virtual bool GetSrtpCipher(std::string* cipher) {
247 if (!chosen_srtp_cipher_.empty()) { 248 if (!chosen_srtp_cipher_.empty()) {
248 *cipher = chosen_srtp_cipher_; 249 *cipher = chosen_srtp_cipher_;
249 return true; 250 return true;
250 } 251 }
251 return false; 252 return false;
252 } 253 }
253 254
254 virtual bool GetSslCipher(std::string* cipher) { 255 virtual bool GetSslCipher(std::string* cipher) {
255 return false; 256 return false;
256 } 257 }
257 258
258 virtual bool GetLocalIdentity(rtc::SSLIdentity** identity) const { 259 bool GetLocalCertificate(
259 if (!identity_) 260 rtc::scoped_refptr<webrtc::DtlsCertificate>* certificate) const override {
261 if (!certificate_.get())
260 return false; 262 return false;
261 263
262 *identity = identity_->GetReference(); 264 *certificate = certificate_;
263 return true; 265 return true;
264 } 266 }
265 267
266 virtual bool GetRemoteCertificate(rtc::SSLCertificate** cert) const { 268 bool GetRemoteCertificate(rtc::SSLCertificate** cert) const override {
267 if (!remote_cert_) 269 if (!remote_cert_)
268 return false; 270 return false;
269 271
270 *cert = remote_cert_->GetReference(); 272 *cert = remote_cert_->GetReference();
271 return true; 273 return true;
272 } 274 }
273 275
274 virtual bool ExportKeyingMaterial(const std::string& label, 276 virtual bool ExportKeyingMaterial(const std::string& label,
275 const uint8* context, 277 const uint8* context,
276 size_t context_len, 278 size_t context_len,
(...skipping 29 matching lines...) Expand all
306 infos->push_back(info); 308 infos->push_back(info);
307 return true; 309 return true;
308 } 310 }
309 311
310 private: 312 private:
311 enum State { STATE_INIT, STATE_CONNECTING, STATE_CONNECTED }; 313 enum State { STATE_INIT, STATE_CONNECTING, STATE_CONNECTED };
312 Transport* transport_; 314 Transport* transport_;
313 FakeTransportChannel* dest_; 315 FakeTransportChannel* dest_;
314 State state_; 316 State state_;
315 bool async_; 317 bool async_;
316 rtc::SSLIdentity* identity_; 318 rtc::scoped_refptr<webrtc::DtlsCertificate> certificate_;
317 rtc::FakeSSLCertificate* remote_cert_; 319 rtc::FakeSSLCertificate* remote_cert_;
318 bool do_dtls_; 320 bool do_dtls_;
319 std::vector<std::string> srtp_ciphers_; 321 std::vector<std::string> srtp_ciphers_;
320 std::string chosen_srtp_cipher_; 322 std::string chosen_srtp_cipher_;
321 IceRole role_; 323 IceRole role_;
322 uint64 tiebreaker_; 324 uint64 tiebreaker_;
323 IceProtocolType ice_proto_; 325 IceProtocolType ice_proto_;
324 std::string ice_ufrag_; 326 std::string ice_ufrag_;
325 std::string ice_pwd_; 327 std::string ice_pwd_;
326 std::string remote_ice_ufrag_; 328 std::string remote_ice_ufrag_;
327 std::string remote_ice_pwd_; 329 std::string remote_ice_pwd_;
328 IceMode remote_ice_mode_; 330 IceMode remote_ice_mode_;
329 rtc::SSLFingerprint dtls_fingerprint_; 331 rtc::SSLFingerprint dtls_fingerprint_;
330 rtc::SSLRole ssl_role_; 332 rtc::SSLRole ssl_role_;
331 size_t connection_count_; 333 size_t connection_count_;
332 }; 334 };
333 335
334 // Fake transport class, which can be passed to anything that needs a Transport. 336 // Fake transport class, which can be passed to anything that needs a Transport.
335 // Can be informed of another FakeTransport via SetDestination (low-tech way 337 // Can be informed of another FakeTransport via SetDestination (low-tech way
336 // of doing candidates) 338 // of doing candidates)
337 class FakeTransport : public Transport { 339 class FakeTransport : public Transport {
338 public: 340 public:
339 typedef std::map<int, FakeTransportChannel*> ChannelMap; 341 typedef std::map<int, FakeTransportChannel*> ChannelMap;
340 FakeTransport(rtc::Thread* signaling_thread, 342 FakeTransport(rtc::Thread* signaling_thread,
341 rtc::Thread* worker_thread, 343 rtc::Thread* worker_thread,
342 const std::string& content_name, 344 const std::string& content_name,
343 PortAllocator* alllocator = NULL) 345 PortAllocator* alllocator = nullptr)
344 : Transport(signaling_thread, worker_thread, 346 : Transport(signaling_thread, worker_thread,
345 content_name, "test_type", NULL), 347 content_name, "test_type", nullptr),
346 dest_(NULL), 348 dest_(nullptr),
347 async_(false), 349 async_(false),
348 identity_(NULL) { 350 certificate_(nullptr) {
349 } 351 }
350 ~FakeTransport() { 352 ~FakeTransport() {
351 DestroyAllChannels(); 353 DestroyAllChannels();
352 } 354 }
353 355
354 const ChannelMap& channels() const { return channels_; } 356 const ChannelMap& channels() const { return channels_; }
355 357
356 void SetAsync(bool async) { async_ = async; } 358 void SetAsync(bool async) { async_ = async; }
357 void SetDestination(FakeTransport* dest) { 359 void SetDestination(FakeTransport* dest) {
358 dest_ = dest; 360 dest_ = dest;
359 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end(); 361 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end();
360 ++it) { 362 ++it) {
361 it->second->SetLocalIdentity(identity_); 363 it->second->SetLocalCertificate(certificate_);
362 SetChannelDestination(it->first, it->second); 364 SetChannelDestination(it->first, it->second);
363 } 365 }
364 } 366 }
365 367
366 void SetWritable(bool writable) { 368 void SetWritable(bool writable) {
367 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end(); 369 for (ChannelMap::iterator it = channels_.begin(); it != channels_.end();
368 ++it) { 370 ++it) {
369 it->second->SetWritable(writable); 371 it->second->SetWritable(writable);
370 } 372 }
371 } 373 }
372 374
373 void set_identity(rtc::SSLIdentity* identity) { 375 void set_certificate(
374 identity_ = identity; 376 const rtc::scoped_refptr<webrtc::DtlsCertificate>& certificate) {
377 certificate_ = certificate;
375 } 378 }
376 379
377 using Transport::local_description; 380 using Transport::local_description;
378 using Transport::remote_description; 381 using Transport::remote_description;
379 382
380 protected: 383 protected:
381 virtual TransportChannelImpl* CreateTransportChannel(int component) { 384 virtual TransportChannelImpl* CreateTransportChannel(int component) {
382 if (channels_.find(component) != channels_.end()) { 385 if (channels_.find(component) != channels_.end()) {
383 return NULL; 386 return NULL;
384 } 387 }
385 FakeTransportChannel* channel = 388 FakeTransportChannel* channel =
386 new FakeTransportChannel(this, content_name(), component); 389 new FakeTransportChannel(this, content_name(), component);
387 channel->SetAsync(async_); 390 channel->SetAsync(async_);
388 SetChannelDestination(component, channel); 391 SetChannelDestination(component, channel);
389 channels_[component] = channel; 392 channels_[component] = channel;
390 return channel; 393 return channel;
391 } 394 }
392 virtual void DestroyTransportChannel(TransportChannelImpl* channel) { 395 virtual void DestroyTransportChannel(TransportChannelImpl* channel) {
393 channels_.erase(channel->component()); 396 channels_.erase(channel->component());
394 delete channel; 397 delete channel;
395 } 398 }
396 virtual void SetIdentity_w(rtc::SSLIdentity* identity) { 399 void SetCertificate_w(
397 identity_ = identity; 400 const rtc::scoped_refptr<webrtc::DtlsCertificate>& certificate) override {
401 certificate_ = certificate;
398 } 402 }
399 virtual bool GetIdentity_w(rtc::SSLIdentity** identity) { 403 bool GetCertificate_w(
400 if (!identity_) 404 rtc::scoped_refptr<webrtc::DtlsCertificate>* certificate) override {
405 if (!certificate_.get())
401 return false; 406 return false;
402 407
403 *identity = identity_->GetReference(); 408 *certificate = certificate_;
404 return true; 409 return true;
405 } 410 }
406 411
407 private: 412 private:
408 FakeTransportChannel* GetFakeChannel(int component) { 413 FakeTransportChannel* GetFakeChannel(int component) {
409 ChannelMap::iterator it = channels_.find(component); 414 ChannelMap::iterator it = channels_.find(component);
410 return (it != channels_.end()) ? it->second : NULL; 415 return (it != channels_.end()) ? it->second : NULL;
411 } 416 }
412 void SetChannelDestination(int component, 417 void SetChannelDestination(int component,
413 FakeTransportChannel* channel) { 418 FakeTransportChannel* channel) {
414 FakeTransportChannel* dest_channel = NULL; 419 FakeTransportChannel* dest_channel = NULL;
415 if (dest_) { 420 if (dest_) {
416 dest_channel = dest_->GetFakeChannel(component); 421 dest_channel = dest_->GetFakeChannel(component);
417 if (dest_channel) { 422 if (dest_channel) {
418 dest_channel->SetLocalIdentity(dest_->identity_); 423 dest_channel->SetLocalCertificate(dest_->certificate_);
419 } 424 }
420 } 425 }
421 channel->SetDestination(dest_channel); 426 channel->SetDestination(dest_channel);
422 } 427 }
423 428
424 // Note, this is distinct from the Channel map owned by Transport. 429 // Note, this is distinct from the Channel map owned by Transport.
425 // This map just tracks the FakeTransportChannels created by this class. 430 // This map just tracks the FakeTransportChannels created by this class.
426 ChannelMap channels_; 431 ChannelMap channels_;
427 FakeTransport* dest_; 432 FakeTransport* dest_;
428 bool async_; 433 bool async_;
429 rtc::SSLIdentity* identity_; 434 rtc::scoped_refptr<webrtc::DtlsCertificate> certificate_;
430 }; 435 };
431 436
432 // Fake session class, which can be passed into a BaseChannel object for 437 // Fake session class, which can be passed into a BaseChannel object for
433 // test purposes. Can be connected to other FakeSessions via Connect(). 438 // test purposes. Can be connected to other FakeSessions via Connect().
434 class FakeSession : public BaseSession { 439 class FakeSession : public BaseSession {
435 public: 440 public:
436 explicit FakeSession() 441 explicit FakeSession()
437 : BaseSession(rtc::Thread::Current(), 442 : BaseSession(rtc::Thread::Current(),
438 rtc::Thread::Current(), 443 rtc::Thread::Current(),
439 NULL, "", "", true), 444 NULL, "", "", true),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 return NULL; 480 return NULL;
476 } 481 }
477 return BaseSession::CreateChannel(content_name, component); 482 return BaseSession::CreateChannel(content_name, component);
478 } 483 }
479 484
480 void set_fail_channel_creation(bool fail_channel_creation) { 485 void set_fail_channel_creation(bool fail_channel_creation) {
481 fail_create_channel_ = fail_channel_creation; 486 fail_create_channel_ = fail_channel_creation;
482 } 487 }
483 488
484 // TODO: Hoist this into Session when we re-work the Session code. 489 // TODO: Hoist this into Session when we re-work the Session code.
485 void set_ssl_identity(rtc::SSLIdentity* identity) { 490 void set_ssl_certificate(
491 const rtc::scoped_refptr<webrtc::DtlsCertificate>& certificate) {
486 for (TransportMap::const_iterator it = transport_proxies().begin(); 492 for (TransportMap::const_iterator it = transport_proxies().begin();
487 it != transport_proxies().end(); ++it) { 493 it != transport_proxies().end(); ++it) {
488 // We know that we have a FakeTransport* 494 // We know that we have a FakeTransport*
489 495
490 static_cast<FakeTransport*>(it->second->impl())->set_identity 496 static_cast<FakeTransport*>(it->second->impl())->set_certificate
491 (identity); 497 (certificate);
492 } 498 }
493 } 499 }
494 500
495 protected: 501 protected:
496 virtual Transport* CreateTransport(const std::string& content_name) { 502 virtual Transport* CreateTransport(const std::string& content_name) {
497 return new FakeTransport(signaling_thread(), worker_thread(), content_name); 503 return new FakeTransport(signaling_thread(), worker_thread(), content_name);
498 } 504 }
499 505
500 void CompleteNegotiation() { 506 void CompleteNegotiation() {
501 for (TransportMap::const_iterator it = transport_proxies().begin(); 507 for (TransportMap::const_iterator it = transport_proxies().begin();
502 it != transport_proxies().end(); ++it) { 508 it != transport_proxies().end(); ++it) {
503 it->second->CompleteNegotiation(); 509 it->second->CompleteNegotiation();
504 it->second->ConnectChannels(); 510 it->second->ConnectChannels();
505 } 511 }
506 } 512 }
507 513
508 private: 514 private:
509 bool fail_create_channel_; 515 bool fail_create_channel_;
510 }; 516 };
511 517
512 } // namespace cricket 518 } // namespace cricket
513 519
514 #endif // WEBRTC_P2P_BASE_FAKESESSION_H_ 520 #endif // WEBRTC_P2P_BASE_FAKESESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698