| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 |
| 11 #include "webrtc/p2p/base/jseptransport.h" |
| 12 |
| 11 #include <memory> | 13 #include <memory> |
| 12 #include <utility> // for std::pair | 14 #include <utility> // for std::pair |
| 13 | 15 |
| 14 #include "webrtc/p2p/base/jseptransport.h" | 16 #include "webrtc/base/bind.h" |
| 15 | 17 #include "webrtc/base/checks.h" |
| 18 #include "webrtc/base/logging.h" |
| 16 #include "webrtc/p2p/base/candidate.h" | 19 #include "webrtc/p2p/base/candidate.h" |
| 17 #include "webrtc/p2p/base/dtlstransportchannel.h" | 20 #include "webrtc/p2p/base/dtlstransportchannel.h" |
| 18 #include "webrtc/p2p/base/p2pconstants.h" | 21 #include "webrtc/p2p/base/p2pconstants.h" |
| 19 #include "webrtc/p2p/base/p2ptransportchannel.h" | 22 #include "webrtc/p2p/base/p2ptransportchannel.h" |
| 20 #include "webrtc/p2p/base/port.h" | 23 #include "webrtc/p2p/base/port.h" |
| 21 #include "webrtc/p2p/base/transportchannelimpl.h" | |
| 22 #include "webrtc/base/bind.h" | |
| 23 #include "webrtc/base/checks.h" | |
| 24 #include "webrtc/base/logging.h" | |
| 25 | 24 |
| 26 namespace cricket { | 25 namespace cricket { |
| 27 | 26 |
| 28 static bool VerifyIceParams(const TransportDescription& desc) { | 27 static bool VerifyIceParams(const TransportDescription& desc) { |
| 29 // For legacy protocols. | 28 // For legacy protocols. |
| 30 if (desc.ice_ufrag.empty() && desc.ice_pwd.empty()) | 29 if (desc.ice_ufrag.empty() && desc.ice_pwd.empty()) |
| 31 return true; | 30 return true; |
| 32 | 31 |
| 33 if (desc.ice_ufrag.length() < ICE_UFRAG_MIN_LENGTH || | 32 if (desc.ice_ufrag.length() < ICE_UFRAG_MIN_LENGTH || |
| 34 desc.ice_ufrag.length() > ICE_UFRAG_MAX_LENGTH) { | 33 desc.ice_ufrag.length() > ICE_UFRAG_MAX_LENGTH) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 119 } |
| 121 } | 120 } |
| 122 return true; | 121 return true; |
| 123 } | 122 } |
| 124 | 123 |
| 125 JsepTransport::JsepTransport( | 124 JsepTransport::JsepTransport( |
| 126 const std::string& mid, | 125 const std::string& mid, |
| 127 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) | 126 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) |
| 128 : mid_(mid), certificate_(certificate) {} | 127 : mid_(mid), certificate_(certificate) {} |
| 129 | 128 |
| 130 bool JsepTransport::AddChannel(TransportChannelImpl* dtls, int component) { | 129 bool JsepTransport::AddChannel(DtlsTransportInternal* dtls, int component) { |
| 131 if (channels_.find(component) != channels_.end()) { | 130 if (channels_.find(component) != channels_.end()) { |
| 132 LOG(LS_ERROR) << "Adding channel for component " << component << " twice."; | 131 LOG(LS_ERROR) << "Adding channel for component " << component << " twice."; |
| 133 return false; | 132 return false; |
| 134 } | 133 } |
| 135 channels_[component] = dtls; | 134 channels_[component] = dtls; |
| 136 // Something's wrong if a channel is being added after a description is set. | 135 // Something's wrong if a channel is being added after a description is set. |
| 137 // This may currently occur if rtcp-mux is negotiated, then a new m= section | 136 // This may currently occur if rtcp-mux is negotiated, then a new m= section |
| 138 // is added in a later offer/answer. But this is suboptimal and should be | 137 // is added in a later offer/answer. But this is suboptimal and should be |
| 139 // changed; we shouldn't support going from muxed to non-muxed. | 138 // changed; we shouldn't support going from muxed to non-muxed. |
| 140 // TODO(deadbeef): Once this is fixed, make the warning an error, and remove | 139 // TODO(deadbeef): Once this is fixed, make the warning an error, and remove |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 278 |
| 280 void JsepTransport::GetSslRole(rtc::SSLRole* ssl_role) const { | 279 void JsepTransport::GetSslRole(rtc::SSLRole* ssl_role) const { |
| 281 RTC_DCHECK(ssl_role); | 280 RTC_DCHECK(ssl_role); |
| 282 *ssl_role = secure_role_; | 281 *ssl_role = secure_role_; |
| 283 } | 282 } |
| 284 | 283 |
| 285 bool JsepTransport::GetStats(TransportStats* stats) { | 284 bool JsepTransport::GetStats(TransportStats* stats) { |
| 286 stats->transport_name = mid(); | 285 stats->transport_name = mid(); |
| 287 stats->channel_stats.clear(); | 286 stats->channel_stats.clear(); |
| 288 for (auto& kv : channels_) { | 287 for (auto& kv : channels_) { |
| 289 TransportChannelImpl* channel = kv.second; | 288 DtlsTransportInternal* dtls_transport = kv.second; |
| 290 TransportChannelStats substats; | 289 TransportChannelStats substats; |
| 291 substats.component = kv.first; | 290 substats.component = kv.first; |
| 292 channel->GetSrtpCryptoSuite(&substats.srtp_crypto_suite); | 291 dtls_transport->GetSrtpCryptoSuite(&substats.srtp_crypto_suite); |
| 293 channel->GetSslCipherSuite(&substats.ssl_cipher_suite); | 292 dtls_transport->GetSslCipherSuite(&substats.ssl_cipher_suite); |
| 294 substats.dtls_state = channel->dtls_state(); | 293 substats.dtls_state = dtls_transport->dtls_state(); |
| 295 if (!channel->GetStats(&substats.connection_infos)) { | 294 if (!dtls_transport->ice_transport()->GetStats( |
| 295 &substats.connection_infos)) { |
| 296 return false; | 296 return false; |
| 297 } | 297 } |
| 298 stats->channel_stats.push_back(substats); | 298 stats->channel_stats.push_back(substats); |
| 299 } | 299 } |
| 300 return true; | 300 return true; |
| 301 } | 301 } |
| 302 | 302 |
| 303 bool JsepTransport::VerifyCertificateFingerprint( | 303 bool JsepTransport::VerifyCertificateFingerprint( |
| 304 const rtc::RTCCertificate* certificate, | 304 const rtc::RTCCertificate* certificate, |
| 305 const rtc::SSLFingerprint* fingerprint, | 305 const rtc::SSLFingerprint* fingerprint, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 318 return true; | 318 return true; |
| 319 } | 319 } |
| 320 std::ostringstream desc; | 320 std::ostringstream desc; |
| 321 desc << "Local fingerprint does not match identity. Expected: "; | 321 desc << "Local fingerprint does not match identity. Expected: "; |
| 322 desc << fp_tmp->ToString(); | 322 desc << fp_tmp->ToString(); |
| 323 desc << " Got: " << fingerprint->ToString(); | 323 desc << " Got: " << fingerprint->ToString(); |
| 324 return BadTransportDescription(desc.str(), error_desc); | 324 return BadTransportDescription(desc.str(), error_desc); |
| 325 } | 325 } |
| 326 | 326 |
| 327 bool JsepTransport::ApplyLocalTransportDescription( | 327 bool JsepTransport::ApplyLocalTransportDescription( |
| 328 TransportChannelImpl* channel, | 328 DtlsTransportInternal* dtls_transport, |
| 329 std::string* error_desc) { | 329 std::string* error_desc) { |
| 330 channel->SetIceParameters(local_description_->GetIceParameters()); | 330 dtls_transport->ice_transport()->SetIceParameters( |
| 331 local_description_->GetIceParameters()); |
| 331 return true; | 332 return true; |
| 332 } | 333 } |
| 333 | 334 |
| 334 bool JsepTransport::ApplyRemoteTransportDescription( | 335 bool JsepTransport::ApplyRemoteTransportDescription( |
| 335 TransportChannelImpl* channel, | 336 DtlsTransportInternal* dtls_transport, |
| 336 std::string* error_desc) { | 337 std::string* error_desc) { |
| 337 // Currently, all ICE-related calls still go through this DTLS channel. But | 338 // Currently, all ICE-related calls still go through this DTLS channel. But |
| 338 // that will change once we get rid of TransportChannelImpl, and the DTLS | 339 // that will change once we get rid of TransportChannelImpl, and the DTLS |
| 339 // channel interface no longer includes ICE-specific methods. Then this class | 340 // channel interface no longer includes ICE-specific methods. Then this class |
| 340 // will need to call dtls->ice()->SetIceRole(), for example, assuming the Dtls | 341 // will need to call dtls->ice()->SetIceRole(), for example, assuming the Dtls |
| 341 // interface will expose its inner ICE channel. | 342 // interface will expose its inner ICE channel. |
| 342 channel->SetRemoteIceParameters(remote_description_->GetIceParameters()); | 343 dtls_transport->ice_transport()->SetRemoteIceParameters( |
| 343 channel->SetRemoteIceMode(remote_description_->ice_mode); | 344 remote_description_->GetIceParameters()); |
| 345 dtls_transport->ice_transport()->SetRemoteIceMode( |
| 346 remote_description_->ice_mode); |
| 344 return true; | 347 return true; |
| 345 } | 348 } |
| 346 | 349 |
| 347 bool JsepTransport::ApplyNegotiatedTransportDescription( | 350 bool JsepTransport::ApplyNegotiatedTransportDescription( |
| 348 TransportChannelImpl* channel, | 351 DtlsTransportInternal* dtls_transport, |
| 349 std::string* error_desc) { | 352 std::string* error_desc) { |
| 350 // Set SSL role. Role must be set before fingerprint is applied, which | 353 // Set SSL role. Role must be set before fingerprint is applied, which |
| 351 // initiates DTLS setup. | 354 // initiates DTLS setup. |
| 352 if (!channel->SetSslRole(secure_role_)) { | 355 if (!dtls_transport->SetSslRole(secure_role_)) { |
| 353 return BadTransportDescription("Failed to set SSL role for the channel.", | 356 return BadTransportDescription("Failed to set SSL role for the channel.", |
| 354 error_desc); | 357 error_desc); |
| 355 } | 358 } |
| 356 // Apply remote fingerprint. | 359 // Apply remote fingerprint. |
| 357 if (!channel->SetRemoteFingerprint( | 360 if (!dtls_transport->SetRemoteFingerprint( |
| 358 remote_fingerprint_->algorithm, | 361 remote_fingerprint_->algorithm, |
| 359 reinterpret_cast<const uint8_t*>(remote_fingerprint_->digest.data()), | 362 reinterpret_cast<const uint8_t*>(remote_fingerprint_->digest.data()), |
| 360 remote_fingerprint_->digest.size())) { | 363 remote_fingerprint_->digest.size())) { |
| 361 return BadTransportDescription("Failed to apply remote fingerprint.", | 364 return BadTransportDescription("Failed to apply remote fingerprint.", |
| 362 error_desc); | 365 error_desc); |
| 363 } | 366 } |
| 364 return true; | 367 return true; |
| 365 } | 368 } |
| 366 | 369 |
| 367 bool JsepTransport::NegotiateTransportDescription(ContentAction local_role, | 370 bool JsepTransport::NegotiateTransportDescription(ContentAction local_role, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 } | 478 } |
| 476 | 479 |
| 477 // If local is passive, local will act as server. | 480 // If local is passive, local will act as server. |
| 478 } | 481 } |
| 479 | 482 |
| 480 *ssl_role = is_remote_server ? rtc::SSL_CLIENT : rtc::SSL_SERVER; | 483 *ssl_role = is_remote_server ? rtc::SSL_CLIENT : rtc::SSL_SERVER; |
| 481 return true; | 484 return true; |
| 482 } | 485 } |
| 483 | 486 |
| 484 } // namespace cricket | 487 } // namespace cricket |
| OLD | NEW |