本文整理汇总了C++中CRYPTO_set_id_callback函数的典型用法代码示例。如果您正苦于以下问题:C++ CRYPTO_set_id_callback函数的具体用法?C++ CRYPTO_set_id_callback怎么用?C++ CRYPTO_set_id_callback使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CRYPTO_set_id_callback函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ff_tls_init
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();
}
示例2: CRYPTO_thread_setup
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);
}
示例3: lock
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);
}
}
示例4: server_initialize_ssl
/*
* 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;
}
示例5: server_destroy_ssl
/*
* 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;
}
示例6: ssl_fini
/*
* 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();
}
示例7: SetupOpenSSLThreadLocks
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);
}
示例8: main
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;
}
示例9: pthread_mutex_lock
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);
}
示例10: tls_init_multithread
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;
}
示例11: ssl_util_thread_setup
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);
}
示例12: CRYPTO_malloc_debug_init
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();
};
示例13: setup_ssl_mutexes
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;
}
示例14: _ossSSLTheadInit
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;
}
示例15: SSL_library_init
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;
}