Index: webrtc/pc/channel.cc |
diff --git a/webrtc/pc/channel.cc b/webrtc/pc/channel.cc |
index 4d47e878b8e2b8c7d7c858c439d822f9d95a4720..afa3c056082db46919e9b5d368cf8399d3ee8954 100644 |
--- a/webrtc/pc/channel.cc |
+++ b/webrtc/pc/channel.cc |
@@ -466,6 +466,11 @@ int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, |
return channel ? channel->SetOption(opt, value) : -1; |
} |
+bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { |
+ crypto_options_ = crypto_options; |
+ return true; |
+} |
+ |
void BaseChannel::OnWritableState(TransportChannel* channel) { |
ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
UpdateWritableState_w(); |
@@ -852,7 +857,7 @@ bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { |
if (!rtcp) { |
GetSrtpCryptoSuites(&crypto_suites); |
} else { |
- GetDefaultSrtpCryptoSuites(&crypto_suites); |
+ GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites); |
} |
return tc->SetSrtpCryptoSuites(crypto_suites); |
} |
@@ -883,9 +888,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( |
@@ -898,22 +910,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; |
@@ -1653,7 +1659,7 @@ void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, |
} |
void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |
- GetSupportedAudioCryptoSuites(crypto_suites); |
+ GetSupportedAudioCryptoSuites(crypto_options(), crypto_suites); |
} |
VideoChannel::VideoChannel(rtc::Thread* thread, |
@@ -1886,7 +1892,7 @@ void VideoChannel::OnMediaMonitorUpdate( |
} |
void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |
- GetSupportedVideoCryptoSuites(crypto_suites); |
+ GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites); |
} |
DataChannel::DataChannel(rtc::Thread* thread, |
@@ -2196,7 +2202,7 @@ void DataChannel::OnDataChannelReadyToSend(bool writable) { |
} |
void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |
- GetSupportedDataCryptoSuites(crypto_suites); |
+ GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); |
} |
bool DataChannel::ShouldSetupDtlsSrtp() const { |