From 5b4ce3391d60229342963ef524b7c1e359e5bfc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bostr=C3=B6m?= Date: Wed, 5 Aug 2015 16:55:22 +0200 Subject: [PATCH] DtlsIdentityStoreInterface added. New PeerConnectionFactoryInterface::CreatePeerConnection taking both service and store added (old CreatePC signature still exists). This is CL is part of an effort to land https://codereview.webrtc.org/1176383004 without breaking Chromium. See bug for more information. BUG=webrtc:4899 R=tommi@webrtc.org Review URL: https://codereview.webrtc.org/1268363002 . Cr-Commit-Position: refs/heads/master@{#9680} --- talk/app/webrtc/dtlsidentitystore.h | 51 ++++++++++++++++++++++- talk/app/webrtc/peerconnectioninterface.h | 31 +++++++------- webrtc/base/sslidentity.h | 2 + 3 files changed, 66 insertions(+), 18 deletions(-) diff --git a/talk/app/webrtc/dtlsidentitystore.h b/talk/app/webrtc/dtlsidentitystore.h index b2a797462f..b655a7d1b2 100644 --- a/talk/app/webrtc/dtlsidentitystore.h +++ b/talk/app/webrtc/dtlsidentitystore.h @@ -31,17 +31,64 @@ #include #include -#include "talk/app/webrtc/peerconnectioninterface.h" #include "webrtc/base/messagehandler.h" #include "webrtc/base/messagequeue.h" +#include "webrtc/base/refcount.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/base/scoped_ref_ptr.h" +#include "webrtc/base/sslidentity.h" +#include "webrtc/base/thread.h" namespace webrtc { -class DTLSIdentityRequestObserver; class SSLIdentity; class Thread; +// Used to receive callbacks of DTLS identity requests. +class DTLSIdentityRequestObserver : public rtc::RefCountInterface { + public: + virtual void OnFailure(int error) = 0; + // TODO(jiayl): Unify the OnSuccess method once Chrome code is updated. + virtual void OnSuccess(const std::string& der_cert, + const std::string& der_private_key) = 0; + // |identity| is a scoped_ptr because rtc::SSLIdentity is not copyable and the + // client has to get the ownership of the object to make use of it. + virtual void OnSuccessWithIdentityObj( + rtc::scoped_ptr identity) = 0; + + protected: + virtual ~DTLSIdentityRequestObserver() {} +}; + +// TODO(hbos): To replace DTLSIdentityRequestObserver. +// Used to receive callbacks of DTLS identity requests. +class DtlsIdentityRequestObserver : public rtc::RefCountInterface { + public: + virtual void OnFailure(int error) = 0; + // TODO(hbos): Unify the OnSuccess method once Chrome code is updated. + virtual void OnSuccess(const std::string& der_cert, + const std::string& der_private_key) = 0; + // |identity| is a scoped_ptr because rtc::SSLIdentity is not copyable and the + // client has to get the ownership of the object to make use of it. + virtual void OnSuccess(rtc::scoped_ptr identity) = 0; + + protected: + virtual ~DtlsIdentityRequestObserver() {} +}; + +// TODO(hbos): To be implemented. +// This interface defines an in-memory DTLS identity store, which generates DTLS +// identities. +// APIs calls must be made on the signaling thread and the callbacks are also +// called on the signaling thread. +class DtlsIdentityStoreInterface { + public: + virtual ~DtlsIdentityStoreInterface() { } + + virtual void RequestIdentity( + rtc::KeyType key_type, + const rtc::scoped_refptr& observer) = 0; +}; + // This class implements an in-memory DTLS identity store, which generates the // DTLS identity on the worker thread. // APIs calls must be made on the signaling thread and the callbacks are also diff --git a/talk/app/webrtc/peerconnectioninterface.h b/talk/app/webrtc/peerconnectioninterface.h index ce32b50291..946b1253c9 100644 --- a/talk/app/webrtc/peerconnectioninterface.h +++ b/talk/app/webrtc/peerconnectioninterface.h @@ -72,6 +72,7 @@ #include #include "talk/app/webrtc/datachannelinterface.h" +#include "talk/app/webrtc/dtlsidentitystore.h" #include "talk/app/webrtc/dtmfsenderinterface.h" #include "talk/app/webrtc/jsep.h" #include "talk/app/webrtc/mediastreaminterface.h" @@ -466,22 +467,6 @@ class PortAllocatorFactoryInterface : public rtc::RefCountInterface { ~PortAllocatorFactoryInterface() {} }; -// Used to receive callbacks of DTLS identity requests. -class DTLSIdentityRequestObserver : public rtc::RefCountInterface { - public: - virtual void OnFailure(int error) = 0; - // TODO(jiayl): Unify the OnSuccess method once Chrome code is updated. - virtual void OnSuccess(const std::string& der_cert, - const std::string& der_private_key) = 0; - // |identity| is a scoped_ptr because rtc::SSLIdentity is not copyable and the - // client has to get the ownership of the object to make use of it. - virtual void OnSuccessWithIdentityObj( - rtc::scoped_ptr identity) = 0; - - protected: - virtual ~DTLSIdentityRequestObserver() {} -}; - class DTLSIdentityServiceInterface { public: // Asynchronously request a DTLS identity, including a self-signed certificate @@ -548,6 +533,20 @@ class PeerConnectionFactoryInterface : public rtc::RefCountInterface { virtual void SetOptions(const Options& options) = 0; + // TODO(hbos): Temporary CreatePeerConnection function while we transition + // from DTLSIdentityServiceInterface to DtlsIdentityStoreInterface. + rtc::scoped_refptr + CreatePeerConnection( + const PeerConnectionInterface::RTCConfiguration& configuration, + const MediaConstraintsInterface* constraints, + PortAllocatorFactoryInterface* allocator_factory, + DTLSIdentityServiceInterface* dtls_identity_service, + rtc::scoped_ptr dtls_identity_store, + PeerConnectionObserver* observer) { + return CreatePeerConnection(configuration, constraints, allocator_factory, + dtls_identity_service, observer); + } + // This method takes the ownership of |dtls_identity_service|. virtual rtc::scoped_refptr CreatePeerConnection( diff --git a/webrtc/base/sslidentity.h b/webrtc/base/sslidentity.h index 320fe53d0f..ca1aa11f83 100644 --- a/webrtc/base/sslidentity.h +++ b/webrtc/base/sslidentity.h @@ -22,6 +22,8 @@ namespace rtc { +enum KeyType { KT_RSA, KT_ECDSA, KT_LAST, KT_DEFAULT = KT_RSA }; + // Forward declaration due to circular dependency with SSLCertificate. class SSLCertChain;