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); |
89 bool SetRtcpParams(int send_cs, | 96 bool SetRtcpParams(int send_cs, |
90 const uint8_t* send_key, | 97 const uint8_t* send_key, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 143 |
137 protected: | 144 protected: |
138 bool ExpectOffer(ContentSource source); | 145 bool ExpectOffer(ContentSource source); |
139 bool StoreParams(const std::vector<CryptoParams>& params, | 146 bool StoreParams(const std::vector<CryptoParams>& params, |
140 ContentSource source); | 147 ContentSource source); |
141 bool ExpectAnswer(ContentSource source); | 148 bool ExpectAnswer(ContentSource source); |
142 bool DoSetAnswer(const std::vector<CryptoParams>& answer_params, | 149 bool DoSetAnswer(const std::vector<CryptoParams>& answer_params, |
143 ContentSource source, | 150 ContentSource source, |
144 bool final); | 151 bool final); |
145 void CreateSrtpSessions(); | 152 void CreateSrtpSessions(); |
| 153 void GetSendRecvEncryptedHeaderExtensions( |
| 154 std::vector<int>* send_extensions, std::vector<int>* recv_extensions); |
146 bool NegotiateParams(const std::vector<CryptoParams>& answer_params, | 155 bool NegotiateParams(const std::vector<CryptoParams>& answer_params, |
147 CryptoParams* selected_params); | 156 CryptoParams* selected_params); |
148 bool ApplyParams(const CryptoParams& send_params, | 157 bool ApplyParams(const CryptoParams& send_params, |
149 const CryptoParams& recv_params); | 158 const CryptoParams& recv_params); |
150 static bool ParseKeyParams(const std::string& params, | 159 static bool ParseKeyParams(const std::string& params, |
151 uint8_t* key, | 160 uint8_t* key, |
152 size_t len); | 161 size_t len); |
153 | 162 |
154 private: | 163 private: |
155 enum State { | 164 enum State { |
(...skipping 22 matching lines...) Expand all Loading... |
178 State state_ = ST_INIT; | 187 State state_ = ST_INIT; |
179 int signal_silent_time_in_ms_ = 0; | 188 int signal_silent_time_in_ms_ = 0; |
180 bool external_auth_enabled_ = false; | 189 bool external_auth_enabled_ = false; |
181 std::vector<CryptoParams> offer_params_; | 190 std::vector<CryptoParams> offer_params_; |
182 std::unique_ptr<SrtpSession> send_session_; | 191 std::unique_ptr<SrtpSession> send_session_; |
183 std::unique_ptr<SrtpSession> recv_session_; | 192 std::unique_ptr<SrtpSession> recv_session_; |
184 std::unique_ptr<SrtpSession> send_rtcp_session_; | 193 std::unique_ptr<SrtpSession> send_rtcp_session_; |
185 std::unique_ptr<SrtpSession> recv_rtcp_session_; | 194 std::unique_ptr<SrtpSession> recv_rtcp_session_; |
186 CryptoParams applied_send_params_; | 195 CryptoParams applied_send_params_; |
187 CryptoParams applied_recv_params_; | 196 CryptoParams applied_recv_params_; |
| 197 std::vector<webrtc::RtpExtension> local_encrypted_header_extensions_; |
| 198 std::vector<webrtc::RtpExtension> remote_encrypted_header_extensions_; |
188 }; | 199 }; |
189 | 200 |
190 // Class that wraps a libSRTP session. | 201 // Class that wraps a libSRTP session. |
191 class SrtpSession { | 202 class SrtpSession { |
192 public: | 203 public: |
193 SrtpSession(); | 204 SrtpSession(); |
194 ~SrtpSession(); | 205 ~SrtpSession(); |
195 | 206 |
196 // Configures the session for sending data using the specified | 207 // Configures the session for sending data using the specified |
197 // cipher-suite and key. Receiving must be done by a separate session. | 208 // cipher-suite and key. Receiving must be done by a separate session. |
198 bool SetSend(int cs, const uint8_t* key, size_t len); | 209 bool SetSend(int cs, const uint8_t* key, size_t len, |
| 210 const std::vector<int>& encrypted_header_extensions); |
199 // Configures the session for receiving data using the specified | 211 // Configures the session for receiving data using the specified |
200 // cipher-suite and key. Sending must be done by a separate session. | 212 // cipher-suite and key. Sending must be done by a separate session. |
201 bool SetRecv(int cs, const uint8_t* key, size_t len); | 213 bool SetRecv(int cs, const uint8_t* key, size_t len, |
| 214 const std::vector<int>& encrypted_header_extensions); |
202 | 215 |
203 // Encrypts/signs an individual RTP/RTCP packet, in-place. | 216 // Encrypts/signs an individual RTP/RTCP packet, in-place. |
204 // If an HMAC is used, this will increase the packet size. | 217 // 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); | 218 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); |
206 // Overloaded version, outputs packet index. | 219 // Overloaded version, outputs packet index. |
207 bool ProtectRtp(void* data, | 220 bool ProtectRtp(void* data, |
208 int in_len, | 221 int in_len, |
209 int max_len, | 222 int max_len, |
210 int* out_len, | 223 int* out_len, |
211 int64_t* index); | 224 int64_t* index); |
(...skipping 24 matching lines...) Expand all Loading... |
236 // Update the silent threshold (in ms) for signaling errors. | 249 // Update the silent threshold (in ms) for signaling errors. |
237 void set_signal_silent_time(int signal_silent_time_in_ms); | 250 void set_signal_silent_time(int signal_silent_time_in_ms); |
238 | 251 |
239 // Calls srtp_shutdown if it's initialized. | 252 // Calls srtp_shutdown if it's initialized. |
240 static void Terminate(); | 253 static void Terminate(); |
241 | 254 |
242 sigslot::repeater3<uint32_t, SrtpFilter::Mode, SrtpFilter::Error> | 255 sigslot::repeater3<uint32_t, SrtpFilter::Mode, SrtpFilter::Error> |
243 SignalSrtpError; | 256 SignalSrtpError; |
244 | 257 |
245 private: | 258 private: |
246 bool SetKey(int type, int cs, const uint8_t* key, size_t len); | 259 bool SetKeyAndEncryptedHeaderExtensions(int type, int cs, const uint8_t* key, |
| 260 size_t len, const std::vector<int>& encrypted_header_extensions); |
247 // Returns send stream current packet index from srtp db. | 261 // Returns send stream current packet index from srtp db. |
248 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); | 262 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); |
249 | 263 |
250 static bool Init(); | 264 static bool Init(); |
251 void HandleEvent(const srtp_event_data_t* ev); | 265 void HandleEvent(const srtp_event_data_t* ev); |
252 static void HandleEventThunk(srtp_event_data_t* ev); | 266 static void HandleEventThunk(srtp_event_data_t* ev); |
253 | 267 |
254 rtc::ThreadChecker thread_checker_; | 268 rtc::ThreadChecker thread_checker_; |
255 srtp_ctx_t_* session_ = nullptr; | 269 srtp_ctx_t_* session_ = nullptr; |
256 int rtp_auth_tag_len_ = 0; | 270 int rtp_auth_tag_len_ = 0; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 std::map<FailureKey, FailureStat> failures_; | 346 std::map<FailureKey, FailureStat> failures_; |
333 // Threshold in ms to silent the signaling errors. | 347 // Threshold in ms to silent the signaling errors. |
334 int signal_silent_time_; | 348 int signal_silent_time_; |
335 | 349 |
336 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStat); | 350 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStat); |
337 }; | 351 }; |
338 | 352 |
339 } // namespace cricket | 353 } // namespace cricket |
340 | 354 |
341 #endif // WEBRTC_PC_SRTPFILTER_H_ | 355 #endif // WEBRTC_PC_SRTPFILTER_H_ |
OLD | NEW |