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

Side by Side Diff: talk/app/webrtc/webrtcsessiondescriptionfactory.cc

Issue 1151943005: Ability to specify KeyType (RSA, ECDSA) for SSLIdentity generation in libjingle (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressing ASAN, LSAN issues in unittests Created 5 years, 6 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 * 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 MediaSessionOptions::Streams sorted_streams = streams; 58 MediaSessionOptions::Streams sorted_streams = streams;
59 std::sort(sorted_streams.begin(), sorted_streams.end(), CompareStream); 59 std::sort(sorted_streams.begin(), sorted_streams.end(), CompareStream);
60 MediaSessionOptions::Streams::iterator it = 60 MediaSessionOptions::Streams::iterator it =
61 std::adjacent_find(sorted_streams.begin(), sorted_streams.end(), 61 std::adjacent_find(sorted_streams.begin(), sorted_streams.end(),
62 SameId); 62 SameId);
63 return it == sorted_streams.end(); 63 return it == sorted_streams.end();
64 } 64 }
65 65
66 enum { 66 enum {
67 MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, 67 MSG_CREATE_SESSIONDESCRIPTION_SUCCESS,
68 MSG_CREATE_SESSIONDESCRIPTION_FAILED, 68 MSG_CREATE_SESSIONDESCRIPTION_FAILED
69 MSG_GENERATE_IDENTITY,
70 }; 69 };
71 70
72 struct CreateSessionDescriptionMsg : public rtc::MessageData { 71 struct CreateSessionDescriptionMsg : public rtc::MessageData {
73 explicit CreateSessionDescriptionMsg( 72 explicit CreateSessionDescriptionMsg(
74 webrtc::CreateSessionDescriptionObserver* observer) 73 webrtc::CreateSessionDescriptionObserver* observer)
75 : observer(observer) { 74 : observer(observer) {
76 } 75 }
77 76
78 rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserver> observer; 77 rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserver> observer;
79 std::string error; 78 std::string error;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (!dest_candidates->HasCandidate(new_candidate)) 120 if (!dest_candidates->HasCandidate(new_candidate))
122 dest_desc->AddCandidate(source_candidates->at(n)); 121 dest_desc->AddCandidate(source_candidates->at(n));
123 } 122 }
124 } 123 }
125 } 124 }
126 125
127 WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory( 126 WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory(
128 rtc::Thread* signaling_thread, 127 rtc::Thread* signaling_thread,
129 cricket::ChannelManager* channel_manager, 128 cricket::ChannelManager* channel_manager,
130 MediaStreamSignaling* mediastream_signaling, 129 MediaStreamSignaling* mediastream_signaling,
131 DTLSIdentityServiceInterface* dtls_identity_service, 130 DtlsIdentityStoreInterface* dtls_identity_store,
132 WebRtcSession* session, 131 WebRtcSession* session,
133 const std::string& session_id, 132 const std::string& session_id,
134 cricket::DataChannelType dct, 133 cricket::DataChannelType dct,
135 bool dtls_enabled) 134 bool dtls_enabled,
135 rtc::KeyType key_type)
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 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 key_type_(key_type) {
149 transport_desc_factory_.set_protocol(cricket::ICEPROTO_RFC5245); 150 transport_desc_factory_.set_protocol(cricket::ICEPROTO_RFC5245);
150 session_desc_factory_.set_add_legacy_streams(false); 151 session_desc_factory_.set_add_legacy_streams(false);
151 // SRTP-SDES is disabled if DTLS is on. 152 // SRTP-SDES is disabled if DTLS is on.
152 SetSdesPolicy(dtls_enabled ? cricket::SEC_DISABLED : cricket::SEC_REQUIRED); 153 SetSdesPolicy(dtls_enabled ? cricket::SEC_DISABLED : cricket::SEC_REQUIRED);
153 154
154 if (!dtls_enabled) { 155 // If |dtls_enabled| we must have an |identity_store_|.
155 return; 156 DCHECK(!dtls_enabled || identity_store_);
156 }
157 157
158 if (identity_service_.get()) { 158 if (dtls_enabled && identity_store_) {
159 identity_request_observer_ = 159 identity_request_observer_ =
160 new rtc::RefCountedObject<WebRtcIdentityRequestObserver>(); 160 new rtc::RefCountedObject<WebRtcIdentityRequestObserver>();
161 161
162 identity_request_observer_->SignalRequestFailed.connect( 162 identity_request_observer_->SignalRequestFailed.connect(
163 this, &WebRtcSessionDescriptionFactory::OnIdentityRequestFailed); 163 this, &WebRtcSessionDescriptionFactory::OnIdentityRequestFailed);
164 identity_request_observer_->SignalIdentityReady.connect( 164 identity_request_observer_->SignalIdentityReady.connect(
165 this, &WebRtcSessionDescriptionFactory::SetIdentity); 165 this, &WebRtcSessionDescriptionFactory::SetIdentity);
166 166
167 if (identity_service_->RequestIdentity( 167 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; 168 identity_request_state_ = IDENTITY_WAITING;
179 // Do not generate the identity in the constructor since the caller has 169 identity_store_->RequestIdentity(key_type_,
180 // not got a chance to connect to SignalIdentityReady. 170 identity_request_observer_.get());
181 signaling_thread_->Post(this, MSG_GENERATE_IDENTITY, NULL);
182 } 171 }
183 } 172 }
184 173
185 WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() { 174 WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() {
186 transport_desc_factory_.set_identity(NULL); 175 transport_desc_factory_.set_identity(NULL);
187 } 176 }
188 177
189 void WebRtcSessionDescriptionFactory::CreateOffer( 178 void WebRtcSessionDescriptionFactory::CreateOffer(
190 CreateSessionDescriptionObserver* observer, 179 CreateSessionDescriptionObserver* observer,
191 const PeerConnectionInterface::RTCOfferAnswerOptions& options) { 180 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 delete param; 292 delete param;
304 break; 293 break;
305 } 294 }
306 case MSG_CREATE_SESSIONDESCRIPTION_FAILED: { 295 case MSG_CREATE_SESSIONDESCRIPTION_FAILED: {
307 CreateSessionDescriptionMsg* param = 296 CreateSessionDescriptionMsg* param =
308 static_cast<CreateSessionDescriptionMsg*>(msg->pdata); 297 static_cast<CreateSessionDescriptionMsg*>(msg->pdata);
309 param->observer->OnFailure(param->error); 298 param->observer->OnFailure(param->error);
310 delete param; 299 delete param;
311 break; 300 break;
312 } 301 }
313 case MSG_GENERATE_IDENTITY: {
314 LOG(LS_INFO) << "Generating identity.";
315 SetIdentity(rtc::SSLIdentity::Generate(DtlsIdentityStore::kIdentityName));
316 break;
317 }
318 default: 302 default:
319 ASSERT(false); 303 ASSERT(false);
320 break; 304 break;
321 } 305 }
322 } 306 }
323 307
324 void WebRtcSessionDescriptionFactory::InternalCreateOffer( 308 void WebRtcSessionDescriptionFactory::InternalCreateOffer(
325 CreateSessionDescriptionRequest request) { 309 CreateSessionDescriptionRequest request) {
326 cricket::SessionDescription* desc( 310 cricket::SessionDescription* desc(
327 session_desc_factory_.CreateOffer( 311 session_desc_factory_.CreateOffer(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 if (create_session_description_requests_.front().type == 432 if (create_session_description_requests_.front().type ==
449 CreateSessionDescriptionRequest::kOffer) { 433 CreateSessionDescriptionRequest::kOffer) {
450 InternalCreateOffer(create_session_description_requests_.front()); 434 InternalCreateOffer(create_session_description_requests_.front());
451 } else { 435 } else {
452 InternalCreateAnswer(create_session_description_requests_.front()); 436 InternalCreateAnswer(create_session_description_requests_.front());
453 } 437 }
454 create_session_description_requests_.pop(); 438 create_session_description_requests_.pop();
455 } 439 }
456 } 440 }
457 } // namespace webrtc 441 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698