Wed Jan 8 2020 09:49:50

Asterisk developer's documentation


res_srtp.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2005, Mikael Magnusson
5  *
6  * Mikael Magnusson <mikma@users.sourceforge.net>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  *
18  * Builds on libSRTP http://srtp.sourceforge.net
19  */
20 
21 /*! \file res_srtp.c
22  *
23  * \brief Secure RTP (SRTP)
24  *
25  * Secure RTP (SRTP)
26  * Specified in RFC 3711.
27  *
28  * \author Mikael Magnusson <mikma@users.sourceforge.net>
29  */
30 
31 /*** MODULEINFO
32  <depend>srtp</depend>
33  <support_level>core</support_level>
34 ***/
35 
36 /* See https://wiki.asterisk.org/wiki/display/AST/Secure+Calling */
37 
38 #include "asterisk.h"
39 
40 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 426140 $")
41 
42 #include <srtp/srtp.h>
43 #include <srtp/crypto_kernel.h>
44 
45 #include "asterisk/lock.h"
46 #include "asterisk/sched.h"
47 #include "asterisk/module.h"
48 #include "asterisk/options.h"
49 #include "asterisk/rtp_engine.h"
50 #include "asterisk/astobj2.h"
51 
52 struct ast_srtp {
55  srtp_t session;
56  const struct ast_srtp_cb *cb;
57  void *data;
58  int warned;
59  unsigned char buf[8192 + AST_FRIENDLY_OFFSET];
60  unsigned char rtcpbuf[8192 + AST_FRIENDLY_OFFSET];
61 };
62 
64  srtp_policy_t sp;
65 };
66 
67 /*! Tracks whether or not we've initialized the libsrtp library */
68 static int g_initialized = 0;
69 
70 /* SRTP functions */
71 static int ast_srtp_create(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy);
72 static int ast_srtp_replace(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy);
73 static void ast_srtp_destroy(struct ast_srtp *srtp);
74 static int ast_srtp_add_stream(struct ast_srtp *srtp, struct ast_srtp_policy *policy);
75 static int ast_srtp_change_source(struct ast_srtp *srtp, unsigned int from_ssrc, unsigned int to_ssrc);
76 
77 static int ast_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len, int rtcp);
78 static int ast_srtp_protect(struct ast_srtp *srtp, void **buf, int *len, int rtcp);
79 static void ast_srtp_set_cb(struct ast_srtp *srtp, const struct ast_srtp_cb *cb, void *data);
80 static int ast_srtp_get_random(unsigned char *key, size_t len);
81 
82 /* Policy functions */
83 static struct ast_srtp_policy *ast_srtp_policy_alloc(void);
84 static void ast_srtp_policy_destroy(struct ast_srtp_policy *policy);
85 static int ast_srtp_policy_set_suite(struct ast_srtp_policy *policy, enum ast_srtp_suite suite);
86 static int ast_srtp_policy_set_master_key(struct ast_srtp_policy *policy, const unsigned char *key, size_t key_len, const unsigned char *salt, size_t salt_len);
87 static void ast_srtp_policy_set_ssrc(struct ast_srtp_policy *policy, unsigned long ssrc, int inbound);
88 
89 static struct ast_srtp_res srtp_res = {
91  .replace = ast_srtp_replace,
92  .destroy = ast_srtp_destroy,
93  .add_stream = ast_srtp_add_stream,
94  .change_source = ast_srtp_change_source,
95  .set_cb = ast_srtp_set_cb,
96  .unprotect = ast_srtp_unprotect,
97  .protect = ast_srtp_protect,
98  .get_random = ast_srtp_get_random
99 };
100 
103  .destroy = ast_srtp_policy_destroy,
104  .set_suite = ast_srtp_policy_set_suite,
105  .set_master_key = ast_srtp_policy_set_master_key,
106  .set_ssrc = ast_srtp_policy_set_ssrc
107 };
108 
109 static const char *srtp_errstr(int err)
110 {
111  switch(err) {
112  case err_status_ok:
113  return "nothing to report";
114  case err_status_fail:
115  return "unspecified failure";
116  case err_status_bad_param:
117  return "unsupported parameter";
118  case err_status_alloc_fail:
119  return "couldn't allocate memory";
120  case err_status_dealloc_fail:
121  return "couldn't deallocate properly";
122  case err_status_init_fail:
123  return "couldn't initialize";
124  case err_status_terminus:
125  return "can't process as much data as requested";
126  case err_status_auth_fail:
127  return "authentication failure";
128  case err_status_cipher_fail:
129  return "cipher failure";
130  case err_status_replay_fail:
131  return "replay check failed (bad index)";
132  case err_status_replay_old:
133  return "replay check failed (index too old)";
134  case err_status_algo_fail:
135  return "algorithm failed test routine";
136  case err_status_no_such_op:
137  return "unsupported operation";
138  case err_status_no_ctx:
139  return "no appropriate context found";
140  case err_status_cant_check:
141  return "unable to perform desired validation";
142  case err_status_key_expired:
143  return "can't use key any more";
144  default:
145  return "unknown";
146  }
147 }
148 
149 static int policy_hash_fn(const void *obj, const int flags)
150 {
151  const struct ast_srtp_policy *policy = obj;
152 
153  return policy->sp.ssrc.type == ssrc_specific ? policy->sp.ssrc.value : policy->sp.ssrc.type;
154 }
155 
156 static int policy_cmp_fn(void *obj, void *arg, int flags)
157 {
158  const struct ast_srtp_policy *one = obj, *two = arg;
159 
160  return one->sp.ssrc.type == two->sp.ssrc.type && one->sp.ssrc.value == two->sp.ssrc.value;
161 }
162 
163 static struct ast_srtp_policy *find_policy(struct ast_srtp *srtp, const srtp_policy_t *policy, int flags)
164 {
165  struct ast_srtp_policy tmp = {
166  .sp = {
167  .ssrc.type = policy->ssrc.type,
168  .ssrc.value = policy->ssrc.value,
169  },
170  };
171 
172  return ao2_t_find(srtp->policies, &tmp, flags, "Looking for policy");
173 }
174 
175 static struct ast_srtp *res_srtp_new(void)
176 {
177  struct ast_srtp *srtp;
178 
179  if (!(srtp = ast_calloc(1, sizeof(*srtp)))) {
180  ast_log(LOG_ERROR, "Unable to allocate memory for srtp\n");
181  return NULL;
182  }
183 
184  if (!(srtp->policies = ao2_t_container_alloc(5, policy_hash_fn, policy_cmp_fn, "SRTP policy container"))) {
185  ast_free(srtp);
186  return NULL;
187  }
188 
189  srtp->warned = 1;
190 
191  return srtp;
192 }
193 
194 /*
195  struct ast_srtp_policy
196 */
197 static void srtp_event_cb(srtp_event_data_t *data)
198 {
199  switch (data->event) {
200  case event_ssrc_collision:
201  ast_debug(1, "SSRC collision\n");
202  break;
203  case event_key_soft_limit:
204  ast_debug(1, "event_key_soft_limit\n");
205  break;
206  case event_key_hard_limit:
207  ast_debug(1, "event_key_hard_limit\n");
208  break;
209  case event_packet_index_limit:
210  ast_debug(1, "event_packet_index_limit\n");
211  break;
212  }
213 }
214 
215 static void ast_srtp_policy_set_ssrc(struct ast_srtp_policy *policy,
216  unsigned long ssrc, int inbound)
217 {
218  if (ssrc) {
219  policy->sp.ssrc.type = ssrc_specific;
220  policy->sp.ssrc.value = ssrc;
221  } else {
222  policy->sp.ssrc.type = inbound ? ssrc_any_inbound : ssrc_any_outbound;
223  }
224 }
225 
226 static void policy_destructor(void *obj)
227 {
228  struct ast_srtp_policy *policy = obj;
229 
230  if (policy->sp.key) {
231  ast_free(policy->sp.key);
232  policy->sp.key = NULL;
233  }
234 }
235 
237 {
238  struct ast_srtp_policy *tmp;
239 
240  if (!(tmp = ao2_t_alloc(sizeof(*tmp), policy_destructor, "Allocating policy"))) {
241  ast_log(LOG_ERROR, "Unable to allocate memory for srtp_policy\n");
242  }
243 
244  return tmp;
245 }
246 
247 static void ast_srtp_policy_destroy(struct ast_srtp_policy *policy)
248 {
249  ao2_t_ref(policy, -1, "Destroying policy");
250 }
251 
252 static int policy_set_suite(crypto_policy_t *p, enum ast_srtp_suite suite)
253 {
254  switch (suite) {
256  p->cipher_type = AES_128_ICM;
257  p->cipher_key_len = 30;
258  p->auth_type = HMAC_SHA1;
259  p->auth_key_len = 20;
260  p->auth_tag_len = 10;
261  p->sec_serv = sec_serv_conf_and_auth;
262  return 0;
263 
265  p->cipher_type = AES_128_ICM;
266  p->cipher_key_len = 30;
267  p->auth_type = HMAC_SHA1;
268  p->auth_key_len = 20;
269  p->auth_tag_len = 4;
270  p->sec_serv = sec_serv_conf_and_auth;
271  return 0;
272 
273  default:
274  ast_log(LOG_ERROR, "Invalid crypto suite: %u\n", suite);
275  return -1;
276  }
277 }
278 
279 static int ast_srtp_policy_set_suite(struct ast_srtp_policy *policy, enum ast_srtp_suite suite)
280 {
281  return policy_set_suite(&policy->sp.rtp, suite) | policy_set_suite(&policy->sp.rtcp, suite);
282 }
283 
284 static int ast_srtp_policy_set_master_key(struct ast_srtp_policy *policy, const unsigned char *key, size_t key_len, const unsigned char *salt, size_t salt_len)
285 {
286  size_t size = key_len + salt_len;
287  unsigned char *master_key;
288 
289  if (policy->sp.key) {
290  ast_free(policy->sp.key);
291  policy->sp.key = NULL;
292  }
293 
294  if (!(master_key = ast_calloc(1, size))) {
295  return -1;
296  }
297 
298  memcpy(master_key, key, key_len);
299  memcpy(master_key + key_len, salt, salt_len);
300 
301  policy->sp.key = master_key;
302 
303  return 0;
304 }
305 
306 static int ast_srtp_get_random(unsigned char *key, size_t len)
307 {
308  return crypto_get_random(key, len) != err_status_ok ? -1: 0;
309 }
310 
311 static void ast_srtp_set_cb(struct ast_srtp *srtp, const struct ast_srtp_cb *cb, void *data)
312 {
313  if (!srtp) {
314  return;
315  }
316 
317  srtp->cb = cb;
318  srtp->data = data;
319 }
320 
321 /* Vtable functions */
322 static int ast_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len, int rtcp)
323 {
324  int res = 0;
325  int i;
326  int retry = 0;
327  struct ast_rtp_instance_stats stats = {0,};
328 
329 tryagain:
330 
331  for (i = 0; i < 2; i++) {
332  res = rtcp ? srtp_unprotect_rtcp(srtp->session, buf, len) : srtp_unprotect(srtp->session, buf, len);
333  if (res != err_status_no_ctx) {
334  break;
335  }
336 
337  if (srtp->cb && srtp->cb->no_ctx) {
339  break;
340  }
341  if (srtp->cb->no_ctx(srtp->rtp, stats.remote_ssrc, srtp->data) < 0) {
342  break;
343  }
344  } else {
345  break;
346  }
347  }
348 
349  if (retry == 0 && res == err_status_replay_old) {
350  ast_log(AST_LOG_NOTICE, "SRTP unprotect failed with %s, retrying\n", srtp_errstr(res));
351 
352  if (srtp->session) {
353  struct ast_srtp_policy *policy;
354  struct ao2_iterator it;
355  int policies_count;
356 
357  /* dealloc first */
358  ast_debug(5, "SRTP destroy before re-create\n");
359  srtp_dealloc(srtp->session);
360 
361  /* get the count */
362  policies_count = ao2_container_count(srtp->policies);
363 
364  /* get the first to build up */
365  it = ao2_iterator_init(srtp->policies, 0);
366  policy = ao2_iterator_next(&it);
367 
368  ast_debug(5, "SRTP try to re-create\n");
369  if (policy) {
370  int res_srtp_create = srtp_create(&srtp->session, &policy->sp);
371  if (res_srtp_create == err_status_ok) {
372  ast_debug(5, "SRTP re-created with first policy\n");
373  ao2_t_ref(policy, -1, "Unreffing first policy for re-creating srtp session");
374 
375  /* if we have more than one policy, add them */
376  if (policies_count > 1) {
377  ast_debug(5, "Add all the other %d policies\n",
378  policies_count - 1);
379  while ((policy = ao2_iterator_next(&it))) {
380  srtp_add_stream(srtp->session, &policy->sp);
381  ao2_t_ref(policy, -1, "Unreffing n-th policy for re-creating srtp session");
382  }
383  }
384 
385  retry++;
387  goto tryagain;
388  }
389  ast_log(LOG_ERROR, "SRTP session could not be re-created after unprotect failure: %s\n", srtp_errstr(res_srtp_create));
390 
391  /* If srtp_create() fails with a previously alloced session, it will have been dealloced before returning. */
392  srtp->session = NULL;
393 
394  ao2_t_ref(policy, -1, "Unreffing first policy after srtp_create failed");
395  }
397  }
398  }
399 
400  if (!srtp->session) {
401  errno = EINVAL;
402  return -1;
403  }
404 
405  if (res != err_status_ok && res != err_status_replay_fail ) {
406  if ((srtp->warned >= 10) && !((srtp->warned - 10) % 100)) {
407  ast_log(AST_LOG_WARNING, "SRTP unprotect failed with: %s %d\n", srtp_errstr(res), srtp->warned);
408  srtp->warned = 11;
409  } else {
410  srtp->warned++;
411  }
412  errno = EAGAIN;
413  return -1;
414  }
415 
416  return *len;
417 }
418 
419 static int ast_srtp_protect(struct ast_srtp *srtp, void **buf, int *len, int rtcp)
420 {
421  int res;
422  unsigned char *localbuf;
423 
424  if ((*len + SRTP_MAX_TRAILER_LEN) > sizeof(srtp->buf)) {
425  return -1;
426  }
427 
428  localbuf = rtcp ? srtp->rtcpbuf : srtp->buf;
429 
430  memcpy(localbuf, *buf, *len);
431 
432  if ((res = rtcp ? srtp_protect_rtcp(srtp->session, localbuf, len) : srtp_protect(srtp->session, localbuf, len)) != err_status_ok && res != err_status_replay_fail) {
433  ast_log(LOG_WARNING, "SRTP protect: %s\n", srtp_errstr(res));
434  return -1;
435  }
436 
437  *buf = localbuf;
438  return *len;
439 }
440 
441 static int ast_srtp_create(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
442 {
443  struct ast_srtp *temp;
444 
445  if (!(temp = res_srtp_new())) {
446  return -1;
447  }
449 
450  /* Any failures after this point can use ast_srtp_destroy to destroy the instance */
451  if (srtp_create(&temp->session, &policy->sp) != err_status_ok) {
452  /* Session either wasn't created or was created and dealloced. */
453  temp->session = NULL;
454  ast_srtp_destroy(temp);
455  return -1;
456  }
457 
458  temp->rtp = rtp;
459  *srtp = temp;
460 
461  ao2_t_link((*srtp)->policies, policy, "Created initial policy");
462 
463  return 0;
464 }
465 
466 static int ast_srtp_replace(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
467 {
468  if ((*srtp) != NULL) {
469  ast_srtp_destroy(*srtp);
470  }
471  return ast_srtp_create(srtp, rtp, policy);
472 }
473 
474 static void ast_srtp_destroy(struct ast_srtp *srtp)
475 {
476  if (srtp->session) {
477  srtp_dealloc(srtp->session);
478  }
479 
480  ao2_t_callback(srtp->policies, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "Unallocate policy");
481  ao2_t_ref(srtp->policies, -1, "Destroying container");
482 
483  ast_free(srtp);
485 }
486 
487 static int ast_srtp_add_stream(struct ast_srtp *srtp, struct ast_srtp_policy *policy)
488 {
489  struct ast_srtp_policy *match;
490 
491  /* For existing streams, replace if its an SSRC stream, or bail if its a wildcard */
492  if ((match = find_policy(srtp, &policy->sp, OBJ_POINTER))) {
493  if (policy->sp.ssrc.type != ssrc_specific) {
494  ast_log(AST_LOG_WARNING, "Cannot replace an existing wildcard policy\n");
495  ao2_t_ref(match, -1, "Unreffing already existing policy");
496  return -1;
497  } else {
498  if (srtp_remove_stream(srtp->session, match->sp.ssrc.value) != err_status_ok) {
499  ast_log(AST_LOG_WARNING, "Failed to remove SRTP stream for SSRC %u\n", match->sp.ssrc.value);
500  }
501  ao2_t_unlink(srtp->policies, match, "Remove existing match policy");
502  ao2_t_ref(match, -1, "Unreffing already existing policy");
503  }
504  }
505 
506  ast_debug(3, "Adding new policy for %s %u\n",
507  policy->sp.ssrc.type == ssrc_specific ? "SSRC" : "type",
508  policy->sp.ssrc.type == ssrc_specific ? policy->sp.ssrc.value : policy->sp.ssrc.type);
509  if (srtp_add_stream(srtp->session, &policy->sp) != err_status_ok) {
510  ast_log(AST_LOG_WARNING, "Failed to add SRTP stream for %s %u\n",
511  policy->sp.ssrc.type == ssrc_specific ? "SSRC" : "type",
512  policy->sp.ssrc.type == ssrc_specific ? policy->sp.ssrc.value : policy->sp.ssrc.type);
513  return -1;
514  }
515 
516  ao2_t_link(srtp->policies, policy, "Added additional stream");
517 
518  return 0;
519 }
520 
521 static int ast_srtp_change_source(struct ast_srtp *srtp, unsigned int from_ssrc, unsigned int to_ssrc)
522 {
523  struct ast_srtp_policy *match;
524  struct srtp_policy_t sp = {
525  .ssrc.type = ssrc_specific,
526  .ssrc.value = from_ssrc,
527  };
528  err_status_t status;
529 
530  /* If we find a match, return and unlink it from the container so we
531  * can change the SSRC (which is part of the hash) and then have
532  * ast_srtp_add_stream link it back in if all is well */
533  if ((match = find_policy(srtp, &sp, OBJ_POINTER | OBJ_UNLINK))) {
534  match->sp.ssrc.value = to_ssrc;
535  if (ast_srtp_add_stream(srtp, match)) {
536  ast_log(LOG_WARNING, "Couldn't add stream\n");
537  } else if ((status = srtp_remove_stream(srtp->session, from_ssrc))) {
538  ast_debug(3, "Couldn't remove stream (%u)\n", status);
539  }
540  ao2_t_ref(match, -1, "Unreffing found policy in change_source");
541  }
542 
543  return 0;
544 }
545 
546 static void res_srtp_shutdown(void)
547 {
548  srtp_install_event_handler(NULL);
550 #ifdef HAVE_SRTP_SHUTDOWN
551  srtp_shutdown();
552 #endif
553  g_initialized = 0;
554 }
555 
556 static int res_srtp_init(void)
557 {
558  if (g_initialized) {
559  return 0;
560  }
561 
562  if (srtp_init() != err_status_ok) {
563  ast_log(AST_LOG_WARNING, "Failed to initialize libsrtp\n");
564  return -1;
565  }
566 
567  srtp_install_event_handler(srtp_event_cb);
568 
569  if (ast_rtp_engine_register_srtp(&srtp_res, &policy_res)) {
570  ast_log(AST_LOG_WARNING, "Failed to register SRTP with rtp engine\n");
572  return -1;
573  }
574 
575  g_initialized = 1;
576  return 0;
577 }
578 
579 /*
580  * Exported functions
581  */
582 
583 static int load_module(void)
584 {
585  return res_srtp_init();
586 }
587 
588 static int unload_module(void)
589 {
591  return 0;
592 }
593 
595  .load = load_module,
596  .unload = unload_module,
597  .load_pri = AST_MODPRI_CHANNEL_DEPEND,
598 );
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:471
#define ao2_t_find(arg1, arg2, arg3, arg4)
Definition: astobj2.h:963
static struct ast_srtp_policy * ast_srtp_policy_alloc(void)
Definition: res_srtp.c:236
Asterisk locking-related definitions:
static int unload_module(void)
Definition: res_srtp.c:588
Asterisk main include file. File version handling, generic pbx functions.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
Definition: astobj2.c:470
void ast_module_unref(struct ast_module *)
Definition: loader.c:1312
static int policy_hash_fn(const void *obj, const int flags)
Definition: res_srtp.c:149
static void ast_srtp_set_cb(struct ast_srtp *srtp, const struct ast_srtp_cb *cb, void *data)
Definition: res_srtp.c:311
void * data
Definition: res_srtp.c:57
#define ao2_t_alloc(data_size, destructor_fn, debug_msg)
Allocate and initialize an object.
Definition: astobj2.h:429
int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
Retrieve statistics about an RTP instance.
Definition: rtp_engine.c:1604
#define ao2_iterator_next(arg1)
Definition: astobj2.h:1126
#define LOG_WARNING
Definition: logger.h:144
static void res_srtp_shutdown(void)
Definition: res_srtp.c:546
static int ast_srtp_policy_set_master_key(struct ast_srtp_policy *policy, const unsigned char *key, size_t key_len, const unsigned char *salt, size_t salt_len)
Definition: res_srtp.c:284
unsigned char rtcpbuf[8192+AST_FRIENDLY_OFFSET]
Definition: res_srtp.c:60
#define AST_LOG_WARNING
Definition: logger.h:149
static int ast_srtp_create(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
Definition: res_srtp.c:441
int(* create)(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
Definition: res_srtp.h:34
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags)
Create an iterator for a container.
Definition: astobj2.c:818
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:374
struct ao2_container * policies
Definition: res_srtp.c:54
#define ao2_t_container_alloc(arg1, arg2, arg3, arg4)
Allocate and initialize a container with the desired number of buckets.
Definition: astobj2.h:733
static struct ast_srtp_res srtp_res
Definition: res_srtp.c:89
static void ast_srtp_destroy(struct ast_srtp *srtp)
Definition: res_srtp.c:474
void ast_rtp_engine_unregister_srtp(void)
Definition: rtp_engine.c:1818
#define ao2_t_link(arg1, arg2, arg3)
Add an object to a container.
Definition: astobj2.h:784
#define AST_LOG_NOTICE
Definition: logger.h:138
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static int ast_srtp_change_source(struct ast_srtp *srtp, unsigned int from_ssrc, unsigned int to_ssrc)
Definition: res_srtp.c:521
struct ast_module * self
Definition: module.h:227
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
Definition: frame.h:204
struct ast_srtp_policy *(* alloc)(void)
Definition: res_srtp.h:61
Scheduler Routines (derived from cheops)
static int load_module(void)
Definition: res_srtp.c:583
static void ast_srtp_policy_destroy(struct ast_srtp_policy *policy)
Definition: res_srtp.c:247
static int ast_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len, int rtcp)
Definition: res_srtp.c:322
static struct ast_srtp_policy_res policy_res
Definition: res_srtp.c:101
int warned
Definition: res_srtp.c:58
struct ast_srtp_cb * cb
Definition: res_srtp.c:56
static struct ast_srtp_policy * find_policy(struct ast_srtp *srtp, const srtp_policy_t *policy, int flags)
Definition: res_srtp.c:163
int ast_rtp_engine_register_srtp(struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res)
Definition: rtp_engine.c:1803
#define LOG_ERROR
Definition: logger.h:155
#define ao2_t_unlink(arg1, arg2, arg3)
Remove an object from a container.
Definition: astobj2.h:816
static int ast_srtp_get_random(unsigned char *key, size_t len)
Definition: res_srtp.c:306
static int ast_srtp_add_stream(struct ast_srtp *srtp, struct ast_srtp_policy *policy)
Definition: res_srtp.c:487
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ao2_t_callback(c, flags, cb_fn, arg, tag)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
Definition: astobj2.h:909
static int res_srtp_init(void)
Definition: res_srtp.c:556
static int ast_srtp_replace(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
Definition: res_srtp.c:466
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static int ast_srtp_policy_set_suite(struct ast_srtp_policy *policy, enum ast_srtp_suite suite)
Definition: res_srtp.c:279
int(* no_ctx)(struct ast_rtp_instance *rtp, unsigned long ssrc, void *data)
Definition: res_srtp.h:29
int errno
#define ast_free(a)
Definition: astmm.h:97
static void policy_destructor(void *obj)
Definition: res_srtp.c:226
static struct ast_srtp * res_srtp_new(void)
Definition: res_srtp.c:175
static const char * srtp_errstr(int err)
Definition: res_srtp.c:109
srtp_t session
Definition: res_srtp.c:55
void ao2_iterator_destroy(struct ao2_iterator *i)
Destroy a container iterator.
Definition: astobj2.c:833
static int ast_srtp_protect(struct ast_srtp *srtp, void **buf, int *len, int rtcp)
Definition: res_srtp.c:419
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1053
#define ast_calloc(a, b)
Definition: astmm.h:82
static void ast_srtp_policy_set_ssrc(struct ast_srtp_policy *policy, unsigned long ssrc, int inbound)
Definition: res_srtp.c:215
static int policy_set_suite(crypto_policy_t *p, enum ast_srtp_suite suite)
Definition: res_srtp.c:252
static void srtp_event_cb(srtp_event_data_t *data)
Definition: res_srtp.c:197
Options provided by main asterisk program.
unsigned char buf[8192+AST_FRIENDLY_OFFSET]
Definition: res_srtp.c:59
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Pluggable RTP Architecture.
Asterisk module definitions.
ast_srtp_suite
Definition: res_srtp.h:54
static int g_initialized
Definition: res_srtp.c:68
static int match(struct sockaddr_in *sin, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2069
struct ast_rtp_instance * rtp
Definition: res_srtp.c:53
jack_status_t status
Definition: app_jack.c:143
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
srtp_policy_t sp
Definition: res_srtp.c:64
unsigned int remote_ssrc
Definition: rtp_engine.h:293
static int policy_cmp_fn(void *obj, void *arg, int flags)
Definition: res_srtp.c:156
struct ast_module * ast_module_ref(struct ast_module *)
Definition: loader.c:1300