res_crypto.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2006, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  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. /*! \file
  19. *
  20. * \brief Provide Cryptographic Signature capability
  21. *
  22. * \author Mark Spencer <markster@digium.com>
  23. *
  24. * Uses the OpenSSL library, available at
  25. * http://www.openssl.org/
  26. */
  27. /*** MODULEINFO
  28. <depend>openssl</depend>
  29. <support_level>core</support_level>
  30. ***/
  31. #include "asterisk.h"
  32. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  33. #include "asterisk/paths.h" /* use ast_config_AST_KEY_DIR */
  34. #include <openssl/ssl.h>
  35. #include <openssl/err.h>
  36. #include <openssl/aes.h>
  37. #include <dirent.h>
  38. #include "asterisk/module.h"
  39. #include "asterisk/md5.h"
  40. #include "asterisk/cli.h"
  41. #include "asterisk/io.h"
  42. #include "asterisk/lock.h"
  43. #include "asterisk/utils.h"
  44. #define AST_API_MODULE
  45. #include "asterisk/crypto.h"
  46. /*
  47. * Asterisk uses RSA keys with SHA-1 message digests for its
  48. * digital signatures. The choice of RSA is due to its higher
  49. * throughput on verification, and the choice of SHA-1 based
  50. * on the recently discovered collisions in MD5's compression
  51. * algorithm and recommendations of avoiding MD5 in new schemes
  52. * from various industry experts.
  53. *
  54. * We use OpenSSL to provide our crypto routines, although we never
  55. * actually use full-up SSL
  56. *
  57. */
  58. #define KEY_NEEDS_PASSCODE (1 << 16)
  59. struct ast_key {
  60. /*! Name of entity */
  61. char name[80];
  62. /*! File name */
  63. char fn[256];
  64. /*! Key type (AST_KEY_PUB or AST_KEY_PRIV, along with flags from above) */
  65. int ktype;
  66. /*! RSA structure (if successfully loaded) */
  67. RSA *rsa;
  68. /*! Whether we should be deleted */
  69. int delme;
  70. /*! FD for input (or -1 if no input allowed, or -2 if we needed input) */
  71. int infd;
  72. /*! FD for output */
  73. int outfd;
  74. /*! Last MD5 Digest */
  75. unsigned char digest[16];
  76. AST_RWLIST_ENTRY(ast_key) list;
  77. };
  78. static AST_RWLIST_HEAD_STATIC(keys, ast_key);
  79. /*!
  80. * \brief setting of priv key
  81. * \param buf
  82. * \param size
  83. * \param rwflag
  84. * \param userdata
  85. * \return length of string,-1 on failure
  86. */
  87. static int pw_cb(char *buf, int size, int rwflag, void *userdata)
  88. {
  89. struct ast_key *key = (struct ast_key *)userdata;
  90. char prompt[256];
  91. int tmp;
  92. int res;
  93. if (key->infd < 0) {
  94. /* Note that we were at least called */
  95. key->infd = -2;
  96. return -1;
  97. }
  98. snprintf(prompt, sizeof(prompt), ">>>> passcode for %s key '%s': ",
  99. key->ktype == AST_KEY_PRIVATE ? "PRIVATE" : "PUBLIC", key->name);
  100. if (write(key->outfd, prompt, strlen(prompt)) < 0) {
  101. ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
  102. key->infd = -2;
  103. return -1;
  104. }
  105. tmp = ast_hide_password(key->infd);
  106. memset(buf, 0, size);
  107. res = read(key->infd, buf, size);
  108. if (res == -1) {
  109. ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
  110. }
  111. ast_restore_tty(key->infd, tmp);
  112. if (buf[strlen(buf) -1] == '\n') {
  113. buf[strlen(buf) - 1] = '\0';
  114. }
  115. return strlen(buf);
  116. }
  117. /*!
  118. * \brief return the ast_key structure for name
  119. * \see ast_key_get
  120. */
  121. struct ast_key * AST_OPTIONAL_API_NAME(ast_key_get)(const char *kname, int ktype)
  122. {
  123. struct ast_key *key;
  124. AST_RWLIST_RDLOCK(&keys);
  125. AST_RWLIST_TRAVERSE(&keys, key, list) {
  126. if (!strcmp(kname, key->name) &&
  127. (ktype == key->ktype)) {
  128. break;
  129. }
  130. }
  131. AST_RWLIST_UNLOCK(&keys);
  132. return key;
  133. }
  134. /*!
  135. * \brief load RSA key from file
  136. * \param dir directory string
  137. * \param fname name of file
  138. * \param ifd incoming file descriptor
  139. * \param ofd outgoing file descriptor
  140. * \param not2
  141. * \retval key on success.
  142. * \retval NULL on failure.
  143. */
  144. static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd, int ofd, int *not2)
  145. {
  146. int ktype = 0, found = 0;
  147. char *c = NULL, ffname[256];
  148. unsigned char digest[16];
  149. FILE *f;
  150. struct MD5Context md5;
  151. struct ast_key *key;
  152. static int notice = 0;
  153. /* Make sure its name is a public or private key */
  154. if ((c = strstr(fname, ".pub")) && !strcmp(c, ".pub")) {
  155. ktype = AST_KEY_PUBLIC;
  156. } else if ((c = strstr(fname, ".key")) && !strcmp(c, ".key")) {
  157. ktype = AST_KEY_PRIVATE;
  158. } else {
  159. return NULL;
  160. }
  161. /* Get actual filename */
  162. snprintf(ffname, sizeof(ffname), "%s/%s", dir, fname);
  163. /* Open file */
  164. if (!(f = fopen(ffname, "r"))) {
  165. ast_log(LOG_WARNING, "Unable to open key file %s: %s\n", ffname, strerror(errno));
  166. return NULL;
  167. }
  168. MD5Init(&md5);
  169. while (!feof(f)) {
  170. /* Calculate a "whatever" quality md5sum of the key */
  171. char buf[256] = "";
  172. if (!fgets(buf, sizeof(buf), f)) {
  173. continue;
  174. }
  175. if (!feof(f)) {
  176. MD5Update(&md5, (unsigned char *) buf, strlen(buf));
  177. }
  178. }
  179. MD5Final(digest, &md5);
  180. /* Look for an existing key */
  181. AST_RWLIST_TRAVERSE(&keys, key, list) {
  182. if (!strcasecmp(key->fn, ffname)) {
  183. break;
  184. }
  185. }
  186. if (key) {
  187. /* If the MD5 sum is the same, and it isn't awaiting a passcode
  188. then this is far enough */
  189. if (!memcmp(digest, key->digest, 16) &&
  190. !(key->ktype & KEY_NEEDS_PASSCODE)) {
  191. fclose(f);
  192. key->delme = 0;
  193. return NULL;
  194. } else {
  195. /* Preserve keytype */
  196. ktype = key->ktype;
  197. /* Recycle the same structure */
  198. found++;
  199. }
  200. }
  201. /* Make fname just be the normal name now */
  202. *c = '\0';
  203. if (!key) {
  204. if (!(key = ast_calloc(1, sizeof(*key)))) {
  205. fclose(f);
  206. return NULL;
  207. }
  208. }
  209. /* First the filename */
  210. ast_copy_string(key->fn, ffname, sizeof(key->fn));
  211. /* Then the name */
  212. ast_copy_string(key->name, fname, sizeof(key->name));
  213. key->ktype = ktype;
  214. /* Yes, assume we're going to be deleted */
  215. key->delme = 1;
  216. /* Keep the key type */
  217. memcpy(key->digest, digest, 16);
  218. /* Can I/O takes the FD we're given */
  219. key->infd = ifd;
  220. key->outfd = ofd;
  221. /* Reset the file back to the beginning */
  222. rewind(f);
  223. /* Now load the key with the right method */
  224. if (ktype == AST_KEY_PUBLIC) {
  225. key->rsa = PEM_read_RSA_PUBKEY(f, NULL, pw_cb, key);
  226. } else {
  227. key->rsa = PEM_read_RSAPrivateKey(f, NULL, pw_cb, key);
  228. }
  229. fclose(f);
  230. if (key->rsa) {
  231. if (RSA_size(key->rsa) == 128) {
  232. /* Key loaded okay */
  233. key->ktype &= ~KEY_NEEDS_PASSCODE;
  234. ast_verb(3, "Loaded %s key '%s'\n", key->ktype == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE", key->name);
  235. ast_debug(1, "Key '%s' loaded OK\n", key->name);
  236. key->delme = 0;
  237. } else {
  238. ast_log(LOG_NOTICE, "Key '%s' is not expected size.\n", key->name);
  239. }
  240. } else if (key->infd != -2) {
  241. ast_log(LOG_WARNING, "Key load %s '%s' failed\n",key->ktype == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE", key->name);
  242. if (ofd > -1) {
  243. ERR_print_errors_fp(stderr);
  244. } else {
  245. ERR_print_errors_fp(stderr);
  246. }
  247. } else {
  248. ast_log(LOG_NOTICE, "Key '%s' needs passcode.\n", key->name);
  249. key->ktype |= KEY_NEEDS_PASSCODE;
  250. if (!notice) {
  251. if (!ast_opt_init_keys) {
  252. ast_log(LOG_NOTICE, "Add the '-i' flag to the asterisk command line if you want to automatically initialize passcodes at launch.\n");
  253. }
  254. notice++;
  255. }
  256. /* Keep it anyway */
  257. key->delme = 0;
  258. /* Print final notice about "keys init" when done */
  259. *not2 = 1;
  260. }
  261. /* If this is a new key add it to the list */
  262. if (!found) {
  263. AST_RWLIST_INSERT_TAIL(&keys, key, list);
  264. }
  265. return key;
  266. }
  267. /*!
  268. * \brief signs outgoing message with public key
  269. * \see ast_sign_bin
  270. */
  271. int AST_OPTIONAL_API_NAME(ast_sign_bin)(struct ast_key *key, const char *msg, int msglen, unsigned char *dsig)
  272. {
  273. unsigned char digest[20];
  274. unsigned int siglen = 128;
  275. int res;
  276. if (key->ktype != AST_KEY_PRIVATE) {
  277. ast_log(LOG_WARNING, "Cannot sign with a public key\n");
  278. return -1;
  279. }
  280. /* Calculate digest of message */
  281. SHA1((unsigned char *)msg, msglen, digest);
  282. /* Verify signature */
  283. if (!(res = RSA_sign(NID_sha1, digest, sizeof(digest), dsig, &siglen, key->rsa))) {
  284. ast_log(LOG_WARNING, "RSA Signature (key %s) failed\n", key->name);
  285. return -1;
  286. }
  287. if (siglen != 128) {
  288. ast_log(LOG_WARNING, "Unexpected signature length %d, expecting %d\n", (int)siglen, (int)128);
  289. return -1;
  290. }
  291. return 0;
  292. }
  293. /*!
  294. * \brief decrypt a message
  295. * \see ast_decrypt_bin
  296. */
  297. int AST_OPTIONAL_API_NAME(ast_decrypt_bin)(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key)
  298. {
  299. int res, pos = 0;
  300. if (key->ktype != AST_KEY_PRIVATE) {
  301. ast_log(LOG_WARNING, "Cannot decrypt with a public key\n");
  302. return -1;
  303. }
  304. if (srclen % 128) {
  305. ast_log(LOG_NOTICE, "Tried to decrypt something not a multiple of 128 bytes\n");
  306. return -1;
  307. }
  308. while (srclen) {
  309. /* Process chunks 128 bytes at a time */
  310. if ((res = RSA_private_decrypt(128, src, dst, key->rsa, RSA_PKCS1_OAEP_PADDING)) < 0) {
  311. return -1;
  312. }
  313. pos += res;
  314. src += 128;
  315. srclen -= 128;
  316. dst += res;
  317. }
  318. return pos;
  319. }
  320. /*!
  321. * \brief encrypt a message
  322. * \see ast_encrypt_bin
  323. */
  324. int AST_OPTIONAL_API_NAME(ast_encrypt_bin)(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key)
  325. {
  326. int res, bytes, pos = 0;
  327. if (key->ktype != AST_KEY_PUBLIC) {
  328. ast_log(LOG_WARNING, "Cannot encrypt with a private key\n");
  329. return -1;
  330. }
  331. while (srclen) {
  332. bytes = srclen;
  333. if (bytes > 128 - 41) {
  334. bytes = 128 - 41;
  335. }
  336. /* Process chunks 128-41 bytes at a time */
  337. if ((res = RSA_public_encrypt(bytes, src, dst, key->rsa, RSA_PKCS1_OAEP_PADDING)) != 128) {
  338. ast_log(LOG_NOTICE, "How odd, encrypted size is %d\n", res);
  339. return -1;
  340. }
  341. src += bytes;
  342. srclen -= bytes;
  343. pos += res;
  344. dst += res;
  345. }
  346. return pos;
  347. }
  348. /*!
  349. * \brief wrapper for __ast_sign_bin then base64 encode it
  350. * \see ast_sign
  351. */
  352. int AST_OPTIONAL_API_NAME(ast_sign)(struct ast_key *key, char *msg, char *sig)
  353. {
  354. unsigned char dsig[128];
  355. int siglen = sizeof(dsig), res;
  356. if (!(res = ast_sign_bin(key, msg, strlen(msg), dsig))) {
  357. /* Success -- encode (256 bytes max as documented) */
  358. ast_base64encode(sig, dsig, siglen, 256);
  359. }
  360. return res;
  361. }
  362. /*!
  363. * \brief check signature of a message
  364. * \see ast_check_signature_bin
  365. */
  366. int AST_OPTIONAL_API_NAME(ast_check_signature_bin)(struct ast_key *key, const char *msg, int msglen, const unsigned char *dsig)
  367. {
  368. unsigned char digest[20];
  369. int res;
  370. if (key->ktype != AST_KEY_PUBLIC) {
  371. /* Okay, so of course you really *can* but for our purposes
  372. we're going to say you can't */
  373. ast_log(LOG_WARNING, "Cannot check message signature with a private key\n");
  374. return -1;
  375. }
  376. /* Calculate digest of message */
  377. SHA1((unsigned char *)msg, msglen, digest);
  378. /* Verify signature */
  379. if (!(res = RSA_verify(NID_sha1, digest, sizeof(digest), (unsigned char *)dsig, 128, key->rsa))) {
  380. ast_debug(1, "Key failed verification: %s\n", key->name);
  381. return -1;
  382. }
  383. /* Pass */
  384. return 0;
  385. }
  386. /*!
  387. * \brief base64 decode then sent to __ast_check_signature_bin
  388. * \see ast_check_signature
  389. */
  390. int AST_OPTIONAL_API_NAME(ast_check_signature)(struct ast_key *key, const char *msg, const char *sig)
  391. {
  392. unsigned char dsig[128];
  393. int res;
  394. /* Decode signature */
  395. if ((res = ast_base64decode(dsig, sig, sizeof(dsig))) != sizeof(dsig)) {
  396. ast_log(LOG_WARNING, "Signature improper length (expect %d, got %d)\n", (int)sizeof(dsig), (int)res);
  397. return -1;
  398. }
  399. res = ast_check_signature_bin(key, msg, strlen(msg), dsig);
  400. return res;
  401. }
  402. int AST_OPTIONAL_API_NAME(ast_crypto_loaded)(void)
  403. {
  404. return 1;
  405. }
  406. int AST_OPTIONAL_API_NAME(ast_aes_set_encrypt_key)(const unsigned char *key, ast_aes_encrypt_key *ctx)
  407. {
  408. return AES_set_encrypt_key(key, 128, ctx);
  409. }
  410. int AST_OPTIONAL_API_NAME(ast_aes_set_decrypt_key)(const unsigned char *key, ast_aes_decrypt_key *ctx)
  411. {
  412. return AES_set_decrypt_key(key, 128, ctx);
  413. }
  414. void AST_OPTIONAL_API_NAME(ast_aes_encrypt)(const unsigned char *in, unsigned char *out, const ast_aes_encrypt_key *ctx)
  415. {
  416. return AES_encrypt(in, out, ctx);
  417. }
  418. void AST_OPTIONAL_API_NAME(ast_aes_decrypt)(const unsigned char *in, unsigned char *out, const ast_aes_decrypt_key *ctx)
  419. {
  420. return AES_decrypt(in, out, ctx);
  421. }
  422. /*!
  423. * \brief refresh RSA keys from file
  424. * \param ifd file descriptor
  425. * \param ofd file descriptor
  426. * \return void
  427. */
  428. static void crypto_load(int ifd, int ofd)
  429. {
  430. struct ast_key *key;
  431. DIR *dir = NULL;
  432. struct dirent *ent;
  433. int note = 0;
  434. AST_RWLIST_WRLOCK(&keys);
  435. /* Mark all keys for deletion */
  436. AST_RWLIST_TRAVERSE(&keys, key, list) {
  437. key->delme = 1;
  438. }
  439. /* Load new keys */
  440. if ((dir = opendir(ast_config_AST_KEY_DIR))) {
  441. while ((ent = readdir(dir))) {
  442. try_load_key(ast_config_AST_KEY_DIR, ent->d_name, ifd, ofd, &note);
  443. }
  444. closedir(dir);
  445. } else {
  446. ast_log(LOG_WARNING, "Unable to open key directory '%s'\n", ast_config_AST_KEY_DIR);
  447. }
  448. if (note) {
  449. ast_log(LOG_NOTICE, "Please run the command 'keys init' to enter the passcodes for the keys\n");
  450. }
  451. /* Delete any keys that are no longer present */
  452. AST_RWLIST_TRAVERSE_SAFE_BEGIN(&keys, key, list) {
  453. if (key->delme) {
  454. ast_debug(1, "Deleting key %s type %d\n", key->name, key->ktype);
  455. AST_RWLIST_REMOVE_CURRENT(list);
  456. if (key->rsa) {
  457. RSA_free(key->rsa);
  458. }
  459. ast_free(key);
  460. }
  461. }
  462. AST_RWLIST_TRAVERSE_SAFE_END;
  463. AST_RWLIST_UNLOCK(&keys);
  464. }
  465. static void md52sum(char *sum, unsigned char *md5)
  466. {
  467. int x;
  468. for (x = 0; x < 16; x++) {
  469. sum += sprintf(sum, "%02x", (unsigned)*(md5++));
  470. }
  471. }
  472. /*!
  473. * \brief show the list of RSA keys
  474. * \param e CLI command
  475. * \param cmd
  476. * \param a list of CLI arguments
  477. * \return CLI_SUCCESS
  478. */
  479. static char *handle_cli_keys_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  480. {
  481. #define FORMAT "%-18s %-8s %-16s %-33s\n"
  482. struct ast_key *key;
  483. char sum[16 * 2 + 1];
  484. int count_keys = 0;
  485. switch (cmd) {
  486. case CLI_INIT:
  487. e->command = "keys show";
  488. e->usage =
  489. "Usage: keys show\n"
  490. " Displays information about RSA keys known by Asterisk\n";
  491. return NULL;
  492. case CLI_GENERATE:
  493. return NULL;
  494. }
  495. ast_cli(a->fd, FORMAT, "Key Name", "Type", "Status", "Sum");
  496. ast_cli(a->fd, FORMAT, "------------------", "--------", "----------------", "--------------------------------");
  497. AST_RWLIST_RDLOCK(&keys);
  498. AST_RWLIST_TRAVERSE(&keys, key, list) {
  499. md52sum(sum, key->digest);
  500. ast_cli(a->fd, FORMAT, key->name,
  501. (key->ktype & 0xf) == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE",
  502. key->ktype & KEY_NEEDS_PASSCODE ? "[Needs Passcode]" : "[Loaded]", sum);
  503. count_keys++;
  504. }
  505. AST_RWLIST_UNLOCK(&keys);
  506. ast_cli(a->fd, "\n%d known RSA keys.\n", count_keys);
  507. return CLI_SUCCESS;
  508. #undef FORMAT
  509. }
  510. /*!
  511. * \brief initialize all RSA keys
  512. * \param e CLI command
  513. * \param cmd
  514. * \param a list of CLI arguments
  515. * \return CLI_SUCCESS
  516. */
  517. static char *handle_cli_keys_init(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  518. {
  519. struct ast_key *key;
  520. int ign;
  521. char *kn, tmp[256] = "";
  522. switch (cmd) {
  523. case CLI_INIT:
  524. e->command = "keys init";
  525. e->usage =
  526. "Usage: keys init\n"
  527. " Initializes private keys (by reading in pass code from\n"
  528. " the user)\n";
  529. return NULL;
  530. case CLI_GENERATE:
  531. return NULL;
  532. }
  533. if (a->argc != 2) {
  534. return CLI_SHOWUSAGE;
  535. }
  536. AST_RWLIST_WRLOCK(&keys);
  537. AST_RWLIST_TRAVERSE_SAFE_BEGIN(&keys, key, list) {
  538. /* Reload keys that need pass codes now */
  539. if (key->ktype & KEY_NEEDS_PASSCODE) {
  540. kn = key->fn + strlen(ast_config_AST_KEY_DIR) + 1;
  541. ast_copy_string(tmp, kn, sizeof(tmp));
  542. try_load_key(ast_config_AST_KEY_DIR, tmp, a->fd, a->fd, &ign);
  543. }
  544. }
  545. AST_RWLIST_TRAVERSE_SAFE_END
  546. AST_RWLIST_UNLOCK(&keys);
  547. return CLI_SUCCESS;
  548. }
  549. static struct ast_cli_entry cli_crypto[] = {
  550. AST_CLI_DEFINE(handle_cli_keys_show, "Displays RSA key information"),
  551. AST_CLI_DEFINE(handle_cli_keys_init, "Initialize RSA key passcodes")
  552. };
  553. /*! \brief initialise the res_crypto module */
  554. static int crypto_init(void)
  555. {
  556. ast_cli_register_multiple(cli_crypto, ARRAY_LEN(cli_crypto));
  557. return 0;
  558. }
  559. static int reload(void)
  560. {
  561. crypto_load(-1, -1);
  562. return 0;
  563. }
  564. static int load_module(void)
  565. {
  566. crypto_init();
  567. if (ast_opt_init_keys) {
  568. crypto_load(STDIN_FILENO, STDOUT_FILENO);
  569. } else {
  570. crypto_load(-1, -1);
  571. }
  572. return AST_MODULE_LOAD_SUCCESS;
  573. }
  574. static int unload_module(void)
  575. {
  576. /* Can't unload this once we're loaded */
  577. return -1;
  578. }
  579. /* needs usecount semantics defined */
  580. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Cryptographic Digital Signatures",
  581. .support_level = AST_MODULE_SUPPORT_CORE,
  582. .load = load_module,
  583. .unload = unload_module,
  584. .reload = reload,
  585. .load_pri = AST_MODPRI_CHANNEL_DEPEND, /*!< Since we don't have a config file, we could move up to REALTIME_DEPEND, if necessary */
  586. );