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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2004 Google Inc. 3 * Copyright 2004 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 enabled_(false), 188 enabled_(false),
189 writable_(false), 189 writable_(false),
190 rtp_ready_to_send_(false), 190 rtp_ready_to_send_(false),
191 rtcp_ready_to_send_(false), 191 rtcp_ready_to_send_(false),
192 was_ever_writable_(false), 192 was_ever_writable_(false),
193 local_content_direction_(MD_INACTIVE), 193 local_content_direction_(MD_INACTIVE),
194 remote_content_direction_(MD_INACTIVE), 194 remote_content_direction_(MD_INACTIVE),
195 has_received_packet_(false), 195 has_received_packet_(false),
196 dtls_keyed_(false), 196 dtls_keyed_(false),
197 secure_required_(false), 197 secure_required_(false),
198 enable_gcm_crypto_suites_(false),
198 rtp_abs_sendtime_extn_id_(-1) { 199 rtp_abs_sendtime_extn_id_(-1) {
199 ASSERT(worker_thread_ == rtc::Thread::Current()); 200 ASSERT(worker_thread_ == rtc::Thread::Current());
200 LOG(LS_INFO) << "Created channel for " << content_name; 201 LOG(LS_INFO) << "Created channel for " << content_name;
201 } 202 }
202 203
203 BaseChannel::~BaseChannel() { 204 BaseChannel::~BaseChannel() {
204 ASSERT(worker_thread_ == rtc::Thread::Current()); 205 ASSERT(worker_thread_ == rtc::Thread::Current());
205 Deinit(); 206 Deinit();
206 StopConnectionMonitor(); 207 StopConnectionMonitor();
207 FlushRtcpMessages(); // Send any outstanding RTCP packets. 208 FlushRtcpMessages(); // Send any outstanding RTCP packets.
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 break; 470 break;
470 case ST_RTCP: 471 case ST_RTCP:
471 channel = rtcp_transport_channel_; 472 channel = rtcp_transport_channel_;
472 rtcp_socket_options_.push_back( 473 rtcp_socket_options_.push_back(
473 std::pair<rtc::Socket::Option, int>(opt, value)); 474 std::pair<rtc::Socket::Option, int>(opt, value));
474 break; 475 break;
475 } 476 }
476 return channel ? channel->SetOption(opt, value) : -1; 477 return channel ? channel->SetOption(opt, value) : -1;
477 } 478 }
478 479
480 bool BaseChannel::SetEnableGcmCryptoSuites(bool enable) {
481 enable_gcm_crypto_suites_ = enable;
482 return true;
483 }
484
479 void BaseChannel::OnWritableState(TransportChannel* channel) { 485 void BaseChannel::OnWritableState(TransportChannel* channel) {
480 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); 486 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
481 UpdateWritableState_w(); 487 UpdateWritableState_w();
482 } 488 }
483 489
484 void BaseChannel::OnChannelRead(TransportChannel* channel, 490 void BaseChannel::OnChannelRead(TransportChannel* channel,
485 const char* data, size_t len, 491 const char* data, size_t len,
486 const rtc::PacketTime& packet_time, 492 const rtc::PacketTime& packet_time,
487 int flags) { 493 int flags) {
488 TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); 494 TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead");
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); 840 &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp));
835 } 841 }
836 842
837 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { 843 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) {
838 ASSERT(signaling_thread() == rtc::Thread::Current()); 844 ASSERT(signaling_thread() == rtc::Thread::Current());
839 SignalDtlsSetupFailure(this, rtcp); 845 SignalDtlsSetupFailure(this, rtcp);
840 } 846 }
841 847
842 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { 848 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) {
843 std::vector<int> crypto_suites; 849 std::vector<int> crypto_suites;
850 MediaSessionOptions options;
851 options.enable_gcm_crypto_suites = enable_gcm_crypto_suites_;
844 // We always use the default SRTP crypto suites for RTCP, but we may use 852 // We always use the default SRTP crypto suites for RTCP, but we may use
845 // different crypto suites for RTP depending on the media type. 853 // different crypto suites for RTP depending on the media type.
846 if (!rtcp) { 854 if (!rtcp) {
847 GetSrtpCryptoSuites(&crypto_suites); 855 GetSrtpCryptoSuites(&crypto_suites, options);
848 } else { 856 } else {
849 GetDefaultSrtpCryptoSuites(&crypto_suites); 857 GetDefaultSrtpCryptoSuites(&crypto_suites, options);
850 } 858 }
851 return tc->SetSrtpCryptoSuites(crypto_suites); 859 return tc->SetSrtpCryptoSuites(crypto_suites);
852 } 860 }
853 861
854 bool BaseChannel::ShouldSetupDtlsSrtp() const { 862 bool BaseChannel::ShouldSetupDtlsSrtp() const {
855 // Since DTLS is applied to all channels, checking RTP should be enough. 863 // Since DTLS is applied to all channels, checking RTP should be enough.
856 return transport_channel_ && transport_channel_->IsDtlsActive(); 864 return transport_channel_ && transport_channel_->IsDtlsActive();
857 } 865 }
858 866
859 // This function returns true if either DTLS-SRTP is not in use 867 // This function returns true if either DTLS-SRTP is not in use
(...skipping 10 matching lines...) Expand all
870 878
871 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { 879 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) {
872 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; 880 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite";
873 return false; 881 return false;
874 } 882 }
875 883
876 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " 884 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on "
877 << content_name() << " " 885 << content_name() << " "
878 << PacketType(rtcp_channel); 886 << PacketType(rtcp_channel);
879 887
888 int key_len;
889 int salt_len;
890 if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len,
891 &salt_len)) {
892 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite;
893 return false;
894 }
895
880 // OK, we're now doing DTLS (RFC 5764) 896 // OK, we're now doing DTLS (RFC 5764)
881 std::vector<unsigned char> dtls_buffer(SRTP_MASTER_KEY_KEY_LEN * 2 + 897 std::vector<unsigned char> dtls_buffer(key_len * 2 + salt_len * 2);
882 SRTP_MASTER_KEY_SALT_LEN * 2);
883 898
884 // RFC 5705 exporter using the RFC 5764 parameters 899 // RFC 5705 exporter using the RFC 5764 parameters
885 if (!channel->ExportKeyingMaterial( 900 if (!channel->ExportKeyingMaterial(
886 kDtlsSrtpExporterLabel, 901 kDtlsSrtpExporterLabel,
887 NULL, 0, false, 902 NULL, 0, false,
888 &dtls_buffer[0], dtls_buffer.size())) { 903 &dtls_buffer[0], dtls_buffer.size())) {
889 LOG(LS_WARNING) << "DTLS-SRTP key export failed"; 904 LOG(LS_WARNING) << "DTLS-SRTP key export failed";
890 ASSERT(false); // This should never happen 905 ASSERT(false); // This should never happen
891 return false; 906 return false;
892 } 907 }
893 908
894 // Sync up the keys with the DTLS-SRTP interface 909 // Sync up the keys with the DTLS-SRTP interface
895 std::vector<unsigned char> client_write_key(SRTP_MASTER_KEY_KEY_LEN + 910 std::vector<unsigned char> client_write_key(key_len + salt_len);
896 SRTP_MASTER_KEY_SALT_LEN); 911 std::vector<unsigned char> server_write_key(key_len + salt_len);
897 std::vector<unsigned char> server_write_key(SRTP_MASTER_KEY_KEY_LEN +
898 SRTP_MASTER_KEY_SALT_LEN);
899 size_t offset = 0; 912 size_t offset = 0;
900 memcpy(&client_write_key[0], &dtls_buffer[offset], 913 memcpy(&client_write_key[0], &dtls_buffer[offset], key_len);
901 SRTP_MASTER_KEY_KEY_LEN); 914 offset += key_len;
902 offset += SRTP_MASTER_KEY_KEY_LEN; 915 memcpy(&server_write_key[0], &dtls_buffer[offset], key_len);
903 memcpy(&server_write_key[0], &dtls_buffer[offset], 916 offset += key_len;
904 SRTP_MASTER_KEY_KEY_LEN); 917 memcpy(&client_write_key[key_len], &dtls_buffer[offset], salt_len);
905 offset += SRTP_MASTER_KEY_KEY_LEN; 918 offset += salt_len;
906 memcpy(&client_write_key[SRTP_MASTER_KEY_KEY_LEN], 919 memcpy(&server_write_key[key_len], &dtls_buffer[offset], salt_len);
907 &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN);
908 offset += SRTP_MASTER_KEY_SALT_LEN;
909 memcpy(&server_write_key[SRTP_MASTER_KEY_KEY_LEN],
910 &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN);
911 920
912 std::vector<unsigned char> *send_key, *recv_key; 921 std::vector<unsigned char> *send_key, *recv_key;
913 rtc::SSLRole role; 922 rtc::SSLRole role;
914 if (!channel->GetSslRole(&role)) { 923 if (!channel->GetSslRole(&role)) {
915 LOG(LS_WARNING) << "GetSslRole failed"; 924 LOG(LS_WARNING) << "GetSslRole failed";
916 return false; 925 return false;
917 } 926 }
918 927
919 if (role == rtc::SSL_SERVER) { 928 if (role == rtc::SSL_SERVER) {
920 send_key = &server_write_key; 929 send_key = &server_write_key;
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 VoiceMediaChannel* media_channel, const VoiceMediaInfo& info) { 1627 VoiceMediaChannel* media_channel, const VoiceMediaInfo& info) {
1619 ASSERT(media_channel == this->media_channel()); 1628 ASSERT(media_channel == this->media_channel());
1620 SignalMediaMonitor(this, info); 1629 SignalMediaMonitor(this, info);
1621 } 1630 }
1622 1631
1623 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, 1632 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor,
1624 const AudioInfo& info) { 1633 const AudioInfo& info) {
1625 SignalAudioMonitor(this, info); 1634 SignalAudioMonitor(this, info);
1626 } 1635 }
1627 1636
1628 void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { 1637 void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites,
1629 GetSupportedAudioCryptoSuites(crypto_suites); 1638 const MediaSessionOptions& options) const {
1639 GetSupportedAudioCryptoSuites(crypto_suites, options);
1630 } 1640 }
1631 1641
1632 VideoChannel::VideoChannel(rtc::Thread* thread, 1642 VideoChannel::VideoChannel(rtc::Thread* thread,
1633 VideoMediaChannel* media_channel, 1643 VideoMediaChannel* media_channel,
1634 TransportController* transport_controller, 1644 TransportController* transport_controller,
1635 const std::string& content_name, 1645 const std::string& content_name,
1636 bool rtcp) 1646 bool rtcp)
1637 : BaseChannel(thread, 1647 : BaseChannel(thread,
1638 media_channel, 1648 media_channel,
1639 transport_controller, 1649 transport_controller,
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2009 for (ScreencastMap::iterator iter = screencast_capturers_.begin(); 2019 for (ScreencastMap::iterator iter = screencast_capturers_.begin();
2010 iter != screencast_capturers_.end(); ++iter) { 2020 iter != screencast_capturers_.end(); ++iter) {
2011 if (iter->second == capturer) { 2021 if (iter->second == capturer) {
2012 *ssrc = iter->first; 2022 *ssrc = iter->first;
2013 return true; 2023 return true;
2014 } 2024 }
2015 } 2025 }
2016 return false; 2026 return false;
2017 } 2027 }
2018 2028
2019 void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { 2029 void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites,
2020 GetSupportedVideoCryptoSuites(crypto_suites); 2030 const MediaSessionOptions& options) const {
2031 GetSupportedVideoCryptoSuites(crypto_suites, options);
2021 } 2032 }
2022 2033
2023 DataChannel::DataChannel(rtc::Thread* thread, 2034 DataChannel::DataChannel(rtc::Thread* thread,
2024 DataMediaChannel* media_channel, 2035 DataMediaChannel* media_channel,
2025 TransportController* transport_controller, 2036 TransportController* transport_controller,
2026 const std::string& content_name, 2037 const std::string& content_name,
2027 bool rtcp) 2038 bool rtcp)
2028 : BaseChannel(thread, 2039 : BaseChannel(thread,
2029 media_channel, 2040 media_channel,
2030 transport_controller, 2041 transport_controller,
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
2318 } 2329 }
2319 2330
2320 void DataChannel::OnDataChannelReadyToSend(bool writable) { 2331 void DataChannel::OnDataChannelReadyToSend(bool writable) {
2321 // This is usded for congestion control to indicate that the stream is ready 2332 // This is usded for congestion control to indicate that the stream is ready
2322 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates 2333 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates
2323 // that the transport channel is ready. 2334 // that the transport channel is ready.
2324 signaling_thread()->Post(this, MSG_READYTOSENDDATA, 2335 signaling_thread()->Post(this, MSG_READYTOSENDDATA,
2325 new DataChannelReadyToSendMessageData(writable)); 2336 new DataChannelReadyToSendMessageData(writable));
2326 } 2337 }
2327 2338
2328 void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { 2339 void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites,
2329 GetSupportedDataCryptoSuites(crypto_suites); 2340 const MediaSessionOptions& options) const {
2341 GetSupportedDataCryptoSuites(crypto_suites, options);
2330 } 2342 }
2331 2343
2332 bool DataChannel::ShouldSetupDtlsSrtp() const { 2344 bool DataChannel::ShouldSetupDtlsSrtp() const {
2333 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); 2345 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp();
2334 } 2346 }
2335 2347
2336 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { 2348 void DataChannel::OnStreamClosedRemotely(uint32_t sid) {
2337 rtc::TypedMessageData<uint32_t>* message = 2349 rtc::TypedMessageData<uint32_t>* message =
2338 new rtc::TypedMessageData<uint32_t>(sid); 2350 new rtc::TypedMessageData<uint32_t>(sid);
2339 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); 2351 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message);
2340 } 2352 }
2341 2353
2342 } // namespace cricket 2354 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698