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

View File

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

View File

@@ -159,14 +159,50 @@
</Page> </Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ModernKeePassLib, Version=2.36.0.27373, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="ModernKeePassLibPCL, Version=2.28.1.32947, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ModernKeePassLib.2.36.0.27373\lib\netstandard1.2\ModernKeePassLib.dll</HintPath> <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> <Private>True</Private>
</Reference> </Reference>
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <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> <HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\win8\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </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 /> <ItemGroup />
<ItemGroup> <ItemGroup>

View File

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

View File

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

View File

@@ -4,11 +4,19 @@
<package id="Microsoft.Bcl.Compression" version="3.9.85" targetFramework="win81" /> <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.Platforms" version="2.0.0" targetFramework="win81" />
<package id="Microsoft.NETCore.Portable.Compatibility" version="1.0.2" 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="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.Net.Requests" version="4.3.0" targetFramework="win81" />
<package id="System.Runtime.InteropServices.RuntimeInformation" 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.Runtime.WindowsRuntime" version="4.3.0" targetFramework="win81" />
<package id="System.Xml.ReaderWriter" 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="System.Xml.XmlSerializer" version="4.3.0" targetFramework="win81" />
<package id="Validation" version="2.4.15" targetFramework="win81" />
</packages> </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.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using ModernKeePassLib.Interfaces; using ModernKeePassLibPCL.Interfaces;
namespace ModernKeePassLib.Collections namespace ModernKeePassLibPCL.Collections
{ {
[Flags] [Flags]
public enum AutoTypeObfuscationOptions public enum AutoTypeObfuscationOptions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -23,7 +23,7 @@ using System.Text;
using System.IO; using System.IO;
using System.Xml; using System.Xml;
namespace ModernKeePassLib.Interfaces namespace ModernKeePassLibPCL.Interfaces
{ {
public interface IXmlSerializerEx 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.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.InteropServices.WindowsRuntime; #if ModernKeePassLibPCL
using Windows.Security.Cryptography.Core; using PCLCrypto;
using Windows.Security.ExchangeActiveSyncProvisioning;
#if PCL
using Windows.Security.Cryptography;
#else #else
using System.Security.Cryptography; using System.Security.Cryptography;
#endif #endif
using ModernKeePassLib.Resources; #if KeePassRT
using ModernKeePassLib.Security; using Org.BouncyCastle.Crypto.Engines;
using ModernKeePassLib.Utility; 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> /// <summary>
/// Represents a key. A key can be build up using several user key data sources /// 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, /// like a password, a key file, the currently logged on user credentials,
/// the current computer ID, etc. /// the current computer ID, etc.
/// </summary> /// </summary>
public sealed class CompositeKey public sealed class CompositeKey
{ {
private List<IUserKey> m_vUserKeys = new List<IUserKey>(); private List<IUserKey> m_vUserKeys = new List<IUserKey>();
/// <summary> /// <summary>
/// List of all user keys contained in the current composite key. /// List of all user keys contained in the current composite key.
/// </summary> /// </summary>
public IEnumerable<IUserKey> UserKeys public IEnumerable<IUserKey> UserKeys
{ {
get { return m_vUserKeys; } get { return m_vUserKeys; }
} }
public uint UserKeyCount public uint UserKeyCount
{ {
get { return (uint) m_vUserKeys.Count; } get { return (uint)m_vUserKeys.Count; }
} }
/// <summary> /// <summary>
/// Construct a new, empty key object. /// Construct a new, empty key object.
/// </summary> /// </summary>
public CompositeKey() public CompositeKey()
{ {
} }
// /// <summary> // /// <summary>
// /// Deconstructor, clears up the key. // /// Deconstructor, clears up the key.
// /// </summary> // /// </summary>
// ~CompositeKey() // ~CompositeKey()
// { // {
// Clear(); // Clear();
// } // }
// /// <summary> // /// <summary>
// /// Clears the key. This function also erases all previously stored // /// Clears the key. This function also erases all previously stored
// /// user key data objects. // /// user key data objects.
// /// </summary> // /// </summary>
// public void Clear() // public void Clear()
// { // {
// foreach(IUserKey pKey in m_vUserKeys) // foreach(IUserKey pKey in m_vUserKeys)
// pKey.Clear(); // pKey.Clear();
// m_vUserKeys.Clear(); // m_vUserKeys.Clear();
// } // }
/// <summary> /// <summary>
/// Add a user key. /// Add a user key.
/// </summary> /// </summary>
/// <param name="pKey">User key to add.</param> /// <param name="pKey">User key to add.</param>
public void AddUserKey(IUserKey pKey) public void AddUserKey(IUserKey pKey)
{ {
Debug.Assert(pKey != null); Debug.Assert(pKey != null); if(pKey == null) throw new ArgumentNullException("pKey");
if (pKey == null) throw new ArgumentNullException("pKey");
m_vUserKeys.Add(pKey); m_vUserKeys.Add(pKey);
} }
/// <summary> /// <summary>
/// Remove a user key. /// Remove a user key.
/// </summary> /// </summary>
/// <param name="pKey">User key to remove.</param> /// <param name="pKey">User key to remove.</param>
/// <returns>Returns <c>true</c> if the key was removed successfully.</returns> /// <returns>Returns <c>true</c> if the key was removed successfully.</returns>
public bool RemoveUserKey(IUserKey pKey) public bool RemoveUserKey(IUserKey pKey)
{ {
Debug.Assert(pKey != null); Debug.Assert(pKey != null); if(pKey == null) throw new ArgumentNullException("pKey");
if (pKey == null) throw new ArgumentNullException("pKey");
Debug.Assert(m_vUserKeys.IndexOf(pKey) >= 0); Debug.Assert(m_vUserKeys.IndexOf(pKey) >= 0);
return m_vUserKeys.Remove(pKey); return m_vUserKeys.Remove(pKey);
} }
#if !PCL && !KeePassRT /// <summary> #if !ModernKeePassLibPCL && !KeePassRT
/// Test whether the composite key contains a specific type of /// <summary>
/// user keys (password, key file, ...). If at least one user /// Test whether the composite key contains a specific type of
/// key of that type is present, the function returns <c>true</c>. /// user keys (password, key file, ...). If at least one user
/// </summary> /// key of that type is present, the function returns <c>true</c>.
/// <param name="tUserKeyType">User key type.</param> /// </summary>
/// <returns>Returns <c>true</c>, if the composite key contains /// <param name="tUserKeyType">User key type.</param>
/// a user key of the specified type.</returns> /// <returns>Returns <c>true</c>, if the composite key contains
/// a user key of the specified type.</returns>
public bool ContainsType(Type tUserKeyType) public bool ContainsType(Type tUserKeyType)
{ {
Debug.Assert(tUserKeyType != null); Debug.Assert(tUserKeyType != null);
@@ -154,91 +156,85 @@ namespace ModernKeePassLib.Keys
} }
#endif #endif
/// <summary> /// <summary>
/// Creates the composite key from the supplied user key sources (password, /// Creates the composite key from the supplied user key sources (password,
/// key file, user account, computer ID, etc.). /// key file, user account, computer ID, etc.).
/// </summary> /// </summary>
private byte[] CreateRawCompositeKey32() private byte[] CreateRawCompositeKey32()
{ {
ValidateUserKeys(); ValidateUserKeys();
// Concatenate user key data // Concatenate user key data
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
foreach (IUserKey pKey in m_vUserKeys) foreach(IUserKey pKey in m_vUserKeys)
{ {
ProtectedBinary b = pKey.KeyData; ProtectedBinary b = pKey.KeyData;
if (b != null) if(b != null)
{ {
byte[] pbKeyData = b.ReadData(); byte[] pbKeyData = b.ReadData();
ms.Write(pbKeyData, 0, pbKeyData.Length); ms.Write(pbKeyData, 0, pbKeyData.Length);
MemUtil.ZeroByteArray(pbKeyData); MemUtil.ZeroByteArray(pbKeyData);
} }
} }
#if PCL #if ModernKeePassLibPCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256); var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbHash = sha256.HashData(ms.ToArray().AsBuffer()).ToArray(); var pbHash = sha256.HashData(ms.ToArray());
#else #else
SHA256Managed sha256 = new SHA256Managed(); SHA256Managed sha256 = new SHA256Managed();
byte[] pbHash = sha256.ComputeHash(ms.ToArray()); byte[] pbHash = sha256.ComputeHash(ms.ToArray());
#endif #endif
ms.Dispose(); ms.Dispose();
return pbHash; return pbHash;
} }
public bool EqualsValue(CompositeKey ckOther) public bool EqualsValue(CompositeKey ckOther)
{ {
if (ckOther == null) throw new ArgumentNullException("ckOther"); if(ckOther == null) throw new ArgumentNullException("ckOther");
byte[] pbThis = CreateRawCompositeKey32(); byte[] pbThis = CreateRawCompositeKey32();
byte[] pbOther = ckOther.CreateRawCompositeKey32(); byte[] pbOther = ckOther.CreateRawCompositeKey32();
bool bResult = MemUtil.ArraysEqual(pbThis, pbOther); bool bResult = MemUtil.ArraysEqual(pbThis, pbOther);
Array.Clear(pbOther, 0, pbOther.Length); Array.Clear(pbOther, 0, pbOther.Length);
Array.Clear(pbThis, 0, pbThis.Length); Array.Clear(pbThis, 0, pbThis.Length);
return bResult; return bResult;
} }
/// <summary> /// <summary>
/// Generate a 32-bit wide key out of the composite key. /// Generate a 32-bit wide key out of the composite key.
/// </summary> /// </summary>
/// <param name="pbKeySeed32">Seed used in the key transformation /// <param name="pbKeySeed32">Seed used in the key transformation
/// rounds. Must be a byte array containing exactly 32 bytes; must /// rounds. Must be a byte array containing exactly 32 bytes; must
/// not be null.</param> /// not be null.</param>
/// <param name="uNumRounds">Number of key transformation rounds.</param> /// <param name="uNumRounds">Number of key transformation rounds.</param>
/// <returns>Returns a protected binary object that contains the /// <returns>Returns a protected binary object that contains the
/// resulting 32-bit wide key.</returns> /// resulting 32-bit wide key.</returns>
public ProtectedBinary GenerateKey32(byte[] pbKeySeed32, ulong uNumRounds) public ProtectedBinary GenerateKey32(byte[] pbKeySeed32, ulong uNumRounds)
{ {
Debug.Assert(pbKeySeed32 != null); Debug.Assert(pbKeySeed32 != null);
if (pbKeySeed32 == null) throw new ArgumentNullException("pbKeySeed32"); if(pbKeySeed32 == null) throw new ArgumentNullException("pbKeySeed32");
Debug.Assert(pbKeySeed32.Length == 32); Debug.Assert(pbKeySeed32.Length == 32);
if (pbKeySeed32.Length != 32) throw new ArgumentException("pbKeySeed32"); if(pbKeySeed32.Length != 32) throw new ArgumentException("pbKeySeed32");
byte[] pbRaw32 = CreateRawCompositeKey32(); byte[] pbRaw32 = CreateRawCompositeKey32();
if ((pbRaw32 == null) || (pbRaw32.Length != 32)) if((pbRaw32 == null) || (pbRaw32.Length != 32))
{ { Debug.Assert(false); return null; }
Debug.Assert(false);
return null;
}
byte[] pbTrf32 = TransformKey(pbRaw32, pbKeySeed32, uNumRounds); byte[] pbTrf32 = TransformKey(pbRaw32, pbKeySeed32, uNumRounds);
if ((pbTrf32 == null) || (pbTrf32.Length != 32)) if((pbTrf32 == null) || (pbTrf32.Length != 32))
{ { Debug.Assert(false); return null; }
Debug.Assert(false);
return null;
}
ProtectedBinary pbRet = new ProtectedBinary(true, pbTrf32); ProtectedBinary pbRet = new ProtectedBinary(true, pbTrf32);
MemUtil.ZeroByteArray(pbTrf32); MemUtil.ZeroByteArray(pbTrf32);
MemUtil.ZeroByteArray(pbRaw32); MemUtil.ZeroByteArray(pbRaw32);
return pbRet; return pbRet;
} }
private void ValidateUserKeys() private void ValidateUserKeys()
{ {
#if !PCL #if !ModernKeePassLibPCL
int nAccounts = 0; int nAccounts = 0;
foreach(IUserKey uKey in m_vUserKeys) foreach(IUserKey uKey in m_vUserKeys)
@@ -253,51 +249,52 @@ namespace ModernKeePassLib.Keys
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
#endif #endif
} }
/// <summary> /// <summary>
/// Transform the current key <c>uNumRounds</c> times. /// Transform the current key <c>uNumRounds</c> times.
/// </summary> /// </summary>
/// <param name="pbOriginalKey32">The original key which will be transformed. /// <param name="pbOriginalKey32">The original key which will be transformed.
/// This parameter won't be modified.</param> /// This parameter won't be modified.</param>
/// <param name="pbKeySeed32">Seed used for key transformations. Must not /// <param name="pbKeySeed32">Seed used for key transformations. Must not
/// be <c>null</c>. This parameter won't be modified.</param> /// be <c>null</c>. This parameter won't be modified.</param>
/// <param name="uNumRounds">Transformation count.</param> /// <param name="uNumRounds">Transformation count.</param>
/// <returns>256-bit transformed key.</returns> /// <returns>256-bit transformed key.</returns>
private static byte[] TransformKey(byte[] pbOriginalKey32, byte[] pbKeySeed32, private static byte[] TransformKey(byte[] pbOriginalKey32, byte[] pbKeySeed32,
ulong uNumRounds) ulong uNumRounds)
{ {
Debug.Assert((pbOriginalKey32 != null) && (pbOriginalKey32.Length == 32)); Debug.Assert((pbOriginalKey32 != null) && (pbOriginalKey32.Length == 32));
if (pbOriginalKey32 == null) throw new ArgumentNullException("pbOriginalKey32"); if(pbOriginalKey32 == null) throw new ArgumentNullException("pbOriginalKey32");
if (pbOriginalKey32.Length != 32) throw new ArgumentException(); if(pbOriginalKey32.Length != 32) throw new ArgumentException();
Debug.Assert((pbKeySeed32 != null) && (pbKeySeed32.Length == 32)); Debug.Assert((pbKeySeed32 != null) && (pbKeySeed32.Length == 32));
if (pbKeySeed32 == null) throw new ArgumentNullException("pbKeySeed32"); if(pbKeySeed32 == null) throw new ArgumentNullException("pbKeySeed32");
if (pbKeySeed32.Length != 32) throw new ArgumentException(); if(pbKeySeed32.Length != 32) throw new ArgumentException();
byte[] pbNewKey = new byte[32]; byte[] pbNewKey = new byte[32];
Array.Copy(pbOriginalKey32, pbNewKey, pbNewKey.Length); 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)) if(NativeLib.TransformKey256(pbNewKey, pbKeySeed32, uNumRounds))
return (new SHA256Managed()).ComputeHash(pbNewKey); return (new SHA256Managed()).ComputeHash(pbNewKey);
#endif #endif
if (TransformKeyManaged(pbNewKey, pbKeySeed32, uNumRounds) == false) if(TransformKeyManaged(pbNewKey, pbKeySeed32, uNumRounds) == false)
return null; return null;
#if PCL #if ModernKeePassLibPCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256); var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
return sha256.HashData(pbNewKey.AsBuffer()).ToArray(); return sha256.HashData(pbNewKey);
#else #else
SHA256Managed sha256 = new SHA256Managed(); SHA256Managed sha256 = new SHA256Managed();
return sha256.ComputeHash(pbNewKey); return sha256.ComputeHash(pbNewKey);
#endif #endif
} }
public static bool TransformKeyManaged(byte[] pbNewKey32, byte[] pbKeySeed32, public static bool TransformKeyManaged(byte[] pbNewKey32, byte[] pbKeySeed32,
ulong uNumRounds) ulong uNumRounds)
{ {
#if KeePassRT #if KeePassRT
KeyParameter kp = new KeyParameter(pbKeySeed32); KeyParameter kp = new KeyParameter(pbKeySeed32);
AesEngine aes = new AesEngine(); AesEngine aes = new AesEngine();
@@ -308,10 +305,11 @@ namespace ModernKeePassLib.Keys
aes.ProcessBlock(pbNewKey32, 0, pbNewKey32, 0); aes.ProcessBlock(pbNewKey32, 0, pbNewKey32, 0);
aes.ProcessBlock(pbNewKey32, 16, pbNewKey32, 16); aes.ProcessBlock(pbNewKey32, 16, pbNewKey32, 16);
} }
#elif PCL #else
var aes = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcb); #if ModernKeePassLibPCL
var key = aes.CreateSymmetricKey(pbKeySeed32.AsBuffer()); var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
//var iCrypt = CryptographicEngine.CreateEncryptor(key); var key = aes.CreateSymmetricKey(pbKeySeed32);
var iCrypt = WinRTCrypto.CryptographicEngine.CreateEncryptor(key);
#else #else
byte[] pbIV = new byte[16]; byte[] pbIV = new byte[16];
Array.Clear(pbIV, 0, pbIV.Length); Array.Clear(pbIV, 0, pbIV.Length);
@@ -330,29 +328,125 @@ namespace ModernKeePassLib.Keys
ICryptoTransform iCrypt = r.CreateEncryptor(); ICryptoTransform iCrypt = r.CreateEncryptor();
#endif #endif
// !iCrypt.CanReuseTransform -- doesn't work with Mono // !iCrypt.CanReuseTransform -- doesn't work with Mono
/*if ((iCrypt == null) || (iCrypt.InputBlockSize != 16) || if((iCrypt == null) || (iCrypt.InputBlockSize != 16) ||
(iCrypt.OutputBlockSize != 16))*/ (iCrypt.OutputBlockSize != 16))
if (aes.BlockLength != 16) {
{ Debug.Assert(false, "Invalid ICryptoTransform.");
Debug.Assert(false, "Invalid ICryptoTransform."); Debug.Assert((iCrypt.InputBlockSize == 16), "Invalid input block size!");
/*Debug.Assert((iCrypt.InputBlockSize == 16), "Invalid input block size!"); Debug.Assert((iCrypt.OutputBlockSize == 16), "Invalid output block size!");
Debug.Assert((iCrypt.OutputBlockSize == 16), "Invalid output block size!");*/ return false;
Debug.Assert(aes.BlockLength == 16, "Invalid input block size!"); }
return false;
}
for (ulong i = 0; i < uNumRounds; ++i) for(ulong i = 0; i < uNumRounds; ++i)
{ {
/*iCrypt.TransformBlock(pbNewKey32, 0, 16, pbNewKey32, 0); iCrypt.TransformBlock(pbNewKey32, 0, 16, pbNewKey32, 0);
iCrypt.TransformBlock(pbNewKey32, 16, 16, pbNewKey32, 16);*/ 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 public override string Message
{ {

View File

@@ -19,9 +19,9 @@
using System; using System;
using ModernKeePassLib.Security; using ModernKeePassLibPCL.Security;
namespace ModernKeePassLib.Keys namespace ModernKeePassLibPCL.Keys
{ {
/// <summary> /// <summary>
/// Interface to a user key, like a password, key file data, etc. /// 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.Collections.Generic;
using System.Text; using System.Text;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime; #if ModernKeePassLibPCL
using Windows.Security.Cryptography.Core; using PCLCrypto;
#if PCL
using Windows.Security.Cryptography;
#else #else
using System.Security.Cryptography; using System.Security.Cryptography;
#endif #endif
using ModernKeePassLib.Security; using ModernKeePassLibPCL.Security;
using ModernKeePassLib.Utility; using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Keys namespace ModernKeePassLibPCL.Keys
{ {
public sealed class KcpCustomKey : IUserKey public sealed class KcpCustomKey : IUserKey
{ {
@@ -61,14 +59,14 @@ namespace ModernKeePassLib.Keys
if(bPerformHash) if(bPerformHash)
{ {
#if PCL #if ModernKeePassLibPCL
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256); var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbRaw = sha256.HashData(pbKeyData.AsBuffer()); var pbRaw = sha256.HashData(pbKeyData);
#else #else
SHA256Managed sha256 = new SHA256Managed(); SHA256Managed sha256 = new SHA256Managed();
byte[] pbRaw = sha256.ComputeHash(pbKeyData); byte[] pbRaw = sha256.ComputeHash(pbKeyData);
#endif #endif
m_pbKey = new ProtectedBinary(true, pbRaw.ToArray()); m_pbKey = new ProtectedBinary(true, pbRaw);
} }
else m_pbKey = new ProtectedBinary(true, pbKeyData); else m_pbKey = new ProtectedBinary(true, pbKeyData);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -19,7 +19,7 @@
using System; using System;
namespace ModernKeePassLib.Keys namespace ModernKeePassLibPCL.Keys
{ {
[Flags] [Flags]
public enum UserKeyType 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 > <package >
<metadata> <metadata>
<id>ModernKeePassLib</id> <id>ModernKeePassLibPCL</id>
<version>2.19.2950</version> <version>2.28.1000</version>
<title>ModernKeePassLib</title> <title>ModernKeePassLibPCL</title>
<authors>Geoffroy Bonneville</authors> <authors>Geoffroy Bonneville</authors>
<owners>Geoffroy Bonneville</owners> <owners>Geoffroy Bonneville</owners>
<licenseUrl>https://www.gnu.org/licenses/gpl-3.0.en.html</licenseUrl> <licenseUrl>https://www.gnu.org/licenses/gpl-3.0.en.html</licenseUrl>
@@ -12,8 +12,8 @@
<description>Portable KeePass Password Management Library</description> <description>Portable KeePass Password Management Library</description>
<releaseNotes>Initial release.</releaseNotes> <releaseNotes>Initial release.</releaseNotes>
<copyright>Copyright © 2017 Geoffroy Bonneville</copyright> <copyright>Copyright © 2017 Geoffroy Bonneville</copyright>
<tags>KeePass KeePassLib NetStandard</tags> <tags>KeePass KeePassLib Portable</tags>
<dependencies> <!--<dependencies>
<group targetFramework=".NETStandard1.2"> <group targetFramework=".NETStandard1.2">
<dependency id="Microsoft.NETCore.Portable.Compatibility" version="1.0.2" exclude="Build,Analyzers" /> <dependency id="Microsoft.NETCore.Portable.Compatibility" version="1.0.2" exclude="Build,Analyzers" />
<dependency id="NETStandard.Library" version="2.0.0" 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.Runtime.WindowsRuntime" version="4.3.0" exclude="Build,Analyzers" />
<dependency id="System.Xml.XmlSerializer" version="4.3.0" exclude="Build,Analyzers" /> <dependency id="System.Xml.XmlSerializer" version="4.3.0" exclude="Build,Analyzers" />
</group> </group>
</dependencies> </dependencies>-->
</metadata> </metadata>
<!-- DLLs and resources --> <!-- DLLs and resources -->
<files> <files>
<file src="bin\Release\ModernKeePassLib.dll" target="lib\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\ARM\Release\ModernKeePassLib.dll" target="lib\ARM\netstandard1.2"/>
<file src="bin\x64\Release\ModernKeePassLib.dll" target="lib\x64\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"/>--> <file src="bin\x86\Release\ModernKeePassLib.dll" target="lib\x86\netstandard1.2"/>-->
</files> </files>

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 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; using System.Runtime.InteropServices;
// General assembly properties // General assembly properties
[assembly: AssemblyTitle("ModernKeePassLib")] [assembly: AssemblyTitle("KeePassLib")]
[assembly: AssemblyDescription("Portable KeePass Password Management Library")] [assembly: AssemblyDescription("KeePass Password Management Library")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Geoffroy Bonneville")] [assembly: AssemblyCompany("Panteam")]
[assembly: AssemblyProduct("ModernKeePassLib")] [assembly: AssemblyProduct("KeePassLib")]
[assembly: AssemblyCopyright("Copyright © 2017 Geoffroy Bonneville")] [assembly: AssemblyCopyright("Copyright © 2003-2017 Dominik Reichl")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// COM settings // COM settings
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
#if !ModernKeePassLibPCL
// Assembly GUID // 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 version information
[assembly: AssemblyVersion("2.36.0.*")] [assembly: AssemblyVersion("2.28.1.*")]
[assembly: AssemblyFileVersion("2.36.0.0")] [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 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> /// <summary>
/// Custom icon. <c>PwCustomIcon</c> objects are immutable. /// Custom icon. <c>PwCustomIcon</c> objects are immutable.
@@ -63,7 +71,7 @@ namespace ModernKeePassLib
// MemoryStream ms = new MemoryStream(m_pbImageDataPng, false); // MemoryStream ms = new MemoryStream(m_pbImageDataPng, false);
// m_pCachedImage = Image.FromStream(ms); // m_pCachedImage = Image.FromStream(ms);
// ms.Close(); // ms.Close();
//m_pCachedImage = GfxUtil.LoadImage(m_pbImageDataPng); m_pCachedImage = GfxUtil.LoadImage(m_pbImageDataPng);
#else #else
m_pCachedImage = null; m_pCachedImage = null;
#endif #endif

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -20,7 +20,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
namespace ModernKeePassLib.Security namespace ModernKeePassLibPCL.Security
{ {
/// <summary> /// <summary>
/// Represents an object that is encrypted using a XOR pad until /// 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.Text;
using System.IO; using System.IO;
using ModernKeePassLib.Utility; using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Serialization namespace ModernKeePassLibPCL.Serialization
{ {
public sealed class BinaryReaderEx public sealed class BinaryReaderEx
{ {

View File

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

View File

@@ -23,13 +23,14 @@ using System.Text;
using System.IO; using System.IO;
using System.Diagnostics; using System.Diagnostics;
#if (!PCL && !KeePassLibSD && !KeePassRT) #if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
using System.Security.AccessControl; using System.Security.AccessControl;
#endif #endif
using ModernKeePassLib.Utility; using ModernKeePassLibPCL.Native;
using ModernKeePassLibPCL.Utility;
namespace ModernKeePassLib.Serialization namespace ModernKeePassLibPCL.Serialization
{ {
public sealed class FileTransactionEx public sealed class FileTransactionEx
{ {
@@ -58,8 +59,8 @@ namespace ModernKeePassLib.Serialization
m_bTransacted = bTransacted; m_bTransacted = bTransacted;
m_iocBase = iocBaseFile.CloneDeep(); m_iocBase = iocBaseFile.CloneDeep();
// ModernKeePassLib is currently targeting .NET 4.5 // ModernKeePassLibPCL is currently targeting .NET 4.5
#if !PCL #if !ModernKeePassLibPCL
// Prevent transactions for FTP URLs under .NET 4.0 in order to // Prevent transactions for FTP URLs under .NET 4.0 in order to
// avoid/workaround .NET bug 621450: // 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 // 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); bool bMadeUnhidden = UrlUtil.UnhideFile(m_iocBase.Path);
#if (!PCL && !KeePassLibSD && !KeePassRT) #if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
FileSecurity bkSecurity = null; FileSecurity bkSecurity = null;
bool bEfsEncrypted = false; bool bEfsEncrypted = false;
#endif #endif
if(IOConnection.FileExists(m_iocBase)) if(IOConnection.FileExists(m_iocBase))
{ {
#if (!PCL && !KeePassLibSD && !KeePassRT) #if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
if(m_iocBase.IsLocalFile()) if(m_iocBase.IsLocalFile())
{ {
try try
@@ -130,7 +131,7 @@ namespace ModernKeePassLib.Serialization
IOConnection.RenameFile(m_iocTemp, m_iocBase); IOConnection.RenameFile(m_iocTemp, m_iocBase);
#if (!PCL && !KeePassLibSD && !KeePassRT) #if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
if(m_iocBase.IsLocalFile()) if(m_iocBase.IsLocalFile())
{ {
try try

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -21,14 +21,17 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.ComponentModel; using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics; using System.Diagnostics;
using System.Xml.Serialization; using System.Xml.Serialization;
using System.Globalization; using System.Globalization;
using System.IO; 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 public sealed class KpccLayout
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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