Downgrade to net standard 1.2

This commit is contained in:
Geoffroy BONNEVILLE
2020-03-23 18:35:00 +01:00
parent b8240d482f
commit 5067f81189
60 changed files with 1250 additions and 285 deletions

View File

@@ -26,7 +26,6 @@ using System.Threading;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Cryptography.KeyDerivation;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Native;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
@@ -122,7 +121,7 @@ namespace ModernKeePassLib.Keys
{
if(pKey == null) { Debug.Assert(false); continue; }
#if KeePassUAP
#if ModernKeePassLib || KeePassUAP
if(pKey.GetType() == tUserKeyType)
return true;
#else
@@ -149,7 +148,7 @@ namespace ModernKeePassLib.Keys
{
if(pKey == null) { Debug.Assert(false); continue; }
#if KeePassUAP
#if ModernKeePassLib || KeePassUAP
if(pKey.GetType() == tUserKeyType)
return pKey;
#else
@@ -279,9 +278,11 @@ namespace ModernKeePassLib.Keys
internal ProtectedBinary GenerateKey32Ex(KdfParameters p, IStatusLogger sl)
{
if(sl == null) return GenerateKey32(p);
CkGkTaskInfo ti = new CkGkTaskInfo();
#if ModernKeePassLib
return GenerateKey32(p);
#else
if (sl == null) return GenerateKey32(p);
CkGkTaskInfo ti = new CkGkTaskInfo();
ThreadStart f = delegate()
{
@@ -319,6 +320,7 @@ namespace ModernKeePassLib.Keys
Debug.Assert(ti.Key != null);
return ti.Key;
#endif
}
private void ValidateUserKeys()

View File

@@ -248,6 +248,33 @@ namespace ModernKeePassLib.Keys
try
{
#if ModernKeePassLib
var doc = XDocument.Load(ms);
var el = doc.Root;
if((el == null) || !el.Name.LocalName.Equals(RootElementName))
return null;
if(el.DescendantNodes().Count() < 2)
return null;
foreach(var xmlChild in el.Descendants())
{
if(xmlChild.Name == MetaElementName) { } // Ignore Meta
else if(xmlChild.Name == KeyElementName)
{
foreach(var xmlKeyChild in xmlChild.Descendants())
{
if(xmlKeyChild.Name == KeyDataElementName)
{
if(pbKeyData == null)
pbKeyData = Convert.FromBase64String(xmlKeyChild.Value);
}
}
}
}
#else
XmlDocument doc = XmlUtilEx.CreateXmlDocument();
doc.Load(ms);
@@ -270,6 +297,7 @@ namespace ModernKeePassLib.Keys
}
}
}
#endif
}
catch(Exception) { pbKeyData = null; }
finally { ms.Dispose(); }

View File

@@ -99,8 +99,13 @@ namespace ModernKeePassLib.Keys
{
try
{
#if ModernKeePassLib
// TODO: find a way to implement this
return true;
#else
string str = StrUtil.Utf8.GetString(pb);
return str.IsNormalized(NormalizationForm.FormC);
#endif
}
catch(Exception) { Debug.Assert(false); }

View File

@@ -23,10 +23,12 @@ using System.IO;
using System.Security;
#if ModernKeePassLib
using System.Security.Cryptography;
using Windows.Storage;
using Windows.Security.Cryptography;
#endif
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Native;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
@@ -87,6 +89,8 @@ namespace ModernKeePassLib.Keys
{
#if KeePassUAP
string strUserDir = EnvironmentExt.AppDataRoamingFolderPath;
#elif ModernKeePassLib
string strUserDir = Windows.Storage.ApplicationData.Current.RoamingFolder.Path;
#else
string strUserDir = Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData);
@@ -95,8 +99,11 @@ namespace ModernKeePassLib.Keys
strUserDir = UrlUtil.EnsureTerminatingSeparator(strUserDir, false);
strUserDir += PwDefs.ShortProductName;
#if !ModernKeePassLib
if(bCreate && !Directory.Exists(strUserDir))
Directory.CreateDirectory(strUserDir);
#endif
strUserDir = UrlUtil.EnsureTerminatingSeparator(strUserDir, false);
return (strUserDir + UserKeyFileName);
@@ -110,7 +117,15 @@ namespace ModernKeePassLib.Keys
try
{
string strFilePath = GetUserKeyFilePath(false);
#if ModernKeePassLib
var fileStream = StorageFile.GetFileFromPathAsync(strFilePath).GetAwaiter().GetResult().OpenStreamForReadAsync().GetAwaiter().GetResult();
var pbProtectedKey = new byte[(int)fileStream.Length];
fileStream.Read(pbProtectedKey, 0, (int)fileStream.Length);
fileStream.Dispose();
#else
byte[] pbProtectedKey = File.ReadAllBytes(strFilePath);
#endif
pbKey = CryptoUtil.UnprotectData(pbProtectedKey, m_pbEntropy,
DataProtectionScope.CurrentUser);
@@ -135,8 +150,13 @@ namespace ModernKeePassLib.Keys
byte[] pbRandomKey = CryptoRandom.Instance.GetRandomBytes(64);
byte[] pbProtectedKey = CryptoUtil.ProtectData(pbRandomKey,
m_pbEntropy, DataProtectionScope.CurrentUser);
#if ModernKeePassLib
var fileStream = StorageFile.GetFileFromPathAsync(strFilePath).GetAwaiter().GetResult().OpenStreamForWriteAsync().GetAwaiter().GetResult();
fileStream.Write(pbProtectedKey, 0, (int)fileStream.Length);
fileStream.Dispose();
#else
File.WriteAllBytes(strFilePath, pbProtectedKey);
#endif
byte[] pbKey = LoadUserKey(true);
Debug.Assert(MemUtil.ArraysEqual(pbKey, pbRandomKey));