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 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 28 | #ifndef WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |
| 29 | #define WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 30 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 31 | #include "talk/session/media/mediasession.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 32 | #include "webrtc/api/dtlsidentitystore.h" |
| 33 | #include "webrtc/api/peerconnectioninterface.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 34 | #include "webrtc/base/messagehandler.h" |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 35 | #include "webrtc/base/rtccertificate.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 36 | #include "webrtc/p2p/base/transportdescriptionfactory.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; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 46 | class SessionDescriptionInterface; |
| 47 | class WebRtcSession; |
| 48 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 49 | // DTLS identity request callback class. |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 50 | class WebRtcIdentityRequestObserver : public DtlsIdentityRequestObserver, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 51 | public sigslot::has_slots<> { |
| 52 | public: |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 53 | // DtlsIdentityRequestObserver overrides. |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 +0000 | [diff] [blame] | 54 | void OnFailure(int error) override; |
| 55 | void OnSuccess(const std::string& der_cert, |
| 56 | const std::string& der_private_key) override; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 57 | void OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity> identity) override; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 58 | |
| 59 | sigslot::signal1<int> SignalRequestFailed; |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 60 | sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&> |
| 61 | SignalCertificateReady; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | struct CreateSessionDescriptionRequest { |
| 65 | enum Type { |
| 66 | kOffer, |
| 67 | kAnswer, |
| 68 | }; |
| 69 | |
| 70 | CreateSessionDescriptionRequest( |
| 71 | Type type, |
| 72 | CreateSessionDescriptionObserver* observer, |
| 73 | const cricket::MediaSessionOptions& options) |
| 74 | : type(type), |
| 75 | observer(observer), |
| 76 | options(options) {} |
| 77 | |
| 78 | Type type; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 79 | rtc::scoped_refptr<CreateSessionDescriptionObserver> observer; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 80 | cricket::MediaSessionOptions options; |
| 81 | }; |
| 82 | |
| 83 | // This class is used to create offer/answer session description with regards to |
| 84 | // the async DTLS identity generation for WebRtcSession. |
| 85 | // It queues the create offer/answer request until the DTLS identity |
| 86 | // request has completed, i.e. when OnIdentityRequestFailed or OnIdentityReady |
| 87 | // is called. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 88 | class WebRtcSessionDescriptionFactory : public rtc::MessageHandler, |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 89 | public sigslot::has_slots<> { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 90 | public: |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 91 | // Construct with DTLS disabled. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 92 | WebRtcSessionDescriptionFactory(rtc::Thread* signaling_thread, |
| 93 | cricket::ChannelManager* channel_manager, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 94 | WebRtcSession* session, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 95 | const std::string& session_id); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 96 | |
| 97 | // Construct with DTLS enabled using the specified |dtls_identity_store| to |
| 98 | // generate a certificate. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 99 | WebRtcSessionDescriptionFactory( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 100 | rtc::Thread* signaling_thread, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 101 | cricket::ChannelManager* channel_manager, |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 102 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 103 | WebRtcSession* session, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 104 | const std::string& session_id); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 105 | |
| 106 | // Construct with DTLS enabled using the specified (already generated) |
| 107 | // |certificate|. |
| 108 | WebRtcSessionDescriptionFactory( |
| 109 | rtc::Thread* signaling_thread, |
| 110 | cricket::ChannelManager* channel_manager, |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 111 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate, |
| 112 | WebRtcSession* session, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 113 | const std::string& session_id); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 114 | virtual ~WebRtcSessionDescriptionFactory(); |
| 115 | |
| 116 | static void CopyCandidatesFromSessionDescription( |
| 117 | const SessionDescriptionInterface* source_desc, |
| 118 | SessionDescriptionInterface* dest_desc); |
| 119 | |
| 120 | void CreateOffer( |
| 121 | CreateSessionDescriptionObserver* observer, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 122 | const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| 123 | const cricket::MediaSessionOptions& session_options); |
| 124 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 125 | const MediaConstraintsInterface* constraints, |
| 126 | const cricket::MediaSessionOptions& session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 127 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 128 | void SetSdesPolicy(cricket::SecurePolicy secure_policy); |
| 129 | cricket::SecurePolicy SdesPolicy() const; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 130 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 131 | sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&> |
| 132 | SignalCertificateReady; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 133 | |
| 134 | // For testing. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 135 | bool waiting_for_certificate_for_testing() const { |
| 136 | return certificate_request_state_ == CERTIFICATE_WAITING; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 137 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 138 | |
| 139 | private: |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 140 | enum CertificateRequestState { |
| 141 | CERTIFICATE_NOT_NEEDED, |
| 142 | CERTIFICATE_WAITING, |
| 143 | CERTIFICATE_SUCCEEDED, |
| 144 | CERTIFICATE_FAILED, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 145 | }; |
| 146 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 147 | WebRtcSessionDescriptionFactory( |
| 148 | rtc::Thread* signaling_thread, |
| 149 | cricket::ChannelManager* channel_manager, |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 150 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 151 | const rtc::scoped_refptr<WebRtcIdentityRequestObserver>& |
| 152 | identity_request_observer, |
| 153 | WebRtcSession* session, |
| 154 | const std::string& session_id, |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 155 | bool dtls_enabled); |
| 156 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 157 | // MessageHandler implementation. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 158 | virtual void OnMessage(rtc::Message* msg); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 159 | |
| 160 | void InternalCreateOffer(CreateSessionDescriptionRequest request); |
| 161 | void InternalCreateAnswer(CreateSessionDescriptionRequest request); |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 162 | // Posts failure notifications for all pending session description requests. |
| 163 | void FailPendingRequests(const std::string& reason); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 164 | void PostCreateSessionDescriptionFailed( |
| 165 | CreateSessionDescriptionObserver* observer, |
| 166 | const std::string& error); |
| 167 | void PostCreateSessionDescriptionSucceeded( |
| 168 | CreateSessionDescriptionObserver* observer, |
| 169 | SessionDescriptionInterface* description); |
| 170 | |
| 171 | void OnIdentityRequestFailed(int error); |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 172 | void SetCertificate( |
| 173 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 174 | |
| 175 | std::queue<CreateSessionDescriptionRequest> |
| 176 | create_session_description_requests_; |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 177 | rtc::Thread* const signaling_thread_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 178 | cricket::TransportDescriptionFactory transport_desc_factory_; |
| 179 | cricket::MediaSessionDescriptionFactory session_desc_factory_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 180 | uint64_t session_version_; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 181 | const rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store_; |
| 182 | const rtc::scoped_refptr<WebRtcIdentityRequestObserver> |
| 183 | identity_request_observer_; |
| 184 | // TODO(jiayl): remove the dependency on session once bug 2264 is fixed. |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 185 | WebRtcSession* const session_; |
| 186 | const std::string session_id_; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 187 | CertificateRequestState certificate_request_state_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 188 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 189 | RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 190 | }; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 191 | } // namespace webrtc |
| 192 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 193 | #endif // WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |