mirror of
https://github.com/wismna/ModernKeePassLib.git
synced 2025-10-03 15:40:20 -04:00
Update Lib to version 2.44
Update nuget packages
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 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
|
||||
@@ -92,6 +92,8 @@ namespace ModernKeePassLib.Cryptography
|
||||
TestHmacOtp();
|
||||
|
||||
TestProtectedObjects(r);
|
||||
TestNativeLib();
|
||||
|
||||
TestMemUtil(r);
|
||||
TestStrUtil();
|
||||
TestUrlUtil();
|
||||
@@ -796,94 +798,6 @@ namespace ModernKeePassLib.Cryptography
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void TestMemUtil(Random r)
|
||||
{
|
||||
#if DEBUG
|
||||
byte[] pb = CryptoRandom.Instance.GetRandomBytes((uint)r.Next(
|
||||
0, 0x2FFFF));
|
||||
|
||||
byte[] pbCompressed = MemUtil.Compress(pb);
|
||||
if(!MemUtil.ArraysEqual(MemUtil.Decompress(pbCompressed), pb))
|
||||
throw new InvalidOperationException("GZip");
|
||||
|
||||
Encoding enc = StrUtil.Utf8;
|
||||
pb = enc.GetBytes("012345678901234567890a");
|
||||
byte[] pbN = enc.GetBytes("9012");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 9)
|
||||
throw new InvalidOperationException("MemUtil-1");
|
||||
pbN = enc.GetBytes("01234567890123");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 0)
|
||||
throw new InvalidOperationException("MemUtil-2");
|
||||
pbN = enc.GetBytes("a");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 21)
|
||||
throw new InvalidOperationException("MemUtil-3");
|
||||
pbN = enc.GetBytes("0a");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 20)
|
||||
throw new InvalidOperationException("MemUtil-4");
|
||||
pbN = enc.GetBytes("1");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 1)
|
||||
throw new InvalidOperationException("MemUtil-5");
|
||||
pbN = enc.GetBytes("b");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) >= 0)
|
||||
throw new InvalidOperationException("MemUtil-6");
|
||||
pbN = enc.GetBytes("012b");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) >= 0)
|
||||
throw new InvalidOperationException("MemUtil-7");
|
||||
|
||||
byte[] pbRes = MemUtil.ParseBase32("MY======");
|
||||
byte[] pbExp = Encoding.UTF8.GetBytes("f");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-1");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXQ====");
|
||||
pbExp = Encoding.UTF8.GetBytes("fo");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-2");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6===");
|
||||
pbExp = Encoding.UTF8.GetBytes("foo");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-3");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YQ=");
|
||||
pbExp = Encoding.UTF8.GetBytes("foob");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-4");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YTB");
|
||||
pbExp = Encoding.UTF8.GetBytes("fooba");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-5");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YTBOI======");
|
||||
pbExp = Encoding.UTF8.GetBytes("foobar");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-6");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("JNSXSIDQOJXXM2LEMVZCAYTBONSWIIDPNYQG63TFFV2GS3LFEBYGC43TO5XXEZDTFY======");
|
||||
pbExp = Encoding.UTF8.GetBytes("Key provider based on one-time passwords.");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-7");
|
||||
|
||||
int i = 0 - 0x10203040;
|
||||
pbRes = MemUtil.Int32ToBytes(i);
|
||||
if(MemUtil.ByteArrayToHexString(pbRes) != "C0CFDFEF")
|
||||
throw new Exception("MemUtil-8"); // Must be little-endian
|
||||
if(MemUtil.BytesToUInt32(pbRes) != (uint)i)
|
||||
throw new Exception("MemUtil-9");
|
||||
if(MemUtil.BytesToInt32(pbRes) != i)
|
||||
throw new Exception("MemUtil-10");
|
||||
|
||||
ArrayHelperEx<char> ah = MemUtil.ArrayHelperExOfChar;
|
||||
for(int j = 0; j < 30; ++j)
|
||||
{
|
||||
string strA = r.Next(30).ToString();
|
||||
string strB = r.Next(30).ToString();
|
||||
char[] vA = strA.ToCharArray();
|
||||
char[] vB = strB.ToCharArray();
|
||||
|
||||
if(ah.Equals(vA, vB) != string.Equals(strA, strB))
|
||||
throw new Exception("MemUtil-11");
|
||||
if((vA.Length == vB.Length) && (Math.Sign(ah.Compare(vA, vB)) !=
|
||||
Math.Sign(string.CompareOrdinal(strA, strB))))
|
||||
throw new Exception("MemUtil-12");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void TestHmacOtp()
|
||||
{
|
||||
#if (DEBUG && !KeePassLibSD)
|
||||
@@ -999,6 +913,119 @@ namespace ModernKeePassLib.Cryptography
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void TestNativeLib()
|
||||
{
|
||||
#if DEBUG && !ModernKeePassLib
|
||||
if(NativeLib.IsUnix())
|
||||
{
|
||||
if(NativeLib.EncodeDataToArgs("A\"B C\\D") !=
|
||||
"A\\\"B C\\\\D")
|
||||
throw new Exception("NativeLib-Args-U");
|
||||
}
|
||||
else // Windows
|
||||
{
|
||||
if(NativeLib.EncodeDataToArgs("A\"B C\\D \\\\ \\\" \\\\\" \\\\\\\" \\\\\\") !=
|
||||
"A\\\"B C\\D \\\\ \\\\\\\" \\\\\\\\\\\" \\\\\\\\\\\\\\\" \\\\\\")
|
||||
throw new Exception("NativeLib-Args-W");
|
||||
}
|
||||
|
||||
string strOrg = "A\\B\\\\C\\\\\\D E\"F\"\"G\"\"\"H I\'J\'\'K\'\'\'L " +
|
||||
"M\\\"N\\\\\"O\\\\\\\"P\\\\\\\\\\\"Q R\\\'S T\\\\\'U \\\\\\";
|
||||
string strArgs = NativeLib.EncodeDataToArgs(strOrg);
|
||||
string strDec = NativeLib.DecodeArgsToData(strArgs);
|
||||
if(strDec != strOrg)
|
||||
throw new Exception("NativeLib-Args-EncDec");
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void TestMemUtil(Random r)
|
||||
{
|
||||
#if DEBUG
|
||||
byte[] pb = CryptoRandom.Instance.GetRandomBytes((uint)r.Next(
|
||||
0, 0x2FFFF));
|
||||
|
||||
byte[] pbCompressed = MemUtil.Compress(pb);
|
||||
if(!MemUtil.ArraysEqual(MemUtil.Decompress(pbCompressed), pb))
|
||||
throw new InvalidOperationException("GZip");
|
||||
|
||||
Encoding enc = StrUtil.Utf8;
|
||||
pb = enc.GetBytes("012345678901234567890a");
|
||||
byte[] pbN = enc.GetBytes("9012");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 9)
|
||||
throw new InvalidOperationException("MemUtil-1");
|
||||
pbN = enc.GetBytes("01234567890123");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 0)
|
||||
throw new InvalidOperationException("MemUtil-2");
|
||||
pbN = enc.GetBytes("a");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 21)
|
||||
throw new InvalidOperationException("MemUtil-3");
|
||||
pbN = enc.GetBytes("0a");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 20)
|
||||
throw new InvalidOperationException("MemUtil-4");
|
||||
pbN = enc.GetBytes("1");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 1)
|
||||
throw new InvalidOperationException("MemUtil-5");
|
||||
pbN = enc.GetBytes("b");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) >= 0)
|
||||
throw new InvalidOperationException("MemUtil-6");
|
||||
pbN = enc.GetBytes("012b");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) >= 0)
|
||||
throw new InvalidOperationException("MemUtil-7");
|
||||
|
||||
byte[] pbRes = MemUtil.ParseBase32("MY======");
|
||||
byte[] pbExp = Encoding.ASCII.GetBytes("f");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-1");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXQ====");
|
||||
pbExp = Encoding.ASCII.GetBytes("fo");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-2");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6===");
|
||||
pbExp = Encoding.ASCII.GetBytes("foo");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-3");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YQ=");
|
||||
pbExp = Encoding.ASCII.GetBytes("foob");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-4");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YTB");
|
||||
pbExp = Encoding.ASCII.GetBytes("fooba");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-5");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YTBOI======");
|
||||
pbExp = Encoding.ASCII.GetBytes("foobar");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-6");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("JNSXSIDQOJXXM2LEMVZCAYTBONSWIIDPNYQG63TFFV2GS3LFEBYGC43TO5XXEZDTFY======");
|
||||
pbExp = Encoding.ASCII.GetBytes("Key provider based on one-time passwords.");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-7");
|
||||
|
||||
int i = 0 - 0x10203040;
|
||||
pbRes = MemUtil.Int32ToBytes(i);
|
||||
if(MemUtil.ByteArrayToHexString(pbRes) != "C0CFDFEF")
|
||||
throw new Exception("MemUtil-8"); // Must be little-endian
|
||||
if(MemUtil.BytesToUInt32(pbRes) != (uint)i)
|
||||
throw new Exception("MemUtil-9");
|
||||
if(MemUtil.BytesToInt32(pbRes) != i)
|
||||
throw new Exception("MemUtil-10");
|
||||
|
||||
ArrayHelperEx<char> ah = MemUtil.ArrayHelperExOfChar;
|
||||
for(int j = 0; j < 30; ++j)
|
||||
{
|
||||
string strA = r.Next(30).ToString();
|
||||
string strB = r.Next(30).ToString();
|
||||
char[] vA = strA.ToCharArray();
|
||||
char[] vB = strB.ToCharArray();
|
||||
|
||||
if(ah.Equals(vA, vB) != string.Equals(strA, strB))
|
||||
throw new Exception("MemUtil-11");
|
||||
if((vA.Length == vB.Length) && (Math.Sign(ah.Compare(vA, vB)) !=
|
||||
Math.Sign(string.CompareOrdinal(strA, strB))))
|
||||
throw new Exception("MemUtil-12");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void TestStrUtil()
|
||||
{
|
||||
#if DEBUG
|
||||
@@ -1128,6 +1155,21 @@ namespace ModernKeePassLib.Cryptography
|
||||
Debug.Assert(Uri.UriSchemeHttps.Equals("https", StrUtil.CaseIgnoreCmp));
|
||||
#endif
|
||||
|
||||
string str = UrlUtil.FilterFileName(" A \"*:?/\\|<>B.txt . ");
|
||||
if(!str.StartsWith(" A ")) throw new Exception("UrlUtil-FFN1");
|
||||
if(!str.EndsWith("B.txt")) throw new Exception("UrlUtil-FFN2");
|
||||
if(str.IndexOfAny(new char[] { '\"', '*', ':', '?', '/', '\\', '|', '<', '>' }) >= 0)
|
||||
throw new Exception("UrlUtil-FFN3");
|
||||
|
||||
if(UrlUtil.GetScheme("cmdG://\"Test.txt\"") != "cmdG")
|
||||
throw new Exception("UrlUtil-GS");
|
||||
if(UrlUtil.RemoveScheme("cmdX://\"T\":A") != "\"T\":A")
|
||||
throw new Exception("UrlUtil-RS1");
|
||||
if(UrlUtil.RemoveScheme("cmdY:/\"T\":A") != "/\"T\":A")
|
||||
throw new Exception("UrlUtil-RS2");
|
||||
if(UrlUtil.RemoveScheme("cmdZ:\"T\":A") != "\"T\":A")
|
||||
throw new Exception("UrlUtil-RS3");
|
||||
|
||||
if(UrlUtil.GetHost(@"scheme://domain:port/path?query_string#fragment_id") !=
|
||||
"domain")
|
||||
throw new InvalidOperationException("UrlUtil-H1");
|
||||
@@ -1145,13 +1187,25 @@ namespace ModernKeePassLib.Cryptography
|
||||
if(UrlUtil.GetHost(@"s://u:p@d.tld:p/p?q#f") != "d.tld")
|
||||
throw new InvalidOperationException("UrlUtil-H7");
|
||||
|
||||
if(!NativeLib.IsUnix()) // Windows
|
||||
{
|
||||
if(UrlUtil.FileUrlToPath("file:///C:/Windows/Win.ini") !=
|
||||
"C:\\Windows\\Win.ini")
|
||||
throw new Exception("UrlUtil-FUTP-W");
|
||||
}
|
||||
else // Unix
|
||||
{
|
||||
if(UrlUtil.FileUrlToPath("file:///etc/fstab") != "/etc/fstab")
|
||||
throw new Exception("UrlUtil-FUTP-U");
|
||||
}
|
||||
|
||||
if(NativeLib.IsUnix()) return;
|
||||
|
||||
string strBase = "\\\\HOMESERVER\\Apps\\KeePass\\KeePass.exe";
|
||||
string strDoc = "\\\\HOMESERVER\\Documents\\KeePass\\NewDatabase.kdbx";
|
||||
string strRel = "..\\..\\Documents\\KeePass\\NewDatabase.kdbx";
|
||||
|
||||
string str = UrlUtil.MakeRelativePath(strBase, strDoc);
|
||||
str = UrlUtil.MakeRelativePath(strBase, strDoc);
|
||||
if(!str.Equals(strRel)) throw new InvalidOperationException("UrlUtil-R1");
|
||||
|
||||
str = UrlUtil.MakeAbsolutePath(strBase, strRel);
|
||||
|
Reference in New Issue
Block a user