WIP Lib 2.37 - databases created by ModernKeepass work fine, but no interoperability...

This commit is contained in:
2017-10-23 18:48:46 +02:00
committed by BONNEVILLE Geoffroy
parent 2bbd931b1a
commit 5b31d3ff72
30 changed files with 250 additions and 244 deletions

View File

@@ -1,6 +1,6 @@
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
Copyright (C) 2003-2017 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
@@ -19,16 +19,15 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
#if ModernKeePassLib
using System.Threading.Tasks;
#else
using System.Threading;
#endif
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
#if ModernKeePassLib
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Storage.Streams;
#endif
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Utility;

View File

@@ -1,6 +1,6 @@
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
Copyright (C) 2003-2017 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
@@ -19,9 +19,9 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.IO;
using System.Text;
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
using System.Security.AccessControl;

View File

@@ -29,6 +29,7 @@ using ModernKeePassLib.Resources;
using ModernKeePassLib.Utility;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Macs;
using Org.BouncyCastle.Crypto.Parameters;
namespace ModernKeePassLib.Serialization
{
@@ -244,17 +245,18 @@ namespace ModernKeePassLib.Serialization
byte[] pbCmpHmac;
byte[] pbBlockKey = GetHmacKey64(m_pbKey, m_uBlockIndex);
/*#if ModernKeePassLib
#if ModernKeePassLib
var h = new HMac(new Sha256Digest());
h.Init(new KeyParameter(pbBlockKey));
h.BlockUpdate(pbBlockIndex, 0, pbBlockIndex.Length);
h.BlockUpdate(pbBlockSize, 0, pbBlockSize.Length);
if (m_pbBuffer.Length > 0)
h.BlockUpdate(m_pbBuffer, 0, m_pbBuffer.Length);
pbCmpHmac = MemUtil.EmptyByteArray;
h.DoFinal(pbCmpHmac, 0);
h.Reset();
#else*/
using(HMACSHA256 h = new HMACSHA256(pbBlockKey))
#else
using(HMACSHA256 h = new HMACSHA256(pbBlockKey))
{
h.TransformBlock(pbBlockIndex, 0, pbBlockIndex.Length,
pbBlockIndex, 0);
@@ -269,7 +271,7 @@ namespace ModernKeePassLib.Serialization
pbCmpHmac = h.Hash;
}
//#endif
#endif
MemUtil.ZeroByteArray(pbBlockKey);
if(!MemUtil.ArraysEqual(pbCmpHmac, pbStoredHmac))
@@ -317,16 +319,18 @@ namespace ModernKeePassLib.Serialization
byte[] pbBlockHmac;
byte[] pbBlockKey = GetHmacKey64(m_pbKey, m_uBlockIndex);
/*#if ModernKeePassLib
#if ModernKeePassLib
var h = new HMac(new Sha256Digest());
h.BlockUpdate(pbBlockIndex, 0, pbBlockIndex.Length);
h.Init(new KeyParameter(pbBlockKey));
h.BlockUpdate(pbBlockIndex, 0, pbBlockIndex.Length);
h.BlockUpdate(pbBlockSize, 0, pbBlockSize.Length);
if (m_pbBuffer.Length > 0)
h.BlockUpdate(m_pbBuffer, 0, m_pbBuffer.Length);
if (cbBlockSize > 0)
h.BlockUpdate(m_pbBuffer, 0, cbBlockSize);
h.DoFinal(pbBlockHmac, 0);
pbBlockHmac = MemUtil.EmptyByteArray;
h.DoFinal(pbBlockHmac, 0);
h.Reset();
#else*/
#else
using(HMACSHA256 h = new HMACSHA256(pbBlockKey))
{
h.TransformBlock(pbBlockIndex, 0, pbBlockIndex.Length,
@@ -341,7 +345,7 @@ namespace ModernKeePassLib.Serialization
pbBlockHmac = h.Hash;
}
//#endif
#endif
MemUtil.ZeroByteArray(pbBlockKey);
MemUtil.Write(m_sBase, pbBlockHmac);

View File

@@ -1,13 +1,12 @@
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
Copyright (C) 2003-2017 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
@@ -19,24 +18,27 @@
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Diagnostics;
using Windows.Storage.Streams;
using System.Threading.Tasks;
using ModernKeePassLib.Native;
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
using System.Reflection;
using System.Text;
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassUAP)
using System.Net.Cache;
using System.Net.Security;
#endif
#if !ModernKeePassLib && !KeePassRT
#if !ModernKeePassLib && !KeePassUAP
using System.Security.Cryptography.X509Certificates;
#endif
#if ModernKeePassLib
using Windows.Storage;
using Windows.Storage.Streams;
#endif
using ModernKeePassLib.Native;
using ModernKeePassLib.Utility;
namespace ModernKeePassLib.Serialization
@@ -44,10 +46,17 @@ namespace ModernKeePassLib.Serialization
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
internal sealed class IOWebClient : WebClient
{
private IOConnectionInfo m_ioc;
public IOWebClient(IOConnectionInfo ioc) : base()
{
m_ioc = ioc;
}
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
IOConnection.ConfigureWebRequest(request);
IOConnection.ConfigureWebRequest(request, m_ioc);
return request;
}
}
@@ -581,7 +590,7 @@ namespace ModernKeePassLib.Serialization
new Uri(ioc.Path)));
}
#else
public static Stream OpenRead(IOConnectionInfo ioc)
public static Stream OpenRead(IOConnectionInfo ioc)
{
RaiseIOAccessPreEvent(ioc, IOAccessType.Read);
@@ -700,7 +709,7 @@ namespace ModernKeePassLib.Serialization
catch(Exception) { Debug.Assert(false); }
}
#endif
public static byte[] ReadFile(IOConnectionInfo ioc)
public static byte[] ReadFile(IOConnectionInfo ioc)
{
Stream sIn = null;
MemoryStream ms = null;

View File

@@ -1,6 +1,6 @@
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
Copyright (C) 2003-2017 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
@@ -19,12 +19,11 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml.Serialization;
#if ModernKeePassLib
using Windows.Storage;
//using PCLStorage;
@@ -338,13 +337,13 @@ namespace ModernKeePassLib.Serialization
public StorageFile StorageFile { get; set; }
public async Task<bool> CanProbablyAccess()
public bool CanProbablyAccess()
{
#if ModernKeePassLib
if (IsLocalFile())
{
//return (FileSystem.Current.GetFileFromPathAsync(m_strUrl).Result != null);
var file = await StorageFile.GetFileFromPathAsync(m_strUrl);
var file = StorageFile.GetFileFromPathAsync(m_strUrl).GetAwaiter().GetResult();
return file != null;
}
#else

View File

@@ -25,8 +25,6 @@ using System.Text;
using System.Security;
using System.Drawing;
using System.Xml;
using System.IO;
using System.Diagnostics;
using ModernKeePassLib;
using ModernKeePassLib.Collections;

View File

@@ -1,6 +1,6 @@
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
Copyright (C) 2003-2017 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
@@ -17,18 +17,22 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// #define KDBX_BENCHMARK
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.IO;
using System.Security;
using System.Text;
using System.Xml;
#if ModernKeePassLib
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
using Windows.Storage.Streams;
#else
using System.Security.Cryptography;
#endif
using System.Xml;
#if !KeePassLibSD
using System.IO.Compression;
@@ -42,8 +46,6 @@ using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Keys;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Utility;
using Windows.Security.Cryptography.Core;
using Windows.Storage.Streams;
using ModernKeePassLib.Collections;
using ModernKeePassLib.Cryptography.KeyDerivation;
using ModernKeePassLib.Security;

View File

@@ -1,6 +1,6 @@
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
Copyright (C) 2003-2017 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
@@ -19,23 +19,23 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Xml;
using System.Security;
using System.Text;
using System.Xml;
#if ModernKeePassLib
using Windows.Security.Cryptography;
#else
using System.Drawing;
using System.Security.Cryptography;
#endif
using System.Drawing;
using System.Globalization;
using System.Diagnostics;
#if !KeePassLibSD
using System.IO.Compression;
#else
#if KeePassLibSD
using KeePassLibSD;
#else
using System.IO.Compression;
#endif
using ModernKeePassLib.Collections;

View File

@@ -1,6 +1,6 @@
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
Copyright (C) 2003-2017 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
@@ -19,20 +19,17 @@
using System;
using System.Collections.Generic;
using System.Xml;
using System.Text;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Diagnostics;
using System.Security;
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
#if !KeePassLibSD
using System.IO.Compression;
#endif
using System.Text;
using System.Xml;
#if ModernKeePassLib
using Windows.Storage;
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
#endif
using ModernKeePassLib.Collections;
@@ -207,11 +204,7 @@ namespace ModernKeePassLib.Serialization
private PwDatabase m_pwDatabase; // Not null, see constructor
private bool m_bUsedOnce = false;
#if ModernKeePassLib
private XmlWriter m_xmlWriter = null;
#else
private XmlTextWriter m_xmlWriter = null;
#endif
private CryptoRandomStream m_randomStream = null;
private KdbxFormat m_format = KdbxFormat.Default;
private IStatusLogger m_slLogger = null;
@@ -403,12 +396,12 @@ namespace ModernKeePassLib.Serialization
.HashData(CryptographicBuffer.CreateFromByteArray(pbCmp));
CryptographicBuffer.CopyToByteArray(h, out pbHmacKey64);
#else
using(SHA512Managed h = new SHA512Managed())
using(SHA512Managed h = new SHA512Managed())
{
pbHmacKey64 = h.ComputeHash(pbCmp);
}
#endif
}
}
finally { MemUtil.ZeroByteArray(pbCmp); }
}
@@ -459,11 +452,11 @@ namespace ModernKeePassLib.Serialization
byte[] pbHeaderHmac;
byte[] pbBlockKey = HmacBlockStream.GetHmacKey64(
pbKey, ulong.MaxValue);
using (HMACSHA256 h = new HMACSHA256(pbBlockKey))
using(HMACSHA256 h = new HMACSHA256(pbBlockKey))
{
pbHeaderHmac = h.ComputeHash(pbHeader);
}
MemUtil.ZeroByteArray(pbBlockKey);
MemUtil.ZeroByteArray(pbBlockKey);
return pbHeaderHmac;
}
@@ -522,10 +515,9 @@ namespace ModernKeePassLib.Serialization
if(!string.IsNullOrEmpty(strExt)) strPath += "." + strExt;
++iTry;
}
++iTry;
}
#if ModernKeePassLib
//while(FileSystem.Current.GetFileFromPathAsync(strPath).Result != null);
while (StorageFile.GetFileFromPathAsync(strPath).GetResults() != null);
#else
while(File.Exists(strPath));