From d365f68d1f0a2667f9982dcd6a9bf6bbf1b05219 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 18 Jun 2024 11:30:33 +0200 Subject: [PATCH] [platform] restoring inadvertently broken KeePass configuration GitOrigin-RevId: 30b88dad6cf3796d6f2c54ca077cb07717827735 --- .../credential-store-ui/src/PasswordSafeConfigurable.kt | 5 +++-- .../src/credentialStore/PasswordSafeSettings.kt | 6 +++--- .../src/credentialStore/keePass/KeePassCredentialStore.kt | 1 + .../src/ide/passwordSafe/impl/PasswordSafeImpl.kt | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/platform/credential-store-ui/src/PasswordSafeConfigurable.kt b/platform/credential-store-ui/src/PasswordSafeConfigurable.kt index 4109c45ee0aa..df4918374a79 100644 --- a/platform/credential-store-ui/src/PasswordSafeConfigurable.kt +++ b/platform/credential-store-ui/src/PasswordSafeConfigurable.kt @@ -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 diff --git a/platform/credential-store/src/credentialStore/PasswordSafeSettings.kt b/platform/credential-store/src/credentialStore/PasswordSafeSettings.kt index 9fc96f6f88cc..775829b3501f 100644 --- a/platform/credential-store/src/credentialStore/PasswordSafeSettings.kt +++ b/platform/credential-store/src/credentialStore/PasswordSafeSettings.kt @@ -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 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 diff --git a/platform/credential-store/src/credentialStore/keePass/KeePassCredentialStore.kt b/platform/credential-store/src/credentialStore/keePass/KeePassCredentialStore.kt index 32f13f3970d3..244f3939236e 100644 --- a/platform/credential-store/src/credentialStore/keePass/KeePassCredentialStore.kt +++ b/platform/credential-store/src/credentialStore/keePass/KeePassCredentialStore.kt @@ -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) /** diff --git a/platform/credential-store/src/ide/passwordSafe/impl/PasswordSafeImpl.kt b/platform/credential-store/src/ide/passwordSafe/impl/PasswordSafeImpl.kt index 6c945051d1dc..7e37df65b26e 100644 --- a/platform/credential-store/src/ide/passwordSafe/impl/PasswordSafeImpl.kt +++ b/platform/credential-store/src/ide/passwordSafe/impl/PasswordSafeImpl.kt @@ -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) {