|
@@ -36,13 +36,6 @@
|
|
|
|
|
|
|
|
void *libssl_handle = NULL;
|
|
void *libssl_handle = NULL;
|
|
|
static bd::Array<bd::String> my_symbols;
|
|
static bd::Array<bd::String> my_symbols;
|
|
|
-#ifdef EGG_SSL_EXT
|
|
|
|
|
-SSL_CTX *ssl_ctx = NULL;
|
|
|
|
|
-char *tls_rand_file = NULL;
|
|
|
|
|
-#endif
|
|
|
|
|
-int ssl_use = 0; /* kyotou */
|
|
|
|
|
-
|
|
|
|
|
-static int seed_PRNG(void);
|
|
|
|
|
|
|
|
|
|
static int load_symbols(void *handle) {
|
|
static int load_symbols(void *handle) {
|
|
|
const char *dlsym_error = NULL;
|
|
const char *dlsym_error = NULL;
|
|
@@ -61,12 +54,13 @@ static int load_symbols(void *handle) {
|
|
|
DLSYM_GLOBAL(handle, SSL_shutdown);
|
|
DLSYM_GLOBAL(handle, SSL_shutdown);
|
|
|
DLSYM_GLOBAL(handle, SSLv23_client_method);
|
|
DLSYM_GLOBAL(handle, SSLv23_client_method);
|
|
|
DLSYM_GLOBAL(handle, SSL_write);
|
|
DLSYM_GLOBAL(handle, SSL_write);
|
|
|
|
|
+ DLSYM_GLOBAL(handle, SSL_CTX_ctrl);
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-int load_ssl() {
|
|
|
|
|
|
|
+int load_libssl() {
|
|
|
if (ssl_ctx) {
|
|
if (ssl_ctx) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -90,37 +84,11 @@ int load_ssl() {
|
|
|
|
|
|
|
|
load_symbols(libssl_handle);
|
|
load_symbols(libssl_handle);
|
|
|
|
|
|
|
|
-#ifdef EGG_SSL_EXT
|
|
|
|
|
- /* good place to init ssl stuff */
|
|
|
|
|
- SSL_load_error_strings();
|
|
|
|
|
- OpenSSL_add_ssl_algorithms();
|
|
|
|
|
- ssl_ctx = SSL_CTX_new(SSLv23_client_method());
|
|
|
|
|
- if (!ssl_ctx) {
|
|
|
|
|
- sdprintf("SSL_CTX_new() failed");
|
|
|
|
|
- return 1;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (seed_PRNG()) {
|
|
|
|
|
- sdprintf("Wasn't able to properly seed the PRNG!");
|
|
|
|
|
- return 1;
|
|
|
|
|
- }
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int unload_ssl() {
|
|
|
|
|
|
|
+int unload_libssl() {
|
|
|
if (libssl_handle) {
|
|
if (libssl_handle) {
|
|
|
-#ifdef EGG_SSL_EXT
|
|
|
|
|
- /* cleanup mess when quiting */
|
|
|
|
|
- if (ssl_ctx) {
|
|
|
|
|
- SSL_CTX_free(ssl_ctx);
|
|
|
|
|
- ssl_ctx = NULL;
|
|
|
|
|
- }
|
|
|
|
|
- if (tls_rand_file)
|
|
|
|
|
- RAND_write_file(tls_rand_file);
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
// Cleanup symbol table
|
|
// Cleanup symbol table
|
|
|
for (size_t i = 0; i < my_symbols.length(); ++i) {
|
|
for (size_t i = 0; i < my_symbols.length(); ++i) {
|
|
|
dl_symbol_table.remove(my_symbols[i]);
|
|
dl_symbol_table.remove(my_symbols[i]);
|
|
@@ -134,49 +102,3 @@ int unload_ssl() {
|
|
|
}
|
|
}
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-#ifdef EGG_SSL_EXT
|
|
|
|
|
-static int seed_PRNG(void)
|
|
|
|
|
-{
|
|
|
|
|
- char stackdata[1024];
|
|
|
|
|
- static char rand_file[300];
|
|
|
|
|
- FILE *fh;
|
|
|
|
|
-
|
|
|
|
|
-#if OPENSSL_VERSION_NUMBER >= 0x00905100
|
|
|
|
|
- if (RAND_status())
|
|
|
|
|
- return 0; /* PRNG already good seeded */
|
|
|
|
|
-#endif
|
|
|
|
|
- /* if the device '/dev/urandom' is present, OpenSSL uses it by default.
|
|
|
|
|
- * check if it's present, else we have to make random data ourselfs.
|
|
|
|
|
- */
|
|
|
|
|
- if ((fh = fopen("/dev/urandom", "r"))) {
|
|
|
|
|
- fclose(fh);
|
|
|
|
|
- // Try /dev/random if urandom is unavailable
|
|
|
|
|
- if ((fh = fopen("/dev/random", "r"))) {
|
|
|
|
|
- fclose(fh);
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (RAND_file_name(rand_file, sizeof(rand_file)))
|
|
|
|
|
- tls_rand_file = rand_file;
|
|
|
|
|
- else
|
|
|
|
|
- return 1;
|
|
|
|
|
- if (!RAND_load_file(rand_file, 1024)) {
|
|
|
|
|
- /* no .rnd file found, create new seed */
|
|
|
|
|
- unsigned int c;
|
|
|
|
|
- c = time(NULL);
|
|
|
|
|
- RAND_seed(&c, sizeof(c));
|
|
|
|
|
- c = getpid();
|
|
|
|
|
- RAND_seed(&c, sizeof(c));
|
|
|
|
|
- RAND_seed(stackdata, sizeof(stackdata));
|
|
|
|
|
- }
|
|
|
|
|
-#if OPENSSL_VERSION_NUMBER >= 0x00905100
|
|
|
|
|
- if (!RAND_status())
|
|
|
|
|
- return 2; /* PRNG still badly seeded */
|
|
|
|
|
-#endif
|
|
|
|
|
- return 0;
|
|
|
|
|
-}
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|