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