blob: a12d2c59040eba2d7586aa8ea6f3c7f27af3c8bc [file] [log] [blame]
zstein398c3fd2017-07-19 13:38:02 -07001/*
2 * Copyright 2017 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
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <string.h>
12#include <set>
Steve Anton36b29d12017-10-30 09:57:42 -070013#include <vector>
14
Karl Wiberg918f50c2018-07-05 11:40:33 +020015#include "absl/memory/memory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010016#include "call/rtp_demuxer.h"
Steve Anton10542f22019-01-11 09:11:00 -080017#include "media/base/fake_rtp.h"
18#include "p2p/base/dtls_transport_internal.h"
19#include "p2p/base/fake_packet_transport.h"
20#include "pc/srtp_transport.h"
21#include "pc/test/rtp_transport_test_util.h"
22#include "pc/test/srtp_test_util.h"
23#include "rtc_base/async_packet_socket.h"
24#include "rtc_base/byte_order.h"
Yves Gerey3e707812018-11-28 16:47:49 +010025#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "rtc_base/ssl_stream_adapter.h"
Yves Gerey3e707812018-11-28 16:47:49 +010027#include "rtc_base/third_party/sigslot/sigslot.h"
28#include "test/gtest.h"
Zhi Huangcf990f52017-09-22 12:12:30 -070029
30using rtc::kTestKey1;
31using rtc::kTestKey2;
32using rtc::kTestKeyLen;
33using rtc::SRTP_AEAD_AES_128_GCM;
zstein398c3fd2017-07-19 13:38:02 -070034
35namespace webrtc {
Zhi Huangcf990f52017-09-22 12:12:30 -070036static const uint8_t kTestKeyGcm128_1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ12";
37static const uint8_t kTestKeyGcm128_2[] = "21ZYXWVUTSRQPONMLKJIHGFEDCBA";
38static const int kTestKeyGcm128Len = 28; // 128 bits key + 96 bits salt.
39static const uint8_t kTestKeyGcm256_1[] =
40 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr";
41static const uint8_t kTestKeyGcm256_2[] =
42 "rqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA";
43static const int kTestKeyGcm256Len = 44; // 256 bits key + 96 bits salt.
zstein398c3fd2017-07-19 13:38:02 -070044
Mirko Bonadei6a489f22019-04-09 15:11:12 +020045class SrtpTransportTest : public ::testing::Test, public sigslot::has_slots<> {
Zhi Huangcf990f52017-09-22 12:12:30 -070046 protected:
47 SrtpTransportTest() {
48 bool rtcp_mux_enabled = true;
zstein398c3fd2017-07-19 13:38:02 -070049
Zhi Huangcf990f52017-09-22 12:12:30 -070050 rtp_packet_transport1_ =
Karl Wiberg918f50c2018-07-05 11:40:33 +020051 absl::make_unique<rtc::FakePacketTransport>("fake_packet_transport1");
Zhi Huangcf990f52017-09-22 12:12:30 -070052 rtp_packet_transport2_ =
Karl Wiberg918f50c2018-07-05 11:40:33 +020053 absl::make_unique<rtc::FakePacketTransport>("fake_packet_transport2");
zstein398c3fd2017-07-19 13:38:02 -070054
Zhi Huangcf990f52017-09-22 12:12:30 -070055 bool asymmetric = false;
56 rtp_packet_transport1_->SetDestination(rtp_packet_transport2_.get(),
57 asymmetric);
zstein398c3fd2017-07-19 13:38:02 -070058
Karl Wiberg918f50c2018-07-05 11:40:33 +020059 srtp_transport1_ = absl::make_unique<SrtpTransport>(rtcp_mux_enabled);
60 srtp_transport2_ = absl::make_unique<SrtpTransport>(rtcp_mux_enabled);
Zhi Huangcf990f52017-09-22 12:12:30 -070061
Zhi Huang365381f2018-04-13 16:44:34 -070062 srtp_transport1_->SetRtpPacketTransport(rtp_packet_transport1_.get());
63 srtp_transport2_->SetRtpPacketTransport(rtp_packet_transport2_.get());
Zhi Huangcf990f52017-09-22 12:12:30 -070064
Zhi Huang365381f2018-04-13 16:44:34 -070065 srtp_transport1_->SignalRtcpPacketReceived.connect(
66 &rtp_sink1_, &TransportObserver::OnRtcpPacketReceived);
67 srtp_transport2_->SignalRtcpPacketReceived.connect(
68 &rtp_sink2_, &TransportObserver::OnRtcpPacketReceived);
69
70 RtpDemuxerCriteria demuxer_criteria;
71 // 0x00 is the payload type used in kPcmuFrame.
72 demuxer_criteria.payload_types = {0x00};
73
74 srtp_transport1_->RegisterRtpDemuxerSink(demuxer_criteria, &rtp_sink1_);
75 srtp_transport2_->RegisterRtpDemuxerSink(demuxer_criteria, &rtp_sink2_);
zstein398c3fd2017-07-19 13:38:02 -070076 }
Zhi Huangcf990f52017-09-22 12:12:30 -070077
Zhi Huang365381f2018-04-13 16:44:34 -070078 ~SrtpTransportTest() {
79 if (srtp_transport1_) {
80 srtp_transport1_->UnregisterRtpDemuxerSink(&rtp_sink1_);
81 }
82 if (srtp_transport2_) {
83 srtp_transport2_->UnregisterRtpDemuxerSink(&rtp_sink2_);
84 }
Zhi Huangcf990f52017-09-22 12:12:30 -070085 }
86
87 // With external auth enabled, SRTP doesn't write the auth tag and
88 // unprotect would fail. Check accessing the information about the
89 // tag instead, similar to what the actual code would do that relies
90 // on external auth.
91 void TestRtpAuthParams(SrtpTransport* transport, const std::string& cs) {
92 int overhead;
93 EXPECT_TRUE(transport->GetSrtpOverhead(&overhead));
94 switch (rtc::SrtpCryptoSuiteFromName(cs)) {
95 case rtc::SRTP_AES128_CM_SHA1_32:
96 EXPECT_EQ(32 / 8, overhead); // 32-bit tag.
97 break;
98 case rtc::SRTP_AES128_CM_SHA1_80:
99 EXPECT_EQ(80 / 8, overhead); // 80-bit tag.
100 break;
101 default:
102 RTC_NOTREACHED();
103 break;
104 }
105
106 uint8_t* auth_key = nullptr;
107 int key_len = 0;
108 int tag_len = 0;
109 EXPECT_TRUE(transport->GetRtpAuthParams(&auth_key, &key_len, &tag_len));
110 EXPECT_NE(nullptr, auth_key);
111 EXPECT_EQ(160 / 8, key_len); // Length of SHA-1 is 160 bits.
112 EXPECT_EQ(overhead, tag_len);
113 }
114
115 void TestSendRecvRtpPacket(const std::string& cipher_suite_name) {
116 size_t rtp_len = sizeof(kPcmuFrame);
117 size_t packet_size = rtp_len + rtc::rtp_auth_tag_len(cipher_suite_name);
118 rtc::Buffer rtp_packet_buffer(packet_size);
119 char* rtp_packet_data = rtp_packet_buffer.data<char>();
120 memcpy(rtp_packet_data, kPcmuFrame, rtp_len);
121 // In order to be able to run this test function multiple times we can not
122 // use the same sequence number twice. Increase the sequence number by one.
123 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_data) + 2,
124 ++sequence_number_);
125 rtc::CopyOnWriteBuffer rtp_packet1to2(rtp_packet_data, rtp_len,
126 packet_size);
127 rtc::CopyOnWriteBuffer rtp_packet2to1(rtp_packet_data, rtp_len,
128 packet_size);
129
130 char original_rtp_data[sizeof(kPcmuFrame)];
131 memcpy(original_rtp_data, rtp_packet_data, rtp_len);
132
133 rtc::PacketOptions options;
134 // Send a packet from |srtp_transport1_| to |srtp_transport2_| and verify
135 // that the packet can be successfully received and decrypted.
136 ASSERT_TRUE(srtp_transport1_->SendRtpPacket(&rtp_packet1to2, options,
137 cricket::PF_SRTP_BYPASS));
138 if (srtp_transport1_->IsExternalAuthActive()) {
139 TestRtpAuthParams(srtp_transport1_.get(), cipher_suite_name);
140 } else {
Zhi Huang365381f2018-04-13 16:44:34 -0700141 ASSERT_TRUE(rtp_sink2_.last_recv_rtp_packet().data());
142 EXPECT_EQ(0, memcmp(rtp_sink2_.last_recv_rtp_packet().data(),
143 original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700144 // Get the encrypted packet from underneath packet transport and verify
145 // the data is actually encrypted.
146 auto fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>(
147 srtp_transport1_->rtp_packet_transport());
Steve Anton36b29d12017-10-30 09:57:42 -0700148 EXPECT_NE(0, memcmp(fake_rtp_packet_transport->last_sent_packet()->data(),
149 original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700150 }
151
152 // Do the same thing in the opposite direction;
153 ASSERT_TRUE(srtp_transport2_->SendRtpPacket(&rtp_packet2to1, options,
154 cricket::PF_SRTP_BYPASS));
155 if (srtp_transport2_->IsExternalAuthActive()) {
156 TestRtpAuthParams(srtp_transport2_.get(), cipher_suite_name);
157 } else {
Zhi Huang365381f2018-04-13 16:44:34 -0700158 ASSERT_TRUE(rtp_sink1_.last_recv_rtp_packet().data());
159 EXPECT_EQ(0, memcmp(rtp_sink1_.last_recv_rtp_packet().data(),
160 original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700161 auto fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>(
162 srtp_transport2_->rtp_packet_transport());
Steve Anton36b29d12017-10-30 09:57:42 -0700163 EXPECT_NE(0, memcmp(fake_rtp_packet_transport->last_sent_packet()->data(),
164 original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700165 }
166 }
167
168 void TestSendRecvRtcpPacket(const std::string& cipher_suite_name) {
Zhi Huang365381f2018-04-13 16:44:34 -0700169 size_t rtcp_len = sizeof(::kRtcpReport);
Zhi Huangcf990f52017-09-22 12:12:30 -0700170 size_t packet_size =
171 rtcp_len + 4 + rtc::rtcp_auth_tag_len(cipher_suite_name);
172 rtc::Buffer rtcp_packet_buffer(packet_size);
173 char* rtcp_packet_data = rtcp_packet_buffer.data<char>();
Zhi Huang365381f2018-04-13 16:44:34 -0700174 memcpy(rtcp_packet_data, ::kRtcpReport, rtcp_len);
Zhi Huangcf990f52017-09-22 12:12:30 -0700175
176 rtc::CopyOnWriteBuffer rtcp_packet1to2(rtcp_packet_data, rtcp_len,
177 packet_size);
178 rtc::CopyOnWriteBuffer rtcp_packet2to1(rtcp_packet_data, rtcp_len,
179 packet_size);
180
181 rtc::PacketOptions options;
182 // Send a packet from |srtp_transport1_| to |srtp_transport2_| and verify
183 // that the packet can be successfully received and decrypted.
184 ASSERT_TRUE(srtp_transport1_->SendRtcpPacket(&rtcp_packet1to2, options,
185 cricket::PF_SRTP_BYPASS));
Zhi Huang365381f2018-04-13 16:44:34 -0700186 ASSERT_TRUE(rtp_sink2_.last_recv_rtcp_packet().data());
187 EXPECT_EQ(0, memcmp(rtp_sink2_.last_recv_rtcp_packet().data(),
188 rtcp_packet_data, rtcp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700189 // Get the encrypted packet from underneath packet transport and verify the
190 // data is actually encrypted.
191 auto fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>(
192 srtp_transport1_->rtp_packet_transport());
Steve Anton36b29d12017-10-30 09:57:42 -0700193 EXPECT_NE(0, memcmp(fake_rtp_packet_transport->last_sent_packet()->data(),
194 rtcp_packet_data, rtcp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700195
196 // Do the same thing in the opposite direction;
197 ASSERT_TRUE(srtp_transport2_->SendRtcpPacket(&rtcp_packet2to1, options,
198 cricket::PF_SRTP_BYPASS));
Zhi Huang365381f2018-04-13 16:44:34 -0700199 ASSERT_TRUE(rtp_sink1_.last_recv_rtcp_packet().data());
200 EXPECT_EQ(0, memcmp(rtp_sink1_.last_recv_rtcp_packet().data(),
201 rtcp_packet_data, rtcp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700202 fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>(
203 srtp_transport2_->rtp_packet_transport());
Steve Anton36b29d12017-10-30 09:57:42 -0700204 EXPECT_NE(0, memcmp(fake_rtp_packet_transport->last_sent_packet()->data(),
205 rtcp_packet_data, rtcp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700206 }
207
208 void TestSendRecvPacket(bool enable_external_auth,
209 int cs,
210 const uint8_t* key1,
211 int key1_len,
212 const uint8_t* key2,
213 int key2_len,
214 const std::string& cipher_suite_name) {
215 EXPECT_EQ(key1_len, key2_len);
216 EXPECT_EQ(cipher_suite_name, rtc::SrtpCryptoSuiteToName(cs));
217 if (enable_external_auth) {
218 srtp_transport1_->EnableExternalAuth();
219 srtp_transport2_->EnableExternalAuth();
220 }
Zhi Huangc99b6c72017-11-10 16:44:46 -0800221 std::vector<int> extension_ids;
222 EXPECT_TRUE(srtp_transport1_->SetRtpParams(
223 cs, key1, key1_len, extension_ids, cs, key2, key2_len, extension_ids));
224 EXPECT_TRUE(srtp_transport2_->SetRtpParams(
225 cs, key2, key2_len, extension_ids, cs, key1, key1_len, extension_ids));
226 EXPECT_TRUE(srtp_transport1_->SetRtcpParams(
227 cs, key1, key1_len, extension_ids, cs, key2, key2_len, extension_ids));
228 EXPECT_TRUE(srtp_transport2_->SetRtcpParams(
229 cs, key2, key2_len, extension_ids, cs, key1, key1_len, extension_ids));
Zhi Huange830e682018-03-30 10:48:35 -0700230 EXPECT_TRUE(srtp_transport1_->IsSrtpActive());
231 EXPECT_TRUE(srtp_transport2_->IsSrtpActive());
Zhi Huangcf990f52017-09-22 12:12:30 -0700232 if (rtc::IsGcmCryptoSuite(cs)) {
233 EXPECT_FALSE(srtp_transport1_->IsExternalAuthActive());
234 EXPECT_FALSE(srtp_transport2_->IsExternalAuthActive());
235 } else if (enable_external_auth) {
236 EXPECT_TRUE(srtp_transport1_->IsExternalAuthActive());
237 EXPECT_TRUE(srtp_transport2_->IsExternalAuthActive());
238 }
239 TestSendRecvRtpPacket(cipher_suite_name);
240 TestSendRecvRtcpPacket(cipher_suite_name);
241 }
242
243 void TestSendRecvPacketWithEncryptedHeaderExtension(
244 const std::string& cs,
245 const std::vector<int>& encrypted_header_ids) {
246 size_t rtp_len = sizeof(kPcmuFrameWithExtensions);
247 size_t packet_size = rtp_len + rtc::rtp_auth_tag_len(cs);
248 rtc::Buffer rtp_packet_buffer(packet_size);
249 char* rtp_packet_data = rtp_packet_buffer.data<char>();
250 memcpy(rtp_packet_data, kPcmuFrameWithExtensions, rtp_len);
251 // In order to be able to run this test function multiple times we can not
252 // use the same sequence number twice. Increase the sequence number by one.
253 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_data) + 2,
254 ++sequence_number_);
255 rtc::CopyOnWriteBuffer rtp_packet1to2(rtp_packet_data, rtp_len,
256 packet_size);
257 rtc::CopyOnWriteBuffer rtp_packet2to1(rtp_packet_data, rtp_len,
258 packet_size);
259
260 char original_rtp_data[sizeof(kPcmuFrameWithExtensions)];
261 memcpy(original_rtp_data, rtp_packet_data, rtp_len);
262
263 rtc::PacketOptions options;
264 // Send a packet from |srtp_transport1_| to |srtp_transport2_| and verify
265 // that the packet can be successfully received and decrypted.
266 ASSERT_TRUE(srtp_transport1_->SendRtpPacket(&rtp_packet1to2, options,
267 cricket::PF_SRTP_BYPASS));
Zhi Huang365381f2018-04-13 16:44:34 -0700268 ASSERT_TRUE(rtp_sink2_.last_recv_rtp_packet().data());
269 EXPECT_EQ(0, memcmp(rtp_sink2_.last_recv_rtp_packet().data(),
270 original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700271 // Get the encrypted packet from underneath packet transport and verify the
272 // data and header extension are actually encrypted.
273 auto fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>(
274 srtp_transport1_->rtp_packet_transport());
Steve Anton36b29d12017-10-30 09:57:42 -0700275 EXPECT_NE(0, memcmp(fake_rtp_packet_transport->last_sent_packet()->data(),
276 original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700277 CompareHeaderExtensions(
278 reinterpret_cast<const char*>(
279 fake_rtp_packet_transport->last_sent_packet()->data()),
280 fake_rtp_packet_transport->last_sent_packet()->size(),
281 original_rtp_data, rtp_len, encrypted_header_ids, false);
282
283 // Do the same thing in the opposite direction;
284 ASSERT_TRUE(srtp_transport2_->SendRtpPacket(&rtp_packet2to1, options,
285 cricket::PF_SRTP_BYPASS));
Zhi Huang365381f2018-04-13 16:44:34 -0700286 ASSERT_TRUE(rtp_sink1_.last_recv_rtp_packet().data());
287 EXPECT_EQ(0, memcmp(rtp_sink1_.last_recv_rtp_packet().data(),
288 original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700289 fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>(
290 srtp_transport2_->rtp_packet_transport());
Steve Anton36b29d12017-10-30 09:57:42 -0700291 EXPECT_NE(0, memcmp(fake_rtp_packet_transport->last_sent_packet()->data(),
292 original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700293 CompareHeaderExtensions(
294 reinterpret_cast<const char*>(
295 fake_rtp_packet_transport->last_sent_packet()->data()),
296 fake_rtp_packet_transport->last_sent_packet()->size(),
297 original_rtp_data, rtp_len, encrypted_header_ids, false);
298 }
299
300 void TestSendRecvEncryptedHeaderExtension(int cs,
301 const uint8_t* key1,
302 int key1_len,
303 const uint8_t* key2,
304 int key2_len,
305 const std::string& cs_name) {
306 std::vector<int> encrypted_headers;
Zhi Huangf2d7beb2017-11-20 14:35:11 -0800307 encrypted_headers.push_back(kHeaderExtensionIDs[0]);
Zhi Huangcf990f52017-09-22 12:12:30 -0700308 // Don't encrypt header ids 2 and 3.
Zhi Huangf2d7beb2017-11-20 14:35:11 -0800309 encrypted_headers.push_back(kHeaderExtensionIDs[1]);
Zhi Huangcf990f52017-09-22 12:12:30 -0700310 EXPECT_EQ(key1_len, key2_len);
311 EXPECT_EQ(cs_name, rtc::SrtpCryptoSuiteToName(cs));
Zhi Huangc99b6c72017-11-10 16:44:46 -0800312 EXPECT_TRUE(srtp_transport1_->SetRtpParams(cs, key1, key1_len,
313 encrypted_headers, cs, key2,
314 key2_len, encrypted_headers));
315 EXPECT_TRUE(srtp_transport2_->SetRtpParams(cs, key2, key2_len,
316 encrypted_headers, cs, key1,
317 key1_len, encrypted_headers));
Zhi Huange830e682018-03-30 10:48:35 -0700318 EXPECT_TRUE(srtp_transport1_->IsSrtpActive());
319 EXPECT_TRUE(srtp_transport2_->IsSrtpActive());
Zhi Huangcf990f52017-09-22 12:12:30 -0700320 EXPECT_FALSE(srtp_transport1_->IsExternalAuthActive());
321 EXPECT_FALSE(srtp_transport2_->IsExternalAuthActive());
322 TestSendRecvPacketWithEncryptedHeaderExtension(cs_name, encrypted_headers);
323 }
324
325 std::unique_ptr<SrtpTransport> srtp_transport1_;
326 std::unique_ptr<SrtpTransport> srtp_transport2_;
327
328 std::unique_ptr<rtc::FakePacketTransport> rtp_packet_transport1_;
329 std::unique_ptr<rtc::FakePacketTransport> rtp_packet_transport2_;
330
Zhi Huang365381f2018-04-13 16:44:34 -0700331 TransportObserver rtp_sink1_;
332 TransportObserver rtp_sink2_;
333
Zhi Huangcf990f52017-09-22 12:12:30 -0700334 int sequence_number_ = 0;
zstein398c3fd2017-07-19 13:38:02 -0700335};
336
Zhi Huangcf990f52017-09-22 12:12:30 -0700337class SrtpTransportTestWithExternalAuth
338 : public SrtpTransportTest,
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200339 public ::testing::WithParamInterface<bool> {};
zstein398c3fd2017-07-19 13:38:02 -0700340
Zhi Huangcf990f52017-09-22 12:12:30 -0700341TEST_P(SrtpTransportTestWithExternalAuth,
342 SendAndRecvPacket_AES_CM_128_HMAC_SHA1_80) {
343 bool enable_external_auth = GetParam();
344 TestSendRecvPacket(enable_external_auth, rtc::SRTP_AES128_CM_SHA1_80,
345 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen,
346 rtc::CS_AES_CM_128_HMAC_SHA1_80);
zstein398c3fd2017-07-19 13:38:02 -0700347}
348
Zhi Huangcf990f52017-09-22 12:12:30 -0700349TEST_F(SrtpTransportTest,
350 SendAndRecvPacketWithHeaderExtension_AES_CM_128_HMAC_SHA1_80) {
351 TestSendRecvEncryptedHeaderExtension(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1,
352 kTestKeyLen, kTestKey2, kTestKeyLen,
353 rtc::CS_AES_CM_128_HMAC_SHA1_80);
354}
zstein398c3fd2017-07-19 13:38:02 -0700355
Zhi Huangcf990f52017-09-22 12:12:30 -0700356TEST_P(SrtpTransportTestWithExternalAuth,
357 SendAndRecvPacket_AES_CM_128_HMAC_SHA1_32) {
358 bool enable_external_auth = GetParam();
359 TestSendRecvPacket(enable_external_auth, rtc::SRTP_AES128_CM_SHA1_32,
360 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen,
361 rtc::CS_AES_CM_128_HMAC_SHA1_32);
362}
zstein398c3fd2017-07-19 13:38:02 -0700363
Zhi Huangcf990f52017-09-22 12:12:30 -0700364TEST_F(SrtpTransportTest,
365 SendAndRecvPacketWithHeaderExtension_AES_CM_128_HMAC_SHA1_32) {
366 TestSendRecvEncryptedHeaderExtension(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1,
367 kTestKeyLen, kTestKey2, kTestKeyLen,
368 rtc::CS_AES_CM_128_HMAC_SHA1_32);
369}
zstein398c3fd2017-07-19 13:38:02 -0700370
Zhi Huangcf990f52017-09-22 12:12:30 -0700371TEST_P(SrtpTransportTestWithExternalAuth,
372 SendAndRecvPacket_SRTP_AEAD_AES_128_GCM) {
373 bool enable_external_auth = GetParam();
374 TestSendRecvPacket(enable_external_auth, rtc::SRTP_AEAD_AES_128_GCM,
375 kTestKeyGcm128_1, kTestKeyGcm128Len, kTestKeyGcm128_2,
376 kTestKeyGcm128Len, rtc::CS_AEAD_AES_128_GCM);
377}
zstein398c3fd2017-07-19 13:38:02 -0700378
Zhi Huangcf990f52017-09-22 12:12:30 -0700379TEST_F(SrtpTransportTest,
380 SendAndRecvPacketWithHeaderExtension_SRTP_AEAD_AES_128_GCM) {
381 TestSendRecvEncryptedHeaderExtension(
382 rtc::SRTP_AEAD_AES_128_GCM, kTestKeyGcm128_1, kTestKeyGcm128Len,
383 kTestKeyGcm128_2, kTestKeyGcm128Len, rtc::CS_AEAD_AES_128_GCM);
384}
385
386TEST_P(SrtpTransportTestWithExternalAuth,
387 SendAndRecvPacket_SRTP_AEAD_AES_256_GCM) {
388 bool enable_external_auth = GetParam();
389 TestSendRecvPacket(enable_external_auth, rtc::SRTP_AEAD_AES_256_GCM,
390 kTestKeyGcm256_1, kTestKeyGcm256Len, kTestKeyGcm256_2,
391 kTestKeyGcm256Len, rtc::CS_AEAD_AES_256_GCM);
392}
393
394TEST_F(SrtpTransportTest,
395 SendAndRecvPacketWithHeaderExtension_SRTP_AEAD_AES_256_GCM) {
396 TestSendRecvEncryptedHeaderExtension(
397 rtc::SRTP_AEAD_AES_256_GCM, kTestKeyGcm256_1, kTestKeyGcm256Len,
398 kTestKeyGcm256_2, kTestKeyGcm256Len, rtc::CS_AEAD_AES_256_GCM);
399}
400
401// Run all tests both with and without external auth enabled.
Mirko Bonadeic84f6612019-01-31 12:20:57 +0100402INSTANTIATE_TEST_SUITE_P(ExternalAuth,
403 SrtpTransportTestWithExternalAuth,
404 ::testing::Values(true, false));
Zhi Huangcf990f52017-09-22 12:12:30 -0700405
406// Test directly setting the params with bogus keys.
407TEST_F(SrtpTransportTest, TestSetParamsKeyTooShort) {
Zhi Huangc99b6c72017-11-10 16:44:46 -0800408 std::vector<int> extension_ids;
Zhi Huangcf990f52017-09-22 12:12:30 -0700409 EXPECT_FALSE(srtp_transport1_->SetRtpParams(
Zhi Huangc99b6c72017-11-10 16:44:46 -0800410 rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen - 1, extension_ids,
411 rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen - 1, extension_ids));
Zhi Huangcf990f52017-09-22 12:12:30 -0700412 EXPECT_FALSE(srtp_transport1_->SetRtcpParams(
Zhi Huangc99b6c72017-11-10 16:44:46 -0800413 rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen - 1, extension_ids,
414 rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen - 1, extension_ids));
zstein398c3fd2017-07-19 13:38:02 -0700415}
416
417} // namespace webrtc