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 21 matching lines...) Expand all Loading... |
32 #include "webrtc/pc/channelmanager.h" | 32 #include "webrtc/pc/channelmanager.h" |
33 #include "webrtc/pc/srtpfilter.h" | 33 #include "webrtc/pc/srtpfilter.h" |
34 | 34 |
35 namespace { | 35 namespace { |
36 const char kInline[] = "inline:"; | 36 const char kInline[] = "inline:"; |
37 | 37 |
38 void GetSupportedCryptoSuiteNames(void (*func)(const rtc::CryptoOptions&, | 38 void GetSupportedCryptoSuiteNames(void (*func)(const rtc::CryptoOptions&, |
39 std::vector<int>*), | 39 std::vector<int>*), |
40 const rtc::CryptoOptions& crypto_options, | 40 const rtc::CryptoOptions& crypto_options, |
41 std::vector<std::string>* names) { | 41 std::vector<std::string>* names) { |
42 #ifdef HAVE_SRTP | |
43 std::vector<int> crypto_suites; | 42 std::vector<int> crypto_suites; |
44 func(crypto_options, &crypto_suites); | 43 func(crypto_options, &crypto_suites); |
45 for (const auto crypto : crypto_suites) { | 44 for (const auto crypto : crypto_suites) { |
46 names->push_back(rtc::SrtpCryptoSuiteToName(crypto)); | 45 names->push_back(rtc::SrtpCryptoSuiteToName(crypto)); |
47 } | 46 } |
48 #endif | |
49 } | 47 } |
50 } // namespace | 48 } // namespace |
51 | 49 |
52 namespace cricket { | 50 namespace cricket { |
53 | 51 |
54 // RTP Profile names | 52 // RTP Profile names |
55 // http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml | 53 // http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml |
56 // RFC4585 | 54 // RFC4585 |
57 const char kMediaProtocolAvpf[] = "RTP/AVPF"; | 55 const char kMediaProtocolAvpf[] = "RTP/AVPF"; |
58 // RFC5124 | 56 // RFC5124 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 RTC_CHECK_EQ(master_key_len, master_key.size()); | 122 RTC_CHECK_EQ(master_key_len, master_key.size()); |
125 std::string key = rtc::Base64::Encode(master_key); | 123 std::string key = rtc::Base64::Encode(master_key); |
126 | 124 |
127 out->tag = tag; | 125 out->tag = tag; |
128 out->cipher_suite = cipher; | 126 out->cipher_suite = cipher; |
129 out->key_params = kInline; | 127 out->key_params = kInline; |
130 out->key_params += key; | 128 out->key_params += key; |
131 return true; | 129 return true; |
132 } | 130 } |
133 | 131 |
134 #ifdef HAVE_SRTP | |
135 static bool AddCryptoParams(const std::string& cipher_suite, | 132 static bool AddCryptoParams(const std::string& cipher_suite, |
136 CryptoParamsVec *out) { | 133 CryptoParamsVec *out) { |
137 int size = static_cast<int>(out->size()); | 134 int size = static_cast<int>(out->size()); |
138 | 135 |
139 out->resize(size + 1); | 136 out->resize(size + 1); |
140 return CreateCryptoParams(size, cipher_suite, &out->at(size)); | 137 return CreateCryptoParams(size, cipher_suite, &out->at(size)); |
141 } | 138 } |
142 | 139 |
143 void AddMediaCryptos(const CryptoParamsVec& cryptos, | 140 void AddMediaCryptos(const CryptoParamsVec& cryptos, |
144 MediaContentDescription* media) { | 141 MediaContentDescription* media) { |
145 for (CryptoParamsVec::const_iterator crypto = cryptos.begin(); | 142 for (CryptoParamsVec::const_iterator crypto = cryptos.begin(); |
146 crypto != cryptos.end(); ++crypto) { | 143 crypto != cryptos.end(); ++crypto) { |
147 media->AddCrypto(*crypto); | 144 media->AddCrypto(*crypto); |
148 } | 145 } |
149 } | 146 } |
150 | 147 |
151 bool CreateMediaCryptos(const std::vector<std::string>& crypto_suites, | 148 bool CreateMediaCryptos(const std::vector<std::string>& crypto_suites, |
152 MediaContentDescription* media) { | 149 MediaContentDescription* media) { |
153 CryptoParamsVec cryptos; | 150 CryptoParamsVec cryptos; |
154 for (std::vector<std::string>::const_iterator it = crypto_suites.begin(); | 151 for (std::vector<std::string>::const_iterator it = crypto_suites.begin(); |
155 it != crypto_suites.end(); ++it) { | 152 it != crypto_suites.end(); ++it) { |
156 if (!AddCryptoParams(*it, &cryptos)) { | 153 if (!AddCryptoParams(*it, &cryptos)) { |
157 return false; | 154 return false; |
158 } | 155 } |
159 } | 156 } |
160 AddMediaCryptos(cryptos, media); | 157 AddMediaCryptos(cryptos, media); |
161 return true; | 158 return true; |
162 } | 159 } |
163 #endif | |
164 | 160 |
165 const CryptoParamsVec* GetCryptos(const MediaContentDescription* media) { | 161 const CryptoParamsVec* GetCryptos(const MediaContentDescription* media) { |
166 if (!media) { | 162 if (!media) { |
167 return NULL; | 163 return NULL; |
168 } | 164 } |
169 return &media->cryptos(); | 165 return &media->cryptos(); |
170 } | 166 } |
171 | 167 |
172 bool FindMatchingCrypto(const CryptoParamsVec& cryptos, | 168 bool FindMatchingCrypto(const CryptoParamsVec& cryptos, |
173 const CryptoParams& crypto, | 169 const CryptoParams& crypto, |
174 CryptoParams* out) { | 170 CryptoParams* out) { |
175 for (CryptoParamsVec::const_iterator it = cryptos.begin(); | 171 for (CryptoParamsVec::const_iterator it = cryptos.begin(); |
176 it != cryptos.end(); ++it) { | 172 it != cryptos.end(); ++it) { |
177 if (crypto.Matches(*it)) { | 173 if (crypto.Matches(*it)) { |
178 *out = *it; | 174 *out = *it; |
179 return true; | 175 return true; |
180 } | 176 } |
181 } | 177 } |
182 return false; | 178 return false; |
183 } | 179 } |
184 | 180 |
185 // For audio, HMAC 32 is prefered over HMAC 80 because of the low overhead. | 181 // For audio, HMAC 32 is prefered over HMAC 80 because of the low overhead. |
186 void GetSupportedAudioCryptoSuites(const rtc::CryptoOptions& crypto_options, | 182 void GetSupportedAudioCryptoSuites(const rtc::CryptoOptions& crypto_options, |
187 std::vector<int>* crypto_suites) { | 183 std::vector<int>* crypto_suites) { |
188 #ifdef HAVE_SRTP | |
189 if (crypto_options.enable_gcm_crypto_suites) { | 184 if (crypto_options.enable_gcm_crypto_suites) { |
190 crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM); | 185 crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM); |
191 crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM); | 186 crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM); |
192 } | 187 } |
193 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_32); | 188 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_32); |
194 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); | 189 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); |
195 #endif | |
196 } | 190 } |
197 | 191 |
198 void GetSupportedAudioCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, | 192 void GetSupportedAudioCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, |
199 std::vector<std::string>* crypto_suite_names) { | 193 std::vector<std::string>* crypto_suite_names) { |
200 GetSupportedCryptoSuiteNames(GetSupportedAudioCryptoSuites, | 194 GetSupportedCryptoSuiteNames(GetSupportedAudioCryptoSuites, |
201 crypto_options, crypto_suite_names); | 195 crypto_options, crypto_suite_names); |
202 } | 196 } |
203 | 197 |
204 void GetSupportedVideoCryptoSuites(const rtc::CryptoOptions& crypto_options, | 198 void GetSupportedVideoCryptoSuites(const rtc::CryptoOptions& crypto_options, |
205 std::vector<int>* crypto_suites) { | 199 std::vector<int>* crypto_suites) { |
(...skipping 12 matching lines...) Expand all Loading... |
218 } | 212 } |
219 | 213 |
220 void GetSupportedDataCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, | 214 void GetSupportedDataCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, |
221 std::vector<std::string>* crypto_suite_names) { | 215 std::vector<std::string>* crypto_suite_names) { |
222 GetSupportedCryptoSuiteNames(GetSupportedDataCryptoSuites, | 216 GetSupportedCryptoSuiteNames(GetSupportedDataCryptoSuites, |
223 crypto_options, crypto_suite_names); | 217 crypto_options, crypto_suite_names); |
224 } | 218 } |
225 | 219 |
226 void GetDefaultSrtpCryptoSuites(const rtc::CryptoOptions& crypto_options, | 220 void GetDefaultSrtpCryptoSuites(const rtc::CryptoOptions& crypto_options, |
227 std::vector<int>* crypto_suites) { | 221 std::vector<int>* crypto_suites) { |
228 #ifdef HAVE_SRTP | |
229 if (crypto_options.enable_gcm_crypto_suites) { | 222 if (crypto_options.enable_gcm_crypto_suites) { |
230 crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM); | 223 crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM); |
231 crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM); | 224 crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM); |
232 } | 225 } |
233 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); | 226 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); |
234 #endif | |
235 } | 227 } |
236 | 228 |
237 void GetDefaultSrtpCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, | 229 void GetDefaultSrtpCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, |
238 std::vector<std::string>* crypto_suite_names) { | 230 std::vector<std::string>* crypto_suite_names) { |
239 GetSupportedCryptoSuiteNames(GetDefaultSrtpCryptoSuites, | 231 GetSupportedCryptoSuiteNames(GetDefaultSrtpCryptoSuites, |
240 crypto_options, crypto_suite_names); | 232 crypto_options, crypto_suite_names); |
241 } | 233 } |
242 | 234 |
243 // Support any GCM cipher (if enabled through options). For video support only | 235 // Support any GCM cipher (if enabled through options). For video support only |
244 // 80-bit SHA1 HMAC. For audio 32-bit HMAC is tolerated unless bundle is enabled | 236 // 80-bit SHA1 HMAC. For audio 32-bit HMAC is tolerated unless bundle is enabled |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 offer->set_rtcp_reduced_size(true); | 747 offer->set_rtcp_reduced_size(true); |
756 } | 748 } |
757 offer->set_multistream(options.is_muc); | 749 offer->set_multistream(options.is_muc); |
758 offer->set_rtp_header_extensions(rtp_extensions); | 750 offer->set_rtp_header_extensions(rtp_extensions); |
759 | 751 |
760 if (!AddStreamParams(offer->type(), options, current_streams, offer, | 752 if (!AddStreamParams(offer->type(), options, current_streams, offer, |
761 add_legacy_stream)) { | 753 add_legacy_stream)) { |
762 return false; | 754 return false; |
763 } | 755 } |
764 | 756 |
765 #ifdef HAVE_SRTP | |
766 if (secure_policy != SEC_DISABLED) { | 757 if (secure_policy != SEC_DISABLED) { |
767 if (current_cryptos) { | 758 if (current_cryptos) { |
768 AddMediaCryptos(*current_cryptos, offer); | 759 AddMediaCryptos(*current_cryptos, offer); |
769 } | 760 } |
770 if (offer->cryptos().empty()) { | 761 if (offer->cryptos().empty()) { |
771 if (!CreateMediaCryptos(crypto_suites, offer)) { | 762 if (!CreateMediaCryptos(crypto_suites, offer)) { |
772 return false; | 763 return false; |
773 } | 764 } |
774 } | 765 } |
775 } | 766 } |
776 #endif | |
777 | 767 |
778 if (secure_policy == SEC_REQUIRED && offer->cryptos().empty()) { | 768 if (secure_policy == SEC_REQUIRED && offer->cryptos().empty()) { |
779 return false; | 769 return false; |
780 } | 770 } |
781 return true; | 771 return true; |
782 } | 772 } |
783 | 773 |
784 template <class C> | 774 template <class C> |
785 static bool ReferencedCodecsMatch(const std::vector<C>& codecs1, | 775 static bool ReferencedCodecsMatch(const std::vector<C>& codecs1, |
786 const int codec1_id, | 776 const int codec1_id, |
(...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2193 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); | 2183 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); |
2194 } | 2184 } |
2195 | 2185 |
2196 DataContentDescription* GetFirstDataContentDescription( | 2186 DataContentDescription* GetFirstDataContentDescription( |
2197 SessionDescription* sdesc) { | 2187 SessionDescription* sdesc) { |
2198 return static_cast<DataContentDescription*>( | 2188 return static_cast<DataContentDescription*>( |
2199 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); | 2189 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); |
2200 } | 2190 } |
2201 | 2191 |
2202 } // namespace cricket | 2192 } // namespace cricket |
OLD | NEW |