henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_P2P_BASE_TRANSPORTDESCRIPTION_H_ |
| 12 | #define WEBRTC_P2P_BASE_TRANSPORTDESCRIPTION_H_ |
| 13 | |
| 14 | #include <algorithm> |
kwiberg | 3ec4679 | 2016-04-27 07:22:53 -0700 | [diff] [blame] | 15 | #include <memory> |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
kjellander | f475277 | 2016-03-02 05:42:30 -0800 | [diff] [blame] | 19 | #include "webrtc/p2p/base/p2pconstants.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 20 | #include "webrtc/rtc_base/sslfingerprint.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 21 | |
| 22 | namespace cricket { |
| 23 | |
| 24 | // SEC_ENABLED and SEC_REQUIRED should only be used if the session |
| 25 | // was negotiated over TLS, to protect the inline crypto material |
| 26 | // exchange. |
| 27 | // SEC_DISABLED: No crypto in outgoing offer, ignore any supplied crypto. |
| 28 | // SEC_ENABLED: Crypto in outgoing offer and answer (if supplied in offer). |
| 29 | // SEC_REQUIRED: Crypto in outgoing offer and answer. Fail any offer with absent |
| 30 | // or unsupported crypto. |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 31 | // TODO(deadbeef): Remove this or rename it to something more appropriate, like |
| 32 | // SdesPolicy. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 33 | enum SecurePolicy { |
| 34 | SEC_DISABLED, |
| 35 | SEC_ENABLED, |
| 36 | SEC_REQUIRED |
| 37 | }; |
| 38 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 39 | // Whether our side of the call is driving the negotiation, or the other side. |
| 40 | enum IceRole { |
| 41 | ICEROLE_CONTROLLING = 0, |
| 42 | ICEROLE_CONTROLLED, |
| 43 | ICEROLE_UNKNOWN |
| 44 | }; |
| 45 | |
| 46 | // ICE RFC 5245 implementation type. |
| 47 | enum IceMode { |
| 48 | ICEMODE_FULL, // As defined in http://tools.ietf.org/html/rfc5245#section-4.1 |
| 49 | ICEMODE_LITE // As defined in http://tools.ietf.org/html/rfc5245#section-4.2 |
| 50 | }; |
| 51 | |
| 52 | // RFC 4145 - http://tools.ietf.org/html/rfc4145#section-4 |
| 53 | // 'active': The endpoint will initiate an outgoing connection. |
| 54 | // 'passive': The endpoint will accept an incoming connection. |
| 55 | // 'actpass': The endpoint is willing to accept an incoming |
| 56 | // connection or to initiate an outgoing connection. |
| 57 | enum ConnectionRole { |
| 58 | CONNECTIONROLE_NONE = 0, |
| 59 | CONNECTIONROLE_ACTIVE, |
| 60 | CONNECTIONROLE_PASSIVE, |
| 61 | CONNECTIONROLE_ACTPASS, |
| 62 | CONNECTIONROLE_HOLDCONN, |
| 63 | }; |
| 64 | |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 65 | struct IceParameters { |
| 66 | // TODO(honghaiz): Include ICE mode in this structure to match the ORTC |
| 67 | // struct: |
| 68 | // http://ortc.org/wp-content/uploads/2016/03/ortc.html#idl-def-RTCIceParameters |
| 69 | std::string ufrag; |
| 70 | std::string pwd; |
| 71 | bool renomination = false; |
| 72 | IceParameters() = default; |
| 73 | IceParameters(const std::string& ice_ufrag, |
| 74 | const std::string& ice_pwd, |
| 75 | bool ice_renomination) |
| 76 | : ufrag(ice_ufrag), pwd(ice_pwd), renomination(ice_renomination) {} |
| 77 | |
| 78 | bool operator==(const IceParameters& other) { |
| 79 | return ufrag == other.ufrag && pwd == other.pwd && |
| 80 | renomination == other.renomination; |
| 81 | } |
| 82 | bool operator!=(const IceParameters& other) { return !(*this == other); } |
| 83 | }; |
| 84 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 85 | extern const char CONNECTIONROLE_ACTIVE_STR[]; |
| 86 | extern const char CONNECTIONROLE_PASSIVE_STR[]; |
| 87 | extern const char CONNECTIONROLE_ACTPASS_STR[]; |
| 88 | extern const char CONNECTIONROLE_HOLDCONN_STR[]; |
| 89 | |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 90 | constexpr auto ICE_OPTION_TRICKLE = "trickle"; |
| 91 | constexpr auto ICE_OPTION_RENOMINATION = "renomination"; |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 92 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 93 | bool StringToConnectionRole(const std::string& role_str, ConnectionRole* role); |
| 94 | bool ConnectionRoleToString(const ConnectionRole& role, std::string* role_str); |
| 95 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 96 | struct TransportDescription { |
| 97 | TransportDescription() |
| 98 | : ice_mode(ICEMODE_FULL), |
| 99 | connection_role(CONNECTIONROLE_NONE) {} |
| 100 | |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 101 | TransportDescription(const std::vector<std::string>& transport_options, |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 102 | const std::string& ice_ufrag, |
| 103 | const std::string& ice_pwd, |
| 104 | IceMode ice_mode, |
| 105 | ConnectionRole role, |
deadbeef | 46eed76 | 2016-01-28 13:24:37 -0800 | [diff] [blame] | 106 | const rtc::SSLFingerprint* identity_fingerprint) |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 107 | : transport_options(transport_options), |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 108 | ice_ufrag(ice_ufrag), |
| 109 | ice_pwd(ice_pwd), |
| 110 | ice_mode(ice_mode), |
| 111 | connection_role(role), |
deadbeef | 46eed76 | 2016-01-28 13:24:37 -0800 | [diff] [blame] | 112 | identity_fingerprint(CopyFingerprint(identity_fingerprint)) {} |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 113 | TransportDescription(const std::string& ice_ufrag, |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 114 | const std::string& ice_pwd) |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 115 | : ice_ufrag(ice_ufrag), |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 116 | ice_pwd(ice_pwd), |
| 117 | ice_mode(ICEMODE_FULL), |
| 118 | connection_role(CONNECTIONROLE_NONE) {} |
| 119 | TransportDescription(const TransportDescription& from) |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 120 | : transport_options(from.transport_options), |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 121 | ice_ufrag(from.ice_ufrag), |
| 122 | ice_pwd(from.ice_pwd), |
| 123 | ice_mode(from.ice_mode), |
| 124 | connection_role(from.connection_role), |
deadbeef | 46eed76 | 2016-01-28 13:24:37 -0800 | [diff] [blame] | 125 | identity_fingerprint(CopyFingerprint(from.identity_fingerprint.get())) { |
| 126 | } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 127 | |
| 128 | TransportDescription& operator=(const TransportDescription& from) { |
| 129 | // Self-assignment |
| 130 | if (this == &from) |
| 131 | return *this; |
| 132 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 133 | transport_options = from.transport_options; |
| 134 | ice_ufrag = from.ice_ufrag; |
| 135 | ice_pwd = from.ice_pwd; |
| 136 | ice_mode = from.ice_mode; |
| 137 | connection_role = from.connection_role; |
| 138 | |
| 139 | identity_fingerprint.reset(CopyFingerprint( |
| 140 | from.identity_fingerprint.get())); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 141 | return *this; |
| 142 | } |
| 143 | |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 144 | // TODO(deadbeef): Rename to HasIceOption, etc. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 145 | bool HasOption(const std::string& option) const { |
| 146 | return (std::find(transport_options.begin(), transport_options.end(), |
| 147 | option) != transport_options.end()); |
| 148 | } |
| 149 | void AddOption(const std::string& option) { |
| 150 | transport_options.push_back(option); |
| 151 | } |
steweg | 4b37127 | 2017-04-09 09:09:06 -0700 | [diff] [blame] | 152 | bool secure() const { return identity_fingerprint != nullptr; } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 153 | |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 154 | IceParameters GetIceParameters() { |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 155 | return IceParameters(ice_ufrag, ice_pwd, |
| 156 | HasOption(ICE_OPTION_RENOMINATION)); |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 157 | } |
| 158 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 159 | static rtc::SSLFingerprint* CopyFingerprint( |
| 160 | const rtc::SSLFingerprint* from) { |
| 161 | if (!from) |
| 162 | return NULL; |
| 163 | |
| 164 | return new rtc::SSLFingerprint(*from); |
| 165 | } |
| 166 | |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 167 | // These are actually ICE options (appearing in the ice-options attribute in |
| 168 | // SDP). |
| 169 | // TODO(deadbeef): Rename to ice_options. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 170 | std::vector<std::string> transport_options; |
| 171 | std::string ice_ufrag; |
| 172 | std::string ice_pwd; |
| 173 | IceMode ice_mode; |
| 174 | ConnectionRole connection_role; |
| 175 | |
kwiberg | 3ec4679 | 2016-04-27 07:22:53 -0700 | [diff] [blame] | 176 | std::unique_ptr<rtc::SSLFingerprint> identity_fingerprint; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | } // namespace cricket |
| 180 | |
| 181 | #endif // WEBRTC_P2P_BASE_TRANSPORTDESCRIPTION_H_ |