Skip to content

Commit

Permalink
reorder sdes suites to not prefer gcm
Browse files Browse the repository at this point in the history
BUG=chromium:713701

Change-Id: I1ef00df7a7b86a83ae97d4c7c5f41d85eb60b391
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174803
Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com>
Reviewed-by: Taylor <deadbeef@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31225}
  • Loading branch information
fippo authored and Commit Bot committed May 12, 2020
1 parent 8c7384c commit 1aec2bf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
12 changes: 6 additions & 6 deletions pc/media_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ bool FindMatchingCrypto(const CryptoParamsVec& cryptos,
void GetSupportedAudioSdesCryptoSuites(
const webrtc::CryptoOptions& crypto_options,
std::vector<int>* crypto_suites) {
if (crypto_options.srtp.enable_gcm_crypto_suites) {
crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM);
crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM);
}
if (crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher) {
crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_32);
}
crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80);
if (crypto_options.srtp.enable_gcm_crypto_suites) {
crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM);
crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM);
}
}

void GetSupportedAudioSdesCryptoSuiteNames(
Expand All @@ -202,11 +202,11 @@ void GetSupportedAudioSdesCryptoSuiteNames(
void GetSupportedVideoSdesCryptoSuites(
const webrtc::CryptoOptions& crypto_options,
std::vector<int>* crypto_suites) {
crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80);
if (crypto_options.srtp.enable_gcm_crypto_suites) {
crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM);
crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM);
}
crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80);
}

void GetSupportedVideoSdesCryptoSuiteNames(
Expand All @@ -219,11 +219,11 @@ void GetSupportedVideoSdesCryptoSuiteNames(
void GetSupportedDataSdesCryptoSuites(
const webrtc::CryptoOptions& crypto_options,
std::vector<int>* crypto_suites) {
crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80);
if (crypto_options.srtp.enable_gcm_crypto_suites) {
crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM);
crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM);
}
crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80);
}

void GetSupportedDataSdesCryptoSuiteNames(
Expand Down
28 changes: 28 additions & 0 deletions pc/media_session_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,17 @@ static MediaSessionOptions CreatePlanBMediaSessionOptions() {
return session_options;
}

// prefers GCM SDES crypto suites by removing non-GCM defaults.
void PreferGcmCryptoParameters(CryptoParamsVec* cryptos) {
cryptos->erase(
std::remove_if(cryptos->begin(), cryptos->end(),
[](const cricket::CryptoParams& crypto) {
return crypto.cipher_suite != CS_AEAD_AES_256_GCM &&
crypto.cipher_suite != CS_AEAD_AES_128_GCM;
}),
cryptos->end());
}

// TODO(zhihuang): Most of these tests were written while MediaSessionOptions
// was designed for Plan B SDP, where only one audio "m=" section and one video
// "m=" section could be generated, and ordering couldn't be controlled. Many of
Expand Down Expand Up @@ -698,6 +709,13 @@ class MediaSessionDescriptionFactoryTest : public ::testing::Test {
std::unique_ptr<SessionDescription> offer =
f1_.CreateOffer(offer_opts, NULL);
ASSERT_TRUE(offer.get() != NULL);
if (gcm_offer && gcm_answer) {
for (cricket::ContentInfo& content : offer->contents()) {
auto cryptos = content.media_description()->cryptos();
PreferGcmCryptoParameters(&cryptos);
content.media_description()->set_cryptos(cryptos);
}
}
std::unique_ptr<SessionDescription> answer =
f2_.CreateAnswer(offer.get(), answer_opts, NULL);
const ContentInfo* ac = answer->GetContentByName("audio");
Expand Down Expand Up @@ -1237,6 +1255,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerGcm) {
opts.crypto_options.srtp.enable_gcm_crypto_suites = true;
std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL);
ASSERT_TRUE(offer.get() != NULL);
for (cricket::ContentInfo& content : offer->contents()) {
auto cryptos = content.media_description()->cryptos();
PreferGcmCryptoParameters(&cryptos);
content.media_description()->set_cryptos(cryptos);
}
std::unique_ptr<SessionDescription> answer =
f2_.CreateAnswer(offer.get(), opts, NULL);
const ContentInfo* ac = answer->GetContentByName("audio");
Expand Down Expand Up @@ -1343,6 +1366,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerGcm) {
f2_.set_secure(SEC_ENABLED);
std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL);
ASSERT_TRUE(offer.get() != NULL);
for (cricket::ContentInfo& content : offer->contents()) {
auto cryptos = content.media_description()->cryptos();
PreferGcmCryptoParameters(&cryptos);
content.media_description()->set_cryptos(cryptos);
}
std::unique_ptr<SessionDescription> answer =
f2_.CreateAnswer(offer.get(), opts, NULL);
const ContentInfo* ac = answer->GetContentByName("audio");
Expand Down
18 changes: 14 additions & 4 deletions pc/peer_connection_crypto_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ SdpContentPredicate HaveSdesGcmCryptos(size_t num_crypto_suites) {
if (cryptos.size() != num_crypto_suites) {
return false;
}
const cricket::CryptoParams first_params = cryptos[0];
return first_params.key_params.size() == 67U &&
first_params.cipher_suite == "AEAD_AES_256_GCM";
for (size_t i = 0; i < cryptos.size(); ++i) {
if (cryptos[i].key_params.size() == 67U &&
cryptos[i].cipher_suite == "AEAD_AES_256_GCM")
return true;
}
return false;
};
}

Expand Down Expand Up @@ -333,7 +336,14 @@ TEST_P(PeerConnectionCryptoTest, CorrectCryptoInAnswerWithSdesAndGcm) {
auto caller = CreatePeerConnectionWithAudioVideo(config);
auto callee = CreatePeerConnectionWithAudioVideo(config);

callee->SetRemoteDescription(caller->CreateOffer());
auto offer = caller->CreateOffer();
for (cricket::ContentInfo& content : offer->description()->contents()) {
auto cryptos = content.media_description()->cryptos();
cryptos.erase(cryptos.begin()); // Assumes that non-GCM is the default.
content.media_description()->set_cryptos(cryptos);
}

callee->SetRemoteDescription(std::move(offer));
auto answer = callee->CreateAnswer();
ASSERT_TRUE(answer);

Expand Down

0 comments on commit 1aec2bf

Please sign in to comment.