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

Unified Diff: talk/session/media/channel.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: Updates after feedback from Peter 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 side-by-side diff with in-line comments
Download patch
Index: talk/session/media/channel.cc
diff --git a/talk/session/media/channel.cc b/talk/session/media/channel.cc
index 91808524e176be6ec0b46bd40042643048cfad59..c7c74e8b8fa78db38715290f6567bdeb093969e7 100644
--- a/talk/session/media/channel.cc
+++ b/talk/session/media/channel.cc
@@ -195,6 +195,7 @@ BaseChannel::BaseChannel(rtc::Thread* thread,
has_received_packet_(false),
dtls_keyed_(false),
secure_required_(false),
+ enable_gcm_crypto_suites_(false),
rtp_abs_sendtime_extn_id_(-1) {
ASSERT(worker_thread_ == rtc::Thread::Current());
LOG(LS_INFO) << "Created channel for " << content_name;
@@ -476,6 +477,11 @@ int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt,
return channel ? channel->SetOption(opt, value) : -1;
}
+bool BaseChannel::SetEnableGcmCryptoSuites(bool enable) {
+ enable_gcm_crypto_suites_ = enable;
+ return true;
+}
+
void BaseChannel::OnWritableState(TransportChannel* channel) {
ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
UpdateWritableState_w();
@@ -841,12 +847,14 @@ void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) {
bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) {
std::vector<int> crypto_suites;
+ MediaSessionOptions options;
+ options.enable_gcm_crypto_suites = enable_gcm_crypto_suites_;
// We always use the default SRTP crypto suites for RTCP, but we may use
// different crypto suites for RTP depending on the media type.
if (!rtcp) {
- GetSrtpCryptoSuites(&crypto_suites);
+ GetSrtpCryptoSuites(&crypto_suites, options);
} else {
- GetDefaultSrtpCryptoSuites(&crypto_suites);
+ GetDefaultSrtpCryptoSuites(&crypto_suites, options);
}
return tc->SetSrtpCryptoSuites(crypto_suites);
}
@@ -877,9 +885,16 @@ bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) {
<< content_name() << " "
<< PacketType(rtcp_channel);
+ int key_len;
+ int salt_len;
+ if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len,
+ &salt_len)) {
+ LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite;
+ return false;
+ }
+
// OK, we're now doing DTLS (RFC 5764)
- std::vector<unsigned char> dtls_buffer(SRTP_MASTER_KEY_KEY_LEN * 2 +
- SRTP_MASTER_KEY_SALT_LEN * 2);
+ std::vector<unsigned char> dtls_buffer(key_len * 2 + salt_len * 2);
// RFC 5705 exporter using the RFC 5764 parameters
if (!channel->ExportKeyingMaterial(
@@ -892,22 +907,16 @@ bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) {
}
// Sync up the keys with the DTLS-SRTP interface
- std::vector<unsigned char> client_write_key(SRTP_MASTER_KEY_KEY_LEN +
- SRTP_MASTER_KEY_SALT_LEN);
- std::vector<unsigned char> server_write_key(SRTP_MASTER_KEY_KEY_LEN +
- SRTP_MASTER_KEY_SALT_LEN);
+ std::vector<unsigned char> client_write_key(key_len + salt_len);
+ std::vector<unsigned char> server_write_key(key_len + salt_len);
size_t offset = 0;
- memcpy(&client_write_key[0], &dtls_buffer[offset],
- SRTP_MASTER_KEY_KEY_LEN);
- offset += SRTP_MASTER_KEY_KEY_LEN;
- memcpy(&server_write_key[0], &dtls_buffer[offset],
- SRTP_MASTER_KEY_KEY_LEN);
- offset += SRTP_MASTER_KEY_KEY_LEN;
- memcpy(&client_write_key[SRTP_MASTER_KEY_KEY_LEN],
- &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN);
- offset += SRTP_MASTER_KEY_SALT_LEN;
- memcpy(&server_write_key[SRTP_MASTER_KEY_KEY_LEN],
- &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN);
+ memcpy(&client_write_key[0], &dtls_buffer[offset], key_len);
+ offset += key_len;
+ memcpy(&server_write_key[0], &dtls_buffer[offset], key_len);
+ offset += key_len;
+ memcpy(&client_write_key[key_len], &dtls_buffer[offset], salt_len);
+ offset += salt_len;
+ memcpy(&server_write_key[key_len], &dtls_buffer[offset], salt_len);
std::vector<unsigned char> *send_key, *recv_key;
rtc::SSLRole role;
@@ -1625,8 +1634,9 @@ void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor,
SignalAudioMonitor(this, info);
}
-void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const {
- GetSupportedAudioCryptoSuites(crypto_suites);
+void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites,
+ const MediaSessionOptions& options) const {
+ GetSupportedAudioCryptoSuites(crypto_suites, options);
}
VideoChannel::VideoChannel(rtc::Thread* thread,
@@ -2016,8 +2026,9 @@ bool VideoChannel::GetLocalSsrc(const VideoCapturer* capturer, uint32_t* ssrc) {
return false;
}
-void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const {
- GetSupportedVideoCryptoSuites(crypto_suites);
+void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites,
+ const MediaSessionOptions& options) const {
+ GetSupportedVideoCryptoSuites(crypto_suites, options);
}
DataChannel::DataChannel(rtc::Thread* thread,
@@ -2325,8 +2336,9 @@ void DataChannel::OnDataChannelReadyToSend(bool writable) {
new DataChannelReadyToSendMessageData(writable));
}
-void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const {
- GetSupportedDataCryptoSuites(crypto_suites);
+void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites,
+ const MediaSessionOptions& options) const {
+ GetSupportedDataCryptoSuites(crypto_suites, options);
}
bool DataChannel::ShouldSetupDtlsSrtp() const {

Powered by Google App Engine
This is Rietveld 408576698