| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 bool SetProvisionalAnswer(const std::vector<CryptoParams>& answer_params, | 69 bool SetProvisionalAnswer(const std::vector<CryptoParams>& answer_params, |
| 70 ContentSource source); | 70 ContentSource source); |
| 71 // Indicates which crypto algorithms and keys were contained in the answer. | 71 // Indicates which crypto algorithms and keys were contained in the answer. |
| 72 // answer_params should contain the negotiated parameters, which may be none, | 72 // answer_params should contain the negotiated parameters, which may be none, |
| 73 // if crypto was not desired or could not be negotiated (and not required). | 73 // if crypto was not desired or could not be negotiated (and not required). |
| 74 // This must be called after SetOffer. If crypto negotiation completes | 74 // This must be called after SetOffer. If crypto negotiation completes |
| 75 // successfully, this will advance the filter to the active state. | 75 // successfully, this will advance the filter to the active state. |
| 76 bool SetAnswer(const std::vector<CryptoParams>& answer_params, | 76 bool SetAnswer(const std::vector<CryptoParams>& answer_params, |
| 77 ContentSource source); | 77 ContentSource source); |
| 78 | 78 |
| 79 // Set the header extension ids that should be encrypted for the given source. |
| 80 void SetEncryptedHeaderExtensionIds(ContentSource source, |
| 81 const std::vector<int>& extension_ids); |
| 82 |
| 79 // Just set up both sets of keys directly. | 83 // Just set up both sets of keys directly. |
| 80 // Used with DTLS-SRTP. | 84 // Used with DTLS-SRTP. |
| 81 bool SetRtpParams(int send_cs, | 85 bool SetRtpParams(int send_cs, |
| 82 const uint8_t* send_key, | 86 const uint8_t* send_key, |
| 83 int send_key_len, | 87 int send_key_len, |
| 84 int recv_cs, | 88 int recv_cs, |
| 85 const uint8_t* recv_key, | 89 const uint8_t* recv_key, |
| 86 int recv_key_len); | 90 int recv_key_len); |
| 91 bool UpdateRtpParams(int send_cs, |
| 92 const uint8_t* send_key, |
| 93 int send_key_len, |
| 94 int recv_cs, |
| 95 const uint8_t* recv_key, |
| 96 int recv_key_len); |
| 87 bool SetRtcpParams(int send_cs, | 97 bool SetRtcpParams(int send_cs, |
| 88 const uint8_t* send_key, | 98 const uint8_t* send_key, |
| 89 int send_key_len, | 99 int send_key_len, |
| 90 int recv_cs, | 100 int recv_cs, |
| 91 const uint8_t* recv_key, | 101 const uint8_t* recv_key, |
| 92 int recv_key_len); | 102 int recv_key_len); |
| 93 | 103 |
| 94 // Encrypts/signs an individual RTP/RTCP packet, in-place. | 104 // Encrypts/signs an individual RTP/RTCP packet, in-place. |
| 95 // If an HMAC is used, this will increase the packet size. | 105 // If an HMAC is used, this will increase the packet size. |
| 96 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); | 106 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 }; | 180 }; |
| 171 State state_ = ST_INIT; | 181 State state_ = ST_INIT; |
| 172 bool external_auth_enabled_ = false; | 182 bool external_auth_enabled_ = false; |
| 173 std::vector<CryptoParams> offer_params_; | 183 std::vector<CryptoParams> offer_params_; |
| 174 std::unique_ptr<SrtpSession> send_session_; | 184 std::unique_ptr<SrtpSession> send_session_; |
| 175 std::unique_ptr<SrtpSession> recv_session_; | 185 std::unique_ptr<SrtpSession> recv_session_; |
| 176 std::unique_ptr<SrtpSession> send_rtcp_session_; | 186 std::unique_ptr<SrtpSession> send_rtcp_session_; |
| 177 std::unique_ptr<SrtpSession> recv_rtcp_session_; | 187 std::unique_ptr<SrtpSession> recv_rtcp_session_; |
| 178 CryptoParams applied_send_params_; | 188 CryptoParams applied_send_params_; |
| 179 CryptoParams applied_recv_params_; | 189 CryptoParams applied_recv_params_; |
| 190 std::vector<int> send_encrypted_header_extension_ids_; |
| 191 std::vector<int> recv_encrypted_header_extension_ids_; |
| 180 }; | 192 }; |
| 181 | 193 |
| 182 // Class that wraps a libSRTP session. | 194 // Class that wraps a libSRTP session. |
| 183 class SrtpSession { | 195 class SrtpSession { |
| 184 public: | 196 public: |
| 185 SrtpSession(); | 197 SrtpSession(); |
| 186 ~SrtpSession(); | 198 ~SrtpSession(); |
| 187 | 199 |
| 188 // Configures the session for sending data using the specified | 200 // Configures the session for sending data using the specified |
| 189 // cipher-suite and key. Receiving must be done by a separate session. | 201 // cipher-suite and key. Receiving must be done by a separate session. |
| 190 bool SetSend(int cs, const uint8_t* key, size_t len); | 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 |
| 191 // Configures the session for receiving data using the specified | 205 // Configures the session for receiving data using the specified |
| 192 // cipher-suite and key. Sending must be done by a separate session. | 206 // cipher-suite and key. Sending must be done by a separate session. |
| 193 bool SetRecv(int cs, const uint8_t* key, size_t len); | 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); |
| 194 | 212 |
| 195 // Encrypts/signs an individual RTP/RTCP packet, in-place. | 213 // Encrypts/signs an individual RTP/RTCP packet, in-place. |
| 196 // If an HMAC is used, this will increase the packet size. | 214 // If an HMAC is used, this will increase the packet size. |
| 197 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); | 215 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); |
| 198 // Overloaded version, outputs packet index. | 216 // Overloaded version, outputs packet index. |
| 199 bool ProtectRtp(void* data, | 217 bool ProtectRtp(void* data, |
| 200 int in_len, | 218 int in_len, |
| 201 int max_len, | 219 int max_len, |
| 202 int* out_len, | 220 int* out_len, |
| 203 int64_t* index); | 221 int64_t* index); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 222 | 240 |
| 223 // A SRTP session supports external creation of the auth tag if a non-GCM | 241 // A SRTP session supports external creation of the auth tag if a non-GCM |
| 224 // cipher is used. This method is only valid after the RTP params have | 242 // cipher is used. This method is only valid after the RTP params have |
| 225 // been set. | 243 // been set. |
| 226 bool IsExternalAuthActive() const; | 244 bool IsExternalAuthActive() const; |
| 227 | 245 |
| 228 // Calls srtp_shutdown if it's initialized. | 246 // Calls srtp_shutdown if it's initialized. |
| 229 static void Terminate(); | 247 static void Terminate(); |
| 230 | 248 |
| 231 private: | 249 private: |
| 250 bool DoSetKey(int type, int cs, const uint8_t* key, size_t len); |
| 232 bool SetKey(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); |
| 233 // Returns send stream current packet index from srtp db. | 255 // Returns send stream current packet index from srtp db. |
| 234 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); | 256 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); |
| 235 | 257 |
| 236 static bool Init(); | 258 static bool Init(); |
| 237 void HandleEvent(const srtp_event_data_t* ev); | 259 void HandleEvent(const srtp_event_data_t* ev); |
| 238 static void HandleEventThunk(srtp_event_data_t* ev); | 260 static void HandleEventThunk(srtp_event_data_t* ev); |
| 239 | 261 |
| 240 rtc::ThreadChecker thread_checker_; | 262 rtc::ThreadChecker thread_checker_; |
| 241 srtp_ctx_t_* session_ = nullptr; | 263 srtp_ctx_t_* session_ = nullptr; |
| 242 int rtp_auth_tag_len_ = 0; | 264 int rtp_auth_tag_len_ = 0; |
| 243 int rtcp_auth_tag_len_ = 0; | 265 int rtcp_auth_tag_len_ = 0; |
| 244 static bool inited_; | 266 static bool inited_; |
| 245 static rtc::GlobalLockPod lock_; | 267 static rtc::GlobalLockPod lock_; |
| 246 int last_send_seq_num_ = -1; | 268 int last_send_seq_num_ = -1; |
| 247 bool external_auth_active_ = false; | 269 bool external_auth_active_ = false; |
| 248 bool external_auth_enabled_ = false; | 270 bool external_auth_enabled_ = false; |
| 271 std::vector<int> encrypted_header_extension_ids_; |
| 249 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession); | 272 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession); |
| 250 }; | 273 }; |
| 251 | 274 |
| 252 } // namespace cricket | 275 } // namespace cricket |
| 253 | 276 |
| 254 #endif // WEBRTC_PC_SRTPFILTER_H_ | 277 #endif // WEBRTC_PC_SRTPFILTER_H_ |
| OLD | NEW |