| 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 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 bool SetProvisionalAnswer(const std::vector<CryptoParams>& answer_params, | 71 bool SetProvisionalAnswer(const std::vector<CryptoParams>& answer_params, |
| 72 ContentSource source); | 72 ContentSource source); |
| 73 // Indicates which crypto algorithms and keys were contained in the answer. | 73 // Indicates which crypto algorithms and keys were contained in the answer. |
| 74 // answer_params should contain the negotiated parameters, which may be none, | 74 // 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). | 75 // if crypto was not desired or could not be negotiated (and not required). |
| 76 // This must be called after SetOffer. If crypto negotiation completes | 76 // This must be called after SetOffer. If crypto negotiation completes |
| 77 // successfully, this will advance the filter to the active state. | 77 // successfully, this will advance the filter to the active state. |
| 78 bool SetAnswer(const std::vector<CryptoParams>& answer_params, | 78 bool SetAnswer(const std::vector<CryptoParams>& answer_params, |
| 79 ContentSource source); | 79 ContentSource source); |
| 80 | 80 |
| 81 // Set the header extension ids that should be encrypted for the given source. |
| 82 void SetEncryptedHeaderExtensionIds(ContentSource source, |
| 83 const std::vector<int>& extension_ids); |
| 84 |
| 81 // Just set up both sets of keys directly. | 85 // Just set up both sets of keys directly. |
| 82 // Used with DTLS-SRTP. | 86 // Used with DTLS-SRTP. |
| 83 bool SetRtpParams(int send_cs, | 87 bool SetRtpParams(int send_cs, |
| 84 const uint8_t* send_key, | 88 const uint8_t* send_key, |
| 85 int send_key_len, | 89 int send_key_len, |
| 86 int recv_cs, | 90 int recv_cs, |
| 87 const uint8_t* recv_key, | 91 const uint8_t* recv_key, |
| 88 int recv_key_len); | 92 int recv_key_len); |
| 93 bool UpdateRtpParams(int send_cs, |
| 94 const uint8_t* send_key, |
| 95 int send_key_len, |
| 96 int recv_cs, |
| 97 const uint8_t* recv_key, |
| 98 int recv_key_len); |
| 89 bool SetRtcpParams(int send_cs, | 99 bool SetRtcpParams(int send_cs, |
| 90 const uint8_t* send_key, | 100 const uint8_t* send_key, |
| 91 int send_key_len, | 101 int send_key_len, |
| 92 int recv_cs, | 102 int recv_cs, |
| 93 const uint8_t* recv_key, | 103 const uint8_t* recv_key, |
| 94 int recv_key_len); | 104 int recv_key_len); |
| 95 | 105 |
| 96 // Encrypts/signs an individual RTP/RTCP packet, in-place. | 106 // Encrypts/signs an individual RTP/RTCP packet, in-place. |
| 97 // If an HMAC is used, this will increase the packet size. | 107 // 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); | 108 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 State state_ = ST_INIT; | 188 State state_ = ST_INIT; |
| 179 int signal_silent_time_in_ms_ = 0; | 189 int signal_silent_time_in_ms_ = 0; |
| 180 bool external_auth_enabled_ = false; | 190 bool external_auth_enabled_ = false; |
| 181 std::vector<CryptoParams> offer_params_; | 191 std::vector<CryptoParams> offer_params_; |
| 182 std::unique_ptr<SrtpSession> send_session_; | 192 std::unique_ptr<SrtpSession> send_session_; |
| 183 std::unique_ptr<SrtpSession> recv_session_; | 193 std::unique_ptr<SrtpSession> recv_session_; |
| 184 std::unique_ptr<SrtpSession> send_rtcp_session_; | 194 std::unique_ptr<SrtpSession> send_rtcp_session_; |
| 185 std::unique_ptr<SrtpSession> recv_rtcp_session_; | 195 std::unique_ptr<SrtpSession> recv_rtcp_session_; |
| 186 CryptoParams applied_send_params_; | 196 CryptoParams applied_send_params_; |
| 187 CryptoParams applied_recv_params_; | 197 CryptoParams applied_recv_params_; |
| 198 std::vector<int> send_encrypted_header_extension_ids_; |
| 199 std::vector<int> recv_encrypted_header_extension_ids_; |
| 188 }; | 200 }; |
| 189 | 201 |
| 190 // Class that wraps a libSRTP session. | 202 // Class that wraps a libSRTP session. |
| 191 class SrtpSession { | 203 class SrtpSession { |
| 192 public: | 204 public: |
| 193 SrtpSession(); | 205 SrtpSession(); |
| 194 ~SrtpSession(); | 206 ~SrtpSession(); |
| 195 | 207 |
| 196 // Configures the session for sending data using the specified | 208 // Configures the session for sending data using the specified |
| 197 // cipher-suite and key. Receiving must be done by a separate session. | 209 // cipher-suite and key. Receiving must be done by a separate session. |
| 198 bool SetSend(int cs, const uint8_t* key, size_t len); | 210 bool SetSend(int cs, const uint8_t* key, size_t len); |
| 211 bool UpdateSend(int cs, const uint8_t* key, size_t len); |
| 212 |
| 199 // Configures the session for receiving data using the specified | 213 // Configures the session for receiving data using the specified |
| 200 // cipher-suite and key. Sending must be done by a separate session. | 214 // cipher-suite and key. Sending must be done by a separate session. |
| 201 bool SetRecv(int cs, const uint8_t* key, size_t len); | 215 bool SetRecv(int cs, const uint8_t* key, size_t len); |
| 216 bool UpdateRecv(int cs, const uint8_t* key, size_t len); |
| 217 |
| 218 void SetEncryptedHeaderExtensionIds( |
| 219 const std::vector<int>& encrypted_header_extension_ids); |
| 202 | 220 |
| 203 // Encrypts/signs an individual RTP/RTCP packet, in-place. | 221 // Encrypts/signs an individual RTP/RTCP packet, in-place. |
| 204 // If an HMAC is used, this will increase the packet size. | 222 // 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); | 223 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); |
| 206 // Overloaded version, outputs packet index. | 224 // Overloaded version, outputs packet index. |
| 207 bool ProtectRtp(void* data, | 225 bool ProtectRtp(void* data, |
| 208 int in_len, | 226 int in_len, |
| 209 int max_len, | 227 int max_len, |
| 210 int* out_len, | 228 int* out_len, |
| 211 int64_t* index); | 229 int64_t* index); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 236 // Update the silent threshold (in ms) for signaling errors. | 254 // Update the silent threshold (in ms) for signaling errors. |
| 237 void set_signal_silent_time(int signal_silent_time_in_ms); | 255 void set_signal_silent_time(int signal_silent_time_in_ms); |
| 238 | 256 |
| 239 // Calls srtp_shutdown if it's initialized. | 257 // Calls srtp_shutdown if it's initialized. |
| 240 static void Terminate(); | 258 static void Terminate(); |
| 241 | 259 |
| 242 sigslot::repeater3<uint32_t, SrtpFilter::Mode, SrtpFilter::Error> | 260 sigslot::repeater3<uint32_t, SrtpFilter::Mode, SrtpFilter::Error> |
| 243 SignalSrtpError; | 261 SignalSrtpError; |
| 244 | 262 |
| 245 private: | 263 private: |
| 264 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); | 265 bool SetKey(int type, int cs, const uint8_t* key, size_t len); |
| 266 bool UpdateKey(int type, int cs, const uint8_t* key, size_t len); |
| 267 bool SetEncryptedHeaderExtensionIds(int type, |
| 268 const std::vector<int>& encrypted_header_extension_ids); |
| 247 // Returns send stream current packet index from srtp db. | 269 // Returns send stream current packet index from srtp db. |
| 248 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); | 270 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); |
| 249 | 271 |
| 250 static bool Init(); | 272 static bool Init(); |
| 251 void HandleEvent(const srtp_event_data_t* ev); | 273 void HandleEvent(const srtp_event_data_t* ev); |
| 252 static void HandleEventThunk(srtp_event_data_t* ev); | 274 static void HandleEventThunk(srtp_event_data_t* ev); |
| 253 | 275 |
| 254 rtc::ThreadChecker thread_checker_; | 276 rtc::ThreadChecker thread_checker_; |
| 255 srtp_ctx_t_* session_ = nullptr; | 277 srtp_ctx_t_* session_ = nullptr; |
| 256 int rtp_auth_tag_len_ = 0; | 278 int rtp_auth_tag_len_ = 0; |
| 257 int rtcp_auth_tag_len_ = 0; | 279 int rtcp_auth_tag_len_ = 0; |
| 258 std::unique_ptr<SrtpStat> srtp_stat_; | 280 std::unique_ptr<SrtpStat> srtp_stat_; |
| 259 static bool inited_; | 281 static bool inited_; |
| 260 static rtc::GlobalLockPod lock_; | 282 static rtc::GlobalLockPod lock_; |
| 261 int last_send_seq_num_ = -1; | 283 int last_send_seq_num_ = -1; |
| 262 bool external_auth_active_ = false; | 284 bool external_auth_active_ = false; |
| 263 bool external_auth_enabled_ = false; | 285 bool external_auth_enabled_ = false; |
| 286 std::vector<int> encrypted_header_extension_ids_; |
| 264 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession); | 287 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession); |
| 265 }; | 288 }; |
| 266 | 289 |
| 267 // Class that collects failures of SRTP. | 290 // Class that collects failures of SRTP. |
| 268 class SrtpStat { | 291 class SrtpStat { |
| 269 public: | 292 public: |
| 270 SrtpStat(); | 293 SrtpStat(); |
| 271 | 294 |
| 272 // Report RTP protection results to the handler. | 295 // Report RTP protection results to the handler. |
| 273 void AddProtectRtpResult(uint32_t ssrc, int result); | 296 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_; | 355 std::map<FailureKey, FailureStat> failures_; |
| 333 // Threshold in ms to silent the signaling errors. | 356 // Threshold in ms to silent the signaling errors. |
| 334 int signal_silent_time_; | 357 int signal_silent_time_; |
| 335 | 358 |
| 336 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStat); | 359 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStat); |
| 337 }; | 360 }; |
| 338 | 361 |
| 339 } // namespace cricket | 362 } // namespace cricket |
| 340 | 363 |
| 341 #endif // WEBRTC_PC_SRTPFILTER_H_ | 364 #endif // WEBRTC_PC_SRTPFILTER_H_ |
| OLD | NEW |