| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#include "mod_auth_otp.h" |
| 26 |
#include "crypto.h" |
| 27 |
|
| 28 |
int auth_otp_crypto_init(void) { |
| 29 |
return 0; |
| 30 |
} |
| 31 |
|
| 32 |
void auth_otp_crypto_free(int flags) { |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
if (pr_module_get("mod_digest.c") == NULL && |
| 42 |
pr_module_get("mod_ldap.c") == NULL && |
| 43 |
pr_module_get("mod_proxy.c") == NULL && |
| 44 |
pr_module_get("mod_radius.c") == NULL && |
| 45 |
pr_module_get("mod_sftp.c") == NULL && |
| 46 |
pr_module_get("mod_sql.c") == NULL && |
| 47 |
pr_module_get("mod_sql_passwd.c") == NULL && |
| 48 |
pr_module_get("mod_tls.c") == NULL) { |
| 49 |
|
| 50 |
#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 51 |
ERR_free_strings(); |
| 52 |
EVP_cleanup(); |
| 53 |
RAND_cleanup(); |
| 54 |
# if OPENSSL_VERSION_NUMBER >= 0x10000001L |
| 55 |
ERR_remove_state(0); |
| 56 |
# endif |
| 57 |
#endif |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
const char *auth_otp_crypto_get_errors(void) { |
| 62 |
unsigned int count = 0; |
| 63 |
unsigned long e = ERR_get_error(); |
| 64 |
BIO *bio = NULL; |
| 65 |
char *data = NULL; |
| 66 |
long datalen; |
| 67 |
const char *str = "(unknown)"; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
if (e) { |
| 74 |
bio = BIO_new(BIO_s_mem()); |
| 75 |
} |
| 76 |
|
| 77 |
while (e) { |
| 78 |
pr_signals_handle(); |
| 79 |
BIO_printf(bio, "\n (%u) %s", ++count, ERR_error_string(e, NULL)); |
| 80 |
e = ERR_get_error(); |
| 81 |
} |
| 82 |
|
| 83 |
datalen = BIO_get_mem_data(bio, &data); |
| 84 |
if (data) { |
| 85 |
data[datalen] = '\0'; |
| 86 |
str = pstrndup(auth_otp_pool, data, datalen-1); |
| 87 |
} |
| 88 |
|
| 89 |
if (bio) { |
| 90 |
BIO_free(bio); |
| 91 |
} |
| 92 |
|
| 93 |
return str; |
| 94 |
} |
| 95 |
|
| 96 |
int auth_otp_hmac(const EVP_MD *md, const unsigned char *key, size_t key_len, |
| 97 |
const unsigned char *data, size_t data_len, unsigned char *mac, |
| 98 |
size_t *mac_len) { |
| 99 |
|
| 100 |
if ((key == NULL || key_len == 0) || |
| 101 |
(data == NULL || data_len == 0) || |
| 102 |
(mac == NULL || mac_len == NULL)) { |
| 103 |
errno = EINVAL; |
| 104 |
return -1; |
| 105 |
} |
| 106 |
|
| 107 |
if (HMAC(md, key, key_len, data, data_len, mac, |
| 108 |
(unsigned int *) mac_len) == NULL) { |
| 109 |
(void) pr_log_writefile(auth_otp_logfd, MOD_AUTH_OTP_VERSION, |
| 110 |
"HMAC error: %s", auth_otp_crypto_get_errors()); |
| 111 |
errno = EPERM; |
| 112 |
return -1; |
| 113 |
} |
| 114 |
|
| 115 |
return 0; |
| 116 |
} |