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

Side by Side Diff: webrtc/p2p/base/dtlstransportchannel.cc

Issue 1453523002: Allow remote fingerprint update during a call (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Remove empty line Created 5 years 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 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 192
193 return dtls_->GetSslCipherSuite(cipher); 193 return dtls_->GetSslCipherSuite(cipher);
194 } 194 }
195 195
196 bool DtlsTransportChannelWrapper::SetRemoteFingerprint( 196 bool DtlsTransportChannelWrapper::SetRemoteFingerprint(
197 const std::string& digest_alg, 197 const std::string& digest_alg,
198 const uint8_t* digest, 198 const uint8_t* digest,
199 size_t digest_len) { 199 size_t digest_len) {
200 rtc::Buffer remote_fingerprint_value(digest, digest_len); 200 rtc::Buffer remote_fingerprint_value(digest, digest_len);
201 201
202 // Once we have the local certificate, the same remote fingerprint can be set
203 // multiple times.
202 if (dtls_active_ && remote_fingerprint_value_ == remote_fingerprint_value && 204 if (dtls_active_ && remote_fingerprint_value_ == remote_fingerprint_value &&
203 !digest_alg.empty()) { 205 !digest_alg.empty()) {
204 // This may happen during renegotiation. 206 // This may happen during renegotiation.
205 LOG_J(LS_INFO, this) << "Ignoring identical remote DTLS fingerprint"; 207 LOG_J(LS_INFO, this) << "Ignoring identical remote DTLS fingerprint";
206 return true; 208 return true;
207 } 209 }
208 210
209 // Allow SetRemoteFingerprint with a NULL digest even if SetLocalCertificate 211 // If the other side doesn't support DTLS, turn off |dtls_active_|.
210 // hasn't been called.
211 if (dtls_ || (!dtls_active_ && !digest_alg.empty())) {
212 LOG_J(LS_ERROR, this) << "Can't set DTLS remote settings in this state.";
213 return false;
214 }
215
216 if (digest_alg.empty()) { 212 if (digest_alg.empty()) {
213 RTC_DCHECK(!digest_len);
217 LOG_J(LS_INFO, this) << "Other side didn't support DTLS."; 214 LOG_J(LS_INFO, this) << "Other side didn't support DTLS.";
218 dtls_active_ = false; 215 dtls_active_ = false;
219 return true; 216 return true;
220 } 217 }
221 218
219 // Otherwise, we must have a local certificate before setting remote
220 // fingerprint.
221 if (!dtls_active_) {
222 LOG_J(LS_ERROR, this) << "Can't set DTLS remote settings in this state.";
223 return false;
224 }
225
222 // At this point we know we are doing DTLS 226 // At this point we know we are doing DTLS
223 remote_fingerprint_value_ = remote_fingerprint_value.Pass(); 227 remote_fingerprint_value_ = remote_fingerprint_value.Pass();
224 remote_fingerprint_algorithm_ = digest_alg; 228 remote_fingerprint_algorithm_ = digest_alg;
225 229
230 bool reconnect = dtls_;
231
226 if (!SetupDtls()) { 232 if (!SetupDtls()) {
227 set_dtls_state(DTLS_TRANSPORT_FAILED); 233 set_dtls_state(DTLS_TRANSPORT_FAILED);
228 return false; 234 return false;
229 } 235 }
230 236
237 if (reconnect) {
238 Reconnect();
239 }
240
231 return true; 241 return true;
232 } 242 }
233 243
234 bool DtlsTransportChannelWrapper::GetRemoteSSLCertificate( 244 bool DtlsTransportChannelWrapper::GetRemoteSSLCertificate(
235 rtc::SSLCertificate** cert) const { 245 rtc::SSLCertificate** cert) const {
236 if (!dtls_) { 246 if (!dtls_) {
237 return false; 247 return false;
238 } 248 }
239 249
240 return dtls_->GetPeerCertificate(cert); 250 return dtls_->GetPeerCertificate(cert);
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 if (dtls_->GetState() == rtc::SS_OPEN) { 533 if (dtls_->GetState() == rtc::SS_OPEN) {
524 // The check for OPEN shouldn't be necessary but let's make 534 // The check for OPEN shouldn't be necessary but let's make
525 // sure we don't accidentally frob the state if it's closed. 535 // sure we don't accidentally frob the state if it's closed.
526 set_dtls_state(DTLS_TRANSPORT_CONNECTED); 536 set_dtls_state(DTLS_TRANSPORT_CONNECTED);
527 set_writable(true); 537 set_writable(true);
528 } 538 }
529 } 539 }
530 if (sig & rtc::SE_READ) { 540 if (sig & rtc::SE_READ) {
531 char buf[kMaxDtlsPacketLen]; 541 char buf[kMaxDtlsPacketLen];
532 size_t read; 542 size_t read;
533 if (dtls_->Read(buf, sizeof(buf), &read, NULL) == rtc::SR_SUCCESS) { 543 rtc::StreamResult result = dtls_->Read(buf, sizeof(buf), &read, NULL);
544 if (result == rtc::SR_SUCCESS) {
534 SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0); 545 SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0);
546 } else if (result == rtc::SR_EOS) {
547 // If the SSL stream has closed remotely, reset the |sig| to be SE_CLOSE
juberti 2015/12/02 00:29:43 Won't we get a SE_CLOSE anyway after the SE_READ?
guoweis_webrtc 2015/12/02 18:44:15 This crashes randomly after many repeated runs so
guoweis_webrtc 2015/12/03 22:59:41 I'm backing this out. This still crashes but with
548 // so it could be handled below.
549 sig = rtc::SE_CLOSE;
535 } 550 }
536 } 551 }
537 if (sig & rtc::SE_CLOSE) { 552 if (sig & rtc::SE_CLOSE) {
538 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself. 553 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself.
539 set_writable(false); 554 set_writable(false);
540 if (!err) { 555 if (!err) {
541 LOG_J(LS_INFO, this) << "DTLS channel closed"; 556 LOG_J(LS_INFO, this) << "DTLS channel closed";
542 set_dtls_state(DTLS_TRANSPORT_CLOSED); 557 set_dtls_state(DTLS_TRANSPORT_CLOSED);
543 } else { 558 } else {
544 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err; 559 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 ASSERT(channel == channel_); 624 ASSERT(channel == channel_);
610 SignalRouteChange(this, candidate); 625 SignalRouteChange(this, candidate);
611 } 626 }
612 627
613 void DtlsTransportChannelWrapper::OnConnectionRemoved( 628 void DtlsTransportChannelWrapper::OnConnectionRemoved(
614 TransportChannelImpl* channel) { 629 TransportChannelImpl* channel) {
615 ASSERT(channel == channel_); 630 ASSERT(channel == channel_);
616 SignalConnectionRemoved(this); 631 SignalConnectionRemoved(this);
617 } 632 }
618 633
634 void DtlsTransportChannelWrapper::Reconnect() {
635 set_dtls_state(DTLS_TRANSPORT_NEW);
636 set_writable(false);
637 if (channel_->writable()) {
638 OnWritableState(channel_);
639 } else {
640 channel_->Connect();
juberti 2015/12/02 00:29:44 Why do we need to call Connect() here? We didn't d
guoweis_webrtc 2015/12/02 18:44:15 Indeed, the tranfered endpoint has always maintain
guoweis_webrtc 2015/12/03 22:59:41 Right, we don't need this part. Removing it.
641 }
642 }
643
619 } // namespace cricket 644 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698