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