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

Side by Side Diff: talk/session/media/channel_unittest.cc

Issue 1528843005: Add support for GCM cipher suites from RFC 7714. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added PeerConnection tests using GCM ciphers, fixed passing of flag through DtlsTransportChannel. Created 5 years 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
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2009 Google Inc. 3 * Copyright 2009 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 rtc::StreamInterface* Open(const std::string& path) { 118 rtc::StreamInterface* Open(const std::string& path) {
119 return rtc::Filesystem::OpenFile( 119 return rtc::Filesystem::OpenFile(
120 rtc::Pathname(path), "wb"); 120 rtc::Pathname(path), "wb");
121 } 121 }
122 122
123 // Base class for Voice/VideoChannel tests 123 // Base class for Voice/VideoChannel tests
124 template<class T> 124 template<class T>
125 class ChannelTest : public testing::Test, public sigslot::has_slots<> { 125 class ChannelTest : public testing::Test, public sigslot::has_slots<> {
126 public: 126 public:
127 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8, 127 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
128 DTLS = 0x10 }; 128 DTLS = 0x10, GCM_CIPHER = 0x20 };
129 129
130 ChannelTest(bool verify_playout, 130 ChannelTest(bool verify_playout,
131 const uint8_t* rtp_data, 131 const uint8_t* rtp_data,
132 int rtp_len, 132 int rtp_len,
133 const uint8_t* rtcp_data, 133 const uint8_t* rtcp_data,
134 int rtcp_len) 134 int rtcp_len)
135 : verify_playout_(verify_playout), 135 : verify_playout_(verify_playout),
136 transport_controller1_(cricket::ICEROLE_CONTROLLING), 136 transport_controller1_(cricket::ICEROLE_CONTROLLING),
137 transport_controller2_(cricket::ICEROLE_CONTROLLED), 137 transport_controller2_(cricket::ICEROLE_CONTROLLED),
138 media_channel1_(NULL), 138 media_channel1_(NULL),
139 media_channel2_(NULL), 139 media_channel2_(NULL),
140 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len), 140 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
141 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len), 141 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
142 media_info_callbacks1_(), 142 media_info_callbacks1_(),
143 media_info_callbacks2_() {} 143 media_info_callbacks2_() {}
144 144
145 void CreateChannels(int flags1, int flags2) { 145 void CreateChannels(int flags1, int flags2) {
146 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()), 146 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
147 new typename T::MediaChannel(NULL, typename T::Options()), 147 new typename T::MediaChannel(NULL, typename T::Options()),
148 flags1, flags2, rtc::Thread::Current()); 148 flags1, flags2, rtc::Thread::Current());
149 } 149 }
150 void CreateChannels( 150 void CreateChannels(
151 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2, 151 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
152 int flags1, int flags2, rtc::Thread* thread) { 152 int flags1, int flags2, rtc::Thread* thread) {
153 media_channel1_ = ch1; 153 media_channel1_ = ch1;
154 media_channel2_ = ch2; 154 media_channel2_ = ch2;
155 transport_controller1_.SetEnableGcmCiphers((flags1 & GCM_CIPHER) != 0);
156 transport_controller2_.SetEnableGcmCiphers((flags2 & GCM_CIPHER) != 0);
155 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, 157 channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
156 &transport_controller1_, 158 &transport_controller1_,
157 (flags1 & RTCP) != 0)); 159 (flags1 & RTCP) != 0));
158 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, 160 channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
159 &transport_controller2_, 161 &transport_controller2_,
160 (flags2 & RTCP) != 0)); 162 (flags2 & RTCP) != 0));
161 channel1_->SignalMediaMonitor.connect( 163 channel1_->SignalMediaMonitor.connect(
162 this, &ChannelTest<T>::OnMediaMonitor); 164 this, &ChannelTest<T>::OnMediaMonitor);
163 channel2_->SignalMediaMonitor.connect( 165 channel2_->SignalMediaMonitor.connect(
164 this, &ChannelTest<T>::OnMediaMonitor); 166 this, &ChannelTest<T>::OnMediaMonitor);
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 } 394 }
393 bool CheckNoRtp2() { 395 bool CheckNoRtp2() {
394 return media_channel2_->CheckNoRtp(); 396 return media_channel2_->CheckNoRtp();
395 } 397 }
396 bool CheckNoRtcp1() { 398 bool CheckNoRtcp1() {
397 return media_channel1_->CheckNoRtcp(); 399 return media_channel1_->CheckNoRtcp();
398 } 400 }
399 bool CheckNoRtcp2() { 401 bool CheckNoRtcp2() {
400 return media_channel2_->CheckNoRtcp(); 402 return media_channel2_->CheckNoRtcp();
401 } 403 }
404 bool CheckGcmCipher(typename T::Channel* channel, int flags) {
405 int suite;
406 if (!channel->transport_channel()->GetSrtpCryptoSuite(&suite)) {
407 return false;
408 }
409
410 if (flags & GCM_CIPHER) {
411 return (suite == rtc::SRTP_AEAD_AES_128_GCM ||
412 suite == rtc::SRTP_AEAD_AES_256_GCM);
413 } else {
414 return (suite == rtc::SRTP_AES128_CM_SHA1_80 ||
415 suite == rtc::SRTP_AES128_CM_SHA1_32);
416 }
417 }
402 418
403 void CreateContent(int flags, 419 void CreateContent(int flags,
404 const cricket::AudioCodec& audio_codec, 420 const cricket::AudioCodec& audio_codec,
405 const cricket::VideoCodec& video_codec, 421 const cricket::VideoCodec& video_codec,
406 typename T::Content* content) { 422 typename T::Content* content) {
407 // overridden in specialized classes 423 // overridden in specialized classes
408 } 424 }
409 void CopyContent(const typename T::Content& source, 425 void CopyContent(const typename T::Content& source,
410 typename T::Content* content) { 426 typename T::Content* content) {
411 // overridden in specialized classes 427 // overridden in specialized classes
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 EXPECT_EQ(1U, GetTransport1()->channels().size()); 1255 EXPECT_EQ(1U, GetTransport1()->channels().size());
1240 EXPECT_TRUE(SendRtcp1()); 1256 EXPECT_TRUE(SendRtcp1());
1241 EXPECT_TRUE(CheckRtcp2()); 1257 EXPECT_TRUE(CheckRtcp2());
1242 EXPECT_TRUE(SendRtcp2()); 1258 EXPECT_TRUE(SendRtcp2());
1243 EXPECT_TRUE(CheckRtcp1()); 1259 EXPECT_TRUE(CheckRtcp1());
1244 } 1260 }
1245 1261
1246 // Test that we properly send SRTP with RTCP in both directions. 1262 // Test that we properly send SRTP with RTCP in both directions.
1247 // You can pass in DTLS and/or RTCP_MUX as flags. 1263 // You can pass in DTLS and/or RTCP_MUX as flags.
1248 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) { 1264 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1249 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0); 1265 ASSERT((flags1_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
1250 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0); 1266 ASSERT((flags2_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
1251 1267
1252 int flags1 = RTCP | SECURE | flags1_in; 1268 int flags1 = RTCP | SECURE | flags1_in;
1253 int flags2 = RTCP | SECURE | flags2_in; 1269 int flags2 = RTCP | SECURE | flags2_in;
1254 bool dtls1 = !!(flags1_in & DTLS); 1270 bool dtls1 = !!(flags1_in & DTLS);
1255 bool dtls2 = !!(flags2_in & DTLS); 1271 bool dtls2 = !!(flags2_in & DTLS);
1256 CreateChannels(flags1, flags2); 1272 CreateChannels(flags1, flags2);
1257 EXPECT_FALSE(channel1_->secure()); 1273 EXPECT_FALSE(channel1_->secure());
1258 EXPECT_FALSE(channel2_->secure()); 1274 EXPECT_FALSE(channel2_->secure());
1259 EXPECT_TRUE(SendInitiate()); 1275 EXPECT_TRUE(SendInitiate());
1260 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout); 1276 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1261 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout); 1277 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1262 EXPECT_TRUE(SendAccept()); 1278 EXPECT_TRUE(SendAccept());
1263 EXPECT_TRUE(channel1_->secure()); 1279 EXPECT_TRUE(channel1_->secure());
1264 EXPECT_TRUE(channel2_->secure()); 1280 EXPECT_TRUE(channel2_->secure());
1265 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls()); 1281 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1266 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls()); 1282 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1283 // A GCM cipher is only used if both channels support GCM ciphers.
1284 int common_gcm_flags = (flags1 & GCM_CIPHER) & (flags2 & GCM_CIPHER);
1285 EXPECT_TRUE(CheckGcmCipher(channel1_.get(), common_gcm_flags));
1286 EXPECT_TRUE(CheckGcmCipher(channel2_.get(), common_gcm_flags));
1267 EXPECT_TRUE(SendRtp1()); 1287 EXPECT_TRUE(SendRtp1());
1268 EXPECT_TRUE(SendRtp2()); 1288 EXPECT_TRUE(SendRtp2());
1269 EXPECT_TRUE(SendRtcp1()); 1289 EXPECT_TRUE(SendRtcp1());
1270 EXPECT_TRUE(SendRtcp2()); 1290 EXPECT_TRUE(SendRtcp2());
1271 EXPECT_TRUE(CheckRtp1()); 1291 EXPECT_TRUE(CheckRtp1());
1272 EXPECT_TRUE(CheckRtp2()); 1292 EXPECT_TRUE(CheckRtp2());
1273 EXPECT_TRUE(CheckNoRtp1()); 1293 EXPECT_TRUE(CheckNoRtp1());
1274 EXPECT_TRUE(CheckNoRtp2()); 1294 EXPECT_TRUE(CheckNoRtp2());
1275 EXPECT_TRUE(CheckRtcp1()); 1295 EXPECT_TRUE(CheckRtcp1());
1276 EXPECT_TRUE(CheckRtcp2()); 1296 EXPECT_TRUE(CheckRtcp2());
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) { 2100 TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2081 MAYBE_SKIP_TEST(HaveDtlsSrtp); 2101 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2082 Base::SendSrtpToSrtp(DTLS, 0); 2102 Base::SendSrtpToSrtp(DTLS, 0);
2083 } 2103 }
2084 2104
2085 TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) { 2105 TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2086 MAYBE_SKIP_TEST(HaveDtlsSrtp); 2106 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2087 Base::SendSrtpToSrtp(DTLS, DTLS); 2107 Base::SendSrtpToSrtp(DTLS, DTLS);
2088 } 2108 }
2089 2109
2110 TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2111 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2112 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2113 }
2114
2115 TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2116 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2117 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2118 }
2119
2120 TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2121 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2122 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2123 }
2124
2090 TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) { 2125 TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2091 MAYBE_SKIP_TEST(HaveDtlsSrtp); 2126 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2092 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX); 2127 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2093 } 2128 }
2094 2129
2095 TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) { 2130 TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2096 Base::SendEarlyMediaUsingRtcpMuxSrtp(); 2131 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2097 } 2132 }
2098 2133
2099 TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) { 2134 TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
2416 TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) { 2451 TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2417 MAYBE_SKIP_TEST(HaveDtlsSrtp); 2452 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2418 Base::SendSrtpToSrtp(DTLS, 0); 2453 Base::SendSrtpToSrtp(DTLS, 0);
2419 } 2454 }
2420 2455
2421 TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) { 2456 TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2422 MAYBE_SKIP_TEST(HaveDtlsSrtp); 2457 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2423 Base::SendSrtpToSrtp(DTLS, DTLS); 2458 Base::SendSrtpToSrtp(DTLS, DTLS);
2424 } 2459 }
2425 2460
2461 TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2462 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2463 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2464 }
2465
2466 TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2467 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2468 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2469 }
2470
2471 TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2472 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2473 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2474 }
2475
2426 TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) { 2476 TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2427 MAYBE_SKIP_TEST(HaveDtlsSrtp); 2477 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2428 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX); 2478 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2429 } 2479 }
2430 2480
2431 TEST_F(VideoChannelTest, SendSrtcpMux) { 2481 TEST_F(VideoChannelTest, SendSrtcpMux) {
2432 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX); 2482 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2433 } 2483 }
2434 2484
2435 TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) { 2485 TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
2770 }; 2820 };
2771 rtc::Buffer payload(data, 3); 2821 rtc::Buffer payload(data, 3);
2772 cricket::SendDataResult result; 2822 cricket::SendDataResult result;
2773 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); 2823 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2774 EXPECT_EQ(params.ssrc, 2824 EXPECT_EQ(params.ssrc,
2775 media_channel1_->last_sent_data_params().ssrc); 2825 media_channel1_->last_sent_data_params().ssrc);
2776 EXPECT_EQ("foo", media_channel1_->last_sent_data()); 2826 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2777 } 2827 }
2778 2828
2779 // TODO(pthatcher): TestSetReceiver? 2829 // TODO(pthatcher): TestSetReceiver?
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698