|
@@ -1,5 +1,6 @@
|
|
package io.nexilis.service.core
|
|
package io.nexilis.service.core
|
|
|
|
|
|
|
|
+import android.annotation.SuppressLint
|
|
import android.content.Context
|
|
import android.content.Context
|
|
import android.net.Uri
|
|
import android.net.Uri
|
|
import android.os.Build
|
|
import android.os.Build
|
|
@@ -31,7 +32,6 @@ import java.io.File
|
|
import java.io.IOException
|
|
import java.io.IOException
|
|
import java.security.SecureRandom
|
|
import java.security.SecureRandom
|
|
import java.security.cert.X509Certificate
|
|
import java.security.cert.X509Certificate
|
|
-import javax.net.ssl.HostnameVerifier
|
|
|
|
import javax.net.ssl.SSLContext
|
|
import javax.net.ssl.SSLContext
|
|
import javax.net.ssl.SSLSession
|
|
import javax.net.ssl.SSLSession
|
|
import javax.net.ssl.SSLSocketFactory
|
|
import javax.net.ssl.SSLSocketFactory
|
|
@@ -43,11 +43,14 @@ import javax.security.cert.CertificateException
|
|
fun getUnsafeOkHttpClient(): OkHttpClient {
|
|
fun getUnsafeOkHttpClient(): OkHttpClient {
|
|
return try {
|
|
return try {
|
|
val trustAllCerts = arrayOf<TrustManager>(
|
|
val trustAllCerts = arrayOf<TrustManager>(
|
|
|
|
+ @SuppressLint("CustomX509TrustManager")
|
|
object : X509TrustManager {
|
|
object : X509TrustManager {
|
|
|
|
+ @SuppressLint("TrustAllX509TrustManager")
|
|
@Throws(CertificateException::class)
|
|
@Throws(CertificateException::class)
|
|
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
|
|
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @SuppressLint("TrustAllX509TrustManager")
|
|
@Throws(CertificateException::class)
|
|
@Throws(CertificateException::class)
|
|
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
|
|
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
|
|
}
|
|
}
|
|
@@ -63,7 +66,7 @@ fun getUnsafeOkHttpClient(): OkHttpClient {
|
|
val builder = OkHttpClient.Builder()
|
|
val builder = OkHttpClient.Builder()
|
|
builder.followRedirects(false)
|
|
builder.followRedirects(false)
|
|
builder.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
|
|
builder.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
|
|
- builder.hostnameVerifier(HostnameVerifier { hostname: String?, session: SSLSession? -> true })
|
|
|
|
|
|
+ builder.hostnameVerifier { _: String?, _: SSLSession? -> true }
|
|
builder.build()
|
|
builder.build()
|
|
} catch (e: Exception) {
|
|
} catch (e: Exception) {
|
|
throw RuntimeException(e)
|
|
throw RuntimeException(e)
|
|
@@ -176,11 +179,14 @@ class Network {
|
|
onProgress: ((Long, Long) -> Unit) = { _, _ -> }
|
|
onProgress: ((Long, Long) -> Unit) = { _, _ -> }
|
|
): Uri? {
|
|
): Uri? {
|
|
val trustAllCerts = arrayOf<TrustManager>(
|
|
val trustAllCerts = arrayOf<TrustManager>(
|
|
|
|
+ @SuppressLint("CustomX509TrustManager")
|
|
object : X509TrustManager {
|
|
object : X509TrustManager {
|
|
|
|
+ @SuppressLint("TrustAllX509TrustManager")
|
|
@Throws(CertificateException::class)
|
|
@Throws(CertificateException::class)
|
|
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
|
|
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @SuppressLint("TrustAllX509TrustManager")
|
|
@Throws(CertificateException::class)
|
|
@Throws(CertificateException::class)
|
|
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
|
|
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
|
|
}
|
|
}
|
|
@@ -195,7 +201,7 @@ class Network {
|
|
val sslSocketFactory: SSLSocketFactory = sslContext.socketFactory
|
|
val sslSocketFactory: SSLSocketFactory = sslContext.socketFactory
|
|
val client = OkHttpClient.Builder()
|
|
val client = OkHttpClient.Builder()
|
|
.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
|
|
.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
|
|
- .hostnameVerifier(HostnameVerifier { hostname: String?, session: SSLSession? -> true })
|
|
|
|
|
|
+ .hostnameVerifier { _: String?, _: SSLSession? -> true }
|
|
.addNetworkInterceptor {
|
|
.addNetworkInterceptor {
|
|
val originalResponse = it.proceed(it.request())
|
|
val originalResponse = it.proceed(it.request())
|
|
val interceptor = originalResponse.newBuilder()
|
|
val interceptor = originalResponse.newBuilder()
|