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 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 | 841 |
842 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { | 842 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { |
843 std::vector<int> crypto_suites; | 843 std::vector<int> crypto_suites; |
844 // We always use the default SRTP crypto suites for RTCP, but we may use | 844 // 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. | 845 // different crypto suites for RTP depending on the media type. |
846 if (!rtcp) { | 846 if (!rtcp) { |
847 GetSrtpCryptoSuites(&crypto_suites); | 847 GetSrtpCryptoSuites(&crypto_suites); |
848 } else { | 848 } else { |
849 GetDefaultSrtpCryptoSuites(&crypto_suites); | 849 GetDefaultSrtpCryptoSuites(&crypto_suites); |
850 } | 850 } |
851 if (!tc->IsEnableGcmCiphers()) { | |
852 FilterGcmCiphers(&crypto_suites); | |
853 } | |
pthatcher1
2015/12/18 20:31:31
Having the "enable gcm ciphers" passed down from t
joachim
2015/12/19 15:26:23
Agreed. I pass the flag from the PeerConnectionFac
| |
851 return tc->SetSrtpCryptoSuites(crypto_suites); | 854 return tc->SetSrtpCryptoSuites(crypto_suites); |
852 } | 855 } |
853 | 856 |
854 bool BaseChannel::ShouldSetupDtlsSrtp() const { | 857 bool BaseChannel::ShouldSetupDtlsSrtp() const { |
855 // Since DTLS is applied to all channels, checking RTP should be enough. | 858 // Since DTLS is applied to all channels, checking RTP should be enough. |
856 return transport_channel_ && transport_channel_->IsDtlsActive(); | 859 return transport_channel_ && transport_channel_->IsDtlsActive(); |
857 } | 860 } |
858 | 861 |
859 // This function returns true if either DTLS-SRTP is not in use | 862 // This function returns true if either DTLS-SRTP is not in use |
860 // *or* DTLS-SRTP is successfully set up. | 863 // *or* DTLS-SRTP is successfully set up. |
861 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { | 864 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { |
862 bool ret = false; | 865 bool ret = false; |
863 | 866 |
864 TransportChannel* channel = | 867 TransportChannel* channel = |
865 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; | 868 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; |
866 | 869 |
867 RTC_DCHECK(channel->IsDtlsActive()); | 870 RTC_DCHECK(channel->IsDtlsActive()); |
868 | 871 |
869 int selected_crypto_suite; | 872 int selected_crypto_suite; |
870 | 873 |
871 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { | 874 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { |
872 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; | 875 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; |
873 return false; | 876 return false; |
874 } | 877 } |
875 | 878 |
876 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " | 879 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " |
877 << content_name() << " " | 880 << content_name() << " " |
878 << PacketType(rtcp_channel); | 881 << PacketType(rtcp_channel); |
879 | 882 |
883 int key_len; | |
884 int salt_len; | |
885 if (!rtc::SrtpCryptoSuiteParams(selected_crypto_suite, &key_len, &salt_len)) { | |
pthatcher1
2015/12/18 20:31:31
Can you call this GetSrtpKeyAndSaltLengths?
joachim
2015/12/19 15:26:23
Done.
| |
886 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite; | |
887 return false; | |
888 } | |
889 | |
880 // OK, we're now doing DTLS (RFC 5764) | 890 // OK, we're now doing DTLS (RFC 5764) |
881 std::vector<unsigned char> dtls_buffer(SRTP_MASTER_KEY_KEY_LEN * 2 + | 891 std::vector<unsigned char> dtls_buffer(key_len * 2 + salt_len * 2); |
882 SRTP_MASTER_KEY_SALT_LEN * 2); | |
883 | 892 |
884 // RFC 5705 exporter using the RFC 5764 parameters | 893 // RFC 5705 exporter using the RFC 5764 parameters |
885 if (!channel->ExportKeyingMaterial( | 894 if (!channel->ExportKeyingMaterial( |
886 kDtlsSrtpExporterLabel, | 895 kDtlsSrtpExporterLabel, |
887 NULL, 0, false, | 896 NULL, 0, false, |
888 &dtls_buffer[0], dtls_buffer.size())) { | 897 &dtls_buffer[0], dtls_buffer.size())) { |
889 LOG(LS_WARNING) << "DTLS-SRTP key export failed"; | 898 LOG(LS_WARNING) << "DTLS-SRTP key export failed"; |
890 ASSERT(false); // This should never happen | 899 ASSERT(false); // This should never happen |
891 return false; | 900 return false; |
892 } | 901 } |
893 | 902 |
894 // Sync up the keys with the DTLS-SRTP interface | 903 // Sync up the keys with the DTLS-SRTP interface |
895 std::vector<unsigned char> client_write_key(SRTP_MASTER_KEY_KEY_LEN + | 904 std::vector<unsigned char> client_write_key(key_len + salt_len); |
896 SRTP_MASTER_KEY_SALT_LEN); | 905 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; | 906 size_t offset = 0; |
900 memcpy(&client_write_key[0], &dtls_buffer[offset], | 907 memcpy(&client_write_key[0], &dtls_buffer[offset], key_len); |
901 SRTP_MASTER_KEY_KEY_LEN); | 908 offset += key_len; |
902 offset += SRTP_MASTER_KEY_KEY_LEN; | 909 memcpy(&server_write_key[0], &dtls_buffer[offset], key_len); |
903 memcpy(&server_write_key[0], &dtls_buffer[offset], | 910 offset += key_len; |
904 SRTP_MASTER_KEY_KEY_LEN); | 911 memcpy(&client_write_key[key_len], &dtls_buffer[offset], salt_len); |
905 offset += SRTP_MASTER_KEY_KEY_LEN; | 912 offset += salt_len; |
906 memcpy(&client_write_key[SRTP_MASTER_KEY_KEY_LEN], | 913 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 | 914 |
912 std::vector<unsigned char> *send_key, *recv_key; | 915 std::vector<unsigned char> *send_key, *recv_key; |
913 rtc::SSLRole role; | 916 rtc::SSLRole role; |
914 if (!channel->GetSslRole(&role)) { | 917 if (!channel->GetSslRole(&role)) { |
915 LOG(LS_WARNING) << "GetSslRole failed"; | 918 LOG(LS_WARNING) << "GetSslRole failed"; |
916 return false; | 919 return false; |
917 } | 920 } |
918 | 921 |
919 if (role == rtc::SSL_SERVER) { | 922 if (role == rtc::SSL_SERVER) { |
920 send_key = &server_write_key; | 923 send_key = &server_write_key; |
(...skipping 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2333 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); | 2336 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); |
2334 } | 2337 } |
2335 | 2338 |
2336 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2339 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
2337 rtc::TypedMessageData<uint32_t>* message = | 2340 rtc::TypedMessageData<uint32_t>* message = |
2338 new rtc::TypedMessageData<uint32_t>(sid); | 2341 new rtc::TypedMessageData<uint32_t>(sid); |
2339 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2342 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
2340 } | 2343 } |
2341 | 2344 |
2342 } // namespace cricket | 2345 } // namespace cricket |
OLD | NEW |