android - Qt for Android 和 BoringSSL

标签 android qt ssl openssl boringssl

我正在为 Android 开发一个基于 Qt 的应用程序,它使用 QSslSocket 下载数据。由于依赖于 OpenSSL 库的 Marshmallow Qt 程序在 Android 6+ 上产生以下警告,因此 Android 从 OpenSSL 转向 BoringSSL:

W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve CRYPTO_free
W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve EVP_CipherFinal
W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve EVP_rc2_cbc
W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve SSLv2_client_method
W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve SSLv2_server_method
W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve OPENSSL_add_all_algorithms_noconf
W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve OPENSSL_add_all_algorithms_conf
W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve EC_get_builtin_curves
W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot call unresolved function OPENSSL_add_all_algorithms_conf
W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot call unresolved function EC_get_builtin_curves
W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot call unresolved function EC_get_builtin_curves
W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: could not set SSL_CTRL_SET_TLSEXT_HOSTNAME, Server Name Indication disabled
W libtestopenssl.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot call unresolved function CRYPTO_free

但是,套接字本身成功连接到远程主机并从那里读取数据,没有任何可见问题。这让我想知道我是否需要自己构建 OpenSSL 库并打包它,或者使用平台提供的 BoringSSL 就可以了。

我还注意到,Android 6 以下版本的应用程序倾向于使用系统版本的 OpenSSL,即使我提供了自己的版本。我尝试使用 ANDROID_EXTRA_LIBS 添加内置的 libssl.so 和 libcrypto.so(从 libssl.so.1.0.0 和 libcrypto.so.1.0.0 重命名)(不确定 LIBS+= 也需要使用)甚至静态链接 libssl.a 和 libcrypto.a。 QSslSocket::sslLibraryVersionString() 仍然返回平台上可用的版本。

我的问题是:

  1. 我需要自己构建OpenSSL库并打包还是使用平台提供的库就可以了?
  2. 如果我这样做,如何让 Android 识别 libssl.so 和 libcrypto.so?

最佳答案

<强>1。是需要自己搭建OpenSSL库并打包还是直接使用平台提供的库就可以了?

  • 是的——您应该构建 OpenSSL 并将其打包。

https://developer.android.com/about/versions/nougat/android-7.0-changes.html

Starting in Android 7.0, the system prevents apps from dynamically linking against non-NDK libraries, which may cause your app to crash. This change in behavior aims to create a consistent app experience across platform updates and different devices.

  • 使用已安装的 BoringSSL 目前可能可行,但建议应用自带 OpenSSL 库。
  • 否则您的用户会看到一条警告消息弹出,并且该应用可能无法在更高版本的 Android 上运行。

In order to reduce the impact that this restriction may have on currently released apps, a set of libraries that see significant use—such as libandroid_runtime.so, libcutils.so, libcrypto.so, and libssl.so—are temporarily accessible on Android 7.0 (API level 24) for apps targeting API level 23 or lower. If your app loads one of these libraries, logcat generates a warning and a toast appears on the target device to notify you. If you see these warnings, you should update your app to either include its own copy of those libraries or only use the public NDK APIs. Future releases of the Android platform may restrict the use of private libraries altogether and cause your app to crash.

<强>2。如果我这样做,如何让 Android 识别 libssl.so 和 libcrypto.so?

  • 我主要是按照此处列出的步骤成功的: http://doc.qt.io/qt-5/opensslsupport.html

  • 但请确保您获得了正确的版本:openssl-1.1.0f.tar.gz 似乎与 Qt 5.9 不兼容并且我的应用程序没有加载库。

  • 为桌面编译并调用 QSslSocket::sslLibraryVersionString() 以查看您的 Qt 使用的 OpenSSL 版本。对我来说,它显示“OpenSSL 1.0.1t 2016 年 5 月 3 日”
  • 在 git 仓库中标记“OpenSSL_1_0_1t”对我来说适用于 Qt 5.9.1
  • 来自 openssl.org 的 openssl-1.0.2l.tar.gz 也适用于 Qt 5.9.1

我使用的是 API 级别 19。在我使用 API 级别 23 或 25 进行测试后,我将更新此答案。

关于android - Qt for Android 和 BoringSSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42442688/

相关文章:

android - 即使在 Android 中使用 @hide 注解后,API 也不会被隐藏

android - 在 Kotlin 中使用正则表达式获取字符串中模式的索引

android - 在android中安装应用程序期间创建文件夹

qt - QWidget如何检测鼠标停止移动

.net - 为特定页面禁用 ssl

ssl - 续订 SSL 根 CA 证书 - 野外的客户端程序需要更新吗?

java - 无法在对象上找到参数 [目录 'libs'] 的方法实现()

qt - QSettings-ini文件的位置在哪里?

ruby-on-rails - Rails 4 SSL 错误停止使用回形针直接上传 s3

c++ - Qt - 设置界面