Update Lib to version 2.44

Update nuget packages
This commit is contained in:
Geoffroy BONNEVILLE
2020-03-16 15:28:05 +01:00
parent 3a85b60e58
commit b8240d482f
108 changed files with 1102 additions and 595 deletions

View File

@@ -7,10 +7,13 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.0-preview-20200310-03" />
<PackageReference Include="NUnit" Version="3.12.0" /> <PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" /> <PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.3.0" /> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 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 public sealed class ChaCha20Engine : ICipherEngine2
{ {
private PwUuid m_uuid = new PwUuid(new byte[] { private static PwUuid g_uuid = null;
0xD6, 0x03, 0x8A, 0x2B, 0x8B, 0x6F, 0x4C, 0xB5, internal static PwUuid ChaCha20Uuid
0xA5, 0x24, 0x33, 0x9A, 0x31, 0xDB, 0xB5, 0x9A {
}); 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 public PwUuid CipherUuid
{ {
get { return m_uuid; } get { return ChaCha20Engine.ChaCha20Uuid; }
} }
public string DisplayName public string DisplayName

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 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 Punctuation = @",.;:";
public static readonly string Brackets = @"[]{}()<>"; public static readonly string Brackets = @"[]{}()<>";
public static readonly string Special = "!\"#$%&'*+,./:;=?@\\^`|~";
public static readonly string PrintableAsciiSpecial = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; public static readonly string PrintableAsciiSpecial = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
public static readonly string UpperHex = "0123456789ABCDEF"; public static readonly string UpperHex = "0123456789ABCDEF";
@@ -45,95 +46,54 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
public static readonly string LookAlike = @"O0l1I|"; 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; 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 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 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> /// <summary>
/// Create a new, empty character set collection object. /// Create a new, empty character set.
/// </summary> /// </summary>
public PwCharSet() public PwCharSet()
{ {
Initialize(true); Debug.Assert(PwCharSet.Latin1S.Length == (16 * 6 - 2));
} }
public PwCharSet(string strCharSet) public PwCharSet(string strCharSet)
{ {
Initialize(true);
Add(strCharSet); 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> /// <summary>
/// Number of characters in this set. /// Number of characters in this set.
/// </summary> /// </summary>
public uint Size public uint Size
{ {
get { return (uint)m_vChars.Count; } get { return (uint)m_lChars.Count; }
} }
/// <summary> /// <summary>
@@ -146,10 +106,10 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
{ {
get get
{ {
if(uPos >= (uint)m_vChars.Count) if(uPos >= (uint)m_lChars.Count)
throw new ArgumentOutOfRangeException("uPos"); throw new ArgumentOutOfRangeException("uPos");
return m_vChars[(int)uPos]; return m_lChars[(int)uPos];
} }
} }
@@ -158,7 +118,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
/// </summary> /// </summary>
public void Clear() public void Clear()
{ {
m_vChars.Clear(); m_lChars.Clear();
Array.Clear(m_vTab, 0, m_vTab.Length); Array.Clear(m_vTab, 0, m_vTab.Length);
} }
@@ -190,7 +150,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
if(!Contains(ch)) if(!Contains(ch))
{ {
m_vChars.Add(ch); m_lChars.Add(ch);
m_vTab[ch / 8] |= (byte)(1 << (ch % 8)); m_vTab[ch / 8] |= (byte)(1 << (ch % 8));
} }
} }
@@ -204,8 +164,6 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
Debug.Assert(strCharSet != null); Debug.Assert(strCharSet != null);
if(strCharSet == null) throw new ArgumentNullException("strCharSet"); if(strCharSet == null) throw new ArgumentNullException("strCharSet");
m_vChars.Capacity = m_vChars.Count + strCharSet.Length;
foreach(char ch in strCharSet) foreach(char ch in strCharSet)
Add(ch); Add(ch);
} }
@@ -225,8 +183,6 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
public void AddRange(char chMin, char chMax) public void AddRange(char chMin, char chMax)
{ {
m_vChars.Capacity = m_vChars.Count + (chMax - chMin) + 1;
for(char ch = chMin; ch < chMax; ++ch) for(char ch = chMin; ch < chMax; ++ch)
Add(ch); Add(ch);
@@ -261,7 +217,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
case 'v': Add(PwCharSet.LowerVowels); break; case 'v': Add(PwCharSet.LowerVowels); break;
case 'V': Add(PwCharSet.LowerVowels, PwCharSet.UpperVowels); break; case 'V': Add(PwCharSet.LowerVowels, PwCharSet.UpperVowels); break;
case 'Z': Add(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; default: bResult = false; break;
} }
@@ -271,7 +227,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
public bool Remove(char ch) public bool Remove(char ch)
{ {
m_vTab[ch / 8] &= (byte)(~(1 << (ch % 8))); m_vTab[ch / 8] &= (byte)(~(1 << (ch % 8)));
return m_vChars.Remove(ch); return m_lChars.Remove(ch);
} }
public bool Remove(string strCharacters) public bool Remove(string strCharacters)
@@ -305,8 +261,8 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
/// <returns>String containing all character set characters.</returns> /// <returns>String containing all character set characters.</returns>
public override string ToString() public override string ToString()
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder(m_lChars.Count);
foreach(char ch in m_vChars) foreach(char ch in m_lChars)
sb.Append(ch); sb.Append(ch);
return sb.ToString(); return sb.ToString();
@@ -319,13 +275,13 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
sb.Append(RemoveIfAllExist(PwCharSet.UpperCase) ? 'U' : '_'); sb.Append(RemoveIfAllExist(PwCharSet.UpperCase) ? 'U' : '_');
sb.Append(RemoveIfAllExist(PwCharSet.LowerCase) ? 'L' : '_'); sb.Append(RemoveIfAllExist(PwCharSet.LowerCase) ? 'L' : '_');
sb.Append(RemoveIfAllExist(PwCharSet.Digits) ? 'D' : '_'); 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(PwCharSet.Punctuation) ? 'P' : '_');
sb.Append(RemoveIfAllExist(@"-") ? 'm' : '_'); sb.Append(RemoveIfAllExist("-") ? 'm' : '_');
sb.Append(RemoveIfAllExist(@"_") ? 'u' : '_'); sb.Append(RemoveIfAllExist("_") ? 'u' : '_');
sb.Append(RemoveIfAllExist(@" ") ? 's' : '_'); sb.Append(RemoveIfAllExist(" ") ? 's' : '_');
sb.Append(RemoveIfAllExist(PwCharSet.Brackets) ? 'B' : '_'); sb.Append(RemoveIfAllExist(PwCharSet.Brackets) ? 'B' : '_');
sb.Append(RemoveIfAllExist(m_strHighAnsi) ? 'H' : '_'); sb.Append(RemoveIfAllExist(PwCharSet.Latin1S) ? 'H' : '_');
return sb.ToString(); return sb.ToString();
} }
@@ -338,13 +294,13 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
if(strRanges[0] != '_') Add(PwCharSet.UpperCase); if(strRanges[0] != '_') Add(PwCharSet.UpperCase);
if(strRanges[1] != '_') Add(PwCharSet.LowerCase); if(strRanges[1] != '_') Add(PwCharSet.LowerCase);
if(strRanges[2] != '_') Add(PwCharSet.Digits); 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[4] != '_') Add(PwCharSet.Punctuation);
if(strRanges[5] != '_') Add('-'); if(strRanges[5] != '_') Add('-');
if(strRanges[6] != '_') Add('_'); if(strRanges[6] != '_') Add('_');
if(strRanges[7] != '_') Add(' '); if(strRanges[7] != '_') Add(' ');
if(strRanges[8] != '_') Add(PwCharSet.Brackets); if(strRanges[8] != '_') Add(PwCharSet.Brackets);
if(strRanges[9] != '_') Add(m_strHighAnsi); if(strRanges[9] != '_') Add(PwCharSet.Latin1S);
} }
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -42,7 +42,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
} }
/// <summary> /// <summary>
/// Utility functions for generating random passwords. /// Password generator.
/// </summary> /// </summary>
public static class PwGenerator public static class PwGenerator
{ {

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 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); if((ch >= 'A') && (ch <= 'Z')) pcs.Add(PwCharSet.UpperCase);
else if((ch >= 'a') && (ch <= 'z')) pcs.Add(PwCharSet.LowerCase); else if((ch >= 'a') && (ch <= 'z')) pcs.Add(PwCharSet.LowerCase);
else if((ch >= '0') && (ch <= '9')) pcs.Add(PwCharSet.Digits); else if((ch >= '0') && (ch <= '9')) pcs.Add(PwCharSet.Digits);
else if(PwCharSet.SpecialChars.IndexOf(ch) >= 0) else if(PwCharSet.Special.IndexOf(ch) >= 0)
pcs.Add(PwCharSet.SpecialChars); pcs.Add(PwCharSet.Special);
else if(ch == ' ') pcs.Add(' '); else if(ch == ' ') pcs.Add(' ');
else if(ch == '-') pcs.Add('-'); else if(ch == '-') pcs.Add('-');
else if(ch == '_') pcs.Add('_'); else if(ch == '_') pcs.Add('_');
else if(PwCharSet.Brackets.IndexOf(ch) >= 0) else if(PwCharSet.Brackets.IndexOf(ch) >= 0)
pcs.Add(PwCharSet.Brackets); pcs.Add(PwCharSet.Brackets);
else if(PwCharSet.HighAnsiChars.IndexOf(ch) >= 0) else if(PwCharSet.Latin1S.IndexOf(ch) >= 0)
pcs.Add(PwCharSet.HighAnsiChars); pcs.Add(PwCharSet.Latin1S);
else pcs.Add(ch); else pcs.Add(ch);
} }

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 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 UpperAlpha = 'U';
internal const char Digit = 'D'; internal const char Digit = 'D';
internal const char Special = 'S'; internal const char Special = 'S';
internal const char High = 'H'; internal const char Latin1S = 'H';
internal const char Other = 'X'; internal const char Other = 'X';
internal const char Dictionary = 'W'; internal const char Dictionary = 'W';
@@ -295,7 +295,7 @@ namespace ModernKeePassLib.Cryptography
else strSpecial = strSpecial + " "; else strSpecial = strSpecial + " ";
int nSp = strSpecial.Length; int nSp = strSpecial.Length;
int nHi = PwCharSet.HighAnsiChars.Length; int nL1S = PwCharSet.Latin1S.Length;
m_lCharTypes = new List<QeCharType>(); m_lCharTypes = new List<QeCharType>();
@@ -307,10 +307,10 @@ namespace ModernKeePassLib.Cryptography
PwCharSet.Digits, true)); PwCharSet.Digits, true));
m_lCharTypes.Add(new QeCharType(PatternID.Special, m_lCharTypes.Add(new QeCharType(PatternID.Special,
strSpecial, false)); strSpecial, false));
m_lCharTypes.Add(new QeCharType(PatternID.High, m_lCharTypes.Add(new QeCharType(PatternID.Latin1S,
PwCharSet.HighAnsiChars, false)); PwCharSet.Latin1S, false));
m_lCharTypes.Add(new QeCharType(PatternID.Other, m_lCharTypes.Add(new QeCharType(PatternID.Other,
0x10000 - (2 * 26) - 10 - nSp - nHi)); 0x10000 - (2 * 26) - 10 - nSp - nL1S));
} }
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -92,6 +92,8 @@ namespace ModernKeePassLib.Cryptography
TestHmacOtp(); TestHmacOtp();
TestProtectedObjects(r); TestProtectedObjects(r);
TestNativeLib();
TestMemUtil(r); TestMemUtil(r);
TestStrUtil(); TestStrUtil();
TestUrlUtil(); TestUrlUtil();
@@ -796,94 +798,6 @@ namespace ModernKeePassLib.Cryptography
#endif #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() private static void TestHmacOtp()
{ {
#if (DEBUG && !KeePassLibSD) #if (DEBUG && !KeePassLibSD)
@@ -999,6 +913,119 @@ namespace ModernKeePassLib.Cryptography
#endif #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() private static void TestStrUtil()
{ {
#if DEBUG #if DEBUG
@@ -1128,6 +1155,21 @@ namespace ModernKeePassLib.Cryptography
Debug.Assert(Uri.UriSchemeHttps.Equals("https", StrUtil.CaseIgnoreCmp)); Debug.Assert(Uri.UriSchemeHttps.Equals("https", StrUtil.CaseIgnoreCmp));
#endif #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") != if(UrlUtil.GetHost(@"scheme://domain:port/path?query_string#fragment_id") !=
"domain") "domain")
throw new InvalidOperationException("UrlUtil-H1"); 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") if(UrlUtil.GetHost(@"s://u:p@d.tld:p/p?q#f") != "d.tld")
throw new InvalidOperationException("UrlUtil-H7"); 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; if(NativeLib.IsUnix()) return;
string strBase = "\\\\HOMESERVER\\Apps\\KeePass\\KeePass.exe"; string strBase = "\\\\HOMESERVER\\Apps\\KeePass\\KeePass.exe";
string strDoc = "\\\\HOMESERVER\\Documents\\KeePass\\NewDatabase.kdbx"; string strDoc = "\\\\HOMESERVER\\Documents\\KeePass\\NewDatabase.kdbx";
string strRel = "..\\..\\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"); if(!str.Equals(strRel)) throw new InvalidOperationException("UrlUtil-R1");
str = UrlUtil.MakeAbsolutePath(strBase, strRel); str = UrlUtil.MakeAbsolutePath(strBase, strRel);

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -179,15 +179,15 @@ namespace ModernKeePassLib.Keys
return null; return null;
} }
/// <summary> /// <summary>
/// Create a new, random key-file. /// Create a new, random key-file.
/// </summary> /// </summary>
/// <param name="strFilePath">Path where the key-file should be saved to. /// <param name="strFilePath">Path where the key-file should be saved to.
/// If the file exists already, it will be overwritten.</param> /// If the file exists already, it will be overwritten.</param>
/// <param name="pbAdditionalEntropy">Additional entropy used to generate /// <param name="pbAdditionalEntropy">Additional entropy used to generate
/// the random key. May be <c>null</c> (in this case only the KeePass-internal /// the random key. May be <c>null</c> (in this case only the KeePass-internal
/// random number generator is used).</param> /// random number generator is used).</param>
/// <returns>Returns a <c>FileSaveResult</c> error code.</returns> /// <returns>Returns a <c>FileSaveResult</c> error code.</returns>
#if ModernKeePassLib #if ModernKeePassLib
public static byte[] Create(byte[] pbAdditionalEntropy) public static byte[] Create(byte[] pbAdditionalEntropy)
#else #else
@@ -281,7 +281,7 @@ namespace ModernKeePassLib.Keys
private static byte[] CreateXmlKeyFile(byte[] pbKeyData) private static byte[] CreateXmlKeyFile(byte[] pbKeyData)
{ {
#else #else
private static void CreateXmlKeyFile(string strFile, byte[] pbKeyData) private static 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");
@@ -323,6 +323,6 @@ namespace ModernKeePassLib.Keys
return ((MemoryStream) s).ToArray(); return ((MemoryStream) s).ToArray();
#endif #endif
} }
} }
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.42.1.3</Version> <Version>2.44.0</Version>
<Authors>Geoffroy Bonneville</Authors> <Authors>Geoffroy Bonneville</Authors>
<PackageLicense>https://www.gnu.org/licenses/gpl-3.0.en.html</PackageLicense> <PackageLicense>https://www.gnu.org/licenses/gpl-3.0.en.html</PackageLicense>
<PackageProjectUrl>https://github.com/wismna/ModernKeePassLib</PackageProjectUrl> <PackageProjectUrl>https://github.com/wismna/ModernKeePassLib</PackageProjectUrl>
@@ -12,7 +12,7 @@
<Product>ModernKeePassLib</Product> <Product>ModernKeePassLib</Product>
<PackageReleaseNotes>Save corrections</PackageReleaseNotes> <PackageReleaseNotes>Save corrections</PackageReleaseNotes>
<PackageTags>KeePass KeePassLib Portable PCL NetStandard ModernKeePass</PackageTags> <PackageTags>KeePass KeePassLib Portable PCL NetStandard ModernKeePass</PackageTags>
<Copyright>Copyright © 2019 Geoffroy Bonneville</Copyright> <Copyright>Copyright © 2020 Geoffroy Bonneville</Copyright>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -54,9 +54,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0006" /> <PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.3.0" /> <PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="4.5.0" /> <PackageReference Include="System.Security.Cryptography.ProtectedData" Version="4.7.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -27,6 +27,16 @@ namespace ModernKeePassLib.Native
{ {
if (!string.IsNullOrEmpty(strApp)) return strApp; if (!string.IsNullOrEmpty(strApp)) return strApp;
return string.Empty; return string.Empty;
}
internal static string EncodeDataToArgs(string v)
{
throw new NotImplementedException();
}
public static string DecodeArgsToData(string strApp)
{
throw new NotImplementedException();
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -234,7 +234,7 @@ namespace ModernKeePassLib.Native
{ {
ProcessStartInfo psi = new ProcessStartInfo(); ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = EncodePath(strAppPath); psi.FileName = strAppPath;
if(!string.IsNullOrEmpty(strParams)) psi.Arguments = strParams; if(!string.IsNullOrEmpty(strParams)) psi.Arguments = strParams;
psi.CreateNoWindow = true; psi.CreateNoWindow = true;
@@ -244,7 +244,7 @@ namespace ModernKeePassLib.Native
psi.RedirectStandardOutput = bStdOut; psi.RedirectStandardOutput = bStdOut;
if(strStdInput != null) psi.RedirectStandardInput = true; if(strStdInput != null) psi.RedirectStandardInput = true;
Process p = Process.Start(psi); Process p = StartProcessEx(psi);
pToDispose = p; pToDispose = p;
if(strStdInput != null) if(strStdInput != null)
@@ -449,19 +449,18 @@ namespace ModernKeePassLib.Native
Marshal.FreeHGlobal(kvpPointers.Value); Marshal.FreeHGlobal(kvpPointers.Value);
} }
internal static Type GetUwpType(string strType) // internal static Type GetUwpType(string strType)
{ // {
if(string.IsNullOrEmpty(strType)) { Debug.Assert(false); return null; } // if(string.IsNullOrEmpty(strType)) { Debug.Assert(false); return null; }
// // https://referencesource.microsoft.com/#mscorlib/system/runtime/interopservices/windowsruntime/winrtclassactivator.cs
// https://referencesource.microsoft.com/#mscorlib/system/runtime/interopservices/windowsruntime/winrtclassactivator.cs // return Type.GetType(strType + ", Windows, ContentType=WindowsRuntime", false);
return Type.GetType(strType + ", Windows, ContentType=WindowsRuntime", false); // }
}
// Cf. DecodeArgsToData
internal static string EncodeDataToArgs(string strData) internal static string EncodeDataToArgs(string strData)
{ {
if(strData == null) { Debug.Assert(false); return string.Empty; } if(strData == null) { Debug.Assert(false); return string.Empty; }
// Cf. EncodePath and DecodeArgsToPath
if(MonoWorkarounds.IsRequired(3471228285U) && IsUnix()) if(MonoWorkarounds.IsRequired(3471228285U) && IsUnix())
{ {
string str = strData; string str = strData;
@@ -479,53 +478,165 @@ namespace ModernKeePassLib.Native
return str; return str;
} }
// See SHELLEXECUTEINFO structure documentation // SHELLEXECUTEINFOW structure documentation:
return strData.Replace("\"", "\"\"\""); // https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/ns-shellapi-shellexecuteinfow
// return strData.Replace("\"", "\"\"\"");
// Microsoft C/C++ startup code:
// https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments
// CommandLineToArgvW function:
// https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-commandlinetoargvw
StringBuilder sb = new StringBuilder();
int i = 0;
while(i < strData.Length)
{
char ch = strData[i++];
if(ch == '\\')
{
int cBackslashes = 1;
while((i < strData.Length) && (strData[i] == '\\'))
{
++cBackslashes;
++i;
}
if(i == strData.Length)
sb.Append('\\', cBackslashes); // Assume no quote follows
else if(strData[i] == '\"')
{
sb.Append('\\', (cBackslashes * 2) + 1);
sb.Append('\"');
++i;
}
else sb.Append('\\', cBackslashes);
}
else if(ch == '\"') sb.Append("\\\"");
else sb.Append(ch);
}
return sb.ToString();
} }
/// <summary> // Cf. EncodeDataToArgs
/// Encode a path for <c>Process.Start</c>. internal static string DecodeArgsToData(string strArgs)
/// </summary>
internal static string EncodePath(string strPath)
{ {
if(strPath == null) { Debug.Assert(false); return string.Empty; } if(strArgs == null) { Debug.Assert(false); return string.Empty; }
Debug.Assert(StrUtil.Count(strArgs, "\"") == StrUtil.Count(strArgs, "\\\""));
// Cf. EncodeDataToArgs and DecodeArgsToPath
if(MonoWorkarounds.IsRequired(3471228285U) && IsUnix()) if(MonoWorkarounds.IsRequired(3471228285U) && IsUnix())
{ {
string str = strPath; string str = strArgs;
str = str.Replace("\\", "\\\\"); str = str.Replace("\\\"", "\"");
str = str.Replace("\"", "\\\""); str = str.Replace("\\\\", "\\");
// '\'' must not be encoded in paths (only in args)
// str = str.Replace("\'", "\\\'");
return str; return str;
} }
return strPath; // '\"' is not allowed in paths on Windows StringBuilder sb = new StringBuilder();
int i = 0;
while(i < strArgs.Length)
{
char ch = strArgs[i++];
if(ch == '\\')
{
int cBackslashes = 1;
while((i < strArgs.Length) && (strArgs[i] == '\\'))
{
++cBackslashes;
++i;
}
if(i == strArgs.Length)
sb.Append('\\', cBackslashes); // Assume no quote follows
else if(strArgs[i] == '\"')
{
Debug.Assert((cBackslashes & 1) == 1);
sb.Append('\\', (cBackslashes - 1) / 2);
sb.Append('\"');
++i;
}
else sb.Append('\\', cBackslashes);
}
else sb.Append(ch);
}
return sb.ToString();
} }
/// <summary> internal static void StartProcess(string strFile)
/// Decode command line arguments to a path for <c>Process.Start</c>.
/// </summary>
internal static string DecodeArgsToPath(string strArgs)
{ {
if(strArgs == null) { Debug.Assert(false); return string.Empty; } StartProcess(strFile, null);
}
string str = strArgs; internal static void StartProcess(string strFile, string strArgs)
{
ProcessStartInfo psi = new ProcessStartInfo();
if(!string.IsNullOrEmpty(strFile)) psi.FileName = strFile;
if(!string.IsNullOrEmpty(strArgs)) psi.Arguments = strArgs;
// Cf. EncodeDataToArgs and EncodePath StartProcess(psi);
// if(MonoWorkarounds.IsRequired(3471228285U) && IsUnix()) }
// {
// string strPlh = Guid.NewGuid().ToString();
// str = str.Replace("\\\\", strPlh);
// str = str.Replace("\\\'", "\'");
// str = str.Replace(strPlh, "\\\\"); // Restore
// }
return str; // '\"' is not allowed in paths on Windows internal static void StartProcess(ProcessStartInfo psi)
{
Process p = StartProcessEx(psi);
try { if(p != null) p.Dispose(); }
catch(Exception) { Debug.Assert(false); }
}
internal static Process StartProcessEx(ProcessStartInfo psi)
{
if(psi == null) { Debug.Assert(false); return null; }
string strFileOrg = psi.FileName;
if(string.IsNullOrEmpty(strFileOrg)) { Debug.Assert(false); return null; }
Process p;
try
{
string strFile = strFileOrg;
string[] vUrlEncSchemes = new string[] {
"file:", "ftp:", "ftps:", "http:", "https:",
"mailto:", "scp:", "sftp:"
};
foreach(string strPfx in vUrlEncSchemes)
{
if(strFile.StartsWith(strPfx, StrUtil.CaseIgnoreCmp))
{
Debug.Assert(string.IsNullOrEmpty(psi.Arguments));
strFile = strFile.Replace("\"", "%22");
strFile = strFile.Replace("\'", "%27");
strFile = strFile.Replace("\\", "%5C");
break;
}
}
if(IsUnix())
{
// Mono's Process.Start method replaces '\\' by '/',
// which may cause a different file to be executed;
// therefore, we refuse to start such files
if(strFile.Contains("\\") && MonoWorkarounds.IsRequired(190417))
throw new ArgumentException(KLRes.PathBackslash);
strFile = strFile.Replace("\\", "\\\\"); // If WA not required
strFile = strFile.Replace("\"", "\\\"");
}
psi.FileName = strFile;
p = Process.Start(psi);
}
finally { psi.FileName = strFileOrg; }
return p;
} }
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -0,0 +1,150 @@
/*
KeePass Password Safe - The Open-Source Password Manager
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
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
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;
namespace ModernKeePassLib.Native
{
internal sealed class SimpleStat
{
private readonly object m_oPermissions;
private readonly long m_nUserId;
private readonly long m_nGroupId;
private SimpleStat(object oPermissions, long nUserId, long nGroupId)
{
if(oPermissions == null) throw new ArgumentNullException("oPermissions");
m_oPermissions = oPermissions;
m_nUserId = nUserId;
m_nGroupId = nGroupId;
}
public static SimpleStat Get(string strFilePath)
{
try
{
Type tUfsi, tUfi;
object oUfi = GetUnixFileInfo(strFilePath, out tUfsi, out tUfi);
if(oUfi == null) return null;
PropertyInfo piPerm = tUfsi.GetProperty("FileAccessPermissions",
BindingFlags.Public | BindingFlags.Instance);
if(piPerm == null) { Debug.Assert(false); return null; }
Debug.Assert(piPerm.PropertyType.IsEnum);
PropertyInfo piUser = tUfsi.GetProperty("OwnerUserId",
BindingFlags.Public | BindingFlags.Instance);
if(piUser == null) { Debug.Assert(false); return null; }
Debug.Assert(piUser.PropertyType == typeof(long));
PropertyInfo piGroup = tUfsi.GetProperty("OwnerGroupId",
BindingFlags.Public | BindingFlags.Instance);
if(piGroup == null) { Debug.Assert(false); return null; }
Debug.Assert(piGroup.PropertyType == typeof(long));
return new SimpleStat(piPerm.GetValue(oUfi, null),
(long)piUser.GetValue(oUfi, null),
(long)piGroup.GetValue(oUfi, null));
}
catch(Exception) { Debug.Assert(false); }
return null;
}
public static void Set(string strFilePath, SimpleStat s)
{
if(s == null) { Debug.Assert(false); return; }
try
{
Type tUfsi, tUfi;
object oUfi = GetUnixFileInfo(strFilePath, out tUfsi, out tUfi);
if(oUfi == null) return;
PropertyInfo piPerm = tUfsi.GetProperty("FileAccessPermissions",
BindingFlags.Public | BindingFlags.Instance);
if(piPerm == null) { Debug.Assert(false); return; }
piPerm.SetValue(oUfi, s.m_oPermissions, null);
MethodInfo miOwner = tUfsi.GetMethod("SetOwner",
new Type[] { typeof(long), typeof(long) });
if(miOwner == null) { Debug.Assert(false); return; }
miOwner.Invoke(oUfi, new object[] { s.m_nUserId, s.m_nGroupId });
}
catch(Exception) { Debug.Assert(false); }
}
private static bool GetTypes(out Type tUfsi, out Type tUfi)
{
tUfsi = null;
tUfi = null;
try
{
if(!NativeLib.IsUnix()) return false;
string strVer = typeof(XmlNode).Assembly.GetName().Version.ToString();
string strPosix = "Mono.Posix, Version=" + strVer;
Assembly asmPosix = Assembly.Load(strPosix);
if(asmPosix == null) { Debug.Assert(false); return false; }
tUfsi = asmPosix.GetType("Mono.Unix.UnixFileSystemInfo", false);
tUfi = asmPosix.GetType("Mono.Unix.UnixFileInfo", false);
bool b = ((tUfsi != null) && (tUfi != null));
Debug.Assert(b);
return b;
}
catch(Exception) { Debug.Assert(false); }
return false;
}
private static object GetUnixFileInfo(string strFilePath, Type tUfi)
{
if(string.IsNullOrEmpty(strFilePath)) { Debug.Assert(false); return null; }
try
{
if(!File.Exists(strFilePath)) { Debug.Assert(false); return null; }
return Activator.CreateInstance(tUfi, strFilePath);
}
catch(Exception) { Debug.Assert(false); }
return null;
}
private static object GetUnixFileInfo(string strFilePath,
out Type tUfsi, out Type tUfi)
{
if(!GetTypes(out tUfsi, out tUfi)) return null;
return GetUnixFileInfo(strFilePath, tUfi);
}
}
}

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -108,7 +108,7 @@ namespace ModernKeePassLib
private IStatusLogger m_slStatus = null; private IStatusLogger m_slStatus = null;
private static string m_strLocalizedAppName = string.Empty; private static string g_strLocalizedAppName = string.Empty;
// private const string StrBackupExtension = ".bak"; // private const string StrBackupExtension = ".bak";
@@ -116,16 +116,14 @@ namespace ModernKeePassLib
/// Get the root group that contains all groups and entries stored in the /// Get the root group that contains all groups and entries stored in the
/// database. /// database.
/// </summary> /// </summary>
/// <returns>Root group. The return value is <c>null</c>, if no database /// <returns>Root group. The return value is <c>null</c>, if the database
/// has been opened.</returns> /// is not open.</returns>
public PwGroup RootGroup public PwGroup RootGroup
{ {
get { return m_pgRootGroup; } get { return m_pgRootGroup; }
set set
{ {
Debug.Assert(value != null); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
if(value == null) throw new ArgumentNullException("value");
m_pgRootGroup = value; m_pgRootGroup = value;
} }
} }
@@ -167,8 +165,7 @@ namespace ModernKeePassLib
get { return m_pwUserKey; } get { return m_pwUserKey; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_pwUserKey = value; m_pwUserKey = value;
} }
} }
@@ -187,8 +184,8 @@ namespace ModernKeePassLib
get { return m_strName; } get { return m_strName; }
set set
{ {
Debug.Assert(value != null); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
if(value != null) m_strName = value; m_strName = value;
} }
} }
@@ -206,8 +203,8 @@ namespace ModernKeePassLib
get { return m_strDesc; } get { return m_strDesc; }
set set
{ {
Debug.Assert(value != null); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
if(value != null) m_strDesc = value; m_strDesc = value;
} }
} }
@@ -225,8 +222,8 @@ namespace ModernKeePassLib
get { return m_strDefaultUserName; } get { return m_strDefaultUserName; }
set set
{ {
Debug.Assert(value != null); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
if(value != null) m_strDefaultUserName = value; m_strDefaultUserName = value;
} }
} }
@@ -284,8 +281,8 @@ namespace ModernKeePassLib
get { return m_uuidDataCipher; } get { return m_uuidDataCipher; }
set set
{ {
Debug.Assert(value != null); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
if(value != null) m_uuidDataCipher = value; m_uuidDataCipher = value;
} }
} }
@@ -312,7 +309,7 @@ namespace ModernKeePassLib
get { return m_kdfParams; } get { return m_kdfParams; }
set set
{ {
if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_kdfParams = value; m_kdfParams = value;
} }
} }
@@ -325,8 +322,7 @@ namespace ModernKeePassLib
get { return m_memProtConfig; } get { return m_memProtConfig; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_memProtConfig = value; m_memProtConfig = value;
} }
} }
@@ -362,7 +358,7 @@ namespace ModernKeePassLib
get { return m_pwLastSelectedGroup; } get { return m_pwLastSelectedGroup; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_pwLastSelectedGroup = value; m_pwLastSelectedGroup = value;
} }
} }
@@ -372,7 +368,7 @@ namespace ModernKeePassLib
get { return m_pwLastTopVisibleGroup; } get { return m_pwLastTopVisibleGroup; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_pwLastTopVisibleGroup = value; m_pwLastTopVisibleGroup = value;
} }
} }
@@ -388,7 +384,7 @@ namespace ModernKeePassLib
get { return m_pwRecycleBin; } get { return m_pwRecycleBin; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_pwRecycleBin = value; m_pwRecycleBin = value;
} }
} }
@@ -408,7 +404,7 @@ namespace ModernKeePassLib
get { return m_pwEntryTemplatesGroup; } get { return m_pwEntryTemplatesGroup; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_pwEntryTemplatesGroup = value; m_pwEntryTemplatesGroup = value;
} }
} }
@@ -512,8 +508,12 @@ namespace ModernKeePassLib
/// </summary> /// </summary>
public static string LocalizedAppName public static string LocalizedAppName
{ {
get { return m_strLocalizedAppName; } get { return g_strLocalizedAppName; }
set { Debug.Assert(value != null); m_strLocalizedAppName = value; } set
{
if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
g_strLocalizedAppName = value;
}
} }
/// <summary> /// <summary>
@@ -521,8 +521,6 @@ namespace ModernKeePassLib
/// </summary> /// </summary>
public PwDatabase() public PwDatabase()
{ {
if(m_bPrimaryCreated == false) m_bPrimaryCreated = true;
Clear(); Clear();
} }
@@ -682,7 +680,7 @@ namespace ModernKeePassLib
#if ModernKeePassLib #if ModernKeePassLib
IOConnectionInfo.Bytes = ((MemoryStream)s).ToArray(); IOConnectionInfo.Bytes = ((MemoryStream)s).ToArray();
#endif #endif
} }
ft.CommitWrite(); ft.CommitWrite();
} }
@@ -908,19 +906,18 @@ namespace ModernKeePassLib
MergeInLocationChanged(m_pgRootGroup, ppOrg, ppSrc); MergeInLocationChanged(m_pgRootGroup, ppOrg, ppSrc);
ppOrg = null; // Pools are now invalid, because the location ppOrg = null; // Pools are now invalid, because the location
ppSrc = null; // changed times have been merged in ppSrc = null; // changed times have been merged in
// Delete *after* relocating, because relocating might
// empty some groups that are marked for deletion (and
// objects that weren't relocated yet might prevent the
// deletion)
Dictionary<PwUuid, PwDeletedObject> dOrgDel = CreateDeletedObjectsPool();
MergeInDeletionInfo(pdSource.m_vDeletedObjects, dOrgDel);
ApplyDeletions(m_pgRootGroup, dOrgDel);
// The list and the dictionary should be kept in sync
Debug.Assert(m_vDeletedObjects.UCount == (uint)dOrgDel.Count);
} }
// Delete *after* relocating, because relocating might empty
// some groups that are marked for deletion (and objects
// that weren't relocated yet might prevent the deletion)
Dictionary<PwUuid, PwDeletedObject> dOrgDel = CreateDeletedObjectsPool();
if(mm == PwMergeMethod.Synchronize)
MergeInDeletionInfo(pdSource.m_vDeletedObjects, dOrgDel);
ApplyDeletions(m_pgRootGroup, dOrgDel);
// The list and the dictionary should be kept in sync
Debug.Assert(m_vDeletedObjects.UCount == (uint)dOrgDel.Count);
// Must be called *after* merging groups, because group UUIDs // Must be called *after* merging groups, because group UUIDs
// are required for recycle bin and entry template UUIDs // are required for recycle bin and entry template UUIDs
MergeInDbProperties(pdSource, mm); MergeInDbProperties(pdSource, mm);
@@ -1957,16 +1954,22 @@ namespace ModernKeePassLib
return uDeleted; return uDeleted;
} }
private static List<string> m_lStdFields = null; private static List<string> g_lDupStdFields = null;
private static bool DupEntriesEqual(PwEntry a, PwEntry b) private static bool DupEntriesEqual(PwEntry a, PwEntry b)
{ {
if(m_lStdFields == null) m_lStdFields = PwDefs.GetStandardFields(); if(g_lDupStdFields == null)
foreach(string strStdKey in m_lStdFields)
{ {
string strA = a.Strings.ReadSafe(strStdKey); g_lDupStdFields = PwDefs.GetStandardFields();
string strB = b.Strings.ReadSafe(strStdKey); if(g_lDupStdFields.Remove(PwDefs.PasswordField))
if(!strA.Equals(strB)) return false; g_lDupStdFields.Add(PwDefs.PasswordField); // Move to end (perf. opt.)
else { Debug.Assert(false); }
}
foreach(string strStdKey in g_lDupStdFields)
{
ProtectedString psA = a.Strings.GetSafe(strStdKey);
ProtectedString psB = b.Strings.GetSafe(strStdKey);
if(!psA.Equals(psB, false)) return false;
} }
foreach(KeyValuePair<string, ProtectedString> kvpA in a.Strings) foreach(KeyValuePair<string, ProtectedString> kvpA in a.Strings)

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -234,9 +234,33 @@ namespace ModernKeePassLib
if(strFileVersion == null) { Debug.Assert(false); return string.Empty; } if(strFileVersion == null) { Debug.Assert(false); return string.Empty; }
if(strFileVersion == "2.39") return "2.39 / 2.39.1"; if(strFileVersion == "2.39") return "2.39 / 2.39.1";
if(strFileVersion == "2.42") return "2.42 / 2.42.1";
return strFileVersion; return strFileVersion;
} }
internal static PwIcon GroupIconToEntryIcon(PwIcon i)
{
PwIcon r = i; // Inherit by default
switch(i)
{
case PwIcon.Folder:
case PwIcon.FolderOpen:
case PwIcon.FolderPackage:
Debug.Assert((new PwEntry(false, false)).IconId == PwIcon.Key);
r = PwIcon.Key;
break;
case PwIcon.EMailBox:
r = PwIcon.EMail;
break;
default: break;
}
return r;
}
} }
// #pragma warning disable 1591 // Missing XML comments warning // #pragma warning disable 1591 // Missing XML comments warning

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -73,7 +73,7 @@ namespace ModernKeePassLib
get { return m_uuid; } get { return m_uuid; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_uuid = value; m_uuid = value;
} }
} }
@@ -106,7 +106,7 @@ namespace ModernKeePassLib
get { return m_listStrings; } get { return m_listStrings; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_listStrings = value; m_listStrings = value;
} }
} }
@@ -119,7 +119,7 @@ namespace ModernKeePassLib
get { return m_listBinaries; } get { return m_listBinaries; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_listBinaries = value; m_listBinaries = value;
} }
} }
@@ -132,7 +132,7 @@ namespace ModernKeePassLib
get { return m_listAutoType; } get { return m_listAutoType; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_listAutoType = value; m_listAutoType = value;
} }
} }
@@ -145,7 +145,7 @@ namespace ModernKeePassLib
get { return m_listHistory; } get { return m_listHistory; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_listHistory = value; m_listHistory = value;
} }
} }
@@ -169,7 +169,7 @@ namespace ModernKeePassLib
get { return m_pwCustomIconID; } get { return m_pwCustomIconID; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_pwCustomIconID = value; m_pwCustomIconID = value;
} }
} }
@@ -256,7 +256,7 @@ namespace ModernKeePassLib
get { return m_strOverrideUrl; } get { return m_strOverrideUrl; }
set set
{ {
if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_strOverrideUrl = value; m_strOverrideUrl = value;
} }
} }
@@ -269,7 +269,7 @@ namespace ModernKeePassLib
get { return m_vTags; } get { return m_vTags; }
set set
{ {
if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_vTags = value; m_vTags = value;
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -82,7 +82,7 @@ namespace ModernKeePassLib
get { return m_uuid; } get { return m_uuid; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_uuid = value; m_uuid = value;
} }
} }
@@ -95,7 +95,7 @@ namespace ModernKeePassLib
get { return m_strName; } get { return m_strName; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_strName = value; m_strName = value;
} }
} }
@@ -108,7 +108,7 @@ namespace ModernKeePassLib
get { return m_strNotes; } get { return m_strNotes; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_strNotes = value; m_strNotes = value;
} }
} }
@@ -132,7 +132,7 @@ namespace ModernKeePassLib
get { return m_pwCustomIconID; } get { return m_pwCustomIconID; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_pwCustomIconID = value; m_pwCustomIconID = value;
} }
} }
@@ -262,7 +262,7 @@ namespace ModernKeePassLib
get { return m_strDefaultAutoTypeSequence; } get { return m_strDefaultAutoTypeSequence; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_strDefaultAutoTypeSequence = value; m_strDefaultAutoTypeSequence = value;
} }
} }
@@ -284,7 +284,7 @@ namespace ModernKeePassLib
get { return m_pwLastTopVisibleEntry; } get { return m_pwLastTopVisibleEntry; }
set set
{ {
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value"); if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
m_pwLastTopVisibleEntry = value; m_pwLastTopVisibleEntry = value;
} }
} }
@@ -900,7 +900,7 @@ namespace ModernKeePassLib
{ {
RegexOptions ro = RegexOptions.None; // RegexOptions.Compiled RegexOptions ro = RegexOptions.None; // RegexOptions.Compiled
if((sp.ComparisonMode == StringComparison.CurrentCultureIgnoreCase) || if((sp.ComparisonMode == StringComparison.CurrentCultureIgnoreCase) ||
#if !ModernKeePassLib && !KeePassRT #if !ModernKeePassLib
(sp.ComparisonMode == StringComparison.InvariantCultureIgnoreCase) || (sp.ComparisonMode == StringComparison.InvariantCultureIgnoreCase) ||
#endif #endif
(sp.ComparisonMode == StringComparison.OrdinalIgnoreCase)) (sp.ComparisonMode == StringComparison.OrdinalIgnoreCase))

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -26,6 +26,9 @@ namespace ModernKeePassLib.Resources
{ {
if(dictNew == null) throw new ArgumentNullException("dictNew"); if(dictNew == null) throw new ArgumentNullException("dictNew");
m_strAlgorithmUnknown = TryGetEx(dictNew, "AlgorithmUnknown", m_strAlgorithmUnknown);
m_strCharSetInvalid = TryGetEx(dictNew, "CharSetInvalid", m_strCharSetInvalid);
m_strCharSetTooFewChars = TryGetEx(dictNew, "CharSetTooFewChars", m_strCharSetTooFewChars);
m_strCryptoStreamFailed = TryGetEx(dictNew, "CryptoStreamFailed", m_strCryptoStreamFailed); m_strCryptoStreamFailed = TryGetEx(dictNew, "CryptoStreamFailed", m_strCryptoStreamFailed);
m_strEncDataTooLarge = TryGetEx(dictNew, "EncDataTooLarge", m_strEncDataTooLarge); m_strEncDataTooLarge = TryGetEx(dictNew, "EncDataTooLarge", m_strEncDataTooLarge);
m_strErrorInClipboard = TryGetEx(dictNew, "ErrorInClipboard", m_strErrorInClipboard); m_strErrorInClipboard = TryGetEx(dictNew, "ErrorInClipboard", m_strErrorInClipboard);
@@ -58,10 +61,14 @@ namespace ModernKeePassLib.Resources
m_strMasterSeedLengthInvalid = TryGetEx(dictNew, "MasterSeedLengthInvalid", m_strMasterSeedLengthInvalid); m_strMasterSeedLengthInvalid = TryGetEx(dictNew, "MasterSeedLengthInvalid", m_strMasterSeedLengthInvalid);
m_strOldFormat = TryGetEx(dictNew, "OldFormat", m_strOldFormat); m_strOldFormat = TryGetEx(dictNew, "OldFormat", m_strOldFormat);
m_strPassive = TryGetEx(dictNew, "Passive", m_strPassive); m_strPassive = TryGetEx(dictNew, "Passive", m_strPassive);
m_strPathBackslash = TryGetEx(dictNew, "PathBackslash", m_strPathBackslash);
m_strPatternInvalid = TryGetEx(dictNew, "PatternInvalid", m_strPatternInvalid);
m_strPreAuth = TryGetEx(dictNew, "PreAuth", m_strPreAuth); m_strPreAuth = TryGetEx(dictNew, "PreAuth", m_strPreAuth);
m_strPwGenFailed = TryGetEx(dictNew, "PwGenFailed", m_strPwGenFailed);
m_strStructsTooDeep = TryGetEx(dictNew, "StructsTooDeep", m_strStructsTooDeep); m_strStructsTooDeep = TryGetEx(dictNew, "StructsTooDeep", m_strStructsTooDeep);
m_strTimeout = TryGetEx(dictNew, "Timeout", m_strTimeout); m_strTimeout = TryGetEx(dictNew, "Timeout", m_strTimeout);
m_strTryAgainSecs = TryGetEx(dictNew, "TryAgainSecs", m_strTryAgainSecs); m_strTryAgainSecs = TryGetEx(dictNew, "TryAgainSecs", m_strTryAgainSecs);
m_strUnknownError = TryGetEx(dictNew, "UnknownError", m_strUnknownError);
m_strUnknownHeaderId = TryGetEx(dictNew, "UnknownHeaderId", m_strUnknownHeaderId); m_strUnknownHeaderId = TryGetEx(dictNew, "UnknownHeaderId", m_strUnknownHeaderId);
m_strUnknownKdf = TryGetEx(dictNew, "UnknownKdf", m_strUnknownKdf); m_strUnknownKdf = TryGetEx(dictNew, "UnknownKdf", m_strUnknownKdf);
m_strUserAccountKeyError = TryGetEx(dictNew, "UserAccountKeyError", m_strUserAccountKeyError); m_strUserAccountKeyError = TryGetEx(dictNew, "UserAccountKeyError", m_strUserAccountKeyError);
@@ -69,6 +76,9 @@ namespace ModernKeePassLib.Resources
} }
private static readonly string[] m_vKeyNames = { private static readonly string[] m_vKeyNames = {
"AlgorithmUnknown",
"CharSetInvalid",
"CharSetTooFewChars",
"CryptoStreamFailed", "CryptoStreamFailed",
"EncDataTooLarge", "EncDataTooLarge",
"ErrorInClipboard", "ErrorInClipboard",
@@ -101,10 +111,14 @@ namespace ModernKeePassLib.Resources
"MasterSeedLengthInvalid", "MasterSeedLengthInvalid",
"OldFormat", "OldFormat",
"Passive", "Passive",
"PathBackslash",
"PatternInvalid",
"PreAuth", "PreAuth",
"PwGenFailed",
"StructsTooDeep", "StructsTooDeep",
"Timeout", "Timeout",
"TryAgainSecs", "TryAgainSecs",
"UnknownError",
"UnknownHeaderId", "UnknownHeaderId",
"UnknownKdf", "UnknownKdf",
"UserAccountKeyError", "UserAccountKeyError",
@@ -116,6 +130,39 @@ namespace ModernKeePassLib.Resources
return m_vKeyNames; return m_vKeyNames;
} }
private static string m_strAlgorithmUnknown =
@"The algorithm is unknown.";
/// <summary>
/// Look up a localized string similar to
/// 'The algorithm is unknown.'.
/// </summary>
public static string AlgorithmUnknown
{
get { return m_strAlgorithmUnknown; }
}
private static string m_strCharSetInvalid =
@"The character set is invalid.";
/// <summary>
/// Look up a localized string similar to
/// 'The character set is invalid.'.
/// </summary>
public static string CharSetInvalid
{
get { return m_strCharSetInvalid; }
}
private static string m_strCharSetTooFewChars =
@"There are too few characters in the character set.";
/// <summary>
/// Look up a localized string similar to
/// 'There are too few characters in the character set.'.
/// </summary>
public static string CharSetTooFewChars
{
get { return m_strCharSetTooFewChars; }
}
private static string m_strCryptoStreamFailed = private static string m_strCryptoStreamFailed =
@"Failed to initialize encryption/decryption stream!"; @"Failed to initialize encryption/decryption stream!";
/// <summary> /// <summary>
@@ -468,6 +515,28 @@ namespace ModernKeePassLib.Resources
get { return m_strPassive; } get { return m_strPassive; }
} }
private static string m_strPathBackslash =
@"The path contains a backslash. Such paths are not supported (for security reasons).";
/// <summary>
/// Look up a localized string similar to
/// 'The path contains a backslash. Such paths are not supported (for security reasons).'.
/// </summary>
public static string PathBackslash
{
get { return m_strPathBackslash; }
}
private static string m_strPatternInvalid =
@"The pattern is invalid.";
/// <summary>
/// Look up a localized string similar to
/// 'The pattern is invalid.'.
/// </summary>
public static string PatternInvalid
{
get { return m_strPatternInvalid; }
}
private static string m_strPreAuth = private static string m_strPreAuth =
@"Pre-authenticate"; @"Pre-authenticate";
/// <summary> /// <summary>
@@ -479,6 +548,17 @@ namespace ModernKeePassLib.Resources
get { return m_strPreAuth; } get { return m_strPreAuth; }
} }
private static string m_strPwGenFailed =
@"Failed to generate a password.";
/// <summary>
/// Look up a localized string similar to
/// 'Failed to generate a password.'.
/// </summary>
public static string PwGenFailed
{
get { return m_strPwGenFailed; }
}
private static string m_strStructsTooDeep = private static string m_strStructsTooDeep =
@"Structures are nested too deeply."; @"Structures are nested too deeply.";
/// <summary> /// <summary>
@@ -512,6 +592,17 @@ namespace ModernKeePassLib.Resources
get { return m_strTryAgainSecs; } get { return m_strTryAgainSecs; }
} }
private static string m_strUnknownError =
@"An unknown error occurred.";
/// <summary>
/// Look up a localized string similar to
/// 'An unknown error occurred.'.
/// </summary>
public static string UnknownError
{
get { return m_strUnknownError; }
}
private static string m_strUnknownHeaderId = private static string m_strUnknownHeaderId =
@"Unknown header ID!"; @"Unknown header ID!";
/// <summary> /// <summary>

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@ using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Text; using System.Text;
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT) #if (!ModernKeePassLib && !KeePassUAP)
using System.Security.AccessControl; using System.Security.AccessControl;
#endif #endif
@@ -45,9 +45,9 @@ namespace ModernKeePassLib.Serialization
private bool m_bMadeUnhidden = false; private bool m_bMadeUnhidden = false;
private List<IOConnectionInfo> m_lToDelete = new List<IOConnectionInfo>(); private List<IOConnectionInfo> m_lToDelete = new List<IOConnectionInfo>();
private const string StrTempSuffix = ".tmp"; internal const string StrTempSuffix = ".tmp";
private static readonly string StrTxfTempPrefix = PwDefs.ShortProductName + "_TxF_"; private static readonly string StrTxfTempPrefix = PwDefs.ShortProductName + "_TxF_";
private const string StrTxfTempSuffix = ".tmp"; internal const string StrTxfTempSuffix = ".tmp";
private static Dictionary<string, bool> g_dEnabled = private static Dictionary<string, bool> g_dEnabled =
new Dictionary<string, bool>(StrUtil.CaseIgnoreComparer); new Dictionary<string, bool>(StrUtil.CaseIgnoreComparer);
@@ -212,6 +212,7 @@ namespace ModernKeePassLib.Serialization
byte[] pbSec = null; byte[] pbSec = null;
DateTime? otCreation = null; DateTime? otCreation = null;
SimpleStat sStat = null;
bool bBaseExists = IOConnection.FileExists(m_iocBase); bool bBaseExists = IOConnection.FileExists(m_iocBase);
if(bBaseExists && m_iocBase.IsLocalFile()) if(bBaseExists && m_iocBase.IsLocalFile())
@@ -226,6 +227,7 @@ namespace ModernKeePassLib.Serialization
catch(Exception) { Debug.Assert(false); } catch(Exception) { Debug.Assert(false); }
#endif #endif
otCreation = File.GetCreationTimeUtc(m_iocBase.Path); otCreation = File.GetCreationTimeUtc(m_iocBase.Path);
sStat = SimpleStat.Get(m_iocBase.Path);
#if !ModernKeePassLib #if !ModernKeePassLib
// May throw with Mono // May throw with Mono
FileSecurity sec = File.GetAccessControl(m_iocBase.Path, acs); FileSecurity sec = File.GetAccessControl(m_iocBase.Path, acs);
@@ -255,6 +257,8 @@ namespace ModernKeePassLib.Serialization
if(otCreation.HasValue && (otCreation.Value.Year >= 1971)) if(otCreation.HasValue && (otCreation.Value.Year >= 1971))
File.SetCreationTimeUtc(m_iocBase.Path, otCreation.Value); File.SetCreationTimeUtc(m_iocBase.Path, otCreation.Value);
if(sStat != null) SimpleStat.Set(m_iocBase.Path, sStat);
if(bEfsEncrypted) if(bEfsEncrypted)
{ {
try { File.Encrypt(m_iocBase.Path); } try { File.Encrypt(m_iocBase.Path); }
@@ -328,7 +332,7 @@ namespace ModernKeePassLib.Serialization
{ {
if(NativeLib.IsUnix()) return; if(NativeLib.IsUnix()) return;
if(!m_iocBase.IsLocalFile()) return; if(!m_iocBase.IsLocalFile()) return;
if(IsOneDriveWorkaroundRequired()) return; if(TxfIsUnusable()) return;
string strID = StrUtil.AlphaNumericOnly(Convert.ToBase64String( string strID = StrUtil.AlphaNumericOnly(Convert.ToBase64String(
CryptoRandom.Instance.GetRandomBytes(16))); CryptoRandom.Instance.GetRandomBytes(16)));
@@ -420,46 +424,35 @@ namespace ModernKeePassLib.Serialization
} }
} }
#endif #endif
return false; return false;
} }
internal static void ClearOld() private bool TxfIsUnusable()
{
try
{
// See also TxfPrepare method
DirectoryInfo di = new DirectoryInfo(UrlUtil.GetTempPath());
List<FileInfo> l = UrlUtil.GetFileInfos(di, StrTxfTempPrefix +
"*" + StrTxfTempSuffix, SearchOption.TopDirectoryOnly);
foreach(FileInfo fi in l)
{
if(fi == null) { Debug.Assert(false); continue; }
if(!fi.Name.StartsWith(StrTxfTempPrefix, StrUtil.CaseIgnoreCmp) ||
!fi.Name.EndsWith(StrTxfTempSuffix, StrUtil.CaseIgnoreCmp))
continue;
if((DateTime.UtcNow - fi.LastWriteTimeUtc).TotalDays > 1.0)
fi.Delete();
}
}
catch(Exception) { Debug.Assert(false); }
}
// https://sourceforge.net/p/keepass/discussion/329220/thread/672ffecc65/
// https://sourceforge.net/p/keepass/discussion/329221/thread/514786c23a/
private bool IsOneDriveWorkaroundRequired()
{ {
#if !ModernKeePassLib #if !ModernKeePassLib
if(NativeLib.IsUnix()) return false;
try try
{ {
string strReleaseId = (Registry.GetValue( string strReleaseId = (Registry.GetValue(
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
"ReleaseId", string.Empty) as string); "ReleaseId", string.Empty) as string);
// Due to a bug in Microsoft's 'cldflt.sys' driver, a TxF transaction
// results in a Blue Screen of Death on Windows 10 1903/1909;
// https://www.windowslatest.com/2019/10/20/windows-10-update-issues-bsod-broken-apps-and-defender-atp/
// https://sourceforge.net/p/keepass/discussion/329221/thread/924b94ea48/
// This bug is fixed by the Windows update 4530684;
// https://support.microsoft.com/en-us/help/4530684/windows-10-update-kb4530684
// if(strReleaseId == "1903") return true;
// if(strReleaseId == "1909") return true;
if(strReleaseId != "1809") return false; if(strReleaseId != "1809") return false;
// On Windows 10 1809, OneDrive crashes if the file is
// in a OneDrive folder;
// https://sourceforge.net/p/keepass/discussion/329220/thread/672ffecc65/
// https://sourceforge.net/p/keepass/discussion/329221/thread/514786c23a/
string strFile = m_iocBase.Path; string strFile = m_iocBase.Path;
GFunc<string, string, bool> fMatch = delegate(string strRoot, string strSfx) GFunc<string, string, bool> fMatch = delegate(string strRoot, string strSfx)
@@ -529,5 +522,28 @@ namespace ModernKeePassLib.Serialization
#endif #endif
return false; return false;
} }
internal static void ClearOld()
{
try
{
// See also TxfPrepare method
DirectoryInfo di = new DirectoryInfo(UrlUtil.GetTempPath());
List<FileInfo> l = UrlUtil.GetFileInfos(di, StrTxfTempPrefix +
"*" + StrTxfTempSuffix, SearchOption.TopDirectoryOnly);
foreach(FileInfo fi in l)
{
if(fi == null) { Debug.Assert(false); continue; }
if(!fi.Name.StartsWith(StrTxfTempPrefix, StrUtil.CaseIgnoreCmp) ||
!fi.Name.EndsWith(StrTxfTempSuffix, StrUtil.CaseIgnoreCmp))
continue;
if((DateTime.UtcNow - fi.LastWriteTimeUtc).TotalDays > 1.0)
fi.Delete();
}
}
catch(Exception) { Debug.Assert(false); }
}
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -18,6 +18,7 @@
*/ */
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Text; using System.Text;
@@ -36,16 +37,16 @@ namespace ModernKeePassLib.Serialization
{ {
private const int NbDefaultBufferSize = 1024 * 1024; // 1 MB private const int NbDefaultBufferSize = 1024 * 1024; // 1 MB
private Stream m_sBaseStream; private Stream m_sBase;
private bool m_bWriting; private readonly bool m_bWriting;
private bool m_bVerify; private readonly bool m_bVerify;
private BinaryReader m_brInput = null;
private BinaryWriter m_bwOutput = null;
private bool m_bEos = false; private bool m_bEos = false;
private BinaryReader m_brInput;
private BinaryWriter m_bwOutput;
private byte[] m_pbBuffer; private byte[] m_pbBuffer;
private int m_nBufferPos = 0; private int m_iBufferPos = 0;
private uint m_uBlockIndex = 0; private uint m_uBlockIndex = 0;
@@ -75,50 +76,42 @@ namespace ModernKeePassLib.Serialization
set { Debug.Assert(false); throw new NotSupportedException(); } set { Debug.Assert(false); throw new NotSupportedException(); }
} }
public HashedBlockStream(Stream sBaseStream, bool bWriting) public HashedBlockStream(Stream sBase, bool bWriting) :
this(sBase, bWriting, 0, true)
{ {
Initialize(sBaseStream, bWriting, 0, true);
} }
public HashedBlockStream(Stream sBaseStream, bool bWriting, int nBufferSize) public HashedBlockStream(Stream sBase, bool bWriting, int nBufferSize) :
this(sBase, bWriting, nBufferSize, true)
{ {
Initialize(sBaseStream, bWriting, nBufferSize, true);
} }
public HashedBlockStream(Stream sBaseStream, bool bWriting, int nBufferSize, public HashedBlockStream(Stream sBase, bool bWriting, int nBufferSize,
bool bVerify) bool bVerify)
{ {
Initialize(sBaseStream, bWriting, nBufferSize, bVerify); if(sBase == null) throw new ArgumentNullException("sBase");
}
private void Initialize(Stream sBaseStream, bool bWriting, int nBufferSize,
bool bVerify)
{
if(sBaseStream == null) throw new ArgumentNullException("sBaseStream");
if(nBufferSize < 0) throw new ArgumentOutOfRangeException("nBufferSize"); if(nBufferSize < 0) throw new ArgumentOutOfRangeException("nBufferSize");
if(nBufferSize == 0) nBufferSize = NbDefaultBufferSize; if(nBufferSize == 0) nBufferSize = NbDefaultBufferSize;
m_sBaseStream = sBaseStream; m_sBase = sBase;
m_bWriting = bWriting; m_bWriting = bWriting;
m_bVerify = bVerify; m_bVerify = bVerify;
UTF8Encoding utf8 = StrUtil.Utf8; UTF8Encoding utf8 = StrUtil.Utf8;
if(!m_bWriting) // Reading mode if(!m_bWriting) // Reading mode
{ {
if(!m_sBaseStream.CanRead) if(!m_sBase.CanRead) throw new InvalidOperationException();
throw new InvalidOperationException();
m_brInput = new BinaryReader(sBaseStream, utf8); m_brInput = new BinaryReader(m_sBase, utf8);
m_pbBuffer = MemUtil.EmptyByteArray; m_pbBuffer = MemUtil.EmptyByteArray;
} }
else // Writing mode else // Writing mode
{ {
if(!m_sBaseStream.CanWrite) if(!m_sBase.CanWrite) throw new InvalidOperationException();
throw new InvalidOperationException();
m_bwOutput = new BinaryWriter(sBaseStream, utf8); m_bwOutput = new BinaryWriter(m_sBase, utf8);
m_pbBuffer = new byte[nBufferSize]; m_pbBuffer = new byte[nBufferSize];
} }
@@ -126,7 +119,7 @@ namespace ModernKeePassLib.Serialization
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if(disposing && (m_sBaseStream != null)) if(disposing && (m_sBase != null))
{ {
if(!m_bWriting) // Reading mode if(!m_bWriting) // Reading mode
{ {
@@ -135,12 +128,12 @@ namespace ModernKeePassLib.Serialization
} }
else // Writing mode else // Writing mode
{ {
if(m_nBufferPos == 0) // No data left in buffer if(m_iBufferPos == 0) // No data left in buffer
WriteHashedBlock(); // Write terminating block WriteSafeBlock(); // Write terminating block
else else
{ {
WriteHashedBlock(); // Write remaining buffered data WriteSafeBlock(); // Write remaining buffered data
WriteHashedBlock(); // Write terminating block WriteSafeBlock(); // Write terminating block
} }
Flush(); Flush();
@@ -148,47 +141,60 @@ namespace ModernKeePassLib.Serialization
m_bwOutput = null; m_bwOutput = null;
} }
m_sBaseStream.Dispose(); m_sBase.Dispose();
m_sBaseStream = null; m_sBase = null;
} }
SetBuffer(MemUtil.EmptyByteArray);
base.Dispose(disposing); base.Dispose(disposing);
} }
private void SetBuffer(byte[] pb)
{
MemUtil.ZeroByteArray(m_pbBuffer); // Erase previous buffer
m_pbBuffer = pb;
}
public override void Flush() public override void Flush()
{ {
if(m_bWriting) m_bwOutput.Flush(); Debug.Assert(m_sBase != null); // Object should not be disposed
if(m_bWriting && (m_bwOutput != null)) m_bwOutput.Flush();
} }
public override long Seek(long lOffset, SeekOrigin soOrigin) public override long Seek(long lOffset, SeekOrigin soOrigin)
{ {
Debug.Assert(false);
throw new NotSupportedException(); throw new NotSupportedException();
} }
public override void SetLength(long lValue) public override void SetLength(long lValue)
{ {
Debug.Assert(false);
throw new NotSupportedException(); throw new NotSupportedException();
} }
public override int Read(byte[] pbBuffer, int nOffset, int nCount) public override int Read(byte[] pbBuffer, int iOffset, int nCount)
{ {
if(m_bWriting) throw new InvalidOperationException(); if(m_bWriting) throw new InvalidOperationException();
int nRemaining = nCount; int nRemaining = nCount;
while(nRemaining > 0) while(nRemaining > 0)
{ {
if(m_nBufferPos == m_pbBuffer.Length) if(m_iBufferPos == m_pbBuffer.Length)
{ {
if(ReadHashedBlock() == false) if(!ReadSafeBlock())
return (nCount - nRemaining); // Bytes actually read return (nCount - nRemaining); // Bytes actually read
} }
int nCopy = Math.Min(m_pbBuffer.Length - m_nBufferPos, nRemaining); int nCopy = Math.Min(m_pbBuffer.Length - m_iBufferPos, nRemaining);
Debug.Assert(nCopy > 0);
Array.Copy(m_pbBuffer, m_nBufferPos, pbBuffer, nOffset, nCopy); Array.Copy(m_pbBuffer, m_iBufferPos, pbBuffer, iOffset, nCopy);
nOffset += nCopy; iOffset += nCopy;
m_nBufferPos += nCopy; m_iBufferPos += nCopy;
nRemaining -= nCopy; nRemaining -= nCopy;
} }
@@ -196,11 +202,11 @@ namespace ModernKeePassLib.Serialization
return nCount; return nCount;
} }
private bool ReadHashedBlock() private bool ReadSafeBlock()
{ {
if(m_bEos) return false; // End of stream reached already if(m_bEos) return false; // End of stream reached already
m_nBufferPos = 0; m_iBufferPos = 0;
if(m_brInput.ReadUInt32() != m_uBlockIndex) if(m_brInput.ReadUInt32() != m_uBlockIndex)
throw new InvalidDataException(); throw new InvalidDataException();
@@ -229,11 +235,11 @@ namespace ModernKeePassLib.Serialization
} }
m_bEos = true; m_bEos = true;
m_pbBuffer = MemUtil.EmptyByteArray; SetBuffer(MemUtil.EmptyByteArray);
return false; return false;
} }
m_pbBuffer = m_brInput.ReadBytes(nBufferSize); SetBuffer(m_brInput.ReadBytes(nBufferSize));
if((m_pbBuffer == null) || ((m_pbBuffer.Length != nBufferSize) && m_bVerify)) if((m_pbBuffer == null) || ((m_pbBuffer.Length != nBufferSize) && m_bVerify))
throw new InvalidDataException(); throw new InvalidDataException();
@@ -250,44 +256,45 @@ namespace ModernKeePassLib.Serialization
return true; return true;
} }
public override void Write(byte[] pbBuffer, int nOffset, int nCount) public override void Write(byte[] pbBuffer, int iOffset, int nCount)
{ {
if(!m_bWriting) throw new InvalidOperationException(); if(!m_bWriting) throw new InvalidOperationException();
while(nCount > 0) while(nCount > 0)
{ {
if(m_nBufferPos == m_pbBuffer.Length) if(m_iBufferPos == m_pbBuffer.Length)
WriteHashedBlock(); WriteSafeBlock();
int nCopy = Math.Min(m_pbBuffer.Length - m_nBufferPos, nCount); int nCopy = Math.Min(m_pbBuffer.Length - m_iBufferPos, nCount);
Debug.Assert(nCopy > 0);
Array.Copy(pbBuffer, nOffset, m_pbBuffer, m_nBufferPos, nCopy); Array.Copy(pbBuffer, iOffset, m_pbBuffer, m_iBufferPos, nCopy);
nOffset += nCopy; iOffset += nCopy;
m_nBufferPos += nCopy; m_iBufferPos += nCopy;
nCount -= nCopy; nCount -= nCopy;
} }
} }
private void WriteHashedBlock() private void WriteSafeBlock()
{ {
m_bwOutput.Write(m_uBlockIndex); m_bwOutput.Write(m_uBlockIndex);
++m_uBlockIndex; ++m_uBlockIndex;
if(m_nBufferPos > 0) if(m_iBufferPos != 0)
{ {
byte[] pbHash = CryptoUtil.HashSha256(m_pbBuffer, 0, m_nBufferPos); byte[] pbHash = CryptoUtil.HashSha256(m_pbBuffer, 0, m_iBufferPos);
// For KeePassLibSD: // For KeePassLibSD:
// SHA256Managed sha256 = new SHA256Managed(); // SHA256Managed sha256 = new SHA256Managed();
// byte[] pbHash; // byte[] pbHash;
// if(m_nBufferPos == m_pbBuffer.Length) // if(m_iBufferPos == m_pbBuffer.Length)
// pbHash = sha256.ComputeHash(m_pbBuffer); // pbHash = sha256.ComputeHash(m_pbBuffer);
// else // else
// { // {
// byte[] pbData = new byte[m_nBufferPos]; // byte[] pbData = new byte[m_iBufferPos];
// Array.Copy(m_pbBuffer, 0, pbData, 0, m_nBufferPos); // Array.Copy(m_pbBuffer, 0, pbData, 0, m_iBufferPos);
// pbHash = sha256.ComputeHash(pbData); // pbHash = sha256.ComputeHash(pbData);
// } // }
@@ -301,12 +308,12 @@ namespace ModernKeePassLib.Serialization
m_bwOutput.Write((ulong)0); m_bwOutput.Write((ulong)0);
} }
m_bwOutput.Write(m_nBufferPos); m_bwOutput.Write(m_iBufferPos);
if(m_nBufferPos > 0) if(m_iBufferPos != 0)
m_bwOutput.Write(m_pbBuffer, 0, m_nBufferPos); m_bwOutput.Write(m_pbBuffer, 0, m_iBufferPos);
m_nBufferPos = 0; m_iBufferPos = 0;
} }
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -119,9 +119,18 @@ namespace ModernKeePassLib.Serialization
m_sBase = null; m_sBase = null;
} }
SetBuffer(MemUtil.EmptyByteArray);
base.Dispose(disposing); base.Dispose(disposing);
} }
private void SetBuffer(byte[] pb)
{
MemUtil.ZeroByteArray(m_pbBuffer); // Erase previous buffer
m_pbBuffer = pb;
}
public override void Flush() public override void Flush()
{ {
Debug.Assert(m_sBase != null); // Object should not be disposed Debug.Assert(m_sBase != null); // Object should not be disposed
@@ -225,7 +234,7 @@ namespace ModernKeePassLib.Serialization
m_iBufferPos = 0; m_iBufferPos = 0;
m_pbBuffer = MemUtil.Read(m_sBase, nBlockSize); SetBuffer(MemUtil.Read(m_sBase, nBlockSize));
if((m_pbBuffer == null) || ((m_pbBuffer.Length != nBlockSize) && m_bVerify)) if((m_pbBuffer == null) || ((m_pbBuffer.Length != nBlockSize) && m_bVerify))
throw new EndOfStreamException(KLRes.FileCorrupted + " " + throw new EndOfStreamException(KLRes.FileCorrupted + " " +
KLRes.FileIncompleteExpc); KLRes.FileIncompleteExpc);
@@ -241,7 +250,7 @@ namespace ModernKeePassLib.Serialization
h.TransformBlock(pbBlockSize, 0, pbBlockSize.Length, h.TransformBlock(pbBlockSize, 0, pbBlockSize.Length,
pbBlockSize, 0); pbBlockSize, 0);
if(m_pbBuffer.Length > 0) if(m_pbBuffer.Length != 0)
h.TransformBlock(m_pbBuffer, 0, m_pbBuffer.Length, h.TransformBlock(m_pbBuffer, 0, m_pbBuffer.Length,
m_pbBuffer, 0); m_pbBuffer, 0);
@@ -302,7 +311,7 @@ namespace ModernKeePassLib.Serialization
h.TransformBlock(pbBlockSize, 0, pbBlockSize.Length, h.TransformBlock(pbBlockSize, 0, pbBlockSize.Length,
pbBlockSize, 0); pbBlockSize, 0);
if(cbBlockSize > 0) if(cbBlockSize != 0)
h.TransformBlock(m_pbBuffer, 0, cbBlockSize, m_pbBuffer, 0); h.TransformBlock(m_pbBuffer, 0, cbBlockSize, m_pbBuffer, 0);
h.TransformFinalBlock(MemUtil.EmptyByteArray, 0, 0); h.TransformFinalBlock(MemUtil.EmptyByteArray, 0, 0);
@@ -314,7 +323,7 @@ namespace ModernKeePassLib.Serialization
MemUtil.Write(m_sBase, pbBlockHmac); MemUtil.Write(m_sBase, pbBlockHmac);
// MemUtil.Write(m_sBase, pbBlockIndex); // Implicit // MemUtil.Write(m_sBase, pbBlockIndex); // Implicit
MemUtil.Write(m_sBase, pbBlockSize); MemUtil.Write(m_sBase, pbBlockSize);
if(cbBlockSize > 0) if(cbBlockSize != 0)
m_sBase.Write(m_pbBuffer, 0, cbBlockSize); m_sBase.Write(m_pbBuffer, 0, cbBlockSize);
++m_uBlockIndex; ++m_uBlockIndex;

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -38,7 +38,7 @@ using ModernKeePassLib.Utility;
namespace ModernKeePassLib.Serialization namespace ModernKeePassLib.Serialization
{ {
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT) #if (!ModernKeePassLib && !KeePassLibSD)
internal sealed class IOWebClient : WebClient internal sealed class IOWebClient : WebClient
{ {
private IOConnectionInfo m_ioc; private IOConnectionInfo m_ioc;
@@ -240,7 +240,7 @@ namespace ModernKeePassLib.Serialization
public static class IOConnection public static class IOConnection
{ {
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT) #if (!ModernKeePassLib && !KeePassLibSD)
private static ProxyServerType m_pstProxyType = ProxyServerType.System; private static ProxyServerType m_pstProxyType = ProxyServerType.System;
private static string m_strProxyAddr = string.Empty; private static string m_strProxyAddr = string.Empty;
private static string m_strProxyPort = string.Empty; private static string m_strProxyPort = string.Empty;
@@ -269,7 +269,7 @@ namespace ModernKeePassLib.Serialization
public static event EventHandler<IOAccessEventArgs> IOAccessPre; public static event EventHandler<IOAccessEventArgs> IOAccessPre;
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT) #if (!ModernKeePassLib && !KeePassLibSD)
// Allow self-signed certificates, expired certificates, etc. // Allow self-signed certificates, expired certificates, etc.
private static bool AcceptCertificate(object sender, private static bool AcceptCertificate(object sender,
X509Certificate certificate, X509Chain chain, X509Certificate certificate, X509Chain chain,
@@ -598,12 +598,12 @@ namespace ModernKeePassLib.Serialization
#if ModernKeePassLib #if ModernKeePassLib
return new MemoryStream(ioc.Bytes); return new MemoryStream(ioc.Bytes);
#else #else
return new FileStream(ioc.Path, FileMode.Open, FileAccess.Read, return new FileStream(ioc.Path, FileMode.Open, FileAccess.Read,
FileShare.Read); FileShare.Read);
#endif #endif
} }
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT) #if (!ModernKeePassLib && !KeePassLibSD)
public static Stream OpenWrite(IOConnectionInfo ioc) public static Stream OpenWrite(IOConnectionInfo ioc)
{ {
if(ioc == null) { Debug.Assert(false); return null; } if(ioc == null) { Debug.Assert(false); return null; }
@@ -640,7 +640,7 @@ namespace ModernKeePassLib.Serialization
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 bool FileExists(IOConnectionInfo ioc)
{ {
@@ -718,7 +718,7 @@ namespace ModernKeePassLib.Serialization
} }
#endif #endif
#endif #endif
} }
/// <summary> /// <summary>
/// Rename/move a file. For local file system and WebDAV, the /// Rename/move a file. For local file system and WebDAV, the
@@ -740,13 +740,15 @@ namespace ModernKeePassLib.Serialization
WebRequest req = CreateWebRequest(iocFrom); WebRequest req = CreateWebRequest(iocFrom);
if(req != null) if(req != null)
{ {
string strToCnc = UrlUtil.GetCanonicalUri(iocTo.Path);
if(IsHttpWebRequest(req)) if(IsHttpWebRequest(req))
{ {
#if KeePassUAP #if KeePassUAP
throw new NotSupportedException(); throw new NotSupportedException();
#else #else
req.Method = "MOVE"; req.Method = "MOVE";
req.Headers.Set("Destination", iocTo.Path); // Full URL supported req.Headers.Set("Destination", strToCnc); // Full URL supported
#endif #endif
} }
else if(IsFtpWebRequest(req)) else if(IsFtpWebRequest(req))
@@ -755,13 +757,13 @@ namespace ModernKeePassLib.Serialization
throw new NotSupportedException(); throw new NotSupportedException();
#else #else
req.Method = WebRequestMethods.Ftp.Rename; req.Method = WebRequestMethods.Ftp.Rename;
string strTo = UrlUtil.GetFileName(iocTo.Path); string strToName = UrlUtil.GetFileName(strToCnc);
// We're affected by .NET bug 621450: // We're affected by .NET bug 621450:
// https://connect.microsoft.com/VisualStudio/feedback/details/621450/problem-renaming-file-on-ftp-server-using-ftpwebrequest-in-net-framework-4-0-vs2010-only // https://connect.microsoft.com/VisualStudio/feedback/details/621450/problem-renaming-file-on-ftp-server-using-ftpwebrequest-in-net-framework-4-0-vs2010-only
// Prepending "./", "%2E/" or "Dummy/../" doesn't work. // Prepending "./", "%2E/" or "Dummy/../" doesn't work.
((FtpWebRequest)req).RenameTo = strTo; ((FtpWebRequest)req).RenameTo = strToName;
#endif #endif
} }
else if(IsFileWebRequest(req)) else if(IsFileWebRequest(req))
@@ -776,7 +778,7 @@ namespace ModernKeePassLib.Serialization
throw new NotSupportedException(); throw new NotSupportedException();
#else #else
req.Method = WrmMoveFile; req.Method = WrmMoveFile;
req.Headers.Set(WrhMoveFileTo, iocTo.Path); req.Headers.Set(WrhMoveFileTo, strToCnc);
#endif #endif
} }
@@ -800,7 +802,7 @@ namespace ModernKeePassLib.Serialization
#endif #endif
} }
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT) #if (!ModernKeePassLib && !KeePassLibSD)
private static bool SendCommand(IOConnectionInfo ioc, string strMethod) private static bool SendCommand(IOConnectionInfo ioc, string strMethod)
{ {
try try
@@ -835,24 +837,14 @@ namespace ModernKeePassLib.Serialization
#endif #endif
public static byte[] ReadFile(IOConnectionInfo ioc) public static byte[] ReadFile(IOConnectionInfo ioc)
{ {
Stream sIn = null;
MemoryStream ms = null;
try try
{ {
sIn = IOConnection.OpenRead(ioc); using(Stream s = IOConnection.OpenRead(ioc))
if(sIn == null) return null; {
return MemUtil.Read(s);
ms = new MemoryStream(); }
MemUtil.CopyStream(sIn, ms);
return ms.ToArray();
}
catch(Exception) { }
finally
{
if(sIn != null) sIn.Dispose();
if(ms != null) ms.Dispose();
} }
catch(Exception) { Debug.Assert(false); }
return null; return null;
} }

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -63,10 +63,9 @@ namespace ModernKeePassLib.Serialization
public sealed class IOConnectionInfo : IDeepCloneable<IOConnectionInfo> public sealed class IOConnectionInfo : IDeepCloneable<IOConnectionInfo>
{ {
// private IOFileFormatHint m_ioHint = IOFileFormatHint.None; // private IOFileFormatHint m_ioHint = IOFileFormatHint.None;
public byte[] Bytes { get; set; } public byte[] Bytes { get; set; }
private string m_strUrl = string.Empty; private string m_strUrl = string.Empty;
public string Path public string Path
{ {
get { return m_strUrl; } get { return m_strUrl; }
@@ -115,8 +114,7 @@ namespace ModernKeePassLib.Serialization
} }
private IOCredSaveMode m_ioCredSaveMode = IOCredSaveMode.NoSave; private IOCredSaveMode m_ioCredSaveMode = IOCredSaveMode.NoSave;
public IOCredSaveMode CredSaveMode
public IOCredSaveMode CredSaveMode
{ {
get { return m_ioCredSaveMode; } get { return m_ioCredSaveMode; }
set { m_ioCredSaveMode = value; } set { m_ioCredSaveMode = value; }
@@ -333,7 +331,7 @@ namespace ModernKeePassLib.Serialization
return ioc; return ioc;
} }
public bool CanProbablyAccess() public bool CanProbablyAccess()
{ {
#if ModernKeePassLib #if ModernKeePassLib
if (IsLocalFile()) return Bytes != null; if (IsLocalFile()) return Bytes != null;

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -53,18 +53,18 @@ namespace ModernKeePassLib.Serialization
/// </summary> /// </summary>
public sealed partial class KdbxFile public sealed partial class KdbxFile
{ {
/// <summary> /// <summary>
/// Load a KDBX file. /// Load a KDBX file.
/// </summary> /// </summary>
/// <param name="strFilePath">File to load.</param> /// <param name="strFilePath">File to load.</param>
/// <param name="fmt">Format.</param> /// <param name="fmt">Format.</param>
/// <param name="slLogger">Status logger (optional).</param> /// <param name="slLogger">Status logger (optional).</param>
#if ModernKeePassLib #if ModernKeePassLib
public void Load(byte[] fileContents, KdbxFormat fmt, IStatusLogger slLogger) public void Load(byte[] fileContents, KdbxFormat fmt, IStatusLogger slLogger)
{ {
IOConnectionInfo ioc = IOConnectionInfo.FromByteArray(fileContents); IOConnectionInfo ioc = IOConnectionInfo.FromByteArray(fileContents);
#else #else
public void Load(string strFilePath, KdbxFormat fmt, IStatusLogger slLogger) public void Load(string strFilePath, KdbxFormat fmt, IStatusLogger slLogger)
{ {
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFilePath); IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFilePath);
#endif #endif

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -842,7 +842,7 @@ namespace ModernKeePassLib.Serialization
// string transformation here. By default, language-dependent conversions // string transformation here. By default, language-dependent conversions
// should be applied, otherwise characters could be rendered incorrectly // should be applied, otherwise characters could be rendered incorrectly
// (code page problems). // (code page problems).
if(m_bLocalizedNames) if(g_bLocalizedNames)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
foreach(char ch in strValue) foreach(char ch in strValue)
@@ -853,8 +853,7 @@ namespace ModernKeePassLib.Serialization
// page area // page area
if(char.IsSymbol(ch) || char.IsSurrogate(ch)) if(char.IsSymbol(ch) || char.IsSurrogate(ch))
{ {
System.Globalization.UnicodeCategory cat = UnicodeCategory cat = CharUnicodeInfo.GetUnicodeCategory(ch);
CharUnicodeInfo.GetUnicodeCategory(ch);
// Map character to correct position in code page // Map character to correct position in code page
chMapped = (char)((int)cat * 32 + ch); chMapped = (char)((int)cat * 32 + ch);
} }

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by
@@ -227,7 +227,7 @@ namespace ModernKeePassLib.Serialization
private const uint NeutralLanguageOffset = 0x100000; // 2^20, see 32-bit Unicode specs private const uint NeutralLanguageOffset = 0x100000; // 2^20, see 32-bit Unicode specs
private const uint NeutralLanguageIDSec = 0x7DC5C; // See 32-bit Unicode specs private const uint NeutralLanguageIDSec = 0x7DC5C; // See 32-bit Unicode specs
private const uint NeutralLanguageID = NeutralLanguageOffset + NeutralLanguageIDSec; private const uint NeutralLanguageID = NeutralLanguageOffset + NeutralLanguageIDSec;
private static bool m_bLocalizedNames = false; private static bool g_bLocalizedNames = false;
private enum KdbxHeaderFieldID : byte private enum KdbxHeaderFieldID : byte
{ {
@@ -312,8 +312,8 @@ namespace ModernKeePassLib.Serialization
public static void DetermineLanguageId() public static void DetermineLanguageId()
{ {
// Test if localized names should be used. If localized names are used, // Test if localized names should be used. If localized names are used,
// the m_bLocalizedNames value must be set to true. By default, localized // the g_bLocalizedNames value must be set to true. By default, localized
// names should be used! (Otherwise characters could be corrupted // names should be used (otherwise characters could be corrupted
// because of different code pages). // because of different code pages).
unchecked unchecked
{ {
@@ -321,7 +321,7 @@ namespace ModernKeePassLib.Serialization
foreach(char ch in PwDatabase.LocalizedAppName) foreach(char ch in PwDatabase.LocalizedAppName)
uTest = uTest * 5 + ch; uTest = uTest * 5 + ch;
m_bLocalizedNames = (uTest != NeutralLanguageID); g_bLocalizedNames = (uTest != NeutralLanguageID);
} }
} }
@@ -331,8 +331,11 @@ namespace ModernKeePassLib.Serialization
// See also KeePassKdb2x3.Export (KDBX 3.1 export module) // See also KeePassKdb2x3.Export (KDBX 3.1 export module)
if(m_pwDatabase.DataCipherUuid.Equals(ChaCha20Engine.ChaCha20Uuid))
return FileVersion32;
AesKdf kdfAes = new AesKdf(); AesKdf kdfAes = new AesKdf();
if(!kdfAes.Uuid.Equals(m_pwDatabase.KdfParameters.KdfUuid)) if(!m_pwDatabase.KdfParameters.KdfUuid.Equals(kdfAes.Uuid))
return FileVersion32; return FileVersion32;
if(m_pwDatabase.PublicCustomData.Count > 0) if(m_pwDatabase.PublicCustomData.Count > 0)

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
KeePass Password Safe - The Open-Source Password Manager 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 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 it under the terms of the GNU General Public License as published by

Some files were not shown because too many files have changed in this diff Show More