From c514a7f6cced45dd5660b28d576c13a70c029e00 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Thu, 22 Dec 2016 23:45:45 -0800 Subject: [PATCH] Do not remove the CRYPTO_library_init call --- common/src/jni/main/cpp/org_conscrypt_NativeCrypto.cpp | 10 ++++++++++ common/src/main/java/org/conscrypt/NativeCrypto.java | 3 +++ 2 files changed, 13 insertions(+) diff --git a/common/src/jni/main/cpp/org_conscrypt_NativeCrypto.cpp b/common/src/jni/main/cpp/org_conscrypt_NativeCrypto.cpp index a945fe124..5f375a603 100644 --- a/common/src/jni/main/cpp/org_conscrypt_NativeCrypto.cpp +++ b/common/src/jni/main/cpp/org_conscrypt_NativeCrypto.cpp @@ -1667,6 +1667,15 @@ static bool setBlocking(int fd, bool blocking) { #define THROW_SOCKETTIMEOUTEXCEPTION (-3) #define THROWN_EXCEPTION (-4) +/** + * Initialization phase for every OpenSSL job: Loads the Error strings, the + * crypto algorithms and reset the OpenSSL library + */ +static void NativeCrypto_clinit(JNIEnv*, jclass) +{ + CRYPTO_library_init(); +} + /** * private static native int EVP_PKEY_new_RSA(byte[] n, byte[] e, byte[] d, byte[] p, byte[] q); */ @@ -9922,6 +9931,7 @@ static int NativeCrypto_ENGINE_SSL_write_heap(JNIEnv* env, jclass, jlong sslRef, #define REF_HMAC_CTX "L" TO_STRING(JNI_JARJAR_PREFIX) "org/conscrypt/NativeRef$HMAC_CTX;" #define REF_BIO_IN_STREAM "L" TO_STRING(JNI_JARJAR_PREFIX) "org/conscrypt/OpenSSLBIOInputStream;" static JNINativeMethod sNativeCryptoMethods[] = { + NATIVE_METHOD(NativeCrypto, clinit, "()V"), NATIVE_METHOD(NativeCrypto, EVP_PKEY_new_RSA, "([B[B[B[B[B[B[B[B)J"), NATIVE_METHOD(NativeCrypto, EVP_PKEY_new_EC_KEY, "(" REF_EC_GROUP REF_EC_POINT "[B)J"), NATIVE_METHOD(NativeCrypto, EVP_PKEY_type, "(" REF_EVP_PKEY ")I"), diff --git a/common/src/main/java/org/conscrypt/NativeCrypto.java b/common/src/main/java/org/conscrypt/NativeCrypto.java index c02d064e5..ef4fb97b4 100644 --- a/common/src/main/java/org/conscrypt/NativeCrypto.java +++ b/common/src/main/java/org/conscrypt/NativeCrypto.java @@ -52,8 +52,11 @@ public final class NativeCrypto { // --- OpenSSL library initialization -------------------------------------- static { NativeCryptoJni.init(); + clinit(); } + private native static void clinit(); + // --- DSA/RSA public/private key handling functions ----------------------- public static native long EVP_PKEY_new_DSA(byte[] p, byte[] q, byte[] g,