blob: 5ded455ee5ba38268dd56efba4e9bde3503294a6 [file] [log] [blame]
zstein4dde3df2017-07-07 14:26:25 -07001/*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#include "pc/srtp_session.h"
zstein4dde3df2017-07-07 14:26:25 -070012
Danil Chapovalov5740f3e2019-10-10 11:12:15 +020013#include "absl/base/attributes.h"
Steve Anton10542f22019-01-11 09:11:00 -080014#include "media/base/rtp_utils.h"
15#include "pc/external_hmac.h"
16#include "rtc_base/critical_section.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "rtc_base/logging.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "rtc_base/ssl_stream_adapter.h"
Zhi Huang0a5fdbb2018-06-14 10:40:19 -070019#include "system_wrappers/include/metrics.h"
Taylor Brandstetterb140b9f2017-10-12 17:24:16 -070020#include "third_party/libsrtp/include/srtp.h"
21#include "third_party/libsrtp/include/srtp_priv.h"
zstein4dde3df2017-07-07 14:26:25 -070022
23namespace cricket {
24
Zhi Huang0a5fdbb2018-06-14 10:40:19 -070025// One more than the maximum libsrtp error code. Required by
26// RTC_HISTOGRAM_ENUMERATION. Keep this in sync with srtp_error_status_t defined
27// in srtp.h.
28constexpr int kSrtpErrorCodeBoundary = 28;
29
zstein4dde3df2017-07-07 14:26:25 -070030SrtpSession::SrtpSession() {}
31
32SrtpSession::~SrtpSession() {
33 if (session_) {
34 srtp_set_user_data(session_, nullptr);
35 srtp_dealloc(session_);
36 }
Taylor Brandstetterb140b9f2017-10-12 17:24:16 -070037 if (inited_) {
38 DecrementLibsrtpUsageCountAndMaybeDeinit();
39 }
zstein4dde3df2017-07-07 14:26:25 -070040}
41
Zhi Huangc99b6c72017-11-10 16:44:46 -080042bool SrtpSession::SetSend(int cs,
43 const uint8_t* key,
44 size_t len,
45 const std::vector<int>& extension_ids) {
46 return SetKey(ssrc_any_outbound, cs, key, len, extension_ids);
zstein4dde3df2017-07-07 14:26:25 -070047}
48
Zhi Huangc99b6c72017-11-10 16:44:46 -080049bool SrtpSession::UpdateSend(int cs,
50 const uint8_t* key,
51 size_t len,
52 const std::vector<int>& extension_ids) {
53 return UpdateKey(ssrc_any_outbound, cs, key, len, extension_ids);
zstein4dde3df2017-07-07 14:26:25 -070054}
55
Zhi Huangc99b6c72017-11-10 16:44:46 -080056bool SrtpSession::SetRecv(int cs,
57 const uint8_t* key,
58 size_t len,
59 const std::vector<int>& extension_ids) {
60 return SetKey(ssrc_any_inbound, cs, key, len, extension_ids);
zstein4dde3df2017-07-07 14:26:25 -070061}
62
Zhi Huangc99b6c72017-11-10 16:44:46 -080063bool SrtpSession::UpdateRecv(int cs,
64 const uint8_t* key,
65 size_t len,
66 const std::vector<int>& extension_ids) {
67 return UpdateKey(ssrc_any_inbound, cs, key, len, extension_ids);
zstein4dde3df2017-07-07 14:26:25 -070068}
69
70bool SrtpSession::ProtectRtp(void* p, int in_len, int max_len, int* out_len) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +020071 RTC_DCHECK(thread_checker_.IsCurrent());
zstein4dde3df2017-07-07 14:26:25 -070072 if (!session_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010073 RTC_LOG(LS_WARNING) << "Failed to protect SRTP packet: no SRTP Session";
zstein4dde3df2017-07-07 14:26:25 -070074 return false;
75 }
76
77 int need_len = in_len + rtp_auth_tag_len_; // NOLINT
78 if (max_len < need_len) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010079 RTC_LOG(LS_WARNING) << "Failed to protect SRTP packet: The buffer length "
80 << max_len << " is less than the needed " << need_len;
zstein4dde3df2017-07-07 14:26:25 -070081 return false;
82 }
83
84 *out_len = in_len;
85 int err = srtp_protect(session_, p, out_len);
86 int seq_num;
87 GetRtpSeqNum(p, in_len, &seq_num);
88 if (err != srtp_err_status_ok) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010089 RTC_LOG(LS_WARNING) << "Failed to protect SRTP packet, seqnum=" << seq_num
90 << ", err=" << err
91 << ", last seqnum=" << last_send_seq_num_;
zstein4dde3df2017-07-07 14:26:25 -070092 return false;
93 }
94 last_send_seq_num_ = seq_num;
95 return true;
96}
97
98bool SrtpSession::ProtectRtp(void* p,
99 int in_len,
100 int max_len,
101 int* out_len,
102 int64_t* index) {
103 if (!ProtectRtp(p, in_len, max_len, out_len)) {
104 return false;
105 }
106 return (index) ? GetSendStreamPacketIndex(p, in_len, index) : true;
107}
108
109bool SrtpSession::ProtectRtcp(void* p, int in_len, int max_len, int* out_len) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +0200110 RTC_DCHECK(thread_checker_.IsCurrent());
zstein4dde3df2017-07-07 14:26:25 -0700111 if (!session_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100112 RTC_LOG(LS_WARNING) << "Failed to protect SRTCP packet: no SRTP Session";
zstein4dde3df2017-07-07 14:26:25 -0700113 return false;
114 }
115
116 int need_len = in_len + sizeof(uint32_t) + rtcp_auth_tag_len_; // NOLINT
117 if (max_len < need_len) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100118 RTC_LOG(LS_WARNING) << "Failed to protect SRTCP packet: The buffer length "
119 << max_len << " is less than the needed " << need_len;
zstein4dde3df2017-07-07 14:26:25 -0700120 return false;
121 }
122
123 *out_len = in_len;
124 int err = srtp_protect_rtcp(session_, p, out_len);
125 if (err != srtp_err_status_ok) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100126 RTC_LOG(LS_WARNING) << "Failed to protect SRTCP packet, err=" << err;
zstein4dde3df2017-07-07 14:26:25 -0700127 return false;
128 }
129 return true;
130}
131
132bool SrtpSession::UnprotectRtp(void* p, int in_len, int* out_len) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +0200133 RTC_DCHECK(thread_checker_.IsCurrent());
zstein4dde3df2017-07-07 14:26:25 -0700134 if (!session_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100135 RTC_LOG(LS_WARNING) << "Failed to unprotect SRTP packet: no SRTP Session";
zstein4dde3df2017-07-07 14:26:25 -0700136 return false;
137 }
138
139 *out_len = in_len;
140 int err = srtp_unprotect(session_, p, out_len);
141 if (err != srtp_err_status_ok) {
erikvarga@webrtc.orgd76a0fc2018-10-09 12:31:28 +0200142 // Limit the error logging to avoid excessive logs when there are lots of
143 // bad packets.
144 const int kFailureLogThrottleCount = 100;
145 if (decryption_failure_count_ % kFailureLogThrottleCount == 0) {
146 RTC_LOG(LS_WARNING) << "Failed to unprotect SRTP packet, err=" << err
147 << ", previous failure count: "
148 << decryption_failure_count_;
149 }
150 ++decryption_failure_count_;
Qingsi Wang7fc821d2018-07-12 12:54:53 -0700151 RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.SrtpUnprotectError",
Zhi Huang0a5fdbb2018-06-14 10:40:19 -0700152 static_cast<int>(err), kSrtpErrorCodeBoundary);
zstein4dde3df2017-07-07 14:26:25 -0700153 return false;
154 }
155 return true;
156}
157
158bool SrtpSession::UnprotectRtcp(void* p, int in_len, int* out_len) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +0200159 RTC_DCHECK(thread_checker_.IsCurrent());
zstein4dde3df2017-07-07 14:26:25 -0700160 if (!session_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100161 RTC_LOG(LS_WARNING) << "Failed to unprotect SRTCP packet: no SRTP Session";
zstein4dde3df2017-07-07 14:26:25 -0700162 return false;
163 }
164
165 *out_len = in_len;
166 int err = srtp_unprotect_rtcp(session_, p, out_len);
167 if (err != srtp_err_status_ok) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100168 RTC_LOG(LS_WARNING) << "Failed to unprotect SRTCP packet, err=" << err;
Qingsi Wang7fc821d2018-07-12 12:54:53 -0700169 RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.SrtcpUnprotectError",
Zhi Huang0a5fdbb2018-06-14 10:40:19 -0700170 static_cast<int>(err), kSrtpErrorCodeBoundary);
zstein4dde3df2017-07-07 14:26:25 -0700171 return false;
172 }
173 return true;
174}
175
176bool SrtpSession::GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +0200177 RTC_DCHECK(thread_checker_.IsCurrent());
zstein4dde3df2017-07-07 14:26:25 -0700178 RTC_DCHECK(IsExternalAuthActive());
179 if (!IsExternalAuthActive()) {
180 return false;
181 }
182
183 ExternalHmacContext* external_hmac = nullptr;
184 // stream_template will be the reference context for other streams.
185 // Let's use it for getting the keys.
186 srtp_stream_ctx_t* srtp_context = session_->stream_template;
zstein4dde3df2017-07-07 14:26:25 -0700187 if (srtp_context && srtp_context->session_keys &&
188 srtp_context->session_keys->rtp_auth) {
189 external_hmac = reinterpret_cast<ExternalHmacContext*>(
190 srtp_context->session_keys->rtp_auth->state);
191 }
zstein4dde3df2017-07-07 14:26:25 -0700192
193 if (!external_hmac) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100194 RTC_LOG(LS_ERROR) << "Failed to get auth keys from libsrtp!.";
zstein4dde3df2017-07-07 14:26:25 -0700195 return false;
196 }
197
198 *key = external_hmac->key;
199 *key_len = external_hmac->key_length;
200 *tag_len = rtp_auth_tag_len_;
201 return true;
202}
203
204int SrtpSession::GetSrtpOverhead() const {
205 return rtp_auth_tag_len_;
206}
207
208void SrtpSession::EnableExternalAuth() {
209 RTC_DCHECK(!session_);
210 external_auth_enabled_ = true;
211}
212
213bool SrtpSession::IsExternalAuthEnabled() const {
214 return external_auth_enabled_;
215}
216
217bool SrtpSession::IsExternalAuthActive() const {
218 return external_auth_active_;
219}
220
221bool SrtpSession::GetSendStreamPacketIndex(void* p,
222 int in_len,
223 int64_t* index) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +0200224 RTC_DCHECK(thread_checker_.IsCurrent());
zstein4dde3df2017-07-07 14:26:25 -0700225 srtp_hdr_t* hdr = reinterpret_cast<srtp_hdr_t*>(p);
226 srtp_stream_ctx_t* stream = srtp_get_stream(session_, hdr->ssrc);
227 if (!stream) {
228 return false;
229 }
230
231 // Shift packet index, put into network byte order
232 *index = static_cast<int64_t>(rtc::NetworkToHost64(
233 srtp_rdbx_get_packet_index(&stream->rtp_rdbx) << 16));
234 return true;
235}
236
Zhi Huangc99b6c72017-11-10 16:44:46 -0800237bool SrtpSession::DoSetKey(int type,
238 int cs,
239 const uint8_t* key,
240 size_t len,
241 const std::vector<int>& extension_ids) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +0200242 RTC_DCHECK(thread_checker_.IsCurrent());
zstein4dde3df2017-07-07 14:26:25 -0700243
244 srtp_policy_t policy;
245 memset(&policy, 0, sizeof(policy));
246 if (cs == rtc::SRTP_AES128_CM_SHA1_80) {
247 srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp);
248 srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
249 } else if (cs == rtc::SRTP_AES128_CM_SHA1_32) {
250 // RTP HMAC is shortened to 32 bits, but RTCP remains 80 bits.
251 srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp);
252 srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
253 } else if (cs == rtc::SRTP_AEAD_AES_128_GCM) {
254 srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtp);
255 srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtcp);
256 } else if (cs == rtc::SRTP_AEAD_AES_256_GCM) {
257 srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy.rtp);
258 srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy.rtcp);
259 } else {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100260 RTC_LOG(LS_WARNING) << "Failed to " << (session_ ? "update" : "create")
261 << " SRTP session: unsupported cipher_suite " << cs;
zstein4dde3df2017-07-07 14:26:25 -0700262 return false;
263 }
264
265 int expected_key_len;
266 int expected_salt_len;
267 if (!rtc::GetSrtpKeyAndSaltLengths(cs, &expected_key_len,
268 &expected_salt_len)) {
269 // This should never happen.
Jonas Olsson45cc8902018-02-13 10:37:07 +0100270 RTC_NOTREACHED();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100271 RTC_LOG(LS_WARNING)
zstein4dde3df2017-07-07 14:26:25 -0700272 << "Failed to " << (session_ ? "update" : "create")
273 << " SRTP session: unsupported cipher_suite without length information"
274 << cs;
275 return false;
276 }
277
278 if (!key ||
279 len != static_cast<size_t>(expected_key_len + expected_salt_len)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100280 RTC_LOG(LS_WARNING) << "Failed to " << (session_ ? "update" : "create")
281 << " SRTP session: invalid key";
zstein4dde3df2017-07-07 14:26:25 -0700282 return false;
283 }
284
285 policy.ssrc.type = static_cast<srtp_ssrc_type_t>(type);
286 policy.ssrc.value = 0;
287 policy.key = const_cast<uint8_t*>(key);
288 // TODO(astor) parse window size from WSH session-param
289 policy.window_size = 1024;
290 policy.allow_repeat_tx = 1;
291 // If external authentication option is enabled, supply custom auth module
292 // id EXTERNAL_HMAC_SHA1 in the policy structure.
293 // We want to set this option only for rtp packets.
294 // By default policy structure is initialized to HMAC_SHA1.
295 // Enable external HMAC authentication only for outgoing streams and only
296 // for cipher suites that support it (i.e. only non-GCM cipher suites).
297 if (type == ssrc_any_outbound && IsExternalAuthEnabled() &&
298 !rtc::IsGcmCryptoSuite(cs)) {
299 policy.rtp.auth_type = EXTERNAL_HMAC_SHA1;
300 }
Zhi Huangc99b6c72017-11-10 16:44:46 -0800301 if (!extension_ids.empty()) {
302 policy.enc_xtn_hdr = const_cast<int*>(&extension_ids[0]);
303 policy.enc_xtn_hdr_count = static_cast<int>(extension_ids.size());
zstein4dde3df2017-07-07 14:26:25 -0700304 }
305 policy.next = nullptr;
306
307 if (!session_) {
308 int err = srtp_create(&session_, &policy);
309 if (err != srtp_err_status_ok) {
310 session_ = nullptr;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100311 RTC_LOG(LS_ERROR) << "Failed to create SRTP session, err=" << err;
zstein4dde3df2017-07-07 14:26:25 -0700312 return false;
313 }
314 srtp_set_user_data(session_, this);
315 } else {
316 int err = srtp_update(session_, &policy);
317 if (err != srtp_err_status_ok) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100318 RTC_LOG(LS_ERROR) << "Failed to update SRTP session, err=" << err;
zstein4dde3df2017-07-07 14:26:25 -0700319 return false;
320 }
321 }
322
323 rtp_auth_tag_len_ = policy.rtp.auth_tag_len;
324 rtcp_auth_tag_len_ = policy.rtcp.auth_tag_len;
325 external_auth_active_ = (policy.rtp.auth_type == EXTERNAL_HMAC_SHA1);
326 return true;
327}
328
Zhi Huangc99b6c72017-11-10 16:44:46 -0800329bool SrtpSession::SetKey(int type,
330 int cs,
331 const uint8_t* key,
332 size_t len,
333 const std::vector<int>& extension_ids) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +0200334 RTC_DCHECK(thread_checker_.IsCurrent());
zstein4dde3df2017-07-07 14:26:25 -0700335 if (session_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100336 RTC_LOG(LS_ERROR) << "Failed to create SRTP session: "
Jonas Olsson45cc8902018-02-13 10:37:07 +0100337 "SRTP session already created";
zstein4dde3df2017-07-07 14:26:25 -0700338 return false;
339 }
340
Taylor Brandstetterb140b9f2017-10-12 17:24:16 -0700341 // This is the first time we need to actually interact with libsrtp, so
342 // initialize it if needed.
343 if (IncrementLibsrtpUsageCountAndMaybeInit()) {
344 inited_ = true;
345 } else {
zstein4dde3df2017-07-07 14:26:25 -0700346 return false;
347 }
348
Zhi Huangc99b6c72017-11-10 16:44:46 -0800349 return DoSetKey(type, cs, key, len, extension_ids);
zstein4dde3df2017-07-07 14:26:25 -0700350}
351
Zhi Huangc99b6c72017-11-10 16:44:46 -0800352bool SrtpSession::UpdateKey(int type,
353 int cs,
354 const uint8_t* key,
355 size_t len,
356 const std::vector<int>& extension_ids) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +0200357 RTC_DCHECK(thread_checker_.IsCurrent());
zstein4dde3df2017-07-07 14:26:25 -0700358 if (!session_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100359 RTC_LOG(LS_ERROR) << "Failed to update non-existing SRTP session";
zstein4dde3df2017-07-07 14:26:25 -0700360 return false;
361 }
362
Zhi Huangc99b6c72017-11-10 16:44:46 -0800363 return DoSetKey(type, cs, key, len, extension_ids);
zstein4dde3df2017-07-07 14:26:25 -0700364}
365
Danil Chapovalov5740f3e2019-10-10 11:12:15 +0200366ABSL_CONST_INIT int g_libsrtp_usage_count = 0;
367ABSL_CONST_INIT rtc::GlobalLock g_libsrtp_lock;
zstein4dde3df2017-07-07 14:26:25 -0700368
Sebastian Jansson22619b32019-12-12 13:15:54 +0100369void ProhibitLibsrtpInitialization() {
370 rtc::GlobalLockScope ls(&g_libsrtp_lock);
371 ++g_libsrtp_usage_count;
372}
373
Taylor Brandstetterb140b9f2017-10-12 17:24:16 -0700374// static
375bool SrtpSession::IncrementLibsrtpUsageCountAndMaybeInit() {
376 rtc::GlobalLockScope ls(&g_libsrtp_lock);
377
378 RTC_DCHECK_GE(g_libsrtp_usage_count, 0);
379 if (g_libsrtp_usage_count == 0) {
zstein4dde3df2017-07-07 14:26:25 -0700380 int err;
381 err = srtp_init();
382 if (err != srtp_err_status_ok) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100383 RTC_LOG(LS_ERROR) << "Failed to init SRTP, err=" << err;
zstein4dde3df2017-07-07 14:26:25 -0700384 return false;
385 }
386
387 err = srtp_install_event_handler(&SrtpSession::HandleEventThunk);
388 if (err != srtp_err_status_ok) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100389 RTC_LOG(LS_ERROR) << "Failed to install SRTP event handler, err=" << err;
zstein4dde3df2017-07-07 14:26:25 -0700390 return false;
391 }
392
393 err = external_crypto_init();
394 if (err != srtp_err_status_ok) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100395 RTC_LOG(LS_ERROR) << "Failed to initialize fake auth, err=" << err;
zstein4dde3df2017-07-07 14:26:25 -0700396 return false;
397 }
zstein4dde3df2017-07-07 14:26:25 -0700398 }
Taylor Brandstetterb140b9f2017-10-12 17:24:16 -0700399 ++g_libsrtp_usage_count;
zstein4dde3df2017-07-07 14:26:25 -0700400 return true;
401}
402
Taylor Brandstetterb140b9f2017-10-12 17:24:16 -0700403// static
404void SrtpSession::DecrementLibsrtpUsageCountAndMaybeDeinit() {
405 rtc::GlobalLockScope ls(&g_libsrtp_lock);
zstein4dde3df2017-07-07 14:26:25 -0700406
Taylor Brandstetterb140b9f2017-10-12 17:24:16 -0700407 RTC_DCHECK_GE(g_libsrtp_usage_count, 1);
408 if (--g_libsrtp_usage_count == 0) {
zstein4dde3df2017-07-07 14:26:25 -0700409 int err = srtp_shutdown();
410 if (err) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100411 RTC_LOG(LS_ERROR) << "srtp_shutdown failed. err=" << err;
zstein4dde3df2017-07-07 14:26:25 -0700412 }
zstein4dde3df2017-07-07 14:26:25 -0700413 }
414}
415
416void SrtpSession::HandleEvent(const srtp_event_data_t* ev) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +0200417 RTC_DCHECK(thread_checker_.IsCurrent());
zstein4dde3df2017-07-07 14:26:25 -0700418 switch (ev->event) {
419 case event_ssrc_collision:
Mirko Bonadei675513b2017-11-09 11:09:25 +0100420 RTC_LOG(LS_INFO) << "SRTP event: SSRC collision";
zstein4dde3df2017-07-07 14:26:25 -0700421 break;
422 case event_key_soft_limit:
Mirko Bonadei675513b2017-11-09 11:09:25 +0100423 RTC_LOG(LS_INFO) << "SRTP event: reached soft key usage limit";
zstein4dde3df2017-07-07 14:26:25 -0700424 break;
425 case event_key_hard_limit:
Mirko Bonadei675513b2017-11-09 11:09:25 +0100426 RTC_LOG(LS_INFO) << "SRTP event: reached hard key usage limit";
zstein4dde3df2017-07-07 14:26:25 -0700427 break;
428 case event_packet_index_limit:
Mirko Bonadei675513b2017-11-09 11:09:25 +0100429 RTC_LOG(LS_INFO)
430 << "SRTP event: reached hard packet limit (2^48 packets)";
zstein4dde3df2017-07-07 14:26:25 -0700431 break;
432 default:
Mirko Bonadei675513b2017-11-09 11:09:25 +0100433 RTC_LOG(LS_INFO) << "SRTP event: unknown " << ev->event;
zstein4dde3df2017-07-07 14:26:25 -0700434 break;
435 }
436}
437
438void SrtpSession::HandleEventThunk(srtp_event_data_t* ev) {
439 // Callback will be executed from same thread that calls the "srtp_protect"
440 // and "srtp_unprotect" functions.
441 SrtpSession* session =
442 static_cast<SrtpSession*>(srtp_get_user_data(ev->session));
443 if (session) {
444 session->HandleEvent(ev);
445 }
446}
447
448} // namespace cricket