From 38f2879d82bf3b56507d199ec3c03ec74f227d74 Mon Sep 17 00:00:00 2001 From: tarsin Date: Tue, 14 Feb 2023 11:39:04 +0800 Subject: [PATCH] Minor code cleanup --- .../java/com/hippo/ehviewer/EhApplication.kt | 24 +++--------- .../ehviewer/client/EhX509TrustManager.kt | 37 ------------------- 2 files changed, 5 insertions(+), 56 deletions(-) delete mode 100644 app/src/main/java/com/hippo/ehviewer/client/EhX509TrustManager.kt diff --git a/app/src/main/java/com/hippo/ehviewer/EhApplication.kt b/app/src/main/java/com/hippo/ehviewer/EhApplication.kt index c0be0d7b7..04886d407 100644 --- a/app/src/main/java/com/hippo/ehviewer/EhApplication.kt +++ b/app/src/main/java/com/hippo/ehviewer/EhApplication.kt @@ -41,7 +41,6 @@ import com.hippo.ehviewer.client.EhRequestBuilder import com.hippo.ehviewer.client.EhSSLSocketFactory import com.hippo.ehviewer.client.EhTagDatabase import com.hippo.ehviewer.client.EhUrl -import com.hippo.ehviewer.client.EhX509TrustManager import com.hippo.ehviewer.client.data.GalleryDetail import com.hippo.ehviewer.client.parser.EventPaneParser import com.hippo.ehviewer.dao.buildMainDB @@ -61,7 +60,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import okhttp3.OkHttpClient import java.net.Proxy import java.security.KeyStore -import java.util.Arrays import javax.net.ssl.TrustManagerFactory import javax.net.ssl.X509TrustManager @@ -281,24 +279,12 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor .proxySelector(ehProxySelector) if (Settings.getDF()) { - var trustManager: X509TrustManager - try { - val trustManagerFactory = TrustManagerFactory.getInstance( - TrustManagerFactory.getDefaultAlgorithm() - ) - trustManagerFactory.init(null as KeyStore?) - val trustManagers = trustManagerFactory.trustManagers - check(!(trustManagers.size != 1 || trustManagers[0] !is X509TrustManager)) { - "Unexpected default trust managers:" + Arrays.toString( - trustManagers - ) - } - trustManager = trustManagers[0] as X509TrustManager - } catch (e: Exception) { - e.printStackTrace() - trustManager = EhX509TrustManager - } + val factory = + TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())!! + factory.init(null as KeyStore?) + val manager = factory.trustManagers!! + val trustManager = manager.filterIsInstance().first() builder.sslSocketFactory(EhSSLSocketFactory, trustManager) builder.proxy(Proxy.NO_PROXY) } diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhX509TrustManager.kt b/app/src/main/java/com/hippo/ehviewer/client/EhX509TrustManager.kt deleted file mode 100644 index 6522b5bc7..000000000 --- a/app/src/main/java/com/hippo/ehviewer/client/EhX509TrustManager.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2022 Tarsin Norbin - * - * This file is part of EhViewer - * - * EhViewer is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * EhViewer is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with EhViewer. - * If not, see . - */ -package com.hippo.ehviewer.client - -import android.annotation.SuppressLint -import java.security.cert.X509Certificate -import javax.net.ssl.X509TrustManager - -@SuppressLint("CustomX509TrustManager") -object EhX509TrustManager : X509TrustManager { - @SuppressLint("TrustAllX509TrustManager") - override fun checkClientTrusted(chain: Array, authType: String) { - } - - @SuppressLint("TrustAllX509TrustManager") - override fun checkServerTrusted(chain: Array, authType: String) { - } - - override fun getAcceptedIssuers(): Array { - return arrayOfNulls(0) - } -}