OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2009 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 |
11 #ifndef WEBRTC_PC_SRTPFILTER_H_ | 11 #ifndef WEBRTC_PC_SRTPFILTER_H_ |
12 #define WEBRTC_PC_SRTPFILTER_H_ | 12 #define WEBRTC_PC_SRTPFILTER_H_ |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <map> | 15 #include <map> |
16 #include <memory> | 16 #include <memory> |
17 #include <string> | 17 #include <string> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "webrtc/base/basictypes.h" | 20 #include "webrtc/base/basictypes.h" |
21 #include "webrtc/base/constructormagic.h" | 21 #include "webrtc/base/constructormagic.h" |
22 #include "webrtc/base/criticalsection.h" | 22 #include "webrtc/base/criticalsection.h" |
23 #include "webrtc/base/sigslotrepeater.h" | 23 #include "webrtc/base/sigslotrepeater.h" |
24 #include "webrtc/base/sslstreamadapter.h" | 24 #include "webrtc/base/sslstreamadapter.h" |
25 #include "webrtc/base/thread_checker.h" | 25 #include "webrtc/base/thread_checker.h" |
| 26 #include "webrtc/config.h" |
26 #include "webrtc/media/base/cryptoparams.h" | 27 #include "webrtc/media/base/cryptoparams.h" |
27 #include "webrtc/p2p/base/sessiondescription.h" | 28 #include "webrtc/p2p/base/sessiondescription.h" |
28 | 29 |
29 // Forward declaration to avoid pulling in libsrtp headers here | 30 // Forward declaration to avoid pulling in libsrtp headers here |
30 struct srtp_event_data_t; | 31 struct srtp_event_data_t; |
31 struct srtp_ctx_t_; | 32 struct srtp_ctx_t_; |
32 | 33 |
33 namespace cricket { | 34 namespace cricket { |
34 | 35 |
35 class SrtpSession; | 36 class SrtpSession; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 bool SetProvisionalAnswer(const std::vector<CryptoParams>& answer_params, | 72 bool SetProvisionalAnswer(const std::vector<CryptoParams>& answer_params, |
72 ContentSource source); | 73 ContentSource source); |
73 // Indicates which crypto algorithms and keys were contained in the answer. | 74 // Indicates which crypto algorithms and keys were contained in the answer. |
74 // answer_params should contain the negotiated parameters, which may be none, | 75 // answer_params should contain the negotiated parameters, which may be none, |
75 // if crypto was not desired or could not be negotiated (and not required). | 76 // if crypto was not desired or could not be negotiated (and not required). |
76 // This must be called after SetOffer. If crypto negotiation completes | 77 // This must be called after SetOffer. If crypto negotiation completes |
77 // successfully, this will advance the filter to the active state. | 78 // successfully, this will advance the filter to the active state. |
78 bool SetAnswer(const std::vector<CryptoParams>& answer_params, | 79 bool SetAnswer(const std::vector<CryptoParams>& answer_params, |
79 ContentSource source); | 80 ContentSource source); |
80 | 81 |
| 82 // Set the header extensions that should be encrypted for the given source. |
| 83 // Only header extensions that should be encrypted for both sides will be |
| 84 // encrypted. |
| 85 void SetEncryptedHeaderExtensions(ContentSource source, |
| 86 const std::vector<webrtc::RtpExtension>& extensions); |
| 87 |
81 // Just set up both sets of keys directly. | 88 // Just set up both sets of keys directly. |
82 // Used with DTLS-SRTP. | 89 // Used with DTLS-SRTP. |
83 bool SetRtpParams(int send_cs, | 90 bool SetRtpParams(int send_cs, |
84 const uint8_t* send_key, | 91 const uint8_t* send_key, |
85 int send_key_len, | 92 int send_key_len, |
86 int recv_cs, | 93 int recv_cs, |
87 const uint8_t* recv_key, | 94 const uint8_t* recv_key, |
88 int recv_key_len); | 95 int recv_key_len); |
| 96 bool UpdateRtpParams(int send_cs, |
| 97 const uint8_t* send_key, |
| 98 int send_key_len, |
| 99 int recv_cs, |
| 100 const uint8_t* recv_key, |
| 101 int recv_key_len); |
89 bool SetRtcpParams(int send_cs, | 102 bool SetRtcpParams(int send_cs, |
90 const uint8_t* send_key, | 103 const uint8_t* send_key, |
91 int send_key_len, | 104 int send_key_len, |
92 int recv_cs, | 105 int recv_cs, |
93 const uint8_t* recv_key, | 106 const uint8_t* recv_key, |
94 int recv_key_len); | 107 int recv_key_len); |
95 | 108 |
96 // Encrypts/signs an individual RTP/RTCP packet, in-place. | 109 // Encrypts/signs an individual RTP/RTCP packet, in-place. |
97 // If an HMAC is used, this will increase the packet size. | 110 // If an HMAC is used, this will increase the packet size. |
98 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); | 111 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 149 |
137 protected: | 150 protected: |
138 bool ExpectOffer(ContentSource source); | 151 bool ExpectOffer(ContentSource source); |
139 bool StoreParams(const std::vector<CryptoParams>& params, | 152 bool StoreParams(const std::vector<CryptoParams>& params, |
140 ContentSource source); | 153 ContentSource source); |
141 bool ExpectAnswer(ContentSource source); | 154 bool ExpectAnswer(ContentSource source); |
142 bool DoSetAnswer(const std::vector<CryptoParams>& answer_params, | 155 bool DoSetAnswer(const std::vector<CryptoParams>& answer_params, |
143 ContentSource source, | 156 ContentSource source, |
144 bool final); | 157 bool final); |
145 void CreateSrtpSessions(); | 158 void CreateSrtpSessions(); |
| 159 void GetSendRecvEncryptedHeaderExtensions( |
| 160 std::vector<int>* send_extensions, std::vector<int>* recv_extensions); |
146 bool NegotiateParams(const std::vector<CryptoParams>& answer_params, | 161 bool NegotiateParams(const std::vector<CryptoParams>& answer_params, |
147 CryptoParams* selected_params); | 162 CryptoParams* selected_params); |
148 bool ApplyParams(const CryptoParams& send_params, | 163 bool ApplyParams(const CryptoParams& send_params, |
149 const CryptoParams& recv_params); | 164 const CryptoParams& recv_params); |
150 static bool ParseKeyParams(const std::string& params, | 165 static bool ParseKeyParams(const std::string& params, |
151 uint8_t* key, | 166 uint8_t* key, |
152 size_t len); | 167 size_t len); |
153 | 168 |
154 private: | 169 private: |
155 enum State { | 170 enum State { |
(...skipping 22 matching lines...) Expand all Loading... |
178 State state_ = ST_INIT; | 193 State state_ = ST_INIT; |
179 int signal_silent_time_in_ms_ = 0; | 194 int signal_silent_time_in_ms_ = 0; |
180 bool external_auth_enabled_ = false; | 195 bool external_auth_enabled_ = false; |
181 std::vector<CryptoParams> offer_params_; | 196 std::vector<CryptoParams> offer_params_; |
182 std::unique_ptr<SrtpSession> send_session_; | 197 std::unique_ptr<SrtpSession> send_session_; |
183 std::unique_ptr<SrtpSession> recv_session_; | 198 std::unique_ptr<SrtpSession> recv_session_; |
184 std::unique_ptr<SrtpSession> send_rtcp_session_; | 199 std::unique_ptr<SrtpSession> send_rtcp_session_; |
185 std::unique_ptr<SrtpSession> recv_rtcp_session_; | 200 std::unique_ptr<SrtpSession> recv_rtcp_session_; |
186 CryptoParams applied_send_params_; | 201 CryptoParams applied_send_params_; |
187 CryptoParams applied_recv_params_; | 202 CryptoParams applied_recv_params_; |
| 203 std::vector<webrtc::RtpExtension> local_encrypted_header_extensions_; |
| 204 std::vector<webrtc::RtpExtension> remote_encrypted_header_extensions_; |
188 }; | 205 }; |
189 | 206 |
190 // Class that wraps a libSRTP session. | 207 // Class that wraps a libSRTP session. |
191 class SrtpSession { | 208 class SrtpSession { |
192 public: | 209 public: |
193 SrtpSession(); | 210 SrtpSession(); |
194 ~SrtpSession(); | 211 ~SrtpSession(); |
195 | 212 |
196 // Configures the session for sending data using the specified | 213 // Configures the session for sending data using the specified |
197 // cipher-suite and key. Receiving must be done by a separate session. | 214 // cipher-suite and key. Receiving must be done by a separate session. |
198 bool SetSend(int cs, const uint8_t* key, size_t len); | 215 bool SetSend(int cs, const uint8_t* key, size_t len); |
| 216 bool UpdateSend(int cs, const uint8_t* key, size_t len); |
| 217 |
199 // Configures the session for receiving data using the specified | 218 // Configures the session for receiving data using the specified |
200 // cipher-suite and key. Sending must be done by a separate session. | 219 // cipher-suite and key. Sending must be done by a separate session. |
201 bool SetRecv(int cs, const uint8_t* key, size_t len); | 220 bool SetRecv(int cs, const uint8_t* key, size_t len); |
| 221 bool UpdateRecv(int cs, const uint8_t* key, size_t len); |
| 222 |
| 223 void SetEncryptedHeaderExtensions( |
| 224 const std::vector<int>& encrypted_header_extensions); |
202 | 225 |
203 // Encrypts/signs an individual RTP/RTCP packet, in-place. | 226 // Encrypts/signs an individual RTP/RTCP packet, in-place. |
204 // If an HMAC is used, this will increase the packet size. | 227 // If an HMAC is used, this will increase the packet size. |
205 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); | 228 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); |
206 // Overloaded version, outputs packet index. | 229 // Overloaded version, outputs packet index. |
207 bool ProtectRtp(void* data, | 230 bool ProtectRtp(void* data, |
208 int in_len, | 231 int in_len, |
209 int max_len, | 232 int max_len, |
210 int* out_len, | 233 int* out_len, |
211 int64_t* index); | 234 int64_t* index); |
(...skipping 24 matching lines...) Expand all Loading... |
236 // Update the silent threshold (in ms) for signaling errors. | 259 // Update the silent threshold (in ms) for signaling errors. |
237 void set_signal_silent_time(int signal_silent_time_in_ms); | 260 void set_signal_silent_time(int signal_silent_time_in_ms); |
238 | 261 |
239 // Calls srtp_shutdown if it's initialized. | 262 // Calls srtp_shutdown if it's initialized. |
240 static void Terminate(); | 263 static void Terminate(); |
241 | 264 |
242 sigslot::repeater3<uint32_t, SrtpFilter::Mode, SrtpFilter::Error> | 265 sigslot::repeater3<uint32_t, SrtpFilter::Mode, SrtpFilter::Error> |
243 SignalSrtpError; | 266 SignalSrtpError; |
244 | 267 |
245 private: | 268 private: |
| 269 bool DoSetKey(int type, int cs, const uint8_t* key, size_t len); |
246 bool SetKey(int type, int cs, const uint8_t* key, size_t len); | 270 bool SetKey(int type, int cs, const uint8_t* key, size_t len); |
| 271 bool UpdateKey(int type, int cs, const uint8_t* key, size_t len); |
| 272 bool SetEncryptedHeaderExtensions(int type, |
| 273 const std::vector<int>& encrypted_header_extensions); |
247 // Returns send stream current packet index from srtp db. | 274 // Returns send stream current packet index from srtp db. |
248 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); | 275 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); |
249 | 276 |
250 static bool Init(); | 277 static bool Init(); |
251 void HandleEvent(const srtp_event_data_t* ev); | 278 void HandleEvent(const srtp_event_data_t* ev); |
252 static void HandleEventThunk(srtp_event_data_t* ev); | 279 static void HandleEventThunk(srtp_event_data_t* ev); |
253 | 280 |
254 rtc::ThreadChecker thread_checker_; | 281 rtc::ThreadChecker thread_checker_; |
255 srtp_ctx_t_* session_ = nullptr; | 282 srtp_ctx_t_* session_ = nullptr; |
256 int rtp_auth_tag_len_ = 0; | 283 int rtp_auth_tag_len_ = 0; |
257 int rtcp_auth_tag_len_ = 0; | 284 int rtcp_auth_tag_len_ = 0; |
258 std::unique_ptr<SrtpStat> srtp_stat_; | 285 std::unique_ptr<SrtpStat> srtp_stat_; |
259 static bool inited_; | 286 static bool inited_; |
260 static rtc::GlobalLockPod lock_; | 287 static rtc::GlobalLockPod lock_; |
261 int last_send_seq_num_ = -1; | 288 int last_send_seq_num_ = -1; |
262 bool external_auth_active_ = false; | 289 bool external_auth_active_ = false; |
263 bool external_auth_enabled_ = false; | 290 bool external_auth_enabled_ = false; |
| 291 std::vector<int> encrypted_header_extensions_; |
264 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession); | 292 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession); |
265 }; | 293 }; |
266 | 294 |
267 // Class that collects failures of SRTP. | 295 // Class that collects failures of SRTP. |
268 class SrtpStat { | 296 class SrtpStat { |
269 public: | 297 public: |
270 SrtpStat(); | 298 SrtpStat(); |
271 | 299 |
272 // Report RTP protection results to the handler. | 300 // Report RTP protection results to the handler. |
273 void AddProtectRtpResult(uint32_t ssrc, int result); | 301 void AddProtectRtpResult(uint32_t ssrc, int result); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 std::map<FailureKey, FailureStat> failures_; | 360 std::map<FailureKey, FailureStat> failures_; |
333 // Threshold in ms to silent the signaling errors. | 361 // Threshold in ms to silent the signaling errors. |
334 int signal_silent_time_; | 362 int signal_silent_time_; |
335 | 363 |
336 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStat); | 364 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStat); |
337 }; | 365 }; |
338 | 366 |
339 } // namespace cricket | 367 } // namespace cricket |
340 | 368 |
341 #endif // WEBRTC_PC_SRTPFILTER_H_ | 369 #endif // WEBRTC_PC_SRTPFILTER_H_ |
OLD | NEW |