Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Exceptions/KeyStorageException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Runtime.Serialization;

namespace KeePassWinHello
{
[Serializable]
public class KeyStorageException : KeePassWinHelloException
{
public override bool IsPresentable { get { return true; } }

public KeyStorageException(string message) : base(message) { }
public KeyStorageException(string message, Exception inner) : base(message, inner) { }
protected KeyStorageException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}
3 changes: 2 additions & 1 deletion src/KeePassWinHello.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Compile Include="Exceptions\AuthProviderInvalidKeyException.cs" />
<Compile Include="Exceptions\AuthProviderSystemErrorException.cs" />
<Compile Include="Exceptions\AuthProviderException.cs" />
<Compile Include="Exceptions\KeyStorageException.cs" />
<Compile Include="AuthProviders\IAuthProvider.cs" />
<Compile Include="AuthProviders\UIContext.cs" />
<Compile Include="AuthProviders\WinHelloProviderForegroundDecorator.cs" />
Expand Down Expand Up @@ -124,4 +125,4 @@
<Message Importance="normal" Text="Copy artifacts to KeePass plugins directory." />
<Exec ContinueOnError="true" Command="powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File &quot;$(ProjectDir)..\Deploy-Plugin.ps1&quot; -ForDebug -Verbose" WorkingDirectory="$(ProjectDir).." />
</Target>
</Project>
</Project>
17 changes: 16 additions & 1 deletion src/KeyManagement/Storage/KeyWindowsStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace KeePassWinHello
internal class KeyWindowsStorage : IKeyStorage
{
#region Credential Manager API
private const int ERROR_NOT_ENOUGH_MEMORY = 0x8;
private const int ERROR_NOT_FOUND = 0x490;

private const int CRED_TYPE_GENERIC = 0x1;
Expand Down Expand Up @@ -96,7 +97,21 @@ public void AddOrUpdate(string dbPath, ProtectedKey protectedKey)
Marshal.Copy(data, 0, ncred.CredentialBlob, data.Length);
ncred.CredentialBlobSize = (uint)data.Length;

CredWrite(ref ncred, 0).ThrowOnError("CredWrite");
try
{
CredWrite(ref ncred, 0).ThrowOnError("CredWrite");
}
catch (EnviromentErrorException ex)
{
if (ex.ErrorCode != ERROR_NOT_ENOUGH_MEMORY)
throw;

throw new KeyStorageException(
"Windows Credential Manager reported that there was not enough memory to store this database key (CredWrite error 0x8)." +
Environment.NewLine +
"The database was locked, but the key was not saved for Windows Hello unlock. KeePass may ask for the regular master key next time.",
ex);
}
}
finally
{
Expand Down