blob: 670213197abe8974c7ffae514b6e2b11c7e4e229 [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
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>
kwiberg3ec46792016-04-27 07:22:53 -070015#include <memory>
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000016#include <string>
17#include <vector>
18
kjellanderf4752772016-03-02 05:42:30 -080019#include "webrtc/p2p/base/p2pconstants.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020020#include "webrtc/rtc_base/sslfingerprint.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000021
22namespace 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.
deadbeef7af91dd2016-12-13 11:29:11 -080031// TODO(deadbeef): Remove this or rename it to something more appropriate, like
32// SdesPolicy.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000033enum SecurePolicy {
34 SEC_DISABLED,
35 SEC_ENABLED,
36 SEC_REQUIRED
37};
38
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000039// Whether our side of the call is driving the negotiation, or the other side.
40enum IceRole {
41 ICEROLE_CONTROLLING = 0,
42 ICEROLE_CONTROLLED,
43 ICEROLE_UNKNOWN
44};
45
46// ICE RFC 5245 implementation type.
47enum 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.
57enum ConnectionRole {
58 CONNECTIONROLE_NONE = 0,
59 CONNECTIONROLE_ACTIVE,
60 CONNECTIONROLE_PASSIVE,
61 CONNECTIONROLE_ACTPASS,
62 CONNECTIONROLE_HOLDCONN,
63};
64
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070065struct 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.org269fb4b2014-10-28 22:20:11 +000085extern const char CONNECTIONROLE_ACTIVE_STR[];
86extern const char CONNECTIONROLE_PASSIVE_STR[];
87extern const char CONNECTIONROLE_ACTPASS_STR[];
88extern const char CONNECTIONROLE_HOLDCONN_STR[];
89
deadbeef30952b42017-04-21 02:41:29 -070090constexpr auto ICE_OPTION_TRICKLE = "trickle";
91constexpr auto ICE_OPTION_RENOMINATION = "renomination";
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070092
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000093bool StringToConnectionRole(const std::string& role_str, ConnectionRole* role);
94bool ConnectionRoleToString(const ConnectionRole& role, std::string* role_str);
95
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000096struct TransportDescription {
97 TransportDescription()
98 : ice_mode(ICEMODE_FULL),
99 connection_role(CONNECTIONROLE_NONE) {}
100
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700101 TransportDescription(const std::vector<std::string>& transport_options,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000102 const std::string& ice_ufrag,
103 const std::string& ice_pwd,
104 IceMode ice_mode,
105 ConnectionRole role,
deadbeef46eed762016-01-28 13:24:37 -0800106 const rtc::SSLFingerprint* identity_fingerprint)
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700107 : transport_options(transport_options),
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000108 ice_ufrag(ice_ufrag),
109 ice_pwd(ice_pwd),
110 ice_mode(ice_mode),
111 connection_role(role),
deadbeef46eed762016-01-28 13:24:37 -0800112 identity_fingerprint(CopyFingerprint(identity_fingerprint)) {}
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700113 TransportDescription(const std::string& ice_ufrag,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000114 const std::string& ice_pwd)
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700115 : ice_ufrag(ice_ufrag),
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000116 ice_pwd(ice_pwd),
117 ice_mode(ICEMODE_FULL),
118 connection_role(CONNECTIONROLE_NONE) {}
119 TransportDescription(const TransportDescription& from)
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700120 : transport_options(from.transport_options),
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000121 ice_ufrag(from.ice_ufrag),
122 ice_pwd(from.ice_pwd),
123 ice_mode(from.ice_mode),
124 connection_role(from.connection_role),
deadbeef46eed762016-01-28 13:24:37 -0800125 identity_fingerprint(CopyFingerprint(from.identity_fingerprint.get())) {
126 }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000127
128 TransportDescription& operator=(const TransportDescription& from) {
129 // Self-assignment
130 if (this == &from)
131 return *this;
132
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000133 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.org269fb4b2014-10-28 22:20:11 +0000141 return *this;
142 }
143
deadbeef30952b42017-04-21 02:41:29 -0700144 // TODO(deadbeef): Rename to HasIceOption, etc.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000145 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 }
steweg4b371272017-04-09 09:09:06 -0700152 bool secure() const { return identity_fingerprint != nullptr; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000153
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700154 IceParameters GetIceParameters() {
deadbeef30952b42017-04-21 02:41:29 -0700155 return IceParameters(ice_ufrag, ice_pwd,
156 HasOption(ICE_OPTION_RENOMINATION));
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700157 }
158
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000159 static rtc::SSLFingerprint* CopyFingerprint(
160 const rtc::SSLFingerprint* from) {
161 if (!from)
162 return NULL;
163
164 return new rtc::SSLFingerprint(*from);
165 }
166
deadbeef30952b42017-04-21 02:41:29 -0700167 // These are actually ICE options (appearing in the ice-options attribute in
168 // SDP).
169 // TODO(deadbeef): Rename to ice_options.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000170 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
kwiberg3ec46792016-04-27 07:22:53 -0700176 std::unique_ptr<rtc::SSLFingerprint> identity_fingerprint;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000177};
178
179} // namespace cricket
180
181#endif // WEBRTC_P2P_BASE_TRANSPORTDESCRIPTION_H_