Asterisk - The Open Source Telephony Project
18.5.0
|
Provide Cryptographic Signature capability. More...
#include "asterisk.h"
#include <dirent.h>
#include <openssl/aes.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
#include <openssl/sha.h>
#include "asterisk/cli.h"
#include "asterisk/compat.h"
#include "asterisk/io.h"
#include "asterisk/linkedlists.h"
#include "asterisk/logger.h"
#include "asterisk/md5.h"
#include "asterisk/module.h"
#include "asterisk/options.h"
#include "asterisk/paths.h"
#include "asterisk/utils.h"
#include "asterisk/crypto.h"
Go to the source code of this file.
Data Structures | |
struct | ast_key |
struct | keys |
Macros | |
#define | AST_API_MODULE |
#define | FORMAT "%-18s %-8s %-16s %-33s\n" |
#define | KEY_NEEDS_PASSCODE (1 << 16) |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
void AST_OPTIONAL_API_NAME() | ast_aes_decrypt (const unsigned char *in, unsigned char *out, const ast_aes_decrypt_key *ctx) |
void AST_OPTIONAL_API_NAME() | ast_aes_encrypt (const unsigned char *in, unsigned char *out, const ast_aes_encrypt_key *ctx) |
int AST_OPTIONAL_API_NAME() | ast_aes_set_decrypt_key (const unsigned char *key, ast_aes_decrypt_key *ctx) |
int AST_OPTIONAL_API_NAME() | ast_aes_set_encrypt_key (const unsigned char *key, ast_aes_encrypt_key *ctx) |
int AST_OPTIONAL_API_NAME() | ast_check_signature (struct ast_key *key, const char *msg, const char *sig) |
base64 decode then sent to __ast_check_signature_bin More... | |
int AST_OPTIONAL_API_NAME() | ast_check_signature_bin (struct ast_key *key, const char *msg, int msglen, const unsigned char *dsig) |
check signature of a message More... | |
int AST_OPTIONAL_API_NAME() | ast_crypto_loaded (void) |
int AST_OPTIONAL_API_NAME() | ast_decrypt_bin (unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key) |
decrypt a message More... | |
int AST_OPTIONAL_API_NAME() | ast_encrypt_bin (unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key) |
encrypt a message More... | |
struct ast_key *AST_OPTIONAL_API_NAME() | ast_key_get (const char *kname, int ktype) |
return the ast_key structure for name More... | |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
int AST_OPTIONAL_API_NAME() | ast_sign (struct ast_key *key, char *msg, char *sig) |
wrapper for __ast_sign_bin then base64 encode it More... | |
int AST_OPTIONAL_API_NAME() | ast_sign_bin (struct ast_key *key, const char *msg, int msglen, unsigned char *dsig) |
signs outgoing message with public key More... | |
static int | crypto_init (void) |
initialise the res_crypto module More... | |
static void | crypto_load (int ifd, int ofd) |
refresh RSA keys from file More... | |
static char * | handle_cli_keys_init (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
initialize all RSA keys More... | |
static char * | handle_cli_keys_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
show the list of RSA keys More... | |
static int | load_module (void) |
static void | md52sum (char *sum, unsigned char *md5) |
static int | pw_cb (char *buf, int size, int rwflag, void *userdata) |
setting of priv key More... | |
static int | reload (void) |
static struct ast_key * | try_load_key (const char *dir, const char *fname, int ifd, int ofd, int *not2) |
load RSA key from file More... | |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Cryptographic Digital Signatures" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , } |
static struct ast_cli_entry | cli_crypto [] |
static struct keys | keys = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , } |
Provide Cryptographic Signature capability.
Uses the OpenSSL library, available at http://www.openssl.org/
Definition in file res_crypto.c.
#define AST_API_MODULE |
Definition at line 56 of file res_crypto.c.
#define FORMAT "%-18s %-8s %-16s %-33s\n" |
Referenced by handle_cli_keys_show().
#define KEY_NEEDS_PASSCODE (1 << 16) |
Definition at line 72 of file res_crypto.c.
Referenced by handle_cli_keys_init(), handle_cli_keys_show(), and try_load_key().
|
static |
Definition at line 677 of file res_crypto.c.
|
static |
Definition at line 677 of file res_crypto.c.
void AST_OPTIONAL_API_NAME() ast_aes_decrypt | ( | const unsigned char * | in, |
unsigned char * | out, | ||
const ast_aes_decrypt_key * | ctx | ||
) |
Definition at line 481 of file res_crypto.c.
Referenced by __stub__ast_aes_encrypt(), aes_helper(), decrypt_memcpy(), and memcpy_decrypt().
void AST_OPTIONAL_API_NAME() ast_aes_encrypt | ( | const unsigned char * | in, |
unsigned char * | out, | ||
const ast_aes_encrypt_key * | ctx | ||
) |
Definition at line 476 of file res_crypto.c.
Referenced by __stub__ast_aes_set_decrypt_key(), aes_helper(), encrypt_memcpy(), and memcpy_encrypt().
int AST_OPTIONAL_API_NAME() ast_aes_set_decrypt_key | ( | const unsigned char * | key, |
ast_aes_decrypt_key * | ctx | ||
) |
Definition at line 471 of file res_crypto.c.
Referenced by __stub__ast_aes_set_encrypt_key(), aes_helper(), build_ecx_key(), build_encryption_keys(), check_key(), socket_process_helper(), and update_key().
int AST_OPTIONAL_API_NAME() ast_aes_set_encrypt_key | ( | const unsigned char * | key, |
ast_aes_encrypt_key * | ctx | ||
) |
Definition at line 466 of file res_crypto.c.
Referenced by __stub__ast_decrypt_bin(), aes_helper(), build_ecx_key(), check_key(), and update_key().
int AST_OPTIONAL_API_NAME() ast_check_signature | ( | struct ast_key * | key, |
const char * | msg, | ||
const char * | sig | ||
) |
base64 decode then sent to __ast_check_signature_bin
Definition at line 445 of file res_crypto.c.
References ast_base64decode(), ast_check_signature_bin(), ast_log, and LOG_WARNING.
Referenced by authenticate_verify(), and register_verify().
int AST_OPTIONAL_API_NAME() ast_check_signature_bin | ( | struct ast_key * | key, |
const char * | msg, | ||
int | msglen, | ||
const unsigned char * | dsig | ||
) |
check signature of a message
Definition at line 416 of file res_crypto.c.
References ast_debug, AST_KEY_PUBLIC, ast_log, ast_key::digest, ast_key::ktype, LOG_WARNING, ast_key::name, ast_key::rsa, and SHA1.
Referenced by ast_check_signature(), and check_key().
int AST_OPTIONAL_API_NAME() ast_crypto_loaded | ( | void | ) |
Definition at line 461 of file res_crypto.c.
Referenced by AST_TEST_DEFINE().
int AST_OPTIONAL_API_NAME() ast_decrypt_bin | ( | unsigned char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
struct ast_key * | key | ||
) |
decrypt a message
Definition at line 336 of file res_crypto.c.
References AST_KEY_PRIVATE, ast_log, ast_key::ktype, LOG_NOTICE, LOG_WARNING, and ast_key::rsa.
Referenced by check_key().
int AST_OPTIONAL_API_NAME() ast_encrypt_bin | ( | unsigned char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
struct ast_key * | key | ||
) |
encrypt a message
Definition at line 368 of file res_crypto.c.
References AST_KEY_PUBLIC, ast_log, ast_key::ktype, LOG_NOTICE, LOG_WARNING, and ast_key::rsa.
Referenced by update_key().
struct ast_key* AST_OPTIONAL_API_NAME() ast_key_get | ( | const char * | kname, |
int | ktype | ||
) |
return the ast_key structure for name
Definition at line 141 of file res_crypto.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_key::ktype, and ast_key::name.
Referenced by authenticate(), authenticate_verify(), check_key(), register_verify(), and update_key().
struct ast_module* AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 677 of file res_crypto.c.
int AST_OPTIONAL_API_NAME() ast_sign | ( | struct ast_key * | key, |
char * | msg, | ||
char * | sig | ||
) |
wrapper for __ast_sign_bin then base64 encode it
Definition at line 399 of file res_crypto.c.
References ast_base64encode(), and ast_sign_bin().
Referenced by authenticate().
int AST_OPTIONAL_API_NAME() ast_sign_bin | ( | struct ast_key * | key, |
const char * | msg, | ||
int | msglen, | ||
unsigned char * | dsig | ||
) |
signs outgoing message with public key
Definition at line 304 of file res_crypto.c.
References AST_KEY_PRIVATE, ast_log, ast_key::digest, ast_key::ktype, LOG_WARNING, ast_key::name, ast_key::rsa, and SHA1.
Referenced by ast_sign(), and update_key().
|
static |
initialise the res_crypto module
Definition at line 640 of file res_crypto.c.
References ARRAY_LEN, and ast_cli_register_multiple.
Referenced by load_module().
|
static |
refresh RSA keys from file
ifd | file descriptor |
ofd | file descriptor |
Definition at line 492 of file res_crypto.c.
References ast_config_AST_KEY_DIR, ast_debug, ast_free, ast_log, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_key::delme, ast_key::ktype, LOG_NOTICE, LOG_WARNING, ast_key::name, NULL, ast_key::rsa, and try_load_key().
Referenced by load_module(), and reload().
|
static |
initialize all RSA keys
e | CLI command |
cmd | |
a | list of CLI arguments |
Definition at line 597 of file res_crypto.c.
References ast_cli_args::argc, ast_config_AST_KEY_DIR, ast_copy_string(), AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_key::fn, KEY_NEEDS_PASSCODE, ast_key::ktype, NULL, tmp(), try_load_key(), and ast_cli_entry::usage.
|
static |
show the list of RSA keys
e | CLI command |
cmd | |
a | list of CLI arguments |
Definition at line 551 of file res_crypto.c.
References ast_cli(), AST_KEY_PUBLIC, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_key::digest, ast_cli_args::fd, FORMAT, KEY_NEEDS_PASSCODE, ast_key::ktype, md52sum(), ast_key::name, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 652 of file res_crypto.c.
References AST_MODULE_LOAD_SUCCESS, ast_opt_init_keys, crypto_init(), and crypto_load().
Referenced by unload_module().
|
static |
Definition at line 536 of file res_crypto.c.
Referenced by handle_cli_keys_show().
|
static |
setting of priv key
buf | |
size | |
rwflag | |
userdata |
Definition at line 104 of file res_crypto.c.
References ast_hide_password(), AST_KEY_PRIVATE, ast_log, ast_restore_tty(), errno, ast_key::infd, ast_key::ktype, LOG_WARNING, ast_key::name, ast_key::outfd, prompt, and tmp().
Referenced by try_load_key().
|
static |
Definition at line 646 of file res_crypto.c.
References crypto_load().
Referenced by unload_module().
|
static |
load RSA key from file
dir | directory string |
fname | name of file |
ifd | incoming file descriptor |
ofd | outgoing file descriptor |
not2 |
key | on success. |
NULL | on failure. |
Definition at line 167 of file res_crypto.c.
References ast_calloc, ast_copy_string(), ast_debug, AST_KEY_PRIVATE, AST_KEY_PUBLIC, ast_log, ast_opt_init_keys, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, ast_verb, buf, c, ast_key::delme, ast_key::digest, errno, ast_key::fn, ast_key::infd, KEY_NEEDS_PASSCODE, ast_key::ktype, LOG_NOTICE, LOG_WARNING, MD5Final(), MD5Init(), MD5Update(), ast_key::name, NULL, ast_key::outfd, pw_cb(), and ast_key::rsa.
Referenced by crypto_load(), and handle_cli_keys_init().
|
static |
Definition at line 664 of file res_crypto.c.
References ARRAY_LEN, ast_cli_unregister_multiple(), AST_MODFLAG_GLOBAL_SYMBOLS, AST_MODFLAG_LOAD_ORDER, AST_MODPRI_CHANNEL_DEPEND, AST_MODULE_INFO(), AST_MODULE_SUPPORT_CORE, ASTERISK_GPL_KEY, load_module(), and reload().
|
static |
Definition at line 677 of file res_crypto.c.
|
static |
Definition at line 634 of file res_crypto.c.
|
static |
Referenced by misdn_set_opt_exec(), and store_odbc().