mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-04 08:00:16 -04:00
WIP Windows User Accounts Composite Key integration
This commit is contained in:
54
ModernKeePassLib/Cryptography/ProtectedData.cs
Normal file
54
ModernKeePassLib/Cryptography/ProtectedData.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Security.Cryptography.DataProtection;
|
||||
using Windows.Storage.Streams;
|
||||
using ModernKeePassLib.Native;
|
||||
|
||||
namespace ModernKeePassLib.Cryptography
|
||||
{
|
||||
public static class ProtectedData
|
||||
{
|
||||
public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtectionScope scope)
|
||||
{
|
||||
var provider =
|
||||
new DataProtectionProvider(scope == DataProtectionScope.CurrentUser ? "LOCAL=user" : "LOCAL=machine");
|
||||
// Encode the plaintext input message to a buffer.
|
||||
var buffMsg = userData.AsBuffer();
|
||||
|
||||
// Encrypt the message.
|
||||
IBuffer buffProtected;
|
||||
try
|
||||
{
|
||||
buffProtected = provider.ProtectAsync(buffMsg).GetAwaiter().GetResult();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
return buffProtected.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public static byte[] Unprotect(byte[] userData, byte[] optionalEntropy, DataProtectionScope scope)
|
||||
{
|
||||
var provider =
|
||||
new DataProtectionProvider(scope == DataProtectionScope.CurrentUser ? "LOCAL=user" : "LOCAL=machine");
|
||||
// Decode the encrypted input message to a buffer.
|
||||
var buffMsg = userData.AsBuffer();
|
||||
|
||||
// Decrypt the message.
|
||||
IBuffer buffUnprotected;
|
||||
try
|
||||
{
|
||||
buffUnprotected = provider.UnprotectAsync(buffMsg).GetAwaiter().GetResult();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
return buffUnprotected.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
@@ -98,8 +98,9 @@ namespace ModernKeePassLib.Keys
|
||||
#endif
|
||||
|
||||
strUserDir = UrlUtil.EnsureTerminatingSeparator(strUserDir, false);
|
||||
strUserDir += PwDefs.ShortProductName;
|
||||
|
||||
#if !ModernKeePassLib
|
||||
strUserDir += PwDefs.ShortProductName;
|
||||
|
||||
if(bCreate && !Directory.Exists(strUserDir))
|
||||
Directory.CreateDirectory(strUserDir);
|
||||
@@ -117,10 +118,13 @@ namespace ModernKeePassLib.Keys
|
||||
{
|
||||
string strFilePath = GetUserKeyFilePath(false);
|
||||
#if ModernKeePassLib
|
||||
var fileStream = StorageFile.GetFileFromPathAsync(strFilePath).GetAwaiter().GetResult().OpenStreamForReadAsync().GetAwaiter().GetResult();
|
||||
var pbProtectedKey = new byte[(int)fileStream.Length];
|
||||
fileStream.Read(pbProtectedKey, 0, (int)fileStream.Length);
|
||||
fileStream.Dispose();
|
||||
byte[] pbProtectedKey;
|
||||
using (var fileStream = StorageFile.GetFileFromPathAsync(strFilePath).GetAwaiter().GetResult()
|
||||
.OpenStreamForReadAsync().GetAwaiter().GetResult())
|
||||
{
|
||||
pbProtectedKey = new byte[(int) fileStream.Length];
|
||||
fileStream.Read(pbProtectedKey, 0, (int) fileStream.Length);
|
||||
}
|
||||
#else
|
||||
byte[] pbProtectedKey = File.ReadAllBytes(strFilePath);
|
||||
#endif
|
||||
@@ -148,9 +152,11 @@ namespace ModernKeePassLib.Keys
|
||||
byte[] pbProtectedKey = ProtectedData.Protect(pbRandomKey,
|
||||
m_pbEntropy, DataProtectionScope.CurrentUser);
|
||||
#if ModernKeePassLib
|
||||
var fileStream = StorageFile.GetFileFromPathAsync(strFilePath).GetAwaiter().GetResult().OpenStreamForWriteAsync().GetAwaiter().GetResult();
|
||||
fileStream.Write(pbProtectedKey, 0, (int)fileStream.Length);
|
||||
fileStream.Dispose();
|
||||
using (var fileStream = StorageFile.GetFileFromPathAsync(strFilePath).GetAwaiter().GetResult()
|
||||
.OpenStreamForWriteAsync().GetAwaiter().GetResult())
|
||||
{
|
||||
fileStream.Write(pbProtectedKey, 0, (int) fileStream.Length);
|
||||
}
|
||||
#else
|
||||
File.WriteAllBytes(strFilePath, pbProtectedKey);
|
||||
#endif
|
||||
|
@@ -81,6 +81,7 @@
|
||||
<Compile Include="Cryptography\PasswordGenerator\PwCharSet.cs" />
|
||||
<Compile Include="Cryptography\PasswordGenerator\PwProfile.cs" />
|
||||
<Compile Include="Cryptography\PopularPasswords.cs" />
|
||||
<Compile Include="Cryptography\ProtectedData.cs" />
|
||||
<Compile Include="Cryptography\QualityEstimation.cs" />
|
||||
<Compile Include="Cryptography\SelfTest.cs" />
|
||||
<Compile Include="Interfaces\IStructureItem.cs" />
|
||||
|
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>ModernKeePassLib</id>
|
||||
<version>2.37.8000</version>
|
||||
<version>2.37.9000</version>
|
||||
<title>ModernKeePassLib</title>
|
||||
<authors>Geoffroy Bonneville</authors>
|
||||
<owners>Geoffroy Bonneville</owners>
|
||||
@@ -10,7 +10,7 @@
|
||||
<projectUrl>https://github.com/wismna/ModernKeePass</projectUrl>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>Portable KeePass Password Management Library that targets .Net Standard and WinRT. Allows reading, editing and writing to KeePass 2.x databases.</description>
|
||||
<releaseNotes>Code cleanup</releaseNotes>
|
||||
<releaseNotes>Implements Windows User Accounts</releaseNotes>
|
||||
<copyright>Copyright © 2017 Geoffroy Bonneville</copyright>
|
||||
<tags>KeePass KeePassLib Portable PCL NetStandard</tags>
|
||||
<dependencies>
|
||||
|
@@ -54,25 +54,12 @@ namespace ModernKeePassLib.Native
|
||||
}
|
||||
}
|
||||
|
||||
internal enum DataProtectionScope
|
||||
public enum DataProtectionScope
|
||||
{
|
||||
CurrentUser,
|
||||
LocalMachine
|
||||
}
|
||||
|
||||
internal static class ProtectedData
|
||||
{
|
||||
public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtectionScope scope)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static byte[] Unprotect(byte[] userData, byte[] optionalEntropy, DataProtectionScope scope)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal enum MemoryProtectionScope
|
||||
{
|
||||
CrossProcess,
|
||||
|
@@ -34,6 +34,7 @@ using System.Security.Cryptography;
|
||||
#endif
|
||||
|
||||
using ModernKeePassLib.Collections;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Cryptography.PasswordGenerator;
|
||||
using ModernKeePassLib.Native;
|
||||
using ModernKeePassLib.Security;
|
||||
|
Reference in New Issue
Block a user