[platform] restoring inadvertently broken KeePass configuration

GitOrigin-RevId: 30b88dad6cf3796d6f2c54ca077cb07717827735
This commit is contained in:
Roman Shevchenko
2024-06-18 11:30:33 +02:00
committed by intellij-monorepo-bot
parent 92b826b6a7
commit d365f68d1f
4 changed files with 9 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import com.intellij.credentialStore.kdbx.IncorrectMainPasswordException
import com.intellij.credentialStore.keePass.DB_FILE_NAME
import com.intellij.credentialStore.keePass.KeePassFileManager
import com.intellij.credentialStore.keePass.MainKeyFileStorage
import com.intellij.credentialStore.keePass.getDefaultDbFile
import com.intellij.credentialStore.keePass.getDefaultMainPasswordFile
import com.intellij.ide.IdeBundle
import com.intellij.ide.passwordSafe.PasswordSafe
@@ -83,7 +84,7 @@ class PasswordSafeConfigurableUi(private val settings: PasswordSafeSettings) : C
panel.reset()
keePassDbFile?.text = settings.keepassDb ?: getDefaultMainPasswordFile().toString()
keePassDbFile?.text = settings.keepassDb ?: getDefaultDbFile().toString()
}
override fun isModified(settings: PasswordSafeSettings): Boolean {
@@ -160,7 +161,7 @@ class PasswordSafeConfigurableUi(private val settings: PasswordSafeSettings) : C
// not in createAndSaveKeePassDatabaseWithNewOptions (as logically should be) because we want to force users to set custom master passwords even if some another setting (not path) was changed
// (e.g. PGP key)
if (providerType == ProviderType.KEEPASS) {
createKeePassFileManager()?.setCustomMainPasswordIfNeeded(getDefaultMainPasswordFile())
createKeePassFileManager()?.setCustomMainPasswordIfNeeded(getDefaultDbFile())
}
settings.providerType = providerType

View File

@@ -1,7 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.credentialStore
import com.intellij.credentialStore.keePass.getDefaultMainPasswordFile
import com.intellij.credentialStore.keePass.getDefaultDbFile
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.*
import com.intellij.openapi.util.SystemInfo
@@ -34,13 +34,13 @@ class PasswordSafeSettings : PersistentStateComponentWithModificationTracker<Pas
get() {
val result = state.keepassDb
return when {
result == null && providerType === ProviderType.KEEPASS -> getDefaultMainPasswordFile().toString()
result == null && providerType === ProviderType.KEEPASS -> getDefaultDbFile().toString()
else -> result
}
}
set(value) {
var v = value.nullize(nullizeSpaces = true)
if (v != null && v == getDefaultMainPasswordFile().toString()) {
if (v != null && v == getDefaultDbFile().toString()) {
v = null
}
state.keepassDb = v

View File

@@ -20,6 +20,7 @@ import kotlin.io.path.exists
const val DB_FILE_NAME: String = "c.kdbx"
fun getDefaultDbFile(): Path = PathManager.getConfigDir().resolve(DB_FILE_NAME)
fun getDefaultMainPasswordFile(): Path = PathManager.getConfigDir().resolve(MAIN_KEY_FILE_NAME)
/**

View File

@@ -5,6 +5,7 @@ import com.intellij.configurationStore.SettingsSavingComponent
import com.intellij.credentialStore.*
import com.intellij.credentialStore.kdbx.IncorrectMainPasswordException
import com.intellij.credentialStore.keePass.*
import com.intellij.credentialStore.keePass.getDefaultDbFile
import com.intellij.ide.passwordSafe.PasswordSafe
import com.intellij.notification.NotificationAction
import com.intellij.openapi.application.ApplicationManager
@@ -194,7 +195,7 @@ private fun computeProvider(settings: PasswordSafeSettings): CredentialStore {
if (CredentialStoreManager.getInstance().isSupported(settings.providerType)) {
if (settings.providerType == ProviderType.KEEPASS) {
try {
val dbFile = settings.keepassDb?.let { Paths.get(it) } ?: getDefaultMainPasswordFile()
val dbFile = settings.keepassDb?.let { Paths.get(it) } ?: getDefaultDbFile()
return KeePassCredentialStore(dbFile, getDefaultMainPasswordFile())
}
catch (e: IncorrectMainPasswordException) {