JustinGrote / SecretManagement.KeePass

MIT License
116 stars 22 forks source link

Keyfile on UNC path causes error #44

Closed tsmarvin closed 3 years ago

tsmarvin commented 3 years ago

Hello,

Thank you for the great module/extension! Unfortunately I believe I may have found a bug.

If you register a vault and use a UNC KeyPath you will receive an error when trying to unlock the vault. Move the key file to the local disk and the error goes away.

I am able to successfully open the database with a UNC key file using the regular keepass client. I'm running Microsoft.PowerShell.SecretManagement v0.9.1

Replication Steps:

Import-Module 'SecretManagement.KeePass'

Register-SecretVault -Name 'TestVault' -ModuleName 'SecretManagement.Keepass' -VaultParameters @{
    Path              = '\\Server.FQDN.com\Share\Folder\TestVault.kdbx'
    UseMasterPassword = $true
    KeyPath           = '\\Server.FQDN.com\Share\Folder\TestVault.keyx'
}
Test-SecretVault -Name 'TestVault' -Verbose # Enter password at prompt
# Receive Errors

# Cleanup vault and re-register
UnRegister-SecretVault -Name 'TestVault'

Register-SecretVault -Name 'TestVault' -ModuleName 'SecretManagement.Keepass' -VaultParameters @{
    Path              = '\\Server.FQDN.com\Share\Folder\TestVault.kdbx'
    UseMasterPassword = $true
    KeyPath           = 'C:\TestVault.keyx'
}
Test-SecretVault -Name 'TestVault' -Verbose # Enter password at prompt
# Works without error.

Examples

UNC Path

KeyFile on UNC path causes error

Local Path

KeyFile local

I believe I've narrowed down the issue to the [KcpKeyFile]::new() call on line 76 of Connect-KeePassDatabase but have not had time to research further tonight.

I would love to help contribute to the fix (if you need/want help).

Thank you

JustinGrote commented 3 years ago

Sure! Pull Requests are always accepted. As a workaround you can map a drive to the UNC path. If I have some time I'll investigate but it's probably something in how resolve-path handles UNC paths.

tsmarvin commented 3 years ago

Hello! My pull request is ready for review whenever you have time. Thank you!

JustinGrote commented 3 years ago

@tsmarvin I haven't forgotten about this, I hope to carve out time to review tomorrow.