OLD | NEW |
---|---|
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 Loading... | |
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 // When we have local certificate, the same remote fingerprint could be set | |
203 // multiple times. | |
pthatcher1
2015/11/30 20:23:11
When we have local => Once we have the local
coul
guoweis_webrtc
2015/12/01 22:05:13
Done.
| |
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 set_dtls_state(DTLS_TRANSPORT_NEW); | |
pthatcher1
2015/11/30 20:23:11
Why do we set the state to new and then assert the
guoweis_webrtc
2015/12/01 22:05:13
Done.
| |
239 set_writable(false); | |
240 Reconnect(); | |
241 } | |
242 | |
231 return true; | 243 return true; |
232 } | 244 } |
233 | 245 |
234 bool DtlsTransportChannelWrapper::GetRemoteSSLCertificate( | 246 bool DtlsTransportChannelWrapper::GetRemoteSSLCertificate( |
235 rtc::SSLCertificate** cert) const { | 247 rtc::SSLCertificate** cert) const { |
236 if (!dtls_) { | 248 if (!dtls_) { |
237 return false; | 249 return false; |
238 } | 250 } |
239 | 251 |
240 return dtls_->GetPeerCertificate(cert); | 252 return dtls_->GetPeerCertificate(cert); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
523 if (dtls_->GetState() == rtc::SS_OPEN) { | 535 if (dtls_->GetState() == rtc::SS_OPEN) { |
524 // The check for OPEN shouldn't be necessary but let's make | 536 // 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. | 537 // sure we don't accidentally frob the state if it's closed. |
526 set_dtls_state(DTLS_TRANSPORT_CONNECTED); | 538 set_dtls_state(DTLS_TRANSPORT_CONNECTED); |
527 set_writable(true); | 539 set_writable(true); |
528 } | 540 } |
529 } | 541 } |
530 if (sig & rtc::SE_READ) { | 542 if (sig & rtc::SE_READ) { |
531 char buf[kMaxDtlsPacketLen]; | 543 char buf[kMaxDtlsPacketLen]; |
532 size_t read; | 544 size_t read; |
533 if (dtls_->Read(buf, sizeof(buf), &read, NULL) == rtc::SR_SUCCESS) { | 545 rtc::StreamResult result = dtls_->Read(buf, sizeof(buf), &read, NULL); |
546 if (result == rtc::SR_SUCCESS) { | |
534 SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0); | 547 SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0); |
548 } else if (result == rtc::SR_EOS) { | |
549 // If the SSL stream has closed remotely, reset the |sig| to be SE_CLOSE | |
550 // so it could be handled below. | |
551 sig = rtc::SE_CLOSE; | |
pthatcher1
2015/11/30 20:23:11
Shouldn't we have a unit test for dtlstransportcha
guoweis_webrtc
2015/12/01 22:05:13
Yes, but I'd like to add it in next CL.
| |
535 } | 552 } |
536 } | 553 } |
537 if (sig & rtc::SE_CLOSE) { | 554 if (sig & rtc::SE_CLOSE) { |
538 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself. | 555 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself. |
539 set_writable(false); | 556 set_writable(false); |
540 if (!err) { | 557 if (!err) { |
541 LOG_J(LS_INFO, this) << "DTLS channel closed"; | 558 LOG_J(LS_INFO, this) << "DTLS channel closed"; |
542 set_dtls_state(DTLS_TRANSPORT_CLOSED); | 559 set_dtls_state(DTLS_TRANSPORT_CLOSED); |
543 } else { | 560 } else { |
544 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err; | 561 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 ASSERT(channel == channel_); | 626 ASSERT(channel == channel_); |
610 SignalRouteChange(this, candidate); | 627 SignalRouteChange(this, candidate); |
611 } | 628 } |
612 | 629 |
613 void DtlsTransportChannelWrapper::OnConnectionRemoved( | 630 void DtlsTransportChannelWrapper::OnConnectionRemoved( |
614 TransportChannelImpl* channel) { | 631 TransportChannelImpl* channel) { |
615 ASSERT(channel == channel_); | 632 ASSERT(channel == channel_); |
616 SignalConnectionRemoved(this); | 633 SignalConnectionRemoved(this); |
617 } | 634 } |
618 | 635 |
636 void DtlsTransportChannelWrapper::Reconnect() { | |
637 ASSERT(dtls_state() == DTLS_TRANSPORT_NEW); | |
638 if (channel_->writable()) { | |
639 OnWritableState(channel_); | |
640 } else { | |
641 channel_->Connect(); | |
642 } | |
643 } | |
644 | |
619 } // namespace cricket | 645 } // namespace cricket |
OLD | NEW |