|
|
@@ -33,6 +33,7 @@
|
|
|
|
|
|
#include "ssl.h"
|
|
|
|
|
|
+void *libssl_handle = NULL;
|
|
|
#ifdef EGG_SSL_EXT
|
|
|
SSL_CTX *ssl_ctx = NULL;
|
|
|
char *tls_rand_file = NULL;
|
|
|
@@ -41,11 +42,52 @@ int ssl_use = 0; /* kyotou */
|
|
|
|
|
|
static int seed_PRNG(void);
|
|
|
|
|
|
+static int load_symbols(void *handle) {
|
|
|
+ const char *dlsym_error = NULL;
|
|
|
+
|
|
|
+ DLSYM_GLOBAL(handle, SSL_get_error);
|
|
|
+ DLSYM_GLOBAL(handle, SSL_connect);
|
|
|
+ DLSYM_GLOBAL(handle, SSL_CTX_free);
|
|
|
+ DLSYM_GLOBAL(handle, SSL_CTX_new);
|
|
|
+ DLSYM_GLOBAL(handle, SSL_free);
|
|
|
+ DLSYM_GLOBAL(handle, SSL_library_init);
|
|
|
+ DLSYM_GLOBAL(handle, SSL_load_error_strings);
|
|
|
+ DLSYM_GLOBAL(handle, SSL_new);
|
|
|
+ DLSYM_GLOBAL(handle, SSL_pending);
|
|
|
+ DLSYM_GLOBAL(handle, SSL_read);
|
|
|
+ DLSYM_GLOBAL(handle, SSL_set_fd);
|
|
|
+ DLSYM_GLOBAL(handle, SSL_shutdown);
|
|
|
+ DLSYM_GLOBAL(handle, SSLv23_client_method);
|
|
|
+ DLSYM_GLOBAL(handle, SSL_write);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
int load_ssl() {
|
|
|
if (ssl_ctx) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ sdprintf("Loading libssl");
|
|
|
+
|
|
|
+ bd::Array<bd::String> libs_list(bd::String("libssl.so libssl.so.0.9.8 libssl.so.7 libssl.so.6").split(' '));
|
|
|
+
|
|
|
+ for (size_t i = 0; i < libs_list.length(); ++i) {
|
|
|
+ dlerror(); // Clear Errors
|
|
|
+ libssl_handle = dlopen(bd::String(libs_list[i]).c_str(), RTLD_LAZY);
|
|
|
+ if (libssl_handle) {
|
|
|
+ sdprintf("Found libssl: %s", bd::String(libs_list[i]).c_str());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!libssl_handle) {
|
|
|
+ sdprintf("Unable to find libssl");
|
|
|
+ return(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ load_symbols(libssl_handle);
|
|
|
+
|
|
|
#ifdef EGG_SSL_EXT
|
|
|
/* good place to init ssl stuff */
|
|
|
SSL_load_error_strings();
|
|
|
@@ -61,7 +103,7 @@ int load_ssl() {
|
|
|
}
|
|
|
|
|
|
int unload_ssl() {
|
|
|
- if (ssl_ctx) {
|
|
|
+ if (libssl_handle) {
|
|
|
#ifdef EGG_SSL_EXT
|
|
|
/* cleanup mess when quiting */
|
|
|
if (ssl_ctx) {
|
|
|
@@ -71,6 +113,9 @@ int unload_ssl() {
|
|
|
if (tls_rand_file)
|
|
|
RAND_write_file(tls_rand_file);
|
|
|
#endif
|
|
|
+
|
|
|
+ dlclose(libssl_handle);
|
|
|
+ libssl_handle = NULL;
|
|
|
return 0;
|
|
|
}
|
|
|
return 1;
|