From 9621ea78cb42cb48ee23b202dbca0d613fbe23f2 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 22 Oct 2018 11:27:45 +0200 Subject: [PATCH] IDEA-200849 Password Safe: incorrect reaction on custom location setting for the (not existing) KeePass database --- .../credential-store/src/keePass/KeePassFileManager.kt | 9 +++------ .../test/keePass/KeePassFileManagerTest.kt | 1 + 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/platform/credential-store/src/keePass/KeePassFileManager.kt b/platform/credential-store/src/keePass/KeePassFileManager.kt index 4d39cf58fa84..bf06f6791ba4 100644 --- a/platform/credential-store/src/keePass/KeePassFileManager.kt +++ b/platform/credential-store/src/keePass/KeePassFileManager.kt @@ -126,7 +126,7 @@ internal open class KeePassFileManager(private val file: Path, return true } - fun askAndSetMasterKey(event: AnActionEvent?): Boolean { + fun askAndSetMasterKey(event: AnActionEvent?, topNote: String? = null): Boolean { val contextComponent = event?.getData(PlatformDataKeys.CONTEXT_COMPONENT) // to open old database, key can be required, so, to avoid showing 2 dialogs, check it before @@ -138,7 +138,7 @@ internal open class KeePassFileManager(private val file: Path, return requestCurrentAndNewKeys(contextComponent) } - return requestMasterPassword("Set Master Password", contextComponent = contextComponent) { + return requestMasterPassword("Set Master Password", topNote = topNote, contextComponent = contextComponent) { saveDatabase(file, db, createMasterKey(it), masterKeyFileStorage, secureRandom.value) null } @@ -242,9 +242,6 @@ internal open class KeePassFileManager(private val file: Path, return } - requestMasterPassword("Set Master Password", topNote = "Database file located in custom location,\ntherefore custom master password is required.") { - masterKeyFileStorage.save(createMasterKey(it)) - null - } + askAndSetMasterKey(null, topNote = "Database file located in custom location,\ntherefore custom master password is required.") } } \ No newline at end of file diff --git a/platform/credential-store/test/keePass/KeePassFileManagerTest.kt b/platform/credential-store/test/keePass/KeePassFileManagerTest.kt index 6b3cb0d73277..9d019d6ca740 100644 --- a/platform/credential-store/test/keePass/KeePassFileManagerTest.kt +++ b/platform/credential-store/test/keePass/KeePassFileManagerTest.kt @@ -255,6 +255,7 @@ internal class KeePassFileManagerTest { @Test fun `require custom master password if need - not custom`() { val store = createStore() + store.save(defaultEncryptionSpec) TestKeePassFileManager(store, masterPasswordRequestAnswer = "bar42").setCustomMasterPasswordIfNeed(fsRule.fs.getPath("/someDefault")) assertThat(MasterKeyFileStorage(store.masterKeyFile).load()!!.toString(Charsets.UTF_8)).isEqualTo("bar42") assertThat(createTestStoreWithCustomMasterKey().get(testCredentialAttributes)!!.password!!.toString()).isEqualTo("p")