Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: webrtc/pc/srtpfilter.h

Issue 2976443002: Move SrtpSession and tests to their own files. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/pc/DEPS ('k') | webrtc/pc/srtpfilter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 std::unique_ptr<SrtpSession> send_session_; 184 std::unique_ptr<SrtpSession> send_session_;
185 std::unique_ptr<SrtpSession> recv_session_; 185 std::unique_ptr<SrtpSession> recv_session_;
186 std::unique_ptr<SrtpSession> send_rtcp_session_; 186 std::unique_ptr<SrtpSession> send_rtcp_session_;
187 std::unique_ptr<SrtpSession> recv_rtcp_session_; 187 std::unique_ptr<SrtpSession> recv_rtcp_session_;
188 CryptoParams applied_send_params_; 188 CryptoParams applied_send_params_;
189 CryptoParams applied_recv_params_; 189 CryptoParams applied_recv_params_;
190 std::vector<int> send_encrypted_header_extension_ids_; 190 std::vector<int> send_encrypted_header_extension_ids_;
191 std::vector<int> recv_encrypted_header_extension_ids_; 191 std::vector<int> recv_encrypted_header_extension_ids_;
192 }; 192 };
193 193
194 // Class that wraps a libSRTP session.
195 class SrtpSession {
196 public:
197 SrtpSession();
198 ~SrtpSession();
199
200 // Configures the session for sending data using the specified
201 // cipher-suite and key. Receiving must be done by a separate session.
202 bool SetSend(int cs, const uint8_t* key, size_t len);
203 bool UpdateSend(int cs, const uint8_t* key, size_t len);
204
205 // Configures the session for receiving data using the specified
206 // cipher-suite and key. Sending must be done by a separate session.
207 bool SetRecv(int cs, const uint8_t* key, size_t len);
208 bool UpdateRecv(int cs, const uint8_t* key, size_t len);
209
210 void SetEncryptedHeaderExtensionIds(
211 const std::vector<int>& encrypted_header_extension_ids);
212
213 // Encrypts/signs an individual RTP/RTCP packet, in-place.
214 // If an HMAC is used, this will increase the packet size.
215 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len);
216 // Overloaded version, outputs packet index.
217 bool ProtectRtp(void* data,
218 int in_len,
219 int max_len,
220 int* out_len,
221 int64_t* index);
222 bool ProtectRtcp(void* data, int in_len, int max_len, int* out_len);
223 // Decrypts/verifies an invidiual RTP/RTCP packet.
224 // If an HMAC is used, this will decrease the packet size.
225 bool UnprotectRtp(void* data, int in_len, int* out_len);
226 bool UnprotectRtcp(void* data, int in_len, int* out_len);
227
228 // Helper method to get authentication params.
229 bool GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len);
230
231 int GetSrtpOverhead() const;
232
233 // If external auth is enabled, SRTP will write a dummy auth tag that then
234 // later must get replaced before the packet is sent out. Only supported for
235 // non-GCM cipher suites and can be checked through "IsExternalAuthActive"
236 // if it is actually used. This method is only valid before the RTP params
237 // have been set.
238 void EnableExternalAuth();
239 bool IsExternalAuthEnabled() const;
240
241 // A SRTP session supports external creation of the auth tag if a non-GCM
242 // cipher is used. This method is only valid after the RTP params have
243 // been set.
244 bool IsExternalAuthActive() const;
245
246 // Calls srtp_shutdown if it's initialized.
247 static void Terminate();
248
249 private:
250 bool DoSetKey(int type, int cs, const uint8_t* key, size_t len);
251 bool SetKey(int type, int cs, const uint8_t* key, size_t len);
252 bool UpdateKey(int type, int cs, const uint8_t* key, size_t len);
253 bool SetEncryptedHeaderExtensionIds(int type,
254 const std::vector<int>& encrypted_header_extension_ids);
255 // Returns send stream current packet index from srtp db.
256 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index);
257
258 static bool Init();
259 void HandleEvent(const srtp_event_data_t* ev);
260 static void HandleEventThunk(srtp_event_data_t* ev);
261
262 rtc::ThreadChecker thread_checker_;
263 srtp_ctx_t_* session_ = nullptr;
264 int rtp_auth_tag_len_ = 0;
265 int rtcp_auth_tag_len_ = 0;
266 static bool inited_;
267 static rtc::GlobalLockPod lock_;
268 int last_send_seq_num_ = -1;
269 bool external_auth_active_ = false;
270 bool external_auth_enabled_ = false;
271 std::vector<int> encrypted_header_extension_ids_;
272 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession);
273 };
274
275 } // namespace cricket 194 } // namespace cricket
276 195
277 #endif // WEBRTC_PC_SRTPFILTER_H_ 196 #endif // WEBRTC_PC_SRTPFILTER_H_
OLDNEW
« no previous file with comments | « webrtc/pc/DEPS ('k') | webrtc/pc/srtpfilter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698