mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Lib fully migrated to Standard
CryptographicEngine.DeriveKeyMaterial exception...
This commit is contained in:
@@ -159,8 +159,8 @@
|
|||||||
</Page>
|
</Page>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="ModernKeePassLibPCL, Version=2.28.1.33588, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="ModernKeePassLibPCL, Version=2.28.1.32210, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\ModernKeePassLibPCL.2.28.1.33588\lib\portable46-net451+win81+wpa81\ModernKeePassLibPCL.dll</HintPath>
|
<HintPath>..\packages\ModernKeePassLibPCL.2.28.1.32210\lib\netstandard1.2\ModernKeePassLibPCL.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="PCLCrypto, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d4421c8a4786956c, processorArchitecture=MSIL">
|
<Reference Include="PCLCrypto, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d4421c8a4786956c, processorArchitecture=MSIL">
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
<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="ModernKeePassLibPCL" version="2.28.1.33588" targetFramework="win81" />
|
<package id="ModernKeePassLibPCL" version="2.28.1.32210" 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="PCLCrypto" version="2.0.147" targetFramework="win81" />
|
||||||
<package id="PCLStorage" version="1.0.2" targetFramework="win81" />
|
<package id="PCLStorage" version="1.0.2" targetFramework="win81" />
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
<package id="PInvoke.Windows.Core" 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="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.Extensions" 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" />
|
||||||
|
@@ -323,6 +323,9 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
var iCrypt = WinRTCrypto.CryptographicEngine.CreateEncryptor(key);*/
|
var iCrypt = WinRTCrypto.CryptographicEngine.CreateEncryptor(key);*/
|
||||||
var aes = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcb);
|
var aes = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcb);
|
||||||
var key = aes.CreateSymmetricKey(CryptographicBuffer.CreateFromByteArray(pbKeySeed32));
|
var key = aes.CreateSymmetricKey(CryptographicBuffer.CreateFromByteArray(pbKeySeed32));
|
||||||
|
var parameters = KeyDerivationParameters.BuildForPbkdf2(CryptographicBuffer.CreateFromByteArray(pbKeySeed32), (uint)uNumRounds);
|
||||||
|
var result = CryptographicEngine.DeriveKeyMaterial(key, parameters, 32);
|
||||||
|
CryptographicBuffer.CopyToByteArray(result, out pbNewKey32);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
byte[] pbIV = new byte[16];
|
byte[] pbIV = new byte[16];
|
||||||
@@ -343,7 +346,7 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
#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))
|
||||||
{
|
{
|
||||||
Debug.Assert(false, "Invalid ICryptoTransform.");
|
Debug.Assert(false, "Invalid ICryptoTransform.");
|
||||||
@@ -356,7 +359,7 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
{
|
{
|
||||||
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
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -374,7 +377,7 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
/// a value of <c>401</c> is recommended.</param>
|
/// a value of <c>401</c> is recommended.</param>
|
||||||
/// <returns>Number of transformations performed in the specified
|
/// <returns>Number of transformations performed in the specified
|
||||||
/// amount of time. Maximum value is <c>uint.MaxValue</c>.</returns>
|
/// amount of time. Maximum value is <c>uint.MaxValue</c>.</returns>
|
||||||
public static ulong TransformKeyBenchmark(uint uMilliseconds, ulong uStep)
|
/*public static ulong TransformKeyBenchmark(uint uMilliseconds, ulong uStep)
|
||||||
{
|
{
|
||||||
ulong uRounds;
|
ulong uRounds;
|
||||||
|
|
||||||
@@ -398,11 +401,9 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
aes.Init(true, kp);
|
aes.Init(true, kp);
|
||||||
#else
|
#else
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
/*var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
|
var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
|
||||||
var key = aes.CreateSymmetricKey(pbKey);
|
var key = aes.CreateSymmetricKey(pbKey);
|
||||||
var iCrypt = WinRTCrypto.CryptographicEngine.CreateEncryptor(key);*/
|
var iCrypt = WinRTCrypto.CryptographicEngine.CreateEncryptor(key);
|
||||||
var aes = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcb);
|
|
||||||
var key = aes.CreateSymmetricKey(CryptographicBuffer.CreateFromByteArray(pbKey));
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
byte[] pbIV = new byte[16];
|
byte[] pbIV = new byte[16];
|
||||||
@@ -422,8 +423,8 @@ namespace ModernKeePassLibPCL.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))
|
||||||
{
|
{
|
||||||
Debug.Assert(false, "Invalid ICryptoTransform.");
|
Debug.Assert(false, "Invalid ICryptoTransform.");
|
||||||
@@ -460,7 +461,7 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
}
|
}
|
||||||
|
|
||||||
return uRounds;
|
return uRounds;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class InvalidCompositeKeyException : Exception
|
public sealed class InvalidCompositeKeyException : Exception
|
||||||
|
@@ -87,9 +87,9 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
Construct(iocKeyFile, bThrowIfDbFile);
|
Construct(iocKeyFile, bThrowIfDbFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Construct(IOConnectionInfo iocFile, bool bThrowIfDbFile)
|
private async void Construct(IOConnectionInfo iocFile, bool bThrowIfDbFile)
|
||||||
{
|
{
|
||||||
byte[] pbFileData = IOConnection.ReadFile(iocFile);
|
byte[] pbFileData = await IOConnection.ReadFile(iocFile);
|
||||||
if(pbFileData == null) throw new FileNotFoundException();
|
if(pbFileData == null) throw new FileNotFoundException();
|
||||||
|
|
||||||
if(bThrowIfDbFile && (pbFileData.Length >= 8))
|
if(bThrowIfDbFile && (pbFileData.Length >= 8))
|
||||||
@@ -310,7 +310,7 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
return pbKeyData;
|
return pbKeyData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateXmlKeyFile(string strFile, byte[] pbKeyData)
|
private static async void CreateXmlKeyFile(string strFile, byte[] pbKeyData)
|
||||||
{
|
{
|
||||||
Debug.Assert(strFile != null);
|
Debug.Assert(strFile != null);
|
||||||
if(strFile == null) throw new ArgumentNullException("strFile");
|
if(strFile == null) throw new ArgumentNullException("strFile");
|
||||||
@@ -318,7 +318,7 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
if(pbKeyData == null) throw new ArgumentNullException("pbKeyData");
|
if(pbKeyData == null) throw new ArgumentNullException("pbKeyData");
|
||||||
|
|
||||||
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile);
|
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile);
|
||||||
Stream sOut = IOConnection.OpenWrite(ioc);
|
Stream sOut = await IOConnection.OpenWrite(ioc);
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var settings = new XmlWriterSettings() { Encoding = StrUtil.Utf8 };
|
var settings = new XmlWriterSettings() { Encoding = StrUtil.Utf8 };
|
||||||
|
@@ -114,7 +114,6 @@
|
|||||||
<Compile Include="Native\Native.PCL.cs" />
|
<Compile Include="Native\Native.PCL.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Utility\ColorTranslator.cs" />
|
<Compile Include="Utility\ColorTranslator.cs" />
|
||||||
<Compile Include="Utility\StreamExtensions.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.config" />
|
<None Include="app.config" />
|
||||||
|
@@ -566,7 +566,7 @@ namespace ModernKeePassLibPCL
|
|||||||
/// <param name="ioSource">IO connection to load the database from.</param>
|
/// <param name="ioSource">IO connection to load the database from.</param>
|
||||||
/// <param name="pwKey">Key used to open the specified database.</param>
|
/// <param name="pwKey">Key used to open the specified database.</param>
|
||||||
/// <param name="slLogger">Logger, which gets all status messages.</param>
|
/// <param name="slLogger">Logger, which gets all status messages.</param>
|
||||||
public void Open(IOConnectionInfo ioSource, CompositeKey pwKey,
|
public async void Open(IOConnectionInfo ioSource, CompositeKey pwKey,
|
||||||
IStatusLogger slLogger)
|
IStatusLogger slLogger)
|
||||||
{
|
{
|
||||||
Debug.Assert(ioSource != null);
|
Debug.Assert(ioSource != null);
|
||||||
@@ -589,7 +589,7 @@ namespace ModernKeePassLibPCL
|
|||||||
KdbxFile kdbx = new KdbxFile(this);
|
KdbxFile kdbx = new KdbxFile(this);
|
||||||
kdbx.DetachBinaries = m_strDetachBins;
|
kdbx.DetachBinaries = m_strDetachBins;
|
||||||
|
|
||||||
Stream s = IOConnection.OpenRead(ioSource);
|
Stream s = await IOConnection.OpenRead(ioSource);
|
||||||
kdbx.Load(s, KdbxFormat.Default, slLogger);
|
kdbx.Load(s, KdbxFormat.Default, slLogger);
|
||||||
s.Dispose();
|
s.Dispose();
|
||||||
|
|
||||||
@@ -612,7 +612,7 @@ namespace ModernKeePassLibPCL
|
|||||||
/// it has been opened from.
|
/// it has been opened from.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="slLogger">Logger that recieves status information.</param>
|
/// <param name="slLogger">Logger that recieves status information.</param>
|
||||||
public void Save(IStatusLogger slLogger)
|
public async void Save(IStatusLogger slLogger)
|
||||||
{
|
{
|
||||||
Debug.Assert(ValidateUuidUniqueness());
|
Debug.Assert(ValidateUuidUniqueness());
|
||||||
|
|
||||||
@@ -622,7 +622,7 @@ namespace ModernKeePassLibPCL
|
|||||||
{
|
{
|
||||||
FileTransactionEx ft = new FileTransactionEx(m_ioSource,
|
FileTransactionEx ft = new FileTransactionEx(m_ioSource,
|
||||||
m_bUseFileTransactions);
|
m_bUseFileTransactions);
|
||||||
Stream s = ft.OpenWrite();
|
Stream s = await ft.OpenWrite();
|
||||||
|
|
||||||
KdbxFile kdb = new KdbxFile(this);
|
KdbxFile kdb = new KdbxFile(this);
|
||||||
kdb.Save(s, null, KdbxFormat.Default, slLogger);
|
kdb.Save(s, null, KdbxFormat.Default, slLogger);
|
||||||
|
@@ -122,12 +122,12 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LockFileInfo Load(IOConnectionInfo iocLockFile)
|
public static async Task<LockFileInfo> Load(IOConnectionInfo iocLockFile)
|
||||||
{
|
{
|
||||||
Stream s = null;
|
Stream s = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
s = IOConnection.OpenRead(iocLockFile);
|
s = await IOConnection.OpenRead(iocLockFile);
|
||||||
if(s == null) return null;
|
if(s == null) return null;
|
||||||
StreamReader sr = new StreamReader(s, StrUtil.Utf8);
|
StreamReader sr = new StreamReader(s, StrUtil.Utf8);
|
||||||
string str = sr.ReadToEnd();
|
string str = sr.ReadToEnd();
|
||||||
@@ -149,7 +149,7 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Throws on error
|
// Throws on error
|
||||||
public static LockFileInfo Create(IOConnectionInfo iocLockFile)
|
public static async Task<LockFileInfo> Create(IOConnectionInfo iocLockFile)
|
||||||
{
|
{
|
||||||
LockFileInfo lfi;
|
LockFileInfo lfi;
|
||||||
Stream s = null;
|
Stream s = null;
|
||||||
@@ -186,7 +186,7 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
|
|
||||||
byte[] pbFile = StrUtil.Utf8.GetBytes(sb.ToString());
|
byte[] pbFile = StrUtil.Utf8.GetBytes(sb.ToString());
|
||||||
|
|
||||||
s = IOConnection.OpenWrite(iocLockFile);
|
s = await IOConnection.OpenWrite(iocLockFile);
|
||||||
if(s == null) throw new IOException(iocLockFile.GetDisplayName());
|
if(s == null) throw new IOException(iocLockFile.GetDisplayName());
|
||||||
s.Write(pbFile, 0, pbFile.Length);
|
s.Write(pbFile, 0, pbFile.Length);
|
||||||
}
|
}
|
||||||
@@ -203,7 +203,7 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
m_iocLockFile = iocBaseFile.CloneDeep();
|
m_iocLockFile = iocBaseFile.CloneDeep();
|
||||||
m_iocLockFile.Path += LockFileExt;
|
m_iocLockFile.Path += LockFileExt;
|
||||||
|
|
||||||
LockFileInfo lfiEx = LockFileInfo.Load(m_iocLockFile);
|
LockFileInfo lfiEx = LockFileInfo.Load(m_iocLockFile).Result;
|
||||||
if(lfiEx != null)
|
if(lfiEx != null)
|
||||||
{
|
{
|
||||||
m_iocLockFile = null; // Otherwise Dispose deletes the existing one
|
m_iocLockFile = null; // Otherwise Dispose deletes the existing one
|
||||||
|
@@ -29,6 +29,7 @@ using System.Security.AccessControl;
|
|||||||
|
|
||||||
using ModernKeePassLibPCL.Native;
|
using ModernKeePassLibPCL.Native;
|
||||||
using ModernKeePassLibPCL.Utility;
|
using ModernKeePassLibPCL.Utility;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ModernKeePassLibPCL.Serialization
|
namespace ModernKeePassLibPCL.Serialization
|
||||||
{
|
{
|
||||||
@@ -77,7 +78,7 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
else m_iocTemp = m_iocBase;
|
else m_iocTemp = m_iocBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream OpenWrite()
|
public async Task<Stream> OpenWrite()
|
||||||
{
|
{
|
||||||
if(!m_bTransacted) m_bMadeUnhidden = UrlUtil.UnhideFile(m_iocTemp.Path);
|
if(!m_bTransacted) m_bMadeUnhidden = UrlUtil.UnhideFile(m_iocTemp.Path);
|
||||||
else // m_bTransacted
|
else // m_bTransacted
|
||||||
@@ -86,7 +87,7 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
catch(Exception) { }
|
catch(Exception) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
return IOConnection.OpenWrite(m_iocTemp);
|
return await IOConnection.OpenWrite(m_iocTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CommitWrite()
|
public void CommitWrite()
|
||||||
@@ -98,7 +99,7 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CommitWriteTransaction()
|
private async void CommitWriteTransaction()
|
||||||
{
|
{
|
||||||
bool bMadeUnhidden = UrlUtil.UnhideFile(m_iocBase.Path);
|
bool bMadeUnhidden = UrlUtil.UnhideFile(m_iocBase.Path);
|
||||||
|
|
||||||
@@ -107,7 +108,7 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
bool bEfsEncrypted = false;
|
bool bEfsEncrypted = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(IOConnection.FileExists(m_iocBase))
|
if(await IOConnection.FileExists(m_iocBase))
|
||||||
{
|
{
|
||||||
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
|
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
|
||||||
if(m_iocBase.IsLocalFile())
|
if(m_iocBase.IsLocalFile())
|
||||||
|
@@ -23,6 +23,7 @@ using System.IO;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Windows.Storage.Streams;
|
using Windows.Storage.Streams;
|
||||||
|
using System.Threading.Tasks;
|
||||||
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
|
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
|
||||||
using System.Net.Cache;
|
using System.Net.Cache;
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
@@ -421,20 +422,21 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
new Uri(ioc.Path)));
|
new Uri(ioc.Path)));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
public static Stream OpenRead(IOConnectionInfo ioc)
|
public static async Task<Stream> OpenRead(IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
RaiseIOAccessPreEvent(ioc, IOAccessType.Read);
|
RaiseIOAccessPreEvent(ioc, IOAccessType.Read);
|
||||||
|
|
||||||
return OpenReadLocal(ioc);
|
return await OpenReadLocal(ioc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private static Stream OpenReadLocal(IOConnectionInfo ioc)
|
private static async Task<Stream> OpenReadLocal(IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
/*if (ioc.StorageFile != null)
|
/*if (ioc.StorageFile != null)
|
||||||
{*/
|
{*/
|
||||||
return ioc.StorageFile.OpenAsync(FileAccessMode.Read).GetResults().AsStream();
|
var file = await ioc.StorageFile.OpenAsync(FileAccessMode.Read);
|
||||||
|
return file.AsStream();
|
||||||
/*}
|
/*}
|
||||||
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
||||||
return file.OpenAsync(PCLStorage.FileAccess.Read).Result;*/
|
return file.OpenAsync(PCLStorage.FileAccess.Read).Result;*/
|
||||||
@@ -467,35 +469,36 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
return IocStream.WrapIfRequired(s);
|
return IocStream.WrapIfRequired(s);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
public static Stream OpenWrite(IOConnectionInfo ioc)
|
public static async Task<Stream> OpenWrite(IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
RaiseIOAccessPreEvent(ioc, IOAccessType.Write);
|
RaiseIOAccessPreEvent(ioc, IOAccessType.Write);
|
||||||
|
|
||||||
return OpenWriteLocal(ioc);
|
return await OpenWriteLocal(ioc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private static Stream OpenWriteLocal(IOConnectionInfo ioc)
|
private static async Task<Stream> OpenWriteLocal(IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
/*if (ioc.StorageFile != null)
|
/*if (ioc.StorageFile != null)
|
||||||
{*/
|
{*/
|
||||||
return ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite).GetResults().AsStream();
|
var file = await ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite);
|
||||||
/*}
|
return file.AsStream();
|
||||||
|
/*}
|
||||||
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
||||||
return file.OpenAsync(FileAccess.ReadAndWrite).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 async Task<bool> FileExists(IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
return FileExists(ioc, false);
|
return await FileExists(ioc, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool FileExists(IOConnectionInfo ioc, bool bThrowErrors)
|
public static async Task<bool> FileExists(IOConnectionInfo ioc, bool bThrowErrors)
|
||||||
{
|
{
|
||||||
if(ioc == null) { Debug.Assert(false); return false; }
|
if(ioc == null) { Debug.Assert(false); return false; }
|
||||||
|
|
||||||
@@ -520,7 +523,7 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Stream s = OpenRead(ioc);
|
Stream s = await OpenRead(ioc);
|
||||||
if(s == null) throw new FileNotFoundException();
|
if(s == null) throw new FileNotFoundException();
|
||||||
|
|
||||||
try { s.ReadByte(); }
|
try { s.ReadByte(); }
|
||||||
@@ -540,13 +543,13 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DeleteFile(IOConnectionInfo ioc)
|
public static async void DeleteFile(IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
RaiseIOAccessPreEvent(ioc, IOAccessType.Delete);
|
RaiseIOAccessPreEvent(ioc, IOAccessType.Delete);
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
if (!ioc.IsLocalFile()) return;
|
if (!ioc.IsLocalFile()) return;
|
||||||
ioc.StorageFile?.DeleteAsync().GetResults();
|
await ioc.StorageFile?.DeleteAsync();
|
||||||
/*var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
/*var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
||||||
file.DeleteAsync().RunSynchronously();*/
|
file.DeleteAsync().RunSynchronously();*/
|
||||||
#else
|
#else
|
||||||
@@ -581,13 +584,13 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="iocFrom">Source file path.</param>
|
/// <param name="iocFrom">Source file path.</param>
|
||||||
/// <param name="iocTo">Target file path.</param>
|
/// <param name="iocTo">Target file path.</param>
|
||||||
public static void RenameFile(IOConnectionInfo iocFrom, IOConnectionInfo iocTo)
|
public static async void RenameFile(IOConnectionInfo iocFrom, IOConnectionInfo iocTo)
|
||||||
{
|
{
|
||||||
RaiseIOAccessPreEvent(iocFrom, iocTo, IOAccessType.Move);
|
RaiseIOAccessPreEvent(iocFrom, iocTo, IOAccessType.Move);
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
if (!iocFrom.IsLocalFile()) return;
|
if (!iocFrom.IsLocalFile()) return;
|
||||||
iocFrom.StorageFile?.RenameAsync(iocTo.Path).GetResults();
|
await iocFrom.StorageFile?.RenameAsync(iocTo.Path);
|
||||||
/*var file = FileSystem.Current.GetFileFromPathAsync(iocFrom.Path).Result;
|
/*var file = FileSystem.Current.GetFileFromPathAsync(iocFrom.Path).Result;
|
||||||
file.MoveAsync(iocTo.Path).RunSynchronously();*/
|
file.MoveAsync(iocTo.Path).RunSynchronously();*/
|
||||||
#else
|
#else
|
||||||
@@ -676,13 +679,13 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
catch(Exception) { Debug.Assert(false); }
|
catch(Exception) { Debug.Assert(false); }
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
public static byte[] ReadFile(IOConnectionInfo ioc)
|
public static async Task<byte[]> ReadFile(IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
Stream sIn = null;
|
Stream sIn = null;
|
||||||
MemoryStream ms = null;
|
MemoryStream ms = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
sIn = IOConnection.OpenRead(ioc);
|
sIn = await OpenRead(ioc);
|
||||||
if(sIn == null) return null;
|
if(sIn == null) return null;
|
||||||
|
|
||||||
ms = new MemoryStream();
|
ms = new MemoryStream();
|
||||||
|
@@ -32,6 +32,7 @@ using Windows.Storage;
|
|||||||
|
|
||||||
using ModernKeePassLibPCL.Interfaces;
|
using ModernKeePassLibPCL.Interfaces;
|
||||||
using ModernKeePassLibPCL.Utility;
|
using ModernKeePassLibPCL.Utility;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ModernKeePassLibPCL.Serialization
|
namespace ModernKeePassLibPCL.Serialization
|
||||||
{
|
{
|
||||||
@@ -306,12 +307,15 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
|
|
||||||
public StorageFile StorageFile { get; set; }
|
public StorageFile StorageFile { get; set; }
|
||||||
|
|
||||||
public bool CanProbablyAccess()
|
public async Task<bool> CanProbablyAccess()
|
||||||
{
|
{
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
if(IsLocalFile())
|
if (IsLocalFile())
|
||||||
//return (FileSystem.Current.GetFileFromPathAsync(m_strUrl).Result != null);
|
{
|
||||||
return StorageFile.GetFileFromPathAsync(m_strUrl).GetResults() != null;
|
//return (FileSystem.Current.GetFileFromPathAsync(m_strUrl).Result != null);
|
||||||
|
var file = await StorageFile.GetFileFromPathAsync(m_strUrl);
|
||||||
|
return file != null;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if(IsLocalFile()) return File.Exists(m_strUrl);
|
if(IsLocalFile()) return File.Exists(m_strUrl);
|
||||||
#endif
|
#endif
|
||||||
|
@@ -57,10 +57,10 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
/// <param name="strFilePath">File to load.</param>
|
/// <param name="strFilePath">File to load.</param>
|
||||||
/// <param name="kdbFormat">Format specifier.</param>
|
/// <param name="kdbFormat">Format specifier.</param>
|
||||||
/// <param name="slLogger">Status logger (optional).</param>
|
/// <param name="slLogger">Status logger (optional).</param>
|
||||||
public void Load(string strFilePath, KdbxFormat kdbFormat, IStatusLogger slLogger)
|
public async void Load(string strFilePath, KdbxFormat kdbFormat, IStatusLogger slLogger)
|
||||||
{
|
{
|
||||||
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFilePath);
|
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFilePath);
|
||||||
Load(IOConnection.OpenRead(ioc), kdbFormat, slLogger);
|
Load(await IOConnection.OpenRead(ioc), kdbFormat, slLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
"NETStandard.Library": "1.6.0",
|
"NETStandard.Library": "1.6.0",
|
||||||
"PInvoke.Windows.Core": "0.5.97",
|
"PInvoke.Windows.Core": "0.5.97",
|
||||||
"Splat": "2.0.0",
|
"Splat": "2.0.0",
|
||||||
"System.Runtime.Extensions": "4.3.0",
|
"System.Runtime.WindowsRuntime": "4.3.0",
|
||||||
"System.Xml.ReaderWriter": "4.3.0",
|
"System.Xml.ReaderWriter": "4.3.0",
|
||||||
"System.Xml.XmlSerializer": "4.3.0",
|
"System.Xml.XmlSerializer": "4.3.0",
|
||||||
"Validation": "2.4.15"
|
"Validation": "2.4.15"
|
||||||
|
@@ -343,12 +343,12 @@
|
|||||||
"ref/netstandard1.2/System.Runtime.dll": {}
|
"ref/netstandard1.2/System.Runtime.dll": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"System.Runtime.Extensions/4.3.0": {
|
"System.Runtime.Extensions/4.1.0": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.NETCore.Platforms": "1.1.0",
|
"Microsoft.NETCore.Platforms": "1.0.1",
|
||||||
"Microsoft.NETCore.Targets": "1.1.0",
|
"Microsoft.NETCore.Targets": "1.0.1",
|
||||||
"System.Runtime": "4.3.0"
|
"System.Runtime": "4.1.0"
|
||||||
},
|
},
|
||||||
"compile": {
|
"compile": {
|
||||||
"ref/netstandard1.0/System.Runtime.Extensions.dll": {}
|
"ref/netstandard1.0/System.Runtime.Extensions.dll": {}
|
||||||
@@ -401,6 +401,17 @@
|
|||||||
"ref/netstandard1.1/System.Runtime.Numerics.dll": {}
|
"ref/netstandard1.1/System.Runtime.Numerics.dll": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"System.Runtime.WindowsRuntime/4.3.0": {
|
||||||
|
"type": "package",
|
||||||
|
"dependencies": {
|
||||||
|
"System.IO": "4.3.0",
|
||||||
|
"System.Runtime": "4.3.0",
|
||||||
|
"System.Threading.Tasks": "4.3.0"
|
||||||
|
},
|
||||||
|
"compile": {
|
||||||
|
"ref/netstandard1.2/System.Runtime.WindowsRuntime.dll": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"System.Text.Encoding/4.3.0": {
|
"System.Text.Encoding/4.3.0": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -1973,8 +1984,8 @@
|
|||||||
"system.runtime.nuspec"
|
"system.runtime.nuspec"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"System.Runtime.Extensions/4.3.0": {
|
"System.Runtime.Extensions/4.1.0": {
|
||||||
"sha512": "guW0uK0fn5fcJJ1tJVXYd7/1h5F+pea1r7FLSOz/f8vPEqbR2ZAknuRDvTQ8PzAilDveOxNjSfr0CHfIQfFk8g==",
|
"sha512": "CUOHjTT/vgP0qGW22U4/hDlOqXmcPq5YicBaXdUR2UiUoLwBT+olO6we4DVbq57jeX5uXH2uerVZhf0qGj+sVQ==",
|
||||||
"type": "package",
|
"type": "package",
|
||||||
"files": [
|
"files": [
|
||||||
"ThirdPartyNotices.txt",
|
"ThirdPartyNotices.txt",
|
||||||
@@ -2047,7 +2058,7 @@
|
|||||||
"ref/xamarinmac20/_._",
|
"ref/xamarinmac20/_._",
|
||||||
"ref/xamarintvos10/_._",
|
"ref/xamarintvos10/_._",
|
||||||
"ref/xamarinwatchos10/_._",
|
"ref/xamarinwatchos10/_._",
|
||||||
"system.runtime.extensions.4.3.0.nupkg.sha512",
|
"system.runtime.extensions.4.1.0.nupkg.sha512",
|
||||||
"system.runtime.extensions.nuspec"
|
"system.runtime.extensions.nuspec"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -2223,6 +2234,59 @@
|
|||||||
"system.runtime.numerics.nuspec"
|
"system.runtime.numerics.nuspec"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"System.Runtime.WindowsRuntime/4.3.0": {
|
||||||
|
"sha512": "xbgfgewneLCfKQfz0VzKsYDacZ680CudYw0uzj0bZ8ATpotkwicgtAsyJZ/J7/Dh2QIwpadjA2zLW/LFk7FKiA==",
|
||||||
|
"type": "package",
|
||||||
|
"files": [
|
||||||
|
"System.Runtime.WindowsRuntime.4.3.0.nupkg.sha512",
|
||||||
|
"System.Runtime.WindowsRuntime.nuspec",
|
||||||
|
"ThirdPartyNotices.txt",
|
||||||
|
"dotnet_library_license.txt",
|
||||||
|
"lib/portable-win8+wp8+wpa81/_._",
|
||||||
|
"lib/win8/_._",
|
||||||
|
"lib/wp80/_._",
|
||||||
|
"lib/wpa81/_._",
|
||||||
|
"ref/netcore50/System.Runtime.WindowsRuntime.dll",
|
||||||
|
"ref/netcore50/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netcore50/de/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netcore50/es/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netcore50/fr/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netcore50/it/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netcore50/ja/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netcore50/ko/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netcore50/ru/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netcore50/zh-hans/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netcore50/zh-hant/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.0/System.Runtime.WindowsRuntime.dll",
|
||||||
|
"ref/netstandard1.0/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.0/de/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.0/es/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.0/fr/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.0/it/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.0/ja/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.0/ko/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.0/ru/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.0/zh-hans/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.0/zh-hant/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.2/System.Runtime.WindowsRuntime.dll",
|
||||||
|
"ref/netstandard1.2/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.2/de/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.2/es/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.2/fr/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.2/it/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.2/ja/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.2/ko/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.2/ru/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.2/zh-hans/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/netstandard1.2/zh-hant/System.Runtime.WindowsRuntime.xml",
|
||||||
|
"ref/portable-win8+wp8+wpa81/_._",
|
||||||
|
"ref/win8/_._",
|
||||||
|
"ref/wp80/_._",
|
||||||
|
"ref/wpa81/_._",
|
||||||
|
"runtimes/win8-aot/lib/netcore50/System.Runtime.WindowsRuntime.dll",
|
||||||
|
"runtimes/win8/lib/netstandard1.3/System.Runtime.WindowsRuntime.dll"
|
||||||
|
]
|
||||||
|
},
|
||||||
"System.Text.Encoding/4.3.0": {
|
"System.Text.Encoding/4.3.0": {
|
||||||
"sha512": "BiIg+KWaSDOITze6jGQynxg64naAPtqGHBwDrLaCtixsa5bKiR8dpPOHA7ge3C0JJQizJE+sfkz1wV+BAKAYZw==",
|
"sha512": "BiIg+KWaSDOITze6jGQynxg64naAPtqGHBwDrLaCtixsa5bKiR8dpPOHA7ge3C0JJQizJE+sfkz1wV+BAKAYZw==",
|
||||||
"type": "package",
|
"type": "package",
|
||||||
@@ -2859,7 +2923,7 @@
|
|||||||
"NETStandard.Library >= 1.6.0",
|
"NETStandard.Library >= 1.6.0",
|
||||||
"PInvoke.Windows.Core >= 0.5.97",
|
"PInvoke.Windows.Core >= 0.5.97",
|
||||||
"Splat >= 2.0.0",
|
"Splat >= 2.0.0",
|
||||||
"System.Runtime.Extensions >= 4.3.0",
|
"System.Runtime.WindowsRuntime >= 4.3.0",
|
||||||
"System.Xml.ReaderWriter >= 4.3.0",
|
"System.Xml.ReaderWriter >= 4.3.0",
|
||||||
"System.Xml.XmlSerializer >= 4.3.0",
|
"System.Xml.XmlSerializer >= 4.3.0",
|
||||||
"Validation >= 2.4.15"
|
"Validation >= 2.4.15"
|
||||||
|
Reference in New Issue
Block a user