blob: d93ea131e281f147c273d0ef484caca2442253e4 [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
Steve Anton36b29d12017-10-30 09:57:42 -070011#include <vector>
12
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "pc/srtptransport.h"
zstein398c3fd2017-07-19 13:38:02 -070014
Zhi Huangcf990f52017-09-22 12:12:30 -070015#include "media/base/fakertp.h"
16#include "p2p/base/dtlstransportinternal.h"
17#include "p2p/base/fakepackettransport.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "pc/rtptransport.h"
19#include "pc/rtptransporttestutil.h"
Zhi Huangcf990f52017-09-22 12:12:30 -070020#include "pc/srtptestutil.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "rtc_base/asyncpacketsocket.h"
22#include "rtc_base/gunit.h"
23#include "rtc_base/ptr_util.h"
Zhi Huangcf990f52017-09-22 12:12:30 -070024#include "rtc_base/sslstreamadapter.h"
25
26using rtc::kTestKey1;
27using rtc::kTestKey2;
28using rtc::kTestKeyLen;
29using rtc::SRTP_AEAD_AES_128_GCM;
zstein398c3fd2017-07-19 13:38:02 -070030
31namespace webrtc {
Zhi Huangcf990f52017-09-22 12:12:30 -070032static const uint8_t kTestKeyGcm128_1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ12";
33static const uint8_t kTestKeyGcm128_2[] = "21ZYXWVUTSRQPONMLKJIHGFEDCBA";
34static const int kTestKeyGcm128Len = 28; // 128 bits key + 96 bits salt.
35static const uint8_t kTestKeyGcm256_1[] =
36 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr";
37static const uint8_t kTestKeyGcm256_2[] =
38 "rqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA";
39static const int kTestKeyGcm256Len = 44; // 256 bits key + 96 bits salt.
zstein398c3fd2017-07-19 13:38:02 -070040
Zhi Huangcf990f52017-09-22 12:12:30 -070041class SrtpTransportTest : public testing::Test, public sigslot::has_slots<> {
42 protected:
43 SrtpTransportTest() {
44 bool rtcp_mux_enabled = true;
45 auto rtp_transport1 = rtc::MakeUnique<RtpTransport>(rtcp_mux_enabled);
46 auto rtp_transport2 = rtc::MakeUnique<RtpTransport>(rtcp_mux_enabled);
zstein398c3fd2017-07-19 13:38:02 -070047
Zhi Huangcf990f52017-09-22 12:12:30 -070048 rtp_packet_transport1_ =
49 rtc::MakeUnique<rtc::FakePacketTransport>("fake_packet_transport1");
50 rtp_packet_transport2_ =
51 rtc::MakeUnique<rtc::FakePacketTransport>("fake_packet_transport2");
zstein398c3fd2017-07-19 13:38:02 -070052
Zhi Huangcf990f52017-09-22 12:12:30 -070053 bool asymmetric = false;
54 rtp_packet_transport1_->SetDestination(rtp_packet_transport2_.get(),
55 asymmetric);
zstein398c3fd2017-07-19 13:38:02 -070056
Zhi Huangcf990f52017-09-22 12:12:30 -070057 rtp_transport1->SetRtpPacketTransport(rtp_packet_transport1_.get());
58 rtp_transport2->SetRtpPacketTransport(rtp_packet_transport2_.get());
59
60 // Add payload type for RTP packet and RTCP packet.
61 rtp_transport1->AddHandledPayloadType(0x00);
62 rtp_transport2->AddHandledPayloadType(0x00);
63 rtp_transport1->AddHandledPayloadType(0xc9);
64 rtp_transport2->AddHandledPayloadType(0xc9);
65
66 srtp_transport1_ =
67 rtc::MakeUnique<SrtpTransport>(std::move(rtp_transport1), "content");
68 srtp_transport2_ =
69 rtc::MakeUnique<SrtpTransport>(std::move(rtp_transport2), "content");
70
71 srtp_transport1_->SignalPacketReceived.connect(
72 this, &SrtpTransportTest::OnPacketReceived1);
73 srtp_transport2_->SignalPacketReceived.connect(
74 this, &SrtpTransportTest::OnPacketReceived2);
zstein398c3fd2017-07-19 13:38:02 -070075 }
Zhi Huangcf990f52017-09-22 12:12:30 -070076
77 void OnPacketReceived1(bool rtcp,
78 rtc::CopyOnWriteBuffer* packet,
79 const rtc::PacketTime& packet_time) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010080 RTC_LOG(LS_INFO) << "SrtpTransport1 Received a packet.";
Zhi Huangcf990f52017-09-22 12:12:30 -070081 last_recv_packet1_ = *packet;
82 }
83
84 void OnPacketReceived2(bool rtcp,
85 rtc::CopyOnWriteBuffer* packet,
86 const rtc::PacketTime& packet_time) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010087 RTC_LOG(LS_INFO) << "SrtpTransport2 Received a packet.";
Zhi Huangcf990f52017-09-22 12:12:30 -070088 last_recv_packet2_ = *packet;
89 }
90
91 // With external auth enabled, SRTP doesn't write the auth tag and
92 // unprotect would fail. Check accessing the information about the
93 // tag instead, similar to what the actual code would do that relies
94 // on external auth.
95 void TestRtpAuthParams(SrtpTransport* transport, const std::string& cs) {
96 int overhead;
97 EXPECT_TRUE(transport->GetSrtpOverhead(&overhead));
98 switch (rtc::SrtpCryptoSuiteFromName(cs)) {
99 case rtc::SRTP_AES128_CM_SHA1_32:
100 EXPECT_EQ(32 / 8, overhead); // 32-bit tag.
101 break;
102 case rtc::SRTP_AES128_CM_SHA1_80:
103 EXPECT_EQ(80 / 8, overhead); // 80-bit tag.
104 break;
105 default:
106 RTC_NOTREACHED();
107 break;
108 }
109
110 uint8_t* auth_key = nullptr;
111 int key_len = 0;
112 int tag_len = 0;
113 EXPECT_TRUE(transport->GetRtpAuthParams(&auth_key, &key_len, &tag_len));
114 EXPECT_NE(nullptr, auth_key);
115 EXPECT_EQ(160 / 8, key_len); // Length of SHA-1 is 160 bits.
116 EXPECT_EQ(overhead, tag_len);
117 }
118
119 void TestSendRecvRtpPacket(const std::string& cipher_suite_name) {
120 size_t rtp_len = sizeof(kPcmuFrame);
121 size_t packet_size = rtp_len + rtc::rtp_auth_tag_len(cipher_suite_name);
122 rtc::Buffer rtp_packet_buffer(packet_size);
123 char* rtp_packet_data = rtp_packet_buffer.data<char>();
124 memcpy(rtp_packet_data, kPcmuFrame, rtp_len);
125 // In order to be able to run this test function multiple times we can not
126 // use the same sequence number twice. Increase the sequence number by one.
127 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_data) + 2,
128 ++sequence_number_);
129 rtc::CopyOnWriteBuffer rtp_packet1to2(rtp_packet_data, rtp_len,
130 packet_size);
131 rtc::CopyOnWriteBuffer rtp_packet2to1(rtp_packet_data, rtp_len,
132 packet_size);
133
134 char original_rtp_data[sizeof(kPcmuFrame)];
135 memcpy(original_rtp_data, rtp_packet_data, rtp_len);
136
137 rtc::PacketOptions options;
138 // Send a packet from |srtp_transport1_| to |srtp_transport2_| and verify
139 // that the packet can be successfully received and decrypted.
140 ASSERT_TRUE(srtp_transport1_->SendRtpPacket(&rtp_packet1to2, options,
141 cricket::PF_SRTP_BYPASS));
142 if (srtp_transport1_->IsExternalAuthActive()) {
143 TestRtpAuthParams(srtp_transport1_.get(), cipher_suite_name);
144 } else {
145 ASSERT_TRUE(last_recv_packet2_.data());
Steve Anton36b29d12017-10-30 09:57:42 -0700146 EXPECT_EQ(0,
147 memcmp(last_recv_packet2_.data(), original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700148 // Get the encrypted packet from underneath packet transport and verify
149 // the data is actually encrypted.
150 auto fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>(
151 srtp_transport1_->rtp_packet_transport());
Steve Anton36b29d12017-10-30 09:57:42 -0700152 EXPECT_NE(0, memcmp(fake_rtp_packet_transport->last_sent_packet()->data(),
153 original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700154 }
155
156 // Do the same thing in the opposite direction;
157 ASSERT_TRUE(srtp_transport2_->SendRtpPacket(&rtp_packet2to1, options,
158 cricket::PF_SRTP_BYPASS));
159 if (srtp_transport2_->IsExternalAuthActive()) {
160 TestRtpAuthParams(srtp_transport2_.get(), cipher_suite_name);
161 } else {
162 ASSERT_TRUE(last_recv_packet1_.data());
Steve Anton36b29d12017-10-30 09:57:42 -0700163 EXPECT_EQ(0,
164 memcmp(last_recv_packet1_.data(), original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700165 auto fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>(
166 srtp_transport2_->rtp_packet_transport());
Steve Anton36b29d12017-10-30 09:57:42 -0700167 EXPECT_NE(0, memcmp(fake_rtp_packet_transport->last_sent_packet()->data(),
168 original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700169 }
170 }
171
172 void TestSendRecvRtcpPacket(const std::string& cipher_suite_name) {
173 size_t rtcp_len = sizeof(kRtcpReport);
174 size_t packet_size =
175 rtcp_len + 4 + rtc::rtcp_auth_tag_len(cipher_suite_name);
176 rtc::Buffer rtcp_packet_buffer(packet_size);
177 char* rtcp_packet_data = rtcp_packet_buffer.data<char>();
178 memcpy(rtcp_packet_data, kRtcpReport, rtcp_len);
179
180 rtc::CopyOnWriteBuffer rtcp_packet1to2(rtcp_packet_data, rtcp_len,
181 packet_size);
182 rtc::CopyOnWriteBuffer rtcp_packet2to1(rtcp_packet_data, rtcp_len,
183 packet_size);
184
185 rtc::PacketOptions options;
186 // Send a packet from |srtp_transport1_| to |srtp_transport2_| and verify
187 // that the packet can be successfully received and decrypted.
188 ASSERT_TRUE(srtp_transport1_->SendRtcpPacket(&rtcp_packet1to2, options,
189 cricket::PF_SRTP_BYPASS));
190 ASSERT_TRUE(last_recv_packet2_.data());
Steve Anton36b29d12017-10-30 09:57:42 -0700191 EXPECT_EQ(0, memcmp(last_recv_packet2_.data(), rtcp_packet_data, rtcp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700192 // Get the encrypted packet from underneath packet transport and verify the
193 // data is actually encrypted.
194 auto fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>(
195 srtp_transport1_->rtp_packet_transport());
Steve Anton36b29d12017-10-30 09:57:42 -0700196 EXPECT_NE(0, memcmp(fake_rtp_packet_transport->last_sent_packet()->data(),
197 rtcp_packet_data, rtcp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700198
199 // Do the same thing in the opposite direction;
200 ASSERT_TRUE(srtp_transport2_->SendRtcpPacket(&rtcp_packet2to1, options,
201 cricket::PF_SRTP_BYPASS));
202 ASSERT_TRUE(last_recv_packet1_.data());
Steve Anton36b29d12017-10-30 09:57:42 -0700203 EXPECT_EQ(0, memcmp(last_recv_packet1_.data(), rtcp_packet_data, rtcp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700204 fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>(
205 srtp_transport2_->rtp_packet_transport());
Steve Anton36b29d12017-10-30 09:57:42 -0700206 EXPECT_NE(0, memcmp(fake_rtp_packet_transport->last_sent_packet()->data(),
207 rtcp_packet_data, rtcp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700208 }
209
210 void TestSendRecvPacket(bool enable_external_auth,
211 int cs,
212 const uint8_t* key1,
213 int key1_len,
214 const uint8_t* key2,
215 int key2_len,
216 const std::string& cipher_suite_name) {
217 EXPECT_EQ(key1_len, key2_len);
218 EXPECT_EQ(cipher_suite_name, rtc::SrtpCryptoSuiteToName(cs));
219 if (enable_external_auth) {
220 srtp_transport1_->EnableExternalAuth();
221 srtp_transport2_->EnableExternalAuth();
222 }
Zhi Huangc99b6c72017-11-10 16:44:46 -0800223 std::vector<int> extension_ids;
224 EXPECT_TRUE(srtp_transport1_->SetRtpParams(
225 cs, key1, key1_len, extension_ids, cs, key2, key2_len, extension_ids));
226 EXPECT_TRUE(srtp_transport2_->SetRtpParams(
227 cs, key2, key2_len, extension_ids, cs, key1, key1_len, extension_ids));
228 EXPECT_TRUE(srtp_transport1_->SetRtcpParams(
229 cs, key1, key1_len, extension_ids, cs, key2, key2_len, extension_ids));
230 EXPECT_TRUE(srtp_transport2_->SetRtcpParams(
231 cs, key2, key2_len, extension_ids, cs, key1, key1_len, extension_ids));
Zhi Huangcf990f52017-09-22 12:12:30 -0700232 EXPECT_TRUE(srtp_transport1_->IsActive());
233 EXPECT_TRUE(srtp_transport2_->IsActive());
234 if (rtc::IsGcmCryptoSuite(cs)) {
235 EXPECT_FALSE(srtp_transport1_->IsExternalAuthActive());
236 EXPECT_FALSE(srtp_transport2_->IsExternalAuthActive());
237 } else if (enable_external_auth) {
238 EXPECT_TRUE(srtp_transport1_->IsExternalAuthActive());
239 EXPECT_TRUE(srtp_transport2_->IsExternalAuthActive());
240 }
241 TestSendRecvRtpPacket(cipher_suite_name);
242 TestSendRecvRtcpPacket(cipher_suite_name);
243 }
244
245 void TestSendRecvPacketWithEncryptedHeaderExtension(
246 const std::string& cs,
247 const std::vector<int>& encrypted_header_ids) {
248 size_t rtp_len = sizeof(kPcmuFrameWithExtensions);
249 size_t packet_size = rtp_len + rtc::rtp_auth_tag_len(cs);
250 rtc::Buffer rtp_packet_buffer(packet_size);
251 char* rtp_packet_data = rtp_packet_buffer.data<char>();
252 memcpy(rtp_packet_data, kPcmuFrameWithExtensions, rtp_len);
253 // In order to be able to run this test function multiple times we can not
254 // use the same sequence number twice. Increase the sequence number by one.
255 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_data) + 2,
256 ++sequence_number_);
257 rtc::CopyOnWriteBuffer rtp_packet1to2(rtp_packet_data, rtp_len,
258 packet_size);
259 rtc::CopyOnWriteBuffer rtp_packet2to1(rtp_packet_data, rtp_len,
260 packet_size);
261
262 char original_rtp_data[sizeof(kPcmuFrameWithExtensions)];
263 memcpy(original_rtp_data, rtp_packet_data, rtp_len);
264
265 rtc::PacketOptions options;
266 // Send a packet from |srtp_transport1_| to |srtp_transport2_| and verify
267 // that the packet can be successfully received and decrypted.
268 ASSERT_TRUE(srtp_transport1_->SendRtpPacket(&rtp_packet1to2, options,
269 cricket::PF_SRTP_BYPASS));
270 ASSERT_TRUE(last_recv_packet2_.data());
Steve Anton36b29d12017-10-30 09:57:42 -0700271 EXPECT_EQ(0, memcmp(last_recv_packet2_.data(), original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700272 // Get the encrypted packet from underneath packet transport and verify the
273 // data and header extension are actually encrypted.
274 auto fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>(
275 srtp_transport1_->rtp_packet_transport());
Steve Anton36b29d12017-10-30 09:57:42 -0700276 EXPECT_NE(0, memcmp(fake_rtp_packet_transport->last_sent_packet()->data(),
277 original_rtp_data, rtp_len));
Zhi Huangcf990f52017-09-22 12:12:30 -0700278 CompareHeaderExtensions(
279 reinterpret_cast<const char*>(
280 fake_rtp_packet_transport->last_sent_packet()->data()),
281 fake_rtp_packet_transport->last_sent_packet()->size(),
282 original_rtp_data, rtp_len, encrypted_header_ids, false);
283
284 // Do the same thing in the opposite direction;
285 ASSERT_TRUE(srtp_transport2_->SendRtpPacket(&rtp_packet2to1, options,
286 cricket::PF_SRTP_BYPASS));
287 ASSERT_TRUE(last_recv_packet1_.data());
Steve Anton36b29d12017-10-30 09:57:42 -0700288 EXPECT_EQ(0, memcmp(last_recv_packet1_.data(), 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 Huangcf990f52017-09-22 12:12:30 -0700318 EXPECT_TRUE(srtp_transport1_->IsActive());
319 EXPECT_TRUE(srtp_transport2_->IsActive());
320 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
331 rtc::CopyOnWriteBuffer last_recv_packet1_;
332 rtc::CopyOnWriteBuffer last_recv_packet2_;
333 int sequence_number_ = 0;
zstein398c3fd2017-07-19 13:38:02 -0700334};
335
Zhi Huangcf990f52017-09-22 12:12:30 -0700336class SrtpTransportTestWithExternalAuth
337 : public SrtpTransportTest,
338 public testing::WithParamInterface<bool> {};
zstein398c3fd2017-07-19 13:38:02 -0700339
Zhi Huangcf990f52017-09-22 12:12:30 -0700340TEST_P(SrtpTransportTestWithExternalAuth,
341 SendAndRecvPacket_AES_CM_128_HMAC_SHA1_80) {
342 bool enable_external_auth = GetParam();
343 TestSendRecvPacket(enable_external_auth, rtc::SRTP_AES128_CM_SHA1_80,
344 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen,
345 rtc::CS_AES_CM_128_HMAC_SHA1_80);
zstein398c3fd2017-07-19 13:38:02 -0700346}
347
Zhi Huangcf990f52017-09-22 12:12:30 -0700348TEST_F(SrtpTransportTest,
349 SendAndRecvPacketWithHeaderExtension_AES_CM_128_HMAC_SHA1_80) {
350 TestSendRecvEncryptedHeaderExtension(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1,
351 kTestKeyLen, kTestKey2, kTestKeyLen,
352 rtc::CS_AES_CM_128_HMAC_SHA1_80);
353}
zstein398c3fd2017-07-19 13:38:02 -0700354
Zhi Huangcf990f52017-09-22 12:12:30 -0700355TEST_P(SrtpTransportTestWithExternalAuth,
356 SendAndRecvPacket_AES_CM_128_HMAC_SHA1_32) {
357 bool enable_external_auth = GetParam();
358 TestSendRecvPacket(enable_external_auth, rtc::SRTP_AES128_CM_SHA1_32,
359 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen,
360 rtc::CS_AES_CM_128_HMAC_SHA1_32);
361}
zstein398c3fd2017-07-19 13:38:02 -0700362
Zhi Huangcf990f52017-09-22 12:12:30 -0700363TEST_F(SrtpTransportTest,
364 SendAndRecvPacketWithHeaderExtension_AES_CM_128_HMAC_SHA1_32) {
365 TestSendRecvEncryptedHeaderExtension(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1,
366 kTestKeyLen, kTestKey2, kTestKeyLen,
367 rtc::CS_AES_CM_128_HMAC_SHA1_32);
368}
zstein398c3fd2017-07-19 13:38:02 -0700369
Zhi Huangcf990f52017-09-22 12:12:30 -0700370TEST_P(SrtpTransportTestWithExternalAuth,
371 SendAndRecvPacket_SRTP_AEAD_AES_128_GCM) {
372 bool enable_external_auth = GetParam();
373 TestSendRecvPacket(enable_external_auth, rtc::SRTP_AEAD_AES_128_GCM,
374 kTestKeyGcm128_1, kTestKeyGcm128Len, kTestKeyGcm128_2,
375 kTestKeyGcm128Len, rtc::CS_AEAD_AES_128_GCM);
376}
zstein398c3fd2017-07-19 13:38:02 -0700377
Zhi Huangcf990f52017-09-22 12:12:30 -0700378TEST_F(SrtpTransportTest,
379 SendAndRecvPacketWithHeaderExtension_SRTP_AEAD_AES_128_GCM) {
380 TestSendRecvEncryptedHeaderExtension(
381 rtc::SRTP_AEAD_AES_128_GCM, kTestKeyGcm128_1, kTestKeyGcm128Len,
382 kTestKeyGcm128_2, kTestKeyGcm128Len, rtc::CS_AEAD_AES_128_GCM);
383}
384
385TEST_P(SrtpTransportTestWithExternalAuth,
386 SendAndRecvPacket_SRTP_AEAD_AES_256_GCM) {
387 bool enable_external_auth = GetParam();
388 TestSendRecvPacket(enable_external_auth, rtc::SRTP_AEAD_AES_256_GCM,
389 kTestKeyGcm256_1, kTestKeyGcm256Len, kTestKeyGcm256_2,
390 kTestKeyGcm256Len, rtc::CS_AEAD_AES_256_GCM);
391}
392
393TEST_F(SrtpTransportTest,
394 SendAndRecvPacketWithHeaderExtension_SRTP_AEAD_AES_256_GCM) {
395 TestSendRecvEncryptedHeaderExtension(
396 rtc::SRTP_AEAD_AES_256_GCM, kTestKeyGcm256_1, kTestKeyGcm256Len,
397 kTestKeyGcm256_2, kTestKeyGcm256Len, rtc::CS_AEAD_AES_256_GCM);
398}
399
400// Run all tests both with and without external auth enabled.
401INSTANTIATE_TEST_CASE_P(ExternalAuth,
402 SrtpTransportTestWithExternalAuth,
403 ::testing::Values(true, false));
404
405// Test directly setting the params with bogus keys.
406TEST_F(SrtpTransportTest, TestSetParamsKeyTooShort) {
Zhi Huangc99b6c72017-11-10 16:44:46 -0800407 std::vector<int> extension_ids;
Zhi Huangcf990f52017-09-22 12:12:30 -0700408 EXPECT_FALSE(srtp_transport1_->SetRtpParams(
Zhi Huangc99b6c72017-11-10 16:44:46 -0800409 rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen - 1, extension_ids,
410 rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen - 1, extension_ids));
Zhi Huangcf990f52017-09-22 12:12:30 -0700411 EXPECT_FALSE(srtp_transport1_->SetRtcpParams(
Zhi Huangc99b6c72017-11-10 16:44:46 -0800412 rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen - 1, extension_ids,
413 rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen - 1, extension_ids));
zstein398c3fd2017-07-19 13:38:02 -0700414}
415
416} // namespace webrtc