Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: webrtc/pc/srtpfilter_unittest.cc

Issue 2722423003: Improve testing of SRTP external auth code paths. (Closed)
Patch Set: Changes based on feedback from Taylor. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/pc/srtpfilter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2004 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
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 const std::vector<CryptoParams>& params2) { 100 const std::vector<CryptoParams>& params2) {
101 EXPECT_TRUE(f1_.SetOffer(params1, CS_LOCAL)); 101 EXPECT_TRUE(f1_.SetOffer(params1, CS_LOCAL));
102 EXPECT_TRUE(f2_.SetOffer(params1, CS_REMOTE)); 102 EXPECT_TRUE(f2_.SetOffer(params1, CS_REMOTE));
103 EXPECT_FALSE(f1_.IsActive()); 103 EXPECT_FALSE(f1_.IsActive());
104 EXPECT_FALSE(f2_.IsActive()); 104 EXPECT_FALSE(f2_.IsActive());
105 EXPECT_TRUE(f2_.SetAnswer(params2, CS_LOCAL)); 105 EXPECT_TRUE(f2_.SetAnswer(params2, CS_LOCAL));
106 EXPECT_TRUE(f1_.SetAnswer(params2, CS_REMOTE)); 106 EXPECT_TRUE(f1_.SetAnswer(params2, CS_REMOTE));
107 EXPECT_TRUE(f1_.IsActive()); 107 EXPECT_TRUE(f1_.IsActive());
108 EXPECT_TRUE(f2_.IsActive()); 108 EXPECT_TRUE(f2_.IsActive());
109 } 109 }
110 void TestRtpAuthParams(cricket::SrtpFilter* filter, const std::string& cs) {
111 int overhead;
112 EXPECT_TRUE(filter->GetSrtpOverhead(&overhead));
113 switch (rtc::SrtpCryptoSuiteFromName(cs)) {
114 case rtc::SRTP_AES128_CM_SHA1_32:
115 EXPECT_EQ(32/8, overhead); // 32-bit tag.
116 break;
117 case rtc::SRTP_AES128_CM_SHA1_80:
118 EXPECT_EQ(80/8, overhead); // 80-bit tag.
119 break;
120 default:
121 RTC_NOTREACHED();
122 break;
123 }
124
125 uint8_t* auth_key = nullptr;
126 int key_len = 0;
127 int tag_len = 0;
128 EXPECT_TRUE(filter->GetRtpAuthParams(&auth_key, &key_len, &tag_len));
129 EXPECT_NE(nullptr, auth_key);
130 EXPECT_EQ(160/8, key_len); // Length of SHA-1 is 160 bits.
131 EXPECT_EQ(overhead, tag_len);
132 }
110 void TestProtectUnprotect(const std::string& cs1, const std::string& cs2) { 133 void TestProtectUnprotect(const std::string& cs1, const std::string& cs2) {
111 rtc::Buffer rtp_buffer(sizeof(kPcmuFrame) + rtp_auth_tag_len(cs1)); 134 rtc::Buffer rtp_buffer(sizeof(kPcmuFrame) + rtp_auth_tag_len(cs1));
112 char* rtp_packet = rtp_buffer.data<char>(); 135 char* rtp_packet = rtp_buffer.data<char>();
113 char original_rtp_packet[sizeof(kPcmuFrame)]; 136 char original_rtp_packet[sizeof(kPcmuFrame)];
114 rtc::Buffer rtcp_buffer(sizeof(kRtcpReport) + 4 + rtcp_auth_tag_len(cs2)); 137 rtc::Buffer rtcp_buffer(sizeof(kRtcpReport) + 4 + rtcp_auth_tag_len(cs2));
115 char* rtcp_packet = rtcp_buffer.data<char>(); 138 char* rtcp_packet = rtcp_buffer.data<char>();
116 int rtp_len = sizeof(kPcmuFrame), rtcp_len = sizeof(kRtcpReport), out_len; 139 int rtp_len = sizeof(kPcmuFrame), rtcp_len = sizeof(kRtcpReport), out_len;
117 memcpy(rtp_packet, kPcmuFrame, rtp_len); 140 memcpy(rtp_packet, kPcmuFrame, rtp_len);
118 // In order to be able to run this test function multiple times we can not 141 // In order to be able to run this test function multiple times we can not
119 // use the same sequence number twice. Increase the sequence number by one. 142 // use the same sequence number twice. Increase the sequence number by one.
120 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet) + 2, 143 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet) + 2,
121 ++sequence_number_); 144 ++sequence_number_);
122 memcpy(original_rtp_packet, rtp_packet, rtp_len); 145 memcpy(original_rtp_packet, rtp_packet, rtp_len);
123 memcpy(rtcp_packet, kRtcpReport, rtcp_len); 146 memcpy(rtcp_packet, kRtcpReport, rtcp_len);
124 147
125 EXPECT_TRUE(f1_.ProtectRtp(rtp_packet, rtp_len, 148 EXPECT_TRUE(f1_.ProtectRtp(rtp_packet, rtp_len,
126 static_cast<int>(rtp_buffer.size()), 149 static_cast<int>(rtp_buffer.size()),
127 &out_len)); 150 &out_len));
128 EXPECT_EQ(out_len, rtp_len + rtp_auth_tag_len(cs1)); 151 EXPECT_EQ(out_len, rtp_len + rtp_auth_tag_len(cs1));
129 EXPECT_NE(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); 152 EXPECT_NE(0, memcmp(rtp_packet, original_rtp_packet, rtp_len));
130 EXPECT_TRUE(f2_.UnprotectRtp(rtp_packet, out_len, &out_len)); 153 if (!f1_.IsExternalAuthActive()) {
131 EXPECT_EQ(rtp_len, out_len); 154 EXPECT_TRUE(f2_.UnprotectRtp(rtp_packet, out_len, &out_len));
132 EXPECT_EQ(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); 155 EXPECT_EQ(rtp_len, out_len);
156 EXPECT_EQ(0, memcmp(rtp_packet, original_rtp_packet, rtp_len));
157 } else {
158 // With external auth enabled, SRTP doesn't write the auth tag and
159 // unprotect would fail. Check accessing the information about the
160 // tag instead, similar to what the actual code would do that relies
161 // on external auth.
162 TestRtpAuthParams(&f1_, cs1);
163 }
133 164
134 EXPECT_TRUE(f2_.ProtectRtp(rtp_packet, rtp_len, 165 EXPECT_TRUE(f2_.ProtectRtp(rtp_packet, rtp_len,
135 static_cast<int>(rtp_buffer.size()), 166 static_cast<int>(rtp_buffer.size()),
136 &out_len)); 167 &out_len));
137 EXPECT_EQ(out_len, rtp_len + rtp_auth_tag_len(cs2)); 168 EXPECT_EQ(out_len, rtp_len + rtp_auth_tag_len(cs2));
138 EXPECT_NE(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); 169 EXPECT_NE(0, memcmp(rtp_packet, original_rtp_packet, rtp_len));
139 EXPECT_TRUE(f1_.UnprotectRtp(rtp_packet, out_len, &out_len)); 170 if (!f2_.IsExternalAuthActive()) {
140 EXPECT_EQ(rtp_len, out_len); 171 EXPECT_TRUE(f1_.UnprotectRtp(rtp_packet, out_len, &out_len));
141 EXPECT_EQ(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); 172 EXPECT_EQ(rtp_len, out_len);
173 EXPECT_EQ(0, memcmp(rtp_packet, original_rtp_packet, rtp_len));
174 } else {
175 TestRtpAuthParams(&f2_, cs2);
176 }
142 177
143 EXPECT_TRUE(f1_.ProtectRtcp(rtcp_packet, rtcp_len, 178 EXPECT_TRUE(f1_.ProtectRtcp(rtcp_packet, rtcp_len,
144 static_cast<int>(rtcp_buffer.size()), 179 static_cast<int>(rtcp_buffer.size()),
145 &out_len)); 180 &out_len));
146 EXPECT_EQ(out_len, rtcp_len + 4 + rtcp_auth_tag_len(cs1)); // NOLINT 181 EXPECT_EQ(out_len, rtcp_len + 4 + rtcp_auth_tag_len(cs1)); // NOLINT
147 EXPECT_NE(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len)); 182 EXPECT_NE(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len));
148 EXPECT_TRUE(f2_.UnprotectRtcp(rtcp_packet, out_len, &out_len)); 183 EXPECT_TRUE(f2_.UnprotectRtcp(rtcp_packet, out_len, &out_len));
149 EXPECT_EQ(rtcp_len, out_len); 184 EXPECT_EQ(rtcp_len, out_len);
150 EXPECT_EQ(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len)); 185 EXPECT_EQ(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len));
151 186
152 EXPECT_TRUE(f2_.ProtectRtcp(rtcp_packet, rtcp_len, 187 EXPECT_TRUE(f2_.ProtectRtcp(rtcp_packet, rtcp_len,
153 static_cast<int>(rtcp_buffer.size()), 188 static_cast<int>(rtcp_buffer.size()),
154 &out_len)); 189 &out_len));
155 EXPECT_EQ(out_len, rtcp_len + 4 + rtcp_auth_tag_len(cs2)); // NOLINT 190 EXPECT_EQ(out_len, rtcp_len + 4 + rtcp_auth_tag_len(cs2)); // NOLINT
156 EXPECT_NE(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len)); 191 EXPECT_NE(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len));
157 EXPECT_TRUE(f1_.UnprotectRtcp(rtcp_packet, out_len, &out_len)); 192 EXPECT_TRUE(f1_.UnprotectRtcp(rtcp_packet, out_len, &out_len));
158 EXPECT_EQ(rtcp_len, out_len); 193 EXPECT_EQ(rtcp_len, out_len);
159 EXPECT_EQ(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len)); 194 EXPECT_EQ(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len));
160 } 195 }
196 void TestProtectSetParamsDirect(bool enable_external_auth, int cs,
197 const uint8_t* key1, int key1_len, const uint8_t* key2, int key2_len,
198 const std::string& cs_name) {
199 EXPECT_EQ(key1_len, key2_len);
200 EXPECT_EQ(cs_name, rtc::SrtpCryptoSuiteToName(cs));
201 if (enable_external_auth) {
202 f1_.EnableExternalAuth();
203 f2_.EnableExternalAuth();
204 }
205 EXPECT_TRUE(f1_.SetRtpParams(cs, key1, key1_len, cs, key2, key2_len));
206 EXPECT_TRUE(f2_.SetRtpParams(cs, key2, key2_len, cs, key1, key1_len));
207 EXPECT_TRUE(f1_.SetRtcpParams(cs, key1, key1_len, cs, key2, key2_len));
208 EXPECT_TRUE(f2_.SetRtcpParams(cs, key2, key2_len, cs, key1, key1_len));
209 EXPECT_TRUE(f1_.IsActive());
210 EXPECT_TRUE(f2_.IsActive());
211 if (rtc::IsGcmCryptoSuite(cs)) {
212 EXPECT_FALSE(f1_.IsExternalAuthActive());
213 EXPECT_FALSE(f2_.IsExternalAuthActive());
214 } else if (enable_external_auth) {
215 EXPECT_TRUE(f1_.IsExternalAuthActive());
216 EXPECT_TRUE(f2_.IsExternalAuthActive());
217 }
218 TestProtectUnprotect(cs_name, cs_name);
219 }
161 cricket::SrtpFilter f1_; 220 cricket::SrtpFilter f1_;
162 cricket::SrtpFilter f2_; 221 cricket::SrtpFilter f2_;
163 int sequence_number_; 222 int sequence_number_;
164 }; 223 };
165 224
166 // Test that we can set up the session and keys properly. 225 // Test that we can set up the session and keys properly.
167 TEST_F(SrtpFilterTest, TestGoodSetupOneCipherSuite) { 226 TEST_F(SrtpFilterTest, TestGoodSetupOneCipherSuite) {
168 EXPECT_TRUE(f1_.SetOffer(MakeVector(kTestCryptoParams1), CS_LOCAL)); 227 EXPECT_TRUE(f1_.SetOffer(MakeVector(kTestCryptoParams1), CS_LOCAL));
169 EXPECT_FALSE(f1_.IsActive()); 228 EXPECT_FALSE(f1_.IsActive());
170 EXPECT_TRUE(f1_.SetAnswer(MakeVector(kTestCryptoParams2), CS_REMOTE)); 229 EXPECT_TRUE(f1_.SetAnswer(MakeVector(kTestCryptoParams2), CS_REMOTE));
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); 599 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80);
541 600
542 // Complete the negotiation. 601 // Complete the negotiation.
543 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); 602 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL));
544 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); 603 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE));
545 604
546 EXPECT_FALSE(f1_.IsActive()); 605 EXPECT_FALSE(f1_.IsActive());
547 EXPECT_FALSE(f2_.IsActive()); 606 EXPECT_FALSE(f2_.IsActive());
548 } 607 }
549 608
609 class SrtpFilterProtectSetParamsDirectTest
610 : public SrtpFilterTest,
611 public testing::WithParamInterface<bool> {
612 };
613
550 // Test directly setting the params with AES_CM_128_HMAC_SHA1_80. 614 // Test directly setting the params with AES_CM_128_HMAC_SHA1_80.
551 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_80) { 615 TEST_P(SrtpFilterProtectSetParamsDirectTest, Test_AES_CM_128_HMAC_SHA1_80) {
552 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 616 bool enable_external_auth = GetParam();
553 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80, 617 TestProtectSetParamsDirect(enable_external_auth, rtc::SRTP_AES128_CM_SHA1_80,
554 kTestKey2, kTestKeyLen)); 618 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen,
555 EXPECT_TRUE(f2_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey2, 619 CS_AES_CM_128_HMAC_SHA1_80);
556 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80,
557 kTestKey1, kTestKeyLen));
558 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1,
559 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80,
560 kTestKey2, kTestKeyLen));
561 EXPECT_TRUE(f2_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey2,
562 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80,
563 kTestKey1, kTestKeyLen));
564 EXPECT_TRUE(f1_.IsActive());
565 EXPECT_TRUE(f2_.IsActive());
566 #if defined(ENABLE_EXTERNAL_AUTH)
567 EXPECT_TRUE(f1_.IsExternalAuthActive());
568 EXPECT_TRUE(f2_.IsExternalAuthActive());
569 #endif
570 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80);
571 } 620 }
572 621
573 // Test directly setting the params with AES_CM_128_HMAC_SHA1_32. 622 // Test directly setting the params with AES_CM_128_HMAC_SHA1_32.
574 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_32) { 623 TEST_P(SrtpFilterProtectSetParamsDirectTest, Test_AES_CM_128_HMAC_SHA1_32) {
575 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, 624 bool enable_external_auth = GetParam();
576 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32, 625 TestProtectSetParamsDirect(enable_external_auth, rtc::SRTP_AES128_CM_SHA1_32,
577 kTestKey2, kTestKeyLen)); 626 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen,
578 EXPECT_TRUE(f2_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey2, 627 CS_AES_CM_128_HMAC_SHA1_32);
579 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
580 kTestKey1, kTestKeyLen));
581 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1,
582 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
583 kTestKey2, kTestKeyLen));
584 EXPECT_TRUE(f2_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey2,
585 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
586 kTestKey1, kTestKeyLen));
587 EXPECT_TRUE(f1_.IsActive());
588 EXPECT_TRUE(f2_.IsActive());
589 #if defined(ENABLE_EXTERNAL_AUTH)
590 EXPECT_TRUE(f1_.IsExternalAuthActive());
591 EXPECT_TRUE(f2_.IsExternalAuthActive());
592 #endif
593 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_32, CS_AES_CM_128_HMAC_SHA1_32);
594 } 628 }
595 629
596 // Test directly setting the params with SRTP_AEAD_AES_128_GCM. 630 // Test directly setting the params with SRTP_AEAD_AES_128_GCM.
597 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_SRTP_AEAD_AES_128_GCM) { 631 TEST_P(SrtpFilterProtectSetParamsDirectTest, Test_SRTP_AEAD_AES_128_GCM) {
598 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AEAD_AES_128_GCM, kTestKeyGcm128_1, 632 bool enable_external_auth = GetParam();
599 kTestKeyGcm128Len, rtc::SRTP_AEAD_AES_128_GCM, 633 TestProtectSetParamsDirect(enable_external_auth, rtc::SRTP_AEAD_AES_128_GCM,
600 kTestKeyGcm128_2, kTestKeyGcm128Len)); 634 kTestKeyGcm128_1, kTestKeyGcm128Len, kTestKeyGcm128_2, kTestKeyGcm128Len,
601 EXPECT_TRUE(f2_.SetRtpParams(rtc::SRTP_AEAD_AES_128_GCM, kTestKeyGcm128_2, 635 CS_AEAD_AES_128_GCM);
602 kTestKeyGcm128Len, rtc::SRTP_AEAD_AES_128_GCM,
603 kTestKeyGcm128_1, kTestKeyGcm128Len));
604 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AEAD_AES_128_GCM, kTestKeyGcm128_1,
605 kTestKeyGcm128Len, rtc::SRTP_AEAD_AES_128_GCM,
606 kTestKeyGcm128_2, kTestKeyGcm128Len));
607 EXPECT_TRUE(f2_.SetRtcpParams(rtc::SRTP_AEAD_AES_128_GCM, kTestKeyGcm128_2,
608 kTestKeyGcm128Len, rtc::SRTP_AEAD_AES_128_GCM,
609 kTestKeyGcm128_1, kTestKeyGcm128Len));
610 EXPECT_TRUE(f1_.IsActive());
611 EXPECT_TRUE(f2_.IsActive());
612 #if defined(ENABLE_EXTERNAL_AUTH)
613 EXPECT_FALSE(f1_.IsExternalAuthActive());
614 EXPECT_FALSE(f2_.IsExternalAuthActive());
615 #endif
616 TestProtectUnprotect(CS_AEAD_AES_128_GCM, CS_AEAD_AES_128_GCM);
617 } 636 }
618 637
619 // Test directly setting the params with SRTP_AEAD_AES_256_GCM. 638 // Test directly setting the params with SRTP_AEAD_AES_256_GCM.
620 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_SRTP_AEAD_AES_256_GCM) { 639 TEST_P(SrtpFilterProtectSetParamsDirectTest, Test_SRTP_AEAD_AES_256_GCM) {
621 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AEAD_AES_256_GCM, kTestKeyGcm256_1, 640 bool enable_external_auth = GetParam();
622 kTestKeyGcm256Len, rtc::SRTP_AEAD_AES_256_GCM, 641 TestProtectSetParamsDirect(enable_external_auth, rtc::SRTP_AEAD_AES_256_GCM,
623 kTestKeyGcm256_2, kTestKeyGcm256Len)); 642 kTestKeyGcm256_1, kTestKeyGcm256Len, kTestKeyGcm256_2, kTestKeyGcm256Len,
624 EXPECT_TRUE(f2_.SetRtpParams(rtc::SRTP_AEAD_AES_256_GCM, kTestKeyGcm256_2, 643 CS_AEAD_AES_256_GCM);
625 kTestKeyGcm256Len, rtc::SRTP_AEAD_AES_256_GCM,
626 kTestKeyGcm256_1, kTestKeyGcm256Len));
627 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AEAD_AES_256_GCM, kTestKeyGcm256_1,
628 kTestKeyGcm256Len, rtc::SRTP_AEAD_AES_256_GCM,
629 kTestKeyGcm256_2, kTestKeyGcm256Len));
630 EXPECT_TRUE(f2_.SetRtcpParams(rtc::SRTP_AEAD_AES_256_GCM, kTestKeyGcm256_2,
631 kTestKeyGcm256Len, rtc::SRTP_AEAD_AES_256_GCM,
632 kTestKeyGcm256_1, kTestKeyGcm256Len));
633 EXPECT_TRUE(f1_.IsActive());
634 EXPECT_TRUE(f2_.IsActive());
635 #if defined(ENABLE_EXTERNAL_AUTH)
636 EXPECT_FALSE(f1_.IsExternalAuthActive());
637 EXPECT_FALSE(f2_.IsExternalAuthActive());
638 #endif
639 TestProtectUnprotect(CS_AEAD_AES_256_GCM, CS_AEAD_AES_256_GCM);
640 } 644 }
641 645
646 // Run all tests both with and without external auth enabled.
647 INSTANTIATE_TEST_CASE_P(ExternalAuth,
648 SrtpFilterProtectSetParamsDirectTest,
649 ::testing::Values(true, false));
650
642 // Test directly setting the params with bogus keys. 651 // Test directly setting the params with bogus keys.
643 TEST_F(SrtpFilterTest, TestSetParamsKeyTooShort) { 652 TEST_F(SrtpFilterTest, TestSetParamsKeyTooShort) {
644 EXPECT_FALSE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 653 EXPECT_FALSE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1,
645 kTestKeyLen - 1, rtc::SRTP_AES128_CM_SHA1_80, 654 kTestKeyLen - 1, rtc::SRTP_AES128_CM_SHA1_80,
646 kTestKey1, kTestKeyLen - 1)); 655 kTestKey1, kTestKeyLen - 1));
647 EXPECT_FALSE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 656 EXPECT_FALSE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1,
648 kTestKeyLen - 1, rtc::SRTP_AES128_CM_SHA1_80, 657 kTestKeyLen - 1, rtc::SRTP_AES128_CM_SHA1_80,
649 kTestKey1, kTestKeyLen - 1)); 658 kTestKey1, kTestKeyLen - 1));
650 } 659 }
651 660
652 #if defined(ENABLE_EXTERNAL_AUTH)
653 TEST_F(SrtpFilterTest, TestGetSendAuthParams) {
654 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1,
655 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
656 kTestKey2, kTestKeyLen));
657 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1,
658 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
659 kTestKey2, kTestKeyLen));
660 // Non-GCM ciphers support external auth.
661 EXPECT_TRUE(f1_.IsExternalAuthActive());
662 uint8_t* auth_key = NULL;
663 int auth_key_len = 0, auth_tag_len = 0;
664 EXPECT_TRUE(f1_.GetRtpAuthParams(&auth_key, &auth_key_len, &auth_tag_len));
665 EXPECT_TRUE(auth_key != NULL);
666 EXPECT_EQ(20, auth_key_len);
667 EXPECT_EQ(4, auth_tag_len);
668 }
669 #endif
670
671 class SrtpSessionTest : public testing::Test { 661 class SrtpSessionTest : public testing::Test {
672 protected: 662 protected:
673 virtual void SetUp() { 663 virtual void SetUp() {
674 rtp_len_ = sizeof(kPcmuFrame); 664 rtp_len_ = sizeof(kPcmuFrame);
675 rtcp_len_ = sizeof(kRtcpReport); 665 rtcp_len_ = sizeof(kRtcpReport);
676 memcpy(rtp_packet_, kPcmuFrame, rtp_len_); 666 memcpy(rtp_packet_, kPcmuFrame, rtp_len_);
677 memcpy(rtcp_packet_, kRtcpReport, rtcp_len_); 667 memcpy(rtcp_packet_, kRtcpReport, rtcp_len_);
678 } 668 }
679 void TestProtectRtp(const std::string& cs) { 669 void TestProtectRtp(const std::string& cs) {
680 int out_len = 0; 670 int out_len = 0;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail); 1003 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail);
1014 EXPECT_EQ(-1, mode_); 1004 EXPECT_EQ(-1, mode_);
1015 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_); 1005 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_);
1016 // Now the error will be triggered again. 1006 // Now the error will be triggered again.
1017 Reset(); 1007 Reset();
1018 rtc::Thread::Current()->SleepMs(210); 1008 rtc::Thread::Current()->SleepMs(210);
1019 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail); 1009 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail);
1020 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); 1010 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
1021 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_); 1011 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_);
1022 } 1012 }
OLDNEW
« no previous file with comments | « webrtc/pc/srtpfilter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698