WIP KeePassLibPCL - problem with awaitables

This commit is contained in:
2017-09-22 18:48:09 +02:00
parent a43bc20eb3
commit 668afbe817
108 changed files with 1205 additions and 4203 deletions

View File

@@ -5,7 +5,7 @@ VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernKeePass", "ModernKeePass\ModernKeePass.csproj", "{A0CFC681-769B-405A-8482-0CDEE595A91F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernKeePassLib", "ModernKeePassLib\ModernKeePassLib.csproj", "{A207789D-9020-401B-9D0A-D0D2CFF721BD}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernKeePassLibPCL", "ModernKeePassLib\ModernKeePassLibPCL.csproj", "{2E710089-9559-4967-846C-E763DD1F3ACB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -43,22 +43,22 @@ Global
{A0CFC681-769B-405A-8482-0CDEE595A91F}.Release|x86.ActiveCfg = Release|x86
{A0CFC681-769B-405A-8482-0CDEE595A91F}.Release|x86.Build.0 = Release|x86
{A0CFC681-769B-405A-8482-0CDEE595A91F}.Release|x86.Deploy.0 = Release|x86
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Debug|ARM.ActiveCfg = Debug|ARM
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Debug|ARM.Build.0 = Debug|ARM
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Debug|x64.ActiveCfg = Debug|x64
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Debug|x64.Build.0 = Debug|x64
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Debug|x86.ActiveCfg = Debug|x86
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Debug|x86.Build.0 = Debug|x86
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Release|Any CPU.Build.0 = Release|Any CPU
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Release|ARM.ActiveCfg = Release|ARM
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Release|ARM.Build.0 = Release|ARM
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Release|x64.ActiveCfg = Release|x64
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Release|x64.Build.0 = Release|x64
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Release|x86.ActiveCfg = Release|x86
{A207789D-9020-401B-9D0A-D0D2CFF721BD}.Release|x86.Build.0 = Release|x86
{2E710089-9559-4967-846C-E763DD1F3ACB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Debug|ARM.ActiveCfg = Debug|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Debug|ARM.Build.0 = Debug|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Debug|x64.ActiveCfg = Debug|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Debug|x64.Build.0 = Debug|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Debug|x86.ActiveCfg = Debug|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Debug|x86.Build.0 = Debug|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Release|Any CPU.Build.0 = Release|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Release|ARM.ActiveCfg = Release|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Release|ARM.Build.0 = Release|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Release|x64.ActiveCfg = Release|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Release|x64.Build.0 = Release|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Release|x86.ActiveCfg = Release|Any CPU
{2E710089-9559-4967-846C-E763DD1F3ACB}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -2,10 +2,10 @@
using Windows.Storage;
using System.Threading.Tasks;
using ModernKeePass.ViewModels;
using ModernKeePassLib;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Keys;
using ModernKeePassLib.Serialization;
using ModernKeePassLibPCL;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Keys;
using ModernKeePassLibPCL.Serialization;
namespace ModernKeePass.Common
{

View File

@@ -159,14 +159,50 @@
</Page>
</ItemGroup>
<ItemGroup>
<Reference Include="ModernKeePassLib, Version=2.36.0.27373, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ModernKeePassLib.2.36.0.27373\lib\netstandard1.2\ModernKeePassLib.dll</HintPath>
<Reference Include="ModernKeePassLibPCL, Version=2.28.1.32947, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ModernKeePassLibPCL.2.28.1.32947\lib\portable46-net451+win81+wpa81\ModernKeePassLibPCL.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PCLCrypto, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d4421c8a4786956c, processorArchitecture=MSIL">
<HintPath>..\packages\PCLCrypto.2.0.147\lib\portable-win81+wpa81\PCLCrypto.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PCLStorage, Version=1.0.2.0, Culture=neutral, PublicKeyToken=286fe515a2c35b64, processorArchitecture=MSIL">
<HintPath>..\packages\PCLStorage.1.0.2\lib\portable-win8+wpa81\PCLStorage.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PCLStorage.Abstractions, Version=1.0.2.0, Culture=neutral, PublicKeyToken=286fe515a2c35b64, processorArchitecture=MSIL">
<HintPath>..\packages\PCLStorage.1.0.2\lib\portable-win8+wpa81\PCLStorage.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PInvoke.BCrypt, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.BCrypt.0.5.97\lib\portable-net45+win8+wpa81\PInvoke.BCrypt.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PInvoke.Kernel32, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.Kernel32.0.5.97\lib\portable-net45+win8+wpa81\PInvoke.Kernel32.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PInvoke.NCrypt, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.NCrypt.0.5.97\lib\portable-net45+win8+wpa81\PInvoke.NCrypt.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PInvoke.Windows.Core, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.Windows.Core.0.5.97\lib\portable-net45+win8+wpa81\PInvoke.Windows.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Splat, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Splat.2.0.0\lib\Portable-Win81+Wpa81\Splat.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\win8\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Validation, Version=2.4.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL">
<HintPath>..\packages\Validation.2.4.15\lib\portable-net45+win8+wp8+wpa81\Validation.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup />
<ItemGroup>

View File

@@ -1,5 +1,5 @@
using System.ComponentModel;
using ModernKeePassLib;
using ModernKeePassLibPCL;
namespace ModernKeePass.ViewModels
{

View File

@@ -1,7 +1,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using ModernKeePassLib;
using ModernKeePassLibPCL;
namespace ModernKeePass.ViewModels
{

View File

@@ -4,11 +4,19 @@
<package id="Microsoft.Bcl.Compression" version="3.9.85" targetFramework="win81" />
<package id="Microsoft.NETCore.Platforms" version="2.0.0" targetFramework="win81" />
<package id="Microsoft.NETCore.Portable.Compatibility" version="1.0.2" targetFramework="win81" />
<package id="ModernKeePassLib" version="2.36.0.27373" targetFramework="win81" />
<package id="ModernKeePassLibPCL" version="2.28.1.32947" targetFramework="win81" />
<package id="NETStandard.Library" version="2.0.0" targetFramework="win81" />
<package id="PCLCrypto" version="2.0.147" targetFramework="win81" />
<package id="PCLStorage" version="1.0.2" targetFramework="win81" />
<package id="PInvoke.BCrypt" version="0.5.97" targetFramework="win81" />
<package id="PInvoke.Kernel32" version="0.5.97" targetFramework="win81" />
<package id="PInvoke.NCrypt" version="0.5.97" targetFramework="win81" />
<package id="PInvoke.Windows.Core" version="0.5.97" targetFramework="win81" />
<package id="Splat" version="2.0.0" targetFramework="win81" />
<package id="System.Net.Requests" version="4.3.0" targetFramework="win81" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="win81" />
<package id="System.Runtime.WindowsRuntime" version="4.3.0" targetFramework="win81" />
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="win81" />
<package id="System.Xml.XmlSerializer" version="4.3.0" targetFramework="win81" />
<package id="Validation" version="2.4.15" targetFramework="win81" />
</packages>

View File

@@ -1,36 +0,0 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################
#ignore thumbnails created by windows
Thumbs.db
#Ignore files build by Visual Studio
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
[Tt]est[Rr]esult*
Translation/TrlUtil.vshost.exe.manifest
*.nupkg
.vs/
/UpgradeLog.htm

View File

@@ -21,9 +21,9 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using ModernKeePassLib.Interfaces;
using ModernKeePassLibPCL.Interfaces;
namespace ModernKeePassLib.Collections
namespace ModernKeePassLibPCL.Collections
{
[Flags]
public enum AutoTypeObfuscationOptions

View File

@@ -23,15 +23,15 @@ using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
#if KeePassLibSD
using KeePassLibSD;
#endif
namespace ModernKeePassLib.Collections
namespace ModernKeePassLibPCL.Collections
{
/// <summary>
/// A list of <c>ProtectedBinary</c> objects (dictionary).

View File

@@ -23,15 +23,15 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
#if KeePassLibSD
using KeePassLibSD;
#endif
namespace ModernKeePassLib.Collections
namespace ModernKeePassLibPCL.Collections
{
/// <summary>
/// A list of <c>ProtectedString</c> objects (dictionary).

View File

@@ -22,9 +22,9 @@ using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using ModernKeePassLib.Interfaces;
using ModernKeePassLibPCL.Interfaces;
namespace ModernKeePassLib.Collections
namespace ModernKeePassLibPCL.Collections
{
/// <summary>
/// List of objects that implement <c>IDeepCloneable</c>,

View File

@@ -22,14 +22,14 @@ using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using ModernKeePassLib.Delegates;
using ModernKeePassLib.Interfaces;
using ModernKeePassLibPCL.Delegates;
using ModernKeePassLibPCL.Interfaces;
#if KeePassLibSD
using KeePassLibSD;
#endif
namespace ModernKeePassLib.Collections
namespace ModernKeePassLibPCL.Collections
{
public sealed class PwObjectPool
{

View File

@@ -23,13 +23,13 @@ using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using ModernKeePassLib.Interfaces;
using ModernKeePassLibPCL.Interfaces;
#if KeePassLibSD
using KeePassLibSD;
#endif
namespace ModernKeePassLib.Collections
namespace ModernKeePassLibPCL.Collections
{
public sealed class StringDictionaryEx : IDeepCloneable<StringDictionaryEx>,
IEnumerable<KeyValuePair<string, string>>

View File

@@ -24,7 +24,7 @@ using System.IO;
using System.Diagnostics;
using System.Security;
namespace ModernKeePassLib.Cryptography.Cipher
namespace ModernKeePassLibPCL.Cryptography.Cipher
{
/// <summary>
/// Pool of encryption/decryption algorithms (ciphers).

View File

@@ -20,7 +20,7 @@
using System;
using System.IO;
namespace ModernKeePassLib.Cryptography.Cipher
namespace ModernKeePassLibPCL.Cryptography.Cipher
{
/// <summary>
/// Interface of an encryption/decryption class.

View File

@@ -22,9 +22,9 @@
using System;
using System.Diagnostics;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Cryptography.Cipher
namespace ModernKeePassLibPCL.Cryptography.Cipher
{
public sealed class Salsa20Cipher : IDisposable
{

View File

@@ -23,10 +23,9 @@ using System.Text;
using System.IO;
using System.Security;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Security.Cryptography.Core;
#if PCL
using Windows.Security.Cryptography;
#if ModernKeePassLibPCL
using PCLCrypto;
#else
#if !KeePassRT
@@ -42,16 +41,16 @@ using Org.BouncyCastle.Crypto.Parameters;
#endif
using ModernKeePassLib.Resources;
using ModernKeePassLibPCL.Resources;
namespace ModernKeePassLib.Cryptography.Cipher
namespace ModernKeePassLibPCL.Cryptography.Cipher
{
/// <summary>
/// Standard AES cipher implementation.
/// </summary>
public sealed class StandardAesEngine : ICipherEngine
{
#if !PCL && !KeePassRT
#if !ModernKeePassLibPCL && !KeePassRT
private const CipherMode m_rCipherMode = CipherMode.CBC;
private const PaddingMode m_rCipherPadding = PaddingMode.PKCS7;
#endif
@@ -114,28 +113,31 @@ namespace ModernKeePassLib.Cryptography.Cipher
}
}
private static Stream CreateStream(Stream s, bool bEncrypt, byte[] pbKey, byte[] pbIV)
{
ValidateArguments(s, bEncrypt, pbKey, pbIV);
#if PCL
var provider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
var key = provider.CreateSymmetricKey(CryptographicBuffer.GenerateRandom(32));
using (var ms = new MemoryStream())
{
s.CopyTo(ms);
if (bEncrypt)
{
return CryptographicEngine.Encrypt(key, ms.GetWindowsRuntimeBuffer(), CryptographicBuffer.GenerateRandom(16)).AsStream();
}
/*var encryptor = CryptographicEngine.CreateEncryptor(
private static Stream CreateStream(Stream s, bool bEncrypt, byte[] pbKey, byte[] pbIV)
{
StandardAesEngine.ValidateArguments(s, bEncrypt, pbKey, pbIV);
byte[] pbLocalIV = new byte[16];
Array.Copy(pbIV, pbLocalIV, 16);
byte[] pbLocalKey = new byte[32];
Array.Copy(pbKey, pbLocalKey, 32);
#if ModernKeePassLibPCL
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.
OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
var key = provider.CreateSymmetricKey(pbLocalKey);
if (bEncrypt)
{
var encryptor = WinRTCrypto.CryptographicEngine.CreateEncryptor(
key, pbLocalIV);
return new CryptoStream(s, encryptor, CryptoStreamMode.Write);*/
return CryptographicEngine.Decrypt(key, ms.GetWindowsRuntimeBuffer(), CryptographicBuffer.GenerateRandom(16)).AsStream();
/*var decryptor = CryptographicEngine.CreateDecryptor(
key, pbLocalIV);
return new CryptoStream(s, decryptor, CryptoStreamMode.Read);*/
}
return new CryptoStream(s, encryptor, CryptoStreamMode.Write);
} else
{
var decryptor = WinRTCrypto.CryptographicEngine.CreateDecryptor(
key, pbLocalIV);
return new CryptoStream(s, decryptor, CryptoStreamMode.Read);
}
#else
#if !KeePassRT

View File

@@ -19,18 +19,18 @@
using System;
using System.Security;
#if PCL
using Windows.Security.Cryptography;
#if ModernKeePassLibPCL
using PCLCrypto;
#else
using System.Security.Cryptography;
#endif
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Security.Cryptography.Core;
using ModernKeePassLib.Utility;
namespace ModernKeePassLib.Cryptography
using ModernKeePassLibPCL.Native;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLibPCL.Cryptography
{
/// <summary>
/// Cryptographically strong random number generator. The returned values
@@ -41,8 +41,8 @@ namespace ModernKeePassLib.Cryptography
{
private byte[] m_pbEntropyPool = new byte[64];
private uint m_uCounter;
#if PCL
//private IRandomNumberGenerator m_rng = NetFxCrypto.RandomNumberGenerator;
#if ModernKeePassLibPCL
private IRandomNumberGenerator m_rng = NetFxCrypto.RandomNumberGenerator;
#else
private RNGCryptoServiceProvider m_rng = new RNGCryptoServiceProvider();
#endif
@@ -106,9 +106,9 @@ namespace ModernKeePassLib.Cryptography
byte[] pbNewData = pbEntropy;
if(pbEntropy.Length >= 64)
{
#if PCL
var shaNew = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha512);
pbNewData = shaNew.HashData(pbEntropy.AsBuffer()).ToArray();
#if ModernKeePassLibPCL
var shaNew = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512);
pbNewData = shaNew.HashData(pbEntropy);
#else
#if !KeePassLibSD
@@ -128,9 +128,9 @@ namespace ModernKeePassLib.Cryptography
ms.Write(pbNewData, 0, pbNewData.Length);
byte[] pbFinal = ms.ToArray();
#if PCL
var shaPool = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha512);
m_pbEntropyPool = shaPool.HashData(pbFinal.AsBuffer()).ToArray();
#if ModernKeePassLibPCL
var shaPool = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512);
m_pbEntropyPool = shaPool.HashData(pbFinal);
#else
#if !KeePassLibSD
@@ -157,7 +157,7 @@ namespace ModernKeePassLib.Cryptography
pb = TimeUtil.PackTime(DateTime.Now);
ms.Write(pb, 0, pb.Length);
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
// In try-catch for systems without GUI;
// https://sourceforge.net/p/keepass/discussion/329221/thread/20335b73/
try
@@ -174,7 +174,7 @@ namespace ModernKeePassLib.Cryptography
pb = MemUtil.UInt32ToBytes((uint)rWeak.Next());
ms.Write(pb, 0, pb.Length);
#if PCL
#if ModernKeePassLibPCL
pb = MemUtil.UInt32ToBytes((uint)Environment.ProcessorCount);
ms.Write(pb, 0, pb.Length);
@@ -185,7 +185,7 @@ namespace ModernKeePassLib.Cryptography
ms.Write(pb, 0, pb.Length);
#endif
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
Process p = null;
try
{
@@ -249,10 +249,9 @@ namespace ModernKeePassLib.Cryptography
private byte[] GetCspData()
{
//byte[] pbCspRandom = new byte[32];
var pbCspRandom = CryptographicBuffer.GenerateRandom(32);
//m_rng.GetBytes(pbCspRandom);
return pbCspRandom.ToArray();
byte[] pbCspRandom = new byte[32];
m_rng.GetBytes(pbCspRandom);
return pbCspRandom;
}
private byte[] GenerateRandom256()
@@ -280,9 +279,9 @@ namespace ModernKeePassLib.Cryptography
m_uGeneratedBytesCount += 32;
}
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
return sha256.HashData(pbFinal.AsBuffer()).ToArray();
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
return sha256.HashData(pbFinal);
#else
SHA256Managed sha256 = new SHA256Managed();
return sha256.ComputeHash(pbFinal);
@@ -310,7 +309,7 @@ namespace ModernKeePassLib.Cryptography
long lCopy = (long)((uRequestedBytes < 32) ? uRequestedBytes : 32);
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
Array.Copy(pbRandom256, 0, pbRes, lPos, lCopy);
#else
Array.Copy(pbRandom256, 0, pbRes, (int)lPos, (int)lCopy);

View File

@@ -19,17 +19,15 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Security.Cryptography.Core;
#if PCL
using Windows.Security.Cryptography;
#if ModernKeePassLibPCL
using PCLCrypto;
#else
using System.Security.Cryptography;
#endif
using ModernKeePassLib.Cryptography.Cipher;
using ModernKeePassLibPCL.Cryptography.Cipher;
namespace ModernKeePassLib.Cryptography
namespace ModernKeePassLibPCL.Cryptography
{
/// <summary>
/// Algorithms supported by <c>CryptoRandomStream</c>.
@@ -117,9 +115,9 @@ namespace ModernKeePassLib.Cryptography
}
else if(genAlgorithm == CrsAlgorithm.Salsa20)
{
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var pbKey32 = sha256.HashData(pbKey.AsBuffer()).ToArray();
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbKey32 = sha256.HashData(pbKey);
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] pbKey32 = sha256.ComputeHash(pbKey);

View File

@@ -21,25 +21,23 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
#if PCL
using Windows.Security.Cryptography;
#if ModernKeePassLibPCL
using PCLCrypto;
#else
using System.Security.Cryptography;
#endif
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Security.Cryptography.Core;
using ModernKeePassLib.Utility;
using CryptographicHash = Windows.Security.Cryptography.Core.CryptographicHash;
namespace ModernKeePassLib.Cryptography
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLibPCL.Cryptography
{
public sealed class HashingStreamEx : Stream
{
private Stream m_sBaseStream;
private bool m_bWriting;
#if PCL
private CryptographicHash m_hash;
#if ModernKeePassLibPCL
private ICryptoTransform m_hash;
#else
private HashAlgorithm m_hash;
#endif
@@ -77,8 +75,8 @@ namespace ModernKeePassLib.Cryptography
set { throw new NotSupportedException(); }
}
#if PCL
public HashingStreamEx(Stream sBaseStream, bool bWriting, string hashAlgorithm)
#if ModernKeePassLibPCL
public HashingStreamEx(Stream sBaseStream, bool bWriting, HashAlgorithm? hashAlgorithm)
#else
public HashingStreamEx(Stream sBaseStream, bool bWriting, HashAlgorithm hashAlgorithm)
#endif
@@ -88,8 +86,8 @@ namespace ModernKeePassLib.Cryptography
m_sBaseStream = sBaseStream;
m_bWriting = bWriting;
#if PCL
m_hash = HashAlgorithmProvider.OpenAlgorithm(hashAlgorithm ?? HashAlgorithmNames.Sha256).CreateHash();
#if ModernKeePassLibPCL
m_hash = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(hashAlgorithm ?? HashAlgorithm.Sha256).CreateHash();
#elif !KeePassLibSD
m_hash = (hashAlgorithm ?? new SHA256Managed());
#else // KeePassLibSD
@@ -103,14 +101,14 @@ namespace ModernKeePassLib.Cryptography
if(m_hash == null) { Debug.Assert(false); return; }
// Validate hash algorithm
/*if((!m_hash.CanReuseTransform) || (!m_hash.CanTransformMultipleBlocks) ||
if((!m_hash.CanReuseTransform) || (!m_hash.CanTransformMultipleBlocks) ||
(m_hash.InputBlockSize != 1) || (m_hash.OutputBlockSize != 1))
{
#if false && DEBUG
MessageService.ShowWarning("Broken HashAlgorithm object in HashingStreamEx.");
#endif
m_hash = null;
}*/
}
}
public override void Flush()
@@ -118,7 +116,7 @@ namespace ModernKeePassLib.Cryptography
m_sBaseStream.Flush();
}
#if PCL || KeePassRT
#if ModernKeePassLibPCL || KeePassRT
protected override void Dispose(bool disposing)
{
if(!disposing) return;
@@ -130,9 +128,9 @@ namespace ModernKeePassLib.Cryptography
{
try
{
//m_hash.TransformFinalBlock(new byte[0], 0, 0);
#if PCL
m_pbFinalHash = m_hash.GetValueAndReset().ToArray();
m_hash.TransformFinalBlock(new byte[0], 0, 0);
#if ModernKeePassLibPCL
m_pbFinalHash = (m_hash as CryptographicHash).GetValueAndReset ();
#else
m_pbFinalHash = m_hash.Hash;
#endif
@@ -173,8 +171,8 @@ namespace ModernKeePassLib.Cryptography
Array.Copy(pbBuffer, pbOrg, pbBuffer.Length);
#endif
/*if((m_hash != null) && (nRead > 0))
m_hash.TransformBlock(pbBuffer, nOffset, nRead, pbBuffer, nOffset);*/
if((m_hash != null) && (nRead > 0))
m_hash.TransformBlock(pbBuffer, nOffset, nRead, pbBuffer, nOffset);
#if DEBUG
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
@@ -192,8 +190,8 @@ namespace ModernKeePassLib.Cryptography
Array.Copy(pbBuffer, pbOrg, pbBuffer.Length);
#endif
/*if((m_hash != null) && (nCount > 0))
m_hash.TransformBlock(pbBuffer, nOffset, nCount, pbBuffer, nOffset);*/
if((m_hash != null) && (nCount > 0))
m_hash.TransformBlock(pbBuffer, nOffset, nCount, pbBuffer, nOffset);
#if DEBUG
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));

View File

@@ -18,17 +18,19 @@
*/
using System;
#if PCL
using Windows.Security.Cryptography.Core;
using System.Collections.Generic;
using System.Text;
#if ModernKeePassLibPCL
using PCLCrypto;
#else
using System.Security.Cryptography;
#endif
using System.Globalization;
using System.Runtime.InteropServices.WindowsRuntime;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Utility;
#if (!KeePassLibSD && !KeePassRT)
namespace ModernKeePassLib.Cryptography
namespace ModernKeePassLibPCL.Cryptography
{
/// <summary>
/// Generate HMAC-based one-time passwords as specified in RFC 4226.
@@ -44,10 +46,10 @@ namespace ModernKeePassLib.Cryptography
byte[] pbText = MemUtil.UInt64ToBytes(uFactor);
Array.Reverse(pbText); // Big-Endian
#if PCL
var hsha1 = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha1).CreateHash(pbSecret.AsBuffer());
hsha1.Append(pbText.AsBuffer());
var pbHash = hsha1.GetValueAndReset().ToArray();
#if ModernKeePassLibPCL
var hsha1 = WinRTCrypto.MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha1).CreateHash(pbSecret);
hsha1.Append(pbText);
var pbHash = hsha1.GetValueAndReset();
#else
HMACSHA1 hsha1 = new HMACSHA1(pbSecret);
byte[] pbHash = hsha1.ComputeHash(pbText);

View File

@@ -22,10 +22,10 @@ using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Cryptography.PasswordGenerator
namespace ModernKeePassLibPCL.Cryptography.PasswordGenerator
{
internal static class CharSetBasedGenerator
{

View File

@@ -21,10 +21,10 @@ using System;
using System.Collections.Generic;
using System.Text;
using ModernKeePassLib;
using ModernKeePassLib.Security;
using ModernKeePassLibPCL;
using ModernKeePassLibPCL.Security;
namespace ModernKeePassLib.Cryptography.PasswordGenerator
namespace ModernKeePassLibPCL.Cryptography.PasswordGenerator
{
public abstract class CustomPwGenerator
{

View File

@@ -22,7 +22,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace ModernKeePassLib.Cryptography.PasswordGenerator
namespace ModernKeePassLibPCL.Cryptography.PasswordGenerator
{
public sealed class CustomPwGeneratorPool : IEnumerable<CustomPwGenerator>
{

View File

@@ -22,10 +22,10 @@ using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Cryptography.PasswordGenerator
namespace ModernKeePassLibPCL.Cryptography.PasswordGenerator
{
internal static class PatternBasedGenerator
{

View File

@@ -22,7 +22,7 @@ using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace ModernKeePassLib.Cryptography.PasswordGenerator
namespace ModernKeePassLibPCL.Cryptography.PasswordGenerator
{
public sealed class PwCharSet
{

View File

@@ -22,9 +22,9 @@ using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using ModernKeePassLib.Security;
using ModernKeePassLibPCL.Security;
namespace ModernKeePassLib.Cryptography.PasswordGenerator
namespace ModernKeePassLibPCL.Cryptography.PasswordGenerator
{
public enum PwgError
{

View File

@@ -24,11 +24,11 @@ using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Cryptography.PasswordGenerator
namespace ModernKeePassLibPCL.Cryptography.PasswordGenerator
{
/// <summary>
/// Type of the password generator. Different types like generators

View File

@@ -22,9 +22,9 @@ using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Cryptography
namespace ModernKeePassLibPCL.Cryptography
{
public static class PopularPasswords
{

View File

@@ -22,10 +22,10 @@ using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using ModernKeePassLib.Cryptography.PasswordGenerator;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Cryptography.PasswordGenerator;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Cryptography
namespace ModernKeePassLibPCL.Cryptography
{
/// <summary>
/// A class that offers static functions to estimate the quality of

View File

@@ -20,8 +20,8 @@
using System;
using System.Collections.Generic;
using System.Security;
#if PCL
using Windows.Security.Cryptography;
#if ModernKeePassLibPCL
using PCLCrypto;
#else
using System.Security.Cryptography;
#endif
@@ -29,13 +29,14 @@ using System.Text;
using System.Globalization;
using System.Diagnostics;
using ModernKeePassLib.Cryptography.Cipher;
using ModernKeePassLib.Keys;
using ModernKeePassLib.Utility;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Security;
using ModernKeePassLibPCL.Cryptography.Cipher;
using ModernKeePassLibPCL.Keys;
using ModernKeePassLibPCL.Native;
using ModernKeePassLibPCL.Utility;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Security;
namespace ModernKeePassLib.Cryptography
namespace ModernKeePassLibPCL.Cryptography
{
/* /// <summary>
/// Return values of the <c>SelfTest.Perform</c> method.
@@ -63,7 +64,7 @@ namespace ModernKeePassLib.Cryptography
TestRijndael();
TestSalsa20();
#if !PCL
#if !ModernKeePassLibPCL
TestNativeKeyTransform();
#endif
@@ -81,7 +82,7 @@ namespace ModernKeePassLib.Cryptography
internal static void TestFipsComplianceProblems()
{
#if !PCL && !KeePassRT
#if !ModernKeePassLibPCL && !KeePassRT
try { new RijndaelManaged(); }
catch(Exception exAes)
{
@@ -98,7 +99,7 @@ namespace ModernKeePassLib.Cryptography
private static void TestRijndael()
{
#if !PCL && !KeePassRT
#if !ModernKeePassLibPCL && !KeePassRT
// Test vector (official ECB test vector #356)
byte[] pbIV = new byte[16];
byte[] pbTestKey = new byte[32];
@@ -210,7 +211,7 @@ namespace ModernKeePassLib.Cryptography
}
#endif
#if !PCL
#if !ModernKeePassLibPCL
private static void TestNativeKeyTransform()
{
#if DEBUG
@@ -519,7 +520,7 @@ namespace ModernKeePassLib.Cryptography
if(UrlUtil.GetHost(@"s://u:p@d.tld:p/p?q#f") != "d.tld")
throw new InvalidOperationException("UrlUtil-H7");
//if(NativeLib.IsUnix()) return;
if(NativeLib.IsUnix()) return;
string strBase = "\\\\HOMESERVER\\Apps\\KeePass\\KeePass.exe";
string strDoc = "\\\\HOMESERVER\\Documents\\KeePass\\NewDatabase.kdbx";

View File

@@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModernKeePassLib
{
public class Debug
{
[Conditional("DEBUG")]
public static void Assert(bool condition, string why)
{
if (!condition)
System.Diagnostics.Debugger.Break();
}
[Conditional("DEBUG")]
public static void Assert(bool condition)
{
if (!condition)
System.Diagnostics.Debugger.Break();
}
}
}

View File

@@ -19,7 +19,7 @@
using System;
namespace ModernKeePassLib.Delegates
namespace ModernKeePassLibPCL.Delegates
{
/// <summary>
/// Function definition of a method that performs an action on a group.

View File

@@ -20,7 +20,7 @@
using System;
using System.Collections.Generic;
namespace ModernKeePassLib.Interfaces
namespace ModernKeePassLibPCL.Interfaces
{
/// <summary>
/// Interface for objects that are deeply cloneable.

View File

@@ -20,7 +20,7 @@
using System;
using System.Collections.Generic;
namespace ModernKeePassLib.Interfaces
namespace ModernKeePassLibPCL.Interfaces
{
/// <summary>
/// Status message types.

View File

@@ -19,7 +19,7 @@
using System;
namespace ModernKeePassLib.Interfaces
namespace ModernKeePassLibPCL.Interfaces
{
public interface IStructureItem : ITimeLogger // Provides LocationChanged
{

View File

@@ -19,7 +19,7 @@
using System;
namespace ModernKeePassLib.Interfaces
namespace ModernKeePassLibPCL.Interfaces
{
/// <summary>
/// Interface for objects that support various times (creation time, last

View File

@@ -21,7 +21,7 @@ using System;
using System.Collections.Generic;
using System.Text;
namespace ModernKeePassLib.Interfaces
namespace ModernKeePassLibPCL.Interfaces
{
public interface IUIOperations
{

View File

@@ -23,7 +23,7 @@ using System.Text;
using System.IO;
using System.Xml;
namespace ModernKeePassLib.Interfaces
namespace ModernKeePassLibPCL.Interfaces
{
public interface IXmlSerializerEx
{

View File

@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(NuGetPackageRoot)' == ''">
<NuGetPackageRoot>$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
</PropertyGroup>
<ImportGroup>
<Import Project="$(NuGetPackageRoot)\NETStandard.Library\2.0.0\build\NETStandard.Library.targets" Condition="Exists('$(NuGetPackageRoot)\NETStandard.Library\2.0.0\build\NETStandard.Library.targets')" />
</ImportGroup>
</Project>

View File

@@ -22,103 +22,105 @@ using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Security.Cryptography.Core;
using Windows.Security.ExchangeActiveSyncProvisioning;
#if PCL
using Windows.Security.Cryptography;
#if ModernKeePassLibPCL
using PCLCrypto;
#else
using System.Security.Cryptography;
#endif
using ModernKeePassLib.Resources;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
#if KeePassRT
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Parameters;
#endif
namespace ModernKeePassLib.Keys
using ModernKeePassLibPCL.Native;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLibPCL.Keys
{
/// <summary>
/// Represents a key. A key can be build up using several user key data sources
/// like a password, a key file, the currently logged on user credentials,
/// the current computer ID, etc.
/// </summary>
public sealed class CompositeKey
{
private List<IUserKey> m_vUserKeys = new List<IUserKey>();
/// <summary>
/// Represents a key. A key can be build up using several user key data sources
/// like a password, a key file, the currently logged on user credentials,
/// the current computer ID, etc.
/// </summary>
public sealed class CompositeKey
{
private List<IUserKey> m_vUserKeys = new List<IUserKey>();
/// <summary>
/// List of all user keys contained in the current composite key.
/// </summary>
public IEnumerable<IUserKey> UserKeys
{
get { return m_vUserKeys; }
}
/// <summary>
/// List of all user keys contained in the current composite key.
/// </summary>
public IEnumerable<IUserKey> UserKeys
{
get { return m_vUserKeys; }
}
public uint UserKeyCount
{
get { return (uint) m_vUserKeys.Count; }
}
public uint UserKeyCount
{
get { return (uint)m_vUserKeys.Count; }
}
/// <summary>
/// Construct a new, empty key object.
/// </summary>
public CompositeKey()
{
}
/// <summary>
/// Construct a new, empty key object.
/// </summary>
public CompositeKey()
{
}
// /// <summary>
// /// Deconstructor, clears up the key.
// /// </summary>
// ~CompositeKey()
// {
// Clear();
// }
// /// <summary>
// /// Deconstructor, clears up the key.
// /// </summary>
// ~CompositeKey()
// {
// Clear();
// }
// /// <summary>
// /// Clears the key. This function also erases all previously stored
// /// user key data objects.
// /// </summary>
// public void Clear()
// {
// foreach(IUserKey pKey in m_vUserKeys)
// pKey.Clear();
// m_vUserKeys.Clear();
// }
// /// <summary>
// /// Clears the key. This function also erases all previously stored
// /// user key data objects.
// /// </summary>
// public void Clear()
// {
// foreach(IUserKey pKey in m_vUserKeys)
// pKey.Clear();
// m_vUserKeys.Clear();
// }
/// <summary>
/// Add a user key.
/// </summary>
/// <param name="pKey">User key to add.</param>
public void AddUserKey(IUserKey pKey)
{
Debug.Assert(pKey != null);
if (pKey == null) throw new ArgumentNullException("pKey");
/// <summary>
/// Add a user key.
/// </summary>
/// <param name="pKey">User key to add.</param>
public void AddUserKey(IUserKey pKey)
{
Debug.Assert(pKey != null); if(pKey == null) throw new ArgumentNullException("pKey");
m_vUserKeys.Add(pKey);
}
m_vUserKeys.Add(pKey);
}
/// <summary>
/// Remove a user key.
/// </summary>
/// <param name="pKey">User key to remove.</param>
/// <returns>Returns <c>true</c> if the key was removed successfully.</returns>
public bool RemoveUserKey(IUserKey pKey)
{
Debug.Assert(pKey != null);
if (pKey == null) throw new ArgumentNullException("pKey");
/// <summary>
/// Remove a user key.
/// </summary>
/// <param name="pKey">User key to remove.</param>
/// <returns>Returns <c>true</c> if the key was removed successfully.</returns>
public bool RemoveUserKey(IUserKey pKey)
{
Debug.Assert(pKey != null); if(pKey == null) throw new ArgumentNullException("pKey");
Debug.Assert(m_vUserKeys.IndexOf(pKey) >= 0);
return m_vUserKeys.Remove(pKey);
}
Debug.Assert(m_vUserKeys.IndexOf(pKey) >= 0);
return m_vUserKeys.Remove(pKey);
}
#if !PCL && !KeePassRT /// <summary>
/// Test whether the composite key contains a specific type of
/// user keys (password, key file, ...). If at least one user
/// key of that type is present, the function returns <c>true</c>.
/// </summary>
/// <param name="tUserKeyType">User key type.</param>
/// <returns>Returns <c>true</c>, if the composite key contains
/// a user key of the specified type.</returns>
#if !ModernKeePassLibPCL && !KeePassRT
/// <summary>
/// Test whether the composite key contains a specific type of
/// user keys (password, key file, ...). If at least one user
/// key of that type is present, the function returns <c>true</c>.
/// </summary>
/// <param name="tUserKeyType">User key type.</param>
/// <returns>Returns <c>true</c>, if the composite key contains
/// a user key of the specified type.</returns>
public bool ContainsType(Type tUserKeyType)
{
Debug.Assert(tUserKeyType != null);
@@ -154,91 +156,85 @@ namespace ModernKeePassLib.Keys
}
#endif
/// <summary>
/// Creates the composite key from the supplied user key sources (password,
/// key file, user account, computer ID, etc.).
/// </summary>
private byte[] CreateRawCompositeKey32()
{
ValidateUserKeys();
/// <summary>
/// Creates the composite key from the supplied user key sources (password,
/// key file, user account, computer ID, etc.).
/// </summary>
private byte[] CreateRawCompositeKey32()
{
ValidateUserKeys();
// Concatenate user key data
MemoryStream ms = new MemoryStream();
foreach (IUserKey pKey in m_vUserKeys)
{
ProtectedBinary b = pKey.KeyData;
if (b != null)
{
byte[] pbKeyData = b.ReadData();
ms.Write(pbKeyData, 0, pbKeyData.Length);
MemUtil.ZeroByteArray(pbKeyData);
}
}
// Concatenate user key data
MemoryStream ms = new MemoryStream();
foreach(IUserKey pKey in m_vUserKeys)
{
ProtectedBinary b = pKey.KeyData;
if(b != null)
{
byte[] pbKeyData = b.ReadData();
ms.Write(pbKeyData, 0, pbKeyData.Length);
MemUtil.ZeroByteArray(pbKeyData);
}
}
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var pbHash = sha256.HashData(ms.ToArray().AsBuffer()).ToArray();
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbHash = sha256.HashData(ms.ToArray());
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] pbHash = sha256.ComputeHash(ms.ToArray());
#endif
ms.Dispose();
return pbHash;
}
ms.Dispose();
return pbHash;
}
public bool EqualsValue(CompositeKey ckOther)
{
if (ckOther == null) throw new ArgumentNullException("ckOther");
public bool EqualsValue(CompositeKey ckOther)
{
if(ckOther == null) throw new ArgumentNullException("ckOther");
byte[] pbThis = CreateRawCompositeKey32();
byte[] pbOther = ckOther.CreateRawCompositeKey32();
bool bResult = MemUtil.ArraysEqual(pbThis, pbOther);
Array.Clear(pbOther, 0, pbOther.Length);
Array.Clear(pbThis, 0, pbThis.Length);
byte[] pbThis = CreateRawCompositeKey32();
byte[] pbOther = ckOther.CreateRawCompositeKey32();
bool bResult = MemUtil.ArraysEqual(pbThis, pbOther);
Array.Clear(pbOther, 0, pbOther.Length);
Array.Clear(pbThis, 0, pbThis.Length);
return bResult;
}
return bResult;
}
/// <summary>
/// Generate a 32-bit wide key out of the composite key.
/// </summary>
/// <param name="pbKeySeed32">Seed used in the key transformation
/// rounds. Must be a byte array containing exactly 32 bytes; must
/// not be null.</param>
/// <param name="uNumRounds">Number of key transformation rounds.</param>
/// <returns>Returns a protected binary object that contains the
/// resulting 32-bit wide key.</returns>
public ProtectedBinary GenerateKey32(byte[] pbKeySeed32, ulong uNumRounds)
{
Debug.Assert(pbKeySeed32 != null);
if (pbKeySeed32 == null) throw new ArgumentNullException("pbKeySeed32");
Debug.Assert(pbKeySeed32.Length == 32);
if (pbKeySeed32.Length != 32) throw new ArgumentException("pbKeySeed32");
/// <summary>
/// Generate a 32-bit wide key out of the composite key.
/// </summary>
/// <param name="pbKeySeed32">Seed used in the key transformation
/// rounds. Must be a byte array containing exactly 32 bytes; must
/// not be null.</param>
/// <param name="uNumRounds">Number of key transformation rounds.</param>
/// <returns>Returns a protected binary object that contains the
/// resulting 32-bit wide key.</returns>
public ProtectedBinary GenerateKey32(byte[] pbKeySeed32, ulong uNumRounds)
{
Debug.Assert(pbKeySeed32 != null);
if(pbKeySeed32 == null) throw new ArgumentNullException("pbKeySeed32");
Debug.Assert(pbKeySeed32.Length == 32);
if(pbKeySeed32.Length != 32) throw new ArgumentException("pbKeySeed32");
byte[] pbRaw32 = CreateRawCompositeKey32();
if ((pbRaw32 == null) || (pbRaw32.Length != 32))
{
Debug.Assert(false);
return null;
}
byte[] pbRaw32 = CreateRawCompositeKey32();
if((pbRaw32 == null) || (pbRaw32.Length != 32))
{ Debug.Assert(false); return null; }
byte[] pbTrf32 = TransformKey(pbRaw32, pbKeySeed32, uNumRounds);
if ((pbTrf32 == null) || (pbTrf32.Length != 32))
{
Debug.Assert(false);
return null;
}
byte[] pbTrf32 = TransformKey(pbRaw32, pbKeySeed32, uNumRounds);
if((pbTrf32 == null) || (pbTrf32.Length != 32))
{ Debug.Assert(false); return null; }
ProtectedBinary pbRet = new ProtectedBinary(true, pbTrf32);
MemUtil.ZeroByteArray(pbTrf32);
MemUtil.ZeroByteArray(pbRaw32);
ProtectedBinary pbRet = new ProtectedBinary(true, pbTrf32);
MemUtil.ZeroByteArray(pbTrf32);
MemUtil.ZeroByteArray(pbRaw32);
return pbRet;
}
return pbRet;
}
private void ValidateUserKeys()
{
#if !PCL
private void ValidateUserKeys()
{
#if !ModernKeePassLibPCL
int nAccounts = 0;
foreach(IUserKey uKey in m_vUserKeys)
@@ -253,51 +249,52 @@ namespace ModernKeePassLib.Keys
throw new InvalidOperationException();
}
#endif
}
}
/// <summary>
/// Transform the current key <c>uNumRounds</c> times.
/// </summary>
/// <param name="pbOriginalKey32">The original key which will be transformed.
/// This parameter won't be modified.</param>
/// <param name="pbKeySeed32">Seed used for key transformations. Must not
/// be <c>null</c>. This parameter won't be modified.</param>
/// <param name="uNumRounds">Transformation count.</param>
/// <returns>256-bit transformed key.</returns>
private static byte[] TransformKey(byte[] pbOriginalKey32, byte[] pbKeySeed32,
ulong uNumRounds)
{
Debug.Assert((pbOriginalKey32 != null) && (pbOriginalKey32.Length == 32));
if (pbOriginalKey32 == null) throw new ArgumentNullException("pbOriginalKey32");
if (pbOriginalKey32.Length != 32) throw new ArgumentException();
/// <summary>
/// Transform the current key <c>uNumRounds</c> times.
/// </summary>
/// <param name="pbOriginalKey32">The original key which will be transformed.
/// This parameter won't be modified.</param>
/// <param name="pbKeySeed32">Seed used for key transformations. Must not
/// be <c>null</c>. This parameter won't be modified.</param>
/// <param name="uNumRounds">Transformation count.</param>
/// <returns>256-bit transformed key.</returns>
private static byte[] TransformKey(byte[] pbOriginalKey32, byte[] pbKeySeed32,
ulong uNumRounds)
{
Debug.Assert((pbOriginalKey32 != null) && (pbOriginalKey32.Length == 32));
if(pbOriginalKey32 == null) throw new ArgumentNullException("pbOriginalKey32");
if(pbOriginalKey32.Length != 32) throw new ArgumentException();
Debug.Assert((pbKeySeed32 != null) && (pbKeySeed32.Length == 32));
if (pbKeySeed32 == null) throw new ArgumentNullException("pbKeySeed32");
if (pbKeySeed32.Length != 32) throw new ArgumentException();
Debug.Assert((pbKeySeed32 != null) && (pbKeySeed32.Length == 32));
if(pbKeySeed32 == null) throw new ArgumentNullException("pbKeySeed32");
if(pbKeySeed32.Length != 32) throw new ArgumentException();
byte[] pbNewKey = new byte[32];
Array.Copy(pbOriginalKey32, pbNewKey, pbNewKey.Length);
byte[] pbNewKey = new byte[32];
Array.Copy(pbOriginalKey32, pbNewKey, pbNewKey.Length);
#if !PCL // Try to use the native library first
#if !ModernKeePassLibPCL
// Try to use the native library first
if(NativeLib.TransformKey256(pbNewKey, pbKeySeed32, uNumRounds))
return (new SHA256Managed()).ComputeHash(pbNewKey);
#endif
if (TransformKeyManaged(pbNewKey, pbKeySeed32, uNumRounds) == false)
return null;
if(TransformKeyManaged(pbNewKey, pbKeySeed32, uNumRounds) == false)
return null;
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
return sha256.HashData(pbNewKey.AsBuffer()).ToArray();
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
return sha256.HashData(pbNewKey);
#else
SHA256Managed sha256 = new SHA256Managed();
return sha256.ComputeHash(pbNewKey);
#endif
}
}
public static bool TransformKeyManaged(byte[] pbNewKey32, byte[] pbKeySeed32,
ulong uNumRounds)
{
public static bool TransformKeyManaged(byte[] pbNewKey32, byte[] pbKeySeed32,
ulong uNumRounds)
{
#if KeePassRT
KeyParameter kp = new KeyParameter(pbKeySeed32);
AesEngine aes = new AesEngine();
@@ -308,10 +305,11 @@ namespace ModernKeePassLib.Keys
aes.ProcessBlock(pbNewKey32, 0, pbNewKey32, 0);
aes.ProcessBlock(pbNewKey32, 16, pbNewKey32, 16);
}
#elif PCL
var aes = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcb);
var key = aes.CreateSymmetricKey(pbKeySeed32.AsBuffer());
//var iCrypt = CryptographicEngine.CreateEncryptor(key);
#else
#if ModernKeePassLibPCL
var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
var key = aes.CreateSymmetricKey(pbKeySeed32);
var iCrypt = WinRTCrypto.CryptographicEngine.CreateEncryptor(key);
#else
byte[] pbIV = new byte[16];
Array.Clear(pbIV, 0, pbIV.Length);
@@ -330,29 +328,125 @@ namespace ModernKeePassLib.Keys
ICryptoTransform iCrypt = r.CreateEncryptor();
#endif
// !iCrypt.CanReuseTransform -- doesn't work with Mono
/*if ((iCrypt == null) || (iCrypt.InputBlockSize != 16) ||
(iCrypt.OutputBlockSize != 16))*/
if (aes.BlockLength != 16)
{
Debug.Assert(false, "Invalid ICryptoTransform.");
/*Debug.Assert((iCrypt.InputBlockSize == 16), "Invalid input block size!");
Debug.Assert((iCrypt.OutputBlockSize == 16), "Invalid output block size!");*/
Debug.Assert(aes.BlockLength == 16, "Invalid input block size!");
return false;
}
// !iCrypt.CanReuseTransform -- doesn't work with Mono
if((iCrypt == null) || (iCrypt.InputBlockSize != 16) ||
(iCrypt.OutputBlockSize != 16))
{
Debug.Assert(false, "Invalid ICryptoTransform.");
Debug.Assert((iCrypt.InputBlockSize == 16), "Invalid input block size!");
Debug.Assert((iCrypt.OutputBlockSize == 16), "Invalid output block size!");
return false;
}
for (ulong i = 0; i < uNumRounds; ++i)
{
/*iCrypt.TransformBlock(pbNewKey32, 0, 16, pbNewKey32, 0);
iCrypt.TransformBlock(pbNewKey32, 16, 16, pbNewKey32, 16);*/
}
for(ulong i = 0; i < uNumRounds; ++i)
{
iCrypt.TransformBlock(pbNewKey32, 0, 16, pbNewKey32, 0);
iCrypt.TransformBlock(pbNewKey32, 16, 16, pbNewKey32, 16);
}
#endif
return true;
}
}
return true;
}
public sealed class InvalidCompositeKeyException : Exception
/// <summary>
/// Benchmark the <c>TransformKey</c> method. Within
/// <paramref name="uMilliseconds"/> ms, random keys will be transformed
/// and the number of performed transformations are returned.
/// </summary>
/// <param name="uMilliseconds">Test duration in ms.</param>
/// <param name="uStep">Stepping.
/// <paramref name="uStep" /> should be a prime number. For fast processors
/// (PCs) a value of <c>3001</c> is recommended, for slower processors (PocketPC)
/// a value of <c>401</c> is recommended.</param>
/// <returns>Number of transformations performed in the specified
/// amount of time. Maximum value is <c>uint.MaxValue</c>.</returns>
public static ulong TransformKeyBenchmark(uint uMilliseconds, ulong uStep)
{
ulong uRounds;
#if !ModernKeePassLibPCL
// Try native method
if(NativeLib.TransformKeyBenchmark256(uMilliseconds, out uRounds))
return uRounds;
#endif
byte[] pbKey = new byte[32];
byte[] pbNewKey = new byte[32];
for(int i = 0; i < pbKey.Length; ++i)
{
pbKey[i] = (byte)i;
pbNewKey[i] = (byte)i;
}
#if KeePassRT
KeyParameter kp = new KeyParameter(pbKey);
AesEngine aes = new AesEngine();
aes.Init(true, kp);
#else
#if ModernKeePassLibPCL
var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
var key = aes.CreateSymmetricKey(pbKey);
var iCrypt = WinRTCrypto.CryptographicEngine.CreateEncryptor(key);
#else
byte[] pbIV = new byte[16];
Array.Clear(pbIV, 0, pbIV.Length);
RijndaelManaged r = new RijndaelManaged();
if(r.BlockSize != 128) // AES block size
{
Debug.Assert(false);
r.BlockSize = 128;
}
r.IV = pbIV;
r.Mode = CipherMode.ECB;
r.KeySize = 256;
r.Key = pbKey;
ICryptoTransform iCrypt = r.CreateEncryptor();
#endif
// !iCrypt.CanReuseTransform -- doesn't work with Mono
if((iCrypt == null) || (iCrypt.InputBlockSize != 16) ||
(iCrypt.OutputBlockSize != 16))
{
Debug.Assert(false, "Invalid ICryptoTransform.");
Debug.Assert(iCrypt.InputBlockSize == 16, "Invalid input block size!");
Debug.Assert(iCrypt.OutputBlockSize == 16, "Invalid output block size!");
return PwDefs.DefaultKeyEncryptionRounds;
}
#endif
uRounds = 0;
int tStart = Environment.TickCount;
while(true)
{
for(ulong j = 0; j < uStep; ++j)
{
#if KeePassRT
aes.ProcessBlock(pbNewKey, 0, pbNewKey, 0);
aes.ProcessBlock(pbNewKey, 16, pbNewKey, 16);
#else
iCrypt.TransformBlock(pbNewKey, 0, 16, pbNewKey, 0);
iCrypt.TransformBlock(pbNewKey, 16, 16, pbNewKey, 16);
#endif
}
uRounds += uStep;
if(uRounds < uStep) // Overflow check
{
uRounds = ulong.MaxValue;
break;
}
uint tElapsed = (uint)(Environment.TickCount - tStart);
if(tElapsed > uMilliseconds) break;
}
return uRounds;
}
}
public sealed class InvalidCompositeKeyException : Exception
{
public override string Message
{

View File

@@ -19,9 +19,9 @@
using System;
using ModernKeePassLib.Security;
using ModernKeePassLibPCL.Security;
namespace ModernKeePassLib.Keys
namespace ModernKeePassLibPCL.Keys
{
/// <summary>
/// Interface to a user key, like a password, key file data, etc.

View File

@@ -21,18 +21,16 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Security.Cryptography.Core;
#if PCL
using Windows.Security.Cryptography;
#if ModernKeePassLibPCL
using PCLCrypto;
#else
using System.Security.Cryptography;
#endif
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Keys
namespace ModernKeePassLibPCL.Keys
{
public sealed class KcpCustomKey : IUserKey
{
@@ -61,14 +59,14 @@ namespace ModernKeePassLib.Keys
if(bPerformHash)
{
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var pbRaw = sha256.HashData(pbKeyData.AsBuffer());
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbRaw = sha256.HashData(pbKeyData);
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] pbRaw = sha256.ComputeHash(pbKeyData);
#endif
m_pbKey = new ProtectedBinary(true, pbRaw.ToArray());
m_pbKey = new ProtectedBinary(true, pbRaw);
}
else m_pbKey = new ProtectedBinary(true, pbKeyData);
}

View File

@@ -22,24 +22,23 @@ using System.Text;
using System.IO;
using System.Xml;
using System.Security;
#if PCL
#if ModernKeePassLibPCL
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Windows.Security.Cryptography;
using PCLCrypto;
#else
using System.Security.Cryptography;
#endif
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Security.Cryptography.Core;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Security;
using ModernKeePassLib.Serialization;
using ModernKeePassLib.Utility;
namespace ModernKeePassLib.Keys
using ModernKeePassLibPCL.Cryptography;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Serialization;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLibPCL.Keys
{
/// <summary>
/// Key files as provided by the user.
@@ -139,9 +138,9 @@ namespace ModernKeePassLib.Keys
if(pbKey == null)
{
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
pbKey = sha256.HashData(pbFileData.AsBuffer()).ToArray();
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
pbKey = sha256.HashData(pbFileData);
#else
SHA256Managed sha256 = new SHA256Managed();
pbKey = sha256.ComputeHash(pbFileData);
@@ -199,19 +198,18 @@ namespace ModernKeePassLib.Keys
pbFinalKey32 = pbKey32;
else
{
using (MemoryStream ms = new MemoryStream())
{
ms.Write(pbAdditionalEntropy, 0, pbAdditionalEntropy.Length);
ms.Write(pbKey32, 0, 32);
MemoryStream ms = new MemoryStream();
ms.Write(pbAdditionalEntropy, 0, pbAdditionalEntropy.Length);
ms.Write(pbKey32, 0, 32);
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
pbFinalKey32 = sha256.HashData(ms.GetWindowsRuntimeBuffer()).ToArray();
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
pbFinalKey32 = sha256.HashData(ms.ToArray());
#else
SHA256Managed sha256 = new SHA256Managed();
pbFinalKey32 = sha256.ComputeHash(ms.ToArray());
SHA256Managed sha256 = new SHA256Managed();
pbFinalKey32 = sha256.ComputeHash(ms.ToArray());
#endif
}
ms.Dispose();
}
CreateXmlKeyFile(strFilePath, pbFinalKey32);
@@ -247,7 +245,7 @@ namespace ModernKeePassLib.Keys
try
{
#if PCL
#if ModernKeePassLibPCL
var doc = XDocument.Load(ms);
@@ -315,7 +313,7 @@ namespace ModernKeePassLib.Keys
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile);
Stream sOut = IOConnection.OpenWrite(ioc);
#if PCL
#if ModernKeePassLibPCL
var settings = new XmlWriterSettings() { Encoding = StrUtil.Utf8 };
var xtw = XmlWriter.Create(sOut, settings);
#else

View File

@@ -20,18 +20,16 @@
using System;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Security.Cryptography.Core;
#if PCL
using Windows.Security.Cryptography;
#if ModernKeePassLibPCL
using PCLCrypto;
#else
using System.Security.Cryptography;
#endif
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Keys
namespace ModernKeePassLibPCL.Keys
{
/// <summary>
/// Master password / passphrase as provided by the user.
@@ -74,16 +72,16 @@ namespace ModernKeePassLib.Keys
Debug.Assert(pbPasswordUtf8 != null);
if(pbPasswordUtf8 == null) throw new ArgumentNullException("pbPasswordUtf8");
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var pbRaw = sha256.HashData(pbPasswordUtf8.AsBuffer());
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbRaw = sha256.HashData(pbPasswordUtf8);
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] pbRaw = sha256.ComputeHash(pbPasswordUtf8);
#endif
m_psPassword = new ProtectedString(true, pbPasswordUtf8);
m_pbKeyData = new ProtectedBinary(true, pbRaw.ToArray());
m_pbKeyData = new ProtectedBinary(true, pbRaw);
}
// public void Clear()

View File

@@ -19,18 +19,15 @@
using System;
using System.Security;
using Windows.Security.Cryptography;
using System.Security.Cryptography;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Security.Cryptography.DataProtection;
using Windows.Storage;
using Windows.Storage.Streams;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
namespace ModernKeePassLib.Keys
using ModernKeePassLibPCL.Cryptography;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLibPCL.Keys
{
/// <summary>
/// A user key depending on the currently logged on Windows user account.
@@ -65,11 +62,8 @@ namespace ModernKeePassLib.Keys
// Test if ProtectedData is supported -- throws an exception
// when running on an old system (Windows 98 / ME).
byte[] pbDummyData = new byte[128];
DataProtectionProvider provider = new DataProtectionProvider("Local=user");
provider.ProtectAsync(pbDummyData.AsBuffer()).GetResults();
/*ProtectedData.Protect(pbDummyData, m_pbEntropy,
DataProtectionScope.CurrentUser);*/
ProtectedData.Protect(pbDummyData, m_pbEntropy,
DataProtectionScope.CurrentUser);
byte[] pbKey = LoadUserKey(false);
if(pbKey == null) pbKey = CreateUserKey();
@@ -87,19 +81,17 @@ namespace ModernKeePassLib.Keys
private static string GetUserKeyFilePath(bool bCreate)
{
#if KeePassRT
string strUserDir = ApplicationData.Current.RoamingFolder.Path;
string strUserDir = Windows.Storage.ApplicationData.Current.RoamingFolder.Path;
#else
/*string strUserDir = Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData);*/
var strUserDir = ApplicationData.Current.RoamingFolder.Path;
string strUserDir = Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData);
#endif
strUserDir = UrlUtil.EnsureTerminatingSeparator(strUserDir, false);
strUserDir += PwDefs.ShortProductName;
// Folder is sure to exist
/*if(bCreate && !Directory.Exists(strUserDir))
Directory.CreateDirectory(strUserDir);*/
if(bCreate && !Directory.Exists(strUserDir))
Directory.CreateDirectory(strUserDir);
strUserDir = UrlUtil.EnsureTerminatingSeparator(strUserDir, false);
return strUserDir + UserKeyFileName;
@@ -113,27 +105,16 @@ namespace ModernKeePassLib.Keys
try
{
string strFilePath = GetUserKeyFilePath(false);
var pbProtectedKeyStream =
ApplicationData.Current.RoamingFolder.GetFileAsync(strFilePath).GetResults().
OpenAsync(FileAccessMode.Read).GetResults().AsStream();
using (var ms = new MemoryStream())
{
ms.CopyTo(pbProtectedKeyStream);
var pbProtectedKey = ms.ToArray();
byte[] pbProtectedKey = File.ReadAllBytes(strFilePath);
//byte[] pbProtectedKey = File.ReadAllBytes(strFilePath);
pbKey = ProtectedData.Unprotect(pbProtectedKey, m_pbEntropy,
DataProtectionScope.CurrentUser);
DataProtectionProvider provider = new DataProtectionProvider("Local=user");
pbKey = provider.UnprotectAsync(pbProtectedKey.AsBuffer()).GetResults().ToArray();
/*pbKey = ProtectedData.Unprotect(pbProtectedKey, m_pbEntropy,
DataProtectionScope.CurrentUser);*/
Array.Clear(pbProtectedKey, 0, pbProtectedKey.Length);
}
Array.Clear(pbProtectedKey, 0, pbProtectedKey.Length);
}
catch(Exception exLoad)
{
//if(bShowWarning) MessageService.ShowWarning(exLoad);
if(bShowWarning) MessageService.ShowWarning(exLoad);
pbKey = null;
}
@@ -152,16 +133,10 @@ namespace ModernKeePassLib.Keys
string strFilePath = GetUserKeyFilePath(true);
byte[] pbRandomKey = CryptoRandom.Instance.GetRandomBytes(64);
byte[] pbProtectedKey = ProtectedData.Protect(pbRandomKey,
m_pbEntropy, DataProtectionScope.CurrentUser);
DataProtectionProvider provider = new DataProtectionProvider("Local=user");
var pbProtectedKey = provider.ProtectAsync(pbRandomKey.AsBuffer()).GetResults().ToArray();
/*byte[] pbProtectedKey = ProtectedData.Protect(pbRandomKey,
m_pbEntropy, DataProtectionScope.CurrentUser);*/
var file = ApplicationData.Current.RoamingFolder.CreateFileAsync(strFilePath).GetResults().
OpenAsync(FileAccessMode.ReadWrite).GetResults();
file.WriteAsync(pbProtectedKey.AsBuffer()).GetResults();
//File.WriteAllBytes(strFilePath, pbProtectedKey);
File.WriteAllBytes(strFilePath, pbProtectedKey);
Array.Clear(pbProtectedKey, 0, pbProtectedKey.Length);
Array.Clear(pbRandomKey, 0, pbRandomKey.Length);

View File

@@ -21,9 +21,9 @@ using System;
using System.Collections.Generic;
using System.Text;
using ModernKeePassLib.Serialization;
using ModernKeePassLibPCL.Serialization;
namespace ModernKeePassLib.Keys
namespace ModernKeePassLibPCL.Keys
{
public sealed class KeyProviderQueryContext
{

View File

@@ -23,7 +23,7 @@ using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace ModernKeePassLib.Keys
namespace ModernKeePassLibPCL.Keys
{
public sealed class KeyProviderPool : IEnumerable<KeyProvider>
{

View File

@@ -21,7 +21,7 @@ using System;
using System.Collections.Generic;
using System.Text;
namespace ModernKeePassLib.Keys
namespace ModernKeePassLibPCL.Keys
{
public enum KeyValidationType
{

View File

@@ -23,9 +23,9 @@ using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Keys
namespace ModernKeePassLibPCL.Keys
{
public sealed class KeyValidatorPool : IEnumerable<KeyValidator>
{

View File

@@ -19,7 +19,7 @@
using System;
namespace ModernKeePassLib.Keys
namespace ModernKeePassLibPCL.Keys
{
[Flags]
public enum UserKeyType

View File

@@ -1,207 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A207789D-9020-401B-9D0A-D0D2CFF721BD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ModernKeePassLib</RootNamespace>
<AssemblyName>ModernKeePassLib</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NETSTANDARD1_2, PCL</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETSTANDARD1_2, KeePassWinRT</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NETSTANDARD1_2, KeePassWinRT</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETSTANDARD1_2, KeePassWinRT</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NETSTANDARD1_2, KeePassWinRT</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETSTANDARD1_2, KeePassWinRT</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NETSTANDARD1_2, KeePassWinRT</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETSTANDARD1_2, KeePassWinRT</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Compile Include="Collections\AutoTypeConfig.cs" />
<Compile Include="Collections\ProtectedBinaryDictionary.cs" />
<Compile Include="Collections\ProtectedStringDictionary.cs" />
<Compile Include="Collections\PwObjectList.cs" />
<Compile Include="Collections\PwObjectPool.cs" />
<Compile Include="Collections\StringDictionaryEx.cs" />
<Compile Include="Cryptography\Cipher\CipherPool.cs" />
<Compile Include="Cryptography\Cipher\Salsa20Cipher.cs" />
<Compile Include="Cryptography\Cipher\StandardAesEngine.cs" />
<Compile Include="Cryptography\CryptoRandom.cs" />
<Compile Include="Cryptography\CryptoRandomStream.cs" />
<Compile Include="Cryptography\Cipher\ICipherEngine.cs" />
<Compile Include="Cryptography\HashingStreamEx.cs" />
<Compile Include="Cryptography\HmacOtp.cs" />
<Compile Include="Cryptography\PasswordGenerator\CharSetBasedGenerator.cs" />
<Compile Include="Cryptography\PasswordGenerator\CustomPwGenerator.cs" />
<Compile Include="Cryptography\PasswordGenerator\CustomPwGeneratorPool.cs" />
<Compile Include="Cryptography\PasswordGenerator\PatternBasedGenerator.cs" />
<Compile Include="Cryptography\PasswordGenerator\PwCharSet.cs" />
<Compile Include="Cryptography\PasswordGenerator\PwProfile.cs" />
<Compile Include="Cryptography\PopularPasswords.cs" />
<Compile Include="Cryptography\QualityEstimation.cs" />
<Compile Include="Cryptography\SelfTest.cs" />
<Compile Include="DebugAssert.cs" />
<Compile Include="Interfaces\IStructureItem.cs" />
<Compile Include="Interfaces\IUIOperations.cs" />
<Compile Include="Interfaces\IXmlSerializerEx.cs" />
<Compile Include="Keys\KcpCustomKey.cs" />
<Compile Include="Keys\KeyProvider.cs" />
<Compile Include="Keys\KeyProviderPool.cs" />
<Compile Include="Keys\KeyValidator.cs" />
<Compile Include="Keys\KeyValidatorPool.cs" />
<Compile Include="Keys\UserKeyType.cs" />
<Compile Include="PwCustomIcon.cs" />
<Compile Include="Resources\KLRes.Generated.cs" />
<Compile Include="Resources\KSRes.Generated.cs" />
<Compile Include="Security\XorredBuffer.cs" />
<Compile Include="Delegates\Handlers.cs" />
<Compile Include="Interfaces\IDeepCloneable.cs" />
<Compile Include="Interfaces\IStatusLogger.cs" />
<Compile Include="Interfaces\ITimeLogger.cs" />
<Compile Include="Keys\KcpKeyFile.cs" />
<Compile Include="Keys\IUserKey.cs" />
<Compile Include="Keys\KcpPassword.cs" />
<Compile Include="Keys\KcpUserAccount.cs" />
<Compile Include="PwDeletedObject.cs" />
<Compile Include="PwUuid.cs" />
<Compile Include="Security\ProtectedBinary.cs" />
<Compile Include="Security\ProtectedString.cs" />
<Compile Include="PwDefs.cs" />
<Compile Include="PwEntry.cs" />
<Compile Include="PwGroup.cs" />
<Compile Include="Keys\CompositeKey.cs" />
<Compile Include="PwDatabase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PwEnums.cs" />
<Compile Include="Serialization\BinaryReaderEx.cs" />
<Compile Include="Serialization\FileLock.cs" />
<Compile Include="Serialization\FileTransactionEx.cs" />
<Compile Include="Serialization\HashedBlockStream.cs" />
<Compile Include="Serialization\IOConnection.cs" />
<Compile Include="Serialization\IOConnectionInfo.cs" />
<Compile Include="Serialization\KdbxFile.cs" />
<Compile Include="Serialization\KdbxFile.Read.cs" />
<Compile Include="Serialization\KdbxFile.Read.Streamed.cs" />
<Compile Include="Serialization\KdbxFile.Write.cs" />
<Compile Include="Serialization\OldFormatException.cs" />
<Compile Include="Utility\AppLogEx.cs" />
<Compile Include="Utility\MemUtil.cs" />
<Compile Include="Cryptography\PasswordGenerator\PwGenerator.cs" />
<Compile Include="Utility\StrUtil.cs" />
<Compile Include="Utility\UrlUtil.cs" />
<Compile Include="Utility\TimeUtil.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Libs\Windows.winmd" />
<None Include="ModernKeePassLib.nuspec" />
<None Include="ModernKeePassLib.pfx" />
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Reference Include="Windows, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libs\Windows.winmd</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Native\" />
<Folder Include="Translation\" />
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '12.0' ">
<VisualStudioVersion>12.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -1,2 +0,0 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp70</s:String></wpf:ResourceDictionary>

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
</Project>

View File

@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(NuGetPackageRoot)' == ''">
<NuGetPackageRoot>$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
</PropertyGroup>
<ImportGroup>
<Import Project="$(NuGetPackageRoot)\NETStandard.Library\2.0.0\build\NETStandard.Library.targets" Condition="Exists('$(NuGetPackageRoot)\NETStandard.Library\2.0.0\build\NETStandard.Library.targets')" />
</ImportGroup>
</Project>

View File

@@ -0,0 +1,190 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{2E710089-9559-4967-846C-E763DD1F3ACB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ModernKeePassLibPCL</RootNamespace>
<AssemblyName>ModernKeePassLibPCL</AssemblyName>
<SignAssembly>false</SignAssembly>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkProfile>Profile151</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<AssemblyOriginatorKeyFile>KeePassLib.pfx</AssemblyOriginatorKeyFile>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;ModernKeePassLibPCL</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DefineConstants>ModernKeePassLibPCL</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="Collections\AutoTypeConfig.cs" />
<Compile Include="Collections\ProtectedBinaryDictionary.cs" />
<Compile Include="Collections\ProtectedStringDictionary.cs" />
<Compile Include="Collections\PwObjectList.cs" />
<Compile Include="Collections\PwObjectPool.cs" />
<Compile Include="Collections\StringDictionaryEx.cs" />
<Compile Include="Cryptography\Cipher\CipherPool.cs" />
<Compile Include="Cryptography\Cipher\Salsa20Cipher.cs" />
<Compile Include="Cryptography\Cipher\StandardAesEngine.cs" />
<Compile Include="Cryptography\CryptoRandom.cs" />
<Compile Include="Cryptography\CryptoRandomStream.cs" />
<Compile Include="Cryptography\Cipher\ICipherEngine.cs" />
<Compile Include="Cryptography\HmacOtp.cs" />
<Compile Include="Cryptography\PasswordGenerator\CharSetBasedGenerator.cs" />
<Compile Include="Cryptography\PasswordGenerator\CustomPwGenerator.cs" />
<Compile Include="Cryptography\PasswordGenerator\CustomPwGeneratorPool.cs" />
<Compile Include="Cryptography\PasswordGenerator\PatternBasedGenerator.cs" />
<Compile Include="Cryptography\PasswordGenerator\PwCharSet.cs" />
<Compile Include="Cryptography\PasswordGenerator\PwProfile.cs" />
<Compile Include="Cryptography\PopularPasswords.cs" />
<Compile Include="Cryptography\QualityEstimation.cs" />
<Compile Include="Cryptography\SelfTest.cs" />
<Compile Include="Interfaces\IStructureItem.cs" />
<Compile Include="Interfaces\IUIOperations.cs" />
<Compile Include="Interfaces\IXmlSerializerEx.cs" />
<Compile Include="Keys\KcpCustomKey.cs" />
<Compile Include="Keys\KeyProvider.cs" />
<Compile Include="Keys\KeyProviderPool.cs" />
<Compile Include="Keys\KeyValidator.cs" />
<Compile Include="Keys\KeyValidatorPool.cs" />
<Compile Include="Keys\UserKeyType.cs" />
<Compile Include="PwCustomIcon.cs" />
<Compile Include="Resources\KLRes.Generated.cs" />
<Compile Include="Resources\KSRes.Generated.cs" />
<Compile Include="Security\XorredBuffer.cs" />
<Compile Include="Delegates\Handlers.cs" />
<Compile Include="Interfaces\IDeepCloneable.cs" />
<Compile Include="Interfaces\IStatusLogger.cs" />
<Compile Include="Interfaces\ITimeLogger.cs" />
<Compile Include="Keys\KcpKeyFile.cs" />
<Compile Include="Keys\IUserKey.cs" />
<Compile Include="Keys\KcpPassword.cs" />
<Compile Include="PwDeletedObject.cs" />
<Compile Include="PwUuid.cs" />
<Compile Include="Security\ProtectedBinary.cs" />
<Compile Include="Security\ProtectedString.cs" />
<Compile Include="PwDefs.cs" />
<Compile Include="PwEntry.cs" />
<Compile Include="PwGroup.cs" />
<Compile Include="Keys\CompositeKey.cs" />
<Compile Include="PwDatabase.cs" />
<Compile Include="PwEnums.cs" />
<Compile Include="Serialization\BinaryReaderEx.cs" />
<Compile Include="Serialization\FileLock.cs" />
<Compile Include="Serialization\FileTransactionEx.cs" />
<Compile Include="Serialization\HashedBlockStream.cs" />
<Compile Include="Serialization\IOConnection.cs" />
<Compile Include="Serialization\KdbxFile.cs" />
<Compile Include="Serialization\KdbxFile.Read.cs" />
<Compile Include="Serialization\KdbxFile.Read.Streamed.cs" />
<Compile Include="Serialization\KdbxFile.Write.cs" />
<Compile Include="Serialization\IOConnectionInfo.cs" />
<Compile Include="Serialization\OldFormatException.cs" />
<Compile Include="Utility\AppLogEx.cs" />
<Compile Include="Utility\GfxUtil.cs" />
<Compile Include="Utility\MemUtil.cs" />
<Compile Include="Cryptography\PasswordGenerator\PwGenerator.cs" />
<Compile Include="Utility\StrUtil.cs" />
<Compile Include="Utility\UrlUtil.cs" />
<Compile Include="Utility\TimeUtil.cs" />
<Compile Include="Cryptography\HashingStreamEx.cs" />
<Compile Include="Native\Native.PCL.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utility\ColorTranslator.cs" />
<Compile Include="Utility\StreamExtensions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="KeePassLib.pfx" />
<None Include="Libs\Windows.winmd" />
<None Include="ModernKeePassLibPCL.nuspec" />
<None Include="Utility\MessageService.cs" />
<None Include="packages.config" />
<None Include="Native\NativeLib.cs" />
<None Include="Native\NativeMethods.cs" />
<None Include="Native\NativeMethods.Unix.cs" />
<None Include="Keys\KcpUserAccount.cs" />
<None Include="Translation\KPControlCustomization.cs" />
<None Include="Translation\KPFormCustomization.cs" />
<None Include="Translation\KPStringTable.cs" />
<None Include="Translation\KPStringTableItem.cs" />
<None Include="Translation\KPTranslation.cs" />
<None Include="Translation\KPTranslationProperties.cs" />
<None Include="Utility\MonoWorkarounds.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ProjectExtensions>
<MonoDevelop>
<Properties>
<Policies>
<TextStylePolicy TabsToSpaces="False" EolMarker="Windows" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/plain" />
<TextStylePolicy inheritsSet="null" scope="text/x-csharp" />
<CSharpFormattingPolicy IndentPreprocessorDirectives="False" BeforeMethodDeclarationParentheses="False" BeforeMethodCallParentheses="False" BeforeConstructorDeclarationParentheses="False" BeforeDelegateDeclarationParentheses="False" AfterDelegateDeclarationParameterComma="True" NewParentheses="False" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp" />
<DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedHierarchical" ResourceNamePolicy="FileFormatDefault" />
</Policies>
</Properties>
</MonoDevelop>
</ProjectExtensions>
<ItemGroup>
<Reference Include="PCLCrypto, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d4421c8a4786956c, processorArchitecture=MSIL">
<HintPath>..\packages\PCLCrypto.2.0.147\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\PCLCrypto.dll</HintPath>
</Reference>
<Reference Include="PCLStorage">
<HintPath>..\packages\PCLStorage.1.0.2\lib\portable-net45+wp8+wpa81+win8+monoandroid+monotouch+Xamarin.iOS+Xamarin.Mac\PCLStorage.dll</HintPath>
</Reference>
<Reference Include="PCLStorage.Abstractions">
<HintPath>..\packages\PCLStorage.1.0.2\lib\portable-net45+wp8+wpa81+win8+monoandroid+monotouch+Xamarin.iOS+Xamarin.Mac\PCLStorage.Abstractions.dll</HintPath>
</Reference>
<Reference Include="PInvoke.BCrypt, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.BCrypt.0.5.97\lib\portable-net45+win8+wpa81\PInvoke.BCrypt.dll</HintPath>
</Reference>
<Reference Include="PInvoke.Kernel32, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.Kernel32.0.5.97\lib\portable-net45+win8+wpa81\PInvoke.Kernel32.dll</HintPath>
</Reference>
<Reference Include="PInvoke.NCrypt, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.NCrypt.0.5.97\lib\portable-net45+win8+wpa81\PInvoke.NCrypt.dll</HintPath>
</Reference>
<Reference Include="PInvoke.Windows.Core, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.Windows.Core.0.5.97\lib\portable-net45+win8+wpa81\PInvoke.Windows.Core.dll</HintPath>
</Reference>
<Reference Include="Splat, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Splat.2.0.0\lib\netstandard1.1\Splat.dll</HintPath>
</Reference>
<Reference Include="Validation, Version=2.4.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL">
<HintPath>..\packages\Validation.2.4.15\lib\portable-net45+win8+wp8+wpa81\Validation.dll</HintPath>
</Reference>
<Reference Include="Windows, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libs\Windows.winmd</HintPath>
</Reference>
</ItemGroup>
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
</Project>

View File

@@ -1,9 +1,9 @@
<?xml version="1.0"?>
<?xml version="1.0"?>
<package >
<metadata>
<id>ModernKeePassLib</id>
<version>2.19.2950</version>
<title>ModernKeePassLib</title>
<id>ModernKeePassLibPCL</id>
<version>2.28.1000</version>
<title>ModernKeePassLibPCL</title>
<authors>Geoffroy Bonneville</authors>
<owners>Geoffroy Bonneville</owners>
<licenseUrl>https://www.gnu.org/licenses/gpl-3.0.en.html</licenseUrl>
@@ -12,8 +12,8 @@
<description>Portable KeePass Password Management Library</description>
<releaseNotes>Initial release.</releaseNotes>
<copyright>Copyright © 2017 Geoffroy Bonneville</copyright>
<tags>KeePass KeePassLib NetStandard</tags>
<dependencies>
<tags>KeePass KeePassLib Portable</tags>
<!--<dependencies>
<group targetFramework=".NETStandard1.2">
<dependency id="Microsoft.NETCore.Portable.Compatibility" version="1.0.2" exclude="Build,Analyzers" />
<dependency id="NETStandard.Library" version="2.0.0" exclude="Build,Analyzers" />
@@ -21,12 +21,12 @@
<dependency id="System.Runtime.WindowsRuntime" version="4.3.0" exclude="Build,Analyzers" />
<dependency id="System.Xml.XmlSerializer" version="4.3.0" exclude="Build,Analyzers" />
</group>
</dependencies>
</dependencies>-->
</metadata>
<!-- DLLs and resources -->
<files>
<file src="bin\Release\ModernKeePassLib.dll" target="lib\netstandard1.2"/>
<!--<file src="bin\ARM\Release\ModernKeePassLib.dll" target="lib\ARM\netstandard1.2"/>
<!--<file src="bin\Release\ModernKeePassLib.dll" target="lib\netstandard1.2"/>
<file src="bin\ARM\Release\ModernKeePassLib.dll" target="lib\ARM\netstandard1.2"/>
<file src="bin\x64\Release\ModernKeePassLib.dll" target="lib\x64\netstandard1.2"/>
<file src="bin\x86\Release\ModernKeePassLib.dll" target="lib\x86\netstandard1.2"/>-->
</files>

View File

@@ -2,7 +2,7 @@
using PlatformID = System.UInt32;
namespace KeePass2PCL.Native
namespace ModernKeePassLibPCL.Native
{
internal static class NativeLib
{

View File

@@ -28,9 +28,9 @@ using System.IO;
using System.Reflection;
using System.Diagnostics;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Native
namespace ModernKeePassLibPCL.Native
{
/// <summary>
/// Interface to native library (library containing fast versions of

View File

@@ -25,7 +25,7 @@ using System.Runtime.InteropServices;
using System.Reflection;
using System.Diagnostics;
namespace KeePass2PCL.Native
namespace ModernKeePassLibPCL.Native
{
internal static partial class NativeMethods
{

View File

@@ -24,9 +24,9 @@ using System.Runtime.InteropServices;
using System.IO;
using System.Diagnostics;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Native
namespace ModernKeePassLibPCL.Native
{
internal static partial class NativeMethods
{

View File

@@ -1,6 +1,6 @@
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,22 +22,23 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General assembly properties
[assembly: AssemblyTitle("ModernKeePassLib")]
[assembly: AssemblyDescription("Portable KeePass Password Management Library")]
[assembly: AssemblyTitle("KeePassLib")]
[assembly: AssemblyDescription("KeePass Password Management Library")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Geoffroy Bonneville")]
[assembly: AssemblyProduct("ModernKeePassLib")]
[assembly: AssemblyCopyright("Copyright © 2017 Geoffroy Bonneville")]
[assembly: AssemblyCompany("Panteam")]
[assembly: AssemblyProduct("KeePassLib")]
[assembly: AssemblyCopyright("Copyright © 2003-2017 Dominik Reichl")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// COM settings
[assembly: ComVisible(false)]
#if !ModernKeePassLibPCL
// Assembly GUID
//Bert TODO: Disabled Guid
//[assembly: Guid("395f6eec-a1e0-4438-aa82-b75099348134")]
[assembly: Guid("395f6eec-a1e0-4438-aa82-b75099348134")]
#endif
// Assembly version information
[assembly: AssemblyVersion("2.36.0.*")]
[assembly: AssemblyFileVersion("2.36.0.0")]
[assembly: AssemblyVersion("2.28.1.*")]
[assembly: AssemblyFileVersion("2.28.1.0")]

View File

@@ -1,42 +0,0 @@
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General assembly properties
[assembly: AssemblyTitle("KeePassLib")]
[assembly: AssemblyDescription("KeePass Password Management Library")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Dominik Reichl")]
[assembly: AssemblyProduct("KeePassLib")]
[assembly: AssemblyCopyright("Copyright © 2003-2012 Dominik Reichl")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// COM settings
[assembly: ComVisible(false)]
// Assembly GUID
[assembly: Guid("395f6eec-a1e0-4438-aa82-b75099348134")]
// Assembly version information
[assembly: AssemblyVersion("2.19.0.*")]
[assembly: AssemblyFileVersion("2.19.0.0")]

View File

@@ -18,9 +18,17 @@
*/
using System;
using Windows.UI.Xaml.Controls;
using System.Diagnostics;
#if ModernKeePassLibPCL
using Image = Splat.IBitmap;
#else
using System.Drawing;
#endif
using System.IO;
namespace ModernKeePassLib
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLibPCL
{
/// <summary>
/// Custom icon. <c>PwCustomIcon</c> objects are immutable.
@@ -63,7 +71,7 @@ namespace ModernKeePassLib
// MemoryStream ms = new MemoryStream(m_pbImageDataPng, false);
// m_pCachedImage = Image.FromStream(ms);
// ms.Close();
//m_pCachedImage = GfxUtil.LoadImage(m_pbImageDataPng);
m_pCachedImage = GfxUtil.LoadImage(m_pbImageDataPng);
#else
m_pCachedImage = null;
#endif

View File

@@ -21,20 +21,24 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Windows.UI;
using Windows.UI.Xaml.Controls;
using ModernKeePassLib.Collections;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Cryptography.Cipher;
using ModernKeePassLib.Delegates;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Keys;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Security;
using ModernKeePassLib.Serialization;
using ModernKeePassLib.Utility;
using System.Drawing;
namespace ModernKeePassLib
#if ModernKeePassLibPCL
using Image = Splat.IBitmap;
#endif
using ModernKeePassLibPCL.Collections;
using ModernKeePassLibPCL.Cryptography;
using ModernKeePassLibPCL.Cryptography.Cipher;
using ModernKeePassLibPCL.Delegates;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Keys;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Serialization;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLibPCL
{
/// <summary>
/// The core password manager class. It contains a number of groups, which
@@ -68,7 +72,7 @@ namespace ModernKeePassLib
private string m_strDefaultUserName = string.Empty;
private DateTime m_dtDefaultUserChanged = PwDefs.DtDefaultNow;
private uint m_uMntncHistoryDays = 365;
private Color m_clr;
private Color m_clr = Color.Empty;
private DateTime m_dtKeyLastChanged = PwDefs.DtDefaultNow;
private long m_lKeyChangeRecDays = -1;
@@ -498,7 +502,7 @@ namespace ModernKeePassLib
m_strDefaultUserName = string.Empty;
m_dtDefaultUserChanged = dtNow;
m_uMntncHistoryDays = 365;
m_clr = new Color();
m_clr = Color.Empty;
m_dtKeyLastChanged = dtNow;
m_lKeyChangeRecDays = -1;
@@ -1465,14 +1469,10 @@ namespace ModernKeePassLib
/// <returns>Image data.</returns>
public Image GetCustomIcon(PwUuid pwIconId)
{
#if PCL
return null;
#else
int nIndex = GetCustomIconIndex(pwIconId);
int nIndex = GetCustomIconIndex(pwIconId);
if(nIndex >= 0) return m_vCustomIcons[nIndex].Image;
else { Debug.Assert(false); return null; }
#endif
}
public bool DeleteCustomIcons(List<PwUuid> vUuidsToDelete)

View File

@@ -23,11 +23,11 @@ using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics;
using ModernKeePassLib.Delegates;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Serialization;
using ModernKeePassLibPCL.Delegates;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Serialization;
namespace ModernKeePassLib
namespace ModernKeePassLibPCL
{
/// <summary>
/// Contains KeePassLib-global definitions and enums.
@@ -318,7 +318,7 @@ namespace ModernKeePassLib
set { m_bSearchInTags = value; }
}
#if PCL || KeePassRT
#if ModernKeePassLibPCL || KeePassRT
private StringComparison m_scType = StringComparison.OrdinalIgnoreCase;
#else
private StringComparison m_scType = StringComparison.InvariantCultureIgnoreCase;

View File

@@ -21,9 +21,9 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using ModernKeePassLib.Interfaces;
using ModernKeePassLibPCL.Interfaces;
namespace ModernKeePassLib
namespace ModernKeePassLibPCL
{
/// <summary>
/// Represents an object that has been deleted.

View File

@@ -21,13 +21,14 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Xml;
using Windows.UI;
using ModernKeePassLib.Collections;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
using System.Drawing;
namespace ModernKeePassLib
using ModernKeePassLibPCL.Collections;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLibPCL
{
/// <summary>
/// A class representing a password entry. A password entry consists of several
@@ -48,8 +49,8 @@ namespace ModernKeePassLib
private PwIcon m_pwIcon = PwIcon.Key;
private PwUuid m_pwCustomIconID = PwUuid.Zero;
private Color m_clrForeground;
private Color m_clrBackground;
private Color m_clrForeground = Color.Empty;
private Color m_clrBackground = Color.Empty;
private DateTime m_tCreation = PwDefs.DtDefaultNow;
private DateTime m_tLastMod = PwDefs.DtDefaultNow;
@@ -888,7 +889,7 @@ namespace ModernKeePassLib
if(m_bCompareNaturally) return StrUtil.CompareNaturally(strA, strB);
#if PCL || KeePassRT
#if ModernKeePassLibPCL || KeePassRT
return string.Compare(strA, strB, m_bCaseInsensitive ?
StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture);
#else

View File

@@ -19,7 +19,7 @@
using System;
namespace ModernKeePassLib
namespace ModernKeePassLibPCL
{
/// <summary>
/// Compression algorithm specifiers.

View File

@@ -22,13 +22,13 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
using ModernKeePassLib.Collections;
using ModernKeePassLib.Delegates;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Collections;
using ModernKeePassLibPCL.Delegates;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib
namespace ModernKeePassLibPCL
{
/// <summary>
/// A group containing several password entries.
@@ -841,13 +841,13 @@ namespace ModernKeePassLib
Regex rx = null;
if(sp.RegularExpression)
{
#if PCL || KeePassRT
#if ModernKeePassLibPCL || KeePassRT
RegexOptions ro = RegexOptions.None;
#else
RegexOptions ro = RegexOptions.Compiled;
#endif
if((sp.ComparisonMode == StringComparison.CurrentCultureIgnoreCase) ||
#if !PCL && !KeePassRT
#if !ModernKeePassLibPCL && !KeePassRT
(sp.ComparisonMode == StringComparison.InvariantCultureIgnoreCase) ||
#endif
(sp.ComparisonMode == StringComparison.OrdinalIgnoreCase))

View File

@@ -22,9 +22,9 @@ using System.Collections.Generic;
using System.Xml;
using System.Diagnostics;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib
namespace ModernKeePassLibPCL
{
// [ImmutableObject(true)]
/// <summary>

View File

@@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
namespace ModernKeePassLib.Resources
namespace ModernKeePassLibPCL.Resources
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.

View File

@@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
namespace ModernKeePassLib.Resources
namespace ModernKeePassLibPCL.Resources
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.

View File

@@ -21,15 +21,16 @@ using System;
using System.Threading;
using System.Diagnostics;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Cryptography.Cipher;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Cryptography;
using ModernKeePassLibPCL.Cryptography.Cipher;
using ModernKeePassLibPCL.Native;
using ModernKeePassLibPCL.Utility;
#if KeePassLibSD
using KeePassLibSD;
#endif
namespace ModernKeePassLib.Security
namespace ModernKeePassLibPCL.Security
{
[Flags]
public enum PbCryptFlags
@@ -85,19 +86,17 @@ namespace ModernKeePassLib.Security
{
#if KeePassLibSD
return false;
#elif PCL
return false;
#else
bool? ob = g_bProtectedMemorySupported;
if(ob.HasValue) return ob.Value;
// Mono does not implement any encryption for ProtectedMemory;
// https://sourceforge.net/p/keepass/feature-requests/1907/
/*if(NativeLib.IsUnix())
if(NativeLib.IsUnix())
{
g_bProtectedMemorySupported = false;
return false;
}*/
}
ob = false;
try // Test whether ProtectedMemory is supported
@@ -242,15 +241,14 @@ namespace ModernKeePassLib.Security
return;
}
#if !PCL
if(ProtectedBinary.ProtectedMemorySupported)
if(ProtectedBinary.ProtectedMemorySupported)
{
ProtectedMemory.Protect(m_pbData, MemoryProtectionScope.SameProcess);
m_mp = PbMemProt.ProtectedMemory;
return;
}
#endif
byte[] pbKey32 = g_pbKey32;
if(pbKey32 == null)
{
@@ -270,10 +268,9 @@ namespace ModernKeePassLib.Security
private void Decrypt()
{
if(m_pbData.Length == 0) return;
#if !PCL
if(m_mp == PbMemProt.ProtectedMemory)
ProtectedMemory.Unprotect(m_pbData, MemoryProtectionScope.SameProcess);
#endif
else if(m_mp == PbMemProt.Salsa20)
{
Salsa20Cipher s = new Salsa20Cipher(g_pbKey32,

View File

@@ -21,8 +21,8 @@ using System;
using System.Text;
using System.Diagnostics;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Cryptography;
using ModernKeePassLibPCL.Utility;
#if KeePassLibSD
using KeePassLibSD;
@@ -30,7 +30,7 @@ using KeePassLibSD;
// SecureString objects are limited to 65536 characters, don't use
namespace ModernKeePassLib.Security
namespace ModernKeePassLibPCL.Security
{
/// <summary>
/// Represents an in-memory encrypted string.

View File

@@ -20,7 +20,7 @@
using System;
using System.Diagnostics;
namespace ModernKeePassLib.Security
namespace ModernKeePassLibPCL.Security
{
/// <summary>
/// Represents an object that is encrypted using a XOR pad until

View File

@@ -22,9 +22,9 @@ using System.Collections.Generic;
using System.Text;
using System.IO;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Serialization
namespace ModernKeePassLibPCL.Serialization
{
public sealed class BinaryReaderEx
{

View File

@@ -21,18 +21,18 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
#if PCL
#if ModernKeePassLibPCL
using System.Threading.Tasks;
#else
using System.Threading;
#endif
using System.Diagnostics;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Cryptography;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Serialization
namespace ModernKeePassLibPCL.Serialization
{
public sealed class FileLockException : Exception
{
@@ -158,7 +158,7 @@ namespace ModernKeePassLib.Serialization
byte[] pbID = CryptoRandom.Instance.GetRandomBytes(16);
string strTime = TimeUtil.SerializeUtc(DateTime.Now);
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
lfi = new LockFileInfo(Convert.ToBase64String(pbID), strTime,
Environment.UserName, Environment.MachineName,
Environment.UserDomainName);
@@ -243,7 +243,7 @@ namespace ModernKeePassLib.Serialization
if(bFileDeleted) break;
#if PCL
#if ModernKeePassLibPCL
if(bDisposing)
Task.Delay(50).Wait();
#else

View File

@@ -23,13 +23,14 @@ using System.Text;
using System.IO;
using System.Diagnostics;
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
using System.Security.AccessControl;
#endif
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Native;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Serialization
namespace ModernKeePassLibPCL.Serialization
{
public sealed class FileTransactionEx
{
@@ -58,8 +59,8 @@ namespace ModernKeePassLib.Serialization
m_bTransacted = bTransacted;
m_iocBase = iocBaseFile.CloneDeep();
// ModernKeePassLib is currently targeting .NET 4.5
#if !PCL
// ModernKeePassLibPCL is currently targeting .NET 4.5
#if !ModernKeePassLibPCL
// Prevent transactions for FTP URLs under .NET 4.0 in order to
// avoid/workaround .NET bug 621450:
// https://connect.microsoft.com/VisualStudio/feedback/details/621450/problem-renaming-file-on-ftp-server-using-ftpwebrequest-in-net-framework-4-0-vs2010-only
@@ -101,14 +102,14 @@ namespace ModernKeePassLib.Serialization
{
bool bMadeUnhidden = UrlUtil.UnhideFile(m_iocBase.Path);
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
FileSecurity bkSecurity = null;
bool bEfsEncrypted = false;
#endif
if(IOConnection.FileExists(m_iocBase))
{
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
if(m_iocBase.IsLocalFile())
{
try
@@ -130,7 +131,7 @@ namespace ModernKeePassLib.Serialization
IOConnection.RenameFile(m_iocTemp, m_iocBase);
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
if(m_iocBase.IsLocalFile())
{
try

View File

@@ -19,22 +19,23 @@
using System;
using System.IO;
#if PCL
#if ModernKeePassLibPCL
using System.Linq;
using PCLCrypto;
#else
using System.Security.Cryptography;
#endif
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using Windows.Security.Cryptography.Core;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Native;
using ModernKeePassLibPCL.Utility;
#if KeePassLibSD
using KeePassLibSD;
#endif
namespace ModernKeePassLib.Serialization
namespace ModernKeePassLibPCL.Serialization
{
public sealed class HashedBlockStream : Stream
{
@@ -98,8 +99,8 @@ namespace ModernKeePassLib.Serialization
private void Initialize(Stream sBaseStream, bool bWriting, int nBufferSize,
bool bVerify)
{
if (sBaseStream == null) throw new ArgumentNullException(nameof(sBaseStream));
m_sBaseStream = sBaseStream;
if (sBaseStream != null) m_sBaseStream = sBaseStream;
else throw new ArgumentNullException(nameof(sBaseStream));
if (nBufferSize < 0)
throw new ArgumentOutOfRangeException(nameof(nBufferSize));
@@ -134,7 +135,7 @@ namespace ModernKeePassLib.Serialization
if(m_bWriting) m_bwOutput.Flush();
}
#if PCL || KeePassRT
#if ModernKeePassLibPCL || KeePassRT
protected override void Dispose(bool disposing)
{
if(!disposing) return;
@@ -221,11 +222,11 @@ namespace ModernKeePassLib.Serialization
throw new InvalidDataException();
int nBufferSize = 0;
/*try {*/ nBufferSize = m_brInput.ReadInt32(); /*}
try { nBufferSize = m_brInput.ReadInt32(); }
catch(NullReferenceException) // Mono bug workaround (LaunchPad 783268)
{
if(!NativeLib.IsUnix()) throw;
}*/
}
if(nBufferSize < 0)
throw new InvalidDataException();
@@ -249,16 +250,16 @@ namespace ModernKeePassLib.Serialization
if(m_bVerify)
{
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var pbComputedHash = sha256.HashData(m_pbBuffer.AsBuffer()).ToArray();
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbComputedHash = sha256.HashData(m_pbBuffer);
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] pbComputedHash = sha256.ComputeHash(m_pbBuffer);
#endif
if((pbComputedHash == null) || (pbComputedHash.Length != 32))
throw new InvalidOperationException();
for(int iHashPos = 0; iHashPos < 32; ++iHashPos)
{
if(pbStoredHash[iHashPos] != pbComputedHash[iHashPos])
@@ -296,9 +297,9 @@ namespace ModernKeePassLib.Serialization
if(m_nBufferPos > 0)
{
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var pbHash = sha256.HashData(m_pbBuffer.Where((x, i) => i < m_nBufferPos).ToArray().AsBuffer()).ToArray();
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbHash = sha256.HashData(m_pbBuffer.Where((x, i) => i < m_nBufferPos).ToArray());
#else
SHA256Managed sha256 = new SHA256Managed();

View File

@@ -19,31 +19,28 @@
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Reflection;
using System.Diagnostics;
#if (!PCL && !KeePassLibSD && !KeePassRT)
using Windows.Storage.Streams;
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
using System.Net.Cache;
using System.Net.Security;
#endif
#if !PCL && !KeePassRT
#if !ModernKeePassLibPCL && !KeePassRT
using System.Security.Cryptography.X509Certificates;
#endif
#if PCL
#if ModernKeePassLibPCL
using Windows.Storage;
using PCLStorage;
#endif
using ModernKeePassLibPCL.Utility;
using ModernKeePassLib.Utility;
namespace ModernKeePassLib.Serialization
namespace ModernKeePassLibPCL.Serialization
{
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
internal sealed class IOWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
@@ -55,7 +52,7 @@ namespace ModernKeePassLib.Serialization
}
#endif
#if !PCL
#if !ModernKeePassLibPCL
internal abstract class WrapperStream : Stream
{
private readonly Stream m_s;
@@ -228,7 +225,7 @@ namespace ModernKeePassLib.Serialization
public static class IOConnection
{
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
private static ProxyServerType m_pstProxyType = ProxyServerType.System;
private static string m_strProxyAddr = string.Empty;
private static string m_strProxyPort = string.Empty;
@@ -252,7 +249,7 @@ namespace ModernKeePassLib.Serialization
public static event EventHandler<IOAccessEventArgs> IOAccessPre;
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
// Allow self-signed certificates, expired certificates, etc.
private static bool AcceptCertificate(object sender,
X509Certificate certificate, X509Chain chain,
@@ -434,17 +431,20 @@ namespace ModernKeePassLib.Serialization
private static Stream OpenReadLocal(IOConnectionInfo ioc)
{
#if PCL
/*var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
return file.OpenAsync(PCLStorage.FileAccess.Read).Result;*/
return ioc.StorageFile.OpenAsync(FileAccessMode.Read).GetResults().AsStream();
#if ModernKeePassLibPCL
if (ioc.StorageFile != null)
{
return ioc.StorageFile.OpenAsync(FileAccessMode.Read).GetResults().AsStream();
}
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
return file.OpenAsync(PCLStorage.FileAccess.Read).Result;
#else
return new FileStream(ioc.Path, FileMode.Open, FileAccess.Read,
FileShare.Read);
#endif
}
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
public static Stream OpenWrite(IOConnectionInfo ioc)
{
if(ioc == null) { Debug.Assert(false); return null; }
@@ -477,15 +477,18 @@ namespace ModernKeePassLib.Serialization
private static Stream OpenWriteLocal(IOConnectionInfo ioc)
{
#if PCL
return ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite).GetResults().AsStream();
/*var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
return file.OpenAsync(FileAccess.ReadAndWrite).Result;*/
#if ModernKeePassLibPCL
if (ioc.StorageFile != null)
{
return ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite).GetResults().AsStream();
}
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
return file.OpenAsync(FileAccess.ReadAndWrite).Result;
#else
return new FileStream(ioc.Path, FileMode.Create, FileAccess.Write,
FileShare.None);
#endif
}
}
public static bool FileExists(IOConnectionInfo ioc)
{
@@ -498,14 +501,14 @@ namespace ModernKeePassLib.Serialization
RaiseIOAccessPreEvent(ioc, IOAccessType.Exists);
#if PCL
#if ModernKeePassLibPCL
if(ioc.IsLocalFile())
return ioc.StorageFile.IsAvailable;
return (FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result != null);
#else
if(ioc.IsLocalFile()) return File.Exists(ioc.Path);
#endif
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
if(ioc.Path.StartsWith("ftp://", StrUtil.CaseIgnoreCmp))
{
bool b = SendCommand(ioc, WebRequestMethods.Ftp.GetDateTimestamp);
@@ -540,17 +543,16 @@ namespace ModernKeePassLib.Serialization
{
RaiseIOAccessPreEvent(ioc, IOAccessType.Delete);
#if PCL
if(ioc.IsLocalFile()) {
/*var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
file.DeleteAsync().RunSynchronously();*/
ioc.StorageFile.DeleteAsync(StorageDeleteOption.Default).GetResults();
}
#if ModernKeePassLibPCL
if (!ioc.IsLocalFile()) return;
ioc.StorageFile?.DeleteAsync().GetResults();
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
file.DeleteAsync().RunSynchronously();
#else
if(ioc.IsLocalFile()) { File.Delete(ioc.Path); return; }
#endif
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
WebRequest req = CreateWebRequest(ioc);
if(req != null)
{
@@ -582,18 +584,16 @@ namespace ModernKeePassLib.Serialization
{
RaiseIOAccessPreEvent(iocFrom, iocTo, IOAccessType.Move);
#if PCL
if(iocFrom.IsLocalFile()) {
/*var file = FileSystem.Current.GetFileFromPathAsync(iocFrom.Path).Result;
file.MoveAsync(iocTo.Path).RunSynchronously();*/
iocFrom.StorageFile.RenameAsync(iocTo.Path).GetResults();
return;
}
#if ModernKeePassLibPCL
if (!iocFrom.IsLocalFile()) return;
iocFrom.StorageFile?.RenameAsync(iocTo.Path).GetResults();
var file = FileSystem.Current.GetFileFromPathAsync(iocFrom.Path).Result;
file.MoveAsync(iocTo.Path).RunSynchronously();
#else
if(iocFrom.IsLocalFile()) { File.Move(iocFrom.Path, iocTo.Path); return; }
#endif
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
WebRequest req = CreateWebRequest(iocFrom);
if(req != null)
{
@@ -642,7 +642,7 @@ namespace ModernKeePassLib.Serialization
// DeleteFile(iocFrom);
}
#if (!PCL && !KeePassLibSD && !KeePassRT)
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
private static bool SendCommand(IOConnectionInfo ioc, string strMethod)
{
try

View File

@@ -25,15 +25,15 @@ using System.Net;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Diagnostics;
#if PCL
using Windows.Storage;
#if ModernKeePassLibPCL
using PCLStorage;
#endif
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Serialization
namespace ModernKeePassLibPCL.Serialization
{
public enum IOCredSaveMode
{
@@ -67,11 +67,9 @@ namespace ModernKeePassLib.Serialization
public sealed class IOConnectionInfo : IDeepCloneable<IOConnectionInfo>
{
// private IOFileFormatHint m_ioHint = IOFileFormatHint.None;
// private IOFileFormatHint m_ioHint = IOFileFormatHint.None;
public StorageFile StorageFile { get; set; }
private string m_strUrl = string.Empty;
private string m_strUrl = string.Empty;
public string Path
{
get { return m_strUrl; }
@@ -295,23 +293,24 @@ namespace ModernKeePassLib.Serialization
return ioc;
}
public static IOConnectionInfo FromFile(StorageFile file)
{
IOConnectionInfo ioc = new IOConnectionInfo();
public static IOConnectionInfo FromFile(StorageFile file)
{
IOConnectionInfo ioc = new IOConnectionInfo();
ioc.Path = file.Path;
ioc.CredSaveMode = IOCredSaveMode.NoSave;
ioc.StorageFile = file;
ioc.StorageFile = file;
ioc.Path = file.Path;
ioc.CredSaveMode = IOCredSaveMode.NoSave;
return ioc;
}
return ioc;
}
public StorageFile StorageFile { get; set; }
public bool CanProbablyAccess()
{
#if PCL
#if ModernKeePassLibPCL
if(IsLocalFile())
return (StorageFile.IsAvailable);
return (FileSystem.Current.GetFileFromPathAsync(m_strUrl).Result != null);
#else
if(IsLocalFile()) return File.Exists(m_strUrl);
#endif

View File

@@ -21,20 +21,21 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Security;
using System.Drawing;
using System.Xml;
using System.IO;
using System.Diagnostics;
using ModernKeePassLib;
using ModernKeePassLib.Collections;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Cryptography.Cipher;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL;
using ModernKeePassLibPCL.Collections;
using ModernKeePassLibPCL.Cryptography;
using ModernKeePassLibPCL.Cryptography.Cipher;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Serialization
namespace ModernKeePassLibPCL.Serialization
{
/// <summary>
/// Serialization to KeePass KDBX files.
@@ -98,7 +99,7 @@ namespace ModernKeePassLib.Serialization
xrs.IgnoreProcessingInstructions = true;
xrs.IgnoreWhitespace = true;
#if !PCL
#if !ModernKeePassLibPCL
// these are default values, so no need to set them
#if !KeePassRT
#if !KeePassLibSD
@@ -241,8 +242,8 @@ namespace ModernKeePassLib.Serialization
else if(xr.Name == ElemDbColor)
{
string strColor = ReadString(xr);
/*if(!string.IsNullOrEmpty(strColor))
m_pwDatabase.Color = ColorTranslator.FromHtml(strColor);*/
if(!string.IsNullOrEmpty(strColor))
m_pwDatabase.Color = ColorTranslator.FromHtml(strColor);
}
else if(xr.Name == ElemDbKeyChanged)
m_pwDatabase.MasterKeyChanged = ReadTime(xr);
@@ -413,14 +414,14 @@ namespace ModernKeePassLib.Serialization
else if(xr.Name == ElemFgColor)
{
string strColor = ReadString(xr);
/*if(!string.IsNullOrEmpty(strColor))
m_ctxEntry.ForegroundColor = ColorTranslator.FromHtml(strColor);*/
if(!string.IsNullOrEmpty(strColor))
m_ctxEntry.ForegroundColor = ColorTranslator.FromHtml(strColor);
}
else if(xr.Name == ElemBgColor)
{
string strColor = ReadString(xr);
/*if(!string.IsNullOrEmpty(strColor))
m_ctxEntry.BackgroundColor = ColorTranslator.FromHtml(strColor);*/
if(!string.IsNullOrEmpty(strColor))
m_ctxEntry.BackgroundColor = ColorTranslator.FromHtml(strColor);
}
else if(xr.Name == ElemOverrideUrl)
m_ctxEntry.OverrideUrl = ReadString(xr);
@@ -689,7 +690,7 @@ namespace ModernKeePassLib.Serialization
}
m_bReadNextNode = false; // ReadElementString skips end tag
#if PCL
#if ModernKeePassLibPCL
return xr.ReadElementContentAsString();
#else
return xr.ReadElementString();
@@ -699,7 +700,7 @@ namespace ModernKeePassLib.Serialization
private string ReadStringRaw(XmlReader xr)
{
m_bReadNextNode = false; // ReadElementString skips end tag
#if PCL
#if ModernKeePassLibPCL
return xr.ReadElementContentAsString();
#else
return xr.ReadElementString();

View File

@@ -22,29 +22,28 @@ using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Security;
#if PCL
using Windows.Security.Cryptography;
#if ModernKeePassLibPCL
using PCLCrypto;
#else
using System.Security.Cryptography;
#endif
using System.Xml;
using Windows.Security.Cryptography.Core;
#if !KeePassLibSD
using System.IO.Compression;
#else
using KeePassLibSD;
#endif
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Cryptography.Cipher;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Keys;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Cryptography;
using ModernKeePassLibPCL.Cryptography.Cipher;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Keys;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Serialization
namespace ModernKeePassLibPCL.Serialization
{
/// <summary>
/// Serialization to KeePass KDBX files.
@@ -155,7 +154,7 @@ namespace ModernKeePassLib.Serialization
// GC.KeepAlive(br);
// GC.KeepAlive(brDecrypted);
}
#if !PCL
#if !ModernKeePassLibPCL
catch(CryptographicException) // Thrown on invalid padding
{
throw new CryptographicException(KLRes.FileCorrupted);
@@ -221,9 +220,9 @@ namespace ModernKeePassLib.Serialization
byte[] pbHeader = msHeader.ToArray();
msHeader.Dispose();
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
m_pbHashOfHeader = sha256.HashData(pbHeader.AsBuffer()).ToArray();
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
m_pbHashOfHeader = sha256.HashData(pbHeader);
#else
SHA256Managed sha256 = new SHA256Managed();
m_pbHashOfHeader = sha256.ComputeHash(pbHeader);
@@ -333,39 +332,46 @@ namespace ModernKeePassLib.Serialization
m_craInnerRandomStream = (CrsAlgorithm)uID;
}
private Stream AttachStreamDecryptor(Stream s)
{
using (var ms = new MemoryStream())
{
Debug.Assert(m_pbMasterSeed.Length == 32);
if (m_pbMasterSeed.Length != 32)
throw new FormatException(KLRes.MasterSeedLengthInvalid);
ms.Write(m_pbMasterSeed, 0, 32);
private Stream AttachStreamDecryptor(Stream s)
{
MemoryStream ms = new MemoryStream();
byte[] pKey32 = m_pwDatabase.MasterKey.GenerateKey32(m_pbTransformSeed,
m_pwDatabase.KeyEncryptionRounds).ReadData();
if (pKey32 == null || pKey32.Length != 32)
throw new SecurityException(KLRes.InvalidCompositeKey);
ms.Write(pKey32, 0, 32);
Debug.Assert(m_pbMasterSeed.Length == 32);
if(m_pbMasterSeed.Length != 32)
throw new FormatException(KLRes.MasterSeedLengthInvalid);
ms.Write(m_pbMasterSeed, 0, 32);
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var aesKey = sha256.HashData(ms.GetWindowsRuntimeBuffer()).ToArray();
byte[] pKey32 = m_pwDatabase.MasterKey.GenerateKey32(m_pbTransformSeed,
m_pwDatabase.KeyEncryptionRounds).ReadData();
if((pKey32 == null) || (pKey32.Length != 32))
throw new SecurityException(KLRes.InvalidCompositeKey);
ms.Write(pKey32, 0, 32);
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var aesKey = sha256.HashData(ms.ToArray());
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] aesKey = sha256.ComputeHash(ms.ToArray());
#endif
Array.Clear(pKey32, 0, 32);
if (aesKey == null || aesKey.Length != 32)
throw new SecurityException(KLRes.FinalKeyCreationFailed);
ms.Dispose();
Array.Clear(pKey32, 0, 32);
if((aesKey == null) || (aesKey.Length != 32))
throw new SecurityException(KLRes.FinalKeyCreationFailed);
ICipherEngine iEngine = CipherPool.GlobalPool.GetCipher(m_pwDatabase.DataCipherUuid);
if(iEngine == null) throw new SecurityException(KLRes.FileUnknownCipher);
return iEngine.DecryptStream(s, aesKey, m_pbEncryptionIV);
}
[Obsolete]
public static List<PwEntry> ReadEntries(PwDatabase pwDatabase, Stream msData)
{
return ReadEntries(msData);
}
ICipherEngine iEngine = CipherPool.GlobalPool.GetCipher(m_pwDatabase.DataCipherUuid);
if (iEngine == null) throw new SecurityException(KLRes.FileUnknownCipher);
return iEngine.DecryptStream(s, aesKey, m_pbEncryptionIV);
}
}
/// <summary>
/// Read entries from a stream.
/// </summary>

View File

@@ -23,32 +23,32 @@ using System.Text;
using System.IO;
using System.Xml;
using System.Security;
#if PCL
using Windows.Security.Cryptography;
#if ModernKeePassLibPCL
using PCLCrypto;
#else
using System.Security.Cryptography;
#endif
using System.Drawing;
using System.Globalization;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Security.Cryptography.Core;
#if !KeePassLibSD
using System.IO.Compression;
#else
using KeePassLibSD;
#endif
using ModernKeePassLib.Collections;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Cryptography.Cipher;
using ModernKeePassLib.Delegates;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Keys;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Collections;
using ModernKeePassLibPCL.Cryptography;
using ModernKeePassLibPCL.Cryptography.Cipher;
using ModernKeePassLibPCL.Delegates;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Keys;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Serialization
namespace ModernKeePassLibPCL.Serialization
{
/// <summary>
/// Serialization to KeePass KDBX files.
@@ -124,7 +124,7 @@ namespace ModernKeePassLib.Serialization
writerStream = hashedStream;
else { Debug.Assert(false); throw new FormatException("KdbFormat"); }
#if PCL
#if ModernKeePassLibPCL
var settings = new XmlWriterSettings() {
Encoding = encNoBom,
Indent = true,
@@ -188,9 +188,9 @@ namespace ModernKeePassLib.Serialization
byte[] pbHeader = ms.ToArray();
ms.Dispose();
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
m_pbHashOfHeader = sha256.HashData(pbHeader.AsBuffer()).ToArray();
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
m_pbHashOfHeader = sha256.HashData(pbHeader);
#else
SHA256Managed sha256 = new SHA256Managed();
m_pbHashOfHeader = sha256.ComputeHash(pbHeader);
@@ -235,9 +235,9 @@ namespace ModernKeePassLib.Serialization
throw new SecurityException(KLRes.InvalidCompositeKey);
ms.Write(pKey32, 0, 32);
#if PCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var aesKey = sha256.HashData(ms.GetWindowsRuntimeBuffer()).ToArray();
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var aesKey = sha256.HashData(ms.ToArray());
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] aesKey = sha256.ComputeHash(ms.ToArray());
@@ -264,7 +264,7 @@ namespace ModernKeePassLib.Serialization
BinPoolBuild(pgRoot);
#if !PCL
#if !ModernKeePassLibPCL
m_xmlWriter.Formatting = Formatting.Indented;
m_xmlWriter.IndentChar = '\t';
m_xmlWriter.Indentation = 1;

View File

@@ -29,18 +29,18 @@ using System.Diagnostics;
using System.IO.Compression;
#endif
#if PCL
using Windows.Storage;
#if ModernKeePassLibPCL
using PCLStorage;
#endif
using ModernKeePassLib.Collections;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Delegates;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Collections;
using ModernKeePassLibPCL.Cryptography;
using ModernKeePassLibPCL.Delegates;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Serialization
namespace ModernKeePassLibPCL.Serialization
{
/// <summary>
/// The <c>KdbxFile</c> class supports saving the data to various
@@ -195,7 +195,7 @@ namespace ModernKeePassLib.Serialization
private PwDatabase m_pwDatabase; // Not null, see constructor
#if PCL
#if ModernKeePassLibPCL
private XmlWriter m_xmlWriter = null;
#else
private XmlTextWriter m_xmlWriter = null;
@@ -383,16 +383,16 @@ namespace ModernKeePassLib.Serialization
++iTry;
}
#if PCL
while(ApplicationData.Current.RoamingFolder.GetFileAsync(strPath).GetResults() != null);
#if ModernKeePassLibPCL
while(FileSystem.Current.GetFileFromPathAsync(strPath).Result != null);
#else
while(File.Exists(strPath));
#endif
#if PCL
#if ModernKeePassLibPCL
byte[] pbData = pb.ReadData();
var file = ApplicationData.Current.RoamingFolder.GetFileAsync(strPath).GetResults();
using (var stream = file.OpenAsync(FileAccessMode.ReadWrite).GetResults().AsStream()) {
var file = FileSystem.Current.GetFileFromPathAsync(strPath).Result;
using (var stream = file.OpenAsync(FileAccess.ReadAndWrite).Result) {
stream.Write (pbData, 0, pbData.Length);
}
MemUtil.ZeroByteArray(pbData);

View File

@@ -21,10 +21,10 @@ using System;
using System.Collections.Generic;
using System.Text;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Serialization
namespace ModernKeePassLibPCL.Serialization
{
public sealed class OldFormatException : Exception
{

View File

@@ -21,14 +21,17 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Globalization;
using System.IO;
using System.Security.Cryptography;
using System.Drawing;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Translation
namespace ModernKeePassLibPCL.Translation
{
public sealed class KpccLayout
{

View File

@@ -25,7 +25,7 @@ using System.Xml.Serialization;
using System.Diagnostics;
using System.Reflection;
namespace ModernKeePassLib.Translation
namespace ModernKeePassLibPCL.Translation
{
public sealed class KPFormCustomization
{

View File

@@ -24,7 +24,7 @@ using System.Xml.Serialization;
using System.Windows.Forms;
using System.Diagnostics;
namespace ModernKeePassLib.Translation
namespace ModernKeePassLibPCL.Translation
{
public sealed class KPStringTable
{

View File

@@ -22,7 +22,7 @@ using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
namespace ModernKeePassLib.Translation
namespace ModernKeePassLibPCL.Translation
{
public sealed class KPStringTableItem
{

View File

@@ -28,8 +28,8 @@ using System.ComponentModel;
using System.Drawing;
using System.Diagnostics;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Utility;
using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Utility;
#if !KeePassLibSD
using System.IO.Compression;
@@ -37,7 +37,7 @@ using System.IO.Compression;
using ICSharpCode.SharpZipLib.GZip;
#endif
namespace ModernKeePassLib.Translation
namespace ModernKeePassLibPCL.Translation
{
[XmlRoot("Translation")]
public sealed class KPTranslation

View File

@@ -21,7 +21,7 @@ using System;
using System.Collections.Generic;
using System.Text;
namespace ModernKeePassLib.Translation
namespace ModernKeePassLibPCL.Translation
{
public sealed class KPTranslationProperties
{

View File

@@ -27,7 +27,7 @@ using System.Diagnostics;
using System.IO.Compression;
#endif
namespace ModernKeePassLib.Utility
namespace ModernKeePassLibPCL.Utility
{
/// <summary>
/// Application-wide logging services.

View File

@@ -3,7 +3,7 @@ using System.Drawing;
using System.Globalization;
using System.Text.RegularExpressions;
namespace KeePass2PCL.Utility
namespace ModernKeePassLibPCL.Utility
{
/// <summary>
/// Replacement for System.Drawing.ColorTranslator.

View File

@@ -21,7 +21,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
#if KeePass2PCL
#if ModernKeePassLibPCL
using Splat;
#else
using System.Drawing;
@@ -29,7 +29,7 @@ using System.Drawing.Imaging;
#endif
using System.Diagnostics;
namespace KeePass2PCL.Utility
namespace ModernKeePassLibPCL.Utility
{
public static class GfxUtil
{
@@ -40,7 +40,7 @@ namespace KeePass2PCL.Utility
try { return Image.FromStream(ms); }
finally { ms.Close(); }
}
#elif KeePass2PCL
#elif ModernKeePassLibPCL
public static IBitmap LoadImage(byte[] pb)
{
using (var ms = new MemoryStream(pb, false)) {

View File

@@ -29,7 +29,7 @@ using System.IO.Compression;
using KeePassLibSD;
#endif
namespace ModernKeePassLib.Utility
namespace ModernKeePassLibPCL.Utility
{
/// <summary>
/// Contains static buffer manipulation and string conversion routines.

View File

@@ -24,10 +24,10 @@ using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Serialization;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Serialization;
namespace ModernKeePassLib.Utility
namespace ModernKeePassLibPCL.Utility
{
public sealed class MessageServiceEventArgs : EventArgs
{

View File

@@ -25,9 +25,9 @@ using System.ComponentModel;
using System.Reflection;
using System.Diagnostics;
using KeePass2PCL.Native;
using ModernKeePassLibPCL.Native;
namespace KeePass2PCL.Utility
namespace ModernKeePassLibPCL.Utility
{
public static class MonoWorkarounds
{

Some files were not shown because too many files have changed in this diff Show More