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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // If an HMAC is used, this will decrease the packet size. | 107 // If an HMAC is used, this will decrease the packet size. |
108 bool UnprotectRtp(void* data, int in_len, int* out_len); | 108 bool UnprotectRtp(void* data, int in_len, int* out_len); |
109 bool UnprotectRtcp(void* data, int in_len, int* out_len); | 109 bool UnprotectRtcp(void* data, int in_len, int* out_len); |
110 | 110 |
111 // Returns rtp auth params from srtp context. | 111 // Returns rtp auth params from srtp context. |
112 bool GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len); | 112 bool GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len); |
113 | 113 |
114 // Returns srtp overhead for rtp packets. | 114 // Returns srtp overhead for rtp packets. |
115 bool GetSrtpOverhead(int* srtp_overhead) const; | 115 bool GetSrtpOverhead(int* srtp_overhead) const; |
116 | 116 |
117 #if defined(ENABLE_EXTERNAL_AUTH) | 117 // If external auth is enabled, SRTP will write a dummy auth tag that then |
| 118 // later must get replaced before the packet is sent out. Only supported for |
| 119 // non-GCM cipher suites and can be checked through "IsExternalAuthActive" |
| 120 // if it is actually used. This method is only valid before the RTP params |
| 121 // have been set. |
| 122 void EnableExternalAuth(); |
| 123 bool IsExternalAuthEnabled() const; |
| 124 |
118 // A SRTP filter supports external creation of the auth tag if a non-GCM | 125 // A SRTP filter supports external creation of the auth tag if a non-GCM |
119 // cipher is used. This method is only valid after the RTP params have | 126 // cipher is used. This method is only valid after the RTP params have |
120 // been set. | 127 // been set. |
121 bool IsExternalAuthActive() const; | 128 bool IsExternalAuthActive() const; |
122 #endif | |
123 | 129 |
124 // Update the silent threshold (in ms) for signaling errors. | 130 // Update the silent threshold (in ms) for signaling errors. |
125 void set_signal_silent_time(int signal_silent_time_in_ms); | 131 void set_signal_silent_time(int signal_silent_time_in_ms); |
126 | 132 |
127 bool ResetParams(); | 133 bool ResetParams(); |
128 | 134 |
129 sigslot::repeater3<uint32_t, Mode, Error> SignalSrtpError; | 135 sigslot::repeater3<uint32_t, Mode, Error> SignalSrtpError; |
130 | 136 |
131 protected: | 137 protected: |
132 bool ExpectOffer(ContentSource source); | 138 bool ExpectOffer(ContentSource source); |
(...skipping 29 matching lines...) Expand all Loading... |
162 ST_RECEIVEDUPDATEDOFFER, | 168 ST_RECEIVEDUPDATEDOFFER, |
163 // SRTP filter is active but the sent answer is only provisional. | 169 // SRTP filter is active but the sent answer is only provisional. |
164 // When the final answer is set, the state transitions to ST_ACTIVE or | 170 // When the final answer is set, the state transitions to ST_ACTIVE or |
165 // ST_INIT. | 171 // ST_INIT. |
166 ST_SENTPRANSWER, | 172 ST_SENTPRANSWER, |
167 // SRTP filter is active but the received answer is only provisional. | 173 // SRTP filter is active but the received answer is only provisional. |
168 // When the final answer is set, the state transitions to ST_ACTIVE or | 174 // When the final answer is set, the state transitions to ST_ACTIVE or |
169 // ST_INIT. | 175 // ST_INIT. |
170 ST_RECEIVEDPRANSWER | 176 ST_RECEIVEDPRANSWER |
171 }; | 177 }; |
172 State state_; | 178 State state_ = ST_INIT; |
173 int signal_silent_time_in_ms_; | 179 int signal_silent_time_in_ms_ = 0; |
| 180 bool external_auth_enabled_ = false; |
174 std::vector<CryptoParams> offer_params_; | 181 std::vector<CryptoParams> offer_params_; |
175 std::unique_ptr<SrtpSession> send_session_; | 182 std::unique_ptr<SrtpSession> send_session_; |
176 std::unique_ptr<SrtpSession> recv_session_; | 183 std::unique_ptr<SrtpSession> recv_session_; |
177 std::unique_ptr<SrtpSession> send_rtcp_session_; | 184 std::unique_ptr<SrtpSession> send_rtcp_session_; |
178 std::unique_ptr<SrtpSession> recv_rtcp_session_; | 185 std::unique_ptr<SrtpSession> recv_rtcp_session_; |
179 CryptoParams applied_send_params_; | 186 CryptoParams applied_send_params_; |
180 CryptoParams applied_recv_params_; | 187 CryptoParams applied_recv_params_; |
181 }; | 188 }; |
182 | 189 |
183 // Class that wraps a libSRTP session. | 190 // Class that wraps a libSRTP session. |
(...skipping 22 matching lines...) Expand all Loading... |
206 // Decrypts/verifies an invidiual RTP/RTCP packet. | 213 // Decrypts/verifies an invidiual RTP/RTCP packet. |
207 // If an HMAC is used, this will decrease the packet size. | 214 // If an HMAC is used, this will decrease the packet size. |
208 bool UnprotectRtp(void* data, int in_len, int* out_len); | 215 bool UnprotectRtp(void* data, int in_len, int* out_len); |
209 bool UnprotectRtcp(void* data, int in_len, int* out_len); | 216 bool UnprotectRtcp(void* data, int in_len, int* out_len); |
210 | 217 |
211 // Helper method to get authentication params. | 218 // Helper method to get authentication params. |
212 bool GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len); | 219 bool GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len); |
213 | 220 |
214 int GetSrtpOverhead() const; | 221 int GetSrtpOverhead() const; |
215 | 222 |
216 #if defined(ENABLE_EXTERNAL_AUTH) | 223 // If external auth is enabled, SRTP will write a dummy auth tag that then |
| 224 // later must get replaced before the packet is sent out. Only supported for |
| 225 // non-GCM cipher suites and can be checked through "IsExternalAuthActive" |
| 226 // if it is actually used. This method is only valid before the RTP params |
| 227 // have been set. |
| 228 void EnableExternalAuth(); |
| 229 bool IsExternalAuthEnabled() const; |
| 230 |
217 // A SRTP session supports external creation of the auth tag if a non-GCM | 231 // A SRTP session supports external creation of the auth tag if a non-GCM |
218 // cipher is used. This method is only valid after the RTP params have | 232 // cipher is used. This method is only valid after the RTP params have |
219 // been set. | 233 // been set. |
220 bool IsExternalAuthActive() const; | 234 bool IsExternalAuthActive() const; |
221 #endif | |
222 | 235 |
223 // Update the silent threshold (in ms) for signaling errors. | 236 // Update the silent threshold (in ms) for signaling errors. |
224 void set_signal_silent_time(int signal_silent_time_in_ms); | 237 void set_signal_silent_time(int signal_silent_time_in_ms); |
225 | 238 |
226 // Calls srtp_shutdown if it's initialized. | 239 // Calls srtp_shutdown if it's initialized. |
227 static void Terminate(); | 240 static void Terminate(); |
228 | 241 |
229 sigslot::repeater3<uint32_t, SrtpFilter::Mode, SrtpFilter::Error> | 242 sigslot::repeater3<uint32_t, SrtpFilter::Mode, SrtpFilter::Error> |
230 SignalSrtpError; | 243 SignalSrtpError; |
231 | 244 |
232 private: | 245 private: |
233 bool SetKey(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); |
234 // Returns send stream current packet index from srtp db. | 247 // Returns send stream current packet index from srtp db. |
235 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); | 248 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); |
236 | 249 |
237 static bool Init(); | 250 static bool Init(); |
238 void HandleEvent(const srtp_event_data_t* ev); | 251 void HandleEvent(const srtp_event_data_t* ev); |
239 static void HandleEventThunk(srtp_event_data_t* ev); | 252 static void HandleEventThunk(srtp_event_data_t* ev); |
240 | 253 |
241 rtc::ThreadChecker thread_checker_; | 254 rtc::ThreadChecker thread_checker_; |
242 srtp_ctx_t_* session_ = nullptr; | 255 srtp_ctx_t_* session_ = nullptr; |
243 int rtp_auth_tag_len_ = 0; | 256 int rtp_auth_tag_len_ = 0; |
244 int rtcp_auth_tag_len_ = 0; | 257 int rtcp_auth_tag_len_ = 0; |
245 std::unique_ptr<SrtpStat> srtp_stat_; | 258 std::unique_ptr<SrtpStat> srtp_stat_; |
246 static bool inited_; | 259 static bool inited_; |
247 static rtc::GlobalLockPod lock_; | 260 static rtc::GlobalLockPod lock_; |
248 int last_send_seq_num_ = -1; | 261 int last_send_seq_num_ = -1; |
249 #if defined(ENABLE_EXTERNAL_AUTH) | |
250 bool external_auth_active_ = false; | 262 bool external_auth_active_ = false; |
251 #endif | 263 bool external_auth_enabled_ = false; |
252 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession); | 264 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession); |
253 }; | 265 }; |
254 | 266 |
255 // Class that collects failures of SRTP. | 267 // Class that collects failures of SRTP. |
256 class SrtpStat { | 268 class SrtpStat { |
257 public: | 269 public: |
258 SrtpStat(); | 270 SrtpStat(); |
259 | 271 |
260 // Report RTP protection results to the handler. | 272 // Report RTP protection results to the handler. |
261 void AddProtectRtpResult(uint32_t ssrc, int result); | 273 void AddProtectRtpResult(uint32_t ssrc, int result); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 std::map<FailureKey, FailureStat> failures_; | 332 std::map<FailureKey, FailureStat> failures_; |
321 // Threshold in ms to silent the signaling errors. | 333 // Threshold in ms to silent the signaling errors. |
322 int signal_silent_time_; | 334 int signal_silent_time_; |
323 | 335 |
324 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStat); | 336 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStat); |
325 }; | 337 }; |
326 | 338 |
327 } // namespace cricket | 339 } // namespace cricket |
328 | 340 |
329 #endif // WEBRTC_PC_SRTPFILTER_H_ | 341 #endif // WEBRTC_PC_SRTPFILTER_H_ |
OLD | NEW |