OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 15 matching lines...) Expand all Loading... |
26 */ | 26 */ |
27 | 27 |
28 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" | 28 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" |
29 | 29 |
30 #include "talk/app/webrtc/dtlsidentitystore.h" | 30 #include "talk/app/webrtc/dtlsidentitystore.h" |
31 #include "talk/app/webrtc/jsep.h" | 31 #include "talk/app/webrtc/jsep.h" |
32 #include "talk/app/webrtc/jsepsessiondescription.h" | 32 #include "talk/app/webrtc/jsepsessiondescription.h" |
33 #include "talk/app/webrtc/mediaconstraintsinterface.h" | 33 #include "talk/app/webrtc/mediaconstraintsinterface.h" |
34 #include "talk/app/webrtc/mediastreamsignaling.h" | 34 #include "talk/app/webrtc/mediastreamsignaling.h" |
35 #include "talk/app/webrtc/webrtcsession.h" | 35 #include "talk/app/webrtc/webrtcsession.h" |
| 36 #include "webrtc/base/sslidentity.h" |
36 | 37 |
37 using cricket::MediaSessionOptions; | 38 using cricket::MediaSessionOptions; |
38 | 39 |
39 namespace webrtc { | 40 namespace webrtc { |
40 namespace { | 41 namespace { |
41 static const char kFailedDueToIdentityFailed[] = | 42 static const char kFailedDueToIdentityFailed[] = |
42 " failed because DTLS identity request failed"; | 43 " failed because DTLS identity request failed"; |
43 | 44 |
44 static const uint64 kInitSessionVersion = 2; | 45 static const uint64 kInitSessionVersion = 2; |
45 | 46 |
(...skipping 12 matching lines...) Expand all Loading... |
58 MediaSessionOptions::Streams sorted_streams = streams; | 59 MediaSessionOptions::Streams sorted_streams = streams; |
59 std::sort(sorted_streams.begin(), sorted_streams.end(), CompareStream); | 60 std::sort(sorted_streams.begin(), sorted_streams.end(), CompareStream); |
60 MediaSessionOptions::Streams::iterator it = | 61 MediaSessionOptions::Streams::iterator it = |
61 std::adjacent_find(sorted_streams.begin(), sorted_streams.end(), | 62 std::adjacent_find(sorted_streams.begin(), sorted_streams.end(), |
62 SameId); | 63 SameId); |
63 return it == sorted_streams.end(); | 64 return it == sorted_streams.end(); |
64 } | 65 } |
65 | 66 |
66 enum { | 67 enum { |
67 MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, | 68 MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, |
68 MSG_CREATE_SESSIONDESCRIPTION_FAILED, | 69 MSG_CREATE_SESSIONDESCRIPTION_FAILED |
69 MSG_GENERATE_IDENTITY, | |
70 }; | 70 }; |
71 | 71 |
72 struct CreateSessionDescriptionMsg : public rtc::MessageData { | 72 struct CreateSessionDescriptionMsg : public rtc::MessageData { |
73 explicit CreateSessionDescriptionMsg( | 73 explicit CreateSessionDescriptionMsg( |
74 webrtc::CreateSessionDescriptionObserver* observer) | 74 webrtc::CreateSessionDescriptionObserver* observer) |
75 : observer(observer) { | 75 : observer(observer) { |
76 } | 76 } |
77 | 77 |
78 rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserver> observer; | 78 rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserver> observer; |
79 std::string error; | 79 std::string error; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 if (!dest_candidates->HasCandidate(new_candidate)) | 121 if (!dest_candidates->HasCandidate(new_candidate)) |
122 dest_desc->AddCandidate(source_candidates->at(n)); | 122 dest_desc->AddCandidate(source_candidates->at(n)); |
123 } | 123 } |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory( | 127 WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory( |
128 rtc::Thread* signaling_thread, | 128 rtc::Thread* signaling_thread, |
129 cricket::ChannelManager* channel_manager, | 129 cricket::ChannelManager* channel_manager, |
130 MediaStreamSignaling* mediastream_signaling, | 130 MediaStreamSignaling* mediastream_signaling, |
131 DTLSIdentityServiceInterface* dtls_identity_service, | 131 DtlsIdentityStoreInterface* dtls_identity_store, |
132 WebRtcSession* session, | 132 WebRtcSession* session, |
133 const std::string& session_id, | 133 const std::string& session_id, |
134 cricket::DataChannelType dct, | 134 cricket::DataChannelType dct, |
135 bool dtls_enabled) | 135 bool dtls_enabled) |
136 : signaling_thread_(signaling_thread), | 136 : signaling_thread_(signaling_thread), |
137 mediastream_signaling_(mediastream_signaling), | 137 mediastream_signaling_(mediastream_signaling), |
138 session_desc_factory_(channel_manager, &transport_desc_factory_), | 138 session_desc_factory_(channel_manager, &transport_desc_factory_), |
139 // RFC 4566 suggested a Network Time Protocol (NTP) format timestamp | 139 // RFC 4566 suggested a Network Time Protocol (NTP) format timestamp |
140 // as the session id and session version. To simplify, it should be fine | 140 // as the session id and session version. To simplify, it should be fine |
141 // to just use a random number as session id and start version from | 141 // to just use a random number as session id and start version from |
142 // |kInitSessionVersion|. | 142 // |kInitSessionVersion|. |
143 session_version_(kInitSessionVersion), | 143 session_version_(kInitSessionVersion), |
144 identity_service_(dtls_identity_service), | 144 dtls_identity_store_(dtls_identity_store), |
145 session_(session), | 145 session_(session), |
146 session_id_(session_id), | 146 session_id_(session_id), |
147 data_channel_type_(dct), | 147 data_channel_type_(dct), |
148 identity_request_state_(IDENTITY_NOT_NEEDED) { | 148 identity_request_state_(IDENTITY_NOT_NEEDED) { |
149 transport_desc_factory_.set_protocol(cricket::ICEPROTO_RFC5245); | 149 transport_desc_factory_.set_protocol(cricket::ICEPROTO_RFC5245); |
150 session_desc_factory_.set_add_legacy_streams(false); | 150 session_desc_factory_.set_add_legacy_streams(false); |
151 // SRTP-SDES is disabled if DTLS is on. | 151 // SRTP-SDES is disabled if DTLS is on. |
152 SetSdesPolicy(dtls_enabled ? cricket::SEC_DISABLED : cricket::SEC_REQUIRED); | 152 SetSdesPolicy(dtls_enabled ? cricket::SEC_DISABLED : cricket::SEC_REQUIRED); |
153 | 153 |
154 if (!dtls_enabled) { | 154 // If |dtls_enabled| we must have a |dtls_identity_store_|. |
155 return; | 155 DCHECK(!dtls_enabled || dtls_identity_store_); |
156 } | |
157 | 156 |
158 if (identity_service_.get()) { | 157 if (dtls_enabled && dtls_identity_store_) { |
159 identity_request_observer_ = | 158 identity_request_observer_ = |
160 new rtc::RefCountedObject<WebRtcIdentityRequestObserver>(); | 159 new rtc::RefCountedObject<WebRtcIdentityRequestObserver>(); |
161 | 160 |
162 identity_request_observer_->SignalRequestFailed.connect( | 161 identity_request_observer_->SignalRequestFailed.connect( |
163 this, &WebRtcSessionDescriptionFactory::OnIdentityRequestFailed); | 162 this, &WebRtcSessionDescriptionFactory::OnIdentityRequestFailed); |
164 identity_request_observer_->SignalIdentityReady.connect( | 163 identity_request_observer_->SignalIdentityReady.connect( |
165 this, &WebRtcSessionDescriptionFactory::SetIdentity); | 164 this, &WebRtcSessionDescriptionFactory::SetIdentity); |
166 | 165 |
167 if (identity_service_->RequestIdentity( | 166 LOG(LS_VERBOSE) << "DTLS-SRTP enabled; sending DTLS identity request."; |
168 DtlsIdentityStore::kIdentityName, | |
169 DtlsIdentityStore::kIdentityName, | |
170 identity_request_observer_)) { | |
171 LOG(LS_VERBOSE) << "DTLS-SRTP enabled; sent DTLS identity request."; | |
172 identity_request_state_ = IDENTITY_WAITING; | |
173 } else { | |
174 LOG(LS_ERROR) << "Failed to send DTLS identity request."; | |
175 identity_request_state_ = IDENTITY_FAILED; | |
176 } | |
177 } else { | |
178 identity_request_state_ = IDENTITY_WAITING; | 167 identity_request_state_ = IDENTITY_WAITING; |
179 // Do not generate the identity in the constructor since the caller has | 168 dtls_identity_store_->RequestIdentity(rtc::KT_DEFAULT, |
180 // not got a chance to connect to SignalIdentityReady. | 169 identity_request_observer_.get()); |
181 signaling_thread_->Post(this, MSG_GENERATE_IDENTITY, NULL); | |
182 } | 170 } |
183 } | 171 } |
184 | 172 |
185 WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() { | 173 WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() { |
186 transport_desc_factory_.set_identity(NULL); | 174 transport_desc_factory_.set_identity(NULL); |
187 } | 175 } |
188 | 176 |
189 void WebRtcSessionDescriptionFactory::CreateOffer( | 177 void WebRtcSessionDescriptionFactory::CreateOffer( |
190 CreateSessionDescriptionObserver* observer, | 178 CreateSessionDescriptionObserver* observer, |
191 const PeerConnectionInterface::RTCOfferAnswerOptions& options) { | 179 const PeerConnectionInterface::RTCOfferAnswerOptions& options) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 delete param; | 291 delete param; |
304 break; | 292 break; |
305 } | 293 } |
306 case MSG_CREATE_SESSIONDESCRIPTION_FAILED: { | 294 case MSG_CREATE_SESSIONDESCRIPTION_FAILED: { |
307 CreateSessionDescriptionMsg* param = | 295 CreateSessionDescriptionMsg* param = |
308 static_cast<CreateSessionDescriptionMsg*>(msg->pdata); | 296 static_cast<CreateSessionDescriptionMsg*>(msg->pdata); |
309 param->observer->OnFailure(param->error); | 297 param->observer->OnFailure(param->error); |
310 delete param; | 298 delete param; |
311 break; | 299 break; |
312 } | 300 } |
313 case MSG_GENERATE_IDENTITY: { | |
314 LOG(LS_INFO) << "Generating identity."; | |
315 SetIdentity(rtc::SSLIdentity::Generate(DtlsIdentityStore::kIdentityName)); | |
316 break; | |
317 } | |
318 default: | 301 default: |
319 ASSERT(false); | 302 ASSERT(false); |
320 break; | 303 break; |
321 } | 304 } |
322 } | 305 } |
323 | 306 |
324 void WebRtcSessionDescriptionFactory::InternalCreateOffer( | 307 void WebRtcSessionDescriptionFactory::InternalCreateOffer( |
325 CreateSessionDescriptionRequest request) { | 308 CreateSessionDescriptionRequest request) { |
326 cricket::SessionDescription* desc( | 309 cricket::SessionDescription* desc( |
327 session_desc_factory_.CreateOffer( | 310 session_desc_factory_.CreateOffer( |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 if (create_session_description_requests_.front().type == | 431 if (create_session_description_requests_.front().type == |
449 CreateSessionDescriptionRequest::kOffer) { | 432 CreateSessionDescriptionRequest::kOffer) { |
450 InternalCreateOffer(create_session_description_requests_.front()); | 433 InternalCreateOffer(create_session_description_requests_.front()); |
451 } else { | 434 } else { |
452 InternalCreateAnswer(create_session_description_requests_.front()); | 435 InternalCreateAnswer(create_session_description_requests_.front()); |
453 } | 436 } |
454 create_session_description_requests_.pop(); | 437 create_session_description_requests_.pop(); |
455 } | 438 } |
456 } | 439 } |
457 } // namespace webrtc | 440 } // namespace webrtc |
OLD | NEW |