| 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  | 
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  393   // creation, we have the negotiation state saved until a new |  393   // creation, we have the negotiation state saved until a new | 
|  394   // negotiation happens. |  394   // negotiation happens. | 
|  395   for (const auto& kv : channels_) { |  395   for (const auto& kv : channels_) { | 
|  396     if (!ApplyNegotiatedTransportDescription(kv.second, error_desc)) { |  396     if (!ApplyNegotiatedTransportDescription(kv.second, error_desc)) { | 
|  397       return false; |  397       return false; | 
|  398     } |  398     } | 
|  399   } |  399   } | 
|  400   return true; |  400   return true; | 
|  401 } |  401 } | 
|  402  |  402  | 
 |  403 bool Transport::VerifyCertificateFingerprint( | 
 |  404     const rtc::RTCCertificate* certificate, | 
 |  405     const rtc::SSLFingerprint* fingerprint, | 
 |  406     std::string* error_desc) const { | 
 |  407   if (!fingerprint) { | 
 |  408     return BadTransportDescription("No fingerprint.", error_desc); | 
 |  409   } | 
 |  410   if (!certificate) { | 
 |  411     return BadTransportDescription( | 
 |  412         "Fingerprint provided but no identity available.", error_desc); | 
 |  413   } | 
 |  414   rtc::scoped_ptr<rtc::SSLFingerprint> fp_tmp(rtc::SSLFingerprint::Create( | 
 |  415       fingerprint->algorithm, certificate->identity())); | 
 |  416   ASSERT(fp_tmp.get() != NULL); | 
 |  417   if (*fp_tmp == *fingerprint) { | 
 |  418     return true; | 
 |  419   } | 
 |  420   std::ostringstream desc; | 
 |  421   desc << "Local fingerprint does not match identity. Expected: "; | 
 |  422   desc << fp_tmp->ToString(); | 
 |  423   desc << " Got: " << fingerprint->ToString(); | 
 |  424   return BadTransportDescription(desc.str(), error_desc); | 
 |  425 } | 
 |  426  | 
 |  427 bool Transport::NegotiateRole(ContentAction local_role, | 
 |  428                               rtc::SSLRole* ssl_role, | 
 |  429                               std::string* error_desc) const { | 
 |  430   RTC_DCHECK(ssl_role); | 
 |  431   if (!local_description() || !remote_description()) { | 
 |  432     const std::string msg = | 
 |  433         "Local and Remote description must be set before " | 
 |  434         "transport descriptions are negotiated"; | 
 |  435     return BadTransportDescription(msg, error_desc); | 
 |  436   } | 
 |  437  | 
 |  438   // From RFC 4145, section-4.1, The following are the values that the | 
 |  439   // 'setup' attribute can take in an offer/answer exchange: | 
 |  440   //       Offer      Answer | 
 |  441   //      ________________ | 
 |  442   //      active     passive / holdconn | 
 |  443   //      passive    active / holdconn | 
 |  444   //      actpass    active / passive / holdconn | 
 |  445   //      holdconn   holdconn | 
 |  446   // | 
 |  447   // Set the role that is most conformant with RFC 5763, Section 5, bullet 1 | 
 |  448   // The endpoint MUST use the setup attribute defined in [RFC4145]. | 
 |  449   // The endpoint that is the offerer MUST use the setup attribute | 
 |  450   // value of setup:actpass and be prepared to receive a client_hello | 
 |  451   // before it receives the answer.  The answerer MUST use either a | 
 |  452   // setup attribute value of setup:active or setup:passive.  Note that | 
 |  453   // if the answerer uses setup:passive, then the DTLS handshake will | 
 |  454   // not begin until the answerer is received, which adds additional | 
 |  455   // latency. setup:active allows the answer and the DTLS handshake to | 
 |  456   // occur in parallel.  Thus, setup:active is RECOMMENDED.  Whichever | 
 |  457   // party is active MUST initiate a DTLS handshake by sending a | 
 |  458   // ClientHello over each flow (host/port quartet). | 
 |  459   // IOW - actpass and passive modes should be treated as server and | 
 |  460   // active as client. | 
 |  461   ConnectionRole local_connection_role = local_description()->connection_role; | 
 |  462   ConnectionRole remote_connection_role = remote_description()->connection_role; | 
 |  463  | 
 |  464   bool is_remote_server = false; | 
 |  465   if (local_role == CA_OFFER) { | 
 |  466     if (local_connection_role != CONNECTIONROLE_ACTPASS) { | 
 |  467       return BadTransportDescription( | 
 |  468           "Offerer must use actpass value for setup attribute.", error_desc); | 
 |  469     } | 
 |  470  | 
 |  471     if (remote_connection_role == CONNECTIONROLE_ACTIVE || | 
 |  472         remote_connection_role == CONNECTIONROLE_PASSIVE || | 
 |  473         remote_connection_role == CONNECTIONROLE_NONE) { | 
 |  474       is_remote_server = (remote_connection_role == CONNECTIONROLE_PASSIVE); | 
 |  475     } else { | 
 |  476       const std::string msg = | 
 |  477           "Answerer must use either active or passive value " | 
 |  478           "for setup attribute."; | 
 |  479       return BadTransportDescription(msg, error_desc); | 
 |  480     } | 
 |  481     // If remote is NONE or ACTIVE it will act as client. | 
 |  482   } else { | 
 |  483     if (remote_connection_role != CONNECTIONROLE_ACTPASS && | 
 |  484         remote_connection_role != CONNECTIONROLE_NONE) { | 
 |  485       return BadTransportDescription( | 
 |  486           "Offerer must use actpass value for setup attribute.", error_desc); | 
 |  487     } | 
 |  488  | 
 |  489     if (local_connection_role == CONNECTIONROLE_ACTIVE || | 
 |  490         local_connection_role == CONNECTIONROLE_PASSIVE) { | 
 |  491       is_remote_server = (local_connection_role == CONNECTIONROLE_ACTIVE); | 
 |  492     } else { | 
 |  493       const std::string msg = | 
 |  494           "Answerer must use either active or passive value " | 
 |  495           "for setup attribute."; | 
 |  496       return BadTransportDescription(msg, error_desc); | 
 |  497     } | 
 |  498  | 
 |  499     // If local is passive, local will act as server. | 
 |  500   } | 
 |  501  | 
 |  502   *ssl_role = is_remote_server ? rtc::SSL_CLIENT : rtc::SSL_SERVER; | 
 |  503   return true; | 
 |  504 } | 
 |  505  | 
|  403 }  // namespace cricket |  506 }  // namespace cricket | 
| OLD | NEW |