GNUTLS: Tidy up rb_init_ssl() and improve its error logging

This commit is contained in:
Aaron Jones 2016-09-16 12:15:38 +00:00
parent 6cc08ecf90
commit 992aa93b80
No known key found for this signature in database
GPG key ID: EC6F86EE9CD840B5

View file

@ -321,24 +321,26 @@ rb_gcry_random_seed(void *unused)
int int
rb_init_ssl(void) rb_init_ssl(void)
{ {
gnutls_global_init(); int ret;
if(gnutls_certificate_allocate_credentials(&server_cert_key) != GNUTLS_E_SUCCESS) if ((ret = gnutls_global_init()) != GNUTLS_E_SUCCESS)
{ {
rb_lib_log("rb_init_ssl: Unable to allocate SSL/TLS certificate credentials"); rb_lib_log("%s: gnutls_global_init: %s", __func__, gnutls_strerror(ret));
return 0;
}
if((ret = gnutls_certificate_allocate_credentials(&server_cert_key)) != GNUTLS_E_SUCCESS)
{
rb_lib_log("%s: gnutls_certificate_allocate_credentials: %s", __func__, gnutls_strerror(ret));
return 0; return 0;
} }
#if GNUTLS_VERSION_MAJOR < 3 #if (GNUTLS_VERSION_MAJOR < 3)
rb_event_addish("rb_gcry_random_seed", rb_gcry_random_seed, NULL, 300);
gnutls_certificate_client_set_retrieve_function(server_cert_key, rb_ssl_cert_auth_cb); gnutls_certificate_client_set_retrieve_function(server_cert_key, rb_ssl_cert_auth_cb);
#else #else
gnutls_certificate_set_retrieve_function(server_cert_key, rb_ssl_cert_auth_cb); gnutls_certificate_set_retrieve_function(server_cert_key, rb_ssl_cert_auth_cb);
#endif #endif
#if (GNUTLS_VERSION_MAJOR < 3)
rb_event_addish("rb_gcry_random_seed", rb_gcry_random_seed, NULL, 300);
#endif
return 1; return 1;
} }