| OLD | NEW |
| 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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 break; | 459 break; |
| 460 case ST_RTCP: | 460 case ST_RTCP: |
| 461 channel = rtcp_transport_channel_; | 461 channel = rtcp_transport_channel_; |
| 462 rtcp_socket_options_.push_back( | 462 rtcp_socket_options_.push_back( |
| 463 std::pair<rtc::Socket::Option, int>(opt, value)); | 463 std::pair<rtc::Socket::Option, int>(opt, value)); |
| 464 break; | 464 break; |
| 465 } | 465 } |
| 466 return channel ? channel->SetOption(opt, value) : -1; | 466 return channel ? channel->SetOption(opt, value) : -1; |
| 467 } | 467 } |
| 468 | 468 |
| 469 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { |
| 470 crypto_options_ = crypto_options; |
| 471 return true; |
| 472 } |
| 473 |
| 469 void BaseChannel::OnWritableState(TransportChannel* channel) { | 474 void BaseChannel::OnWritableState(TransportChannel* channel) { |
| 470 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 475 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
| 471 UpdateWritableState_w(); | 476 UpdateWritableState_w(); |
| 472 } | 477 } |
| 473 | 478 |
| 474 void BaseChannel::OnChannelRead(TransportChannel* channel, | 479 void BaseChannel::OnChannelRead(TransportChannel* channel, |
| 475 const char* data, size_t len, | 480 const char* data, size_t len, |
| 476 const rtc::PacketTime& packet_time, | 481 const rtc::PacketTime& packet_time, |
| 477 int flags) { | 482 int flags) { |
| 478 TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); | 483 TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 SignalDtlsSetupFailure(this, rtcp); | 850 SignalDtlsSetupFailure(this, rtcp); |
| 846 } | 851 } |
| 847 | 852 |
| 848 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { | 853 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { |
| 849 std::vector<int> crypto_suites; | 854 std::vector<int> crypto_suites; |
| 850 // We always use the default SRTP crypto suites for RTCP, but we may use | 855 // We always use the default SRTP crypto suites for RTCP, but we may use |
| 851 // different crypto suites for RTP depending on the media type. | 856 // different crypto suites for RTP depending on the media type. |
| 852 if (!rtcp) { | 857 if (!rtcp) { |
| 853 GetSrtpCryptoSuites(&crypto_suites); | 858 GetSrtpCryptoSuites(&crypto_suites); |
| 854 } else { | 859 } else { |
| 855 GetDefaultSrtpCryptoSuites(&crypto_suites); | 860 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites); |
| 856 } | 861 } |
| 857 return tc->SetSrtpCryptoSuites(crypto_suites); | 862 return tc->SetSrtpCryptoSuites(crypto_suites); |
| 858 } | 863 } |
| 859 | 864 |
| 860 bool BaseChannel::ShouldSetupDtlsSrtp() const { | 865 bool BaseChannel::ShouldSetupDtlsSrtp() const { |
| 861 // Since DTLS is applied to all channels, checking RTP should be enough. | 866 // Since DTLS is applied to all channels, checking RTP should be enough. |
| 862 return transport_channel_ && transport_channel_->IsDtlsActive(); | 867 return transport_channel_ && transport_channel_->IsDtlsActive(); |
| 863 } | 868 } |
| 864 | 869 |
| 865 // This function returns true if either DTLS-SRTP is not in use | 870 // This function returns true if either DTLS-SRTP is not in use |
| (...skipping 10 matching lines...) Expand all Loading... |
| 876 | 881 |
| 877 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { | 882 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { |
| 878 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; | 883 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; |
| 879 return false; | 884 return false; |
| 880 } | 885 } |
| 881 | 886 |
| 882 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " | 887 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " |
| 883 << content_name() << " " | 888 << content_name() << " " |
| 884 << PacketType(rtcp_channel); | 889 << PacketType(rtcp_channel); |
| 885 | 890 |
| 891 int key_len; |
| 892 int salt_len; |
| 893 if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len, |
| 894 &salt_len)) { |
| 895 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite; |
| 896 return false; |
| 897 } |
| 898 |
| 886 // OK, we're now doing DTLS (RFC 5764) | 899 // OK, we're now doing DTLS (RFC 5764) |
| 887 std::vector<unsigned char> dtls_buffer(SRTP_MASTER_KEY_KEY_LEN * 2 + | 900 std::vector<unsigned char> dtls_buffer(key_len * 2 + salt_len * 2); |
| 888 SRTP_MASTER_KEY_SALT_LEN * 2); | |
| 889 | 901 |
| 890 // RFC 5705 exporter using the RFC 5764 parameters | 902 // RFC 5705 exporter using the RFC 5764 parameters |
| 891 if (!channel->ExportKeyingMaterial( | 903 if (!channel->ExportKeyingMaterial( |
| 892 kDtlsSrtpExporterLabel, | 904 kDtlsSrtpExporterLabel, |
| 893 NULL, 0, false, | 905 NULL, 0, false, |
| 894 &dtls_buffer[0], dtls_buffer.size())) { | 906 &dtls_buffer[0], dtls_buffer.size())) { |
| 895 LOG(LS_WARNING) << "DTLS-SRTP key export failed"; | 907 LOG(LS_WARNING) << "DTLS-SRTP key export failed"; |
| 896 ASSERT(false); // This should never happen | 908 ASSERT(false); // This should never happen |
| 897 return false; | 909 return false; |
| 898 } | 910 } |
| 899 | 911 |
| 900 // Sync up the keys with the DTLS-SRTP interface | 912 // Sync up the keys with the DTLS-SRTP interface |
| 901 std::vector<unsigned char> client_write_key(SRTP_MASTER_KEY_KEY_LEN + | 913 std::vector<unsigned char> client_write_key(key_len + salt_len); |
| 902 SRTP_MASTER_KEY_SALT_LEN); | 914 std::vector<unsigned char> server_write_key(key_len + salt_len); |
| 903 std::vector<unsigned char> server_write_key(SRTP_MASTER_KEY_KEY_LEN + | |
| 904 SRTP_MASTER_KEY_SALT_LEN); | |
| 905 size_t offset = 0; | 915 size_t offset = 0; |
| 906 memcpy(&client_write_key[0], &dtls_buffer[offset], | 916 memcpy(&client_write_key[0], &dtls_buffer[offset], key_len); |
| 907 SRTP_MASTER_KEY_KEY_LEN); | 917 offset += key_len; |
| 908 offset += SRTP_MASTER_KEY_KEY_LEN; | 918 memcpy(&server_write_key[0], &dtls_buffer[offset], key_len); |
| 909 memcpy(&server_write_key[0], &dtls_buffer[offset], | 919 offset += key_len; |
| 910 SRTP_MASTER_KEY_KEY_LEN); | 920 memcpy(&client_write_key[key_len], &dtls_buffer[offset], salt_len); |
| 911 offset += SRTP_MASTER_KEY_KEY_LEN; | 921 offset += salt_len; |
| 912 memcpy(&client_write_key[SRTP_MASTER_KEY_KEY_LEN], | 922 memcpy(&server_write_key[key_len], &dtls_buffer[offset], salt_len); |
| 913 &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN); | |
| 914 offset += SRTP_MASTER_KEY_SALT_LEN; | |
| 915 memcpy(&server_write_key[SRTP_MASTER_KEY_KEY_LEN], | |
| 916 &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN); | |
| 917 | 923 |
| 918 std::vector<unsigned char> *send_key, *recv_key; | 924 std::vector<unsigned char> *send_key, *recv_key; |
| 919 rtc::SSLRole role; | 925 rtc::SSLRole role; |
| 920 if (!channel->GetSslRole(&role)) { | 926 if (!channel->GetSslRole(&role)) { |
| 921 LOG(LS_WARNING) << "GetSslRole failed"; | 927 LOG(LS_WARNING) << "GetSslRole failed"; |
| 922 return false; | 928 return false; |
| 923 } | 929 } |
| 924 | 930 |
| 925 if (role == rtc::SSL_SERVER) { | 931 if (role == rtc::SSL_SERVER) { |
| 926 send_key = &server_write_key; | 932 send_key = &server_write_key; |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1646 ASSERT(media_channel == this->media_channel()); | 1652 ASSERT(media_channel == this->media_channel()); |
| 1647 SignalMediaMonitor(this, info); | 1653 SignalMediaMonitor(this, info); |
| 1648 } | 1654 } |
| 1649 | 1655 |
| 1650 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, | 1656 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, |
| 1651 const AudioInfo& info) { | 1657 const AudioInfo& info) { |
| 1652 SignalAudioMonitor(this, info); | 1658 SignalAudioMonitor(this, info); |
| 1653 } | 1659 } |
| 1654 | 1660 |
| 1655 void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { | 1661 void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |
| 1656 GetSupportedAudioCryptoSuites(crypto_suites); | 1662 GetSupportedAudioCryptoSuites(crypto_options(), crypto_suites); |
| 1657 } | 1663 } |
| 1658 | 1664 |
| 1659 VideoChannel::VideoChannel(rtc::Thread* thread, | 1665 VideoChannel::VideoChannel(rtc::Thread* thread, |
| 1660 VideoMediaChannel* media_channel, | 1666 VideoMediaChannel* media_channel, |
| 1661 TransportController* transport_controller, | 1667 TransportController* transport_controller, |
| 1662 const std::string& content_name, | 1668 const std::string& content_name, |
| 1663 bool rtcp) | 1669 bool rtcp) |
| 1664 : BaseChannel(thread, | 1670 : BaseChannel(thread, |
| 1665 media_channel, | 1671 media_channel, |
| 1666 transport_controller, | 1672 transport_controller, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1879 | 1885 |
| 1880 // TODO(pthatcher): Look into removing duplicate code between | 1886 // TODO(pthatcher): Look into removing duplicate code between |
| 1881 // audio, video, and data, perhaps by using templates. | 1887 // audio, video, and data, perhaps by using templates. |
| 1882 void VideoChannel::OnMediaMonitorUpdate( | 1888 void VideoChannel::OnMediaMonitorUpdate( |
| 1883 VideoMediaChannel* media_channel, const VideoMediaInfo &info) { | 1889 VideoMediaChannel* media_channel, const VideoMediaInfo &info) { |
| 1884 ASSERT(media_channel == this->media_channel()); | 1890 ASSERT(media_channel == this->media_channel()); |
| 1885 SignalMediaMonitor(this, info); | 1891 SignalMediaMonitor(this, info); |
| 1886 } | 1892 } |
| 1887 | 1893 |
| 1888 void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { | 1894 void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |
| 1889 GetSupportedVideoCryptoSuites(crypto_suites); | 1895 GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites); |
| 1890 } | 1896 } |
| 1891 | 1897 |
| 1892 DataChannel::DataChannel(rtc::Thread* thread, | 1898 DataChannel::DataChannel(rtc::Thread* thread, |
| 1893 DataMediaChannel* media_channel, | 1899 DataMediaChannel* media_channel, |
| 1894 TransportController* transport_controller, | 1900 TransportController* transport_controller, |
| 1895 const std::string& content_name, | 1901 const std::string& content_name, |
| 1896 bool rtcp) | 1902 bool rtcp) |
| 1897 : BaseChannel(thread, | 1903 : BaseChannel(thread, |
| 1898 media_channel, | 1904 media_channel, |
| 1899 transport_controller, | 1905 transport_controller, |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2189 | 2195 |
| 2190 void DataChannel::OnDataChannelReadyToSend(bool writable) { | 2196 void DataChannel::OnDataChannelReadyToSend(bool writable) { |
| 2191 // This is usded for congestion control to indicate that the stream is ready | 2197 // This is usded for congestion control to indicate that the stream is ready |
| 2192 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates | 2198 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates |
| 2193 // that the transport channel is ready. | 2199 // that the transport channel is ready. |
| 2194 signaling_thread()->Post(this, MSG_READYTOSENDDATA, | 2200 signaling_thread()->Post(this, MSG_READYTOSENDDATA, |
| 2195 new DataChannelReadyToSendMessageData(writable)); | 2201 new DataChannelReadyToSendMessageData(writable)); |
| 2196 } | 2202 } |
| 2197 | 2203 |
| 2198 void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { | 2204 void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |
| 2199 GetSupportedDataCryptoSuites(crypto_suites); | 2205 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); |
| 2200 } | 2206 } |
| 2201 | 2207 |
| 2202 bool DataChannel::ShouldSetupDtlsSrtp() const { | 2208 bool DataChannel::ShouldSetupDtlsSrtp() const { |
| 2203 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); | 2209 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); |
| 2204 } | 2210 } |
| 2205 | 2211 |
| 2206 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2212 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
| 2207 rtc::TypedMessageData<uint32_t>* message = | 2213 rtc::TypedMessageData<uint32_t>* message = |
| 2208 new rtc::TypedMessageData<uint32_t>(sid); | 2214 new rtc::TypedMessageData<uint32_t>(sid); |
| 2209 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2215 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
| 2210 } | 2216 } |
| 2211 | 2217 |
| 2212 } // namespace cricket | 2218 } // namespace cricket |
| OLD | NEW |