azhon / AppUpdate

Android App update library. Android版本更新库,简单、轻量、可随意定制
Apache License 2.0
2.23k stars 326 forks source link

appupdate:4.2.3 SSLPeerUnverifiedException #165

Closed Flyer-Flair closed 2 months ago

Flyer-Flair commented 2 months ago

appupdate:4.2.3

download error: javax.net.ssl.SSLPeerUnverifiedException: Hostname xxxxxx not verified:
certificate: sha1/67uxxxxxxxxxxx
DN: CN=.xxx.com,O=xxxx公司,L=Wuxi,ST=Jiangsu,C=CN
subjectAltNames: [
.xxx.com, xxx.com]
Hostname not verified:
certificate: sha1/67xxxxxxxxxxxxx
DN: CN=.hikwuxi.com,O=xxxxxxxx公司,L=Wuxi,ST=Jiangsu,C=CN
subjectAltNames: [
.xxxx.com, xxx.com]
How to resolve? Please!

azhon commented 2 months ago

I think you should use custom BaseHttpDownloadManager See more detail

Flyer-Flair commented 2 months ago

I think you should use custom BaseHttpDownloadManager See more detail

I find this class. The mothed of this class is following:

abstract class BaseHttpDownloadManager {
    abstract fun download(apkUrl: String, apkName: String): Flow<DownloadStatus>
    abstract fun cancel()
    abstract fun release()
}

But,I do not know how this class can solve the SSL problem. And, why the following code not work?

private fun trustAllHosts() {
        val manager: TrustManager = object : X509TrustManager {
            override fun getAcceptedIssuers(): Array<X509Certificate> {
                return arrayOf()
            }

            override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) {
                LogUtil.d(TAG, "checkClientTrusted")
            }

            override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) {
                LogUtil.d(TAG, "checkServerTrusted")
            }
        }
        try {
            val sslContext = SSLContext.getInstance("TLS")
            sslContext.init(null, arrayOf(manager), SecureRandom())
            HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.socketFactory)
        } catch (e: Exception) {
            LogUtil.e(TAG, "trustAllHosts error: $e")
        }
    }
azhon commented 2 months ago

I think you should use custom BaseHttpDownloadManager See more detail

I find this class. The mothed of this class is following:

abstract class BaseHttpDownloadManager {
    abstract fun download(apkUrl: String, apkName: String): Flow<DownloadStatus>
    abstract fun cancel()
    abstract fun release()
}

But,I do not know how this class can solve the SSL problem. And, why the following code not work?

private fun trustAllHosts() {
        val manager: TrustManager = object : X509TrustManager {
            override fun getAcceptedIssuers(): Array<X509Certificate> {
                return arrayOf()
            }

            override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) {
                LogUtil.d(TAG, "checkClientTrusted")
            }

            override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) {
                LogUtil.d(TAG, "checkServerTrusted")
            }
        }
        try {
            val sslContext = SSLContext.getInstance("TLS")
            sslContext.init(null, arrayOf(manager), SecureRandom())
            HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.socketFactory)
        } catch (e: Exception) {
            LogUtil.e(TAG, "trustAllHosts error: $e")
        }
    }

Through BaseHttpDownloadManager you can download by yourself, such as using OkHttp and solve the problems encountered