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

Unified 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: Rebased Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: talk/session/media/channel_unittest.cc
diff --git a/talk/session/media/channel_unittest.cc b/talk/session/media/channel_unittest.cc
index 6b1d66fe39c1408d96a6d658b100c4c0da4dbec8..bdd6fbc33de6dc471e51f5a92c51f2b26f8ce263 100644
--- a/talk/session/media/channel_unittest.cc
+++ b/talk/session/media/channel_unittest.cc
@@ -125,7 +125,7 @@ template<class T>
class ChannelTest : public testing::Test, public sigslot::has_slots<> {
public:
enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
- DTLS = 0x10 };
+ DTLS = 0x10, GCM_CIPHER = 0x20 };
ChannelTest(bool verify_playout,
const uint8_t* rtp_data,
@@ -153,11 +153,9 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
media_channel1_ = ch1;
media_channel2_ = ch2;
channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
- &transport_controller1_,
- (flags1 & RTCP) != 0));
+ &transport_controller1_, flags1));
channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
- &transport_controller2_,
- (flags2 & RTCP) != 0));
+ &transport_controller2_, flags2));
channel1_->SignalMediaMonitor.connect(
this, &ChannelTest<T>::OnMediaMonitor);
channel2_->SignalMediaMonitor.connect(
@@ -205,9 +203,13 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
cricket::MediaEngineInterface* engine,
typename T::MediaChannel* ch,
cricket::TransportController* transport_controller,
- bool rtcp) {
+ int flags) {
typename T::Channel* channel = new typename T::Channel(
- thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp);
+ thread, engine, ch, transport_controller, cricket::CN_AUDIO,
+ (flags & RTCP) != 0);
+ rtc::CryptoOptions crypto_options;
+ crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
+ channel->SetCryptoOptions(crypto_options);
if (!channel->Init()) {
delete channel;
channel = NULL;
@@ -397,6 +399,20 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
bool CheckNoRtcp2() {
return media_channel2_->CheckNoRtcp();
}
+ bool CheckGcmCipher(typename T::Channel* channel, int flags) {
+ int suite;
+ if (!channel->transport_channel()->GetSrtpCryptoSuite(&suite)) {
+ return false;
+ }
+
+ if (flags & GCM_CIPHER) {
+ return (suite == rtc::SRTP_AEAD_AES_128_GCM ||
+ suite == rtc::SRTP_AEAD_AES_256_GCM);
+ } else {
+ return (suite == rtc::SRTP_AES128_CM_SHA1_80 ||
+ suite == rtc::SRTP_AES128_CM_SHA1_32);
+ }
+ }
void CreateContent(int flags,
const cricket::AudioCodec& audio_codec,
@@ -1244,8 +1260,8 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
// Test that we properly send SRTP with RTCP in both directions.
// You can pass in DTLS and/or RTCP_MUX as flags.
void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
- ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
- ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
+ ASSERT((flags1_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
+ ASSERT((flags2_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
int flags1 = RTCP | SECURE | flags1_in;
int flags2 = RTCP | SECURE | flags2_in;
@@ -1262,6 +1278,10 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
EXPECT_TRUE(channel2_->secure());
EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
+ // A GCM cipher is only used if both channels support GCM ciphers.
+ int common_gcm_flags = (flags1 & GCM_CIPHER) & (flags2 & GCM_CIPHER);
+ EXPECT_TRUE(CheckGcmCipher(channel1_.get(), common_gcm_flags));
+ EXPECT_TRUE(CheckGcmCipher(channel2_.get(), common_gcm_flags));
EXPECT_TRUE(SendRtp1());
EXPECT_TRUE(SendRtp2());
EXPECT_TRUE(SendRtcp1());
@@ -1863,9 +1883,13 @@ cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
cricket::MediaEngineInterface* engine,
cricket::FakeVideoMediaChannel* ch,
cricket::TransportController* transport_controller,
- bool rtcp) {
+ int flags) {
cricket::VideoChannel* channel = new cricket::VideoChannel(
- thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
+ thread, ch, transport_controller, cricket::CN_VIDEO,
+ (flags & RTCP) != 0);
+ rtc::CryptoOptions crypto_options;
+ crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
+ channel->SetCryptoOptions(crypto_options);
if (!channel->Init()) {
delete channel;
channel = NULL;
@@ -2085,6 +2109,21 @@ TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
Base::SendSrtpToSrtp(DTLS, DTLS);
}
+TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
+ MAYBE_SKIP_TEST(HaveDtlsSrtp);
+ Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
+}
+
+TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
+ MAYBE_SKIP_TEST(HaveDtlsSrtp);
+ Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
+}
+
+TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
+ MAYBE_SKIP_TEST(HaveDtlsSrtp);
+ Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
+}
+
TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
MAYBE_SKIP_TEST(HaveDtlsSrtp);
Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
@@ -2421,6 +2460,21 @@ TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
Base::SendSrtpToSrtp(DTLS, DTLS);
}
+TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
+ MAYBE_SKIP_TEST(HaveDtlsSrtp);
+ Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
+}
+
+TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
+ MAYBE_SKIP_TEST(HaveDtlsSrtp);
+ Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
+}
+
+TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
+ MAYBE_SKIP_TEST(HaveDtlsSrtp);
+ Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
+}
+
TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
MAYBE_SKIP_TEST(HaveDtlsSrtp);
Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
@@ -2585,9 +2639,13 @@ cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
cricket::MediaEngineInterface* engine,
cricket::FakeDataMediaChannel* ch,
cricket::TransportController* transport_controller,
- bool rtcp) {
+ int flags) {
cricket::DataChannel* channel = new cricket::DataChannel(
- thread, ch, transport_controller, cricket::CN_DATA, rtcp);
+ thread, ch, transport_controller, cricket::CN_DATA,
+ (flags & RTCP) != 0);
+ rtc::CryptoOptions crypto_options;
+ crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
+ channel->SetCryptoOptions(crypto_options);
if (!channel->Init()) {
delete channel;
channel = NULL;

Powered by Google App Engine
This is Rietveld 408576698