OLD | NEW |
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 |
11 #include <algorithm> | 11 #include <algorithm> |
12 | 12 |
13 #include "pc/srtpfilter.h" | 13 #include "pc/srtpfilter.h" |
14 | 14 |
15 #include "media/base/cryptoparams.h" | 15 #include "media/base/cryptoparams.h" |
| 16 #include "media/base/fakertp.h" |
| 17 #include "p2p/base/sessiondescription.h" |
| 18 #include "pc/srtptestutil.h" |
| 19 #include "rtc_base/buffer.h" |
| 20 #include "rtc_base/byteorder.h" |
| 21 #include "rtc_base/constructormagic.h" |
16 #include "rtc_base/gunit.h" | 22 #include "rtc_base/gunit.h" |
| 23 #include "rtc_base/thread.h" |
17 | 24 |
18 using cricket::CryptoParams; | 25 using cricket::CryptoParams; |
19 using cricket::CS_LOCAL; | 26 using cricket::CS_LOCAL; |
20 using cricket::CS_REMOTE; | 27 using cricket::CS_REMOTE; |
21 | 28 |
22 namespace rtc { | 29 namespace rtc { |
23 | 30 |
| 31 static const uint8_t kTestKeyGcm128_1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ12"; |
| 32 static const uint8_t kTestKeyGcm128_2[] = "21ZYXWVUTSRQPONMLKJIHGFEDCBA"; |
| 33 static const int kTestKeyGcm128Len = 28; // 128 bits key + 96 bits salt. |
| 34 static const uint8_t kTestKeyGcm256_1[] = |
| 35 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr"; |
| 36 static const uint8_t kTestKeyGcm256_2[] = |
| 37 "rqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA"; |
| 38 static const int kTestKeyGcm256Len = 44; // 256 bits key + 96 bits salt. |
24 static const std::string kTestKeyParams1 = | 39 static const std::string kTestKeyParams1 = |
25 "inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz"; | 40 "inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz"; |
26 static const std::string kTestKeyParams2 = | 41 static const std::string kTestKeyParams2 = |
27 "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR"; | 42 "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR"; |
28 static const std::string kTestKeyParams3 = | 43 static const std::string kTestKeyParams3 = |
29 "inline:1234X19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz"; | 44 "inline:1234X19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz"; |
30 static const std::string kTestKeyParams4 = | 45 static const std::string kTestKeyParams4 = |
31 "inline:4567QCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR"; | 46 "inline:4567QCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR"; |
32 static const std::string kTestKeyParamsGcm1 = | 47 static const std::string kTestKeyParamsGcm1 = |
33 "inline:e166KFlKzJsGW0d5apX+rrI05vxbrvMJEzFI14aTDCa63IRTlLK4iH66uOI="; | 48 "inline:e166KFlKzJsGW0d5apX+rrI05vxbrvMJEzFI14aTDCa63IRTlLK4iH66uOI="; |
(...skipping 11 matching lines...) Expand all Loading... |
45 1, "AEAD_AES_256_GCM", kTestKeyParamsGcm1, ""); | 60 1, "AEAD_AES_256_GCM", kTestKeyParamsGcm1, ""); |
46 static const cricket::CryptoParams kTestCryptoParamsGcm2( | 61 static const cricket::CryptoParams kTestCryptoParamsGcm2( |
47 1, "AEAD_AES_256_GCM", kTestKeyParamsGcm2, ""); | 62 1, "AEAD_AES_256_GCM", kTestKeyParamsGcm2, ""); |
48 static const cricket::CryptoParams kTestCryptoParamsGcm3( | 63 static const cricket::CryptoParams kTestCryptoParamsGcm3( |
49 1, "AEAD_AES_128_GCM", kTestKeyParamsGcm3, ""); | 64 1, "AEAD_AES_128_GCM", kTestKeyParamsGcm3, ""); |
50 static const cricket::CryptoParams kTestCryptoParamsGcm4( | 65 static const cricket::CryptoParams kTestCryptoParamsGcm4( |
51 1, "AEAD_AES_128_GCM", kTestKeyParamsGcm4, ""); | 66 1, "AEAD_AES_128_GCM", kTestKeyParamsGcm4, ""); |
52 | 67 |
53 class SrtpFilterTest : public testing::Test { | 68 class SrtpFilterTest : public testing::Test { |
54 protected: | 69 protected: |
55 SrtpFilterTest() {} | 70 SrtpFilterTest() |
| 71 // Need to initialize |sequence_number_|, the value does not matter. |
| 72 : sequence_number_(1) {} |
56 static std::vector<CryptoParams> MakeVector(const CryptoParams& params) { | 73 static std::vector<CryptoParams> MakeVector(const CryptoParams& params) { |
57 std::vector<CryptoParams> vec; | 74 std::vector<CryptoParams> vec; |
58 vec.push_back(params); | 75 vec.push_back(params); |
59 return vec; | 76 return vec; |
60 } | 77 } |
61 | |
62 void TestSetParams(const std::vector<CryptoParams>& params1, | 78 void TestSetParams(const std::vector<CryptoParams>& params1, |
63 const std::vector<CryptoParams>& params2) { | 79 const std::vector<CryptoParams>& params2) { |
64 EXPECT_TRUE(f1_.SetOffer(params1, CS_LOCAL)); | 80 EXPECT_TRUE(f1_.SetOffer(params1, CS_LOCAL)); |
65 EXPECT_TRUE(f2_.SetOffer(params1, CS_REMOTE)); | 81 EXPECT_TRUE(f2_.SetOffer(params1, CS_REMOTE)); |
66 EXPECT_FALSE(f1_.IsActive()); | 82 EXPECT_FALSE(f1_.IsActive()); |
67 EXPECT_FALSE(f2_.IsActive()); | 83 EXPECT_FALSE(f2_.IsActive()); |
68 EXPECT_TRUE(f2_.SetAnswer(params2, CS_LOCAL)); | 84 EXPECT_TRUE(f2_.SetAnswer(params2, CS_LOCAL)); |
69 EXPECT_TRUE(f1_.SetAnswer(params2, CS_REMOTE)); | 85 EXPECT_TRUE(f1_.SetAnswer(params2, CS_REMOTE)); |
70 EXPECT_TRUE(f1_.IsActive()); | 86 EXPECT_TRUE(f1_.IsActive()); |
71 EXPECT_TRUE(f2_.IsActive()); | 87 EXPECT_TRUE(f2_.IsActive()); |
72 } | 88 } |
| 89 void TestRtpAuthParams(cricket::SrtpFilter* filter, const std::string& cs) { |
| 90 int overhead; |
| 91 EXPECT_TRUE(filter->GetSrtpOverhead(&overhead)); |
| 92 switch (SrtpCryptoSuiteFromName(cs)) { |
| 93 case SRTP_AES128_CM_SHA1_32: |
| 94 EXPECT_EQ(32 / 8, overhead); // 32-bit tag. |
| 95 break; |
| 96 case SRTP_AES128_CM_SHA1_80: |
| 97 EXPECT_EQ(80 / 8, overhead); // 80-bit tag. |
| 98 break; |
| 99 default: |
| 100 RTC_NOTREACHED(); |
| 101 break; |
| 102 } |
73 | 103 |
74 void VerifyCryptoParamsMatch(const std::string& cs1, const std::string& cs2) { | 104 uint8_t* auth_key = nullptr; |
75 EXPECT_EQ(rtc::SrtpCryptoSuiteFromName(cs1), f1_.send_cipher_suite()); | 105 int key_len = 0; |
76 EXPECT_EQ(rtc::SrtpCryptoSuiteFromName(cs2), f2_.send_cipher_suite()); | 106 int tag_len = 0; |
77 EXPECT_TRUE(f1_.send_key() == f2_.recv_key()); | 107 EXPECT_TRUE(filter->GetRtpAuthParams(&auth_key, &key_len, &tag_len)); |
78 EXPECT_TRUE(f2_.send_key() == f1_.recv_key()); | 108 EXPECT_NE(nullptr, auth_key); |
| 109 EXPECT_EQ(160 / 8, key_len); // Length of SHA-1 is 160 bits. |
| 110 EXPECT_EQ(overhead, tag_len); |
79 } | 111 } |
| 112 void TestProtectUnprotect(const std::string& cs1, const std::string& cs2) { |
| 113 Buffer rtp_buffer(sizeof(kPcmuFrame) + rtp_auth_tag_len(cs1)); |
| 114 char* rtp_packet = rtp_buffer.data<char>(); |
| 115 char original_rtp_packet[sizeof(kPcmuFrame)]; |
| 116 Buffer rtcp_buffer(sizeof(kRtcpReport) + 4 + rtcp_auth_tag_len(cs2)); |
| 117 char* rtcp_packet = rtcp_buffer.data<char>(); |
| 118 int rtp_len = sizeof(kPcmuFrame), rtcp_len = sizeof(kRtcpReport), out_len; |
| 119 memcpy(rtp_packet, kPcmuFrame, rtp_len); |
| 120 // In order to be able to run this test function multiple times we can not |
| 121 // use the same sequence number twice. Increase the sequence number by one. |
| 122 SetBE16(reinterpret_cast<uint8_t*>(rtp_packet) + 2, ++sequence_number_); |
| 123 memcpy(original_rtp_packet, rtp_packet, rtp_len); |
| 124 memcpy(rtcp_packet, kRtcpReport, rtcp_len); |
80 | 125 |
| 126 EXPECT_TRUE(f1_.ProtectRtp(rtp_packet, rtp_len, |
| 127 static_cast<int>(rtp_buffer.size()), &out_len)); |
| 128 EXPECT_EQ(out_len, rtp_len + rtp_auth_tag_len(cs1)); |
| 129 EXPECT_NE(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); |
| 130 if (!f1_.IsExternalAuthActive()) { |
| 131 EXPECT_TRUE(f2_.UnprotectRtp(rtp_packet, out_len, &out_len)); |
| 132 EXPECT_EQ(rtp_len, out_len); |
| 133 EXPECT_EQ(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); |
| 134 } else { |
| 135 // With external auth enabled, SRTP doesn't write the auth tag and |
| 136 // unprotect would fail. Check accessing the information about the |
| 137 // tag instead, similar to what the actual code would do that relies |
| 138 // on external auth. |
| 139 TestRtpAuthParams(&f1_, cs1); |
| 140 } |
| 141 |
| 142 EXPECT_TRUE(f2_.ProtectRtp(rtp_packet, rtp_len, |
| 143 static_cast<int>(rtp_buffer.size()), &out_len)); |
| 144 EXPECT_EQ(out_len, rtp_len + rtp_auth_tag_len(cs2)); |
| 145 EXPECT_NE(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); |
| 146 if (!f2_.IsExternalAuthActive()) { |
| 147 EXPECT_TRUE(f1_.UnprotectRtp(rtp_packet, out_len, &out_len)); |
| 148 EXPECT_EQ(rtp_len, out_len); |
| 149 EXPECT_EQ(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); |
| 150 } else { |
| 151 TestRtpAuthParams(&f2_, cs2); |
| 152 } |
| 153 |
| 154 EXPECT_TRUE(f1_.ProtectRtcp( |
| 155 rtcp_packet, rtcp_len, static_cast<int>(rtcp_buffer.size()), &out_len)); |
| 156 EXPECT_EQ(out_len, rtcp_len + 4 + rtcp_auth_tag_len(cs1)); // NOLINT |
| 157 EXPECT_NE(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len)); |
| 158 EXPECT_TRUE(f2_.UnprotectRtcp(rtcp_packet, out_len, &out_len)); |
| 159 EXPECT_EQ(rtcp_len, out_len); |
| 160 EXPECT_EQ(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len)); |
| 161 |
| 162 EXPECT_TRUE(f2_.ProtectRtcp( |
| 163 rtcp_packet, rtcp_len, static_cast<int>(rtcp_buffer.size()), &out_len)); |
| 164 EXPECT_EQ(out_len, rtcp_len + 4 + rtcp_auth_tag_len(cs2)); // NOLINT |
| 165 EXPECT_NE(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len)); |
| 166 EXPECT_TRUE(f1_.UnprotectRtcp(rtcp_packet, out_len, &out_len)); |
| 167 EXPECT_EQ(rtcp_len, out_len); |
| 168 EXPECT_EQ(0, memcmp(rtcp_packet, kRtcpReport, rtcp_len)); |
| 169 } |
| 170 void TestProtectUnprotectHeaderEncryption( |
| 171 const std::string& cs1, |
| 172 const std::string& cs2, |
| 173 const std::vector<int>& encrypted_header_ids) { |
| 174 Buffer rtp_buffer(sizeof(kPcmuFrameWithExtensions) + rtp_auth_tag_len(cs1)); |
| 175 char* rtp_packet = rtp_buffer.data<char>(); |
| 176 size_t rtp_packet_size = rtp_buffer.size(); |
| 177 char original_rtp_packet[sizeof(kPcmuFrameWithExtensions)]; |
| 178 size_t original_rtp_packet_size = sizeof(original_rtp_packet); |
| 179 int rtp_len = sizeof(kPcmuFrameWithExtensions), out_len; |
| 180 memcpy(rtp_packet, kPcmuFrameWithExtensions, rtp_len); |
| 181 // In order to be able to run this test function multiple times we can not |
| 182 // use the same sequence number twice. Increase the sequence number by one. |
| 183 SetBE16(reinterpret_cast<uint8_t*>(rtp_packet) + 2, ++sequence_number_); |
| 184 memcpy(original_rtp_packet, rtp_packet, rtp_len); |
| 185 |
| 186 EXPECT_TRUE(f1_.ProtectRtp(rtp_packet, rtp_len, |
| 187 static_cast<int>(rtp_buffer.size()), &out_len)); |
| 188 EXPECT_EQ(out_len, rtp_len + rtp_auth_tag_len(cs1)); |
| 189 EXPECT_NE(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); |
| 190 CompareHeaderExtensions(rtp_packet, rtp_packet_size, original_rtp_packet, |
| 191 original_rtp_packet_size, encrypted_header_ids, |
| 192 false); |
| 193 EXPECT_TRUE(f2_.UnprotectRtp(rtp_packet, out_len, &out_len)); |
| 194 EXPECT_EQ(rtp_len, out_len); |
| 195 EXPECT_EQ(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); |
| 196 CompareHeaderExtensions(rtp_packet, rtp_packet_size, original_rtp_packet, |
| 197 original_rtp_packet_size, encrypted_header_ids, |
| 198 true); |
| 199 |
| 200 EXPECT_TRUE(f2_.ProtectRtp(rtp_packet, rtp_len, |
| 201 static_cast<int>(rtp_buffer.size()), &out_len)); |
| 202 EXPECT_EQ(out_len, rtp_len + rtp_auth_tag_len(cs2)); |
| 203 EXPECT_NE(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); |
| 204 CompareHeaderExtensions(rtp_packet, rtp_packet_size, original_rtp_packet, |
| 205 original_rtp_packet_size, encrypted_header_ids, |
| 206 false); |
| 207 EXPECT_TRUE(f1_.UnprotectRtp(rtp_packet, out_len, &out_len)); |
| 208 EXPECT_EQ(rtp_len, out_len); |
| 209 EXPECT_EQ(0, memcmp(rtp_packet, original_rtp_packet, rtp_len)); |
| 210 CompareHeaderExtensions(rtp_packet, rtp_packet_size, original_rtp_packet, |
| 211 original_rtp_packet_size, encrypted_header_ids, |
| 212 true); |
| 213 } |
| 214 void TestProtectSetParamsDirect(bool enable_external_auth, |
| 215 int cs, |
| 216 const uint8_t* key1, |
| 217 int key1_len, |
| 218 const uint8_t* key2, |
| 219 int key2_len, |
| 220 const std::string& cs_name) { |
| 221 EXPECT_EQ(key1_len, key2_len); |
| 222 EXPECT_EQ(cs_name, SrtpCryptoSuiteToName(cs)); |
| 223 if (enable_external_auth) { |
| 224 f1_.EnableExternalAuth(); |
| 225 f2_.EnableExternalAuth(); |
| 226 } |
| 227 EXPECT_TRUE(f1_.SetRtpParams(cs, key1, key1_len, cs, key2, key2_len)); |
| 228 EXPECT_TRUE(f2_.SetRtpParams(cs, key2, key2_len, cs, key1, key1_len)); |
| 229 EXPECT_TRUE(f1_.SetRtcpParams(cs, key1, key1_len, cs, key2, key2_len)); |
| 230 EXPECT_TRUE(f2_.SetRtcpParams(cs, key2, key2_len, cs, key1, key1_len)); |
| 231 EXPECT_TRUE(f1_.IsActive()); |
| 232 EXPECT_TRUE(f2_.IsActive()); |
| 233 if (IsGcmCryptoSuite(cs)) { |
| 234 EXPECT_FALSE(f1_.IsExternalAuthActive()); |
| 235 EXPECT_FALSE(f2_.IsExternalAuthActive()); |
| 236 } else if (enable_external_auth) { |
| 237 EXPECT_TRUE(f1_.IsExternalAuthActive()); |
| 238 EXPECT_TRUE(f2_.IsExternalAuthActive()); |
| 239 } |
| 240 TestProtectUnprotect(cs_name, cs_name); |
| 241 } |
| 242 void TestProtectSetParamsDirectHeaderEncryption(int cs, |
| 243 const uint8_t* key1, |
| 244 int key1_len, |
| 245 const uint8_t* key2, |
| 246 int key2_len, |
| 247 const std::string& cs_name) { |
| 248 std::vector<int> encrypted_headers; |
| 249 encrypted_headers.push_back(1); |
| 250 // Don't encrypt header ids 2 and 3. |
| 251 encrypted_headers.push_back(4); |
| 252 EXPECT_EQ(key1_len, key2_len); |
| 253 EXPECT_EQ(cs_name, SrtpCryptoSuiteToName(cs)); |
| 254 f1_.SetEncryptedHeaderExtensionIds(CS_LOCAL, encrypted_headers); |
| 255 f1_.SetEncryptedHeaderExtensionIds(CS_REMOTE, encrypted_headers); |
| 256 f2_.SetEncryptedHeaderExtensionIds(CS_LOCAL, encrypted_headers); |
| 257 f2_.SetEncryptedHeaderExtensionIds(CS_REMOTE, encrypted_headers); |
| 258 EXPECT_TRUE(f1_.SetRtpParams(cs, key1, key1_len, cs, key2, key2_len)); |
| 259 EXPECT_TRUE(f2_.SetRtpParams(cs, key2, key2_len, cs, key1, key1_len)); |
| 260 EXPECT_TRUE(f1_.IsActive()); |
| 261 EXPECT_TRUE(f2_.IsActive()); |
| 262 EXPECT_FALSE(f1_.IsExternalAuthActive()); |
| 263 EXPECT_FALSE(f2_.IsExternalAuthActive()); |
| 264 TestProtectUnprotectHeaderEncryption(cs_name, cs_name, encrypted_headers); |
| 265 } |
81 cricket::SrtpFilter f1_; | 266 cricket::SrtpFilter f1_; |
82 cricket::SrtpFilter f2_; | 267 cricket::SrtpFilter f2_; |
| 268 int sequence_number_; |
83 }; | 269 }; |
84 | 270 |
85 // Test that we can set up the session and keys properly. | 271 // Test that we can set up the session and keys properly. |
86 TEST_F(SrtpFilterTest, TestGoodSetupOneCipherSuite) { | 272 TEST_F(SrtpFilterTest, TestGoodSetupOneCipherSuite) { |
87 EXPECT_TRUE(f1_.SetOffer(MakeVector(kTestCryptoParams1), CS_LOCAL)); | 273 EXPECT_TRUE(f1_.SetOffer(MakeVector(kTestCryptoParams1), CS_LOCAL)); |
88 EXPECT_FALSE(f1_.IsActive()); | 274 EXPECT_FALSE(f1_.IsActive()); |
89 EXPECT_TRUE(f1_.SetAnswer(MakeVector(kTestCryptoParams2), CS_REMOTE)); | 275 EXPECT_TRUE(f1_.SetAnswer(MakeVector(kTestCryptoParams2), CS_REMOTE)); |
90 EXPECT_TRUE(f1_.IsActive()); | 276 EXPECT_TRUE(f1_.IsActive()); |
91 } | 277 } |
92 | 278 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 TEST_F(SrtpFilterTest, TestUnsupportedOptions) { | 472 TEST_F(SrtpFilterTest, TestUnsupportedOptions) { |
287 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); | 473 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); |
288 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); | 474 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); |
289 answer[0].key_params = | 475 answer[0].key_params = |
290 "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4"; | 476 "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4"; |
291 EXPECT_TRUE(f1_.SetOffer(offer, CS_LOCAL)); | 477 EXPECT_TRUE(f1_.SetOffer(offer, CS_LOCAL)); |
292 EXPECT_FALSE(f1_.SetAnswer(answer, CS_REMOTE)); | 478 EXPECT_FALSE(f1_.SetAnswer(answer, CS_REMOTE)); |
293 EXPECT_FALSE(f1_.IsActive()); | 479 EXPECT_FALSE(f1_.IsActive()); |
294 } | 480 } |
295 | 481 |
| 482 // Test that we can encrypt/decrypt after setting the same CryptoParams again on |
| 483 // one side. |
| 484 TEST_F(SrtpFilterTest, TestSettingSameKeyOnOneSide) { |
| 485 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); |
| 486 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); |
| 487 TestSetParams(offer, answer); |
| 488 |
| 489 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); |
| 490 |
| 491 // Re-applying the same keys on one end and it should not reset the ROC. |
| 492 EXPECT_TRUE(f2_.SetOffer(offer, CS_REMOTE)); |
| 493 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); |
| 494 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); |
| 495 } |
| 496 |
296 // Test that we can encrypt/decrypt after negotiating AES_CM_128_HMAC_SHA1_80. | 497 // Test that we can encrypt/decrypt after negotiating AES_CM_128_HMAC_SHA1_80. |
297 TEST_F(SrtpFilterTest, TestProtect_AES_CM_128_HMAC_SHA1_80) { | 498 TEST_F(SrtpFilterTest, TestProtect_AES_CM_128_HMAC_SHA1_80) { |
298 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); | 499 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); |
299 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); | 500 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); |
300 offer.push_back(kTestCryptoParams1); | 501 offer.push_back(kTestCryptoParams1); |
301 offer[1].tag = 2; | 502 offer[1].tag = 2; |
302 offer[1].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; | 503 offer[1].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; |
303 TestSetParams(offer, answer); | 504 TestSetParams(offer, answer); |
304 VerifyCryptoParamsMatch(CS_AES_CM_128_HMAC_SHA1_80, | 505 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); |
305 CS_AES_CM_128_HMAC_SHA1_80); | |
306 } | 506 } |
307 | 507 |
308 // Test that we can encrypt/decrypt after negotiating AES_CM_128_HMAC_SHA1_32. | 508 // Test that we can encrypt/decrypt after negotiating AES_CM_128_HMAC_SHA1_32. |
309 TEST_F(SrtpFilterTest, TestProtect_AES_CM_128_HMAC_SHA1_32) { | 509 TEST_F(SrtpFilterTest, TestProtect_AES_CM_128_HMAC_SHA1_32) { |
310 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); | 510 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); |
311 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); | 511 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); |
312 offer.push_back(kTestCryptoParams1); | 512 offer.push_back(kTestCryptoParams1); |
313 offer[1].tag = 2; | 513 offer[1].tag = 2; |
314 offer[1].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; | 514 offer[1].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; |
315 answer[0].tag = 2; | 515 answer[0].tag = 2; |
316 answer[0].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; | 516 answer[0].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; |
317 TestSetParams(offer, answer); | 517 TestSetParams(offer, answer); |
318 VerifyCryptoParamsMatch(CS_AES_CM_128_HMAC_SHA1_32, | 518 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_32, CS_AES_CM_128_HMAC_SHA1_32); |
319 CS_AES_CM_128_HMAC_SHA1_32); | |
320 } | 519 } |
321 | 520 |
322 // Test that we can change encryption parameters. | 521 // Test that we can change encryption parameters. |
323 TEST_F(SrtpFilterTest, TestChangeParameters) { | 522 TEST_F(SrtpFilterTest, TestChangeParameters) { |
324 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); | 523 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); |
325 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); | 524 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); |
326 | 525 |
327 TestSetParams(offer, answer); | 526 TestSetParams(offer, answer); |
328 VerifyCryptoParamsMatch(CS_AES_CM_128_HMAC_SHA1_80, | 527 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); |
329 CS_AES_CM_128_HMAC_SHA1_80); | |
330 | 528 |
331 // Change the key parameters and cipher_suite. | 529 // Change the key parameters and cipher_suite. |
332 offer[0].key_params = kTestKeyParams3; | 530 offer[0].key_params = kTestKeyParams3; |
333 offer[0].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; | 531 offer[0].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; |
334 answer[0].key_params = kTestKeyParams4; | 532 answer[0].key_params = kTestKeyParams4; |
335 answer[0].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; | 533 answer[0].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; |
336 | 534 |
337 EXPECT_TRUE(f1_.SetOffer(offer, CS_LOCAL)); | 535 EXPECT_TRUE(f1_.SetOffer(offer, CS_LOCAL)); |
338 EXPECT_TRUE(f2_.SetOffer(offer, CS_REMOTE)); | 536 EXPECT_TRUE(f2_.SetOffer(offer, CS_REMOTE)); |
339 EXPECT_TRUE(f1_.IsActive()); | 537 EXPECT_TRUE(f1_.IsActive()); |
340 EXPECT_TRUE(f1_.IsActive()); | 538 EXPECT_TRUE(f1_.IsActive()); |
341 | 539 |
342 // Test that the old keys are valid until the negotiation is complete. | 540 // Test that the old keys are valid until the negotiation is complete. |
343 VerifyCryptoParamsMatch(CS_AES_CM_128_HMAC_SHA1_80, | 541 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); |
344 CS_AES_CM_128_HMAC_SHA1_80); | |
345 | 542 |
346 // Complete the negotiation and test that we can still understand each other. | 543 // Complete the negotiation and test that we can still understand each other. |
347 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); | 544 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); |
348 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); | 545 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); |
349 | 546 |
350 VerifyCryptoParamsMatch(CS_AES_CM_128_HMAC_SHA1_32, | 547 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_32, CS_AES_CM_128_HMAC_SHA1_32); |
351 CS_AES_CM_128_HMAC_SHA1_32); | |
352 } | 548 } |
353 | 549 |
354 // Test that we can send and receive provisional answers with crypto enabled. | 550 // Test that we can send and receive provisional answers with crypto enabled. |
355 // Also test that we can change the crypto. | 551 // Also test that we can change the crypto. |
356 TEST_F(SrtpFilterTest, TestProvisionalAnswer) { | 552 TEST_F(SrtpFilterTest, TestProvisionalAnswer) { |
357 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); | 553 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); |
358 offer.push_back(kTestCryptoParams1); | 554 offer.push_back(kTestCryptoParams1); |
359 offer[1].tag = 2; | 555 offer[1].tag = 2; |
360 offer[1].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; | 556 offer[1].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; |
361 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); | 557 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); |
362 | 558 |
363 EXPECT_TRUE(f1_.SetOffer(offer, CS_LOCAL)); | 559 EXPECT_TRUE(f1_.SetOffer(offer, CS_LOCAL)); |
364 EXPECT_TRUE(f2_.SetOffer(offer, CS_REMOTE)); | 560 EXPECT_TRUE(f2_.SetOffer(offer, CS_REMOTE)); |
365 EXPECT_FALSE(f1_.IsActive()); | 561 EXPECT_FALSE(f1_.IsActive()); |
366 EXPECT_FALSE(f2_.IsActive()); | 562 EXPECT_FALSE(f2_.IsActive()); |
367 EXPECT_TRUE(f2_.SetProvisionalAnswer(answer, CS_LOCAL)); | 563 EXPECT_TRUE(f2_.SetProvisionalAnswer(answer, CS_LOCAL)); |
368 EXPECT_TRUE(f1_.SetProvisionalAnswer(answer, CS_REMOTE)); | 564 EXPECT_TRUE(f1_.SetProvisionalAnswer(answer, CS_REMOTE)); |
369 EXPECT_TRUE(f1_.IsActive()); | 565 EXPECT_TRUE(f1_.IsActive()); |
370 EXPECT_TRUE(f2_.IsActive()); | 566 EXPECT_TRUE(f2_.IsActive()); |
371 VerifyCryptoParamsMatch(CS_AES_CM_128_HMAC_SHA1_80, | 567 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); |
372 CS_AES_CM_128_HMAC_SHA1_80); | |
373 | 568 |
374 answer[0].key_params = kTestKeyParams4; | 569 answer[0].key_params = kTestKeyParams4; |
375 answer[0].tag = 2; | 570 answer[0].tag = 2; |
376 answer[0].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; | 571 answer[0].cipher_suite = CS_AES_CM_128_HMAC_SHA1_32; |
377 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); | 572 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); |
378 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); | 573 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); |
379 EXPECT_TRUE(f1_.IsActive()); | 574 EXPECT_TRUE(f1_.IsActive()); |
380 EXPECT_TRUE(f2_.IsActive()); | 575 EXPECT_TRUE(f2_.IsActive()); |
381 VerifyCryptoParamsMatch(CS_AES_CM_128_HMAC_SHA1_32, | 576 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_32, CS_AES_CM_128_HMAC_SHA1_32); |
382 CS_AES_CM_128_HMAC_SHA1_32); | |
383 } | 577 } |
384 | 578 |
385 // Test that a provisional answer doesn't need to contain a crypto. | 579 // Test that a provisional answer doesn't need to contain a crypto. |
386 TEST_F(SrtpFilterTest, TestProvisionalAnswerWithoutCrypto) { | 580 TEST_F(SrtpFilterTest, TestProvisionalAnswerWithoutCrypto) { |
387 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); | 581 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); |
388 std::vector<CryptoParams> answer; | 582 std::vector<CryptoParams> answer; |
389 | 583 |
390 EXPECT_TRUE(f1_.SetOffer(offer, CS_LOCAL)); | 584 EXPECT_TRUE(f1_.SetOffer(offer, CS_LOCAL)); |
391 EXPECT_TRUE(f2_.SetOffer(offer, CS_REMOTE)); | 585 EXPECT_TRUE(f2_.SetOffer(offer, CS_REMOTE)); |
392 EXPECT_FALSE(f1_.IsActive()); | 586 EXPECT_FALSE(f1_.IsActive()); |
393 EXPECT_FALSE(f2_.IsActive()); | 587 EXPECT_FALSE(f2_.IsActive()); |
394 EXPECT_TRUE(f2_.SetProvisionalAnswer(answer, CS_LOCAL)); | 588 EXPECT_TRUE(f2_.SetProvisionalAnswer(answer, CS_LOCAL)); |
395 EXPECT_TRUE(f1_.SetProvisionalAnswer(answer, CS_REMOTE)); | 589 EXPECT_TRUE(f1_.SetProvisionalAnswer(answer, CS_REMOTE)); |
396 EXPECT_FALSE(f1_.IsActive()); | 590 EXPECT_FALSE(f1_.IsActive()); |
397 EXPECT_FALSE(f2_.IsActive()); | 591 EXPECT_FALSE(f2_.IsActive()); |
398 | 592 |
399 answer.push_back(kTestCryptoParams2); | 593 answer.push_back(kTestCryptoParams2); |
400 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); | 594 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); |
401 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); | 595 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); |
402 EXPECT_TRUE(f1_.IsActive()); | 596 EXPECT_TRUE(f1_.IsActive()); |
403 EXPECT_TRUE(f2_.IsActive()); | 597 EXPECT_TRUE(f2_.IsActive()); |
404 VerifyCryptoParamsMatch(CS_AES_CM_128_HMAC_SHA1_80, | 598 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); |
405 CS_AES_CM_128_HMAC_SHA1_80); | |
406 } | 599 } |
407 | 600 |
408 // Test that if we get a new local offer after a provisional answer | 601 // Test that if we get a new local offer after a provisional answer |
409 // with no crypto, that we are in an inactive state. | 602 // with no crypto, that we are in an inactive state. |
410 TEST_F(SrtpFilterTest, TestLocalOfferAfterProvisionalAnswerWithoutCrypto) { | 603 TEST_F(SrtpFilterTest, TestLocalOfferAfterProvisionalAnswerWithoutCrypto) { |
411 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); | 604 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); |
412 std::vector<CryptoParams> answer; | 605 std::vector<CryptoParams> answer; |
413 | 606 |
414 EXPECT_TRUE(f1_.SetOffer(offer, CS_LOCAL)); | 607 EXPECT_TRUE(f1_.SetOffer(offer, CS_LOCAL)); |
415 EXPECT_TRUE(f2_.SetOffer(offer, CS_REMOTE)); | 608 EXPECT_TRUE(f2_.SetOffer(offer, CS_REMOTE)); |
416 EXPECT_TRUE(f1_.SetProvisionalAnswer(answer, CS_REMOTE)); | 609 EXPECT_TRUE(f1_.SetProvisionalAnswer(answer, CS_REMOTE)); |
417 EXPECT_TRUE(f2_.SetProvisionalAnswer(answer, CS_LOCAL)); | 610 EXPECT_TRUE(f2_.SetProvisionalAnswer(answer, CS_LOCAL)); |
418 EXPECT_FALSE(f1_.IsActive()); | 611 EXPECT_FALSE(f1_.IsActive()); |
419 EXPECT_FALSE(f2_.IsActive()); | 612 EXPECT_FALSE(f2_.IsActive()); |
420 // The calls to set an offer after a provisional answer fail, so the | 613 // The calls to set an offer after a provisional answer fail, so the |
421 // state doesn't change. | 614 // state doesn't change. |
422 EXPECT_FALSE(f1_.SetOffer(offer, CS_LOCAL)); | 615 EXPECT_FALSE(f1_.SetOffer(offer, CS_LOCAL)); |
423 EXPECT_FALSE(f2_.SetOffer(offer, CS_REMOTE)); | 616 EXPECT_FALSE(f2_.SetOffer(offer, CS_REMOTE)); |
424 EXPECT_FALSE(f1_.IsActive()); | 617 EXPECT_FALSE(f1_.IsActive()); |
425 EXPECT_FALSE(f2_.IsActive()); | 618 EXPECT_FALSE(f2_.IsActive()); |
426 | 619 |
427 answer.push_back(kTestCryptoParams2); | 620 answer.push_back(kTestCryptoParams2); |
428 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); | 621 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); |
429 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); | 622 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); |
430 EXPECT_TRUE(f1_.IsActive()); | 623 EXPECT_TRUE(f1_.IsActive()); |
431 EXPECT_TRUE(f2_.IsActive()); | 624 EXPECT_TRUE(f2_.IsActive()); |
432 VerifyCryptoParamsMatch(CS_AES_CM_128_HMAC_SHA1_80, | 625 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); |
433 CS_AES_CM_128_HMAC_SHA1_80); | |
434 } | 626 } |
435 | 627 |
436 // Test that we can disable encryption. | 628 // Test that we can disable encryption. |
437 TEST_F(SrtpFilterTest, TestDisableEncryption) { | 629 TEST_F(SrtpFilterTest, TestDisableEncryption) { |
438 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); | 630 std::vector<CryptoParams> offer(MakeVector(kTestCryptoParams1)); |
439 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); | 631 std::vector<CryptoParams> answer(MakeVector(kTestCryptoParams2)); |
440 | 632 |
441 TestSetParams(offer, answer); | 633 TestSetParams(offer, answer); |
442 VerifyCryptoParamsMatch(CS_AES_CM_128_HMAC_SHA1_80, | 634 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); |
443 CS_AES_CM_128_HMAC_SHA1_80); | |
444 | 635 |
445 offer.clear(); | 636 offer.clear(); |
446 answer.clear(); | 637 answer.clear(); |
447 EXPECT_TRUE(f1_.SetOffer(offer, CS_LOCAL)); | 638 EXPECT_TRUE(f1_.SetOffer(offer, CS_LOCAL)); |
448 EXPECT_TRUE(f2_.SetOffer(offer, CS_REMOTE)); | 639 EXPECT_TRUE(f2_.SetOffer(offer, CS_REMOTE)); |
449 EXPECT_TRUE(f1_.IsActive()); | 640 EXPECT_TRUE(f1_.IsActive()); |
450 EXPECT_TRUE(f2_.IsActive()); | 641 EXPECT_TRUE(f2_.IsActive()); |
451 | 642 |
452 // Test that the old keys are valid until the negotiation is complete. | 643 // Test that the old keys are valid until the negotiation is complete. |
453 VerifyCryptoParamsMatch(CS_AES_CM_128_HMAC_SHA1_80, | 644 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); |
454 CS_AES_CM_128_HMAC_SHA1_80); | |
455 | 645 |
456 // Complete the negotiation. | 646 // Complete the negotiation. |
457 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); | 647 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); |
458 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); | 648 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); |
459 | 649 |
460 EXPECT_FALSE(f1_.IsActive()); | 650 EXPECT_FALSE(f1_.IsActive()); |
461 EXPECT_FALSE(f2_.IsActive()); | 651 EXPECT_FALSE(f2_.IsActive()); |
462 } | 652 } |
463 | 653 |
| 654 class SrtpFilterProtectSetParamsDirectTest |
| 655 : public SrtpFilterTest, |
| 656 public testing::WithParamInterface<bool> {}; |
| 657 |
| 658 // Test directly setting the params with AES_CM_128_HMAC_SHA1_80. |
| 659 TEST_P(SrtpFilterProtectSetParamsDirectTest, Test_AES_CM_128_HMAC_SHA1_80) { |
| 660 bool enable_external_auth = GetParam(); |
| 661 TestProtectSetParamsDirect(enable_external_auth, SRTP_AES128_CM_SHA1_80, |
| 662 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen, |
| 663 CS_AES_CM_128_HMAC_SHA1_80); |
| 664 } |
| 665 |
| 666 TEST_F(SrtpFilterTest, |
| 667 TestProtectSetParamsDirectHeaderEncryption_AES_CM_128_HMAC_SHA1_80) { |
| 668 TestProtectSetParamsDirectHeaderEncryption( |
| 669 SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen, |
| 670 CS_AES_CM_128_HMAC_SHA1_80); |
| 671 } |
| 672 |
| 673 // Test directly setting the params with AES_CM_128_HMAC_SHA1_32. |
| 674 TEST_P(SrtpFilterProtectSetParamsDirectTest, Test_AES_CM_128_HMAC_SHA1_32) { |
| 675 bool enable_external_auth = GetParam(); |
| 676 TestProtectSetParamsDirect(enable_external_auth, SRTP_AES128_CM_SHA1_32, |
| 677 kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen, |
| 678 CS_AES_CM_128_HMAC_SHA1_32); |
| 679 } |
| 680 |
| 681 TEST_F(SrtpFilterTest, |
| 682 TestProtectSetParamsDirectHeaderEncryption_AES_CM_128_HMAC_SHA1_32) { |
| 683 TestProtectSetParamsDirectHeaderEncryption( |
| 684 SRTP_AES128_CM_SHA1_32, kTestKey1, kTestKeyLen, kTestKey2, kTestKeyLen, |
| 685 CS_AES_CM_128_HMAC_SHA1_32); |
| 686 } |
| 687 |
| 688 // Test directly setting the params with SRTP_AEAD_AES_128_GCM. |
| 689 TEST_P(SrtpFilterProtectSetParamsDirectTest, Test_SRTP_AEAD_AES_128_GCM) { |
| 690 bool enable_external_auth = GetParam(); |
| 691 TestProtectSetParamsDirect(enable_external_auth, SRTP_AEAD_AES_128_GCM, |
| 692 kTestKeyGcm128_1, kTestKeyGcm128Len, |
| 693 kTestKeyGcm128_2, kTestKeyGcm128Len, |
| 694 CS_AEAD_AES_128_GCM); |
| 695 } |
| 696 |
| 697 TEST_F(SrtpFilterTest, |
| 698 TestProtectSetParamsDirectHeaderEncryption_SRTP_AEAD_AES_128_GCM) { |
| 699 TestProtectSetParamsDirectHeaderEncryption( |
| 700 SRTP_AEAD_AES_128_GCM, kTestKeyGcm128_1, kTestKeyGcm128Len, |
| 701 kTestKeyGcm128_2, kTestKeyGcm128Len, CS_AEAD_AES_128_GCM); |
| 702 } |
| 703 |
| 704 // Test directly setting the params with SRTP_AEAD_AES_256_GCM. |
| 705 TEST_P(SrtpFilterProtectSetParamsDirectTest, Test_SRTP_AEAD_AES_256_GCM) { |
| 706 bool enable_external_auth = GetParam(); |
| 707 TestProtectSetParamsDirect(enable_external_auth, SRTP_AEAD_AES_256_GCM, |
| 708 kTestKeyGcm256_1, kTestKeyGcm256Len, |
| 709 kTestKeyGcm256_2, kTestKeyGcm256Len, |
| 710 CS_AEAD_AES_256_GCM); |
| 711 } |
| 712 |
| 713 TEST_F(SrtpFilterTest, |
| 714 TestProtectSetParamsDirectHeaderEncryption_SRTP_AEAD_AES_256_GCM) { |
| 715 TestProtectSetParamsDirectHeaderEncryption( |
| 716 SRTP_AEAD_AES_256_GCM, kTestKeyGcm256_1, kTestKeyGcm256Len, |
| 717 kTestKeyGcm256_2, kTestKeyGcm256Len, CS_AEAD_AES_256_GCM); |
| 718 } |
| 719 |
| 720 // Run all tests both with and without external auth enabled. |
| 721 INSTANTIATE_TEST_CASE_P(ExternalAuth, |
| 722 SrtpFilterProtectSetParamsDirectTest, |
| 723 ::testing::Values(true, false)); |
| 724 |
| 725 // Test directly setting the params with bogus keys. |
| 726 TEST_F(SrtpFilterTest, TestSetParamsKeyTooShort) { |
| 727 EXPECT_FALSE(f1_.SetRtpParams(SRTP_AES128_CM_SHA1_80, kTestKey1, |
| 728 kTestKeyLen - 1, SRTP_AES128_CM_SHA1_80, |
| 729 kTestKey1, kTestKeyLen - 1)); |
| 730 EXPECT_FALSE(f1_.SetRtcpParams(SRTP_AES128_CM_SHA1_80, kTestKey1, |
| 731 kTestKeyLen - 1, SRTP_AES128_CM_SHA1_80, |
| 732 kTestKey1, kTestKeyLen - 1)); |
| 733 } |
| 734 |
464 } // namespace rtc | 735 } // namespace rtc |
OLD | NEW |