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

Side by Side Diff: webrtc/pc/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: Disable GCM if ENABLE_EXTERNAL_AUTH is defined. Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « webrtc/pc/channel.h ('k') | webrtc/pc/channel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 break; 548 break;
549 case ST_RTCP: 549 case ST_RTCP:
550 channel = rtcp_transport_channel_; 550 channel = rtcp_transport_channel_;
551 rtcp_socket_options_.push_back( 551 rtcp_socket_options_.push_back(
552 std::pair<rtc::Socket::Option, int>(opt, value)); 552 std::pair<rtc::Socket::Option, int>(opt, value));
553 break; 553 break;
554 } 554 }
555 return channel ? channel->SetOption(opt, value) : -1; 555 return channel ? channel->SetOption(opt, value) : -1;
556 } 556 }
557 557
558 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) {
559 crypto_options_ = crypto_options;
560 return true;
561 }
562
558 void BaseChannel::OnWritableState(TransportChannel* channel) { 563 void BaseChannel::OnWritableState(TransportChannel* channel) {
559 RTC_DCHECK(channel == transport_channel_ || 564 RTC_DCHECK(channel == transport_channel_ ||
560 channel == rtcp_transport_channel_); 565 channel == rtcp_transport_channel_);
561 RTC_DCHECK(network_thread_->IsCurrent()); 566 RTC_DCHECK(network_thread_->IsCurrent());
562 UpdateWritableState_n(); 567 UpdateWritableState_n();
563 } 568 }
564 569
565 void BaseChannel::OnChannelRead(TransportChannel* channel, 570 void BaseChannel::OnChannelRead(TransportChannel* channel,
566 const char* data, size_t len, 571 const char* data, size_t len,
567 const rtc::PacketTime& packet_time, 572 const rtc::PacketTime& packet_time,
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 SignalDtlsSetupFailure(this, rtcp); 962 SignalDtlsSetupFailure(this, rtcp);
958 } 963 }
959 964
960 bool BaseChannel::SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp) { 965 bool BaseChannel::SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp) {
961 std::vector<int> crypto_suites; 966 std::vector<int> crypto_suites;
962 // We always use the default SRTP crypto suites for RTCP, but we may use 967 // We always use the default SRTP crypto suites for RTCP, but we may use
963 // different crypto suites for RTP depending on the media type. 968 // different crypto suites for RTP depending on the media type.
964 if (!rtcp) { 969 if (!rtcp) {
965 GetSrtpCryptoSuites_n(&crypto_suites); 970 GetSrtpCryptoSuites_n(&crypto_suites);
966 } else { 971 } else {
967 GetDefaultSrtpCryptoSuites(&crypto_suites); 972 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites);
968 } 973 }
969 return tc->SetSrtpCryptoSuites(crypto_suites); 974 return tc->SetSrtpCryptoSuites(crypto_suites);
970 } 975 }
971 976
972 bool BaseChannel::ShouldSetupDtlsSrtp_n() const { 977 bool BaseChannel::ShouldSetupDtlsSrtp_n() const {
973 // Since DTLS is applied to all channels, checking RTP should be enough. 978 // Since DTLS is applied to all channels, checking RTP should be enough.
974 return transport_channel_ && transport_channel_->IsDtlsActive(); 979 return transport_channel_ && transport_channel_->IsDtlsActive();
975 } 980 }
976 981
977 // This function returns true if either DTLS-SRTP is not in use 982 // This function returns true if either DTLS-SRTP is not in use
(...skipping 11 matching lines...) Expand all
989 994
990 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { 995 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) {
991 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; 996 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite";
992 return false; 997 return false;
993 } 998 }
994 999
995 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " 1000 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on "
996 << content_name() << " " 1001 << content_name() << " "
997 << PacketType(rtcp_channel); 1002 << PacketType(rtcp_channel);
998 1003
1004 int key_len;
1005 int salt_len;
1006 if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len,
1007 &salt_len)) {
1008 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite;
1009 return false;
1010 }
1011
999 // OK, we're now doing DTLS (RFC 5764) 1012 // OK, we're now doing DTLS (RFC 5764)
1000 std::vector<unsigned char> dtls_buffer(SRTP_MASTER_KEY_KEY_LEN * 2 + 1013 std::vector<unsigned char> dtls_buffer(key_len * 2 + salt_len * 2);
1001 SRTP_MASTER_KEY_SALT_LEN * 2);
1002 1014
1003 // RFC 5705 exporter using the RFC 5764 parameters 1015 // RFC 5705 exporter using the RFC 5764 parameters
1004 if (!channel->ExportKeyingMaterial( 1016 if (!channel->ExportKeyingMaterial(
1005 kDtlsSrtpExporterLabel, 1017 kDtlsSrtpExporterLabel,
1006 NULL, 0, false, 1018 NULL, 0, false,
1007 &dtls_buffer[0], dtls_buffer.size())) { 1019 &dtls_buffer[0], dtls_buffer.size())) {
1008 LOG(LS_WARNING) << "DTLS-SRTP key export failed"; 1020 LOG(LS_WARNING) << "DTLS-SRTP key export failed";
1009 ASSERT(false); // This should never happen 1021 ASSERT(false); // This should never happen
1010 return false; 1022 return false;
1011 } 1023 }
1012 1024
1013 // Sync up the keys with the DTLS-SRTP interface 1025 // Sync up the keys with the DTLS-SRTP interface
1014 std::vector<unsigned char> client_write_key(SRTP_MASTER_KEY_KEY_LEN + 1026 std::vector<unsigned char> client_write_key(key_len + salt_len);
1015 SRTP_MASTER_KEY_SALT_LEN); 1027 std::vector<unsigned char> server_write_key(key_len + salt_len);
1016 std::vector<unsigned char> server_write_key(SRTP_MASTER_KEY_KEY_LEN +
1017 SRTP_MASTER_KEY_SALT_LEN);
1018 size_t offset = 0; 1028 size_t offset = 0;
1019 memcpy(&client_write_key[0], &dtls_buffer[offset], 1029 memcpy(&client_write_key[0], &dtls_buffer[offset], key_len);
1020 SRTP_MASTER_KEY_KEY_LEN); 1030 offset += key_len;
1021 offset += SRTP_MASTER_KEY_KEY_LEN; 1031 memcpy(&server_write_key[0], &dtls_buffer[offset], key_len);
1022 memcpy(&server_write_key[0], &dtls_buffer[offset], 1032 offset += key_len;
1023 SRTP_MASTER_KEY_KEY_LEN); 1033 memcpy(&client_write_key[key_len], &dtls_buffer[offset], salt_len);
1024 offset += SRTP_MASTER_KEY_KEY_LEN; 1034 offset += salt_len;
1025 memcpy(&client_write_key[SRTP_MASTER_KEY_KEY_LEN], 1035 memcpy(&server_write_key[key_len], &dtls_buffer[offset], salt_len);
1026 &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN);
1027 offset += SRTP_MASTER_KEY_SALT_LEN;
1028 memcpy(&server_write_key[SRTP_MASTER_KEY_KEY_LEN],
1029 &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN);
1030 1036
1031 std::vector<unsigned char> *send_key, *recv_key; 1037 std::vector<unsigned char> *send_key, *recv_key;
1032 rtc::SSLRole role; 1038 rtc::SSLRole role;
1033 if (!channel->GetSslRole(&role)) { 1039 if (!channel->GetSslRole(&role)) {
1034 LOG(LS_WARNING) << "GetSslRole failed"; 1040 LOG(LS_WARNING) << "GetSslRole failed";
1035 return false; 1041 return false;
1036 } 1042 }
1037 1043
1038 if (role == rtc::SSL_SERVER) { 1044 if (role == rtc::SSL_SERVER) {
1039 send_key = &server_write_key; 1045 send_key = &server_write_key;
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 SignalMediaMonitor(this, info); 1845 SignalMediaMonitor(this, info);
1840 } 1846 }
1841 1847
1842 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, 1848 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor,
1843 const AudioInfo& info) { 1849 const AudioInfo& info) {
1844 SignalAudioMonitor(this, info); 1850 SignalAudioMonitor(this, info);
1845 } 1851 }
1846 1852
1847 void VoiceChannel::GetSrtpCryptoSuites_n( 1853 void VoiceChannel::GetSrtpCryptoSuites_n(
1848 std::vector<int>* crypto_suites) const { 1854 std::vector<int>* crypto_suites) const {
1849 GetSupportedAudioCryptoSuites(crypto_suites); 1855 GetSupportedAudioCryptoSuites(crypto_options(), crypto_suites);
1850 } 1856 }
1851 1857
1852 VideoChannel::VideoChannel(rtc::Thread* worker_thread, 1858 VideoChannel::VideoChannel(rtc::Thread* worker_thread,
1853 rtc::Thread* network_thread, 1859 rtc::Thread* network_thread,
1854 VideoMediaChannel* media_channel, 1860 VideoMediaChannel* media_channel,
1855 TransportController* transport_controller, 1861 TransportController* transport_controller,
1856 const std::string& content_name, 1862 const std::string& content_name,
1857 bool rtcp) 1863 bool rtcp)
1858 : BaseChannel(worker_thread, 1864 : BaseChannel(worker_thread,
1859 network_thread, 1865 network_thread,
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2100 // TODO(pthatcher): Look into removing duplicate code between 2106 // TODO(pthatcher): Look into removing duplicate code between
2101 // audio, video, and data, perhaps by using templates. 2107 // audio, video, and data, perhaps by using templates.
2102 void VideoChannel::OnMediaMonitorUpdate( 2108 void VideoChannel::OnMediaMonitorUpdate(
2103 VideoMediaChannel* media_channel, const VideoMediaInfo &info) { 2109 VideoMediaChannel* media_channel, const VideoMediaInfo &info) {
2104 ASSERT(media_channel == this->media_channel()); 2110 ASSERT(media_channel == this->media_channel());
2105 SignalMediaMonitor(this, info); 2111 SignalMediaMonitor(this, info);
2106 } 2112 }
2107 2113
2108 void VideoChannel::GetSrtpCryptoSuites_n( 2114 void VideoChannel::GetSrtpCryptoSuites_n(
2109 std::vector<int>* crypto_suites) const { 2115 std::vector<int>* crypto_suites) const {
2110 GetSupportedVideoCryptoSuites(crypto_suites); 2116 GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites);
2111 } 2117 }
2112 2118
2113 DataChannel::DataChannel(rtc::Thread* worker_thread, 2119 DataChannel::DataChannel(rtc::Thread* worker_thread,
2114 rtc::Thread* network_thread, 2120 rtc::Thread* network_thread,
2115 DataMediaChannel* media_channel, 2121 DataMediaChannel* media_channel,
2116 TransportController* transport_controller, 2122 TransportController* transport_controller,
2117 const std::string& content_name, 2123 const std::string& content_name,
2118 bool rtcp) 2124 bool rtcp)
2119 : BaseChannel(worker_thread, 2125 : BaseChannel(worker_thread,
2120 network_thread, 2126 network_thread,
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2413 2419
2414 void DataChannel::OnDataChannelReadyToSend(bool writable) { 2420 void DataChannel::OnDataChannelReadyToSend(bool writable) {
2415 // This is usded for congestion control to indicate that the stream is ready 2421 // This is usded for congestion control to indicate that the stream is ready
2416 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates 2422 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates
2417 // that the transport channel is ready. 2423 // that the transport channel is ready.
2418 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, 2424 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA,
2419 new DataChannelReadyToSendMessageData(writable)); 2425 new DataChannelReadyToSendMessageData(writable));
2420 } 2426 }
2421 2427
2422 void DataChannel::GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const { 2428 void DataChannel::GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const {
2423 GetSupportedDataCryptoSuites(crypto_suites); 2429 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites);
2424 } 2430 }
2425 2431
2426 bool DataChannel::ShouldSetupDtlsSrtp_n() const { 2432 bool DataChannel::ShouldSetupDtlsSrtp_n() const {
2427 return data_channel_type_ == DCT_RTP && BaseChannel::ShouldSetupDtlsSrtp_n(); 2433 return data_channel_type_ == DCT_RTP && BaseChannel::ShouldSetupDtlsSrtp_n();
2428 } 2434 }
2429 2435
2430 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { 2436 void DataChannel::OnStreamClosedRemotely(uint32_t sid) {
2431 rtc::TypedMessageData<uint32_t>* message = 2437 rtc::TypedMessageData<uint32_t>* message =
2432 new rtc::TypedMessageData<uint32_t>(sid); 2438 new rtc::TypedMessageData<uint32_t>(sid);
2433 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, 2439 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY,
2434 message); 2440 message);
2435 } 2441 }
2436 2442
2437 } // namespace cricket 2443 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/pc/channel.h ('k') | webrtc/pc/channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698