Android 中的 OpenSSL 现有库
OpenSSL existing library in Android
我正在构建 AOSP,所以可以说我拥有 Android 中所有模块的根目录。当然有 OpenSSL 库可以在其他模块中构建和重用。
并且我们有基础应用程序(系统、外部等),它们也与本机代码通信。 我的问题是:如何在本地项目中包含现有的 Android OpenSSL 库,以便使用它?
换句话说,我如何在本机代码中获取 OpenSSL/BoringSSL 的活动实例。 另外,如何获取 Android Keystore engine 的实例并使用它?
谢谢!
来自release notes of Android 6.0:
If you’re using the Android NDK in your app, don't link against cryptographic libraries that are not a part of the NDK API, such as libcrypto.so and libssl.so. These libraries are not public APIs, and may change or break without notice across releases and devices. In addition, you may expose yourself to security vulnerabilities. Instead, modify your native code to call the Java cryptography APIs via JNI or to statically link against a cryptography library of your choice.
在您的本机代码中,除了 C/native API 之外,您还可以访问 Java API。因此,您可以编写调用常规 Java API 的 C 代码来访问 AndroidKeyStore。您只需将 Java 代码翻译成 C 代码。这样访问Java API有点复杂,但这是最安全的方式(关于兼容性)。
另见
- Calling a java method from c++ in Android
- Android NDK: Calling Java functions from C++
我正在构建 AOSP,所以可以说我拥有 Android 中所有模块的根目录。当然有 OpenSSL 库可以在其他模块中构建和重用。
并且我们有基础应用程序(系统、外部等),它们也与本机代码通信。 我的问题是:如何在本地项目中包含现有的 Android OpenSSL 库,以便使用它?
换句话说,我如何在本机代码中获取 OpenSSL/BoringSSL 的活动实例。 另外,如何获取 Android Keystore engine 的实例并使用它?
谢谢!
来自release notes of Android 6.0:
If you’re using the Android NDK in your app, don't link against cryptographic libraries that are not a part of the NDK API, such as libcrypto.so and libssl.so. These libraries are not public APIs, and may change or break without notice across releases and devices. In addition, you may expose yourself to security vulnerabilities. Instead, modify your native code to call the Java cryptography APIs via JNI or to statically link against a cryptography library of your choice.
在您的本机代码中,除了 C/native API 之外,您还可以访问 Java API。因此,您可以编写调用常规 Java API 的 C 代码来访问 AndroidKeyStore。您只需将 Java 代码翻译成 C 代码。这样访问Java API有点复杂,但这是最安全的方式(关于兼容性)。
另见
- Calling a java method from c++ in Android
- Android NDK: Calling Java functions from C++