我正在 Flutter 中构建 Android 应用程序,并且 Fortify 代码扫描报告了警告:该应用程序不使用 Google Play 服务更新的安全提供程序,这可能使其容易受到 OpenSSL 库中未来漏洞的攻击。
对于原生 Android 应用程序,我可以按照此处的指南进行操作,但如何修复 Flutter 应用程序中的警告?
在您的 MainActivity 中,使用 Google 此代码段中的代码
private const val ERROR_DIALOG_REQUEST_CODE = 1
/**
* Sample activity using {@link ProviderInstaller}.
*/
class MainActivity : Activity(), ProviderInstaller.ProviderInstallListener {
private var retryProviderInstall: Boolean = false
//Update the security provider when the activity is created.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ProviderInstaller.installIfNeededAsync(this, this)
}
/**
* This method is only called if the provider is successfully updated
* (or is already up-to-date).
*/
override fun onProviderInstalled() {
// Provider is up-to-date, app can make secure network calls.
}
/**
* This method is called if updating fails; the error code indicates
* whether the error is recoverable.
*/
override fun onProviderInstallFailed(errorCode: Int, recoveryIntent: Intent) {
GoogleApiAvailability.getInstance().apply {
if (isUserResolvableError(errorCode)) {
// Recoverable error. Show a dialog prompting the user to
// install/update/enable Google Play services.
showErrorDialogFragment(this@MainActivity, errorCode, ERROR_DIALOG_REQUEST_CODE) {
// The user chose not to take the recovery action
onProviderInstallerNotAvailable()
}
} else {
onProviderInstallerNotAvailable()
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int,
data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == ERROR_DIALOG_REQUEST_CODE) {
// Adding a fragment via GoogleApiAvailability.showErrorDialogFragment
// before the instance state is restored throws an error. So instead,
// set a flag here, which will cause the fragment to delay until
// onPostResume.
retryProviderInstall = true
}
}
/**
* On resume, check to see if we flagged that we need to reinstall the
* provider.
*/
override fun onPostResume() {
super.onPostResume()
if (retryProviderInstall) {
// We can now safely retry installation.
ProviderInstaller.installIfNeededAsync(this, this)
}
retryProviderInstall = false
}
private fun onProviderInstallerNotAvailable() {
// This is reached if the provider cannot be updated for some reason.
// App should consider all HTTP communication to be vulnerable, and take
// appropriate action.
}
}