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

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

Issue 2722423003: Improve testing of SRTP external auth code paths. (Closed)
Patch Set: 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
« webrtc/pc/srtpfilter.cc ('K') | « 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) {
Taylor Brandstetter 2017/03/03 02:20:35 nit: Think you meant to use const ref.
joachim 2017/03/03 20:42:57 Done.
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 TestRtpAuthParams(&f1_, cs1);
159 }
133 160
134 EXPECT_TRUE(f2_.ProtectRtp(rtp_packet, rtp_len, 161 EXPECT_TRUE(f2_.ProtectRtp(rtp_packet, rtp_len,
135 static_cast<int>(rtp_buffer.size()), 162 static_cast<int>(rtp_buffer.size()),
136 &out_len)); 163 &out_len));
137 EXPECT_EQ(out_len, rtp_len + rtp_auth_tag_len(cs2)); 164 EXPECT_EQ(out_len, rtp_len + rtp_auth_tag_len(cs2));
138 EXPECT_NE(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); 165 EXPECT_NE(0, memcmp(rtp_packet, original_rtp_packet, rtp_len));
139 EXPECT_TRUE(f1_.UnprotectRtp(rtp_packet, out_len, &out_len)); 166 if (!f2_.IsExternalAuthActive()) {
140 EXPECT_EQ(rtp_len, out_len); 167 EXPECT_TRUE(f1_.UnprotectRtp(rtp_packet, out_len, &out_len));
141 EXPECT_EQ(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); 168 EXPECT_EQ(rtp_len, out_len);
169 EXPECT_EQ(0, memcmp(rtp_packet, original_rtp_packet, rtp_len));
170 } else {
171 TestRtpAuthParams(&f2_, cs2);
Taylor Brandstetter 2017/03/03 02:20:35 Can you leave a comment explaining why this method
joachim 2017/03/03 20:42:57 Done.
172 }
142 173
143 EXPECT_TRUE(f1_.ProtectRtcp(rtcp_packet, rtcp_len, 174 EXPECT_TRUE(f1_.ProtectRtcp(rtcp_packet, rtcp_len,
144 static_cast<int>(rtcp_buffer.size()), 175 static_cast<int>(rtcp_buffer.size()),
145 &out_len)); 176 &out_len));
146 EXPECT_EQ(out_len, rtcp_len + 4 + rtcp_auth_tag_len(cs1)); // NOLINT 177 EXPECT_EQ(out_len, rtcp_len + 4 + rtcp_auth_tag_len(cs1)); // NOLINT
147 EXPECT_NE(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len)); 178 EXPECT_NE(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len));
148 EXPECT_TRUE(f2_.UnprotectRtcp(rtcp_packet, out_len, &out_len)); 179 EXPECT_TRUE(f2_.UnprotectRtcp(rtcp_packet, out_len, &out_len));
149 EXPECT_EQ(rtcp_len, out_len); 180 EXPECT_EQ(rtcp_len, out_len);
150 EXPECT_EQ(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len)); 181 EXPECT_EQ(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len));
151 182
152 EXPECT_TRUE(f2_.ProtectRtcp(rtcp_packet, rtcp_len, 183 EXPECT_TRUE(f2_.ProtectRtcp(rtcp_packet, rtcp_len,
153 static_cast<int>(rtcp_buffer.size()), 184 static_cast<int>(rtcp_buffer.size()),
154 &out_len)); 185 &out_len));
155 EXPECT_EQ(out_len, rtcp_len + 4 + rtcp_auth_tag_len(cs2)); // NOLINT 186 EXPECT_EQ(out_len, rtcp_len + 4 + rtcp_auth_tag_len(cs2)); // NOLINT
156 EXPECT_NE(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len)); 187 EXPECT_NE(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len));
157 EXPECT_TRUE(f1_.UnprotectRtcp(rtcp_packet, out_len, &out_len)); 188 EXPECT_TRUE(f1_.UnprotectRtcp(rtcp_packet, out_len, &out_len));
158 EXPECT_EQ(rtcp_len, out_len); 189 EXPECT_EQ(rtcp_len, out_len);
159 EXPECT_EQ(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len)); 190 EXPECT_EQ(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len));
160 } 191 }
192 void TestProtectSetParamsDirect(bool allow_external_auth, int cs,
193 const uint8_t* key1, int key1_len, const uint8_t* key2, int key2_len,
194 const std::string& cs_name) {
195 EXPECT_EQ(key1_len, key2_len);
196 EXPECT_EQ(cs_name, rtc::SrtpCryptoSuiteToName(cs));
197 f1_.AllowExternalAuthForTest(allow_external_auth);
198 f2_.AllowExternalAuthForTest(allow_external_auth);
199 EXPECT_TRUE(f1_.SetRtpParams(cs, key1, key1_len, cs, key2, key2_len));
200 EXPECT_TRUE(f2_.SetRtpParams(cs, key2, key2_len, cs, key1, key1_len));
201 EXPECT_TRUE(f1_.SetRtcpParams(cs, key1, key1_len, cs, key2, key2_len));
202 EXPECT_TRUE(f2_.SetRtcpParams(cs, key2, key2_len, cs, key1, key1_len));
203 EXPECT_TRUE(f1_.IsActive());
204 EXPECT_TRUE(f2_.IsActive());
205 if (rtc::IsGcmCryptoSuite(cs)) {
206 EXPECT_FALSE(f1_.IsExternalAuthActive());
207 EXPECT_FALSE(f2_.IsExternalAuthActive());
208 } else if (allow_external_auth) {
209 EXPECT_TRUE(f1_.IsExternalAuthActive());
210 EXPECT_TRUE(f2_.IsExternalAuthActive());
211 }
212 TestProtectUnprotect(cs_name, cs_name);
213 }
161 cricket::SrtpFilter f1_; 214 cricket::SrtpFilter f1_;
162 cricket::SrtpFilter f2_; 215 cricket::SrtpFilter f2_;
163 int sequence_number_; 216 int sequence_number_;
164 }; 217 };
165 218
166 // Test that we can set up the session and keys properly. 219 // Test that we can set up the session and keys properly.
167 TEST_F(SrtpFilterTest, TestGoodSetupOneCipherSuite) { 220 TEST_F(SrtpFilterTest, TestGoodSetupOneCipherSuite) {
168 EXPECT_TRUE(f1_.SetOffer(MakeVector(kTestCryptoParams1), CS_LOCAL)); 221 EXPECT_TRUE(f1_.SetOffer(MakeVector(kTestCryptoParams1), CS_LOCAL));
169 EXPECT_FALSE(f1_.IsActive()); 222 EXPECT_FALSE(f1_.IsActive());
170 EXPECT_TRUE(f1_.SetAnswer(MakeVector(kTestCryptoParams2), CS_REMOTE)); 223 EXPECT_TRUE(f1_.SetAnswer(MakeVector(kTestCryptoParams2), CS_REMOTE));
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 // Complete the negotiation. 595 // Complete the negotiation.
543 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); 596 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL));
544 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); 597 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE));
545 598
546 EXPECT_FALSE(f1_.IsActive()); 599 EXPECT_FALSE(f1_.IsActive());
547 EXPECT_FALSE(f2_.IsActive()); 600 EXPECT_FALSE(f2_.IsActive());
548 } 601 }
549 602
550 // Test directly setting the params with AES_CM_128_HMAC_SHA1_80. 603 // Test directly setting the params with AES_CM_128_HMAC_SHA1_80.
551 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_80) { 604 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_80) {
552 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 605 TestProtectSetParamsDirect(false, rtc::SRTP_AES128_CM_SHA1_80,
Taylor Brandstetter 2017/03/03 02:20:35 nit: We often do this: bool external_auth = false
joachim 2017/03/03 20:42:57 Done.
553 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80, 606 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen,
554 kTestKey2, kTestKeyLen)); 607 CS_AES_CM_128_HMAC_SHA1_80);
555 EXPECT_TRUE(f2_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey2, 608 }
556 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80, 609
557 kTestKey1, kTestKeyLen)); 610 TEST_F(SrtpFilterTest,
558 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 611 TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_80_ExternalAuth) {
559 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80, 612 TestProtectSetParamsDirect(true, rtc::SRTP_AES128_CM_SHA1_80,
560 kTestKey2, kTestKeyLen)); 613 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen,
561 EXPECT_TRUE(f2_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey2, 614 CS_AES_CM_128_HMAC_SHA1_80);
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 } 615 }
572 616
573 // Test directly setting the params with AES_CM_128_HMAC_SHA1_32. 617 // Test directly setting the params with AES_CM_128_HMAC_SHA1_32.
574 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_32) { 618 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_32) {
575 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, 619 TestProtectSetParamsDirect(false, rtc::SRTP_AES128_CM_SHA1_32,
576 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32, 620 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen,
577 kTestKey2, kTestKeyLen)); 621 CS_AES_CM_128_HMAC_SHA1_32);
578 EXPECT_TRUE(f2_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey2, 622 }
579 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32, 623
580 kTestKey1, kTestKeyLen)); 624 TEST_F(SrtpFilterTest,
581 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, 625 TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_32_ExternalAuth) {
582 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32, 626 TestProtectSetParamsDirect(true, rtc::SRTP_AES128_CM_SHA1_32,
583 kTestKey2, kTestKeyLen)); 627 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen,
584 EXPECT_TRUE(f2_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey2, 628 CS_AES_CM_128_HMAC_SHA1_32);
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 } 629 }
595 630
596 // Test directly setting the params with SRTP_AEAD_AES_128_GCM. 631 // Test directly setting the params with SRTP_AEAD_AES_128_GCM.
597 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_SRTP_AEAD_AES_128_GCM) { 632 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_SRTP_AEAD_AES_128_GCM) {
598 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AEAD_AES_128_GCM, kTestKeyGcm128_1, 633 TestProtectSetParamsDirect(false, rtc::SRTP_AEAD_AES_128_GCM,
599 kTestKeyGcm128Len, rtc::SRTP_AEAD_AES_128_GCM, 634 kTestKeyGcm128_1, kTestKeyGcm128Len, kTestKeyGcm128_2, kTestKeyGcm128Len,
600 kTestKeyGcm128_2, kTestKeyGcm128Len)); 635 CS_AEAD_AES_128_GCM);
601 EXPECT_TRUE(f2_.SetRtpParams(rtc::SRTP_AEAD_AES_128_GCM, kTestKeyGcm128_2, 636 }
602 kTestKeyGcm128Len, rtc::SRTP_AEAD_AES_128_GCM, 637
603 kTestKeyGcm128_1, kTestKeyGcm128Len)); 638 TEST_F(SrtpFilterTest,
604 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AEAD_AES_128_GCM, kTestKeyGcm128_1, 639 TestProtect_SetParamsDirect_SRTP_AEAD_AES_128_GCM_ExternalAuth) {
605 kTestKeyGcm128Len, rtc::SRTP_AEAD_AES_128_GCM, 640 TestProtectSetParamsDirect(true, rtc::SRTP_AEAD_AES_128_GCM,
606 kTestKeyGcm128_2, kTestKeyGcm128Len)); 641 kTestKeyGcm128_1, kTestKeyGcm128Len, kTestKeyGcm128_2, kTestKeyGcm128Len,
607 EXPECT_TRUE(f2_.SetRtcpParams(rtc::SRTP_AEAD_AES_128_GCM, kTestKeyGcm128_2, 642 CS_AEAD_AES_128_GCM);
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 } 643 }
618 644
619 // Test directly setting the params with SRTP_AEAD_AES_256_GCM. 645 // Test directly setting the params with SRTP_AEAD_AES_256_GCM.
620 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_SRTP_AEAD_AES_256_GCM) { 646 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_SRTP_AEAD_AES_256_GCM) {
621 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AEAD_AES_256_GCM, kTestKeyGcm256_1, 647 TestProtectSetParamsDirect(false, rtc::SRTP_AEAD_AES_256_GCM,
622 kTestKeyGcm256Len, rtc::SRTP_AEAD_AES_256_GCM, 648 kTestKeyGcm256_1, kTestKeyGcm256Len, kTestKeyGcm256_2, kTestKeyGcm256Len,
623 kTestKeyGcm256_2, kTestKeyGcm256Len)); 649 CS_AEAD_AES_256_GCM);
624 EXPECT_TRUE(f2_.SetRtpParams(rtc::SRTP_AEAD_AES_256_GCM, kTestKeyGcm256_2, 650 }
625 kTestKeyGcm256Len, rtc::SRTP_AEAD_AES_256_GCM, 651
626 kTestKeyGcm256_1, kTestKeyGcm256Len)); 652 TEST_F(SrtpFilterTest,
627 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AEAD_AES_256_GCM, kTestKeyGcm256_1, 653 TestProtect_SetParamsDirect_SRTP_AEAD_AES_256_GCM_ExternalAuth) {
628 kTestKeyGcm256Len, rtc::SRTP_AEAD_AES_256_GCM, 654 TestProtectSetParamsDirect(true, rtc::SRTP_AEAD_AES_256_GCM,
629 kTestKeyGcm256_2, kTestKeyGcm256Len)); 655 kTestKeyGcm256_1, kTestKeyGcm256Len, kTestKeyGcm256_2, kTestKeyGcm256Len,
630 EXPECT_TRUE(f2_.SetRtcpParams(rtc::SRTP_AEAD_AES_256_GCM, kTestKeyGcm256_2, 656 CS_AEAD_AES_256_GCM);
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 } 657 }
641 658
642 // Test directly setting the params with bogus keys. 659 // Test directly setting the params with bogus keys.
643 TEST_F(SrtpFilterTest, TestSetParamsKeyTooShort) { 660 TEST_F(SrtpFilterTest, TestSetParamsKeyTooShort) {
644 EXPECT_FALSE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 661 EXPECT_FALSE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1,
645 kTestKeyLen - 1, rtc::SRTP_AES128_CM_SHA1_80, 662 kTestKeyLen - 1, rtc::SRTP_AES128_CM_SHA1_80,
646 kTestKey1, kTestKeyLen - 1)); 663 kTestKey1, kTestKeyLen - 1));
647 EXPECT_FALSE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 664 EXPECT_FALSE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1,
648 kTestKeyLen - 1, rtc::SRTP_AES128_CM_SHA1_80, 665 kTestKeyLen - 1, rtc::SRTP_AES128_CM_SHA1_80,
649 kTestKey1, kTestKeyLen - 1)); 666 kTestKey1, kTestKeyLen - 1));
650 } 667 }
651 668
652 #if defined(ENABLE_EXTERNAL_AUTH)
653 TEST_F(SrtpFilterTest, TestGetSendAuthParams) { 669 TEST_F(SrtpFilterTest, TestGetSendAuthParams) {
Taylor Brandstetter 2017/03/03 02:20:35 Is this test still necessary, now that the above t
joachim 2017/03/03 20:42:57 True, the same is already tested above.
670 f1_.AllowExternalAuthForTest(true);
654 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, 671 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1,
655 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32, 672 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
656 kTestKey2, kTestKeyLen)); 673 kTestKey2, kTestKeyLen));
657 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, 674 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1,
658 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32, 675 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
659 kTestKey2, kTestKeyLen)); 676 kTestKey2, kTestKeyLen));
660 // Non-GCM ciphers support external auth. 677 // Non-GCM ciphers support external auth.
661 EXPECT_TRUE(f1_.IsExternalAuthActive()); 678 EXPECT_TRUE(f1_.IsExternalAuthActive());
662 uint8_t* auth_key = NULL; 679 uint8_t* auth_key = NULL;
663 int auth_key_len = 0, auth_tag_len = 0; 680 int auth_key_len = 0, auth_tag_len = 0;
664 EXPECT_TRUE(f1_.GetRtpAuthParams(&auth_key, &auth_key_len, &auth_tag_len)); 681 EXPECT_TRUE(f1_.GetRtpAuthParams(&auth_key, &auth_key_len, &auth_tag_len));
665 EXPECT_TRUE(auth_key != NULL); 682 EXPECT_TRUE(auth_key != NULL);
666 EXPECT_EQ(20, auth_key_len); 683 EXPECT_EQ(20, auth_key_len);
667 EXPECT_EQ(4, auth_tag_len); 684 EXPECT_EQ(4, auth_tag_len);
668 } 685 }
669 #endif
670 686
671 class SrtpSessionTest : public testing::Test { 687 class SrtpSessionTest : public testing::Test {
672 protected: 688 protected:
673 virtual void SetUp() { 689 virtual void SetUp() {
674 rtp_len_ = sizeof(kPcmuFrame); 690 rtp_len_ = sizeof(kPcmuFrame);
675 rtcp_len_ = sizeof(kRtcpReport); 691 rtcp_len_ = sizeof(kRtcpReport);
676 memcpy(rtp_packet_, kPcmuFrame, rtp_len_); 692 memcpy(rtp_packet_, kPcmuFrame, rtp_len_);
677 memcpy(rtcp_packet_, kRtcpReport, rtcp_len_); 693 memcpy(rtcp_packet_, kRtcpReport, rtcp_len_);
678 } 694 }
679 void TestProtectRtp(const std::string& cs) { 695 void TestProtectRtp(const std::string& cs) {
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail); 1029 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail);
1014 EXPECT_EQ(-1, mode_); 1030 EXPECT_EQ(-1, mode_);
1015 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_); 1031 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_);
1016 // Now the error will be triggered again. 1032 // Now the error will be triggered again.
1017 Reset(); 1033 Reset();
1018 rtc::Thread::Current()->SleepMs(210); 1034 rtc::Thread::Current()->SleepMs(210);
1019 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail); 1035 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail);
1020 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); 1036 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
1021 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_); 1037 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_);
1022 } 1038 }
OLDNEW
« webrtc/pc/srtpfilter.cc ('K') | « webrtc/pc/srtpfilter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698