Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 11 | #include "pc/jsep_transport.h" |
| 12 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 13 | #include <stdint.h> |
| 14 | #include <string.h> |
| 15 | |
| 16 | #include <ostream> |
| 17 | #include <string> |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 18 | #include <tuple> |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 19 | #include <utility> |
| 20 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 21 | #include "api/candidate.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "media/base/fake_rtp.h" |
| 23 | #include "p2p/base/fake_dtls_transport.h" |
| 24 | #include "p2p/base/fake_ice_transport.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 25 | #include "p2p/base/p2p_constants.h" |
| 26 | #include "p2p/base/packet_transport_internal.h" |
| 27 | #include "rtc_base/async_packet_socket.h" |
| 28 | #include "rtc_base/buffer.h" |
| 29 | #include "rtc_base/byte_order.h" |
| 30 | #include "rtc_base/copy_on_write_buffer.h" |
| 31 | #include "rtc_base/helpers.h" |
| 32 | #include "rtc_base/logging.h" |
| 33 | #include "rtc_base/net_helper.h" |
| 34 | #include "rtc_base/ref_counted_object.h" |
| 35 | #include "rtc_base/socket_address.h" |
| 36 | #include "rtc_base/ssl_certificate.h" |
| 37 | #include "rtc_base/ssl_identity.h" |
| 38 | #include "rtc_base/third_party/sigslot/sigslot.h" |
| 39 | #include "test/gtest.h" |
Jonas Oreland | ed99dae | 2022-03-09 09:28:10 +0100 | [diff] [blame] | 40 | #include "test/scoped_key_value_config.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 41 | |
| 42 | namespace cricket { |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 43 | namespace { |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 44 | using webrtc::SdpType; |
| 45 | |
| 46 | static const char kIceUfrag1[] = "U001"; |
| 47 | static const char kIcePwd1[] = "TESTICEPWD00000000000001"; |
| 48 | static const char kIceUfrag2[] = "U002"; |
| 49 | static const char kIcePwd2[] = "TESTIEPWD00000000000002"; |
| 50 | static const char kTransportName[] = "Test Transport"; |
| 51 | |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 52 | enum class SrtpMode { |
| 53 | kSdes, |
| 54 | kDtlsSrtp, |
| 55 | }; |
| 56 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 57 | struct NegotiateRoleParams { |
| 58 | ConnectionRole local_role; |
| 59 | ConnectionRole remote_role; |
| 60 | SdpType local_type; |
| 61 | SdpType remote_type; |
| 62 | }; |
| 63 | |
Harald Alvestrand | efece42 | 2021-08-19 09:12:51 +0000 | [diff] [blame] | 64 | std::ostream& operator<<(std::ostream& os, const ConnectionRole& role) { |
| 65 | std::string str = "invalid"; |
| 66 | ConnectionRoleToString(role, &str); |
| 67 | os << str; |
| 68 | return os; |
| 69 | } |
| 70 | |
| 71 | std::ostream& operator<<(std::ostream& os, const NegotiateRoleParams& param) { |
| 72 | os << "[Local role " << param.local_role << " Remote role " |
| 73 | << param.remote_role << " LocalType " << SdpTypeToString(param.local_type) |
| 74 | << " RemoteType " << SdpTypeToString(param.remote_type) << "]"; |
| 75 | return os; |
| 76 | } |
| 77 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 78 | rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport( |
| 79 | std::unique_ptr<FakeIceTransport> internal) { |
| 80 | if (!internal) { |
| 81 | return nullptr; |
| 82 | } |
| 83 | |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 84 | return rtc::make_ref_counted<FakeIceTransportWrapper>(std::move(internal)); |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 87 | class JsepTransport2Test : public ::testing::Test, public sigslot::has_slots<> { |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 88 | protected: |
| 89 | std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 90 | rtc::PacketTransportInternal* rtp_packet_transport, |
| 91 | rtc::PacketTransportInternal* rtcp_packet_transport) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 92 | auto srtp_transport = std::make_unique<webrtc::SrtpTransport>( |
Jonas Oreland | ed99dae | 2022-03-09 09:28:10 +0100 | [diff] [blame] | 93 | rtcp_packet_transport == nullptr, field_trials_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 94 | |
| 95 | srtp_transport->SetRtpPacketTransport(rtp_packet_transport); |
| 96 | if (rtcp_packet_transport) { |
| 97 | srtp_transport->SetRtcpPacketTransport(rtp_packet_transport); |
| 98 | } |
| 99 | return srtp_transport; |
| 100 | } |
| 101 | |
| 102 | std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 103 | cricket::DtlsTransportInternal* rtp_dtls_transport, |
| 104 | cricket::DtlsTransportInternal* rtcp_dtls_transport) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 105 | auto dtls_srtp_transport = std::make_unique<webrtc::DtlsSrtpTransport>( |
Jonas Oreland | ed99dae | 2022-03-09 09:28:10 +0100 | [diff] [blame] | 106 | rtcp_dtls_transport == nullptr, field_trials_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 107 | dtls_srtp_transport->SetDtlsTransports(rtp_dtls_transport, |
| 108 | rtcp_dtls_transport); |
| 109 | return dtls_srtp_transport; |
| 110 | } |
| 111 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 112 | // Create a new JsepTransport with a FakeDtlsTransport and a |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 113 | // FakeIceTransport. |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 114 | std::unique_ptr<JsepTransport> CreateJsepTransport2(bool rtcp_mux_enabled, |
| 115 | SrtpMode srtp_mode) { |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 116 | auto ice_internal = std::make_unique<FakeIceTransport>( |
| 117 | kTransportName, ICE_CANDIDATE_COMPONENT_RTP); |
| 118 | auto rtp_dtls_transport = |
| 119 | std::make_unique<FakeDtlsTransport>(ice_internal.get()); |
| 120 | auto ice = CreateIceTransport(std::move(ice_internal)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 121 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 122 | std::unique_ptr<FakeIceTransport> rtcp_ice_internal; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 123 | std::unique_ptr<FakeDtlsTransport> rtcp_dtls_transport; |
| 124 | if (!rtcp_mux_enabled) { |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 125 | rtcp_ice_internal = std::make_unique<FakeIceTransport>( |
Bjorn A Mellem | 0c1c1b4 | 2019-05-29 17:34:13 -0700 | [diff] [blame] | 126 | kTransportName, ICE_CANDIDATE_COMPONENT_RTCP); |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 127 | rtcp_dtls_transport = |
| 128 | std::make_unique<FakeDtlsTransport>(rtcp_ice_internal.get()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 129 | } |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 130 | auto rtcp_ice = CreateIceTransport(std::move(rtcp_ice_internal)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 131 | |
| 132 | std::unique_ptr<webrtc::RtpTransport> unencrypted_rtp_transport; |
| 133 | std::unique_ptr<webrtc::SrtpTransport> sdes_transport; |
| 134 | std::unique_ptr<webrtc::DtlsSrtpTransport> dtls_srtp_transport; |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 135 | switch (srtp_mode) { |
| 136 | case SrtpMode::kSdes: |
| 137 | sdes_transport = CreateSdesTransport(rtp_dtls_transport.get(), |
| 138 | rtcp_dtls_transport.get()); |
| 139 | sdes_transport_ = sdes_transport.get(); |
| 140 | break; |
| 141 | case SrtpMode::kDtlsSrtp: |
| 142 | dtls_srtp_transport = CreateDtlsSrtpTransport( |
| 143 | rtp_dtls_transport.get(), rtcp_dtls_transport.get()); |
| 144 | break; |
| 145 | default: |
Artem Titov | d325196 | 2021-11-15 16:57:07 +0100 | [diff] [blame] | 146 | RTC_DCHECK_NOTREACHED(); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 147 | } |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 148 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 149 | auto jsep_transport = std::make_unique<JsepTransport>( |
Bjorn A Mellem | 0c1c1b4 | 2019-05-29 17:34:13 -0700 | [diff] [blame] | 150 | kTransportName, /*local_certificate=*/nullptr, std::move(ice), |
| 151 | std::move(rtcp_ice), std::move(unencrypted_rtp_transport), |
| 152 | std::move(sdes_transport), std::move(dtls_srtp_transport), |
Niels Möller | ab9d6e1 | 2021-02-02 16:49:02 +0100 | [diff] [blame] | 153 | std::move(rtp_dtls_transport), std::move(rtcp_dtls_transport), |
Mirko Bonadei | 96dca92 | 2021-07-10 22:37:40 +0200 | [diff] [blame] | 154 | /*sctp_transport=*/nullptr, |
| 155 | /*rtcp_mux_active_callback=*/[&]() { OnRtcpMuxActive(); }); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 156 | |
| 157 | signal_rtcp_mux_active_received_ = false; |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 158 | return jsep_transport; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | JsepTransportDescription MakeJsepTransportDescription( |
| 162 | bool rtcp_mux_enabled, |
| 163 | const char* ufrag, |
| 164 | const char* pwd, |
| 165 | const rtc::scoped_refptr<rtc::RTCCertificate>& cert, |
| 166 | ConnectionRole role = CONNECTIONROLE_NONE) { |
| 167 | JsepTransportDescription jsep_description; |
| 168 | jsep_description.rtcp_mux_enabled = rtcp_mux_enabled; |
| 169 | |
| 170 | std::unique_ptr<rtc::SSLFingerprint> fingerprint; |
| 171 | if (cert) { |
Steve Anton | 4905edb | 2018-10-15 19:27:44 -0700 | [diff] [blame] | 172 | fingerprint = rtc::SSLFingerprint::CreateFromCertificate(*cert); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 173 | } |
| 174 | jsep_description.transport_desc = |
| 175 | TransportDescription(std::vector<std::string>(), ufrag, pwd, |
| 176 | ICEMODE_FULL, role, fingerprint.get()); |
| 177 | return jsep_description; |
| 178 | } |
| 179 | |
| 180 | Candidate CreateCandidate(int component) { |
| 181 | Candidate c; |
| 182 | c.set_address(rtc::SocketAddress("192.168.1.1", 8000)); |
| 183 | c.set_component(component); |
| 184 | c.set_protocol(UDP_PROTOCOL_NAME); |
| 185 | c.set_priority(1); |
| 186 | return c; |
| 187 | } |
| 188 | |
| 189 | void OnRtcpMuxActive() { signal_rtcp_mux_active_received_ = true; } |
| 190 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 191 | std::unique_ptr<JsepTransport> jsep_transport_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 192 | bool signal_rtcp_mux_active_received_ = false; |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 193 | // The SrtpTransport is owned by `jsep_transport_`. Keep a raw pointer here |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 194 | // for testing. |
| 195 | webrtc::SrtpTransport* sdes_transport_ = nullptr; |
Jonas Oreland | ed99dae | 2022-03-09 09:28:10 +0100 | [diff] [blame] | 196 | |
| 197 | webrtc::test::ScopedKeyValueConfig field_trials_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | // The parameterized tests cover both cases when RTCP mux is enable and |
| 201 | // disabled. |
| 202 | class JsepTransport2WithRtcpMux : public JsepTransport2Test, |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 203 | public ::testing::WithParamInterface<bool> {}; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 204 | |
| 205 | // This test verifies the ICE parameters are properly applied to the transports. |
| 206 | TEST_P(JsepTransport2WithRtcpMux, SetIceParameters) { |
| 207 | bool rtcp_mux_enabled = GetParam(); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 208 | jsep_transport_ = CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 209 | |
| 210 | JsepTransportDescription jsep_description; |
| 211 | jsep_description.transport_desc = TransportDescription(kIceUfrag1, kIcePwd1); |
| 212 | jsep_description.rtcp_mux_enabled = rtcp_mux_enabled; |
| 213 | ASSERT_TRUE( |
| 214 | jsep_transport_ |
| 215 | ->SetLocalJsepTransportDescription(jsep_description, SdpType::kOffer) |
| 216 | .ok()); |
| 217 | auto fake_ice_transport = static_cast<FakeIceTransport*>( |
| 218 | jsep_transport_->rtp_dtls_transport()->ice_transport()); |
| 219 | EXPECT_EQ(ICEMODE_FULL, fake_ice_transport->remote_ice_mode()); |
| 220 | EXPECT_EQ(kIceUfrag1, fake_ice_transport->ice_ufrag()); |
| 221 | EXPECT_EQ(kIcePwd1, fake_ice_transport->ice_pwd()); |
| 222 | if (!rtcp_mux_enabled) { |
| 223 | fake_ice_transport = static_cast<FakeIceTransport*>( |
| 224 | jsep_transport_->rtcp_dtls_transport()->ice_transport()); |
| 225 | ASSERT_TRUE(fake_ice_transport); |
| 226 | EXPECT_EQ(ICEMODE_FULL, fake_ice_transport->remote_ice_mode()); |
| 227 | EXPECT_EQ(kIceUfrag1, fake_ice_transport->ice_ufrag()); |
| 228 | EXPECT_EQ(kIcePwd1, fake_ice_transport->ice_pwd()); |
| 229 | } |
| 230 | |
| 231 | jsep_description.transport_desc = TransportDescription(kIceUfrag2, kIcePwd2); |
| 232 | ASSERT_TRUE(jsep_transport_ |
| 233 | ->SetRemoteJsepTransportDescription(jsep_description, |
| 234 | SdpType::kAnswer) |
| 235 | .ok()); |
| 236 | fake_ice_transport = static_cast<FakeIceTransport*>( |
| 237 | jsep_transport_->rtp_dtls_transport()->ice_transport()); |
| 238 | EXPECT_EQ(ICEMODE_FULL, fake_ice_transport->remote_ice_mode()); |
| 239 | EXPECT_EQ(kIceUfrag2, fake_ice_transport->remote_ice_ufrag()); |
| 240 | EXPECT_EQ(kIcePwd2, fake_ice_transport->remote_ice_pwd()); |
| 241 | if (!rtcp_mux_enabled) { |
| 242 | fake_ice_transport = static_cast<FakeIceTransport*>( |
| 243 | jsep_transport_->rtcp_dtls_transport()->ice_transport()); |
| 244 | ASSERT_TRUE(fake_ice_transport); |
| 245 | EXPECT_EQ(ICEMODE_FULL, fake_ice_transport->remote_ice_mode()); |
| 246 | EXPECT_EQ(kIceUfrag2, fake_ice_transport->remote_ice_ufrag()); |
| 247 | EXPECT_EQ(kIcePwd2, fake_ice_transport->remote_ice_pwd()); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | // Similarly, test DTLS parameters are properly applied to the transports. |
| 252 | TEST_P(JsepTransport2WithRtcpMux, SetDtlsParameters) { |
| 253 | bool rtcp_mux_enabled = GetParam(); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 254 | jsep_transport_ = CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 255 | |
| 256 | // Create certificates. |
| 257 | rtc::scoped_refptr<rtc::RTCCertificate> local_cert = |
Harald Alvestrand | 8515d5a | 2020-03-20 22:51:32 +0100 | [diff] [blame] | 258 | rtc::RTCCertificate::Create( |
| 259 | rtc::SSLIdentity::Create("local", rtc::KT_DEFAULT)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 260 | rtc::scoped_refptr<rtc::RTCCertificate> remote_cert = |
Harald Alvestrand | 8515d5a | 2020-03-20 22:51:32 +0100 | [diff] [blame] | 261 | rtc::RTCCertificate::Create( |
| 262 | rtc::SSLIdentity::Create("remote", rtc::KT_DEFAULT)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 263 | jsep_transport_->SetLocalCertificate(local_cert); |
| 264 | |
| 265 | // Apply offer. |
| 266 | JsepTransportDescription local_description = |
| 267 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag1, kIcePwd1, |
| 268 | local_cert, CONNECTIONROLE_ACTPASS); |
| 269 | ASSERT_TRUE( |
| 270 | jsep_transport_ |
| 271 | ->SetLocalJsepTransportDescription(local_description, SdpType::kOffer) |
| 272 | .ok()); |
| 273 | // Apply Answer. |
| 274 | JsepTransportDescription remote_description = |
| 275 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag2, kIcePwd2, |
| 276 | remote_cert, CONNECTIONROLE_ACTIVE); |
| 277 | ASSERT_TRUE(jsep_transport_ |
| 278 | ->SetRemoteJsepTransportDescription(remote_description, |
| 279 | SdpType::kAnswer) |
| 280 | .ok()); |
| 281 | |
| 282 | // Verify that SSL role and remote fingerprint were set correctly based on |
| 283 | // transport descriptions. |
| 284 | auto role = jsep_transport_->GetDtlsRole(); |
| 285 | ASSERT_TRUE(role); |
| 286 | EXPECT_EQ(rtc::SSL_SERVER, role); // Because remote description was "active". |
| 287 | auto fake_dtls = |
| 288 | static_cast<FakeDtlsTransport*>(jsep_transport_->rtp_dtls_transport()); |
| 289 | EXPECT_EQ(remote_description.transport_desc.identity_fingerprint->ToString(), |
| 290 | fake_dtls->dtls_fingerprint().ToString()); |
| 291 | |
| 292 | if (!rtcp_mux_enabled) { |
| 293 | auto fake_rtcp_dtls = |
| 294 | static_cast<FakeDtlsTransport*>(jsep_transport_->rtcp_dtls_transport()); |
| 295 | EXPECT_EQ( |
| 296 | remote_description.transport_desc.identity_fingerprint->ToString(), |
| 297 | fake_rtcp_dtls->dtls_fingerprint().ToString()); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // Same as above test, but with remote transport description using |
| 302 | // CONNECTIONROLE_PASSIVE, expecting SSL_CLIENT role. |
| 303 | TEST_P(JsepTransport2WithRtcpMux, SetDtlsParametersWithPassiveAnswer) { |
| 304 | bool rtcp_mux_enabled = GetParam(); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 305 | jsep_transport_ = CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 306 | |
| 307 | // Create certificates. |
| 308 | rtc::scoped_refptr<rtc::RTCCertificate> local_cert = |
Harald Alvestrand | 8515d5a | 2020-03-20 22:51:32 +0100 | [diff] [blame] | 309 | rtc::RTCCertificate::Create( |
| 310 | rtc::SSLIdentity::Create("local", rtc::KT_DEFAULT)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 311 | rtc::scoped_refptr<rtc::RTCCertificate> remote_cert = |
Harald Alvestrand | 8515d5a | 2020-03-20 22:51:32 +0100 | [diff] [blame] | 312 | rtc::RTCCertificate::Create( |
| 313 | rtc::SSLIdentity::Create("remote", rtc::KT_DEFAULT)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 314 | jsep_transport_->SetLocalCertificate(local_cert); |
| 315 | |
| 316 | // Apply offer. |
| 317 | JsepTransportDescription local_description = |
| 318 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag1, kIcePwd1, |
| 319 | local_cert, CONNECTIONROLE_ACTPASS); |
| 320 | ASSERT_TRUE( |
| 321 | jsep_transport_ |
| 322 | ->SetLocalJsepTransportDescription(local_description, SdpType::kOffer) |
| 323 | .ok()); |
| 324 | // Apply Answer. |
| 325 | JsepTransportDescription remote_description = |
| 326 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag2, kIcePwd2, |
| 327 | remote_cert, CONNECTIONROLE_PASSIVE); |
| 328 | ASSERT_TRUE(jsep_transport_ |
| 329 | ->SetRemoteJsepTransportDescription(remote_description, |
| 330 | SdpType::kAnswer) |
| 331 | .ok()); |
| 332 | |
| 333 | // Verify that SSL role and remote fingerprint were set correctly based on |
| 334 | // transport descriptions. |
| 335 | auto role = jsep_transport_->GetDtlsRole(); |
| 336 | ASSERT_TRUE(role); |
| 337 | EXPECT_EQ(rtc::SSL_CLIENT, |
| 338 | role); // Because remote description was "passive". |
| 339 | auto fake_dtls = |
| 340 | static_cast<FakeDtlsTransport*>(jsep_transport_->rtp_dtls_transport()); |
| 341 | EXPECT_EQ(remote_description.transport_desc.identity_fingerprint->ToString(), |
| 342 | fake_dtls->dtls_fingerprint().ToString()); |
| 343 | |
| 344 | if (!rtcp_mux_enabled) { |
| 345 | auto fake_rtcp_dtls = |
| 346 | static_cast<FakeDtlsTransport*>(jsep_transport_->rtcp_dtls_transport()); |
| 347 | EXPECT_EQ( |
| 348 | remote_description.transport_desc.identity_fingerprint->ToString(), |
| 349 | fake_rtcp_dtls->dtls_fingerprint().ToString()); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | // Tests SetNeedsIceRestartFlag and need_ice_restart, ensuring needs_ice_restart |
| 354 | // only starts returning "false" once an ICE restart has been initiated. |
| 355 | TEST_P(JsepTransport2WithRtcpMux, NeedsIceRestart) { |
| 356 | bool rtcp_mux_enabled = GetParam(); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 357 | jsep_transport_ = CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 358 | |
| 359 | // Use the same JsepTransportDescription for both offer and answer. |
| 360 | JsepTransportDescription description; |
| 361 | description.transport_desc = TransportDescription(kIceUfrag1, kIcePwd1); |
| 362 | ASSERT_TRUE( |
| 363 | jsep_transport_ |
| 364 | ->SetLocalJsepTransportDescription(description, SdpType::kOffer) |
| 365 | .ok()); |
| 366 | ASSERT_TRUE( |
| 367 | jsep_transport_ |
| 368 | ->SetRemoteJsepTransportDescription(description, SdpType::kAnswer) |
| 369 | .ok()); |
| 370 | // Flag initially should be false. |
| 371 | EXPECT_FALSE(jsep_transport_->needs_ice_restart()); |
| 372 | |
| 373 | // After setting flag, it should be true. |
| 374 | jsep_transport_->SetNeedsIceRestartFlag(); |
| 375 | EXPECT_TRUE(jsep_transport_->needs_ice_restart()); |
| 376 | |
| 377 | ASSERT_TRUE( |
| 378 | jsep_transport_ |
| 379 | ->SetLocalJsepTransportDescription(description, SdpType::kOffer) |
| 380 | .ok()); |
| 381 | ASSERT_TRUE( |
| 382 | jsep_transport_ |
| 383 | ->SetRemoteJsepTransportDescription(description, SdpType::kAnswer) |
| 384 | .ok()); |
| 385 | EXPECT_TRUE(jsep_transport_->needs_ice_restart()); |
| 386 | |
| 387 | // Doing an offer/answer that restarts ICE should clear the flag. |
| 388 | description.transport_desc = TransportDescription(kIceUfrag2, kIcePwd2); |
| 389 | ASSERT_TRUE( |
| 390 | jsep_transport_ |
| 391 | ->SetLocalJsepTransportDescription(description, SdpType::kOffer) |
| 392 | .ok()); |
| 393 | ASSERT_TRUE( |
| 394 | jsep_transport_ |
| 395 | ->SetRemoteJsepTransportDescription(description, SdpType::kAnswer) |
| 396 | .ok()); |
| 397 | EXPECT_FALSE(jsep_transport_->needs_ice_restart()); |
| 398 | } |
| 399 | |
| 400 | TEST_P(JsepTransport2WithRtcpMux, GetStats) { |
| 401 | bool rtcp_mux_enabled = GetParam(); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 402 | jsep_transport_ = CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 403 | |
| 404 | size_t expected_stats_size = rtcp_mux_enabled ? 1u : 2u; |
| 405 | TransportStats stats; |
| 406 | EXPECT_TRUE(jsep_transport_->GetStats(&stats)); |
| 407 | EXPECT_EQ(expected_stats_size, stats.channel_stats.size()); |
| 408 | EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTP, stats.channel_stats[0].component); |
| 409 | if (!rtcp_mux_enabled) { |
| 410 | EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTCP, stats.channel_stats[1].component); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | // Tests that VerifyCertificateFingerprint only returns true when the |
| 415 | // certificate matches the fingerprint. |
| 416 | TEST_P(JsepTransport2WithRtcpMux, VerifyCertificateFingerprint) { |
| 417 | bool rtcp_mux_enabled = GetParam(); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 418 | jsep_transport_ = CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 419 | |
| 420 | EXPECT_FALSE( |
| 421 | jsep_transport_->VerifyCertificateFingerprint(nullptr, nullptr).ok()); |
| 422 | rtc::KeyType key_types[] = {rtc::KT_RSA, rtc::KT_ECDSA}; |
| 423 | |
| 424 | for (auto& key_type : key_types) { |
| 425 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
Harald Alvestrand | 8515d5a | 2020-03-20 22:51:32 +0100 | [diff] [blame] | 426 | rtc::RTCCertificate::Create( |
| 427 | rtc::SSLIdentity::Create("testing", key_type)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 428 | ASSERT_NE(nullptr, certificate); |
| 429 | |
| 430 | std::string digest_algorithm; |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 431 | ASSERT_TRUE(certificate->GetSSLCertificate().GetSignatureDigestAlgorithm( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 432 | &digest_algorithm)); |
| 433 | ASSERT_FALSE(digest_algorithm.empty()); |
Steve Anton | 4905edb | 2018-10-15 19:27:44 -0700 | [diff] [blame] | 434 | std::unique_ptr<rtc::SSLFingerprint> good_fingerprint = |
| 435 | rtc::SSLFingerprint::CreateUnique(digest_algorithm, |
| 436 | *certificate->identity()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 437 | ASSERT_NE(nullptr, good_fingerprint); |
| 438 | |
| 439 | EXPECT_TRUE(jsep_transport_ |
| 440 | ->VerifyCertificateFingerprint(certificate.get(), |
| 441 | good_fingerprint.get()) |
| 442 | .ok()); |
| 443 | EXPECT_FALSE(jsep_transport_ |
| 444 | ->VerifyCertificateFingerprint(certificate.get(), nullptr) |
| 445 | .ok()); |
| 446 | EXPECT_FALSE( |
| 447 | jsep_transport_ |
| 448 | ->VerifyCertificateFingerprint(nullptr, good_fingerprint.get()) |
| 449 | .ok()); |
| 450 | |
| 451 | rtc::SSLFingerprint bad_fingerprint = *good_fingerprint; |
| 452 | bad_fingerprint.digest.AppendData("0", 1); |
| 453 | EXPECT_FALSE( |
| 454 | jsep_transport_ |
| 455 | ->VerifyCertificateFingerprint(certificate.get(), &bad_fingerprint) |
| 456 | .ok()); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | // Tests the logic of DTLS role negotiation for an initial offer/answer. |
| 461 | TEST_P(JsepTransport2WithRtcpMux, ValidDtlsRoleNegotiation) { |
| 462 | bool rtcp_mux_enabled = GetParam(); |
| 463 | // Just use the same certificate for both sides; doesn't really matter in a |
| 464 | // non end-to-end test. |
| 465 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
Harald Alvestrand | 8515d5a | 2020-03-20 22:51:32 +0100 | [diff] [blame] | 466 | rtc::RTCCertificate::Create( |
| 467 | rtc::SSLIdentity::Create("testing", rtc::KT_ECDSA)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 468 | |
| 469 | JsepTransportDescription local_description = MakeJsepTransportDescription( |
| 470 | rtcp_mux_enabled, kIceUfrag1, kIcePwd1, certificate); |
| 471 | JsepTransportDescription remote_description = MakeJsepTransportDescription( |
| 472 | rtcp_mux_enabled, kIceUfrag2, kIcePwd2, certificate); |
| 473 | |
| 474 | // Parameters which set the SSL role to SSL_CLIENT. |
| 475 | NegotiateRoleParams valid_client_params[] = { |
| 476 | {CONNECTIONROLE_ACTIVE, CONNECTIONROLE_ACTPASS, SdpType::kAnswer, |
| 477 | SdpType::kOffer}, |
| 478 | {CONNECTIONROLE_ACTIVE, CONNECTIONROLE_ACTPASS, SdpType::kPrAnswer, |
| 479 | SdpType::kOffer}, |
| 480 | {CONNECTIONROLE_ACTPASS, CONNECTIONROLE_PASSIVE, SdpType::kOffer, |
| 481 | SdpType::kAnswer}, |
| 482 | {CONNECTIONROLE_ACTPASS, CONNECTIONROLE_PASSIVE, SdpType::kOffer, |
Harald Alvestrand | efece42 | 2021-08-19 09:12:51 +0000 | [diff] [blame] | 483 | SdpType::kPrAnswer}, |
| 484 | // Combinations permitted by RFC 8842 section 5.3 |
| 485 | {CONNECTIONROLE_ACTIVE, CONNECTIONROLE_PASSIVE, SdpType::kAnswer, |
| 486 | SdpType::kOffer}, |
| 487 | {CONNECTIONROLE_ACTIVE, CONNECTIONROLE_PASSIVE, SdpType::kPrAnswer, |
| 488 | SdpType::kOffer}, |
| 489 | }; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 490 | |
| 491 | for (auto& param : valid_client_params) { |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 492 | jsep_transport_ = |
| 493 | CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 494 | jsep_transport_->SetLocalCertificate(certificate); |
| 495 | |
| 496 | local_description.transport_desc.connection_role = param.local_role; |
| 497 | remote_description.transport_desc.connection_role = param.remote_role; |
| 498 | |
| 499 | // Set the offer first. |
| 500 | if (param.local_type == SdpType::kOffer) { |
| 501 | EXPECT_TRUE(jsep_transport_ |
| 502 | ->SetLocalJsepTransportDescription(local_description, |
| 503 | param.local_type) |
| 504 | .ok()); |
| 505 | EXPECT_TRUE(jsep_transport_ |
| 506 | ->SetRemoteJsepTransportDescription(remote_description, |
| 507 | param.remote_type) |
| 508 | .ok()); |
| 509 | } else { |
| 510 | EXPECT_TRUE(jsep_transport_ |
| 511 | ->SetRemoteJsepTransportDescription(remote_description, |
| 512 | param.remote_type) |
| 513 | .ok()); |
| 514 | EXPECT_TRUE(jsep_transport_ |
| 515 | ->SetLocalJsepTransportDescription(local_description, |
| 516 | param.local_type) |
| 517 | .ok()); |
| 518 | } |
| 519 | EXPECT_EQ(rtc::SSL_CLIENT, *jsep_transport_->GetDtlsRole()); |
| 520 | } |
| 521 | |
| 522 | // Parameters which set the SSL role to SSL_SERVER. |
| 523 | NegotiateRoleParams valid_server_params[] = { |
| 524 | {CONNECTIONROLE_PASSIVE, CONNECTIONROLE_ACTPASS, SdpType::kAnswer, |
| 525 | SdpType::kOffer}, |
| 526 | {CONNECTIONROLE_PASSIVE, CONNECTIONROLE_ACTPASS, SdpType::kPrAnswer, |
| 527 | SdpType::kOffer}, |
| 528 | {CONNECTIONROLE_ACTPASS, CONNECTIONROLE_ACTIVE, SdpType::kOffer, |
| 529 | SdpType::kAnswer}, |
| 530 | {CONNECTIONROLE_ACTPASS, CONNECTIONROLE_ACTIVE, SdpType::kOffer, |
Harald Alvestrand | efece42 | 2021-08-19 09:12:51 +0000 | [diff] [blame] | 531 | SdpType::kPrAnswer}, |
| 532 | // Combinations permitted by RFC 8842 section 5.3 |
| 533 | {CONNECTIONROLE_PASSIVE, CONNECTIONROLE_ACTIVE, SdpType::kPrAnswer, |
| 534 | SdpType::kOffer}, |
| 535 | }; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 536 | |
| 537 | for (auto& param : valid_server_params) { |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 538 | jsep_transport_ = |
| 539 | CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 540 | jsep_transport_->SetLocalCertificate(certificate); |
| 541 | |
| 542 | local_description.transport_desc.connection_role = param.local_role; |
| 543 | remote_description.transport_desc.connection_role = param.remote_role; |
| 544 | |
| 545 | // Set the offer first. |
| 546 | if (param.local_type == SdpType::kOffer) { |
| 547 | EXPECT_TRUE(jsep_transport_ |
| 548 | ->SetLocalJsepTransportDescription(local_description, |
| 549 | param.local_type) |
| 550 | .ok()); |
| 551 | EXPECT_TRUE(jsep_transport_ |
| 552 | ->SetRemoteJsepTransportDescription(remote_description, |
| 553 | param.remote_type) |
| 554 | .ok()); |
| 555 | } else { |
| 556 | EXPECT_TRUE(jsep_transport_ |
| 557 | ->SetRemoteJsepTransportDescription(remote_description, |
| 558 | param.remote_type) |
| 559 | .ok()); |
| 560 | EXPECT_TRUE(jsep_transport_ |
| 561 | ->SetLocalJsepTransportDescription(local_description, |
| 562 | param.local_type) |
| 563 | .ok()); |
| 564 | } |
| 565 | EXPECT_EQ(rtc::SSL_SERVER, *jsep_transport_->GetDtlsRole()); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | // Tests the logic of DTLS role negotiation for an initial offer/answer. |
| 570 | TEST_P(JsepTransport2WithRtcpMux, InvalidDtlsRoleNegotiation) { |
| 571 | bool rtcp_mux_enabled = GetParam(); |
| 572 | // Just use the same certificate for both sides; doesn't really matter in a |
| 573 | // non end-to-end test. |
| 574 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
Harald Alvestrand | 8515d5a | 2020-03-20 22:51:32 +0100 | [diff] [blame] | 575 | rtc::RTCCertificate::Create( |
| 576 | rtc::SSLIdentity::Create("testing", rtc::KT_ECDSA)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 577 | |
| 578 | JsepTransportDescription local_description = MakeJsepTransportDescription( |
| 579 | rtcp_mux_enabled, kIceUfrag1, kIcePwd1, certificate); |
| 580 | JsepTransportDescription remote_description = MakeJsepTransportDescription( |
| 581 | rtcp_mux_enabled, kIceUfrag2, kIcePwd2, certificate); |
| 582 | |
| 583 | NegotiateRoleParams duplicate_params[] = { |
| 584 | {CONNECTIONROLE_ACTIVE, CONNECTIONROLE_ACTIVE, SdpType::kAnswer, |
| 585 | SdpType::kOffer}, |
| 586 | {CONNECTIONROLE_ACTPASS, CONNECTIONROLE_ACTPASS, SdpType::kAnswer, |
| 587 | SdpType::kOffer}, |
| 588 | {CONNECTIONROLE_PASSIVE, CONNECTIONROLE_PASSIVE, SdpType::kAnswer, |
| 589 | SdpType::kOffer}, |
| 590 | {CONNECTIONROLE_ACTIVE, CONNECTIONROLE_ACTIVE, SdpType::kPrAnswer, |
| 591 | SdpType::kOffer}, |
| 592 | {CONNECTIONROLE_ACTPASS, CONNECTIONROLE_ACTPASS, SdpType::kPrAnswer, |
| 593 | SdpType::kOffer}, |
| 594 | {CONNECTIONROLE_PASSIVE, CONNECTIONROLE_PASSIVE, SdpType::kPrAnswer, |
| 595 | SdpType::kOffer}, |
| 596 | {CONNECTIONROLE_ACTIVE, CONNECTIONROLE_ACTIVE, SdpType::kOffer, |
| 597 | SdpType::kAnswer}, |
| 598 | {CONNECTIONROLE_ACTPASS, CONNECTIONROLE_ACTPASS, SdpType::kOffer, |
| 599 | SdpType::kAnswer}, |
| 600 | {CONNECTIONROLE_PASSIVE, CONNECTIONROLE_PASSIVE, SdpType::kOffer, |
| 601 | SdpType::kAnswer}, |
| 602 | {CONNECTIONROLE_ACTIVE, CONNECTIONROLE_ACTIVE, SdpType::kOffer, |
| 603 | SdpType::kPrAnswer}, |
| 604 | {CONNECTIONROLE_ACTPASS, CONNECTIONROLE_ACTPASS, SdpType::kOffer, |
| 605 | SdpType::kPrAnswer}, |
| 606 | {CONNECTIONROLE_PASSIVE, CONNECTIONROLE_PASSIVE, SdpType::kOffer, |
| 607 | SdpType::kPrAnswer}}; |
| 608 | |
| 609 | for (auto& param : duplicate_params) { |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 610 | jsep_transport_ = |
| 611 | CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 612 | jsep_transport_->SetLocalCertificate(certificate); |
| 613 | |
| 614 | local_description.transport_desc.connection_role = param.local_role; |
| 615 | remote_description.transport_desc.connection_role = param.remote_role; |
| 616 | |
| 617 | if (param.local_type == SdpType::kOffer) { |
| 618 | EXPECT_TRUE(jsep_transport_ |
| 619 | ->SetLocalJsepTransportDescription(local_description, |
| 620 | param.local_type) |
| 621 | .ok()); |
| 622 | EXPECT_FALSE(jsep_transport_ |
| 623 | ->SetRemoteJsepTransportDescription(remote_description, |
| 624 | param.remote_type) |
| 625 | .ok()); |
| 626 | } else { |
| 627 | EXPECT_TRUE(jsep_transport_ |
| 628 | ->SetRemoteJsepTransportDescription(remote_description, |
| 629 | param.remote_type) |
| 630 | .ok()); |
| 631 | EXPECT_FALSE(jsep_transport_ |
| 632 | ->SetLocalJsepTransportDescription(local_description, |
| 633 | param.local_type) |
| 634 | .ok()); |
| 635 | } |
| 636 | } |
| 637 | |
Harald Alvestrand | efece42 | 2021-08-19 09:12:51 +0000 | [diff] [blame] | 638 | // Invalid parameters due to the offerer not using a role consistent with the |
| 639 | // state |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 640 | NegotiateRoleParams offerer_without_actpass_params[] = { |
Harald Alvestrand | efece42 | 2021-08-19 09:12:51 +0000 | [diff] [blame] | 641 | // Cannot use ACTPASS in an answer |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 642 | {CONNECTIONROLE_ACTPASS, CONNECTIONROLE_PASSIVE, SdpType::kAnswer, |
| 643 | SdpType::kOffer}, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 644 | {CONNECTIONROLE_ACTPASS, CONNECTIONROLE_PASSIVE, SdpType::kPrAnswer, |
| 645 | SdpType::kOffer}, |
Harald Alvestrand | efece42 | 2021-08-19 09:12:51 +0000 | [diff] [blame] | 646 | // Cannot send ACTIVE or PASSIVE in an offer (must handle, must not send) |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 647 | {CONNECTIONROLE_ACTIVE, CONNECTIONROLE_PASSIVE, SdpType::kOffer, |
| 648 | SdpType::kAnswer}, |
| 649 | {CONNECTIONROLE_PASSIVE, CONNECTIONROLE_ACTIVE, SdpType::kOffer, |
| 650 | SdpType::kAnswer}, |
| 651 | {CONNECTIONROLE_PASSIVE, CONNECTIONROLE_ACTPASS, SdpType::kOffer, |
| 652 | SdpType::kAnswer}, |
| 653 | {CONNECTIONROLE_ACTIVE, CONNECTIONROLE_PASSIVE, SdpType::kOffer, |
| 654 | SdpType::kPrAnswer}, |
| 655 | {CONNECTIONROLE_PASSIVE, CONNECTIONROLE_ACTIVE, SdpType::kOffer, |
| 656 | SdpType::kPrAnswer}, |
| 657 | {CONNECTIONROLE_PASSIVE, CONNECTIONROLE_ACTPASS, SdpType::kOffer, |
| 658 | SdpType::kPrAnswer}}; |
| 659 | |
| 660 | for (auto& param : offerer_without_actpass_params) { |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 661 | jsep_transport_ = |
| 662 | CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 663 | jsep_transport_->SetLocalCertificate(certificate); |
| 664 | |
| 665 | local_description.transport_desc.connection_role = param.local_role; |
| 666 | remote_description.transport_desc.connection_role = param.remote_role; |
| 667 | |
| 668 | if (param.local_type == SdpType::kOffer) { |
| 669 | EXPECT_TRUE(jsep_transport_ |
| 670 | ->SetLocalJsepTransportDescription(local_description, |
| 671 | param.local_type) |
Harald Alvestrand | efece42 | 2021-08-19 09:12:51 +0000 | [diff] [blame] | 672 | .ok()) |
| 673 | << param; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 674 | EXPECT_FALSE(jsep_transport_ |
| 675 | ->SetRemoteJsepTransportDescription(remote_description, |
| 676 | param.remote_type) |
Harald Alvestrand | efece42 | 2021-08-19 09:12:51 +0000 | [diff] [blame] | 677 | .ok()) |
| 678 | << param; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 679 | } else { |
| 680 | EXPECT_TRUE(jsep_transport_ |
| 681 | ->SetRemoteJsepTransportDescription(remote_description, |
| 682 | param.remote_type) |
Harald Alvestrand | efece42 | 2021-08-19 09:12:51 +0000 | [diff] [blame] | 683 | .ok()) |
| 684 | << param; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 685 | EXPECT_FALSE(jsep_transport_ |
| 686 | ->SetLocalJsepTransportDescription(local_description, |
| 687 | param.local_type) |
Harald Alvestrand | efece42 | 2021-08-19 09:12:51 +0000 | [diff] [blame] | 688 | .ok()) |
| 689 | << param; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 694 | INSTANTIATE_TEST_SUITE_P(JsepTransport2Test, |
| 695 | JsepTransport2WithRtcpMux, |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 696 | ::testing::Bool()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 697 | |
| 698 | // Test that a reoffer in the opposite direction is successful as long as the |
| 699 | // role isn't changing. Doesn't test every possible combination like the test |
| 700 | // above. |
| 701 | TEST_F(JsepTransport2Test, ValidDtlsReofferFromAnswerer) { |
| 702 | // Just use the same certificate for both sides; doesn't really matter in a |
| 703 | // non end-to-end test. |
| 704 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
Harald Alvestrand | 8515d5a | 2020-03-20 22:51:32 +0100 | [diff] [blame] | 705 | rtc::RTCCertificate::Create( |
| 706 | rtc::SSLIdentity::Create("testing", rtc::KT_ECDSA)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 707 | bool rtcp_mux_enabled = true; |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 708 | jsep_transport_ = CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 709 | jsep_transport_->SetLocalCertificate(certificate); |
| 710 | |
| 711 | JsepTransportDescription local_offer = |
| 712 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag1, kIcePwd1, |
| 713 | certificate, CONNECTIONROLE_ACTPASS); |
| 714 | JsepTransportDescription remote_answer = |
| 715 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag2, kIcePwd2, |
| 716 | certificate, CONNECTIONROLE_ACTIVE); |
| 717 | |
| 718 | EXPECT_TRUE( |
| 719 | jsep_transport_ |
| 720 | ->SetLocalJsepTransportDescription(local_offer, SdpType::kOffer) |
| 721 | .ok()); |
| 722 | EXPECT_TRUE( |
| 723 | jsep_transport_ |
| 724 | ->SetRemoteJsepTransportDescription(remote_answer, SdpType::kAnswer) |
| 725 | .ok()); |
| 726 | |
| 727 | // We were actpass->active previously, now in the other direction it's |
| 728 | // actpass->passive. |
| 729 | JsepTransportDescription remote_offer = |
| 730 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag2, kIcePwd2, |
| 731 | certificate, CONNECTIONROLE_ACTPASS); |
| 732 | JsepTransportDescription local_answer = |
| 733 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag1, kIcePwd1, |
| 734 | certificate, CONNECTIONROLE_PASSIVE); |
| 735 | |
| 736 | EXPECT_TRUE( |
| 737 | jsep_transport_ |
| 738 | ->SetRemoteJsepTransportDescription(remote_offer, SdpType::kOffer) |
| 739 | .ok()); |
| 740 | EXPECT_TRUE( |
| 741 | jsep_transport_ |
| 742 | ->SetLocalJsepTransportDescription(local_answer, SdpType::kAnswer) |
| 743 | .ok()); |
| 744 | } |
| 745 | |
| 746 | // Test that a reoffer in the opposite direction fails if the role changes. |
| 747 | // Inverse of test above. |
| 748 | TEST_F(JsepTransport2Test, InvalidDtlsReofferFromAnswerer) { |
| 749 | // Just use the same certificate for both sides; doesn't really matter in a |
| 750 | // non end-to-end test. |
| 751 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
Harald Alvestrand | 8515d5a | 2020-03-20 22:51:32 +0100 | [diff] [blame] | 752 | rtc::RTCCertificate::Create( |
| 753 | rtc::SSLIdentity::Create("testing", rtc::KT_ECDSA)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 754 | bool rtcp_mux_enabled = true; |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 755 | jsep_transport_ = CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 756 | jsep_transport_->SetLocalCertificate(certificate); |
| 757 | |
| 758 | JsepTransportDescription local_offer = |
| 759 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag1, kIcePwd1, |
| 760 | certificate, CONNECTIONROLE_ACTPASS); |
| 761 | JsepTransportDescription remote_answer = |
| 762 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag2, kIcePwd2, |
| 763 | certificate, CONNECTIONROLE_ACTIVE); |
| 764 | |
| 765 | EXPECT_TRUE( |
| 766 | jsep_transport_ |
| 767 | ->SetLocalJsepTransportDescription(local_offer, SdpType::kOffer) |
| 768 | .ok()); |
| 769 | EXPECT_TRUE( |
| 770 | jsep_transport_ |
| 771 | ->SetRemoteJsepTransportDescription(remote_answer, SdpType::kAnswer) |
| 772 | .ok()); |
| 773 | |
| 774 | // Changing role to passive here isn't allowed. Though for some reason this |
| 775 | // only fails in SetLocalTransportDescription. |
| 776 | JsepTransportDescription remote_offer = |
| 777 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag2, kIcePwd2, |
| 778 | certificate, CONNECTIONROLE_PASSIVE); |
| 779 | JsepTransportDescription local_answer = |
| 780 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag1, kIcePwd1, |
| 781 | certificate, CONNECTIONROLE_ACTIVE); |
| 782 | |
| 783 | EXPECT_TRUE( |
| 784 | jsep_transport_ |
| 785 | ->SetRemoteJsepTransportDescription(remote_offer, SdpType::kOffer) |
| 786 | .ok()); |
| 787 | EXPECT_FALSE( |
| 788 | jsep_transport_ |
| 789 | ->SetLocalJsepTransportDescription(local_answer, SdpType::kAnswer) |
| 790 | .ok()); |
| 791 | } |
| 792 | |
| 793 | // Test that a remote offer with the current negotiated role can be accepted. |
| 794 | // This is allowed by dtls-sdp, though we'll never generate such an offer, |
| 795 | // since JSEP requires generating "actpass". |
| 796 | TEST_F(JsepTransport2Test, RemoteOfferWithCurrentNegotiatedDtlsRole) { |
| 797 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
Harald Alvestrand | 8515d5a | 2020-03-20 22:51:32 +0100 | [diff] [blame] | 798 | rtc::RTCCertificate::Create( |
| 799 | rtc::SSLIdentity::Create("testing", rtc::KT_ECDSA)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 800 | bool rtcp_mux_enabled = true; |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 801 | jsep_transport_ = CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 802 | jsep_transport_->SetLocalCertificate(certificate); |
| 803 | |
| 804 | JsepTransportDescription remote_desc = |
| 805 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag1, kIcePwd1, |
| 806 | certificate, CONNECTIONROLE_ACTPASS); |
| 807 | JsepTransportDescription local_desc = |
| 808 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag2, kIcePwd2, |
| 809 | certificate, CONNECTIONROLE_ACTIVE); |
| 810 | |
| 811 | // Normal initial offer/answer with "actpass" in the offer and "active" in |
| 812 | // the answer. |
| 813 | ASSERT_TRUE( |
| 814 | jsep_transport_ |
| 815 | ->SetRemoteJsepTransportDescription(remote_desc, SdpType::kOffer) |
| 816 | .ok()); |
| 817 | ASSERT_TRUE( |
| 818 | jsep_transport_ |
| 819 | ->SetLocalJsepTransportDescription(local_desc, SdpType::kAnswer) |
| 820 | .ok()); |
| 821 | |
| 822 | // Sanity check that role was actually negotiated. |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 823 | absl::optional<rtc::SSLRole> role = jsep_transport_->GetDtlsRole(); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 824 | ASSERT_TRUE(role); |
| 825 | EXPECT_EQ(rtc::SSL_CLIENT, *role); |
| 826 | |
| 827 | // Subsequent offer with current negotiated role of "passive". |
| 828 | remote_desc.transport_desc.connection_role = CONNECTIONROLE_PASSIVE; |
| 829 | EXPECT_TRUE( |
| 830 | jsep_transport_ |
| 831 | ->SetRemoteJsepTransportDescription(remote_desc, SdpType::kOffer) |
| 832 | .ok()); |
| 833 | EXPECT_TRUE( |
| 834 | jsep_transport_ |
| 835 | ->SetLocalJsepTransportDescription(local_desc, SdpType::kAnswer) |
| 836 | .ok()); |
| 837 | } |
| 838 | |
| 839 | // Test that a remote offer with the inverse of the current negotiated DTLS |
| 840 | // role is rejected. |
| 841 | TEST_F(JsepTransport2Test, RemoteOfferThatChangesNegotiatedDtlsRole) { |
| 842 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
Harald Alvestrand | 8515d5a | 2020-03-20 22:51:32 +0100 | [diff] [blame] | 843 | rtc::RTCCertificate::Create( |
| 844 | rtc::SSLIdentity::Create("testing", rtc::KT_ECDSA)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 845 | bool rtcp_mux_enabled = true; |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 846 | jsep_transport_ = CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 847 | jsep_transport_->SetLocalCertificate(certificate); |
| 848 | |
| 849 | JsepTransportDescription remote_desc = |
| 850 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag1, kIcePwd1, |
| 851 | certificate, CONNECTIONROLE_ACTPASS); |
| 852 | JsepTransportDescription local_desc = |
| 853 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag2, kIcePwd2, |
| 854 | certificate, CONNECTIONROLE_ACTIVE); |
| 855 | |
| 856 | // Normal initial offer/answer with "actpass" in the offer and "active" in |
| 857 | // the answer. |
| 858 | ASSERT_TRUE( |
| 859 | jsep_transport_ |
| 860 | ->SetRemoteJsepTransportDescription(remote_desc, SdpType::kOffer) |
| 861 | .ok()); |
| 862 | ASSERT_TRUE( |
| 863 | jsep_transport_ |
| 864 | ->SetLocalJsepTransportDescription(local_desc, SdpType::kAnswer) |
| 865 | .ok()); |
| 866 | |
| 867 | // Sanity check that role was actually negotiated. |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 868 | absl::optional<rtc::SSLRole> role = jsep_transport_->GetDtlsRole(); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 869 | ASSERT_TRUE(role); |
| 870 | EXPECT_EQ(rtc::SSL_CLIENT, *role); |
| 871 | |
| 872 | // Subsequent offer with current negotiated role of "passive". |
| 873 | remote_desc.transport_desc.connection_role = CONNECTIONROLE_ACTIVE; |
| 874 | EXPECT_TRUE( |
| 875 | jsep_transport_ |
| 876 | ->SetRemoteJsepTransportDescription(remote_desc, SdpType::kOffer) |
| 877 | .ok()); |
| 878 | EXPECT_FALSE( |
| 879 | jsep_transport_ |
| 880 | ->SetLocalJsepTransportDescription(local_desc, SdpType::kAnswer) |
| 881 | .ok()); |
| 882 | } |
| 883 | |
| 884 | // Testing that a legacy client that doesn't use the setup attribute will be |
| 885 | // interpreted as having an active role. |
| 886 | TEST_F(JsepTransport2Test, DtlsSetupWithLegacyAsAnswerer) { |
| 887 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
Harald Alvestrand | 8515d5a | 2020-03-20 22:51:32 +0100 | [diff] [blame] | 888 | rtc::RTCCertificate::Create( |
| 889 | rtc::SSLIdentity::Create("testing", rtc::KT_ECDSA)); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 890 | bool rtcp_mux_enabled = true; |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 891 | jsep_transport_ = CreateJsepTransport2(rtcp_mux_enabled, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 892 | jsep_transport_->SetLocalCertificate(certificate); |
| 893 | |
| 894 | JsepTransportDescription remote_desc = |
| 895 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag1, kIcePwd1, |
| 896 | certificate, CONNECTIONROLE_ACTPASS); |
| 897 | JsepTransportDescription local_desc = |
| 898 | MakeJsepTransportDescription(rtcp_mux_enabled, kIceUfrag2, kIcePwd2, |
| 899 | certificate, CONNECTIONROLE_ACTIVE); |
| 900 | |
| 901 | local_desc.transport_desc.connection_role = CONNECTIONROLE_ACTPASS; |
| 902 | ASSERT_TRUE( |
| 903 | jsep_transport_ |
| 904 | ->SetLocalJsepTransportDescription(local_desc, SdpType::kOffer) |
| 905 | .ok()); |
| 906 | // Use CONNECTIONROLE_NONE to simulate legacy endpoint. |
| 907 | remote_desc.transport_desc.connection_role = CONNECTIONROLE_NONE; |
| 908 | ASSERT_TRUE( |
| 909 | jsep_transport_ |
| 910 | ->SetRemoteJsepTransportDescription(remote_desc, SdpType::kAnswer) |
| 911 | .ok()); |
| 912 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 913 | absl::optional<rtc::SSLRole> role = jsep_transport_->GetDtlsRole(); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 914 | ASSERT_TRUE(role); |
| 915 | // Since legacy answer ommitted setup atribute, and we offered actpass, we |
| 916 | // should act as passive (server). |
| 917 | EXPECT_EQ(rtc::SSL_SERVER, *role); |
| 918 | } |
| 919 | |
| 920 | // Tests that when the RTCP mux is successfully negotiated, the RTCP transport |
| 921 | // will be destroyed and the SignalRtpMuxActive will be fired. |
| 922 | TEST_F(JsepTransport2Test, RtcpMuxNegotiation) { |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 923 | jsep_transport_ = |
| 924 | CreateJsepTransport2(/*rtcp_mux_enabled=*/false, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 925 | JsepTransportDescription local_desc; |
| 926 | local_desc.rtcp_mux_enabled = true; |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 927 | ASSERT_NE(nullptr, jsep_transport_->rtcp_dtls_transport()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 928 | EXPECT_FALSE(signal_rtcp_mux_active_received_); |
| 929 | |
| 930 | // The remote side supports RTCP-mux. |
| 931 | JsepTransportDescription remote_desc; |
| 932 | remote_desc.rtcp_mux_enabled = true; |
| 933 | ASSERT_TRUE( |
| 934 | jsep_transport_ |
| 935 | ->SetLocalJsepTransportDescription(local_desc, SdpType::kOffer) |
| 936 | .ok()); |
| 937 | ASSERT_TRUE( |
| 938 | jsep_transport_ |
| 939 | ->SetRemoteJsepTransportDescription(remote_desc, SdpType::kAnswer) |
| 940 | .ok()); |
| 941 | |
| 942 | EXPECT_EQ(nullptr, jsep_transport_->rtcp_dtls_transport()); |
| 943 | EXPECT_TRUE(signal_rtcp_mux_active_received_); |
| 944 | |
| 945 | // The remote side doesn't support RTCP-mux. |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 946 | jsep_transport_ = |
| 947 | CreateJsepTransport2(/*rtcp_mux_enabled=*/false, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 948 | signal_rtcp_mux_active_received_ = false; |
| 949 | remote_desc.rtcp_mux_enabled = false; |
| 950 | ASSERT_TRUE( |
| 951 | jsep_transport_ |
| 952 | ->SetLocalJsepTransportDescription(local_desc, SdpType::kOffer) |
| 953 | .ok()); |
| 954 | ASSERT_TRUE( |
| 955 | jsep_transport_ |
| 956 | ->SetRemoteJsepTransportDescription(remote_desc, SdpType::kAnswer) |
| 957 | .ok()); |
| 958 | |
| 959 | EXPECT_NE(nullptr, jsep_transport_->rtcp_dtls_transport()); |
| 960 | EXPECT_FALSE(signal_rtcp_mux_active_received_); |
| 961 | } |
| 962 | |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 963 | TEST_F(JsepTransport2Test, SdesNegotiation) { |
| 964 | jsep_transport_ = |
| 965 | CreateJsepTransport2(/*rtcp_mux_enabled=*/true, SrtpMode::kSdes); |
| 966 | ASSERT_TRUE(sdes_transport_); |
| 967 | EXPECT_FALSE(sdes_transport_->IsSrtpActive()); |
| 968 | |
| 969 | JsepTransportDescription offer_desc; |
| 970 | offer_desc.cryptos.push_back(cricket::CryptoParams( |
| 971 | 1, rtc::kCsAesCm128HmacSha1_32, "inline:" + rtc::CreateRandomString(40), |
| 972 | std::string())); |
| 973 | ASSERT_TRUE( |
| 974 | jsep_transport_ |
| 975 | ->SetLocalJsepTransportDescription(offer_desc, SdpType::kOffer) |
| 976 | .ok()); |
| 977 | |
| 978 | JsepTransportDescription answer_desc; |
| 979 | answer_desc.cryptos.push_back(cricket::CryptoParams( |
| 980 | 1, rtc::kCsAesCm128HmacSha1_32, "inline:" + rtc::CreateRandomString(40), |
| 981 | std::string())); |
| 982 | ASSERT_TRUE( |
| 983 | jsep_transport_ |
| 984 | ->SetRemoteJsepTransportDescription(answer_desc, SdpType::kAnswer) |
| 985 | .ok()); |
| 986 | EXPECT_TRUE(sdes_transport_->IsSrtpActive()); |
| 987 | } |
| 988 | |
| 989 | TEST_F(JsepTransport2Test, SdesNegotiationWithEmptyCryptosInAnswer) { |
| 990 | jsep_transport_ = |
| 991 | CreateJsepTransport2(/*rtcp_mux_enabled=*/true, SrtpMode::kSdes); |
| 992 | ASSERT_TRUE(sdes_transport_); |
| 993 | EXPECT_FALSE(sdes_transport_->IsSrtpActive()); |
| 994 | |
| 995 | JsepTransportDescription offer_desc; |
| 996 | offer_desc.cryptos.push_back(cricket::CryptoParams( |
| 997 | 1, rtc::kCsAesCm128HmacSha1_32, "inline:" + rtc::CreateRandomString(40), |
| 998 | std::string())); |
| 999 | ASSERT_TRUE( |
| 1000 | jsep_transport_ |
| 1001 | ->SetLocalJsepTransportDescription(offer_desc, SdpType::kOffer) |
| 1002 | .ok()); |
| 1003 | |
| 1004 | JsepTransportDescription answer_desc; |
| 1005 | ASSERT_TRUE( |
| 1006 | jsep_transport_ |
| 1007 | ->SetRemoteJsepTransportDescription(answer_desc, SdpType::kAnswer) |
| 1008 | .ok()); |
| 1009 | // SRTP is not active because the crypto parameter is answer is empty. |
| 1010 | EXPECT_FALSE(sdes_transport_->IsSrtpActive()); |
| 1011 | } |
| 1012 | |
| 1013 | TEST_F(JsepTransport2Test, SdesNegotiationWithMismatchedCryptos) { |
| 1014 | jsep_transport_ = |
| 1015 | CreateJsepTransport2(/*rtcp_mux_enabled=*/true, SrtpMode::kSdes); |
| 1016 | ASSERT_TRUE(sdes_transport_); |
| 1017 | EXPECT_FALSE(sdes_transport_->IsSrtpActive()); |
| 1018 | |
| 1019 | JsepTransportDescription offer_desc; |
| 1020 | offer_desc.cryptos.push_back(cricket::CryptoParams( |
| 1021 | 1, rtc::kCsAesCm128HmacSha1_32, "inline:" + rtc::CreateRandomString(40), |
| 1022 | std::string())); |
| 1023 | ASSERT_TRUE( |
| 1024 | jsep_transport_ |
| 1025 | ->SetLocalJsepTransportDescription(offer_desc, SdpType::kOffer) |
| 1026 | .ok()); |
| 1027 | |
| 1028 | JsepTransportDescription answer_desc; |
| 1029 | answer_desc.cryptos.push_back(cricket::CryptoParams( |
| 1030 | 1, rtc::kCsAesCm128HmacSha1_80, "inline:" + rtc::CreateRandomString(40), |
| 1031 | std::string())); |
| 1032 | // Expected to fail because the crypto parameters don't match. |
| 1033 | ASSERT_FALSE( |
| 1034 | jsep_transport_ |
| 1035 | ->SetRemoteJsepTransportDescription(answer_desc, SdpType::kAnswer) |
| 1036 | .ok()); |
| 1037 | } |
| 1038 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 1039 | // Tests that the remote candidates can be added to the transports after both |
| 1040 | // local and remote descriptions are set. |
| 1041 | TEST_F(JsepTransport2Test, AddRemoteCandidates) { |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 1042 | jsep_transport_ = |
| 1043 | CreateJsepTransport2(/*rtcp_mux_enabled=*/true, SrtpMode::kDtlsSrtp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 1044 | auto fake_ice_transport = static_cast<FakeIceTransport*>( |
| 1045 | jsep_transport_->rtp_dtls_transport()->ice_transport()); |
| 1046 | |
| 1047 | Candidates candidates; |
| 1048 | candidates.push_back(CreateCandidate(/*COMPONENT_RTP*/ 1)); |
| 1049 | candidates.push_back(CreateCandidate(/*COMPONENT_RTP*/ 1)); |
| 1050 | |
| 1051 | JsepTransportDescription desc; |
| 1052 | ASSERT_TRUE( |
| 1053 | jsep_transport_->SetLocalJsepTransportDescription(desc, SdpType::kOffer) |
| 1054 | .ok()); |
| 1055 | // Expected to fail because the remote description is unset. |
| 1056 | EXPECT_FALSE(jsep_transport_->AddRemoteCandidates(candidates).ok()); |
| 1057 | |
| 1058 | ASSERT_TRUE( |
| 1059 | jsep_transport_->SetRemoteJsepTransportDescription(desc, SdpType::kAnswer) |
| 1060 | .ok()); |
| 1061 | EXPECT_EQ(0u, fake_ice_transport->remote_candidates().size()); |
| 1062 | EXPECT_TRUE(jsep_transport_->AddRemoteCandidates(candidates).ok()); |
| 1063 | EXPECT_EQ(candidates.size(), fake_ice_transport->remote_candidates().size()); |
| 1064 | } |
| 1065 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1066 | enum class Scenario { |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 1067 | kSdes, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1068 | kDtlsBeforeCallerSendOffer, |
| 1069 | kDtlsBeforeCallerSetAnswer, |
| 1070 | kDtlsAfterCallerSetAnswer, |
| 1071 | }; |
| 1072 | |
| 1073 | class JsepTransport2HeaderExtensionTest |
| 1074 | : public JsepTransport2Test, |
| 1075 | public ::testing::WithParamInterface<std::tuple<Scenario, bool>> { |
| 1076 | protected: |
| 1077 | JsepTransport2HeaderExtensionTest() {} |
| 1078 | |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 1079 | void CreateJsepTransportPair(SrtpMode mode) { |
| 1080 | jsep_transport1_ = CreateJsepTransport2(/*rtcp_mux_enabled=*/true, mode); |
| 1081 | jsep_transport2_ = CreateJsepTransport2(/*rtcp_mux_enabled=*/true, mode); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1082 | |
| 1083 | auto fake_dtls1 = |
| 1084 | static_cast<FakeDtlsTransport*>(jsep_transport1_->rtp_dtls_transport()); |
| 1085 | auto fake_dtls2 = |
| 1086 | static_cast<FakeDtlsTransport*>(jsep_transport2_->rtp_dtls_transport()); |
| 1087 | |
| 1088 | fake_dtls1->fake_ice_transport()->SignalReadPacket.connect( |
| 1089 | this, &JsepTransport2HeaderExtensionTest::OnReadPacket1); |
| 1090 | fake_dtls2->fake_ice_transport()->SignalReadPacket.connect( |
| 1091 | this, &JsepTransport2HeaderExtensionTest::OnReadPacket2); |
| 1092 | |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 1093 | if (mode == SrtpMode::kDtlsSrtp) { |
| 1094 | auto cert1 = rtc::RTCCertificate::Create( |
| 1095 | rtc::SSLIdentity::Create("session1", rtc::KT_DEFAULT)); |
| 1096 | jsep_transport1_->rtp_dtls_transport()->SetLocalCertificate(cert1); |
| 1097 | auto cert2 = rtc::RTCCertificate::Create( |
| 1098 | rtc::SSLIdentity::Create("session1", rtc::KT_DEFAULT)); |
| 1099 | jsep_transport2_->rtp_dtls_transport()->SetLocalCertificate(cert2); |
| 1100 | } |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | void OnReadPacket1(rtc::PacketTransportInternal* transport, |
| 1104 | const char* data, |
| 1105 | size_t size, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 1106 | const int64_t& /* packet_time_us */, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1107 | int flags) { |
| 1108 | RTC_LOG(LS_INFO) << "JsepTransport 1 Received a packet."; |
| 1109 | CompareHeaderExtensions( |
| 1110 | reinterpret_cast<const char*>(kPcmuFrameWithExtensions), |
| 1111 | sizeof(kPcmuFrameWithExtensions), data, size, recv_encrypted_headers1_, |
| 1112 | false); |
| 1113 | received_packet_count_++; |
| 1114 | } |
| 1115 | |
| 1116 | void OnReadPacket2(rtc::PacketTransportInternal* transport, |
| 1117 | const char* data, |
| 1118 | size_t size, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 1119 | const int64_t& /* packet_time_us */, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1120 | int flags) { |
| 1121 | RTC_LOG(LS_INFO) << "JsepTransport 2 Received a packet."; |
| 1122 | CompareHeaderExtensions( |
| 1123 | reinterpret_cast<const char*>(kPcmuFrameWithExtensions), |
| 1124 | sizeof(kPcmuFrameWithExtensions), data, size, recv_encrypted_headers2_, |
| 1125 | false); |
| 1126 | received_packet_count_++; |
| 1127 | } |
| 1128 | |
| 1129 | void ConnectTransport() { |
| 1130 | auto rtp_dtls_transport1 = |
| 1131 | static_cast<FakeDtlsTransport*>(jsep_transport1_->rtp_dtls_transport()); |
| 1132 | auto rtp_dtls_transport2 = |
| 1133 | static_cast<FakeDtlsTransport*>(jsep_transport2_->rtp_dtls_transport()); |
| 1134 | rtp_dtls_transport1->SetDestination(rtp_dtls_transport2); |
| 1135 | } |
| 1136 | |
| 1137 | int GetRtpAuthLen() { |
| 1138 | bool use_gcm = std::get<1>(GetParam()); |
| 1139 | if (use_gcm) { |
| 1140 | return 16; |
| 1141 | } |
| 1142 | return 10; |
| 1143 | } |
| 1144 | |
| 1145 | void TestSendRecvPacketWithEncryptedHeaderExtension() { |
| 1146 | TestOneWaySendRecvPacketWithEncryptedHeaderExtension( |
| 1147 | jsep_transport1_.get()); |
| 1148 | TestOneWaySendRecvPacketWithEncryptedHeaderExtension( |
| 1149 | jsep_transport2_.get()); |
| 1150 | } |
| 1151 | |
| 1152 | void TestOneWaySendRecvPacketWithEncryptedHeaderExtension( |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 1153 | JsepTransport* sender_transport) { |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1154 | size_t rtp_len = sizeof(kPcmuFrameWithExtensions); |
| 1155 | size_t packet_size = rtp_len + GetRtpAuthLen(); |
| 1156 | rtc::Buffer rtp_packet_buffer(packet_size); |
| 1157 | char* rtp_packet_data = rtp_packet_buffer.data<char>(); |
| 1158 | memcpy(rtp_packet_data, kPcmuFrameWithExtensions, rtp_len); |
| 1159 | // In order to be able to run this test function multiple times we can not |
| 1160 | // use the same sequence number twice. Increase the sequence number by one. |
| 1161 | rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_data) + 2, |
| 1162 | ++sequence_number_); |
| 1163 | rtc::CopyOnWriteBuffer rtp_packet(rtp_packet_data, rtp_len, packet_size); |
| 1164 | |
| 1165 | int packet_count_before = received_packet_count_; |
| 1166 | rtc::PacketOptions options; |
| 1167 | // Send a packet and verify that the packet can be successfully received and |
| 1168 | // decrypted. |
| 1169 | ASSERT_TRUE(sender_transport->rtp_transport()->SendRtpPacket( |
| 1170 | &rtp_packet, options, cricket::PF_SRTP_BYPASS)); |
| 1171 | EXPECT_EQ(packet_count_before + 1, received_packet_count_); |
| 1172 | } |
| 1173 | |
| 1174 | int sequence_number_ = 0; |
| 1175 | int received_packet_count_ = 0; |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 1176 | std::unique_ptr<JsepTransport> jsep_transport1_; |
| 1177 | std::unique_ptr<JsepTransport> jsep_transport2_; |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1178 | std::vector<int> recv_encrypted_headers1_; |
| 1179 | std::vector<int> recv_encrypted_headers2_; |
| 1180 | }; |
| 1181 | |
| 1182 | // Test that the encrypted header extension works and can be changed in |
| 1183 | // different scenarios. |
| 1184 | TEST_P(JsepTransport2HeaderExtensionTest, EncryptedHeaderExtensionNegotiation) { |
| 1185 | Scenario scenario = std::get<0>(GetParam()); |
| 1186 | bool use_gcm = std::get<1>(GetParam()); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 1187 | SrtpMode mode = SrtpMode ::kDtlsSrtp; |
| 1188 | if (scenario == Scenario::kSdes) { |
| 1189 | mode = SrtpMode::kSdes; |
| 1190 | } |
| 1191 | CreateJsepTransportPair(mode); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1192 | recv_encrypted_headers1_.push_back(kHeaderExtensionIDs[0]); |
| 1193 | recv_encrypted_headers2_.push_back(kHeaderExtensionIDs[1]); |
| 1194 | |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 1195 | cricket::CryptoParams sdes_param(1, rtc::kCsAesCm128HmacSha1_80, |
| 1196 | "inline:" + rtc::CreateRandomString(40), |
| 1197 | std::string()); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1198 | if (use_gcm) { |
| 1199 | auto fake_dtls1 = |
| 1200 | static_cast<FakeDtlsTransport*>(jsep_transport1_->rtp_dtls_transport()); |
| 1201 | auto fake_dtls2 = |
| 1202 | static_cast<FakeDtlsTransport*>(jsep_transport2_->rtp_dtls_transport()); |
| 1203 | |
Mirko Bonadei | 7750d80 | 2021-07-26 17:27:42 +0200 | [diff] [blame] | 1204 | fake_dtls1->SetSrtpCryptoSuite(rtc::kSrtpAeadAes256Gcm); |
| 1205 | fake_dtls2->SetSrtpCryptoSuite(rtc::kSrtpAeadAes256Gcm); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | if (scenario == Scenario::kDtlsBeforeCallerSendOffer) { |
| 1209 | ConnectTransport(); |
| 1210 | } |
| 1211 | |
| 1212 | JsepTransportDescription offer_desc; |
| 1213 | offer_desc.encrypted_header_extension_ids = recv_encrypted_headers1_; |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 1214 | if (scenario == Scenario::kSdes) { |
| 1215 | offer_desc.cryptos.push_back(sdes_param); |
| 1216 | } |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1217 | ASSERT_TRUE( |
| 1218 | jsep_transport1_ |
| 1219 | ->SetLocalJsepTransportDescription(offer_desc, SdpType::kOffer) |
| 1220 | .ok()); |
| 1221 | ASSERT_TRUE( |
| 1222 | jsep_transport2_ |
| 1223 | ->SetRemoteJsepTransportDescription(offer_desc, SdpType::kOffer) |
| 1224 | .ok()); |
| 1225 | |
| 1226 | JsepTransportDescription answer_desc; |
| 1227 | answer_desc.encrypted_header_extension_ids = recv_encrypted_headers2_; |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 1228 | if (scenario == Scenario::kSdes) { |
| 1229 | answer_desc.cryptos.push_back(sdes_param); |
| 1230 | } |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1231 | ASSERT_TRUE( |
| 1232 | jsep_transport2_ |
| 1233 | ->SetLocalJsepTransportDescription(answer_desc, SdpType::kAnswer) |
| 1234 | .ok()); |
| 1235 | |
| 1236 | if (scenario == Scenario::kDtlsBeforeCallerSetAnswer) { |
| 1237 | ConnectTransport(); |
| 1238 | // Sending packet from transport2 to transport1 should work when they are |
| 1239 | // partially configured. |
| 1240 | TestOneWaySendRecvPacketWithEncryptedHeaderExtension( |
| 1241 | /*sender_transport=*/jsep_transport2_.get()); |
| 1242 | } |
| 1243 | |
| 1244 | ASSERT_TRUE( |
| 1245 | jsep_transport1_ |
| 1246 | ->SetRemoteJsepTransportDescription(answer_desc, SdpType::kAnswer) |
| 1247 | .ok()); |
| 1248 | |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 1249 | if (scenario == Scenario::kDtlsAfterCallerSetAnswer || |
| 1250 | scenario == Scenario::kSdes) { |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1251 | ConnectTransport(); |
| 1252 | } |
| 1253 | EXPECT_TRUE(jsep_transport1_->rtp_transport()->IsSrtpActive()); |
| 1254 | EXPECT_TRUE(jsep_transport2_->rtp_transport()->IsSrtpActive()); |
| 1255 | TestSendRecvPacketWithEncryptedHeaderExtension(); |
| 1256 | |
| 1257 | // Change the encrypted header extension in a new offer/answer exchange. |
| 1258 | recv_encrypted_headers1_.clear(); |
| 1259 | recv_encrypted_headers2_.clear(); |
| 1260 | recv_encrypted_headers1_.push_back(kHeaderExtensionIDs[1]); |
| 1261 | recv_encrypted_headers2_.push_back(kHeaderExtensionIDs[0]); |
| 1262 | offer_desc.encrypted_header_extension_ids = recv_encrypted_headers1_; |
| 1263 | answer_desc.encrypted_header_extension_ids = recv_encrypted_headers2_; |
| 1264 | ASSERT_TRUE( |
| 1265 | jsep_transport1_ |
| 1266 | ->SetLocalJsepTransportDescription(offer_desc, SdpType::kOffer) |
| 1267 | .ok()); |
| 1268 | ASSERT_TRUE( |
| 1269 | jsep_transport2_ |
| 1270 | ->SetRemoteJsepTransportDescription(offer_desc, SdpType::kOffer) |
| 1271 | .ok()); |
| 1272 | ASSERT_TRUE( |
| 1273 | jsep_transport2_ |
| 1274 | ->SetLocalJsepTransportDescription(answer_desc, SdpType::kAnswer) |
| 1275 | .ok()); |
| 1276 | ASSERT_TRUE( |
| 1277 | jsep_transport1_ |
| 1278 | ->SetRemoteJsepTransportDescription(answer_desc, SdpType::kAnswer) |
| 1279 | .ok()); |
| 1280 | EXPECT_TRUE(jsep_transport1_->rtp_transport()->IsSrtpActive()); |
| 1281 | EXPECT_TRUE(jsep_transport2_->rtp_transport()->IsSrtpActive()); |
| 1282 | TestSendRecvPacketWithEncryptedHeaderExtension(); |
| 1283 | } |
| 1284 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 1285 | INSTANTIATE_TEST_SUITE_P( |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1286 | JsepTransport2Test, |
| 1287 | JsepTransport2HeaderExtensionTest, |
| 1288 | ::testing::Values( |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 1289 | std::make_tuple(Scenario::kSdes, false), |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1290 | std::make_tuple(Scenario::kDtlsBeforeCallerSendOffer, true), |
| 1291 | std::make_tuple(Scenario::kDtlsBeforeCallerSetAnswer, true), |
| 1292 | std::make_tuple(Scenario::kDtlsAfterCallerSetAnswer, true), |
| 1293 | std::make_tuple(Scenario::kDtlsBeforeCallerSendOffer, false), |
| 1294 | std::make_tuple(Scenario::kDtlsBeforeCallerSetAnswer, false), |
| 1295 | std::make_tuple(Scenario::kDtlsAfterCallerSetAnswer, false))); |
Jonas Oreland | 52aea5d | 2020-03-03 13:21:30 +0100 | [diff] [blame] | 1296 | |
| 1297 | // This test verifies the ICE parameters are properly applied to the transports. |
| 1298 | TEST_F(JsepTransport2Test, SetIceParametersWithRenomination) { |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 1299 | jsep_transport_ = |
| 1300 | CreateJsepTransport2(/* rtcp_mux_enabled= */ true, SrtpMode::kDtlsSrtp); |
Jonas Oreland | 52aea5d | 2020-03-03 13:21:30 +0100 | [diff] [blame] | 1301 | |
| 1302 | JsepTransportDescription jsep_description; |
| 1303 | jsep_description.transport_desc = TransportDescription(kIceUfrag1, kIcePwd1); |
| 1304 | jsep_description.transport_desc.AddOption(ICE_OPTION_RENOMINATION); |
| 1305 | ASSERT_TRUE( |
| 1306 | jsep_transport_ |
| 1307 | ->SetLocalJsepTransportDescription(jsep_description, SdpType::kOffer) |
| 1308 | .ok()); |
| 1309 | auto fake_ice_transport = static_cast<FakeIceTransport*>( |
| 1310 | jsep_transport_->rtp_dtls_transport()->ice_transport()); |
| 1311 | EXPECT_EQ(ICEMODE_FULL, fake_ice_transport->remote_ice_mode()); |
| 1312 | EXPECT_EQ(kIceUfrag1, fake_ice_transport->ice_ufrag()); |
| 1313 | EXPECT_EQ(kIcePwd1, fake_ice_transport->ice_pwd()); |
| 1314 | EXPECT_TRUE(fake_ice_transport->ice_parameters().renomination); |
| 1315 | |
| 1316 | jsep_description.transport_desc = TransportDescription(kIceUfrag2, kIcePwd2); |
| 1317 | jsep_description.transport_desc.AddOption(ICE_OPTION_RENOMINATION); |
| 1318 | ASSERT_TRUE(jsep_transport_ |
| 1319 | ->SetRemoteJsepTransportDescription(jsep_description, |
| 1320 | SdpType::kAnswer) |
| 1321 | .ok()); |
| 1322 | fake_ice_transport = static_cast<FakeIceTransport*>( |
| 1323 | jsep_transport_->rtp_dtls_transport()->ice_transport()); |
| 1324 | EXPECT_EQ(ICEMODE_FULL, fake_ice_transport->remote_ice_mode()); |
| 1325 | EXPECT_EQ(kIceUfrag2, fake_ice_transport->remote_ice_ufrag()); |
| 1326 | EXPECT_EQ(kIcePwd2, fake_ice_transport->remote_ice_pwd()); |
| 1327 | EXPECT_TRUE(fake_ice_transport->remote_ice_parameters().renomination); |
| 1328 | } |
| 1329 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 1330 | } // namespace |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 1331 | } // namespace cricket |