| OLD | NEW |
| 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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 break; | 480 break; |
| 481 case ST_RTCP: | 481 case ST_RTCP: |
| 482 channel = rtcp_transport_channel_; | 482 channel = rtcp_transport_channel_; |
| 483 rtcp_socket_options_.push_back( | 483 rtcp_socket_options_.push_back( |
| 484 std::pair<rtc::Socket::Option, int>(opt, value)); | 484 std::pair<rtc::Socket::Option, int>(opt, value)); |
| 485 break; | 485 break; |
| 486 } | 486 } |
| 487 return channel ? channel->SetOption(opt, value) : -1; | 487 return channel ? channel->SetOption(opt, value) : -1; |
| 488 } | 488 } |
| 489 | 489 |
| 490 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { |
| 491 crypto_options_ = crypto_options; |
| 492 return true; |
| 493 } |
| 494 |
| 490 void BaseChannel::OnWritableState(TransportChannel* channel) { | 495 void BaseChannel::OnWritableState(TransportChannel* channel) { |
| 491 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 496 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
| 492 UpdateWritableState_w(); | 497 UpdateWritableState_w(); |
| 493 } | 498 } |
| 494 | 499 |
| 495 void BaseChannel::OnChannelRead(TransportChannel* channel, | 500 void BaseChannel::OnChannelRead(TransportChannel* channel, |
| 496 const char* data, size_t len, | 501 const char* data, size_t len, |
| 497 const rtc::PacketTime& packet_time, | 502 const rtc::PacketTime& packet_time, |
| 498 int flags) { | 503 int flags) { |
| 499 TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); | 504 TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { | 853 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { |
| 849 ASSERT(signaling_thread() == rtc::Thread::Current()); | 854 ASSERT(signaling_thread() == rtc::Thread::Current()); |
| 850 SignalDtlsSetupFailure(this, rtcp); | 855 SignalDtlsSetupFailure(this, rtcp); |
| 851 } | 856 } |
| 852 | 857 |
| 853 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { | 858 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { |
| 854 std::vector<int> crypto_suites; | 859 std::vector<int> crypto_suites; |
| 855 // We always use the default SRTP crypto suites for RTCP, but we may use | 860 // We always use the default SRTP crypto suites for RTCP, but we may use |
| 856 // different crypto suites for RTP depending on the media type. | 861 // different crypto suites for RTP depending on the media type. |
| 857 if (!rtcp) { | 862 if (!rtcp) { |
| 858 GetSrtpCryptoSuites(&crypto_suites); | 863 GetSrtpCryptoSuites(crypto_options_, &crypto_suites); |
| 859 } else { | 864 } else { |
| 860 GetDefaultSrtpCryptoSuites(&crypto_suites); | 865 GetDefaultSrtpCryptoSuites(crypto_options_, &crypto_suites); |
| 861 } | 866 } |
| 862 return tc->SetSrtpCryptoSuites(crypto_suites); | 867 return tc->SetSrtpCryptoSuites(crypto_suites); |
| 863 } | 868 } |
| 864 | 869 |
| 865 bool BaseChannel::ShouldSetupDtlsSrtp() const { | 870 bool BaseChannel::ShouldSetupDtlsSrtp() const { |
| 866 // Since DTLS is applied to all channels, checking RTP should be enough. | 871 // Since DTLS is applied to all channels, checking RTP should be enough. |
| 867 return transport_channel_ && transport_channel_->IsDtlsActive(); | 872 return transport_channel_ && transport_channel_->IsDtlsActive(); |
| 868 } | 873 } |
| 869 | 874 |
| 870 // This function returns true if either DTLS-SRTP is not in use | 875 // This function returns true if either DTLS-SRTP is not in use |
| (...skipping 10 matching lines...) Expand all Loading... |
| 881 | 886 |
| 882 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { | 887 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { |
| 883 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; | 888 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; |
| 884 return false; | 889 return false; |
| 885 } | 890 } |
| 886 | 891 |
| 887 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " | 892 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " |
| 888 << content_name() << " " | 893 << content_name() << " " |
| 889 << PacketType(rtcp_channel); | 894 << PacketType(rtcp_channel); |
| 890 | 895 |
| 896 int key_len; |
| 897 int salt_len; |
| 898 if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len, |
| 899 &salt_len)) { |
| 900 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite; |
| 901 return false; |
| 902 } |
| 903 |
| 891 // OK, we're now doing DTLS (RFC 5764) | 904 // OK, we're now doing DTLS (RFC 5764) |
| 892 std::vector<unsigned char> dtls_buffer(SRTP_MASTER_KEY_KEY_LEN * 2 + | 905 std::vector<unsigned char> dtls_buffer(key_len * 2 + salt_len * 2); |
| 893 SRTP_MASTER_KEY_SALT_LEN * 2); | |
| 894 | 906 |
| 895 // RFC 5705 exporter using the RFC 5764 parameters | 907 // RFC 5705 exporter using the RFC 5764 parameters |
| 896 if (!channel->ExportKeyingMaterial( | 908 if (!channel->ExportKeyingMaterial( |
| 897 kDtlsSrtpExporterLabel, | 909 kDtlsSrtpExporterLabel, |
| 898 NULL, 0, false, | 910 NULL, 0, false, |
| 899 &dtls_buffer[0], dtls_buffer.size())) { | 911 &dtls_buffer[0], dtls_buffer.size())) { |
| 900 LOG(LS_WARNING) << "DTLS-SRTP key export failed"; | 912 LOG(LS_WARNING) << "DTLS-SRTP key export failed"; |
| 901 ASSERT(false); // This should never happen | 913 ASSERT(false); // This should never happen |
| 902 return false; | 914 return false; |
| 903 } | 915 } |
| 904 | 916 |
| 905 // Sync up the keys with the DTLS-SRTP interface | 917 // Sync up the keys with the DTLS-SRTP interface |
| 906 std::vector<unsigned char> client_write_key(SRTP_MASTER_KEY_KEY_LEN + | 918 std::vector<unsigned char> client_write_key(key_len + salt_len); |
| 907 SRTP_MASTER_KEY_SALT_LEN); | 919 std::vector<unsigned char> server_write_key(key_len + salt_len); |
| 908 std::vector<unsigned char> server_write_key(SRTP_MASTER_KEY_KEY_LEN + | |
| 909 SRTP_MASTER_KEY_SALT_LEN); | |
| 910 size_t offset = 0; | 920 size_t offset = 0; |
| 911 memcpy(&client_write_key[0], &dtls_buffer[offset], | 921 memcpy(&client_write_key[0], &dtls_buffer[offset], key_len); |
| 912 SRTP_MASTER_KEY_KEY_LEN); | 922 offset += key_len; |
| 913 offset += SRTP_MASTER_KEY_KEY_LEN; | 923 memcpy(&server_write_key[0], &dtls_buffer[offset], key_len); |
| 914 memcpy(&server_write_key[0], &dtls_buffer[offset], | 924 offset += key_len; |
| 915 SRTP_MASTER_KEY_KEY_LEN); | 925 memcpy(&client_write_key[key_len], &dtls_buffer[offset], salt_len); |
| 916 offset += SRTP_MASTER_KEY_KEY_LEN; | 926 offset += salt_len; |
| 917 memcpy(&client_write_key[SRTP_MASTER_KEY_KEY_LEN], | 927 memcpy(&server_write_key[key_len], &dtls_buffer[offset], salt_len); |
| 918 &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN); | |
| 919 offset += SRTP_MASTER_KEY_SALT_LEN; | |
| 920 memcpy(&server_write_key[SRTP_MASTER_KEY_KEY_LEN], | |
| 921 &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN); | |
| 922 | 928 |
| 923 std::vector<unsigned char> *send_key, *recv_key; | 929 std::vector<unsigned char> *send_key, *recv_key; |
| 924 rtc::SSLRole role; | 930 rtc::SSLRole role; |
| 925 if (!channel->GetSslRole(&role)) { | 931 if (!channel->GetSslRole(&role)) { |
| 926 LOG(LS_WARNING) << "GetSslRole failed"; | 932 LOG(LS_WARNING) << "GetSslRole failed"; |
| 927 return false; | 933 return false; |
| 928 } | 934 } |
| 929 | 935 |
| 930 if (role == rtc::SSL_SERVER) { | 936 if (role == rtc::SSL_SERVER) { |
| 931 send_key = &server_write_key; | 937 send_key = &server_write_key; |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1629 VoiceMediaChannel* media_channel, const VoiceMediaInfo& info) { | 1635 VoiceMediaChannel* media_channel, const VoiceMediaInfo& info) { |
| 1630 ASSERT(media_channel == this->media_channel()); | 1636 ASSERT(media_channel == this->media_channel()); |
| 1631 SignalMediaMonitor(this, info); | 1637 SignalMediaMonitor(this, info); |
| 1632 } | 1638 } |
| 1633 | 1639 |
| 1634 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, | 1640 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, |
| 1635 const AudioInfo& info) { | 1641 const AudioInfo& info) { |
| 1636 SignalAudioMonitor(this, info); | 1642 SignalAudioMonitor(this, info); |
| 1637 } | 1643 } |
| 1638 | 1644 |
| 1639 void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { | 1645 void VoiceChannel::GetSrtpCryptoSuites(const rtc::CryptoOptions& crypto_options, |
| 1640 GetSupportedAudioCryptoSuites(crypto_suites); | 1646 std::vector<int>* crypto_suites) const { |
| 1647 GetSupportedAudioCryptoSuites(crypto_options, crypto_suites); |
| 1641 } | 1648 } |
| 1642 | 1649 |
| 1643 VideoChannel::VideoChannel(rtc::Thread* thread, | 1650 VideoChannel::VideoChannel(rtc::Thread* thread, |
| 1644 VideoMediaChannel* media_channel, | 1651 VideoMediaChannel* media_channel, |
| 1645 TransportController* transport_controller, | 1652 TransportController* transport_controller, |
| 1646 const std::string& content_name, | 1653 const std::string& content_name, |
| 1647 bool rtcp) | 1654 bool rtcp) |
| 1648 : BaseChannel(thread, | 1655 : BaseChannel(thread, |
| 1649 media_channel, | 1656 media_channel, |
| 1650 transport_controller, | 1657 transport_controller, |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1994 for (ScreencastMap::iterator iter = screencast_capturers_.begin(); | 2001 for (ScreencastMap::iterator iter = screencast_capturers_.begin(); |
| 1995 iter != screencast_capturers_.end(); ++iter) { | 2002 iter != screencast_capturers_.end(); ++iter) { |
| 1996 if (iter->second == capturer) { | 2003 if (iter->second == capturer) { |
| 1997 *ssrc = iter->first; | 2004 *ssrc = iter->first; |
| 1998 return true; | 2005 return true; |
| 1999 } | 2006 } |
| 2000 } | 2007 } |
| 2001 return false; | 2008 return false; |
| 2002 } | 2009 } |
| 2003 | 2010 |
| 2004 void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { | 2011 void VideoChannel::GetSrtpCryptoSuites(const rtc::CryptoOptions& crypto_options, |
| 2005 GetSupportedVideoCryptoSuites(crypto_suites); | 2012 std::vector<int>* crypto_suites) const { |
| 2013 GetSupportedVideoCryptoSuites(crypto_options, crypto_suites); |
| 2006 } | 2014 } |
| 2007 | 2015 |
| 2008 DataChannel::DataChannel(rtc::Thread* thread, | 2016 DataChannel::DataChannel(rtc::Thread* thread, |
| 2009 DataMediaChannel* media_channel, | 2017 DataMediaChannel* media_channel, |
| 2010 TransportController* transport_controller, | 2018 TransportController* transport_controller, |
| 2011 const std::string& content_name, | 2019 const std::string& content_name, |
| 2012 bool rtcp) | 2020 bool rtcp) |
| 2013 : BaseChannel(thread, | 2021 : BaseChannel(thread, |
| 2014 media_channel, | 2022 media_channel, |
| 2015 transport_controller, | 2023 transport_controller, |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2303 } | 2311 } |
| 2304 | 2312 |
| 2305 void DataChannel::OnDataChannelReadyToSend(bool writable) { | 2313 void DataChannel::OnDataChannelReadyToSend(bool writable) { |
| 2306 // This is usded for congestion control to indicate that the stream is ready | 2314 // This is usded for congestion control to indicate that the stream is ready |
| 2307 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates | 2315 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates |
| 2308 // that the transport channel is ready. | 2316 // that the transport channel is ready. |
| 2309 signaling_thread()->Post(this, MSG_READYTOSENDDATA, | 2317 signaling_thread()->Post(this, MSG_READYTOSENDDATA, |
| 2310 new DataChannelReadyToSendMessageData(writable)); | 2318 new DataChannelReadyToSendMessageData(writable)); |
| 2311 } | 2319 } |
| 2312 | 2320 |
| 2313 void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { | 2321 void DataChannel::GetSrtpCryptoSuites(const rtc::CryptoOptions& crypto_options, |
| 2314 GetSupportedDataCryptoSuites(crypto_suites); | 2322 std::vector<int>* crypto_suites) const { |
| 2323 GetSupportedDataCryptoSuites(crypto_options, crypto_suites); |
| 2315 } | 2324 } |
| 2316 | 2325 |
| 2317 bool DataChannel::ShouldSetupDtlsSrtp() const { | 2326 bool DataChannel::ShouldSetupDtlsSrtp() const { |
| 2318 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); | 2327 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); |
| 2319 } | 2328 } |
| 2320 | 2329 |
| 2321 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2330 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
| 2322 rtc::TypedMessageData<uint32_t>* message = | 2331 rtc::TypedMessageData<uint32_t>* message = |
| 2323 new rtc::TypedMessageData<uint32_t>(sid); | 2332 new rtc::TypedMessageData<uint32_t>(sid); |
| 2324 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2333 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
| 2325 } | 2334 } |
| 2326 | 2335 |
| 2327 } // namespace cricket | 2336 } // namespace cricket |
| OLD | NEW |