0

I am using prebuilt openssl in my project.after loading app is crashing and giving this error

java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "libcrypto.so.1.0.0" needed by "libPrivateSsl.so"; caused by library "libcrypto.so.1.0.0" not found

my android.mk looks like this

LOCAL_PATH := $(call my-dir)

# Prebuilt libssl
include $(CLEAR_VARS)
LOCAL_MODULE := ssl
LOCAL_SRC_FILES := precompiled/libPrivateSsl.so
include $(PREBUILT_SHARED_LIBRARY)

# Prebuilt libcrypto
include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := precompiled/libPrivateCrypto.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := myLibrary
TARGET_PLATFORM := android-3
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_C_INCLUDES = $(LOCAL_PATH)/include
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := ssl crypto


include $(BUILD_SHARED_LIBRARY)

loading library in activity like this

static {
    System.loadLibrary("PrivateSsl");
    System.loadLibrary("PrivateCrypto");
    System.loadLibrary("myLibrary");

}

i am using Kit-kat for testing with Ubuntu System. please help me to solve this error.

Gaju Kollur
  • 2,046
  • 5
  • 23
  • 47
  • Maybe add the directory containing libcrypto.so.1.0.0 to your LD_LIBRARY_PATH environment variable. – john Jan 30 '18 at 07:00
  • @john I don't have libcrypto.so.1.0.0 i am having libcrypto.so ..but why and how to set LD_LIBRARY_PATH? – Gaju Kollur Jan 30 '18 at 07:06
  • If you don't have libcrypto.so.1.0.0 then I would say that is your problem. But I can't tell exactly what you are trying to do. Nor do I understand all the details of building for android. – john Jan 30 '18 at 07:08
  • Probably you need to describe all the steps you've taken to get to this point. Maybe you made some mistake earlier in the process. – john Jan 30 '18 at 07:21
  • @john i downloaded prebuilt openssl from git. there i got libcrypto.so, libssl.so and include folder which contains some c files. i am using these files in my project directly.as suggested by Alex cohn sir – Gaju Kollur Jan 30 '18 at 07:27
  • downloaded it from where? – john Jan 30 '18 at 07:40
  • Try reversing the load order `static { System.loadLibrary("PrivateCrypto"); System.loadLibrary("PrivateSsl"); System.loadLibrary("myLibrary"); }`. Just a hunch. – john Jan 30 '18 at 07:50
  • @john No still the same error.. – Gaju Kollur Jan 30 '18 at 08:42

2 Answers2

2

You downloaded some wrong version of OpenSSL for Android, which was not built correctly (similar to this one. Android does not support versioning in SONAMEs.

You can find a better prebuilt version of OpenSSL, but this is not recommended. For these libraries to be entrusted with your secret communications, you should better make sure that you yourself build it from a trusted (official) source, and it does not leak your private information to some rogue third party.

As a minimal fix, you can try to use the patchelf utility to fix the SONAME in your library.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • 1
    Not trusting your encryption to some arbitrary openssl prebuilt you found online can no be stated strongly enough. – Dan Albert May 14 '18 at 21:29
1

i solved this issue by making some little changes in android.mk file

i removed .so files and placed .a files.

my android.mk looks like this now

  LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := ssl_static
LOCAL_SRC_FILES := precompiled/libssl.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := crypto_static
LOCAL_SRC_FILES :=precompiled/libcrypto.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := myLibrary

LOCAL_SRC_FILES := native-lib.cpp
LOCAL_C_INCLUDES = $(LOCAL_PATH)/include
LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := ssl_static crypto_static
include $(BUILD_SHARED_LIBRARY)

got this idea from here

link

Gaju Kollur
  • 2,046
  • 5
  • 23
  • 47
  • 3
    Static libs are definitely safer than shared, but still you put your app at risk by using libraries prebuilt by untrusted third party. – Alex Cohn Jan 30 '18 at 10:02