From 67a7438ccb6f5de13073fe4cb01e92c1360deec9 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Wed, 6 Oct 2021 18:16:55 +0200 Subject: Allow legacy algorithm in the OpenSSL Speed test --- main/src/main/cpp/openssl | 2 +- main/src/main/cpp/ovpnutil/sslspeed.c | 43 +++++++++++++++------- .../de/blinkt/openvpn/activities/OpenSSLSpeed.kt | 2 - 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/main/src/main/cpp/openssl b/main/src/main/cpp/openssl index c1525c16..ea3df226 160000 --- a/main/src/main/cpp/openssl +++ b/main/src/main/cpp/openssl @@ -1 +1 @@ -Subproject commit c1525c164ee2e3f400c8063bcc6591db8db4e704 +Subproject commit ea3df2261df94424c6b66d0efccf00a1e46e36a2 diff --git a/main/src/main/cpp/ovpnutil/sslspeed.c b/main/src/main/cpp/ovpnutil/sslspeed.c index 1881998e..be253c6f 100644 --- a/main/src/main/cpp/ovpnutil/sslspeed.c +++ b/main/src/main/cpp/ovpnutil/sslspeed.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,7 @@ #include #include #include +#include /* This file just contains code thrown together until it works */ @@ -102,8 +104,6 @@ static volatile int run = 0; #define TM_START 0 #define TM_STOP 1 -# include - static int usertime = 1; double app_tminterval(int stop, int usertime) @@ -208,6 +208,25 @@ static void* stop_run(void* arg) jdoubleArray Java_de_blinkt_openvpn_core_NativeUtils_getOpenSSLSpeed(JNIEnv* env, jclass thiz, jstring algorithm, jint testnumber) { + + OSSL_PROVIDER *legacy; + OSSL_PROVIDER *deflt; + + OSSL_LIB_CTX *lib_ctx = OSSL_LIB_CTX_new(); + + /* Load Multiple providers into the default (NULL) library context */ + legacy = OSSL_PROVIDER_load(lib_ctx, "legacy"); + if (legacy == NULL) { + __android_log_write(ANDROID_LOG_DEBUG,"openvpn", "Failed to load Legacy provider\n"); + return NULL; + } + deflt = OSSL_PROVIDER_load(lib_ctx, "default"); + if (deflt == NULL) { + __android_log_write(ANDROID_LOG_DEBUG,"openvpn", "Failed to load Default provider\n"); + OSSL_PROVIDER_unload(legacy); + return NULL; + } + static const unsigned char key16[16] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 @@ -216,18 +235,16 @@ jdoubleArray Java_de_blinkt_openvpn_core_NativeUtils_getOpenSSLSpeed(JNIEnv* env const char* alg = (*env)->GetStringUTFChars( env, algorithm , NULL ) ; - evp_cipher = EVP_get_cipherbyname(alg); + evp_cipher = EVP_CIPHER_fetch(lib_ctx, alg, NULL); if (evp_cipher == NULL) - evp_md = EVP_get_digestbyname(alg); + evp_md = EVP_MD_fetch(lib_ctx, alg, NULL); if (evp_cipher == NULL && evp_md == NULL) { // BIO_printf(bio_err, "%s: %s is an unknown cipher or digest\n", prog, opt_arg()); //jniThrowException(env, "java/security/NoSuchAlgorithmException", "Algorithm not found"); + __android_log_write(ANDROID_LOG_DEBUG,"openvpn", "Algorithm not found"); return NULL; } - - const char* name; - loopargs_t *loopargs = NULL; int loopargs_len = 1; int async_jobs=0; @@ -254,9 +271,8 @@ jdoubleArray Java_de_blinkt_openvpn_core_NativeUtils_getOpenSSLSpeed(JNIEnv* env int count; - float d; + double d; if (evp_cipher) { - name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)); /* * -O3 -fschedule-insns messes up an optimization here! * names[D_EVP] somehow becomes NULL @@ -285,12 +301,12 @@ jdoubleArray Java_de_blinkt_openvpn_core_NativeUtils_getOpenSSLSpeed(JNIEnv* env } } if (evp_md) { - name = OBJ_nid2ln(EVP_MD_type(evp_md)); - // print_message(names[D_EVP], save_count, lengths[testnum]); - pthread_t timer_thread; if (pthread_create(&timer_thread, NULL, stop_run, NULL)) + { + __android_log_write(ANDROID_LOG_DEBUG,"openvpn", "creating thread failed"); goto error; + } Time_F(START); count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs); @@ -304,12 +320,13 @@ jdoubleArray Java_de_blinkt_openvpn_core_NativeUtils_getOpenSSLSpeed(JNIEnv* env (*env)->SetDoubleArrayRegion(env, ret, 0, 3, results); // print_result(D_EVP, testnum, count, d); - + OSSL_LIB_CTX_free(lib_ctx); return ret; error: free(loopargs); for (int k = 0; k < loopargs_len; k++) { EVP_CIPHER_CTX_free(loopargs[k].ctx); } + OSSL_LIB_CTX_free(lib_ctx); return NULL; } diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.kt b/main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.kt index 429d5aa4..d54cbc35 100644 --- a/main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.kt +++ b/main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.kt @@ -119,8 +119,6 @@ class OpenSSLSpeed : BaseActivity() { private inner class SpeeedTest : AsyncTask>() { - - private var mCancel = false override fun doInBackground(vararg strings: String): Array { -- cgit v1.2.3