ssl.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "asterisk.h"
00031
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 373061 $")
00033
00034 #ifdef HAVE_OPENSSL
00035 #include <openssl/ssl.h>
00036 #include <openssl/err.h>
00037 #endif
00038
00039 #include "asterisk/_private.h"
00040
00041 #include "asterisk/utils.h"
00042 #include "asterisk/lock.h"
00043
00044 #ifdef HAVE_OPENSSL
00045
00046 static ast_mutex_t *ssl_locks;
00047
00048 static int ssl_num_locks;
00049
00050 static unsigned long ssl_threadid(void)
00051 {
00052 return (unsigned long)pthread_self();
00053 }
00054
00055 static void ssl_lock(int mode, int n, const char *file, int line)
00056 {
00057 if (n < 0 || n >= ssl_num_locks) {
00058 ast_log(LOG_ERROR, "OpenSSL is full of LIES!!! - "
00059 "ssl_num_locks '%d' - n '%d'\n",
00060 ssl_num_locks, n);
00061 return;
00062 }
00063
00064 if (mode & CRYPTO_LOCK) {
00065 ast_mutex_lock(&ssl_locks[n]);
00066 } else {
00067 ast_mutex_unlock(&ssl_locks[n]);
00068 }
00069 }
00070
00071 #endif
00072
00073
00074
00075
00076
00077 int ast_ssl_init(void)
00078 {
00079 #ifdef HAVE_OPENSSL
00080 unsigned int i;
00081
00082 SSL_library_init();
00083 SSL_load_error_strings();
00084 ERR_load_BIO_strings();
00085
00086
00087
00088 CRYPTO_set_id_callback(ssl_threadid);
00089
00090 ssl_num_locks = CRYPTO_num_locks();
00091 if (!(ssl_locks = ast_calloc(ssl_num_locks, sizeof(ssl_locks[0])))) {
00092 return -1;
00093 }
00094 for (i = 0; i < ssl_num_locks; i++) {
00095 ast_mutex_init(&ssl_locks[i]);
00096 }
00097 CRYPTO_set_locking_callback(ssl_lock);
00098
00099 #endif
00100 return 0;
00101 }
00102