Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 #ifdef HAVE_SCTP | 30 #ifdef HAVE_SCTP |
| 31 #include "webrtc/media/sctp/sctpdataengine.h" | 31 #include "webrtc/media/sctp/sctpdataengine.h" |
| 32 #else | 32 #else |
| 33 static const uint32_t kMaxSctpSid = 1023; | 33 static const uint32_t kMaxSctpSid = 1023; |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 const char kInline[] = "inline:"; | 37 const char kInline[] = "inline:"; |
| 38 | 38 |
| 39 void GetSupportedCryptoSuiteNames(void (*func)(std::vector<int>*), | 39 void GetSupportedCryptoSuiteNames(void (*func)(const rtc::CryptoOptions&, |
| 40 std::vector<int>*), | |
| 41 const rtc::CryptoOptions& crypto_options, | |
| 40 std::vector<std::string>* names) { | 42 std::vector<std::string>* names) { |
| 41 #ifdef HAVE_SRTP | 43 #ifdef HAVE_SRTP |
| 42 std::vector<int> crypto_suites; | 44 std::vector<int> crypto_suites; |
| 43 func(&crypto_suites); | 45 func(crypto_options, &crypto_suites); |
| 44 for (const auto crypto : crypto_suites) { | 46 for (const auto crypto : crypto_suites) { |
| 45 names->push_back(rtc::SrtpCryptoSuiteToName(crypto)); | 47 names->push_back(rtc::SrtpCryptoSuiteToName(crypto)); |
| 46 } | 48 } |
| 47 #endif | 49 #endif |
| 48 } | 50 } |
| 49 } // namespace | 51 } // namespace |
| 50 | 52 |
| 51 namespace cricket { | 53 namespace cricket { |
| 52 | 54 |
| 53 | 55 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 75 return false; | 77 return false; |
| 76 } | 78 } |
| 77 | 79 |
| 78 const MediaContentDescription* mdesc = | 80 const MediaContentDescription* mdesc = |
| 79 static_cast<const MediaContentDescription*>(content->description); | 81 static_cast<const MediaContentDescription*>(content->description); |
| 80 return mdesc && mdesc->type() == media_type; | 82 return mdesc && mdesc->type() == media_type; |
| 81 } | 83 } |
| 82 | 84 |
| 83 static bool CreateCryptoParams(int tag, const std::string& cipher, | 85 static bool CreateCryptoParams(int tag, const std::string& cipher, |
| 84 CryptoParams *out) { | 86 CryptoParams *out) { |
| 87 int key_len; | |
| 88 int salt_len; | |
| 89 if (!rtc::GetSrtpKeyAndSaltLengths( | |
| 90 rtc::SrtpCryptoSuiteFromName(cipher), &key_len, &salt_len)) { | |
| 91 return false; | |
| 92 } | |
| 93 | |
| 94 int master_key_base64_len = (key_len + salt_len) * 4 / 3; | |
|
mattdr
2016/05/06 22:34:14
This is bad.
E.g.
SRTP_AEAD_AES_256_GCM has key_l
joachim
2016/05/09 23:21:40
Right, and sorry for missing this :-( I now change
| |
| 95 | |
| 85 std::string key; | 96 std::string key; |
| 86 key.reserve(SRTP_MASTER_KEY_BASE64_LEN); | 97 key.reserve(master_key_base64_len); |
| 87 | 98 |
| 88 if (!rtc::CreateRandomString(SRTP_MASTER_KEY_BASE64_LEN, &key)) { | 99 if (!rtc::CreateRandomString(master_key_base64_len, &key)) { |
| 89 return false; | 100 return false; |
| 90 } | 101 } |
| 91 out->tag = tag; | 102 out->tag = tag; |
| 92 out->cipher_suite = cipher; | 103 out->cipher_suite = cipher; |
| 93 out->key_params = kInline; | 104 out->key_params = kInline; |
| 94 out->key_params += key; | 105 out->key_params += key; |
| 95 return true; | 106 return true; |
| 96 } | 107 } |
| 97 | 108 |
| 98 #ifdef HAVE_SRTP | 109 #ifdef HAVE_SRTP |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 for (CryptoParamsVec::const_iterator it = cryptos.begin(); | 150 for (CryptoParamsVec::const_iterator it = cryptos.begin(); |
| 140 it != cryptos.end(); ++it) { | 151 it != cryptos.end(); ++it) { |
| 141 if (crypto.Matches(*it)) { | 152 if (crypto.Matches(*it)) { |
| 142 *out = *it; | 153 *out = *it; |
| 143 return true; | 154 return true; |
| 144 } | 155 } |
| 145 } | 156 } |
| 146 return false; | 157 return false; |
| 147 } | 158 } |
| 148 | 159 |
| 149 // For audio, HMAC 32 is prefered because of the low overhead. | 160 // For audio, HMAC 32 is prefered over HMAC 80 because of the low overhead. |
| 150 void GetSupportedAudioCryptoSuites(std::vector<int>* crypto_suites) { | 161 void GetSupportedAudioCryptoSuites(const rtc::CryptoOptions& crypto_options, |
| 162 std::vector<int>* crypto_suites) { | |
| 151 #ifdef HAVE_SRTP | 163 #ifdef HAVE_SRTP |
| 164 if (crypto_options.enable_gcm_crypto_suites) { | |
| 165 crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM); | |
|
mattdr
2016/05/06 22:47:52
Judging by the comments above, I'm inferring these
joachim
2016/05/09 23:21:41
No particular reason from my side. I didn't find a
| |
| 166 crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM); | |
| 167 } | |
| 152 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_32); | 168 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_32); |
| 153 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); | 169 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); |
| 154 #endif | 170 #endif |
| 155 } | 171 } |
| 156 | 172 |
| 157 void GetSupportedAudioCryptoSuiteNames( | 173 void GetSupportedAudioCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, |
| 158 std::vector<std::string>* crypto_suite_names) { | 174 std::vector<std::string>* crypto_suite_names) { |
| 159 GetSupportedCryptoSuiteNames(GetSupportedAudioCryptoSuites, | 175 GetSupportedCryptoSuiteNames(GetSupportedAudioCryptoSuites, |
| 160 crypto_suite_names); | 176 crypto_options, crypto_suite_names); |
| 161 } | 177 } |
| 162 | 178 |
| 163 void GetSupportedVideoCryptoSuites(std::vector<int>* crypto_suites) { | 179 void GetSupportedVideoCryptoSuites(const rtc::CryptoOptions& crypto_options, |
| 164 GetDefaultSrtpCryptoSuites(crypto_suites); | 180 std::vector<int>* crypto_suites) { |
| 181 GetDefaultSrtpCryptoSuites(crypto_options, crypto_suites); | |
| 165 } | 182 } |
| 166 | 183 |
| 167 void GetSupportedVideoCryptoSuiteNames( | 184 void GetSupportedVideoCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, |
| 168 std::vector<std::string>* crypto_suite_names) { | 185 std::vector<std::string>* crypto_suite_names) { |
| 169 GetSupportedCryptoSuiteNames(GetSupportedVideoCryptoSuites, | 186 GetSupportedCryptoSuiteNames(GetSupportedVideoCryptoSuites, |
| 170 crypto_suite_names); | 187 crypto_options, crypto_suite_names); |
| 171 } | 188 } |
| 172 | 189 |
| 173 void GetSupportedDataCryptoSuites(std::vector<int>* crypto_suites) { | 190 void GetSupportedDataCryptoSuites(const rtc::CryptoOptions& crypto_options, |
| 174 GetDefaultSrtpCryptoSuites(crypto_suites); | 191 std::vector<int>* crypto_suites) { |
| 192 GetDefaultSrtpCryptoSuites(crypto_options, crypto_suites); | |
| 175 } | 193 } |
| 176 | 194 |
| 177 void GetSupportedDataCryptoSuiteNames( | 195 void GetSupportedDataCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, |
| 178 std::vector<std::string>* crypto_suite_names) { | 196 std::vector<std::string>* crypto_suite_names) { |
| 179 GetSupportedCryptoSuiteNames(GetSupportedDataCryptoSuites, | 197 GetSupportedCryptoSuiteNames(GetSupportedDataCryptoSuites, |
| 180 crypto_suite_names); | 198 crypto_options, crypto_suite_names); |
| 181 } | 199 } |
| 182 | 200 |
| 183 void GetDefaultSrtpCryptoSuites(std::vector<int>* crypto_suites) { | 201 void GetDefaultSrtpCryptoSuites(const rtc::CryptoOptions& crypto_options, |
| 202 std::vector<int>* crypto_suites) { | |
| 184 #ifdef HAVE_SRTP | 203 #ifdef HAVE_SRTP |
| 204 if (crypto_options.enable_gcm_crypto_suites) { | |
| 205 crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM); | |
| 206 crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM); | |
| 207 } | |
| 185 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); | 208 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); |
| 186 #endif | 209 #endif |
| 187 } | 210 } |
| 188 | 211 |
| 189 void GetDefaultSrtpCryptoSuiteNames( | 212 void GetDefaultSrtpCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, |
| 190 std::vector<std::string>* crypto_suite_names) { | 213 std::vector<std::string>* crypto_suite_names) { |
| 191 GetSupportedCryptoSuiteNames(GetDefaultSrtpCryptoSuites, crypto_suite_names); | 214 GetSupportedCryptoSuiteNames(GetDefaultSrtpCryptoSuites, |
| 215 crypto_options, crypto_suite_names); | |
| 192 } | 216 } |
| 193 | 217 |
| 194 // For video support only 80-bit SHA1 HMAC. For audio 32-bit HMAC is | 218 // Support any GCM cipher (if enabled through options). For video support only |
| 195 // tolerated unless bundle is enabled because it is low overhead. Pick the | 219 // 80-bit SHA1 HMAC. For audio 32-bit HMAC is tolerated unless bundle is enabled |
| 196 // crypto in the list that is supported. | 220 // because it is low overhead. |
| 221 // Pick the crypto in the list that is supported. | |
| 197 static bool SelectCrypto(const MediaContentDescription* offer, | 222 static bool SelectCrypto(const MediaContentDescription* offer, |
| 198 bool bundle, | 223 bool bundle, |
| 224 const rtc::CryptoOptions& crypto_options, | |
| 199 CryptoParams *crypto) { | 225 CryptoParams *crypto) { |
| 200 bool audio = offer->type() == MEDIA_TYPE_AUDIO; | 226 bool audio = offer->type() == MEDIA_TYPE_AUDIO; |
| 201 const CryptoParamsVec& cryptos = offer->cryptos(); | 227 const CryptoParamsVec& cryptos = offer->cryptos(); |
| 202 | 228 |
| 203 for (CryptoParamsVec::const_iterator i = cryptos.begin(); | 229 for (CryptoParamsVec::const_iterator i = cryptos.begin(); |
| 204 i != cryptos.end(); ++i) { | 230 i != cryptos.end(); ++i) { |
| 205 if (rtc::CS_AES_CM_128_HMAC_SHA1_80 == i->cipher_suite || | 231 if ((crypto_options.enable_gcm_crypto_suites && |
| 232 rtc::IsGcmCryptoSuiteName(i->cipher_suite)) || | |
|
mattdr
2016/05/06 22:34:14
one more space on this line to align with the begi
joachim
2016/05/09 23:21:40
Done.
| |
| 233 rtc::CS_AES_CM_128_HMAC_SHA1_80 == i->cipher_suite || | |
| 206 (rtc::CS_AES_CM_128_HMAC_SHA1_32 == i->cipher_suite && audio && | 234 (rtc::CS_AES_CM_128_HMAC_SHA1_32 == i->cipher_suite && audio && |
| 207 !bundle)) { | 235 !bundle)) { |
| 208 return CreateCryptoParams(i->tag, i->cipher_suite, crypto); | 236 return CreateCryptoParams(i->tag, i->cipher_suite, crypto); |
| 209 } | 237 } |
| 210 } | 238 } |
| 211 return false; | 239 return false; |
| 212 } | 240 } |
| 213 | 241 |
| 214 static const StreamParams* FindFirstStreamParamsByCname( | 242 static const StreamParams* FindFirstStreamParamsByCname( |
| 215 const StreamParamsVec& params_vec, | 243 const StreamParamsVec& params_vec, |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1060 &negotiated_rtp_extensions); | 1088 &negotiated_rtp_extensions); |
| 1061 answer->set_rtp_header_extensions(negotiated_rtp_extensions); | 1089 answer->set_rtp_header_extensions(negotiated_rtp_extensions); |
| 1062 | 1090 |
| 1063 answer->set_rtcp_mux(options.rtcp_mux_enabled && offer->rtcp_mux()); | 1091 answer->set_rtcp_mux(options.rtcp_mux_enabled && offer->rtcp_mux()); |
| 1064 if (answer->type() == cricket::MEDIA_TYPE_VIDEO) { | 1092 if (answer->type() == cricket::MEDIA_TYPE_VIDEO) { |
| 1065 answer->set_rtcp_reduced_size(offer->rtcp_reduced_size()); | 1093 answer->set_rtcp_reduced_size(offer->rtcp_reduced_size()); |
| 1066 } | 1094 } |
| 1067 | 1095 |
| 1068 if (sdes_policy != SEC_DISABLED) { | 1096 if (sdes_policy != SEC_DISABLED) { |
| 1069 CryptoParams crypto; | 1097 CryptoParams crypto; |
| 1070 if (SelectCrypto(offer, bundle_enabled, &crypto)) { | 1098 if (SelectCrypto(offer, bundle_enabled, options.crypto_options, &crypto)) { |
| 1071 if (current_cryptos) { | 1099 if (current_cryptos) { |
| 1072 FindMatchingCrypto(*current_cryptos, crypto, &crypto); | 1100 FindMatchingCrypto(*current_cryptos, crypto, &crypto); |
| 1073 } | 1101 } |
| 1074 answer->AddCrypto(crypto); | 1102 answer->AddCrypto(crypto); |
| 1075 } | 1103 } |
| 1076 } | 1104 } |
| 1077 | 1105 |
| 1078 if (answer->cryptos().empty() && | 1106 if (answer->cryptos().empty() && |
| 1079 (offer->crypto_required() == CT_SDES || sdes_policy == SEC_REQUIRED)) { | 1107 (offer->crypto_required() == CT_SDES || sdes_policy == SEC_REQUIRED)) { |
| 1080 return false; | 1108 return false; |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1576 GetFirstAudioContent(current_description); | 1604 GetFirstAudioContent(current_description); |
| 1577 std::string content_name = | 1605 std::string content_name = |
| 1578 current_audio_content ? current_audio_content->name : CN_AUDIO; | 1606 current_audio_content ? current_audio_content->name : CN_AUDIO; |
| 1579 | 1607 |
| 1580 cricket::SecurePolicy sdes_policy = | 1608 cricket::SecurePolicy sdes_policy = |
| 1581 IsDtlsActive(content_name, current_description) ? cricket::SEC_DISABLED | 1609 IsDtlsActive(content_name, current_description) ? cricket::SEC_DISABLED |
| 1582 : secure(); | 1610 : secure(); |
| 1583 | 1611 |
| 1584 std::unique_ptr<AudioContentDescription> audio(new AudioContentDescription()); | 1612 std::unique_ptr<AudioContentDescription> audio(new AudioContentDescription()); |
| 1585 std::vector<std::string> crypto_suites; | 1613 std::vector<std::string> crypto_suites; |
| 1586 GetSupportedAudioCryptoSuiteNames(&crypto_suites); | 1614 GetSupportedAudioCryptoSuiteNames(options.crypto_options, &crypto_suites); |
| 1587 if (!CreateMediaContentOffer( | 1615 if (!CreateMediaContentOffer( |
| 1588 options, | 1616 options, |
| 1589 audio_codecs, | 1617 audio_codecs, |
| 1590 sdes_policy, | 1618 sdes_policy, |
| 1591 GetCryptos(GetFirstAudioContentDescription(current_description)), | 1619 GetCryptos(GetFirstAudioContentDescription(current_description)), |
| 1592 crypto_suites, | 1620 crypto_suites, |
| 1593 audio_rtp_extensions, | 1621 audio_rtp_extensions, |
| 1594 add_legacy_, | 1622 add_legacy_, |
| 1595 current_streams, | 1623 current_streams, |
| 1596 audio.get())) { | 1624 audio.get())) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1636 GetFirstVideoContent(current_description); | 1664 GetFirstVideoContent(current_description); |
| 1637 std::string content_name = | 1665 std::string content_name = |
| 1638 current_video_content ? current_video_content->name : CN_VIDEO; | 1666 current_video_content ? current_video_content->name : CN_VIDEO; |
| 1639 | 1667 |
| 1640 cricket::SecurePolicy sdes_policy = | 1668 cricket::SecurePolicy sdes_policy = |
| 1641 IsDtlsActive(content_name, current_description) ? cricket::SEC_DISABLED | 1669 IsDtlsActive(content_name, current_description) ? cricket::SEC_DISABLED |
| 1642 : secure(); | 1670 : secure(); |
| 1643 | 1671 |
| 1644 std::unique_ptr<VideoContentDescription> video(new VideoContentDescription()); | 1672 std::unique_ptr<VideoContentDescription> video(new VideoContentDescription()); |
| 1645 std::vector<std::string> crypto_suites; | 1673 std::vector<std::string> crypto_suites; |
| 1646 GetSupportedVideoCryptoSuiteNames(&crypto_suites); | 1674 GetSupportedVideoCryptoSuiteNames(options.crypto_options, &crypto_suites); |
| 1647 if (!CreateMediaContentOffer( | 1675 if (!CreateMediaContentOffer( |
| 1648 options, | 1676 options, |
| 1649 video_codecs, | 1677 video_codecs, |
| 1650 sdes_policy, | 1678 sdes_policy, |
| 1651 GetCryptos(GetFirstVideoContentDescription(current_description)), | 1679 GetCryptos(GetFirstVideoContentDescription(current_description)), |
| 1652 crypto_suites, | 1680 crypto_suites, |
| 1653 video_rtp_extensions, | 1681 video_rtp_extensions, |
| 1654 add_legacy_, | 1682 add_legacy_, |
| 1655 current_streams, | 1683 current_streams, |
| 1656 video.get())) { | 1684 video.get())) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1712 // SDES doesn't make sense for SCTP, so we disable it, and we only | 1740 // SDES doesn't make sense for SCTP, so we disable it, and we only |
| 1713 // get SDES crypto suites for RTP-based data channels. | 1741 // get SDES crypto suites for RTP-based data channels. |
| 1714 sdes_policy = cricket::SEC_DISABLED; | 1742 sdes_policy = cricket::SEC_DISABLED; |
| 1715 // Unlike SetMediaProtocol below, we need to set the protocol | 1743 // Unlike SetMediaProtocol below, we need to set the protocol |
| 1716 // before we call CreateMediaContentOffer. Otherwise, | 1744 // before we call CreateMediaContentOffer. Otherwise, |
| 1717 // CreateMediaContentOffer won't know this is SCTP and will | 1745 // CreateMediaContentOffer won't know this is SCTP and will |
| 1718 // generate SSRCs rather than SIDs. | 1746 // generate SSRCs rather than SIDs. |
| 1719 data->set_protocol( | 1747 data->set_protocol( |
| 1720 secure_transport ? kMediaProtocolDtlsSctp : kMediaProtocolSctp); | 1748 secure_transport ? kMediaProtocolDtlsSctp : kMediaProtocolSctp); |
| 1721 } else { | 1749 } else { |
| 1722 GetSupportedDataCryptoSuiteNames(&crypto_suites); | 1750 GetSupportedDataCryptoSuiteNames(options.crypto_options, &crypto_suites); |
| 1723 } | 1751 } |
| 1724 | 1752 |
| 1725 if (!CreateMediaContentOffer( | 1753 if (!CreateMediaContentOffer( |
| 1726 options, | 1754 options, |
| 1727 *data_codecs, | 1755 *data_codecs, |
| 1728 sdes_policy, | 1756 sdes_policy, |
| 1729 GetCryptos(GetFirstDataContentDescription(current_description)), | 1757 GetCryptos(GetFirstDataContentDescription(current_description)), |
| 1730 crypto_suites, | 1758 crypto_suites, |
| 1731 RtpHeaderExtensions(), | 1759 RtpHeaderExtensions(), |
| 1732 add_legacy_, | 1760 add_legacy_, |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2004 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); | 2032 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); |
| 2005 } | 2033 } |
| 2006 | 2034 |
| 2007 const DataContentDescription* GetFirstDataContentDescription( | 2035 const DataContentDescription* GetFirstDataContentDescription( |
| 2008 const SessionDescription* sdesc) { | 2036 const SessionDescription* sdesc) { |
| 2009 return static_cast<const DataContentDescription*>( | 2037 return static_cast<const DataContentDescription*>( |
| 2010 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); | 2038 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); |
| 2011 } | 2039 } |
| 2012 | 2040 |
| 2013 } // namespace cricket | 2041 } // namespace cricket |
| OLD | NEW |