Added option to disable SSL verify
This commit is contained in:
parent
bcaea8a417
commit
5bc52bf9df
@ -49,6 +49,7 @@ object AppIcons {
|
|||||||
const val REMOVE_DONE = "remove_done.svg"
|
const val REMOVE_DONE = "remove_done.svg"
|
||||||
const val REVERT = "revert.svg"
|
const val REVERT = "revert.svg"
|
||||||
const val SEARCH = "search.svg"
|
const val SEARCH = "search.svg"
|
||||||
|
const val SECURITY = "security.svg"
|
||||||
const val SETTINGS = "settings.svg"
|
const val SETTINGS = "settings.svg"
|
||||||
const val SIGN = "sign.svg"
|
const val SIGN = "sign.svg"
|
||||||
const val SOURCE = "source.svg"
|
const val SOURCE = "source.svg"
|
||||||
|
@ -2,13 +2,18 @@ package com.jetpackduba.gitnuro.credentials
|
|||||||
|
|
||||||
import com.jetpackduba.gitnuro.exceptions.NotSupportedHelper
|
import com.jetpackduba.gitnuro.exceptions.NotSupportedHelper
|
||||||
import com.jetpackduba.gitnuro.git.remote_operations.CredentialsCache
|
import com.jetpackduba.gitnuro.git.remote_operations.CredentialsCache
|
||||||
|
import com.jetpackduba.gitnuro.logging.printLog
|
||||||
import com.jetpackduba.gitnuro.managers.IShellManager
|
import com.jetpackduba.gitnuro.managers.IShellManager
|
||||||
import com.jetpackduba.gitnuro.preferences.AppSettings
|
import com.jetpackduba.gitnuro.preferences.AppSettings
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
|
import org.eclipse.jgit.internal.JGitText
|
||||||
import org.eclipse.jgit.lib.Config
|
import org.eclipse.jgit.lib.Config
|
||||||
import org.eclipse.jgit.transport.CredentialItem
|
import org.eclipse.jgit.transport.CredentialItem
|
||||||
|
import org.eclipse.jgit.transport.CredentialItem.Password
|
||||||
|
import org.eclipse.jgit.transport.CredentialItem.Username
|
||||||
|
import org.eclipse.jgit.transport.CredentialItem.YesNoType
|
||||||
import org.eclipse.jgit.transport.CredentialsProvider
|
import org.eclipse.jgit.transport.CredentialsProvider
|
||||||
import org.eclipse.jgit.transport.URIish
|
import org.eclipse.jgit.transport.URIish
|
||||||
import java.io.*
|
import java.io.*
|
||||||
@ -16,6 +21,7 @@ import java.util.concurrent.TimeUnit
|
|||||||
import kotlin.coroutines.cancellation.CancellationException
|
import kotlin.coroutines.cancellation.CancellationException
|
||||||
|
|
||||||
private const val TIMEOUT_MIN = 1L
|
private const val TIMEOUT_MIN = 1L
|
||||||
|
private const val TAG = "HttpCredentialsProvider"
|
||||||
|
|
||||||
class HttpCredentialsProvider @AssistedInject constructor(
|
class HttpCredentialsProvider @AssistedInject constructor(
|
||||||
private val credentialsStateManager: CredentialsStateManager,
|
private val credentialsStateManager: CredentialsStateManager,
|
||||||
@ -33,22 +39,42 @@ class HttpCredentialsProvider @AssistedInject constructor(
|
|||||||
|
|
||||||
override fun supports(vararg items: CredentialItem?): Boolean {
|
override fun supports(vararg items: CredentialItem?): Boolean {
|
||||||
val fields = items.map { credentialItem -> credentialItem?.promptText }
|
val fields = items.map { credentialItem -> credentialItem?.promptText }
|
||||||
return if (fields.isEmpty()) {
|
val isEmpty = fields.isEmpty()
|
||||||
true
|
|
||||||
} else
|
val isUserPasswordAuth = fields.size == 2 &&
|
||||||
fields.size == 2 &&
|
|
||||||
fields.contains("Username") &&
|
fields.contains("Username") &&
|
||||||
fields.contains("Password")
|
fields.contains("Password")
|
||||||
|
|
||||||
|
val isAskingForSslDisable = items.any { it is YesNoType }
|
||||||
|
|
||||||
|
return isEmpty || isUserPasswordAuth || isAskingForSslDisable
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun get(uri: URIish, vararg items: CredentialItem): Boolean {
|
override fun get(uri: URIish, vararg items: CredentialItem): Boolean {
|
||||||
val userItem = items.firstOrNull { it.promptText == "Username" }
|
val itemsMap = items.map { "${it::class.simpleName} - ${it.promptText}" }
|
||||||
val passwordItem = items.firstOrNull { it.promptText == "Password" }
|
|
||||||
|
|
||||||
if (userItem !is CredentialItem.Username || passwordItem !is CredentialItem.Password) {
|
printLog(TAG, "Items are $itemsMap")
|
||||||
|
|
||||||
|
val sslTrustNowItem = items
|
||||||
|
.filterIsInstance<YesNoType>()
|
||||||
|
.firstOrNull { it.promptText.contains(JGitText.get().sslTrustNow) }
|
||||||
|
|
||||||
|
val userItem = items
|
||||||
|
.filterIsInstance<Username>()
|
||||||
|
.firstOrNull()
|
||||||
|
|
||||||
|
val passwordItem = items
|
||||||
|
.filterIsInstance<Password>()
|
||||||
|
.firstOrNull()
|
||||||
|
|
||||||
|
if (userItem == null || passwordItem == null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sslTrustNowItem != null) {
|
||||||
|
sslTrustNowItem.value = appSettings.verifySsl
|
||||||
|
}
|
||||||
|
|
||||||
val externalCredentialsHelper = getExternalCredentialsHelper(uri, git)
|
val externalCredentialsHelper = getExternalCredentialsHelper(uri, git)
|
||||||
|
|
||||||
if (externalCredentialsHelper == null) {
|
if (externalCredentialsHelper == null) {
|
||||||
|
@ -45,10 +45,13 @@ private const val PREF_GIT_FF_MERGE = "gitFFMerge"
|
|||||||
private const val PREF_GIT_PULL_REBASE = "gitPullRebase"
|
private const val PREF_GIT_PULL_REBASE = "gitPullRebase"
|
||||||
private const val PREF_GIT_PUSH_WITH_LEASE = "gitPushWithLease"
|
private const val PREF_GIT_PUSH_WITH_LEASE = "gitPushWithLease"
|
||||||
|
|
||||||
|
private const val PREF_VERIFY_SSL = "verifySsl"
|
||||||
|
|
||||||
private const val DEFAULT_COMMITS_LIMIT = 1000
|
private const val DEFAULT_COMMITS_LIMIT = 1000
|
||||||
private const val DEFAULT_COMMITS_LIMIT_ENABLED = true
|
private const val DEFAULT_COMMITS_LIMIT_ENABLED = true
|
||||||
private const val DEFAULT_SWAP_UNCOMMITTED_CHANGES = false
|
private const val DEFAULT_SWAP_UNCOMMITTED_CHANGES = false
|
||||||
private const val DEFAULT_CACHE_CREDENTIALS_IN_MEMORY = true
|
private const val DEFAULT_CACHE_CREDENTIALS_IN_MEMORY = true
|
||||||
|
private const val DEFAULT_VERIFY_SSL = true
|
||||||
const val DEFAULT_UI_SCALE = -1f
|
const val DEFAULT_UI_SCALE = -1f
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@ -67,6 +70,9 @@ class AppSettings @Inject constructor() {
|
|||||||
private val _cacheCredentialsInMemoryFlow = MutableStateFlow(cacheCredentialsInMemory)
|
private val _cacheCredentialsInMemoryFlow = MutableStateFlow(cacheCredentialsInMemory)
|
||||||
val cacheCredentialsInMemoryFlow = _cacheCredentialsInMemoryFlow.asStateFlow()
|
val cacheCredentialsInMemoryFlow = _cacheCredentialsInMemoryFlow.asStateFlow()
|
||||||
|
|
||||||
|
private val _verifySslFlow = MutableStateFlow(cacheCredentialsInMemory)
|
||||||
|
val verifySslFlow = _cacheCredentialsInMemoryFlow.asStateFlow()
|
||||||
|
|
||||||
private val _ffMergeFlow = MutableStateFlow(ffMerge)
|
private val _ffMergeFlow = MutableStateFlow(ffMerge)
|
||||||
val ffMergeFlow = _ffMergeFlow.asStateFlow()
|
val ffMergeFlow = _ffMergeFlow.asStateFlow()
|
||||||
|
|
||||||
@ -168,6 +174,15 @@ class AppSettings @Inject constructor() {
|
|||||||
_cacheCredentialsInMemoryFlow.value = value
|
_cacheCredentialsInMemoryFlow.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var verifySsl: Boolean
|
||||||
|
get() {
|
||||||
|
return preferences.getBoolean(PREF_VERIFY_SSL, DEFAULT_VERIFY_SSL)
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
preferences.putBoolean(PREF_VERIFY_SSL, value)
|
||||||
|
_verifySslFlow.value = value
|
||||||
|
}
|
||||||
|
|
||||||
var scaleUi: Float
|
var scaleUi: Float
|
||||||
get() {
|
get() {
|
||||||
return preferences.getFloat(PREF_UI_SCALE, DEFAULT_UI_SCALE)
|
return preferences.getFloat(PREF_UI_SCALE, DEFAULT_UI_SCALE)
|
||||||
|
@ -49,6 +49,7 @@ val settings = listOf(
|
|||||||
SettingsEntry.Section("Network"),
|
SettingsEntry.Section("Network"),
|
||||||
SettingsEntry.Entry(AppIcons.NETWORK, "Proxy") { Proxy(it) },
|
SettingsEntry.Entry(AppIcons.NETWORK, "Proxy") { Proxy(it) },
|
||||||
SettingsEntry.Entry(AppIcons.PASSWORD, "Authentication") { Authentication(it) },
|
SettingsEntry.Entry(AppIcons.PASSWORD, "Authentication") { Authentication(it) },
|
||||||
|
SettingsEntry.Entry(AppIcons.SECURITY, "Security") { Security(it) },
|
||||||
|
|
||||||
SettingsEntry.Section("Tools"),
|
SettingsEntry.Section("Tools"),
|
||||||
SettingsEntry.Entry(AppIcons.TERMINAL, "Terminal") { Terminal(it) },
|
SettingsEntry.Entry(AppIcons.TERMINAL, "Terminal") { Terminal(it) },
|
||||||
@ -355,6 +356,20 @@ private fun Authentication(settingsViewModel: SettingsViewModel) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun Security(settingsViewModel: SettingsViewModel) {
|
||||||
|
val verifySsl by settingsViewModel.verifySslFlow.collectAsState()
|
||||||
|
|
||||||
|
SettingToggle(
|
||||||
|
title = "Do not verify SSL security",
|
||||||
|
subtitle = "If active, you may connect to the remote server via insecure HTTPS connection",
|
||||||
|
value = !verifySsl,
|
||||||
|
onValueChanged = { value ->
|
||||||
|
settingsViewModel.verifySsl = !value
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Terminal(settingsViewModel: SettingsViewModel) {
|
fun Terminal(settingsViewModel: SettingsViewModel) {
|
||||||
var commitsLimit by remember { mutableStateOf(settingsViewModel.terminalPath) }
|
var commitsLimit by remember { mutableStateOf(settingsViewModel.terminalPath) }
|
||||||
|
@ -29,6 +29,7 @@ class SettingsViewModel @Inject constructor(
|
|||||||
val commitsLimitEnabledFlow = appSettings.commitsLimitEnabledFlow
|
val commitsLimitEnabledFlow = appSettings.commitsLimitEnabledFlow
|
||||||
val swapUncommittedChangesFlow = appSettings.swapUncommittedChangesFlow
|
val swapUncommittedChangesFlow = appSettings.swapUncommittedChangesFlow
|
||||||
val cacheCredentialsInMemoryFlow = appSettings.cacheCredentialsInMemoryFlow
|
val cacheCredentialsInMemoryFlow = appSettings.cacheCredentialsInMemoryFlow
|
||||||
|
val verifySslFlow = appSettings.verifySslFlow
|
||||||
val terminalPathFlow = appSettings.terminalPathFlow
|
val terminalPathFlow = appSettings.terminalPathFlow
|
||||||
|
|
||||||
var scaleUi: Float
|
var scaleUi: Float
|
||||||
@ -61,6 +62,12 @@ class SettingsViewModel @Inject constructor(
|
|||||||
appSettings.cacheCredentialsInMemory = value
|
appSettings.cacheCredentialsInMemory = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var verifySsl: Boolean
|
||||||
|
get() = appSettings.verifySsl
|
||||||
|
set(value) {
|
||||||
|
appSettings.verifySsl = value
|
||||||
|
}
|
||||||
|
|
||||||
var pullRebase: Boolean
|
var pullRebase: Boolean
|
||||||
get() = appSettings.pullRebase
|
get() = appSettings.pullRebase
|
||||||
set(value) {
|
set(value) {
|
||||||
|
1
src/main/resources/security.svg
Normal file
1
src/main/resources/security.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M480-80q-139-35-229.5-159.5T160-516v-244l320-120 320 120v244q0 152-90.5 276.5T480-80Zm0-84q97-30 162-118.5T718-480H480v-315l-240 90v207q0 7 2 18h238v316Z"/></svg>
|
After Width: | Height: | Size: 259 B |
Loading…
Reference in New Issue
Block a user