res_srtp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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. /*! \file res_srtp.c
  21. *
  22. * \brief Secure RTP (SRTP)
  23. *
  24. * Secure RTP (SRTP)
  25. * Specified in RFC 3711.
  26. *
  27. * \author Mikael Magnusson <mikma@users.sourceforge.net>
  28. */
  29. /*** MODULEINFO
  30. <depend>srtp</depend>
  31. <use type="external">openssl</use>
  32. <support_level>core</support_level>
  33. ***/
  34. /* See https://wiki.asterisk.org/wiki/display/AST/Secure+Calling */
  35. #include "asterisk.h"
  36. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  37. #if HAVE_SRTP_VERSION > 1
  38. # include <srtp2/srtp.h>
  39. # include "srtp/srtp_compat.h"
  40. # include <openssl/rand.h>
  41. #else
  42. # include <srtp/srtp.h>
  43. # ifdef HAVE_OPENSSL
  44. # include <openssl/rand.h>
  45. # else
  46. # include <srtp/crypto_kernel.h>
  47. # endif
  48. #endif
  49. #include "asterisk/lock.h"
  50. #include "asterisk/sched.h"
  51. #include "asterisk/module.h"
  52. #include "asterisk/options.h"
  53. #include "asterisk/rtp_engine.h"
  54. #include "asterisk/astobj2.h"
  55. struct ast_srtp {
  56. struct ast_rtp_instance *rtp;
  57. struct ao2_container *policies;
  58. srtp_t session;
  59. const struct ast_srtp_cb *cb;
  60. void *data;
  61. int warned;
  62. unsigned char buf[8192 + AST_FRIENDLY_OFFSET];
  63. unsigned char rtcpbuf[8192 + AST_FRIENDLY_OFFSET];
  64. };
  65. struct ast_srtp_policy {
  66. srtp_policy_t sp;
  67. };
  68. /*! Tracks whether or not we've initialized the libsrtp library */
  69. static int g_initialized = 0;
  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. static int ast_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len, int rtcp);
  77. static int ast_srtp_protect(struct ast_srtp *srtp, void **buf, int *len, int rtcp);
  78. static void ast_srtp_set_cb(struct ast_srtp *srtp, const struct ast_srtp_cb *cb, void *data);
  79. static int ast_srtp_get_random(unsigned char *key, size_t len);
  80. /* Policy functions */
  81. static struct ast_srtp_policy *ast_srtp_policy_alloc(void);
  82. static void ast_srtp_policy_destroy(struct ast_srtp_policy *policy);
  83. static int ast_srtp_policy_set_suite(struct ast_srtp_policy *policy, enum ast_srtp_suite suite);
  84. 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);
  85. static void ast_srtp_policy_set_ssrc(struct ast_srtp_policy *policy, unsigned long ssrc, int inbound);
  86. static struct ast_srtp_res srtp_res = {
  87. .create = ast_srtp_create,
  88. .replace = ast_srtp_replace,
  89. .destroy = ast_srtp_destroy,
  90. .add_stream = ast_srtp_add_stream,
  91. .change_source = ast_srtp_change_source,
  92. .set_cb = ast_srtp_set_cb,
  93. .unprotect = ast_srtp_unprotect,
  94. .protect = ast_srtp_protect,
  95. .get_random = ast_srtp_get_random
  96. };
  97. static struct ast_srtp_policy_res policy_res = {
  98. .alloc = ast_srtp_policy_alloc,
  99. .destroy = ast_srtp_policy_destroy,
  100. .set_suite = ast_srtp_policy_set_suite,
  101. .set_master_key = ast_srtp_policy_set_master_key,
  102. .set_ssrc = ast_srtp_policy_set_ssrc
  103. };
  104. static const char *srtp_errstr(int err)
  105. {
  106. switch(err) {
  107. case err_status_ok:
  108. return "nothing to report";
  109. case err_status_fail:
  110. return "unspecified failure";
  111. case err_status_bad_param:
  112. return "unsupported parameter";
  113. case err_status_alloc_fail:
  114. return "couldn't allocate memory";
  115. case err_status_dealloc_fail:
  116. return "couldn't deallocate properly";
  117. case err_status_init_fail:
  118. return "couldn't initialize";
  119. case err_status_terminus:
  120. return "can't process as much data as requested";
  121. case err_status_auth_fail:
  122. return "authentication failure";
  123. case err_status_cipher_fail:
  124. return "cipher failure";
  125. case err_status_replay_fail:
  126. return "replay check failed (bad index)";
  127. case err_status_replay_old:
  128. return "replay check failed (index too old)";
  129. case err_status_algo_fail:
  130. return "algorithm failed test routine";
  131. case err_status_no_such_op:
  132. return "unsupported operation";
  133. case err_status_no_ctx:
  134. return "no appropriate context found";
  135. case err_status_cant_check:
  136. return "unable to perform desired validation";
  137. case err_status_key_expired:
  138. return "can't use key any more";
  139. default:
  140. return "unknown";
  141. }
  142. }
  143. static int policy_hash_fn(const void *obj, const int flags)
  144. {
  145. const struct ast_srtp_policy *policy = obj;
  146. return policy->sp.ssrc.type == ssrc_specific ? policy->sp.ssrc.value : policy->sp.ssrc.type;
  147. }
  148. static int policy_cmp_fn(void *obj, void *arg, int flags)
  149. {
  150. const struct ast_srtp_policy *one = obj, *two = arg;
  151. return one->sp.ssrc.type == two->sp.ssrc.type && one->sp.ssrc.value == two->sp.ssrc.value;
  152. }
  153. static struct ast_srtp_policy *find_policy(struct ast_srtp *srtp, const srtp_policy_t *policy, int flags)
  154. {
  155. struct ast_srtp_policy tmp = {
  156. .sp = {
  157. .ssrc.type = policy->ssrc.type,
  158. .ssrc.value = policy->ssrc.value,
  159. },
  160. };
  161. return ao2_t_find(srtp->policies, &tmp, flags, "Looking for policy");
  162. }
  163. static struct ast_srtp *res_srtp_new(void)
  164. {
  165. struct ast_srtp *srtp;
  166. if (!(srtp = ast_calloc(1, sizeof(*srtp)))) {
  167. ast_log(LOG_ERROR, "Unable to allocate memory for srtp\n");
  168. return NULL;
  169. }
  170. srtp->policies = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 5,
  171. policy_hash_fn, NULL, policy_cmp_fn, "SRTP policy container");
  172. if (!srtp->policies) {
  173. ast_free(srtp);
  174. return NULL;
  175. }
  176. srtp->warned = 1;
  177. return srtp;
  178. }
  179. /*
  180. struct ast_srtp_policy
  181. */
  182. static void srtp_event_cb(srtp_event_data_t *data)
  183. {
  184. switch (data->event) {
  185. case event_ssrc_collision:
  186. ast_debug(1, "SSRC collision\n");
  187. break;
  188. case event_key_soft_limit:
  189. ast_debug(1, "event_key_soft_limit\n");
  190. break;
  191. case event_key_hard_limit:
  192. ast_debug(1, "event_key_hard_limit\n");
  193. break;
  194. case event_packet_index_limit:
  195. ast_debug(1, "event_packet_index_limit\n");
  196. break;
  197. }
  198. }
  199. static void ast_srtp_policy_set_ssrc(struct ast_srtp_policy *policy,
  200. unsigned long ssrc, int inbound)
  201. {
  202. if (ssrc) {
  203. policy->sp.ssrc.type = ssrc_specific;
  204. policy->sp.ssrc.value = ssrc;
  205. } else {
  206. policy->sp.ssrc.type = inbound ? ssrc_any_inbound : ssrc_any_outbound;
  207. }
  208. }
  209. static void policy_destructor(void *obj)
  210. {
  211. struct ast_srtp_policy *policy = obj;
  212. if (policy->sp.key) {
  213. ast_free(policy->sp.key);
  214. policy->sp.key = NULL;
  215. }
  216. }
  217. static struct ast_srtp_policy *ast_srtp_policy_alloc()
  218. {
  219. struct ast_srtp_policy *tmp;
  220. if (!(tmp = ao2_t_alloc(sizeof(*tmp), policy_destructor, "Allocating policy"))) {
  221. ast_log(LOG_ERROR, "Unable to allocate memory for srtp_policy\n");
  222. }
  223. return tmp;
  224. }
  225. static void ast_srtp_policy_destroy(struct ast_srtp_policy *policy)
  226. {
  227. ao2_t_ref(policy, -1, "Destroying policy");
  228. }
  229. static int policy_set_suite(crypto_policy_t *p, enum ast_srtp_suite suite)
  230. {
  231. switch (suite) {
  232. case AST_AES_CM_128_HMAC_SHA1_80:
  233. p->cipher_type = AES_128_ICM;
  234. p->cipher_key_len = 30;
  235. p->auth_type = HMAC_SHA1;
  236. p->auth_key_len = 20;
  237. p->auth_tag_len = 10;
  238. p->sec_serv = sec_serv_conf_and_auth;
  239. return 0;
  240. case AST_AES_CM_128_HMAC_SHA1_32:
  241. p->cipher_type = AES_128_ICM;
  242. p->cipher_key_len = 30;
  243. p->auth_type = HMAC_SHA1;
  244. p->auth_key_len = 20;
  245. p->auth_tag_len = 4;
  246. p->sec_serv = sec_serv_conf_and_auth;
  247. return 0;
  248. default:
  249. ast_log(LOG_ERROR, "Invalid crypto suite: %u\n", suite);
  250. return -1;
  251. }
  252. }
  253. static int ast_srtp_policy_set_suite(struct ast_srtp_policy *policy, enum ast_srtp_suite suite)
  254. {
  255. return policy_set_suite(&policy->sp.rtp, suite) | policy_set_suite(&policy->sp.rtcp, suite);
  256. }
  257. 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)
  258. {
  259. size_t size = key_len + salt_len;
  260. unsigned char *master_key;
  261. if (policy->sp.key) {
  262. ast_free(policy->sp.key);
  263. policy->sp.key = NULL;
  264. }
  265. if (!(master_key = ast_calloc(1, size))) {
  266. return -1;
  267. }
  268. memcpy(master_key, key, key_len);
  269. memcpy(master_key + key_len, salt, salt_len);
  270. policy->sp.key = master_key;
  271. return 0;
  272. }
  273. static int ast_srtp_get_random(unsigned char *key, size_t len)
  274. {
  275. #ifdef HAVE_OPENSSL
  276. return RAND_bytes(key, len) > 0 ? 0: -1;
  277. #else
  278. return crypto_get_random(key, len) != err_status_ok ? -1: 0;
  279. #endif
  280. }
  281. static void ast_srtp_set_cb(struct ast_srtp *srtp, const struct ast_srtp_cb *cb, void *data)
  282. {
  283. if (!srtp) {
  284. return;
  285. }
  286. srtp->cb = cb;
  287. srtp->data = data;
  288. }
  289. /* Vtable functions */
  290. static int ast_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len, int rtcp)
  291. {
  292. int res = 0;
  293. int i;
  294. int retry = 0;
  295. struct ast_rtp_instance_stats stats = {0,};
  296. tryagain:
  297. for (i = 0; i < 2; i++) {
  298. res = rtcp ? srtp_unprotect_rtcp(srtp->session, buf, len) : srtp_unprotect(srtp->session, buf, len);
  299. if (res != err_status_no_ctx) {
  300. break;
  301. }
  302. if (srtp->cb && srtp->cb->no_ctx) {
  303. if (ast_rtp_instance_get_stats(srtp->rtp, &stats, AST_RTP_INSTANCE_STAT_REMOTE_SSRC)) {
  304. break;
  305. }
  306. if (srtp->cb->no_ctx(srtp->rtp, stats.remote_ssrc, srtp->data) < 0) {
  307. break;
  308. }
  309. } else {
  310. break;
  311. }
  312. }
  313. if (retry == 0 && res == err_status_replay_old) {
  314. ast_log(AST_LOG_NOTICE, "SRTP unprotect failed with %s, retrying\n", srtp_errstr(res));
  315. if (srtp->session) {
  316. struct ast_srtp_policy *policy;
  317. struct ao2_iterator it;
  318. int policies_count;
  319. /* dealloc first */
  320. ast_debug(5, "SRTP destroy before re-create\n");
  321. srtp_dealloc(srtp->session);
  322. /* get the count */
  323. policies_count = ao2_container_count(srtp->policies);
  324. /* get the first to build up */
  325. it = ao2_iterator_init(srtp->policies, 0);
  326. policy = ao2_iterator_next(&it);
  327. ast_debug(5, "SRTP try to re-create\n");
  328. if (policy) {
  329. int res_srtp_create = srtp_create(&srtp->session, &policy->sp);
  330. if (res_srtp_create == err_status_ok) {
  331. ast_debug(5, "SRTP re-created with first policy\n");
  332. ao2_t_ref(policy, -1, "Unreffing first policy for re-creating srtp session");
  333. /* if we have more than one policy, add them */
  334. if (policies_count > 1) {
  335. ast_debug(5, "Add all the other %d policies\n",
  336. policies_count - 1);
  337. while ((policy = ao2_iterator_next(&it))) {
  338. srtp_add_stream(srtp->session, &policy->sp);
  339. ao2_t_ref(policy, -1, "Unreffing n-th policy for re-creating srtp session");
  340. }
  341. }
  342. retry++;
  343. ao2_iterator_destroy(&it);
  344. goto tryagain;
  345. }
  346. ast_log(LOG_ERROR, "SRTP session could not be re-created after unprotect failure: %s\n", srtp_errstr(res_srtp_create));
  347. /* If srtp_create() fails with a previously alloced session, it will have been dealloced before returning. */
  348. srtp->session = NULL;
  349. ao2_t_ref(policy, -1, "Unreffing first policy after srtp_create failed");
  350. }
  351. ao2_iterator_destroy(&it);
  352. }
  353. }
  354. if (!srtp->session) {
  355. errno = EINVAL;
  356. return -1;
  357. }
  358. if (res != err_status_ok && res != err_status_replay_fail ) {
  359. /*
  360. * Authentication failures happen when an active attacker tries to
  361. * insert malicious RTP packets. Furthermore, authentication failures
  362. * happen, when the other party encrypts the sRTP data in an unexpected
  363. * way. This happens quite often with RTCP. Therefore, when you see
  364. * authentication failures, try to identify the implementation
  365. * (author and product name) used by your other party. Try to investigate
  366. * whether they use a custom library or an outdated version of libSRTP.
  367. */
  368. if (rtcp) {
  369. ast_verb(2, "SRTCP unprotect failed because of %s\n", srtp_errstr(res));
  370. } else {
  371. if ((srtp->warned >= 10) && !((srtp->warned - 10) % 150)) {
  372. ast_verb(2, "SRTP unprotect failed because of %s %d\n",
  373. srtp_errstr(res), srtp->warned);
  374. srtp->warned = 11;
  375. } else {
  376. srtp->warned++;
  377. }
  378. }
  379. errno = EAGAIN;
  380. return -1;
  381. }
  382. return *len;
  383. }
  384. static int ast_srtp_protect(struct ast_srtp *srtp, void **buf, int *len, int rtcp)
  385. {
  386. int res;
  387. unsigned char *localbuf;
  388. if ((*len + SRTP_MAX_TRAILER_LEN) > sizeof(srtp->buf)) {
  389. return -1;
  390. }
  391. localbuf = rtcp ? srtp->rtcpbuf : srtp->buf;
  392. memcpy(localbuf, *buf, *len);
  393. if ((res = rtcp ? srtp_protect_rtcp(srtp->session, localbuf, len) : srtp_protect(srtp->session, localbuf, len)) != err_status_ok && res != err_status_replay_fail) {
  394. ast_log(LOG_WARNING, "SRTP protect: %s\n", srtp_errstr(res));
  395. return -1;
  396. }
  397. *buf = localbuf;
  398. return *len;
  399. }
  400. static int ast_srtp_create(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
  401. {
  402. struct ast_srtp *temp;
  403. if (!(temp = res_srtp_new())) {
  404. return -1;
  405. }
  406. ast_module_ref(ast_module_info->self);
  407. /* Any failures after this point can use ast_srtp_destroy to destroy the instance */
  408. if (srtp_create(&temp->session, &policy->sp) != err_status_ok) {
  409. /* Session either wasn't created or was created and dealloced. */
  410. temp->session = NULL;
  411. ast_srtp_destroy(temp);
  412. return -1;
  413. }
  414. temp->rtp = rtp;
  415. *srtp = temp;
  416. ao2_t_link((*srtp)->policies, policy, "Created initial policy");
  417. return 0;
  418. }
  419. static int ast_srtp_replace(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
  420. {
  421. if ((*srtp) != NULL) {
  422. ast_srtp_destroy(*srtp);
  423. }
  424. return ast_srtp_create(srtp, rtp, policy);
  425. }
  426. static void ast_srtp_destroy(struct ast_srtp *srtp)
  427. {
  428. if (srtp->session) {
  429. srtp_dealloc(srtp->session);
  430. }
  431. ao2_t_callback(srtp->policies, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "Unallocate policy");
  432. ao2_t_ref(srtp->policies, -1, "Destroying container");
  433. ast_free(srtp);
  434. ast_module_unref(ast_module_info->self);
  435. }
  436. static int ast_srtp_add_stream(struct ast_srtp *srtp, struct ast_srtp_policy *policy)
  437. {
  438. struct ast_srtp_policy *match;
  439. /* For existing streams, replace if its an SSRC stream, or bail if its a wildcard */
  440. if ((match = find_policy(srtp, &policy->sp, OBJ_POINTER))) {
  441. if (policy->sp.ssrc.type != ssrc_specific) {
  442. ast_log(AST_LOG_WARNING, "Cannot replace an existing wildcard policy\n");
  443. ao2_t_ref(match, -1, "Unreffing already existing policy");
  444. return -1;
  445. } else {
  446. if (srtp_remove_stream(srtp->session, match->sp.ssrc.value) != err_status_ok) {
  447. ast_log(AST_LOG_WARNING, "Failed to remove SRTP stream for SSRC %u\n", match->sp.ssrc.value);
  448. }
  449. ao2_t_unlink(srtp->policies, match, "Remove existing match policy");
  450. ao2_t_ref(match, -1, "Unreffing already existing policy");
  451. }
  452. }
  453. ast_debug(3, "Adding new policy for %s %u\n",
  454. policy->sp.ssrc.type == ssrc_specific ? "SSRC" : "type",
  455. policy->sp.ssrc.type == ssrc_specific ? policy->sp.ssrc.value : policy->sp.ssrc.type);
  456. if (srtp_add_stream(srtp->session, &policy->sp) != err_status_ok) {
  457. ast_log(AST_LOG_WARNING, "Failed to add SRTP stream for %s %u\n",
  458. policy->sp.ssrc.type == ssrc_specific ? "SSRC" : "type",
  459. policy->sp.ssrc.type == ssrc_specific ? policy->sp.ssrc.value : policy->sp.ssrc.type);
  460. return -1;
  461. }
  462. ao2_t_link(srtp->policies, policy, "Added additional stream");
  463. return 0;
  464. }
  465. static int ast_srtp_change_source(struct ast_srtp *srtp, unsigned int from_ssrc, unsigned int to_ssrc)
  466. {
  467. struct ast_srtp_policy *match;
  468. struct srtp_policy_t sp = {
  469. .ssrc.type = ssrc_specific,
  470. .ssrc.value = from_ssrc,
  471. };
  472. err_status_t status;
  473. /* If we find a match, return and unlink it from the container so we
  474. * can change the SSRC (which is part of the hash) and then have
  475. * ast_srtp_add_stream link it back in if all is well */
  476. if ((match = find_policy(srtp, &sp, OBJ_POINTER | OBJ_UNLINK))) {
  477. match->sp.ssrc.value = to_ssrc;
  478. if (ast_srtp_add_stream(srtp, match)) {
  479. ast_log(LOG_WARNING, "Couldn't add stream\n");
  480. } else if ((status = srtp_remove_stream(srtp->session, from_ssrc))) {
  481. ast_debug(3, "Couldn't remove stream (%u)\n", status);
  482. }
  483. ao2_t_ref(match, -1, "Unreffing found policy in change_source");
  484. }
  485. return 0;
  486. }
  487. static void res_srtp_shutdown(void)
  488. {
  489. srtp_install_event_handler(NULL);
  490. ast_rtp_engine_unregister_srtp();
  491. #ifdef HAVE_SRTP_SHUTDOWN
  492. srtp_shutdown();
  493. #endif
  494. g_initialized = 0;
  495. }
  496. static int res_srtp_init(void)
  497. {
  498. if (g_initialized) {
  499. return 0;
  500. }
  501. if (srtp_init() != err_status_ok) {
  502. ast_log(AST_LOG_WARNING, "Failed to initialize libsrtp\n");
  503. return -1;
  504. }
  505. srtp_install_event_handler(srtp_event_cb);
  506. if (ast_rtp_engine_register_srtp(&srtp_res, &policy_res)) {
  507. ast_log(AST_LOG_WARNING, "Failed to register SRTP with rtp engine\n");
  508. res_srtp_shutdown();
  509. return -1;
  510. }
  511. #ifdef HAVE_SRTP_GET_VERSION
  512. ast_verb(2, "%s initialized\n", srtp_get_version_string());
  513. #else
  514. ast_verb(2, "libsrtp initialized\n");
  515. #endif
  516. g_initialized = 1;
  517. return 0;
  518. }
  519. /*
  520. * Exported functions
  521. */
  522. static int load_module(void)
  523. {
  524. return res_srtp_init();
  525. }
  526. static int unload_module(void)
  527. {
  528. res_srtp_shutdown();
  529. return 0;
  530. }
  531. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Secure RTP (SRTP)",
  532. .support_level = AST_MODULE_SUPPORT_CORE,
  533. .load = load_module,
  534. .unload = unload_module,
  535. .load_pri = AST_MODPRI_CHANNEL_DEPEND,
  536. );