wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2013 Google Inc. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifndef TALK_APP_WEBRTC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |
| 29 | #define TALK_APP_WEBRTC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |
| 30 | |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 31 | #include "talk/app/webrtc/dtlsidentitystore.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 32 | #include "talk/app/webrtc/peerconnectioninterface.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 33 | #include "talk/session/media/mediasession.h" |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 34 | #include "webrtc/p2p/base/transportdescriptionfactory.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 35 | #include "webrtc/base/messagehandler.h" |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 36 | #include "webrtc/base/rtccertificate.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 37 | |
| 38 | namespace cricket { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 39 | class ChannelManager; |
| 40 | class TransportDescriptionFactory; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 41 | } // namespace cricket |
| 42 | |
| 43 | namespace webrtc { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 44 | class CreateSessionDescriptionObserver; |
| 45 | class MediaConstraintsInterface; |
| 46 | class MediaStreamSignaling; |
| 47 | class SessionDescriptionInterface; |
| 48 | class WebRtcSession; |
| 49 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 50 | // DTLS identity request callback class. |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 51 | class WebRtcIdentityRequestObserver : public DtlsIdentityRequestObserver, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 52 | public sigslot::has_slots<> { |
| 53 | public: |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 54 | // DtlsIdentityRequestObserver overrides. |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 +0000 | [diff] [blame] | 55 | void OnFailure(int error) override; |
| 56 | void OnSuccess(const std::string& der_cert, |
| 57 | const std::string& der_private_key) override; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 58 | void OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity> identity) override; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 59 | |
| 60 | sigslot::signal1<int> SignalRequestFailed; |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame^] | 61 | sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&> |
| 62 | SignalCertificateReady; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | struct CreateSessionDescriptionRequest { |
| 66 | enum Type { |
| 67 | kOffer, |
| 68 | kAnswer, |
| 69 | }; |
| 70 | |
| 71 | CreateSessionDescriptionRequest( |
| 72 | Type type, |
| 73 | CreateSessionDescriptionObserver* observer, |
| 74 | const cricket::MediaSessionOptions& options) |
| 75 | : type(type), |
| 76 | observer(observer), |
| 77 | options(options) {} |
| 78 | |
| 79 | Type type; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 80 | rtc::scoped_refptr<CreateSessionDescriptionObserver> observer; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 81 | cricket::MediaSessionOptions options; |
| 82 | }; |
| 83 | |
| 84 | // This class is used to create offer/answer session description with regards to |
| 85 | // the async DTLS identity generation for WebRtcSession. |
| 86 | // It queues the create offer/answer request until the DTLS identity |
| 87 | // request has completed, i.e. when OnIdentityRequestFailed or OnIdentityReady |
| 88 | // is called. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 89 | class WebRtcSessionDescriptionFactory : public rtc::MessageHandler, |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 90 | public sigslot::has_slots<> { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 91 | public: |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 92 | // Construct with DTLS disabled. |
| 93 | WebRtcSessionDescriptionFactory( |
| 94 | rtc::Thread* signaling_thread, |
| 95 | cricket::ChannelManager* channel_manager, |
| 96 | MediaStreamSignaling* mediastream_signaling, |
| 97 | WebRtcSession* session, |
| 98 | const std::string& session_id, |
| 99 | cricket::DataChannelType dct); |
| 100 | |
| 101 | // Construct with DTLS enabled using the specified |dtls_identity_store| to |
| 102 | // generate a certificate. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 103 | WebRtcSessionDescriptionFactory( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 104 | rtc::Thread* signaling_thread, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 105 | cricket::ChannelManager* channel_manager, |
| 106 | MediaStreamSignaling* mediastream_signaling, |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 107 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 108 | WebRtcSession* session, |
| 109 | const std::string& session_id, |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 110 | cricket::DataChannelType dct); |
| 111 | |
| 112 | // Construct with DTLS enabled using the specified (already generated) |
| 113 | // |certificate|. |
| 114 | WebRtcSessionDescriptionFactory( |
| 115 | rtc::Thread* signaling_thread, |
| 116 | cricket::ChannelManager* channel_manager, |
| 117 | MediaStreamSignaling* mediastream_signaling, |
| 118 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate, |
| 119 | WebRtcSession* session, |
| 120 | const std::string& session_id, |
| 121 | cricket::DataChannelType dct); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 122 | virtual ~WebRtcSessionDescriptionFactory(); |
| 123 | |
| 124 | static void CopyCandidatesFromSessionDescription( |
| 125 | const SessionDescriptionInterface* source_desc, |
| 126 | SessionDescriptionInterface* dest_desc); |
| 127 | |
| 128 | void CreateOffer( |
| 129 | CreateSessionDescriptionObserver* observer, |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 130 | const PeerConnectionInterface::RTCOfferAnswerOptions& options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 131 | void CreateAnswer( |
| 132 | CreateSessionDescriptionObserver* observer, |
| 133 | const MediaConstraintsInterface* constraints); |
| 134 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 135 | void SetSdesPolicy(cricket::SecurePolicy secure_policy); |
| 136 | cricket::SecurePolicy SdesPolicy() const; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 137 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame^] | 138 | sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&> |
| 139 | SignalCertificateReady; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 140 | |
| 141 | // For testing. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 142 | bool waiting_for_certificate_for_testing() const { |
| 143 | return certificate_request_state_ == CERTIFICATE_WAITING; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 144 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 145 | |
| 146 | private: |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 147 | enum CertificateRequestState { |
| 148 | CERTIFICATE_NOT_NEEDED, |
| 149 | CERTIFICATE_WAITING, |
| 150 | CERTIFICATE_SUCCEEDED, |
| 151 | CERTIFICATE_FAILED, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 154 | WebRtcSessionDescriptionFactory( |
| 155 | rtc::Thread* signaling_thread, |
| 156 | cricket::ChannelManager* channel_manager, |
| 157 | MediaStreamSignaling* mediastream_signaling, |
| 158 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 159 | const rtc::scoped_refptr<WebRtcIdentityRequestObserver>& |
| 160 | identity_request_observer, |
| 161 | WebRtcSession* session, |
| 162 | const std::string& session_id, |
| 163 | cricket::DataChannelType dct, |
| 164 | bool dtls_enabled); |
| 165 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 166 | // MessageHandler implementation. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 167 | virtual void OnMessage(rtc::Message* msg); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 168 | |
| 169 | void InternalCreateOffer(CreateSessionDescriptionRequest request); |
| 170 | void InternalCreateAnswer(CreateSessionDescriptionRequest request); |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 171 | // Posts failure notifications for all pending session description requests. |
| 172 | void FailPendingRequests(const std::string& reason); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 173 | void PostCreateSessionDescriptionFailed( |
| 174 | CreateSessionDescriptionObserver* observer, |
| 175 | const std::string& error); |
| 176 | void PostCreateSessionDescriptionSucceeded( |
| 177 | CreateSessionDescriptionObserver* observer, |
| 178 | SessionDescriptionInterface* description); |
| 179 | |
| 180 | void OnIdentityRequestFailed(int error); |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame^] | 181 | void SetCertificate( |
| 182 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 183 | |
| 184 | std::queue<CreateSessionDescriptionRequest> |
| 185 | create_session_description_requests_; |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 186 | rtc::Thread* const signaling_thread_; |
| 187 | MediaStreamSignaling* const mediastream_signaling_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 188 | cricket::TransportDescriptionFactory transport_desc_factory_; |
| 189 | cricket::MediaSessionDescriptionFactory session_desc_factory_; |
| 190 | uint64 session_version_; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 191 | const rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store_; |
| 192 | const rtc::scoped_refptr<WebRtcIdentityRequestObserver> |
| 193 | identity_request_observer_; |
| 194 | // TODO(jiayl): remove the dependency on session once bug 2264 is fixed. |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 195 | WebRtcSession* const session_; |
| 196 | const std::string session_id_; |
| 197 | const cricket::DataChannelType data_channel_type_; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 198 | CertificateRequestState certificate_request_state_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 199 | |
| 200 | DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory); |
| 201 | }; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 202 | } // namespace webrtc |
| 203 | |
| 204 | #endif // TALK_APP_WEBRTC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |