Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Your app is using an unsafe implementation of WebViewClient.onReceivedSslError handler #1

Open
Aminul-Haque-Aome opened this issue Jun 23, 2020 · 0 comments

Comments

@Aminul-Haque-Aome
Copy link

You need to update WebViewClient interface to handle SSLError.
Otherwise, you will get Alert from google play store after publishing the app. You can try this bunch of code to handle

bkashWebView.webViewClient = object : WebViewClient() {

            override fun onReceivedSslError(view: WebView?, handler: SslErrorHandler, error: SslError?) {
                val builder = AlertDialog.Builder(context!!)

                val message = when (error?.primaryError) {
                    SSL_UNTRUSTED -> "The certificate authority is not trusted."
                    SSL_EXPIRED -> "The certificate has expired."
                    SSL_IDMISMATCH -> "The certificate Hostname mismatch."
                    SSL_NOTYETVALID -> "The certificate is not yet valid."
                    SSL_DATE_INVALID -> "The date of the certificate is invalid"
                    else -> "A generic error occurred"
                }

                builder.setTitle("SSL Certificate Error")
                builder.setMessage(message)

                builder.setPositiveButton("Continue") { _,_ -> handler.proceed() }
                builder.setNegativeButton("Cancel") { _,_ -> handler.cancel() }

                val dialog = builder.create()
                dialog.show()
            }

            override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
                loadingProgressBar.visibility = View.VISIBLE
                if (url == "https://www.bkash.com/terms-and-conditions") {
                    startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
                    return true
                }
                return false
            }

            override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
                loadingProgressBar.visibility = View.VISIBLE
            }

            override fun onPageFinished(view: WebView?, url: String?) {
                bkashWebView.let {
                    it.loadUrl("javascript:callReconfigure($paymentRequest )")
                    it.loadUrl("javascript:clickPayButton()")
                }
                loadingProgressBar.visibility = View.GONE
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant