OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/pc/srtptransport.h" | 11 #include "webrtc/pc/srtptransport.h" |
12 | 12 |
13 #include "webrtc/media/base/fakertp.h" | |
14 #include "webrtc/p2p/base/dtlstransportinternal.h" | |
15 #include "webrtc/p2p/base/fakepackettransport.h" | |
13 #include "webrtc/pc/rtptransport.h" | 16 #include "webrtc/pc/rtptransport.h" |
14 #include "webrtc/pc/rtptransporttestutil.h" | 17 #include "webrtc/pc/rtptransporttestutil.h" |
18 #include "webrtc/pc/srtptestutil.h" | |
15 #include "webrtc/rtc_base/asyncpacketsocket.h" | 19 #include "webrtc/rtc_base/asyncpacketsocket.h" |
16 #include "webrtc/rtc_base/gunit.h" | 20 #include "webrtc/rtc_base/gunit.h" |
17 #include "webrtc/rtc_base/ptr_util.h" | 21 #include "webrtc/rtc_base/ptr_util.h" |
18 #include "webrtc/test/gmock.h" | 22 #include "webrtc/rtc_base/sslstreamadapter.h" |
23 | |
24 using rtc::kTestKey1; | |
25 using rtc::kTestKey2; | |
26 using rtc::kTestKeyLen; | |
27 using rtc::SRTP_AEAD_AES_128_GCM; | |
19 | 28 |
20 namespace webrtc { | 29 namespace webrtc { |
21 | 30 static const uint8_t kTestKeyGcm128_1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ12"; |
22 using testing::_; | 31 static const uint8_t kTestKeyGcm128_2[] = "21ZYXWVUTSRQPONMLKJIHGFEDCBA"; |
23 using testing::Return; | 32 static const int kTestKeyGcm128Len = 28; // 128 bits key + 96 bits salt. |
24 | 33 static const uint8_t kTestKeyGcm256_1[] = |
25 class MockRtpTransport : public RtpTransport { | 34 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr"; |
35 static const uint8_t kTestKeyGcm256_2[] = | |
36 "rqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA"; | |
37 static const int kTestKeyGcm256Len = 44; // 256 bits key + 96 bits salt. | |
38 | |
39 class FakeRtpTransport : public RtpTransport { | |
Taylor Brandstetter
2017/08/30 21:24:26
I'm realizing now: do we even need a "FakeRtpTrans
Zhi Huang
2017/08/31 17:42:41
We don't actually need this fake class. Removing i
| |
26 public: | 40 public: |
27 MockRtpTransport() : RtpTransport(true) {} | 41 FakeRtpTransport() : RtpTransport(true) { |
28 | 42 rtp_packet_transport_ = |
29 MOCK_METHOD4(SendPacket, | 43 rtc::MakeUnique<rtc::FakePacketTransport>("FakePacketTransport"); |
30 bool(bool rtcp, | 44 SetRtpPacketTransport(rtp_packet_transport_.get()); |
31 rtc::CopyOnWriteBuffer* packet, | 45 } |
32 const rtc::PacketOptions& options, | 46 |
33 int flags)); | 47 void Connect(FakeRtpTransport* peer) { |
34 | 48 peer_ = peer; |
35 void PretendReceivedPacket() { | 49 if (peer_) { |
36 bool rtcp = false; | 50 rtp_packet_transport_->SetDestination( |
37 rtc::CopyOnWriteBuffer buffer; | 51 static_cast<rtc::FakePacketTransport*>(peer_->rtp_packet_transport()), |
38 rtc::PacketTime time; | 52 false); |
39 SignalPacketReceived(rtcp, &buffer, time); | 53 } |
40 } | 54 } |
55 | |
56 bool SendRtpPacket(rtc::CopyOnWriteBuffer* packet, | |
57 const rtc::PacketOptions& options) override { | |
58 return SendPacket(false, packet, options, cricket::PF_NORMAL); | |
59 } | |
60 | |
61 bool SendRtcpPacket(rtc::CopyOnWriteBuffer* packet, | |
62 const rtc::PacketOptions& options) override { | |
63 return SendPacket(true, packet, options, cricket::PF_NORMAL); | |
64 } | |
65 | |
66 bool SendPacket(bool rtcp, | |
67 rtc::CopyOnWriteBuffer* packet, | |
68 const rtc::PacketOptions& options, | |
69 int flags) override { | |
70 if (peer_) { | |
71 rtp_packet_transport_->SendPacket( | |
72 reinterpret_cast<const char*>(packet->data()), packet->size(), | |
73 options, flags); | |
74 peer_->SignalPacketReceived(rtcp, packet, rtc::PacketTime()); | |
Taylor Brandstetter
2017/08/30 21:24:26
It looks like this will cause the packet to be rec
Zhi Huang
2017/08/31 17:42:41
Done.
| |
75 } | |
76 return true; | |
77 } | |
78 | |
79 private: | |
80 FakeRtpTransport* peer_ = nullptr; | |
81 std::unique_ptr<rtc::FakePacketTransport> rtp_packet_transport_; | |
41 }; | 82 }; |
42 | 83 |
43 TEST(SrtpTransportTest, SendPacket) { | 84 class SrtpTransportTest : public testing::Test, public sigslot::has_slots<> { |
44 auto rtp_transport = rtc::MakeUnique<MockRtpTransport>(); | 85 protected: |
45 EXPECT_CALL(*rtp_transport, SendPacket(_, _, _, _)).WillOnce(Return(true)); | 86 SrtpTransportTest() { |
46 | 87 auto rtp_transport1 = rtc::MakeUnique<FakeRtpTransport>(); |
47 SrtpTransport srtp_transport(std::move(rtp_transport), "a"); | 88 auto rtp_transport2 = rtc::MakeUnique<FakeRtpTransport>(); |
48 | 89 rtp_transport1->Connect(rtp_transport2.get()); |
49 const bool rtcp = false; | 90 rtp_transport2->Connect(rtp_transport1.get()); |
50 rtc::CopyOnWriteBuffer packet; | 91 |
51 rtc::PacketOptions options; | 92 srtp_transport1_ = |
52 int flags = 0; | 93 rtc::MakeUnique<SrtpTransport>(std::move(rtp_transport1), "content"); |
53 EXPECT_TRUE(srtp_transport.SendPacket(rtcp, &packet, options, flags)); | 94 srtp_transport2_ = |
54 | 95 rtc::MakeUnique<SrtpTransport>(std::move(rtp_transport2), "content"); |
55 // TODO(zstein): Also verify that the packet received by RtpTransport has been | 96 |
56 // protected once SrtpTransport handles that. | 97 srtp_transport1_->SignalPacketReceived.connect( |
57 } | 98 this, &SrtpTransportTest::OnPacketReceived1); |
58 | 99 srtp_transport2_->SignalPacketReceived.connect( |
59 // Test that SrtpTransport fires SignalPacketReceived when the underlying | 100 this, &SrtpTransportTest::OnPacketReceived2); |
60 // RtpTransport fires SignalPacketReceived. | 101 } |
61 TEST(SrtpTransportTest, SignalPacketReceived) { | 102 |
62 auto rtp_transport = rtc::MakeUnique<MockRtpTransport>(); | 103 void OnPacketReceived1(bool rtcp, |
63 MockRtpTransport* rtp_transport_raw = rtp_transport.get(); | 104 rtc::CopyOnWriteBuffer* packet, |
64 SrtpTransport srtp_transport(std::move(rtp_transport), "a"); | 105 const rtc::PacketTime& packet_time) { |
65 | 106 LOG(LS_INFO) << "SrtpTransport1 Received a packet."; |
66 SignalPacketReceivedCounter counter(&srtp_transport); | 107 last_recv_packet1_ = *packet; |
67 | 108 } |
68 rtp_transport_raw->PretendReceivedPacket(); | 109 |
69 | 110 void OnPacketReceived2(bool rtcp, |
70 EXPECT_EQ(1, counter.rtp_count()); | 111 rtc::CopyOnWriteBuffer* packet, |
71 | 112 const rtc::PacketTime& packet_time) { |
72 // TODO(zstein): Also verify that the packet is unprotected once SrtpTransport | 113 LOG(LS_INFO) << "SrtpTransport2 Received a packet."; |
73 // handles that. | 114 last_recv_packet2_ = *packet; |
115 } | |
116 | |
117 // With external auth enabled, SRTP doesn't write the auth tag and | |
118 // unprotect would fail. Check accessing the information about the | |
119 // tag instead, similar to what the actual code would do that relies | |
120 // on external auth. | |
121 void TestRtpAuthParams(SrtpTransport* transport, const std::string& cs) { | |
122 int overhead; | |
123 EXPECT_TRUE(transport->GetSrtpOverhead(&overhead)); | |
124 switch (rtc::SrtpCryptoSuiteFromName(cs)) { | |
125 case rtc::SRTP_AES128_CM_SHA1_32: | |
126 EXPECT_EQ(32 / 8, overhead); // 32-bit tag. | |
127 break; | |
128 case rtc::SRTP_AES128_CM_SHA1_80: | |
129 EXPECT_EQ(80 / 8, overhead); // 80-bit tag. | |
130 break; | |
131 default: | |
132 RTC_NOTREACHED(); | |
133 break; | |
134 } | |
135 | |
136 uint8_t* auth_key = nullptr; | |
137 int key_len = 0; | |
138 int tag_len = 0; | |
139 EXPECT_TRUE(transport->GetRtpAuthParams(&auth_key, &key_len, &tag_len)); | |
140 EXPECT_NE(nullptr, auth_key); | |
141 EXPECT_EQ(160 / 8, key_len); // Length of SHA-1 is 160 bits. | |
142 EXPECT_EQ(overhead, tag_len); | |
143 } | |
144 | |
145 void TestSendRecvRtpPacket(const std::string& cipher_suite_name) { | |
146 int rtp_len = sizeof(kPcmuFrame); | |
147 int packet_size = rtp_len + rtc::rtp_auth_tag_len(cipher_suite_name); | |
148 char rtp_packet_data[packet_size]; | |
149 memcpy(rtp_packet_data, kPcmuFrame, rtp_len); | |
150 // In order to be able to run this test function multiple times we can not | |
151 // use the same sequence number twice. Increase the sequence number by one. | |
152 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_data) + 2, | |
153 ++sequence_number_); | |
154 rtc::CopyOnWriteBuffer rtp_packet1to2(rtp_packet_data, rtp_len, | |
155 packet_size); | |
156 rtc::CopyOnWriteBuffer rtp_packet2to1(rtp_packet_data, rtp_len, | |
157 packet_size); | |
158 | |
159 char original_rtp_data[rtp_len]; | |
160 memcpy(original_rtp_data, rtp_packet_data, rtp_len); | |
161 | |
162 rtc::PacketOptions options; | |
163 // Send a packet from |srtp_transport1_| to |srtp_transport2_| and verify | |
164 // that the packet can be successfully received and decrypted. | |
165 ASSERT_TRUE(srtp_transport1_->SendRtpPacket(&rtp_packet1to2, options)); | |
166 if (srtp_transport1_->IsExternalAuthActive()) { | |
167 TestRtpAuthParams(srtp_transport1_.get(), cipher_suite_name); | |
168 } else { | |
169 ASSERT_TRUE(last_recv_packet2_.data()); | |
170 EXPECT_TRUE( | |
171 memcmp(last_recv_packet2_.data(), original_rtp_data, rtp_len) == 0); | |
172 // Get the encrypted packet from underneath packet transport and verify | |
173 // the data is actually encrypted. | |
174 auto fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>( | |
175 srtp_transport1_->rtp_packet_transport()); | |
176 EXPECT_FALSE(memcmp(fake_rtp_packet_transport->last_sent_packet()->data(), | |
177 original_rtp_data, rtp_len) == 0); | |
178 } | |
179 | |
180 // Do the same thing in the opposite direction; | |
181 ASSERT_TRUE(srtp_transport2_->SendRtpPacket(&rtp_packet2to1, options)); | |
182 if (srtp_transport2_->IsExternalAuthActive()) { | |
183 TestRtpAuthParams(srtp_transport2_.get(), cipher_suite_name); | |
184 } else { | |
185 ASSERT_TRUE(last_recv_packet1_.data()); | |
186 EXPECT_TRUE( | |
187 memcmp(last_recv_packet1_.data(), original_rtp_data, rtp_len) == 0); | |
188 auto fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>( | |
189 srtp_transport2_->rtp_packet_transport()); | |
190 EXPECT_FALSE(memcmp(fake_rtp_packet_transport->last_sent_packet()->data(), | |
191 original_rtp_data, rtp_len) == 0); | |
192 } | |
193 } | |
194 | |
195 void TestSendRecvRtcpPacket(const std::string& cipher_suite_name) { | |
196 int rtcp_len = sizeof(kRtcpReport); | |
197 int packet_size = rtcp_len + 4 + rtc::rtcp_auth_tag_len(cipher_suite_name); | |
198 char rtcp_packet_data[packet_size]; | |
199 memcpy(rtcp_packet_data, kRtcpReport, rtcp_len); | |
200 | |
201 rtc::CopyOnWriteBuffer rtcp_packet1to2(rtcp_packet_data, rtcp_len, | |
202 packet_size); | |
203 rtc::CopyOnWriteBuffer rtcp_packet2to1(rtcp_packet_data, rtcp_len, | |
204 packet_size); | |
205 | |
206 rtc::PacketOptions options; | |
207 // Send a packet from |srtp_transport1_| to |srtp_transport2_| and verify | |
208 // that the packet can be successfully received and decrypted. | |
209 ASSERT_TRUE(srtp_transport1_->SendRtcpPacket(&rtcp_packet1to2, options)); | |
210 ASSERT_TRUE(last_recv_packet2_.data()); | |
211 EXPECT_TRUE(memcmp(last_recv_packet2_.data(), rtcp_packet_data, rtcp_len) == | |
212 0); | |
213 // Get the encrypted packet from underneath packet transport and verify the | |
214 // data is actually encrypted. | |
215 auto fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>( | |
216 srtp_transport1_->rtp_packet_transport()); | |
217 EXPECT_FALSE(memcmp(fake_rtp_packet_transport->last_sent_packet()->data(), | |
218 rtcp_packet_data, rtcp_len) == 0); | |
219 | |
220 // Do the same thing in the opposite direction; | |
221 ASSERT_TRUE(srtp_transport2_->SendRtcpPacket(&rtcp_packet2to1, options)); | |
222 ASSERT_TRUE(last_recv_packet1_.data()); | |
223 EXPECT_TRUE(memcmp(last_recv_packet1_.data(), rtcp_packet_data, rtcp_len) == | |
224 0); | |
225 fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>( | |
226 srtp_transport2_->rtp_packet_transport()); | |
227 EXPECT_FALSE(memcmp(fake_rtp_packet_transport->last_sent_packet()->data(), | |
228 rtcp_packet_data, rtcp_len) == 0); | |
229 } | |
230 | |
231 void TestSendRecvPacket(bool enable_external_auth, | |
232 int cs, | |
233 const uint8_t* key1, | |
234 int key1_len, | |
235 const uint8_t* key2, | |
236 int key2_len, | |
237 const std::string& cipher_suite_name) { | |
238 EXPECT_EQ(key1_len, key2_len); | |
239 EXPECT_EQ(cipher_suite_name, rtc::SrtpCryptoSuiteToName(cs)); | |
240 if (enable_external_auth) { | |
241 srtp_transport1_->EnableExternalAuth(); | |
242 srtp_transport2_->EnableExternalAuth(); | |
243 } | |
244 EXPECT_TRUE( | |
245 srtp_transport1_->SetRtpParams(cs, key1, key1_len, cs, key2, key2_len)); | |
246 EXPECT_TRUE( | |
247 srtp_transport2_->SetRtpParams(cs, key2, key2_len, cs, key1, key1_len)); | |
248 EXPECT_TRUE(srtp_transport1_->SetRtcpParams(cs, key1, key1_len, cs, key2, | |
249 key2_len)); | |
250 EXPECT_TRUE(srtp_transport2_->SetRtcpParams(cs, key2, key2_len, cs, key1, | |
251 key1_len)); | |
252 EXPECT_TRUE(srtp_transport1_->IsActive()); | |
253 EXPECT_TRUE(srtp_transport2_->IsActive()); | |
254 if (rtc::IsGcmCryptoSuite(cs)) { | |
255 EXPECT_FALSE(srtp_transport1_->IsExternalAuthActive()); | |
256 EXPECT_FALSE(srtp_transport2_->IsExternalAuthActive()); | |
257 } else if (enable_external_auth) { | |
258 EXPECT_TRUE(srtp_transport1_->IsExternalAuthActive()); | |
259 EXPECT_TRUE(srtp_transport2_->IsExternalAuthActive()); | |
260 } | |
261 TestSendRecvRtpPacket(cipher_suite_name); | |
262 TestSendRecvRtcpPacket(cipher_suite_name); | |
263 } | |
264 | |
265 void TestSendRecvPacketWithEncryptedHeaderExtension( | |
266 const std::string& cs, | |
267 const std::vector<int>& encrypted_header_ids) { | |
268 int rtp_len = sizeof(kPcmuFrameWithExtensions); | |
269 int packet_size = rtp_len + rtc::rtp_auth_tag_len(cs); | |
270 char rtp_packet_data[packet_size]; | |
271 memcpy(rtp_packet_data, kPcmuFrameWithExtensions, rtp_len); | |
272 // In order to be able to run this test function multiple times we can not | |
273 // use the same sequence number twice. Increase the sequence number by one. | |
274 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_data) + 2, | |
275 ++sequence_number_); | |
276 rtc::CopyOnWriteBuffer rtp_packet(rtp_packet_data, rtp_len, packet_size); | |
277 | |
278 char original_rtp_data[rtp_len]; | |
279 memcpy(original_rtp_data, rtp_packet_data, rtp_len); | |
280 | |
281 rtc::PacketOptions options; | |
282 // Send a packet from |srtp_transport1_| to |srtp_transport2_| and verify | |
283 // that the packet can be successfully received and decrypted. | |
284 ASSERT_TRUE(srtp_transport1_->SendRtpPacket(&rtp_packet, options)); | |
285 ASSERT_TRUE(last_recv_packet2_.data()); | |
286 EXPECT_TRUE(memcmp(last_recv_packet2_.data(), original_rtp_data, rtp_len) == | |
287 0); | |
288 // Get the encrypted packet from underneath packet transport and verify the | |
289 // data and header extension are actually encrypted. | |
290 auto fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>( | |
291 srtp_transport1_->rtp_packet_transport()); | |
292 EXPECT_FALSE(memcmp(fake_rtp_packet_transport->last_sent_packet()->data(), | |
293 original_rtp_data, rtp_len) == 0); | |
294 CompareHeaderExtensions( | |
295 reinterpret_cast<const char*>( | |
296 fake_rtp_packet_transport->last_sent_packet()->data()), | |
297 fake_rtp_packet_transport->last_sent_packet()->size(), | |
298 original_rtp_data, rtp_len, encrypted_header_ids, false); | |
299 | |
300 // Do the same thing in the opposite direction; | |
301 ASSERT_TRUE(srtp_transport2_->SendRtpPacket(&rtp_packet, options)); | |
302 ASSERT_TRUE(last_recv_packet1_.data()); | |
303 EXPECT_TRUE(memcmp(last_recv_packet1_.data(), original_rtp_data, rtp_len) == | |
304 0); | |
305 fake_rtp_packet_transport = static_cast<rtc::FakePacketTransport*>( | |
306 srtp_transport2_->rtp_packet_transport()); | |
307 EXPECT_FALSE(memcmp(fake_rtp_packet_transport->last_sent_packet()->data(), | |
308 original_rtp_data, rtp_len) == 0); | |
309 CompareHeaderExtensions( | |
310 reinterpret_cast<const char*>( | |
311 fake_rtp_packet_transport->last_sent_packet()->data()), | |
312 fake_rtp_packet_transport->last_sent_packet()->size(), | |
313 original_rtp_data, rtp_len, encrypted_header_ids, false); | |
314 } | |
315 | |
316 void TestSendRecvEncryptedHeaderExtension(int cs, | |
317 const uint8_t* key1, | |
318 int key1_len, | |
319 const uint8_t* key2, | |
320 int key2_len, | |
321 const std::string& cs_name) { | |
322 std::vector<int> encrypted_headers; | |
323 encrypted_headers.push_back(1); | |
324 // Don't encrypt header ids 2 and 3. | |
325 encrypted_headers.push_back(4); | |
326 EXPECT_EQ(key1_len, key2_len); | |
327 EXPECT_EQ(cs_name, rtc::SrtpCryptoSuiteToName(cs)); | |
328 srtp_transport1_->SetEncryptedHeaderExtensionIds(cricket::CS_LOCAL, | |
329 encrypted_headers); | |
330 srtp_transport1_->SetEncryptedHeaderExtensionIds(cricket::CS_REMOTE, | |
331 encrypted_headers); | |
332 srtp_transport2_->SetEncryptedHeaderExtensionIds(cricket::CS_LOCAL, | |
333 encrypted_headers); | |
334 srtp_transport2_->SetEncryptedHeaderExtensionIds(cricket::CS_REMOTE, | |
335 encrypted_headers); | |
336 EXPECT_TRUE( | |
337 srtp_transport1_->SetRtpParams(cs, key1, key1_len, cs, key2, key2_len)); | |
338 EXPECT_TRUE( | |
339 srtp_transport2_->SetRtpParams(cs, key2, key2_len, cs, key1, key1_len)); | |
340 EXPECT_TRUE(srtp_transport1_->IsActive()); | |
341 EXPECT_TRUE(srtp_transport2_->IsActive()); | |
342 EXPECT_FALSE(srtp_transport1_->IsExternalAuthActive()); | |
343 EXPECT_FALSE(srtp_transport2_->IsExternalAuthActive()); | |
344 TestSendRecvPacketWithEncryptedHeaderExtension(cs_name, encrypted_headers); | |
345 } | |
346 | |
347 std::unique_ptr<SrtpTransport> srtp_transport1_; | |
348 std::unique_ptr<SrtpTransport> srtp_transport2_; | |
349 | |
350 rtc::CopyOnWriteBuffer last_recv_packet1_; | |
351 rtc::CopyOnWriteBuffer last_recv_packet2_; | |
352 int sequence_number_ = 0; | |
353 }; | |
354 | |
355 class SrtpTransportTestWithExternalAuth | |
356 : public SrtpTransportTest, | |
357 public testing::WithParamInterface<bool> {}; | |
358 | |
359 TEST_P(SrtpTransportTestWithExternalAuth, | |
360 SendAndRecvPacket_AES_CM_128_HMAC_SHA1_80) { | |
361 bool enable_external_auth = GetParam(); | |
362 TestSendRecvPacket(enable_external_auth, rtc::SRTP_AES128_CM_SHA1_80, | |
363 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen, | |
364 rtc::CS_AES_CM_128_HMAC_SHA1_80); | |
365 } | |
366 | |
367 TEST_F(SrtpTransportTest, | |
368 SendAndRecvPacketWithHeaderExtension_AES_CM_128_HMAC_SHA1_80) { | |
369 TestSendRecvEncryptedHeaderExtension(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, | |
370 kTestKeyLen, kTestKey2, kTestKeyLen, | |
371 rtc::CS_AES_CM_128_HMAC_SHA1_80); | |
372 } | |
373 | |
374 TEST_P(SrtpTransportTestWithExternalAuth, | |
375 SendAndRecvPacket_AES_CM_128_HMAC_SHA1_32) { | |
376 bool enable_external_auth = GetParam(); | |
377 TestSendRecvPacket(enable_external_auth, rtc::SRTP_AES128_CM_SHA1_32, | |
378 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen, | |
379 rtc::CS_AES_CM_128_HMAC_SHA1_32); | |
380 } | |
381 | |
382 TEST_F(SrtpTransportTest, | |
383 SendAndRecvPacketWithHeaderExtension_AES_CM_128_HMAC_SHA1_32) { | |
384 TestSendRecvEncryptedHeaderExtension(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, | |
385 kTestKeyLen, kTestKey2, kTestKeyLen, | |
386 rtc::CS_AES_CM_128_HMAC_SHA1_32); | |
387 } | |
388 | |
389 TEST_P(SrtpTransportTestWithExternalAuth, | |
390 SendAndRecvPacket_SRTP_AEAD_AES_128_GCM) { | |
391 bool enable_external_auth = GetParam(); | |
392 TestSendRecvPacket(enable_external_auth, rtc::SRTP_AEAD_AES_128_GCM, | |
393 kTestKeyGcm128_1, kTestKeyGcm128Len, kTestKeyGcm128_2, | |
394 kTestKeyGcm128Len, rtc::CS_AEAD_AES_128_GCM); | |
395 } | |
396 | |
397 TEST_F(SrtpTransportTest, | |
398 SendAndRecvPacketWithHeaderExtension_SRTP_AEAD_AES_128_GCM) { | |
399 TestSendRecvEncryptedHeaderExtension( | |
400 rtc::SRTP_AEAD_AES_128_GCM, kTestKeyGcm128_1, kTestKeyGcm128Len, | |
401 kTestKeyGcm128_2, kTestKeyGcm128Len, rtc::CS_AEAD_AES_128_GCM); | |
402 } | |
403 | |
404 TEST_P(SrtpTransportTestWithExternalAuth, | |
405 SendAndRecvPacket_SRTP_AEAD_AES_256_GCM) { | |
406 bool enable_external_auth = GetParam(); | |
407 TestSendRecvPacket(enable_external_auth, rtc::SRTP_AEAD_AES_256_GCM, | |
408 kTestKeyGcm256_1, kTestKeyGcm256Len, kTestKeyGcm256_2, | |
409 kTestKeyGcm256Len, rtc::CS_AEAD_AES_256_GCM); | |
410 } | |
411 | |
412 TEST_F(SrtpTransportTest, | |
413 SendAndRecvPacketWithHeaderExtension_SRTP_AEAD_AES_256_GCM) { | |
414 TestSendRecvEncryptedHeaderExtension( | |
415 rtc::SRTP_AEAD_AES_256_GCM, kTestKeyGcm256_1, kTestKeyGcm256Len, | |
416 kTestKeyGcm256_2, kTestKeyGcm256Len, rtc::CS_AEAD_AES_256_GCM); | |
417 } | |
418 | |
419 // Run all tests both with and without external auth enabled. | |
420 INSTANTIATE_TEST_CASE_P(ExternalAuth, | |
421 SrtpTransportTestWithExternalAuth, | |
422 ::testing::Values(true, false)); | |
423 | |
424 // Test directly setting the params with bogus keys. | |
425 TEST_F(SrtpTransportTest, TestSetParamsKeyTooShort) { | |
426 EXPECT_FALSE(srtp_transport1_->SetRtpParams( | |
427 rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen - 1, | |
428 rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen - 1)); | |
429 EXPECT_FALSE(srtp_transport1_->SetRtcpParams( | |
430 rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen - 1, | |
431 rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen - 1)); | |
74 } | 432 } |
75 | 433 |
76 } // namespace webrtc | 434 } // namespace webrtc |
OLD | NEW |