Asterisk - The Open Source Telephony Project
18.5.0
|
Asterisk wrapper for crypt(3) More...
Go to the source code of this file.
Macros | |
#define | MAX_SALT_LEN 21 |
Max length of a salt string. More... | |
Functions | |
char * | ast_crypt (const char *key, const char *salt) |
Asterisk wrapper around crypt(3). More... | |
char * | ast_crypt_encrypt (const char *key) |
Asterisk wrapper around crypt(3) for encrypting passwords. More... | |
int | ast_crypt_validate (const char *key, const char *expected) |
Asterisk wrapper around crypt(3) for validating passwords. More... | |
static int | gen_salt (char *current_salt, size_t maxlen) |
Generates a salt to try with crypt. More... | |
static char | gen_salt_char (void) |
Variables | |
static char | salt_chars [] |
Asterisk wrapper for crypt(3)
Definition in file crypt.c.
#define MAX_SALT_LEN 21 |
Max length of a salt string.
$[1,5,6]$[a–zA–Z0–9./]{1,16}$, plus null terminator
Definition at line 43 of file crypt.c.
Referenced by ast_crypt_encrypt(), and gen_salt().
char* ast_crypt | ( | const char * | key, |
const char * | salt | ||
) |
Asterisk wrapper around crypt(3).
The interpretation of the salt (which determines the password hashing algorithm) is system specific. Application code should prefer to use ast_crypt_encrypt() or ast_crypt_validate().
The returned string is heap allocated, and should be freed with ast_free().
key | User's password to crypt. |
salt | Salt to crypt with. |
NULL
on error. Definition at line 121 of file crypt.c.
References ast_begins_with(), ast_strdup, and NULL.
Referenced by ast_crypt_encrypt(), and ast_crypt_validate().
char* ast_crypt_encrypt | ( | const char * | key | ) |
Asterisk wrapper around crypt(3) for encrypting passwords.
This function will generate a random salt and encrypt the given password.
The returned string is heap allocated, and should be freed with ast_free().
key | User's password to crypt. |
NULL
on error. Definition at line 190 of file crypt.c.
References ast_crypt(), gen_salt(), MAX_SALT_LEN, and NULL.
Referenced by ari_mkpasswd(), and AST_TEST_DEFINE().
int ast_crypt_validate | ( | const char * | key, |
const char * | expected | ||
) |
Asterisk wrapper around crypt(3) for validating passwords.
key | User's password to validate. |
expected | Expected result from crypt. |
Definition at line 136 of file crypt.c.
References ast_begins_with(), ast_crypt(), ast_log, AST_MUTEX_DEFINE_STATIC, ast_strdup, lock, LOG_WARNING, NULL, and SCOPED_MUTEX.
Referenced by ast_ari_config_validate_user(), and AST_TEST_DEFINE().
|
static |
Generates a salt to try with crypt.
If given an empty string, will generate a salt for the most secure algorithm to try with crypt(). If given a previously generated salt, the algorithm will be lowered by one level of security.
[out] | current_salt | Output string in which to generate the salt. This can be an empty string, or the results of a prior gen_salt call. |
max_len | Length of current_salt. |
Definition at line 72 of file crypt.c.
References gen_salt_char(), MAX_SALT_LEN, and NULL.
Referenced by ast_crypt_encrypt().
|
static |
Randomly select a character for a salt string
Definition at line 52 of file crypt.c.
References ast_random_double, and salt_chars.
Referenced by gen_salt().
|
static |
Definition at line 45 of file crypt.c.
Referenced by gen_salt_char().