android / ndk-samples

Android NDK samples with Android Studio
http://developer.android.com/ndk
Apache License 2.0
10.06k stars 4.18k forks source link

How to read Native Library...? #968

Closed Drguderian closed 5 months ago

Drguderian commented 10 months ago

Hello. I want to use a Native Library in Android that performs encryption functionalities. This Native Library for encryption includes its own integrity verification and is built in C language. During the initialization phase, the library reads a binary file using fopen to perform integrity verification. However, I'm facing difficulties as the result of fopen shows an error "No such directory or files" leading to initialization failure.

When I check the path where the Native Library is called, it appears as "/data/app/~~wivrDY7LhQOJtujMW39YYw==/com.testcrypto.jniexample-4wqZNEpMUitO9Vn-jpJrPw==/lib/arm64/libcrypto-aarch64.so". The fopen() function returns NULL, and when I check with strerror(errno), it shows "No such directory and files" error.

The following condition must be met:

"Integrity verification must be performed exclusively within the Native Library."

This is the security policy that must be strictly followed by the encryption library.

In a situation where permissions are required within the Android app, what permissions would be necessary? The targeted platform is expected to be embedded in products running Android 10 or above.

Is there any solution to this issue?

DanAlbert commented 5 months ago

Why are you fopening a library? You want dlopen, or more likely System.loadLibrary. I can't really offer more specific advice with the information given.