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
|
||||
|
@@ -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
|
||||
@@ -29,13 +29,27 @@ namespace ModernKeePassLib.Cryptography.Cipher
|
||||
{
|
||||
public sealed class ChaCha20Engine : ICipherEngine2
|
||||
{
|
||||
private PwUuid m_uuid = new PwUuid(new byte[] {
|
||||
0xD6, 0x03, 0x8A, 0x2B, 0x8B, 0x6F, 0x4C, 0xB5,
|
||||
0xA5, 0x24, 0x33, 0x9A, 0x31, 0xDB, 0xB5, 0x9A
|
||||
});
|
||||
private static PwUuid g_uuid = null;
|
||||
internal static PwUuid ChaCha20Uuid
|
||||
{
|
||||
get
|
||||
{
|
||||
PwUuid pu = g_uuid;
|
||||
if(pu == null)
|
||||
{
|
||||
pu = new PwUuid(new byte[] {
|
||||
0xD6, 0x03, 0x8A, 0x2B, 0x8B, 0x6F, 0x4C, 0xB5,
|
||||
0xA5, 0x24, 0x33, 0x9A, 0x31, 0xDB, 0xB5, 0x9A });
|
||||
g_uuid = pu;
|
||||
}
|
||||
|
||||
return pu;
|
||||
}
|
||||
}
|
||||
|
||||
public PwUuid CipherUuid
|
||||
{
|
||||
get { return m_uuid; }
|
||||
get { return ChaCha20Engine.ChaCha20Uuid; }
|
||||
}
|
||||
|
||||
public string DisplayName
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
@@ -38,6 +38,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
public static readonly string Punctuation = @",.;:";
|
||||
public static readonly string Brackets = @"[]{}()<>";
|
||||
|
||||
public static readonly string Special = "!\"#$%&'*+,./:;=?@\\^`|~";
|
||||
public static readonly string PrintableAsciiSpecial = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
||||
|
||||
public static readonly string UpperHex = "0123456789ABCDEF";
|
||||
@@ -45,95 +46,54 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
|
||||
public static readonly string LookAlike = @"O0l1I|";
|
||||
|
||||
/// <summary>
|
||||
/// Latin-1 Supplement except U+00A0 (NBSP) and U+00AD (SHY).
|
||||
/// </summary>
|
||||
public static readonly string Latin1S =
|
||||
"\u00A1\u00A2\u00A3\u00A4\u00A5\u00A6\u00A7" +
|
||||
"\u00A8\u00A9\u00AA\u00AB\u00AC\u00AE\u00AF" +
|
||||
"\u00B0\u00B1\u00B2\u00B3\u00B4\u00B5\u00B6\u00B7" +
|
||||
"\u00B8\u00B9\u00BA\u00BB\u00BC\u00BD\u00BE\u00BF" +
|
||||
"\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5\u00C6\u00C7" +
|
||||
"\u00C8\u00C9\u00CA\u00CB\u00CC\u00CD\u00CE\u00CF" +
|
||||
"\u00D0\u00D1\u00D2\u00D3\u00D4\u00D5\u00D6\u00D7" +
|
||||
"\u00D8\u00D9\u00DA\u00DB\u00DC\u00DD\u00DE\u00DF" +
|
||||
"\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u00E6\u00E7" +
|
||||
"\u00E8\u00E9\u00EA\u00EB\u00EC\u00ED\u00EE\u00EF" +
|
||||
"\u00F0\u00F1\u00F2\u00F3\u00F4\u00F5\u00F6\u00F7" +
|
||||
"\u00F8\u00F9\u00FA\u00FB\u00FC\u00FD\u00FE\u00FF";
|
||||
|
||||
internal static readonly string MenuAccels = PwCharSet.LowerCase + PwCharSet.Digits;
|
||||
|
||||
[Obsolete]
|
||||
public static string SpecialChars { get { return PwCharSet.Special; } }
|
||||
[Obsolete]
|
||||
public static string HighAnsiChars { get { return PwCharSet.Latin1S; } }
|
||||
|
||||
private const int CharTabSize = 0x10000 / 8;
|
||||
|
||||
private List<char> m_vChars = new List<char>();
|
||||
private List<char> m_lChars = new List<char>();
|
||||
private byte[] m_vTab = new byte[CharTabSize];
|
||||
|
||||
private static string m_strHighAnsi = null;
|
||||
public static string HighAnsiChars
|
||||
{
|
||||
get
|
||||
{
|
||||
if(m_strHighAnsi == null) { new PwCharSet(); } // Create string
|
||||
Debug.Assert(m_strHighAnsi != null);
|
||||
return m_strHighAnsi;
|
||||
}
|
||||
}
|
||||
|
||||
private static string m_strSpecial = null;
|
||||
public static string SpecialChars
|
||||
{
|
||||
get
|
||||
{
|
||||
if(m_strSpecial == null) { new PwCharSet(); } // Create string
|
||||
Debug.Assert(m_strSpecial != null);
|
||||
return m_strSpecial;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new, empty character set collection object.
|
||||
/// Create a new, empty character set.
|
||||
/// </summary>
|
||||
public PwCharSet()
|
||||
{
|
||||
Initialize(true);
|
||||
Debug.Assert(PwCharSet.Latin1S.Length == (16 * 6 - 2));
|
||||
}
|
||||
|
||||
public PwCharSet(string strCharSet)
|
||||
{
|
||||
Initialize(true);
|
||||
Add(strCharSet);
|
||||
}
|
||||
|
||||
private PwCharSet(bool bFullInitialize)
|
||||
{
|
||||
Initialize(bFullInitialize);
|
||||
}
|
||||
|
||||
private void Initialize(bool bFullInitialize)
|
||||
{
|
||||
Clear();
|
||||
|
||||
if(!bFullInitialize) return;
|
||||
|
||||
if(m_strHighAnsi == null)
|
||||
{
|
||||
StringBuilder sbHighAnsi = new StringBuilder();
|
||||
// [U+0080, U+009F] are C1 control characters,
|
||||
// U+00A0 is non-breaking space
|
||||
for(char ch = '\u00A1'; ch <= '\u00AC'; ++ch)
|
||||
sbHighAnsi.Append(ch);
|
||||
// U+00AD is soft hyphen (format character)
|
||||
for(char ch = '\u00AE'; ch < '\u00FF'; ++ch)
|
||||
sbHighAnsi.Append(ch);
|
||||
sbHighAnsi.Append('\u00FF');
|
||||
|
||||
m_strHighAnsi = sbHighAnsi.ToString();
|
||||
}
|
||||
|
||||
if(m_strSpecial == null)
|
||||
{
|
||||
PwCharSet pcs = new PwCharSet(false);
|
||||
pcs.AddRange('!', '/');
|
||||
pcs.AddRange(':', '@');
|
||||
pcs.AddRange('[', '`');
|
||||
pcs.Add(@"|~");
|
||||
pcs.Remove(@"-_ ");
|
||||
pcs.Remove(PwCharSet.Brackets);
|
||||
|
||||
m_strSpecial = pcs.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Number of characters in this set.
|
||||
/// </summary>
|
||||
public uint Size
|
||||
{
|
||||
get { return (uint)m_vChars.Count; }
|
||||
get { return (uint)m_lChars.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -146,10 +106,10 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
{
|
||||
get
|
||||
{
|
||||
if(uPos >= (uint)m_vChars.Count)
|
||||
if(uPos >= (uint)m_lChars.Count)
|
||||
throw new ArgumentOutOfRangeException("uPos");
|
||||
|
||||
return m_vChars[(int)uPos];
|
||||
return m_lChars[(int)uPos];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +118,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
m_vChars.Clear();
|
||||
m_lChars.Clear();
|
||||
Array.Clear(m_vTab, 0, m_vTab.Length);
|
||||
}
|
||||
|
||||
@@ -190,7 +150,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
|
||||
if(!Contains(ch))
|
||||
{
|
||||
m_vChars.Add(ch);
|
||||
m_lChars.Add(ch);
|
||||
m_vTab[ch / 8] |= (byte)(1 << (ch % 8));
|
||||
}
|
||||
}
|
||||
@@ -204,8 +164,6 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
Debug.Assert(strCharSet != null);
|
||||
if(strCharSet == null) throw new ArgumentNullException("strCharSet");
|
||||
|
||||
m_vChars.Capacity = m_vChars.Count + strCharSet.Length;
|
||||
|
||||
foreach(char ch in strCharSet)
|
||||
Add(ch);
|
||||
}
|
||||
@@ -225,8 +183,6 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
|
||||
public void AddRange(char chMin, char chMax)
|
||||
{
|
||||
m_vChars.Capacity = m_vChars.Count + (chMax - chMin) + 1;
|
||||
|
||||
for(char ch = chMin; ch < chMax; ++ch)
|
||||
Add(ch);
|
||||
|
||||
@@ -261,7 +217,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
case 'v': Add(PwCharSet.LowerVowels); break;
|
||||
case 'V': Add(PwCharSet.LowerVowels, PwCharSet.UpperVowels); break;
|
||||
case 'Z': Add(PwCharSet.UpperVowels); break;
|
||||
case 'x': Add(m_strHighAnsi); break;
|
||||
case 'x': Add(PwCharSet.Latin1S); break;
|
||||
default: bResult = false; break;
|
||||
}
|
||||
|
||||
@@ -271,7 +227,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
public bool Remove(char ch)
|
||||
{
|
||||
m_vTab[ch / 8] &= (byte)(~(1 << (ch % 8)));
|
||||
return m_vChars.Remove(ch);
|
||||
return m_lChars.Remove(ch);
|
||||
}
|
||||
|
||||
public bool Remove(string strCharacters)
|
||||
@@ -305,8 +261,8 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
/// <returns>String containing all character set characters.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach(char ch in m_vChars)
|
||||
StringBuilder sb = new StringBuilder(m_lChars.Count);
|
||||
foreach(char ch in m_lChars)
|
||||
sb.Append(ch);
|
||||
|
||||
return sb.ToString();
|
||||
@@ -319,13 +275,13 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.UpperCase) ? 'U' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.LowerCase) ? 'L' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Digits) ? 'D' : '_');
|
||||
sb.Append(RemoveIfAllExist(m_strSpecial) ? 'S' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Special) ? 'S' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Punctuation) ? 'P' : '_');
|
||||
sb.Append(RemoveIfAllExist(@"-") ? 'm' : '_');
|
||||
sb.Append(RemoveIfAllExist(@"_") ? 'u' : '_');
|
||||
sb.Append(RemoveIfAllExist(@" ") ? 's' : '_');
|
||||
sb.Append(RemoveIfAllExist("-") ? 'm' : '_');
|
||||
sb.Append(RemoveIfAllExist("_") ? 'u' : '_');
|
||||
sb.Append(RemoveIfAllExist(" ") ? 's' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Brackets) ? 'B' : '_');
|
||||
sb.Append(RemoveIfAllExist(m_strHighAnsi) ? 'H' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Latin1S) ? 'H' : '_');
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
@@ -338,13 +294,13 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
if(strRanges[0] != '_') Add(PwCharSet.UpperCase);
|
||||
if(strRanges[1] != '_') Add(PwCharSet.LowerCase);
|
||||
if(strRanges[2] != '_') Add(PwCharSet.Digits);
|
||||
if(strRanges[3] != '_') Add(m_strSpecial);
|
||||
if(strRanges[3] != '_') Add(PwCharSet.Special);
|
||||
if(strRanges[4] != '_') Add(PwCharSet.Punctuation);
|
||||
if(strRanges[5] != '_') Add('-');
|
||||
if(strRanges[6] != '_') Add('_');
|
||||
if(strRanges[7] != '_') Add(' ');
|
||||
if(strRanges[8] != '_') Add(PwCharSet.Brackets);
|
||||
if(strRanges[9] != '_') Add(m_strHighAnsi);
|
||||
if(strRanges[9] != '_') Add(PwCharSet.Latin1S);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
@@ -42,7 +42,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Utility functions for generating random passwords.
|
||||
/// Password generator.
|
||||
/// </summary>
|
||||
public static class PwGenerator
|
||||
{
|
||||
|
@@ -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
|
||||
@@ -252,15 +252,15 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
if((ch >= 'A') && (ch <= 'Z')) pcs.Add(PwCharSet.UpperCase);
|
||||
else if((ch >= 'a') && (ch <= 'z')) pcs.Add(PwCharSet.LowerCase);
|
||||
else if((ch >= '0') && (ch <= '9')) pcs.Add(PwCharSet.Digits);
|
||||
else if(PwCharSet.SpecialChars.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.SpecialChars);
|
||||
else if(PwCharSet.Special.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.Special);
|
||||
else if(ch == ' ') pcs.Add(' ');
|
||||
else if(ch == '-') pcs.Add('-');
|
||||
else if(ch == '_') pcs.Add('_');
|
||||
else if(PwCharSet.Brackets.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.Brackets);
|
||||
else if(PwCharSet.HighAnsiChars.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.HighAnsiChars);
|
||||
else if(PwCharSet.Latin1S.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.Latin1S);
|
||||
else pcs.Add(ch);
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
@@ -39,7 +39,7 @@ namespace ModernKeePassLib.Cryptography
|
||||
internal const char UpperAlpha = 'U';
|
||||
internal const char Digit = 'D';
|
||||
internal const char Special = 'S';
|
||||
internal const char High = 'H';
|
||||
internal const char Latin1S = 'H';
|
||||
internal const char Other = 'X';
|
||||
|
||||
internal const char Dictionary = 'W';
|
||||
@@ -295,7 +295,7 @@ namespace ModernKeePassLib.Cryptography
|
||||
else strSpecial = strSpecial + " ";
|
||||
|
||||
int nSp = strSpecial.Length;
|
||||
int nHi = PwCharSet.HighAnsiChars.Length;
|
||||
int nL1S = PwCharSet.Latin1S.Length;
|
||||
|
||||
m_lCharTypes = new List<QeCharType>();
|
||||
|
||||
@@ -307,10 +307,10 @@ namespace ModernKeePassLib.Cryptography
|
||||
PwCharSet.Digits, true));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.Special,
|
||||
strSpecial, false));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.High,
|
||||
PwCharSet.HighAnsiChars, false));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.Latin1S,
|
||||
PwCharSet.Latin1S, false));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.Other,
|
||||
0x10000 - (2 * 26) - 10 - nSp - nHi));
|
||||
0x10000 - (2 * 26) - 10 - nSp - nL1S));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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