delete TrustManager
This commit is contained in:
parent
eb3a283645
commit
fc4f7e60cd
|
|
@ -1,6 +0,0 @@
|
|||
import org.gradle.api.artifacts.MinimalExternalModuleDependency
|
||||
import org.gradle.api.artifacts.VersionCatalog
|
||||
import org.gradle.api.provider.Provider
|
||||
|
||||
private fun VersionCatalog.getLibrary(library: String) = findLibrary(library).get()
|
||||
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
import org.gradle.api.artifacts.VersionCatalog
|
||||
|
||||
val VersionCatalog.sdkCompile: String
|
||||
get() = findVersion("compileSdk").get().requiredVersion
|
||||
|
||||
val VersionCatalog.sdkMin: String
|
||||
get() = findVersion("minSdk").get().requiredVersion
|
||||
|
||||
val VersionCatalog.sdkTarget: String
|
||||
get() = findVersion("targetSdk").get().requiredVersion
|
||||
|
||||
val VersionCatalog.jvmBytecode: String
|
||||
get() = findVersion("jvmBytecode").get().requiredVersion
|
||||
|
||||
val VersionCatalog.versionCode: String
|
||||
get() = findVersion("versionCode").get().requiredVersion
|
||||
|
||||
val VersionCatalog.versionName: String
|
||||
get() = findVersion("versionName").get().requiredVersion
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit d6f303bf879a2da1706cfdacaf2bbe0c326044bd
|
||||
Subproject commit 8f595d1a472afe437a56b8ce70ec6ac8e375c3ed
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
package ru.template.data.network
|
||||
|
||||
import ru.template.data.network.sslpinning.ServerInfo
|
||||
import ru.template.data.network.sslpinning.UrlInfo
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
package com.redmadrobot.data.network.sslpinning
|
||||
|
||||
import java.security.cert.CertificateException
|
||||
import java.security.cert.X509Certificate
|
||||
import javax.net.ssl.X509TrustManager
|
||||
|
||||
object TrustManagerUnsafe: X509TrustManager {
|
||||
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkClientTrusted(chain: Array<X509Certificate?>?, authType: String?) = Unit
|
||||
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkServerTrusted(chain: Array<X509Certificate?>?, authType: String?) = Unit
|
||||
|
||||
override fun getAcceptedIssuers() = emptyArray<X509Certificate>()
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
package com.redmadrobot.data.network.sslpinning
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import com.redmadrobot.data.network.NetworkConfig
|
||||
import com.redmadrobot.domain.extension.toHex
|
||||
import com.redmadrobot.domain.repository.ssl.SslPublicKeyRepository
|
||||
import java.security.MessageDigest
|
||||
import java.security.cert.CertificateException
|
||||
import java.security.cert.X509Certificate
|
||||
import java.util.Locale
|
||||
import javax.net.ssl.X509TrustManager
|
||||
|
||||
@SuppressLint("CustomX509TrustManager")
|
||||
class TrustManagerWithoutTls(
|
||||
private val networkConfig: NetworkConfig,
|
||||
private val sslPublicKeyRepository: SslPublicKeyRepository
|
||||
) : X509TrustManager {
|
||||
|
||||
@SuppressLint("TrustAllX509TrustManager")
|
||||
override fun checkClientTrusted(chain: Array<X509Certificate?>?, authType: String?) = Unit
|
||||
|
||||
override fun checkServerTrusted(chain: Array<X509Certificate?>?, authType: String?) {
|
||||
if (networkConfig.isSslPinningEnabled()) {
|
||||
chain?.let { checkCertificateFingerprint(it) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAcceptedIssuers(): Array<X509Certificate> = emptyArray()
|
||||
|
||||
private fun checkCertificateFingerprint(chain: Array<X509Certificate?>) {
|
||||
val pinFromServer = chain[0]?.let { getSha256FingerprintFormatted(it) }
|
||||
networkConfig.getCurrentServer().getPins().also {
|
||||
if (it.contains(pinFromServer)) {
|
||||
sslPublicKeyRepository.setPublicKey(isValid = true)
|
||||
return
|
||||
}
|
||||
}
|
||||
sslPublicKeyRepository.setPublicKey(isValid = false)
|
||||
throw CertificateException("Cannot validate server certificate")
|
||||
}
|
||||
|
||||
private fun getSha256FingerprintFormatted(certificate: X509Certificate): String {
|
||||
return MessageDigest
|
||||
.getInstance("SHA-256")
|
||||
.digest(certificate.encoded)
|
||||
.toHex(separator = ":").toUpperCase(Locale.getDefault())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ javapoet = "1.13.0"
|
|||
googleServices = "4.4.1"
|
||||
googleLicenses = "17.0.1"
|
||||
googleLicensesPlugin = "0.10.6"
|
||||
firebaseBom = "32.7.4"
|
||||
firebaseBom = "32.8.1"
|
||||
firebaseCrashlytics = "2.9.9"
|
||||
firebasePerf = "1.4.2"
|
||||
|
||||
|
|
@ -155,10 +155,6 @@ junit = { group = "junit", name = "junit", version.ref = "junit" }
|
|||
androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" }
|
||||
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" }
|
||||
|
||||
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||
androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" }
|
||||
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" }
|
||||
|
||||
[plugins]
|
||||
|
||||
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
|
||||
|
|
|
|||
Loading…
Reference in New Issue