开发者

Identify Calling Application in Android NDK

I have a native android library (.so) I am bundling with some application. In the native code I want to verify the signer/package name of the calling application.

The reason is, currently anyone can open up the .apk file take my .so 开发者_如何学编程file and use it to built their own applications.

Is there a way to securely identify the calling application from Java side? This could be package name, signature or anything else that can identify the Android application in a unique way.


JNI code is coupled with Java package name, and can be called only from the same package and class. To improve security further, you can check some Java private static final field from the JNI code.


In the native code I want to verify the signer/package name of the calling application.

how about this?

#include <jni.h>
#include <string>

extern "C"
JNIEXPORT jstring JNICALL
Java_com_x_y_TestActivity_stringFromJNI(JNIEnv *env, jobject thiz)
{ 
    jclass jActivity_class = env->GetObjectClass(thiz);
    jmethodID jMethod_id_pn = env->GetMethodID(jActivity_class,"getPackageName","()Ljava/lang/String;");
    jstring package_name = (jstring) env->CallObjectMethod(thiz,jMethod_id_pn);
    return package_name;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜