mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-31 06:15:48 +00:00
Rename ConnectionMode to AuthMode and remove clone_ prefix (#1053)
This commit is contained in:
@@ -8,7 +8,7 @@ package com.zeapo.pwdstore
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import com.zeapo.pwdstore.git.config.ConnectionMode
|
import com.zeapo.pwdstore.git.config.AuthMode
|
||||||
import com.zeapo.pwdstore.git.config.Protocol
|
import com.zeapo.pwdstore.git.config.Protocol
|
||||||
import com.zeapo.pwdstore.utils.PreferenceKeys
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.getString
|
import com.zeapo.pwdstore.utils.getString
|
||||||
@@ -36,7 +36,7 @@ class MigrationsTest {
|
|||||||
putString(PreferenceKeys.GIT_REMOTE_LOCATION, "/mnt/disk3/pass-repo")
|
putString(PreferenceKeys.GIT_REMOTE_LOCATION, "/mnt/disk3/pass-repo")
|
||||||
putString(PreferenceKeys.GIT_REMOTE_SERVER, "192.168.0.102")
|
putString(PreferenceKeys.GIT_REMOTE_SERVER, "192.168.0.102")
|
||||||
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Ssh.pref)
|
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Ssh.pref)
|
||||||
putString(PreferenceKeys.GIT_REMOTE_AUTH, ConnectionMode.Password.pref)
|
putString(PreferenceKeys.GIT_REMOTE_AUTH, AuthMode.Password.pref)
|
||||||
}
|
}
|
||||||
runMigrations(context)
|
runMigrations(context)
|
||||||
checkOldKeysAreRemoved(context)
|
checkOldKeysAreRemoved(context)
|
||||||
@@ -55,7 +55,7 @@ class MigrationsTest {
|
|||||||
putString(PreferenceKeys.GIT_REMOTE_LOCATION, "/mnt/disk3/pass-repo")
|
putString(PreferenceKeys.GIT_REMOTE_LOCATION, "/mnt/disk3/pass-repo")
|
||||||
putString(PreferenceKeys.GIT_REMOTE_SERVER, "192.168.0.102")
|
putString(PreferenceKeys.GIT_REMOTE_SERVER, "192.168.0.102")
|
||||||
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Ssh.pref)
|
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Ssh.pref)
|
||||||
putString(PreferenceKeys.GIT_REMOTE_AUTH, ConnectionMode.SshKey.pref)
|
putString(PreferenceKeys.GIT_REMOTE_AUTH, AuthMode.SshKey.pref)
|
||||||
}
|
}
|
||||||
runMigrations(context)
|
runMigrations(context)
|
||||||
checkOldKeysAreRemoved(context)
|
checkOldKeysAreRemoved(context)
|
||||||
@@ -74,7 +74,7 @@ class MigrationsTest {
|
|||||||
putString(PreferenceKeys.GIT_REMOTE_LOCATION, "Android-Password-Store/pass-test")
|
putString(PreferenceKeys.GIT_REMOTE_LOCATION, "Android-Password-Store/pass-test")
|
||||||
putString(PreferenceKeys.GIT_REMOTE_SERVER, "github.com")
|
putString(PreferenceKeys.GIT_REMOTE_SERVER, "github.com")
|
||||||
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Https.pref)
|
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Https.pref)
|
||||||
putString(PreferenceKeys.GIT_REMOTE_AUTH, ConnectionMode.None.pref)
|
putString(PreferenceKeys.GIT_REMOTE_AUTH, AuthMode.None.pref)
|
||||||
}
|
}
|
||||||
runMigrations(context)
|
runMigrations(context)
|
||||||
checkOldKeysAreRemoved(context)
|
checkOldKeysAreRemoved(context)
|
||||||
|
@@ -78,7 +78,7 @@ private fun migrateToGitUrlBasedConfig(context: Context) {
|
|||||||
}
|
}
|
||||||
if (url == null || GitSettings.updateConnectionSettingsIfValid(
|
if (url == null || GitSettings.updateConnectionSettingsIfValid(
|
||||||
newProtocol = protocol,
|
newProtocol = protocol,
|
||||||
newConnectionMode = GitSettings.connectionMode,
|
newAuthMode = GitSettings.authMode,
|
||||||
newUrl = url,
|
newUrl = url,
|
||||||
newBranch = GitSettings.branch) != GitSettings.UpdateConnectionSettingsResult.Valid) {
|
newBranch = GitSettings.branch) != GitSettings.UpdateConnectionSettingsResult.Valid) {
|
||||||
e { "Failed to migrate to URL-based Git config, generated URL is invalid" }
|
e { "Failed to migrate to URL-based Git config, generated URL is invalid" }
|
||||||
|
@@ -26,7 +26,7 @@ import com.zeapo.pwdstore.databinding.PasswordRecyclerViewBinding
|
|||||||
import com.zeapo.pwdstore.git.BaseGitActivity
|
import com.zeapo.pwdstore.git.BaseGitActivity
|
||||||
import com.zeapo.pwdstore.git.GitOperationActivity
|
import com.zeapo.pwdstore.git.GitOperationActivity
|
||||||
import com.zeapo.pwdstore.git.GitServerConfigActivity
|
import com.zeapo.pwdstore.git.GitServerConfigActivity
|
||||||
import com.zeapo.pwdstore.git.config.ConnectionMode
|
import com.zeapo.pwdstore.git.config.AuthMode
|
||||||
import com.zeapo.pwdstore.git.config.GitSettings
|
import com.zeapo.pwdstore.git.config.GitSettings
|
||||||
import com.zeapo.pwdstore.ui.OnOffItemAnimator
|
import com.zeapo.pwdstore.ui.OnOffItemAnimator
|
||||||
import com.zeapo.pwdstore.ui.adapters.PasswordItemRecyclerAdapter
|
import com.zeapo.pwdstore.ui.adapters.PasswordItemRecyclerAdapter
|
||||||
@@ -93,10 +93,10 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) {
|
|||||||
.show()
|
.show()
|
||||||
binding.swipeRefresher.isRefreshing = false
|
binding.swipeRefresher.isRefreshing = false
|
||||||
} else {
|
} else {
|
||||||
// When authentication is set to ConnectionMode.None then the only git operation we
|
// When authentication is set to AuthMode.None then the only git operation we can
|
||||||
// can run is a pull, so automatically fallback to that.
|
// run is a pull, so automatically fallback to that.
|
||||||
val operationId = when (GitSettings.connectionMode) {
|
val operationId = when (GitSettings.authMode) {
|
||||||
ConnectionMode.None -> BaseGitActivity.REQUEST_PULL
|
AuthMode.None -> BaseGitActivity.REQUEST_PULL
|
||||||
else -> BaseGitActivity.REQUEST_SYNC
|
else -> BaseGitActivity.REQUEST_SYNC
|
||||||
}
|
}
|
||||||
val intent = Intent(context, GitOperationActivity::class.java)
|
val intent = Intent(context, GitOperationActivity::class.java)
|
||||||
|
@@ -50,7 +50,7 @@ import com.zeapo.pwdstore.crypto.PasswordCreationActivity
|
|||||||
import com.zeapo.pwdstore.git.BaseGitActivity
|
import com.zeapo.pwdstore.git.BaseGitActivity
|
||||||
import com.zeapo.pwdstore.git.GitOperationActivity
|
import com.zeapo.pwdstore.git.GitOperationActivity
|
||||||
import com.zeapo.pwdstore.git.GitServerConfigActivity
|
import com.zeapo.pwdstore.git.GitServerConfigActivity
|
||||||
import com.zeapo.pwdstore.git.config.ConnectionMode
|
import com.zeapo.pwdstore.git.config.AuthMode
|
||||||
import com.zeapo.pwdstore.git.config.GitSettings
|
import com.zeapo.pwdstore.git.config.GitSettings
|
||||||
import com.zeapo.pwdstore.ui.dialogs.FolderCreationDialogFragment
|
import com.zeapo.pwdstore.ui.dialogs.FolderCreationDialogFragment
|
||||||
import com.zeapo.pwdstore.utils.PasswordItem
|
import com.zeapo.pwdstore.utils.PasswordItem
|
||||||
@@ -249,7 +249,7 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
val menuRes = when {
|
val menuRes = when {
|
||||||
GitSettings.connectionMode == ConnectionMode.None -> R.menu.main_menu_no_auth
|
GitSettings.authMode == AuthMode.None -> R.menu.main_menu_no_auth
|
||||||
PasswordRepository.isGitRepo() -> R.menu.main_menu_git
|
PasswordRepository.isGitRepo() -> R.menu.main_menu_git
|
||||||
else -> R.menu.main_menu_non_git
|
else -> R.menu.main_menu_non_git
|
||||||
}
|
}
|
||||||
|
@@ -61,7 +61,7 @@ abstract class BaseGitActivity : AppCompatActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
op.executeAfterAuthentication(GitSettings.connectionMode)
|
op.executeAfterAuthentication(GitSettings.authMode)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
MaterialAlertDialogBuilder(this).setMessage(e.message).show()
|
MaterialAlertDialogBuilder(this).setMessage(e.message).show()
|
||||||
|
@@ -13,7 +13,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.zeapo.pwdstore.R
|
import com.zeapo.pwdstore.R
|
||||||
import com.zeapo.pwdstore.databinding.ActivityGitCloneBinding
|
import com.zeapo.pwdstore.databinding.ActivityGitCloneBinding
|
||||||
import com.zeapo.pwdstore.git.config.ConnectionMode
|
import com.zeapo.pwdstore.git.config.AuthMode
|
||||||
import com.zeapo.pwdstore.git.config.GitSettings
|
import com.zeapo.pwdstore.git.config.GitSettings
|
||||||
import com.zeapo.pwdstore.git.config.Protocol
|
import com.zeapo.pwdstore.git.config.Protocol
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||||
@@ -33,7 +33,7 @@ class GitServerConfigActivity : BaseGitActivity() {
|
|||||||
private val binding by viewBinding(ActivityGitCloneBinding::inflate)
|
private val binding by viewBinding(ActivityGitCloneBinding::inflate)
|
||||||
|
|
||||||
private lateinit var newProtocol: Protocol
|
private lateinit var newProtocol: Protocol
|
||||||
private lateinit var newConnectionMode: ConnectionMode
|
private lateinit var newAuthMode: AuthMode
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -45,40 +45,40 @@ class GitServerConfigActivity : BaseGitActivity() {
|
|||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
newProtocol = GitSettings.protocol
|
newProtocol = GitSettings.protocol
|
||||||
binding.cloneProtocolGroup.apply {
|
binding.protocolGroup.apply {
|
||||||
when (newProtocol) {
|
when (newProtocol) {
|
||||||
Protocol.Ssh -> check(R.id.clone_protocol_ssh)
|
Protocol.Ssh -> check(R.id.protocol_ssh)
|
||||||
Protocol.Https -> check(R.id.clone_protocol_https)
|
Protocol.Https -> check(R.id.protocol_https)
|
||||||
}
|
}
|
||||||
addOnButtonCheckedListener { _, checkedId, checked ->
|
addOnButtonCheckedListener { _, checkedId, checked ->
|
||||||
if (checked) {
|
if (checked) {
|
||||||
when (checkedId) {
|
when (checkedId) {
|
||||||
R.id.clone_protocol_https -> newProtocol = Protocol.Https
|
R.id.protocol_https -> newProtocol = Protocol.Https
|
||||||
R.id.clone_protocol_ssh -> newProtocol = Protocol.Ssh
|
R.id.protocol_ssh -> newProtocol = Protocol.Ssh
|
||||||
}
|
}
|
||||||
updateConnectionModeToggleGroup()
|
updateAuthModeToggleGroup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newConnectionMode = GitSettings.connectionMode
|
newAuthMode = GitSettings.authMode
|
||||||
binding.connectionModeGroup.apply {
|
binding.authModeGroup.apply {
|
||||||
when (newConnectionMode) {
|
when (newAuthMode) {
|
||||||
ConnectionMode.SshKey -> check(R.id.connection_mode_ssh_key)
|
AuthMode.SshKey -> check(R.id.auth_mode_ssh_key)
|
||||||
ConnectionMode.Password -> check(R.id.connection_mode_password)
|
AuthMode.Password -> check(R.id.auth_mode_password)
|
||||||
ConnectionMode.OpenKeychain -> check(R.id.connection_mode_open_keychain)
|
AuthMode.OpenKeychain -> check(R.id.auth_mode_open_keychain)
|
||||||
ConnectionMode.None -> uncheck(checkedButtonId)
|
AuthMode.None -> uncheck(checkedButtonId)
|
||||||
}
|
}
|
||||||
addOnButtonCheckedListener { _, _, _ ->
|
addOnButtonCheckedListener { _, _, _ ->
|
||||||
when (checkedButtonId) {
|
when (checkedButtonId) {
|
||||||
R.id.connection_mode_ssh_key -> newConnectionMode = ConnectionMode.SshKey
|
R.id.auth_mode_ssh_key -> newAuthMode = AuthMode.SshKey
|
||||||
R.id.connection_mode_open_keychain -> newConnectionMode = ConnectionMode.OpenKeychain
|
R.id.auth_mode_open_keychain -> newAuthMode = AuthMode.OpenKeychain
|
||||||
R.id.connection_mode_password -> newConnectionMode = ConnectionMode.Password
|
R.id.auth_mode_password -> newAuthMode = AuthMode.Password
|
||||||
View.NO_ID -> newConnectionMode = ConnectionMode.None
|
View.NO_ID -> newAuthMode = AuthMode.None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateConnectionModeToggleGroup()
|
updateAuthModeToggleGroup()
|
||||||
|
|
||||||
binding.serverUrl.setText(GitSettings.url)
|
binding.serverUrl.setText(GitSettings.url)
|
||||||
binding.serverBranch.setText(GitSettings.branch)
|
binding.serverBranch.setText(GitSettings.branch)
|
||||||
@@ -86,7 +86,7 @@ class GitServerConfigActivity : BaseGitActivity() {
|
|||||||
binding.saveButton.setOnClickListener {
|
binding.saveButton.setOnClickListener {
|
||||||
when (GitSettings.updateConnectionSettingsIfValid(
|
when (GitSettings.updateConnectionSettingsIfValid(
|
||||||
newProtocol = newProtocol,
|
newProtocol = newProtocol,
|
||||||
newConnectionMode = newConnectionMode,
|
newAuthMode = newAuthMode,
|
||||||
newUrl = binding.serverUrl.text.toString().trim(),
|
newUrl = binding.serverUrl.text.toString().trim(),
|
||||||
newBranch = binding.serverBranch.text.toString().trim())) {
|
newBranch = binding.serverBranch.text.toString().trim())) {
|
||||||
GitSettings.UpdateConnectionSettingsResult.FailedToParseUrl -> {
|
GitSettings.UpdateConnectionSettingsResult.FailedToParseUrl -> {
|
||||||
@@ -112,25 +112,25 @@ class GitServerConfigActivity : BaseGitActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateConnectionModeToggleGroup() {
|
private fun updateAuthModeToggleGroup() {
|
||||||
if (newProtocol == Protocol.Ssh) {
|
if (newProtocol == Protocol.Ssh) {
|
||||||
binding.connectionModeSshKey.isEnabled = true
|
binding.authModeSshKey.isEnabled = true
|
||||||
binding.connectionModeOpenKeychain.isEnabled = true
|
binding.authModeOpenKeychain.isEnabled = true
|
||||||
// Reset connection mode to SSH key if the current value (none) is not valid for SSH.
|
// Reset connection mode to SSH key if the current value (none) is not valid for SSH.
|
||||||
// Important note: This has to happen after enabling the other toggle buttons or they
|
// Important note: This has to happen after enabling the other toggle buttons or they
|
||||||
// won't check.
|
// won't check.
|
||||||
if (binding.connectionModeGroup.checkedButtonIds.isEmpty())
|
if (binding.authModeGroup.checkedButtonIds.isEmpty())
|
||||||
binding.connectionModeGroup.check(R.id.connection_mode_ssh_key)
|
binding.authModeGroup.check(R.id.auth_mode_ssh_key)
|
||||||
binding.connectionModeGroup.isSelectionRequired = true
|
binding.authModeGroup.isSelectionRequired = true
|
||||||
} else {
|
} else {
|
||||||
binding.connectionModeGroup.isSelectionRequired = false
|
binding.authModeGroup.isSelectionRequired = false
|
||||||
// Reset connection mode to password if the current value is not valid for HTTPS
|
// Reset connection mode to password if the current value is not valid for HTTPS
|
||||||
// Important note: This has to happen before disabling the other toggle buttons or they
|
// Important note: This has to happen before disabling the other toggle buttons or they
|
||||||
// won't uncheck.
|
// won't uncheck.
|
||||||
if (newConnectionMode !in listOf(ConnectionMode.None, ConnectionMode.Password))
|
if (newAuthMode !in listOf(AuthMode.None, AuthMode.Password))
|
||||||
binding.connectionModeGroup.check(R.id.connection_mode_password)
|
binding.authModeGroup.check(R.id.auth_mode_password)
|
||||||
binding.connectionModeSshKey.isEnabled = false
|
binding.authModeSshKey.isEnabled = false
|
||||||
binding.connectionModeOpenKeychain.isEnabled = false
|
binding.authModeOpenKeychain.isEnabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,7 +29,7 @@ enum class Protocol(val pref: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class ConnectionMode(val pref: String) {
|
enum class AuthMode(val pref: String) {
|
||||||
SshKey("ssh-key"),
|
SshKey("ssh-key"),
|
||||||
Password("username/password"),
|
Password("username/password"),
|
||||||
OpenKeychain("OpenKeychain"),
|
OpenKeychain("OpenKeychain"),
|
||||||
@@ -38,10 +38,10 @@ enum class ConnectionMode(val pref: String) {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val map = values().associateBy(ConnectionMode::pref)
|
private val map = values().associateBy(AuthMode::pref)
|
||||||
fun fromString(type: String?): ConnectionMode {
|
fun fromString(type: String?): AuthMode {
|
||||||
return map[type ?: return SshKey]
|
return map[type ?: return SshKey]
|
||||||
?: throw IllegalArgumentException("$type is not a valid ConnectionMode")
|
?: throw IllegalArgumentException("$type is not a valid AuthMode")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,8 +60,8 @@ object GitSettings {
|
|||||||
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, value.pref)
|
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, value.pref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var connectionMode
|
var authMode
|
||||||
get() = ConnectionMode.fromString(settings.getString(PreferenceKeys.GIT_REMOTE_AUTH))
|
get() = AuthMode.fromString(settings.getString(PreferenceKeys.GIT_REMOTE_AUTH))
|
||||||
private set(value) {
|
private set(value) {
|
||||||
settings.edit {
|
settings.edit {
|
||||||
putString(PreferenceKeys.GIT_REMOTE_AUTH, value.pref)
|
putString(PreferenceKeys.GIT_REMOTE_AUTH, value.pref)
|
||||||
@@ -110,18 +110,18 @@ object GitSettings {
|
|||||||
MissingUsername,
|
MissingUsername,
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateConnectionSettingsIfValid(newProtocol: Protocol, newConnectionMode: ConnectionMode, newUrl: String, newBranch: String): UpdateConnectionSettingsResult {
|
fun updateConnectionSettingsIfValid(newProtocol: Protocol, newAuthMode: AuthMode, newUrl: String, newBranch: String): UpdateConnectionSettingsResult {
|
||||||
val parsedUrl = try {
|
val parsedUrl = try {
|
||||||
URIish(newUrl)
|
URIish(newUrl)
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
return UpdateConnectionSettingsResult.FailedToParseUrl
|
return UpdateConnectionSettingsResult.FailedToParseUrl
|
||||||
}
|
}
|
||||||
if (newConnectionMode != ConnectionMode.None && parsedUrl.user.isNullOrBlank())
|
if (newAuthMode != AuthMode.None && parsedUrl.user.isNullOrBlank())
|
||||||
return UpdateConnectionSettingsResult.MissingUsername
|
return UpdateConnectionSettingsResult.MissingUsername
|
||||||
|
|
||||||
url = newUrl
|
url = newUrl
|
||||||
protocol = newProtocol
|
protocol = newProtocol
|
||||||
connectionMode = newConnectionMode
|
authMode = newAuthMode
|
||||||
branch = newBranch
|
branch = newBranch
|
||||||
return UpdateConnectionSettingsResult.Valid
|
return UpdateConnectionSettingsResult.Valid
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
import com.google.android.material.textfield.TextInputLayout
|
import com.google.android.material.textfield.TextInputLayout
|
||||||
import com.zeapo.pwdstore.R
|
import com.zeapo.pwdstore.R
|
||||||
import com.zeapo.pwdstore.git.config.ConnectionMode
|
import com.zeapo.pwdstore.git.config.AuthMode
|
||||||
import com.zeapo.pwdstore.git.sshj.InteractivePasswordFinder
|
import com.zeapo.pwdstore.git.sshj.InteractivePasswordFinder
|
||||||
import com.zeapo.pwdstore.utils.PreferenceKeys
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.getEncryptedPrefs
|
import com.zeapo.pwdstore.utils.getEncryptedPrefs
|
||||||
@@ -20,7 +20,7 @@ import kotlin.coroutines.resume
|
|||||||
|
|
||||||
class CredentialFinder(
|
class CredentialFinder(
|
||||||
val callingActivity: FragmentActivity,
|
val callingActivity: FragmentActivity,
|
||||||
val connectionMode: ConnectionMode
|
val authMode: AuthMode
|
||||||
) : InteractivePasswordFinder() {
|
) : InteractivePasswordFinder() {
|
||||||
|
|
||||||
override fun askForPassword(cont: Continuation<String?>, isRetry: Boolean) {
|
override fun askForPassword(cont: Continuation<String?>, isRetry: Boolean) {
|
||||||
@@ -30,15 +30,15 @@ class CredentialFinder(
|
|||||||
@StringRes val hintRes: Int
|
@StringRes val hintRes: Int
|
||||||
@StringRes val rememberRes: Int
|
@StringRes val rememberRes: Int
|
||||||
@StringRes val errorRes: Int
|
@StringRes val errorRes: Int
|
||||||
when (connectionMode) {
|
when (authMode) {
|
||||||
ConnectionMode.SshKey -> {
|
AuthMode.SshKey -> {
|
||||||
credentialPref = PreferenceKeys.SSH_KEY_LOCAL_PASSPHRASE
|
credentialPref = PreferenceKeys.SSH_KEY_LOCAL_PASSPHRASE
|
||||||
messageRes = R.string.passphrase_dialog_text
|
messageRes = R.string.passphrase_dialog_text
|
||||||
hintRes = R.string.ssh_keygen_passphrase
|
hintRes = R.string.ssh_keygen_passphrase
|
||||||
rememberRes = R.string.git_operation_remember_passphrase
|
rememberRes = R.string.git_operation_remember_passphrase
|
||||||
errorRes = R.string.git_operation_wrong_passphrase
|
errorRes = R.string.git_operation_wrong_passphrase
|
||||||
}
|
}
|
||||||
ConnectionMode.Password -> {
|
AuthMode.Password -> {
|
||||||
// Could be either an SSH or an HTTPS password
|
// Could be either an SSH or an HTTPS password
|
||||||
credentialPref = PreferenceKeys.HTTPS_PASSWORD
|
credentialPref = PreferenceKeys.HTTPS_PASSWORD
|
||||||
messageRes = R.string.password_dialog_text
|
messageRes = R.string.password_dialog_text
|
||||||
|
@@ -13,7 +13,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||||||
import com.zeapo.pwdstore.R
|
import com.zeapo.pwdstore.R
|
||||||
import com.zeapo.pwdstore.UserPreference
|
import com.zeapo.pwdstore.UserPreference
|
||||||
import com.zeapo.pwdstore.git.ErrorMessages
|
import com.zeapo.pwdstore.git.ErrorMessages
|
||||||
import com.zeapo.pwdstore.git.config.ConnectionMode
|
import com.zeapo.pwdstore.git.config.AuthMode
|
||||||
import com.zeapo.pwdstore.git.config.GitSettings
|
import com.zeapo.pwdstore.git.config.GitSettings
|
||||||
import com.zeapo.pwdstore.git.sshj.InteractivePasswordFinder
|
import com.zeapo.pwdstore.git.sshj.InteractivePasswordFinder
|
||||||
import com.zeapo.pwdstore.git.sshj.SshAuthData
|
import com.zeapo.pwdstore.git.sshj.SshAuthData
|
||||||
@@ -116,10 +116,10 @@ abstract class GitOperation(gitDir: File, internal val callingActivity: Fragment
|
|||||||
abstract suspend fun execute()
|
abstract suspend fun execute()
|
||||||
|
|
||||||
suspend fun executeAfterAuthentication(
|
suspend fun executeAfterAuthentication(
|
||||||
connectionMode: ConnectionMode,
|
authMode: AuthMode,
|
||||||
) {
|
) {
|
||||||
when (connectionMode) {
|
when (authMode) {
|
||||||
ConnectionMode.SshKey -> if (!sshKeyFile.exists()) {
|
AuthMode.SshKey -> if (!sshKeyFile.exists()) {
|
||||||
MaterialAlertDialogBuilder(callingActivity)
|
MaterialAlertDialogBuilder(callingActivity)
|
||||||
.setMessage(callingActivity.resources.getString(R.string.ssh_preferences_dialog_text))
|
.setMessage(callingActivity.resources.getString(R.string.ssh_preferences_dialog_text))
|
||||||
.setTitle(callingActivity.resources.getString(R.string.ssh_preferences_dialog_title))
|
.setTitle(callingActivity.resources.getString(R.string.ssh_preferences_dialog_title))
|
||||||
@@ -135,12 +135,12 @@ abstract class GitOperation(gitDir: File, internal val callingActivity: Fragment
|
|||||||
}.show()
|
}.show()
|
||||||
} else {
|
} else {
|
||||||
withPublicKeyAuthentication(
|
withPublicKeyAuthentication(
|
||||||
CredentialFinder(callingActivity, connectionMode)).execute()
|
CredentialFinder(callingActivity, authMode)).execute()
|
||||||
}
|
}
|
||||||
ConnectionMode.OpenKeychain -> withOpenKeychainAuthentication(callingActivity).execute()
|
AuthMode.OpenKeychain -> withOpenKeychainAuthentication(callingActivity).execute()
|
||||||
ConnectionMode.Password -> withPasswordAuthentication(
|
AuthMode.Password -> withPasswordAuthentication(
|
||||||
CredentialFinder(callingActivity, connectionMode)).execute()
|
CredentialFinder(callingActivity, authMode)).execute()
|
||||||
ConnectionMode.None -> execute()
|
AuthMode.None -> execute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@id/server_label" />
|
app:layout_constraintTop_toBottomOf="@id/server_label" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButtonToggleGroup
|
<com.google.android.material.button.MaterialButtonToggleGroup
|
||||||
android:id="@+id/clone_protocol_group"
|
android:id="@+id/protocol_group"
|
||||||
style="@style/TextAppearance.MaterialComponents.Headline1"
|
style="@style/TextAppearance.MaterialComponents.Headline1"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -51,14 +51,14 @@
|
|||||||
app:singleSelection="true">
|
app:singleSelection="true">
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/clone_protocol_ssh"
|
android:id="@+id/protocol_ssh"
|
||||||
style="?attr/materialButtonOutlinedStyle"
|
style="?attr/materialButtonOutlinedStyle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/clone_protocol_ssh" />
|
android:text="@string/clone_protocol_ssh" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/clone_protocol_https"
|
android:id="@+id/protocol_https"
|
||||||
style="?attr/materialButtonOutlinedStyle"
|
style="?attr/materialButtonOutlinedStyle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
android:hint="@string/server_url"
|
android:hint="@string/server_url"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/clone_protocol_group">
|
app:layout_constraintTop_toBottomOf="@id/protocol_group">
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:id="@+id/server_url"
|
android:id="@+id/server_url"
|
||||||
@@ -117,7 +117,7 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@id/label_server_branch" />
|
app:layout_constraintTop_toBottomOf="@id/label_server_branch" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButtonToggleGroup
|
<com.google.android.material.button.MaterialButtonToggleGroup
|
||||||
android:id="@+id/connection_mode_group"
|
android:id="@+id/auth_mode_group"
|
||||||
style="@style/TextAppearance.MaterialComponents.Headline1"
|
style="@style/TextAppearance.MaterialComponents.Headline1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -127,21 +127,21 @@
|
|||||||
app:singleSelection="true">
|
app:singleSelection="true">
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/connection_mode_ssh_key"
|
android:id="@+id/auth_mode_ssh_key"
|
||||||
style="?attr/materialButtonOutlinedStyle"
|
style="?attr/materialButtonOutlinedStyle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/connection_mode_ssh_key" />
|
android:text="@string/connection_mode_ssh_key" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/connection_mode_password"
|
android:id="@+id/auth_mode_password"
|
||||||
style="?attr/materialButtonOutlinedStyle"
|
style="?attr/materialButtonOutlinedStyle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/connection_mode_basic_authentication" />
|
android:text="@string/connection_mode_basic_authentication" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/connection_mode_open_keychain"
|
android:id="@+id/auth_mode_open_keychain"
|
||||||
style="?attr/materialButtonOutlinedStyle"
|
style="?attr/materialButtonOutlinedStyle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -155,6 +155,6 @@
|
|||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:text="@string/crypto_save"
|
android:text="@string/crypto_save"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/connection_mode_group" />
|
app:layout_constraintTop_toBottomOf="@id/auth_mode_group" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
Reference in New Issue
Block a user