void ff_tls_init(void) { avpriv_lock_avformat(); #if CONFIG_OPENSSL if (!openssl_init) { SSL_library_init(); SSL_load_error_strings(); #if HAVE_THREADS if (!CRYPTO_get_locking_callback()) { int i; openssl_mutexes = av_malloc_array(sizeof(pthread_mutex_t), CRYPTO_num_locks()); for (i = 0; i < CRYPTO_num_locks(); i++) pthread_mutex_init(&openssl_mutexes[i], NULL); CRYPTO_set_locking_callback(openssl_lock); #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000 CRYPTO_set_id_callback(openssl_thread_id); #endif } #endif } openssl_init++; #endif #if CONFIG_GNUTLS #if HAVE_THREADS && GNUTLS_VERSION_NUMBER < 0x020b00 if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0) gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); #endif gnutls_global_init(); #endif avpriv_unlock_avformat(); }
void CRYPTO_thread_setup (void) { int i; char filename[20]; strcpy (filename, "/tmp/mttest.XXXXXX"); mktemp (filename); usconfig (CONF_STHREADIOOFF); usconfig (CONF_STHREADMALLOCOFF); usconfig (CONF_INITUSERS, 100); usconfig (CONF_LOCKTYPE, US_DEBUGPLUS); arena = usinit (filename); unlink (filename); lock_cs = OPENSSL_malloc (CRYPTO_num_locks () * sizeof (usema_t *)); for (i = 0; i < CRYPTO_num_locks (); i++) { lock_cs[i] = usnewsema (arena, 1); } CRYPTO_set_id_callback ((unsigned long (*)()) irix_thread_id); CRYPTO_set_locking_callback ((void (*)()) irix_locking_callback); }
void OpenSSLInitializer::initialize() { Poco::FastMutex::ScopedLock lock(_mutex); if (++_rc == 1) { #if OPENSSL_VERSION_NUMBER >= 0x0907000L OPENSSL_config(NULL); #endif SSL_library_init(); SSL_load_error_strings(); OpenSSL_add_all_algorithms(); char seed[SEEDSIZE]; RandomInputStream rnd; rnd.read(seed, sizeof(seed)); RAND_seed(seed, SEEDSIZE); int nMutexes = CRYPTO_num_locks(); _mutexes = new Poco::FastMutex[nMutexes]; CRYPTO_set_locking_callback(&OpenSSLInitializer::lock); #ifndef POCO_OS_FAMILY_WINDOWS // SF# 1828231: random unhandled exceptions when linking with ssl CRYPTO_set_id_callback(&OpenSSLInitializer::id); #endif CRYPTO_set_dynlock_create_callback(&OpenSSLInitializer::dynlockCreate); CRYPTO_set_dynlock_lock_callback(&OpenSSLInitializer::dynlock); CRYPTO_set_dynlock_destroy_callback(&OpenSSLInitializer::dynlockDestroy); } }
/* * Initialize the OpenSSL subsystem for use in a multi threaded enviroment. */ static BOOL server_initialize_ssl( Remote * remote ) { int i = 0; lock_acquire( remote->lock ); // Begin to bring up the OpenSSL subsystem... CRYPTO_malloc_init(); SSL_load_error_strings(); SSL_library_init(); // Setup the required OpenSSL multi-threaded enviroment... ssl_locks = (LOCK**)malloc( CRYPTO_num_locks() * sizeof(LOCK *) ); if( ssl_locks == NULL ) { lock_release( remote->lock ); return FALSE; } for( i=0 ; i<CRYPTO_num_locks() ; i++ ) ssl_locks[i] = lock_create(); CRYPTO_set_id_callback( server_threadid_callback ); CRYPTO_set_locking_callback( server_locking_callback ); CRYPTO_set_dynlock_create_callback( server_dynamiclock_create ); CRYPTO_set_dynlock_lock_callback( server_dynamiclock_lock ); CRYPTO_set_dynlock_destroy_callback( server_dynamiclock_destroy ); lock_release( remote->lock ); return TRUE; }
/* * Bring down the OpenSSL subsystem */ static BOOL server_destroy_ssl( Remote * remote ) { int i = 0; if( remote == NULL ) return FALSE; dprintf("[SERVER] Destroying SSL"); lock_acquire( remote->lock ); SSL_free( remote->ssl ); SSL_CTX_free( remote->ctx ); CRYPTO_set_locking_callback( NULL ); CRYPTO_set_id_callback( NULL ); CRYPTO_set_dynlock_create_callback( NULL ); CRYPTO_set_dynlock_lock_callback( NULL ); CRYPTO_set_dynlock_destroy_callback( NULL ); for( i=0 ; i<CRYPTO_num_locks() ; i++ ) lock_destroy( ssl_locks[i] ); free( ssl_locks ); lock_release( remote->lock ); return TRUE; }
/* * Deinitialize OpenSSL and free as much memory as possible. * Some 10k-100k will still remain resident no matter what. */ void ssl_fini(void) { if (!ssl_initialized) return; ERR_remove_state(0); /* current thread */ #ifdef OPENSSL_THREADS CRYPTO_set_locking_callback(NULL); CRYPTO_set_dynlock_create_callback(NULL); CRYPTO_set_dynlock_lock_callback(NULL); CRYPTO_set_dynlock_destroy_callback(NULL); #ifdef OPENSSL_NO_THREADID CRYPTO_set_id_callback(NULL); #else /* !OPENSSL_NO_THREADID */ CRYPTO_THREADID_set_callback(NULL); #endif /* !OPENSSL_NO_THREADID */ for (int i = 0; i < ssl_mutex_num; i++) { pthread_mutex_destroy(&ssl_mutex[i]); } free(ssl_mutex); #endif ENGINE_cleanup(); CONF_modules_finish(); CONF_modules_unload(1); CONF_modules_free(); EVP_cleanup(); ERR_free_strings(); CRYPTO_cleanup_all_ex_data(); }
static void SetupOpenSSLThreadLocks(void) { const int num_locks = CRYPTO_num_locks(); assert(cf_openssl_locks == NULL); cf_openssl_locks = xmalloc(num_locks * sizeof(*cf_openssl_locks)); for (int i = 0; i < num_locks; i++) { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); int ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); if (ret != 0) { Log(LOG_LEVEL_ERR, "Failed to use error-checking mutexes for openssl," " falling back to normal ones (pthread_mutexattr_settype: %s)", GetErrorStrFromCode(ret)); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); } ret = pthread_mutex_init(&cf_openssl_locks[i], &attr); if (ret != 0) { Log(LOG_LEVEL_CRIT, "Failed to use initialise mutexes for openssl" " (pthread_mutex_init: %s)!", GetErrorStrFromCode(ret)); } pthread_mutexattr_destroy(&attr); } #ifndef __MINGW32__ CRYPTO_set_id_callback((unsigned long (*)())ThreadId_callback); #endif CRYPTO_set_locking_callback((void (*)())OpenSSLLock_callback); }
int main(int argc, char **argv) { int i; pthread_t thread1, thread2, thread3, thread4; int iret1, iret2, iret3, iret4; start = time(NULL); signal(SIGUSR2, sig_handler); /* setup for openssl to handle multithreading code taken from 'the definitive guide to linux network programming, pages 250ish*/ mutex_buffer = (pthread_mutex_t *) malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); for(i=0; i<CRYPTO_num_locks(); i++) pthread_mutex_init(&mutex_buffer[i],NULL); CRYPTO_set_id_callback(thread_id_function); CRYPTO_set_locking_callback(locking_function); /* each thread searches quarter the space, split on the first character of the message */ iret1 = pthread_create( &thread1, NULL, fun1, NULL); iret2 = pthread_create( &thread2, NULL, fun2, NULL); iret3 = pthread_create( &thread3, NULL, fun3, NULL); iret4 = pthread_create( &thread4, NULL, fun4, NULL); pthread_join( thread1, NULL); pthread_join( thread2, NULL); pthread_join( thread3, NULL); pthread_join( thread4, NULL); return 0; }
void SSLSupport::init(void) { pthread_mutex_lock(&s_initLock); if (s_initCounter) { //already inited, exit pthread_mutex_unlock(&s_initLock); return; } ++s_initCounter; SSL_load_error_strings(); /* readable error messages */ SSL_library_init(); /* initialize library */ OpenSSL_add_all_ciphers(); OpenSSL_add_all_digests(); ERR_load_crypto_strings(); s_nLocks = CRYPTO_num_locks(); s_mutexArray = (pthread_mutex_t*) OPENSSL_malloc(s_nLocks * sizeof(pthread_mutex_t)); for (int i = 0; i < s_nLocks; i++) { pthread_mutex_init(&s_mutexArray[i], NULL); } CRYPTO_set_id_callback(getThreadID); CRYPTO_set_locking_callback(lock); pthread_mutex_unlock(&s_initLock); }
static int tls_init_multithread(void) { /* init static locks support */ tls_static_locks_no = CRYPTO_num_locks(); if (tls_static_locks_no>0) { /* init a lock set & pass locking function to SSL */ tls_static_locks = lock_set_alloc(tls_static_locks_no); if (tls_static_locks == NULL) { LM_ERR("Failed to alloc static locks\n"); return -1; } if (lock_set_init(tls_static_locks)==0) { LM_ERR("Failed to init static locks\n"); lock_set_dealloc(tls_static_locks); return -1; } CRYPTO_set_locking_callback(tls_static_locks_ops); } CRYPTO_set_id_callback(tls_get_id); /* dynamic locks support*/ CRYPTO_set_dynlock_create_callback(tls_dyn_lock_create); CRYPTO_set_dynlock_lock_callback(tls_dyn_lock_ops); CRYPTO_set_dynlock_destroy_callback(tls_dyn_lock_destroy); return 0; }
void ssl_util_thread_setup(apr_pool_t *p) { int i; lock_num_locks = CRYPTO_num_locks(); lock_cs = apr_palloc(p, lock_num_locks * sizeof(*lock_cs)); for (i = 0; i < lock_num_locks; i++) { apr_thread_mutex_create(&(lock_cs[i]), APR_THREAD_MUTEX_DEFAULT, p); } CRYPTO_set_id_callback(ssl_util_thr_id); CRYPTO_set_locking_callback(ssl_util_thr_lock); /* Set up dynamic locking scaffolding for OpenSSL to use at its * convenience. */ dynlockpool = p; CRYPTO_set_dynlock_create_callback(ssl_dyn_create_function); CRYPTO_set_dynlock_lock_callback(ssl_dyn_lock_function); CRYPTO_set_dynlock_destroy_callback(ssl_dyn_destroy_function); apr_pool_cleanup_register(p, NULL, ssl_util_thread_cleanup, apr_pool_cleanup_null); }
CSSLApplication::CSSLApplication() { if (SSLInited) return; SSLInited = 1; NeedDataOp = 0; #ifdef _DEBUG // OpenSSL internal memory-leak checkers CRYPTO_malloc_debug_init(); CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); #endif openssl_locks = new Synchronizer[CRYPTO_num_locks()]; // callbacks for static lock CRYPTO_set_locking_callback(funcOpenSSLLockingCallback); CRYPTO_set_id_callback(funcOpenSSLIDCallback); // callbacks for dynamic lock CRYPTO_set_dynlock_create_callback(funcOpenSSLDynCreateCallback); CRYPTO_set_dynlock_destroy_callback(funcOpenSSLDynDestroyCallback); CRYPTO_set_dynlock_lock_callback(funcOpenSSLDynLockCallback); // Load algorithms and error strings. SSL_load_error_strings(); SSL_library_init(); };
static int setup_ssl_mutexes(void) { int i; #ifdef HAVE_OPENSSL_EVP_H /* * Enable all ciphers and digests. */ OpenSSL_add_all_algorithms(); #endif ssl_mutexes = rad_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); if (!ssl_mutexes) { radlog(L_ERR, "Error allocating memory for SSL mutexes!"); return 0; } for (i = 0; i < CRYPTO_num_locks(); i++) { pthread_mutex_init(&(ssl_mutexes[i]), NULL); } CRYPTO_set_id_callback(ssl_id_function); CRYPTO_set_locking_callback(ssl_locking_function); return 1; }
void LLCurl::initClass(F32 curl_reuest_timeout, S32 max_number_handles, bool multi_threaded) { sCurlRequestTimeOut = curl_reuest_timeout ; //seconds sMaxHandles = max_number_handles ; //max number of handles, (multi handles and easy handles combined). // Do not change this "unless you are familiar with and mean to control // internal operations of libcurl" // - http://curl.haxx.se/libcurl/c/curl_global_init.html CURLcode code = curl_global_init(CURL_GLOBAL_ALL); check_curl_code(code); #if SAFE_SSL S32 mutex_count = CRYPTO_num_locks(); for (S32 i=0; i<mutex_count; i++) { sSSLMutex.push_back(new LLMutex(NULL)); } CRYPTO_set_id_callback(&LLCurl::ssl_thread_id); CRYPTO_set_locking_callback(&LLCurl::ssl_locking_callback); #endif sCurlThread = new LLCurlThread(multi_threaded) ; if(multi_threaded) { sHandleMutexp = new LLMutex(NULL) ; Easy::sHandleMutexp = new LLMutex(NULL) ; } }
static INT32 _ossSSLTheadInit() { INT32 i; INT32 ret = SSL_OK; _ossSSLThreadLocks = (ossMutex*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(ossMutex)); if (NULL == _ossSSLThreadLocks) { goto error; } for (i = 0; i < CRYPTO_num_locks(); i++) { ossMutexInit(&_ossSSLThreadLocks[i]); } /* set OpenSSL multithreading callbacks */ CRYPTO_set_id_callback(_ossSSLThreadIdCallback); CRYPTO_set_locking_callback(_ossSSLThreadLockingCallback); done: return ret; error: ret = SSL_ERROR; goto done; }
bool CSSLClient::Initial(unsigned long encryptionType) { //初始SSL s_Lock.Lock(); if (0 == s_objectCount) { SSL_library_init(); const SSL_METHOD * pSSLMethod = NULL; if (TVT_ENCRYPTION_SSL == encryptionType) { pSSLMethod = TLSv1_client_method(); } else if(TVT_ENCRYPTION_TLS == encryptionType) { pSSLMethod = SSLv3_client_method(); } SSL_load_error_strings(); s_SSLCTX = SSL_CTX_new(pSSLMethod); if(NULL == s_SSLCTX) { int errNum = ERR_get_error(); printf("%s:%s:%d, ssl connect error:%s\n", __FUNCTION__, __FILE__, __LINE__, ERR_reason_error_string(errNum)); printf("%s:%s:%d, error function=%s\n", __FUNCTION__, __FILE__, __LINE__, ERR_func_error_string(errNum)); s_Lock.UnLock(); return false; } /* if (SSL_CTX_use_certificate_file(s_SSLCTX, CA_CERT_FILE, SSL_FILETYPE_PEM) <= 0) { printf("Error: %s\n", ERR_reason_error_string(ERR_get_error())); s_Lock.UnLock(); return false; } if (SSL_CTX_use_PrivateKey_file_pass(s_SSLCTX, CA_KEY_FILE, "123456") <= 0) { printf("use_PrivateKey_file err\n"); s_Lock.UnLock(); return false; } */ for (int i=0; i < CRYPTO_num_locks(); ++i) { CPUB_Lock *pLock = new CPUB_Lock; s_vecLock.push_back(pLock); } CRYPTO_set_id_callback(GetThreadId); CRYPTO_set_locking_callback(pthreads_locking_callback); s_bHasInitial = true; } s_objectCount++; s_Lock.UnLock(); return true; }
// Dynamically load SSL library. Set up ctx->ssl_ctx pointer. static int set_ssl_option(struct mg_context *ctx) { int i, size; const char *pem; // If PEM file is not specified and the init_ssl callback // is not specified, skip SSL initialization. if ((pem = ctx->config[SSL_CERTIFICATE]) == NULL) { // MG_INIT_SSL // ctx->callbacks.init_ssl == NULL) { return 1; } #if !defined(NO_SSL_DL) if (!load_dll(ctx, SSL_LIB, ssl_sw) || !load_dll(ctx, CRYPTO_LIB, crypto_sw)) { return 0; } #endif // NO_SSL_DL // Initialize SSL library SSL_library_init(); SSL_load_error_strings(); if ((ctx->ssl_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) { cry(fc(ctx), "SSL_CTX_new (server) error: %s", ssl_error()); return 0; } // If user callback returned non-NULL, that means that user callback has // set up certificate itself. In this case, skip sertificate setting. // MG_INIT_SSL if (SSL_CTX_use_certificate_file(ctx->ssl_ctx, pem, 1) == 0 || SSL_CTX_use_PrivateKey_file(ctx->ssl_ctx, pem, 1) == 0) { cry(fc(ctx), "%s: cannot open %s: %s", __func__, pem, ssl_error()); return 0; } if (pem != NULL) { (void) SSL_CTX_use_certificate_chain_file(ctx->ssl_ctx, pem); } // Initialize locking callbacks, needed for thread safety. // http://www.openssl.org/support/faq.html#PROG1 size = sizeof(pthread_mutex_t) * CRYPTO_num_locks(); if ((ssl_mutexes = (pthread_mutex_t *) malloc((size_t)size)) == NULL) { cry(fc(ctx), "%s: cannot allocate mutexes: %s", __func__, ssl_error()); return 0; } for (i = 0; i < CRYPTO_num_locks(); i++) { pthread_mutex_init(&ssl_mutexes[i], NULL); } CRYPTO_set_locking_callback(&ssl_locking_callback); CRYPTO_set_id_callback(&ssl_id_callback); return 1; }
static void init_locks(void) { int i; lockarray = (pthread_mutex_t*) OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); for (i = 0; i < CRYPTO_num_locks(); i++) pthread_mutex_init(&(lockarray[i]), NULL); CRYPTO_set_id_callback((unsigned long (*)()) thread_id); CRYPTO_set_locking_callback((void (*)()) lock_callback); }
void SSLInit::Init() { assert(!s_isSSLInited); s_locks = new Mutex[CRYPTO_num_locks()]; CRYPTO_set_id_callback((unsigned long (*)())callback_thread_id); CRYPTO_set_locking_callback( (void (*)(int mode, int type, const char *file, int line)) callback_locking); s_isSSLInited = true; }
/* Initialize the MPR SSL layer */ PUBLIC int mprSslInit(void *unused, MprModule *module) { RandBuf randBuf; int i; randBuf.now = mprGetTime(); randBuf.pid = getpid(); RAND_seed((void*) &randBuf, sizeof(randBuf)); #if ME_UNIX_LIKE RAND_load_file("/dev/urandom", 256); #endif if ((openProvider = mprAllocObj(MprSocketProvider, manageOpenProvider)) == NULL) { return MPR_ERR_MEMORY; } openProvider->name = sclone("openssl"); openProvider->upgradeSocket = upgradeOss; openProvider->closeSocket = closeOss; openProvider->disconnectSocket = disconnectOss; openProvider->flushSocket = flushOss; openProvider->socketState = getOssState; openProvider->readSocket = readOss; openProvider->writeSocket = writeOss; mprSetSslProvider(openProvider); /* Configure the SSL library. Use the crypto ID as a one-time test. This allows users to configure the library and have their configuration used instead. */ mprGlobalLock(); if (CRYPTO_get_id_callback() == 0) { numLocks = CRYPTO_num_locks(); if ((olocks = mprAlloc(numLocks * sizeof(MprMutex*))) == 0) { return MPR_ERR_MEMORY; } for (i = 0; i < numLocks; i++) { olocks[i] = mprCreateLock(); } CRYPTO_set_id_callback(sslThreadId); CRYPTO_set_locking_callback(sslStaticLock); CRYPTO_set_dynlock_create_callback(sslCreateDynLock); CRYPTO_set_dynlock_destroy_callback(sslDestroyDynLock); CRYPTO_set_dynlock_lock_callback(sslDynLock); #if !ME_WIN_LIKE OpenSSL_add_all_algorithms(); #endif /* WARNING: SSL_library_init() is not reentrant. Caller must ensure safety. */ SSL_library_init(); SSL_load_error_strings(); } mprGlobalUnlock(); return 0; }
static void tlso_thr_init( void ) { int i; for( i=0; i< CRYPTO_NUM_LOCKS ; i++ ) { ldap_pvt_thread_mutex_init( &tlso_mutexes[i] ); } CRYPTO_set_locking_callback( tlso_locking_cb ); CRYPTO_set_id_callback( tlso_thread_self ); }
CryptThreadingInitializer::CryptThreadingInitializer() { #if KODI_OPENSSL_NEEDS_LOCK_CALLBACK // OpenSSL < 1.1 needs integration code to support multi-threading // This is absolutely required for libcurl if it uses the OpenSSL backend m_locks.resize(CRYPTO_num_locks()); CRYPTO_set_id_callback(thread_id); CRYPTO_set_locking_callback(lock_callback); #endif }
// required for SSL support in multiple threads void MultiThreadSetup() { for (int i=0; i < CRYPTO_NUM_LOCKS; ++i) { pthread_mutex_init(&cryptoLocks[i], NULL); } CRYPTO_set_id_callback(ThreadId); CRYPTO_set_locking_callback(LockingCallback); }
void openssl_pthread_setup(void) { int i; int numLocks = CRYPTO_num_locks(); AllocArray(mutexes, numLocks); for (i = 0; i < numLocks; i++) pthread_mutex_init(&mutexes[i], NULL); CRYPTO_set_id_callback(openssl_id_callback); CRYPTO_set_locking_callback(openssl_locking_callback); }
static apr_status_t cleanup_ssl(void *data) { CRYPTO_set_locking_callback(NULL); CRYPTO_set_id_callback(NULL); CRYPTO_set_dynlock_create_callback(NULL); CRYPTO_set_dynlock_lock_callback(NULL); CRYPTO_set_dynlock_destroy_callback(NULL); return APR_SUCCESS; }
isc_result_t dst__openssl_init() { isc_result_t result; #ifdef DNS_CRYPTO_LEAKS CRYPTO_malloc_debug_init(); CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); #endif CRYPTO_set_mem_functions(mem_alloc, mem_realloc, mem_free); nlocks = CRYPTO_num_locks(); locks = mem_alloc(sizeof(isc_mutex_t) * nlocks); if (locks == NULL) return (ISC_R_NOMEMORY); result = isc_mutexblock_init(locks, nlocks); if (result != ISC_R_SUCCESS) goto cleanup_mutexalloc; CRYPTO_set_locking_callback(lock_callback); CRYPTO_set_id_callback(id_callback); rm = mem_alloc(sizeof(RAND_METHOD)); if (rm == NULL) { result = ISC_R_NOMEMORY; goto cleanup_mutexinit; } rm->seed = NULL; rm->bytes = entropy_get; rm->cleanup = NULL; rm->add = entropy_add; rm->pseudorand = entropy_getpseudo; rm->status = entropy_status; #ifdef USE_ENGINE e = ENGINE_new(); if (e == NULL) { result = ISC_R_NOMEMORY; goto cleanup_rm; } ENGINE_set_RAND(e, rm); RAND_set_rand_method(rm); #else RAND_set_rand_method(rm); #endif /* USE_ENGINE */ return (ISC_R_SUCCESS); #ifdef USE_ENGINE cleanup_rm: mem_free(rm); #endif cleanup_mutexinit: CRYPTO_set_locking_callback(NULL); DESTROYMUTEXBLOCK(locks, nlocks); cleanup_mutexalloc: mem_free(locks); return (result); }
void zdb_finalize() { if(!zdb_init_done) { return; } zdb_init_done = FALSE; #if ZDB_DNSSEC_SUPPORT != 0 dnssec_keystore_destroy(); dnssec_keystore_resetpath(); #endif #if ZDB_OPENSSL_SUPPORT!=0 ERR_remove_state(0); /* Init openssl */ CRYPTO_set_locking_callback(NULL); CRYPTO_set_id_callback(NULL); int i; for(i = 0; i < ssl_mutex_count; i++) { pthread_mutex_destroy(&ssl_mutex[i]); } free(ssl_mutex); ENGINE_cleanup(); #endif logger_stop(); #if ZDB_USE_THREADPOOL != 0 /* * The default value for the database. * This initialization will do nothing if it has already been done. * * The server will have to do it before calling zdb_init(); * */ if(thread_pool_initialized_by_zdb) { thread_pool_destroy(); } #endif }
int main(int argc, char * const argv[]) { if (argc != 3) { fprintf(stderr, "Usage: \n"); fprintf(stderr, " %s ciphersuite certificate\n", argv[0]); fprintf(stderr, "\n"); fprintf(stderr, " - `ciphersuite` is the name of cipher suite to use. Use\n"); fprintf(stderr, " `openssl ciphers` to choose one.\n"); fprintf(stderr, "\n"); fprintf(stderr, " - `certificate` is the name of the file containing\n"); fprintf(stderr, " the certificate, the key and appropriate additional parameters.\n"); return 1; } const char *ciphersuite = argv[1]; const char *certificate = argv[2]; start("Initialize OpenSSL library"); SSL_load_error_strings(); SSL_library_init(); if (!(mutex_buf = malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)))) fail("Unable to allocate memory for mutex"); for (int i = 0; i < CRYPTO_num_locks(); i++) pthread_mutex_init(&mutex_buf[i], NULL); CRYPTO_set_id_callback(id_function); CRYPTO_set_locking_callback(locking_function); pthread_t client, server; start("Prepare client and server"); if (socketpair(AF_UNIX, SOCK_STREAM, 0, clientserver)) fail("Unable to get a socket pair for client/server communication:\n%m"); server = start_server(ciphersuite, certificate); client = start_client(ciphersuite); struct result *client_result, *server_result; start("Waiting for client to finish"); if (pthread_join(client, (void **)&client_result)) fail("Unable to join client thread"); start("Waiting for server to finish"); if (pthread_join(server, (void **)&server_result)) fail("Unable to join server thread"); end("Got the following results:\n" "Handshakes from client: %d\n" "User CPU time in client: %4ld.%03ld\n" "Handshakes from server: %d\n" "User CPU time in server: %4ld.%03ld\n" "Ratio: %.2f %%", client_result->handshakes, client_result->cpu.tv_sec, client_result->cpu.tv_nsec / 1000000, server_result->handshakes, server_result->cpu.tv_sec, server_result->cpu.tv_nsec / 1000000, (server_result->cpu.tv_sec * 1000. + server_result->cpu.tv_nsec / 1000000.) * 100. / (client_result->cpu.tv_sec * 1000. + client_result->cpu.tv_nsec / 1000000.)); }
void curl_load_openssl() { uint32_t i, num_locks; num_locks = CRYPTO_num_locks(); if (!(curl_openssl_sem = calloc(num_locks, sizeof(*curl_openssl_sem)))) stderror("calloc"); for (i = 0; i < num_locks; i++) sem_init(&curl_openssl_sem[i], 0, 1); CRYPTO_set_id_callback(openssl_id_function); CRYPTO_set_locking_callback(curl_openssl_locking_function); }
/** * thread_setup * * Set up multi-thread protection used by the SSL library * * Return value: 0 for success, -1 for failure **/ static int thread_setup(void) { /* Register our locking functions with the SSL library */ CRYPTO_set_id_callback(id_function); CRYPTO_set_locking_callback(lock_function); CRYPTO_set_dynlock_create_callback(dyn_create_function); CRYPTO_set_dynlock_lock_callback(dyn_lock_function); CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function); return(0); /* No errors */ }