/* Initializes SSL and allocate global context SSL_context SYNOPSIS my_ssl_start mysql connection handle RETURN VALUES 0 success 1 error */ int ma_ssl_start(char *errmsg, size_t errmsg_len) { int rc= 1; /* lock mutex to prevent multiple initialization */ pthread_mutex_init(&LOCK_openssl_config,MY_MUTEX_INIT_FAST); pthread_mutex_lock(&LOCK_openssl_config); if (!ma_ssl_initialized) { if (ssl_thread_init()) { strncpy(errmsg, "Not enough memory", errmsg_len); goto end; } SSL_library_init(); #if SSLEAY_VERSION_NUMBER >= 0x00907000L OPENSSL_config(NULL); #endif /* load errors */ SSL_load_error_strings(); /* digests and ciphers */ OpenSSL_add_all_algorithms(); if (!(SSL_context= SSL_CTX_new(TLSv1_client_method()))) { ma_ssl_get_error(errmsg, errmsg_len); goto end; } rc= 0; ma_ssl_initialized= TRUE; } end: pthread_mutex_unlock(&LOCK_openssl_config); return rc; }
/* Initializes SSL and allocate global context SSL_context SYNOPSIS my_ssl_start mysql connection handle RETURN VALUES 0 success 1 error */ int ma_ssl_start(char *errmsg, size_t errmsg_len) { int rc= 1; if (ma_ssl_initialized) return 0; /* lock mutex to prevent multiple initialization */ pthread_mutex_init(&LOCK_openssl_config,MY_MUTEX_INIT_FAST); pthread_mutex_lock(&LOCK_openssl_config); if (ssl_thread_init()) { strncpy(errmsg, "Not enough memory", errmsg_len); goto end; } SSL_library_init(); #if SSLEAY_VERSION_NUMBER >= 0x00907000L OPENSSL_config(NULL); #endif /* load errors */ SSL_load_error_strings(); /* digests and ciphers */ OpenSSL_add_all_algorithms(); #if (OPENSSL_VERSION_NUMBER >= 0x10100000L) if (!(SSL_context= SSL_CTX_new(TLS_client_method()))) #else if (!(SSL_context= SSL_CTX_new(SSLv23_client_method()))) #endif { ma_ssl_get_error(errmsg, errmsg_len); goto end; } #ifdef HAVE_SSL_SESSION_CACHE SSL_CTX_set_session_cache_mode(SSL_context, SSL_SESS_CACHE_CLIENT); ma_ssl_sessions= (MA_SSL_SESSION *)calloc(1, sizeof(struct st_ma_ssl_session) * ma_ssl_session_cache_size); SSL_CTX_sess_set_new_cb(SSL_context, ma_ssl_session_cb); SSL_CTX_sess_set_remove_cb(SSL_context, ma_ssl_remove_session_cb); #endif rc= 0; ma_ssl_initialized= TRUE; end: pthread_mutex_unlock(&LOCK_openssl_config); return rc; }
/* Initializes SSL and allocate global context SSL_context SYNOPSIS my_gnutls_start mysql connection handle RETURN VALUES 0 success 1 error */ int ma_ssl_start(char *errmsg, size_t errmsg_len) { int rc= 0; pthread_mutex_init(&LOCK_gnutls_config,MY_MUTEX_INIT_FAST); pthread_mutex_lock(&LOCK_gnutls_config); if (!ma_ssl_initialized) { if ((rc= gnutls_global_init()) != GNUTLS_E_SUCCESS) { ma_ssl_get_error(errmsg, errmsg_len, rc); goto end; } ma_ssl_initialized= TRUE; } /* Allocate a global context for credentials */ rc= gnutls_certificate_allocate_credentials(&GNUTLS_xcred); end: pthread_mutex_unlock(&LOCK_gnutls_config); return rc; }