Add a login switch to disable SSL verification
Some checks failed
continuous-integration/drone/pr Build is failing
Some checks failed
continuous-integration/drone/pr Build is failing
This commit is contained in:
parent
313042955c
commit
b793301706
@ -139,6 +139,8 @@ class LoginActivity : AppCompatActivity(), DIAware {
|
|||||||
|
|
||||||
showProgress(true)
|
showProgress(true)
|
||||||
|
|
||||||
|
appSettingsService.updateSelfSigned(binding.selfSigned.isChecked)
|
||||||
|
|
||||||
repository.refreshLoginInformation(url, login, password)
|
repository.refreshLoginInformation(url, login, password)
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
@ -2,15 +2,18 @@ package bou.amine.apps.readerforselfossv2.rest
|
|||||||
|
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
import io.github.aakira.napier.Napier
|
import io.github.aakira.napier.Napier
|
||||||
import io.ktor.client.*
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.engine.okhttp.*
|
import io.ktor.client.engine.okhttp.OkHttp
|
||||||
import io.ktor.client.plugins.*
|
import io.ktor.client.plugins.HttpRequestRetry
|
||||||
import io.ktor.client.plugins.cache.*
|
import io.ktor.client.plugins.HttpTimeout
|
||||||
import io.ktor.client.plugins.contentnegotiation.*
|
import io.ktor.client.plugins.cache.HttpCache
|
||||||
import io.ktor.client.plugins.cookies.*
|
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||||
import io.ktor.client.plugins.logging.*
|
import io.ktor.client.plugins.cookies.HttpCookies
|
||||||
import io.ktor.http.*
|
import io.ktor.client.plugins.logging.LogLevel
|
||||||
import io.ktor.serialization.kotlinx.json.*
|
import io.ktor.client.plugins.logging.Logger
|
||||||
|
import io.ktor.client.plugins.logging.Logging
|
||||||
|
import io.ktor.http.HttpStatusCode
|
||||||
|
import io.ktor.serialization.kotlinx.json.json
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -29,8 +32,12 @@ class NaiveTrustManager : X509TrustManager {
|
|||||||
override fun getAcceptedIssuers(): Array<out X509Certificate> = arrayOf()
|
override fun getAcceptedIssuers(): Array<out X509Certificate> = arrayOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun createHttpClient(appSettingsService: AppSettingsService, api: SelfossApi) =
|
actual fun createHttpClient(
|
||||||
|
appSettingsService: AppSettingsService,
|
||||||
|
api: SelfossApi
|
||||||
|
) =
|
||||||
HttpClient(OkHttp) {
|
HttpClient(OkHttp) {
|
||||||
|
if (appSettingsService.getSelfSigned()) {
|
||||||
engine {
|
engine {
|
||||||
val trustManager = NaiveTrustManager()
|
val trustManager = NaiveTrustManager()
|
||||||
val sslContext = SSLContext.getInstance("TLS").apply {
|
val sslContext = SSLContext.getInstance("TLS").apply {
|
||||||
@ -44,6 +51,7 @@ actual fun createHttpClient(appSettingsService: AppSettingsService, api: Selfoss
|
|||||||
.hostnameVerifier(AllowAllHostnameVerifier())
|
.hostnameVerifier(AllowAllHostnameVerifier())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
install(HttpCache)
|
install(HttpCache)
|
||||||
json(Json {
|
json(Json {
|
||||||
|
@ -4,12 +4,22 @@ import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
|||||||
import bou.amine.apps.readerforselfossv2.model.StatusAndData
|
import bou.amine.apps.readerforselfossv2.model.StatusAndData
|
||||||
import bou.amine.apps.readerforselfossv2.model.SuccessResponse
|
import bou.amine.apps.readerforselfossv2.model.SuccessResponse
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
import io.ktor.client.*
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.plugins.auth.providers.BasicAuthCredentials
|
||||||
import io.ktor.client.statement.*
|
import io.ktor.client.request.get
|
||||||
import io.ktor.http.*
|
import io.ktor.client.request.headers
|
||||||
|
import io.ktor.client.request.parameter
|
||||||
|
import io.ktor.client.statement.HttpResponse
|
||||||
|
import io.ktor.http.HttpHeaders
|
||||||
|
import io.ktor.http.Parameters
|
||||||
|
import io.ktor.util.encodeBase64
|
||||||
|
import io.ktor.utils.io.charsets.Charsets
|
||||||
|
import io.ktor.utils.io.core.toByteArray
|
||||||
|
|
||||||
expect fun createHttpClient(appSettingsService: AppSettingsService, api: SelfossApi): HttpClient
|
expect fun createHttpClient(
|
||||||
|
appSettingsService: AppSettingsService,
|
||||||
|
api: SelfossApi
|
||||||
|
): HttpClient
|
||||||
|
|
||||||
class SelfossApi(private val appSettingsService: AppSettingsService) {
|
class SelfossApi(private val appSettingsService: AppSettingsService) {
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ class AppSettingsService(acraSenderServiceProcess: Boolean = false) {
|
|||||||
// Api related
|
// Api related
|
||||||
private var _apiVersion: Int = -1
|
private var _apiVersion: Int = -1
|
||||||
private var _publicAccess: Boolean? = null
|
private var _publicAccess: Boolean? = null
|
||||||
|
private var _selfSigned: Boolean? = null
|
||||||
private var _baseUrl: String = ""
|
private var _baseUrl: String = ""
|
||||||
private var _userName: String = ""
|
private var _userName: String = ""
|
||||||
private var _basicUserName: String = ""
|
private var _basicUserName: String = ""
|
||||||
@ -77,6 +78,22 @@ class AppSettingsService(acraSenderServiceProcess: Boolean = false) {
|
|||||||
_publicAccess = settings.getBoolean(API_PUBLIC_ACCESS, false)
|
_publicAccess = settings.getBoolean(API_PUBLIC_ACCESS, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getSelfSigned(): Boolean {
|
||||||
|
if (_selfSigned == null) {
|
||||||
|
refreshSelfSigned()
|
||||||
|
}
|
||||||
|
return _selfSigned!!
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateSelfSigned(selfSigned: Boolean) {
|
||||||
|
settings.putBoolean(API_SELF_SIGNED, selfSigned)
|
||||||
|
refreshSelfSigned()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun refreshSelfSigned() {
|
||||||
|
_selfSigned = settings.getBoolean(API_SELF_SIGNED, false)
|
||||||
|
}
|
||||||
|
|
||||||
fun getBaseUrl(): String {
|
fun getBaseUrl(): String {
|
||||||
if (_baseUrl.isEmpty()) {
|
if (_baseUrl.isEmpty()) {
|
||||||
refreshBaseUrl()
|
refreshBaseUrl()
|
||||||
@ -383,6 +400,7 @@ class AppSettingsService(acraSenderServiceProcess: Boolean = false) {
|
|||||||
refreshBaseUrl()
|
refreshBaseUrl()
|
||||||
refreshApiVersion()
|
refreshApiVersion()
|
||||||
refreshPublicAccess()
|
refreshPublicAccess()
|
||||||
|
refreshSelfSigned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun refreshUserSettings() {
|
fun refreshUserSettings() {
|
||||||
@ -468,6 +486,8 @@ class AppSettingsService(acraSenderServiceProcess: Boolean = false) {
|
|||||||
|
|
||||||
const val API_PUBLIC_ACCESS = "apiPublicAccess"
|
const val API_PUBLIC_ACCESS = "apiPublicAccess"
|
||||||
|
|
||||||
|
const val API_SELF_SIGNED = "apiSelfSigned"
|
||||||
|
|
||||||
const val API_ITEMS_NUMBER = "prefer_api_items_number"
|
const val API_ITEMS_NUMBER = "prefer_api_items_number"
|
||||||
|
|
||||||
const val API_TIMEOUT = "api_timeout"
|
const val API_TIMEOUT = "api_timeout"
|
||||||
|
Loading…
Reference in New Issue
Block a user