mirror of
https://github.com/wismna/ModernKeePassLib.git
synced 2025-10-03 07:30:16 -04:00
Update Lib to version 2.44
Update nuget packages
This commit is contained in:
@@ -7,10 +7,13 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<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="NUnit3TestAdapter" Version="3.13.0" />
|
||||
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.3.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -29,13 +29,27 @@ namespace ModernKeePassLib.Cryptography.Cipher
|
||||
{
|
||||
public sealed class ChaCha20Engine : ICipherEngine2
|
||||
{
|
||||
private PwUuid m_uuid = new PwUuid(new byte[] {
|
||||
0xD6, 0x03, 0x8A, 0x2B, 0x8B, 0x6F, 0x4C, 0xB5,
|
||||
0xA5, 0x24, 0x33, 0x9A, 0x31, 0xDB, 0xB5, 0x9A
|
||||
});
|
||||
private static PwUuid g_uuid = null;
|
||||
internal static PwUuid ChaCha20Uuid
|
||||
{
|
||||
get
|
||||
{
|
||||
PwUuid pu = g_uuid;
|
||||
if(pu == null)
|
||||
{
|
||||
pu = new PwUuid(new byte[] {
|
||||
0xD6, 0x03, 0x8A, 0x2B, 0x8B, 0x6F, 0x4C, 0xB5,
|
||||
0xA5, 0x24, 0x33, 0x9A, 0x31, 0xDB, 0xB5, 0x9A });
|
||||
g_uuid = pu;
|
||||
}
|
||||
|
||||
return pu;
|
||||
}
|
||||
}
|
||||
|
||||
public PwUuid CipherUuid
|
||||
{
|
||||
get { return m_uuid; }
|
||||
get { return ChaCha20Engine.ChaCha20Uuid; }
|
||||
}
|
||||
|
||||
public string DisplayName
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -38,6 +38,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
public static readonly string Punctuation = @",.;:";
|
||||
public static readonly string Brackets = @"[]{}()<>";
|
||||
|
||||
public static readonly string Special = "!\"#$%&'*+,./:;=?@\\^`|~";
|
||||
public static readonly string PrintableAsciiSpecial = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
||||
|
||||
public static readonly string UpperHex = "0123456789ABCDEF";
|
||||
@@ -45,95 +46,54 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
|
||||
public static readonly string LookAlike = @"O0l1I|";
|
||||
|
||||
/// <summary>
|
||||
/// Latin-1 Supplement except U+00A0 (NBSP) and U+00AD (SHY).
|
||||
/// </summary>
|
||||
public static readonly string Latin1S =
|
||||
"\u00A1\u00A2\u00A3\u00A4\u00A5\u00A6\u00A7" +
|
||||
"\u00A8\u00A9\u00AA\u00AB\u00AC\u00AE\u00AF" +
|
||||
"\u00B0\u00B1\u00B2\u00B3\u00B4\u00B5\u00B6\u00B7" +
|
||||
"\u00B8\u00B9\u00BA\u00BB\u00BC\u00BD\u00BE\u00BF" +
|
||||
"\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5\u00C6\u00C7" +
|
||||
"\u00C8\u00C9\u00CA\u00CB\u00CC\u00CD\u00CE\u00CF" +
|
||||
"\u00D0\u00D1\u00D2\u00D3\u00D4\u00D5\u00D6\u00D7" +
|
||||
"\u00D8\u00D9\u00DA\u00DB\u00DC\u00DD\u00DE\u00DF" +
|
||||
"\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u00E6\u00E7" +
|
||||
"\u00E8\u00E9\u00EA\u00EB\u00EC\u00ED\u00EE\u00EF" +
|
||||
"\u00F0\u00F1\u00F2\u00F3\u00F4\u00F5\u00F6\u00F7" +
|
||||
"\u00F8\u00F9\u00FA\u00FB\u00FC\u00FD\u00FE\u00FF";
|
||||
|
||||
internal static readonly string MenuAccels = PwCharSet.LowerCase + PwCharSet.Digits;
|
||||
|
||||
[Obsolete]
|
||||
public static string SpecialChars { get { return PwCharSet.Special; } }
|
||||
[Obsolete]
|
||||
public static string HighAnsiChars { get { return PwCharSet.Latin1S; } }
|
||||
|
||||
private const int CharTabSize = 0x10000 / 8;
|
||||
|
||||
private List<char> m_vChars = new List<char>();
|
||||
private List<char> m_lChars = new List<char>();
|
||||
private byte[] m_vTab = new byte[CharTabSize];
|
||||
|
||||
private static string m_strHighAnsi = null;
|
||||
public static string HighAnsiChars
|
||||
{
|
||||
get
|
||||
{
|
||||
if(m_strHighAnsi == null) { new PwCharSet(); } // Create string
|
||||
Debug.Assert(m_strHighAnsi != null);
|
||||
return m_strHighAnsi;
|
||||
}
|
||||
}
|
||||
|
||||
private static string m_strSpecial = null;
|
||||
public static string SpecialChars
|
||||
{
|
||||
get
|
||||
{
|
||||
if(m_strSpecial == null) { new PwCharSet(); } // Create string
|
||||
Debug.Assert(m_strSpecial != null);
|
||||
return m_strSpecial;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new, empty character set collection object.
|
||||
/// Create a new, empty character set.
|
||||
/// </summary>
|
||||
public PwCharSet()
|
||||
{
|
||||
Initialize(true);
|
||||
Debug.Assert(PwCharSet.Latin1S.Length == (16 * 6 - 2));
|
||||
}
|
||||
|
||||
public PwCharSet(string strCharSet)
|
||||
{
|
||||
Initialize(true);
|
||||
Add(strCharSet);
|
||||
}
|
||||
|
||||
private PwCharSet(bool bFullInitialize)
|
||||
{
|
||||
Initialize(bFullInitialize);
|
||||
}
|
||||
|
||||
private void Initialize(bool bFullInitialize)
|
||||
{
|
||||
Clear();
|
||||
|
||||
if(!bFullInitialize) return;
|
||||
|
||||
if(m_strHighAnsi == null)
|
||||
{
|
||||
StringBuilder sbHighAnsi = new StringBuilder();
|
||||
// [U+0080, U+009F] are C1 control characters,
|
||||
// U+00A0 is non-breaking space
|
||||
for(char ch = '\u00A1'; ch <= '\u00AC'; ++ch)
|
||||
sbHighAnsi.Append(ch);
|
||||
// U+00AD is soft hyphen (format character)
|
||||
for(char ch = '\u00AE'; ch < '\u00FF'; ++ch)
|
||||
sbHighAnsi.Append(ch);
|
||||
sbHighAnsi.Append('\u00FF');
|
||||
|
||||
m_strHighAnsi = sbHighAnsi.ToString();
|
||||
}
|
||||
|
||||
if(m_strSpecial == null)
|
||||
{
|
||||
PwCharSet pcs = new PwCharSet(false);
|
||||
pcs.AddRange('!', '/');
|
||||
pcs.AddRange(':', '@');
|
||||
pcs.AddRange('[', '`');
|
||||
pcs.Add(@"|~");
|
||||
pcs.Remove(@"-_ ");
|
||||
pcs.Remove(PwCharSet.Brackets);
|
||||
|
||||
m_strSpecial = pcs.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Number of characters in this set.
|
||||
/// </summary>
|
||||
public uint Size
|
||||
{
|
||||
get { return (uint)m_vChars.Count; }
|
||||
get { return (uint)m_lChars.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -146,10 +106,10 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
{
|
||||
get
|
||||
{
|
||||
if(uPos >= (uint)m_vChars.Count)
|
||||
if(uPos >= (uint)m_lChars.Count)
|
||||
throw new ArgumentOutOfRangeException("uPos");
|
||||
|
||||
return m_vChars[(int)uPos];
|
||||
return m_lChars[(int)uPos];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +118,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
m_vChars.Clear();
|
||||
m_lChars.Clear();
|
||||
Array.Clear(m_vTab, 0, m_vTab.Length);
|
||||
}
|
||||
|
||||
@@ -190,7 +150,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
|
||||
if(!Contains(ch))
|
||||
{
|
||||
m_vChars.Add(ch);
|
||||
m_lChars.Add(ch);
|
||||
m_vTab[ch / 8] |= (byte)(1 << (ch % 8));
|
||||
}
|
||||
}
|
||||
@@ -204,8 +164,6 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
Debug.Assert(strCharSet != null);
|
||||
if(strCharSet == null) throw new ArgumentNullException("strCharSet");
|
||||
|
||||
m_vChars.Capacity = m_vChars.Count + strCharSet.Length;
|
||||
|
||||
foreach(char ch in strCharSet)
|
||||
Add(ch);
|
||||
}
|
||||
@@ -225,8 +183,6 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
|
||||
public void AddRange(char chMin, char chMax)
|
||||
{
|
||||
m_vChars.Capacity = m_vChars.Count + (chMax - chMin) + 1;
|
||||
|
||||
for(char ch = chMin; ch < chMax; ++ch)
|
||||
Add(ch);
|
||||
|
||||
@@ -261,7 +217,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
case 'v': Add(PwCharSet.LowerVowels); break;
|
||||
case 'V': Add(PwCharSet.LowerVowels, PwCharSet.UpperVowels); break;
|
||||
case 'Z': Add(PwCharSet.UpperVowels); break;
|
||||
case 'x': Add(m_strHighAnsi); break;
|
||||
case 'x': Add(PwCharSet.Latin1S); break;
|
||||
default: bResult = false; break;
|
||||
}
|
||||
|
||||
@@ -271,7 +227,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
public bool Remove(char ch)
|
||||
{
|
||||
m_vTab[ch / 8] &= (byte)(~(1 << (ch % 8)));
|
||||
return m_vChars.Remove(ch);
|
||||
return m_lChars.Remove(ch);
|
||||
}
|
||||
|
||||
public bool Remove(string strCharacters)
|
||||
@@ -305,8 +261,8 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
/// <returns>String containing all character set characters.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach(char ch in m_vChars)
|
||||
StringBuilder sb = new StringBuilder(m_lChars.Count);
|
||||
foreach(char ch in m_lChars)
|
||||
sb.Append(ch);
|
||||
|
||||
return sb.ToString();
|
||||
@@ -319,13 +275,13 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.UpperCase) ? 'U' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.LowerCase) ? 'L' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Digits) ? 'D' : '_');
|
||||
sb.Append(RemoveIfAllExist(m_strSpecial) ? 'S' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Special) ? 'S' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Punctuation) ? 'P' : '_');
|
||||
sb.Append(RemoveIfAllExist(@"-") ? 'm' : '_');
|
||||
sb.Append(RemoveIfAllExist(@"_") ? 'u' : '_');
|
||||
sb.Append(RemoveIfAllExist(@" ") ? 's' : '_');
|
||||
sb.Append(RemoveIfAllExist("-") ? 'm' : '_');
|
||||
sb.Append(RemoveIfAllExist("_") ? 'u' : '_');
|
||||
sb.Append(RemoveIfAllExist(" ") ? 's' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Brackets) ? 'B' : '_');
|
||||
sb.Append(RemoveIfAllExist(m_strHighAnsi) ? 'H' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Latin1S) ? 'H' : '_');
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
@@ -338,13 +294,13 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
if(strRanges[0] != '_') Add(PwCharSet.UpperCase);
|
||||
if(strRanges[1] != '_') Add(PwCharSet.LowerCase);
|
||||
if(strRanges[2] != '_') Add(PwCharSet.Digits);
|
||||
if(strRanges[3] != '_') Add(m_strSpecial);
|
||||
if(strRanges[3] != '_') Add(PwCharSet.Special);
|
||||
if(strRanges[4] != '_') Add(PwCharSet.Punctuation);
|
||||
if(strRanges[5] != '_') Add('-');
|
||||
if(strRanges[6] != '_') Add('_');
|
||||
if(strRanges[7] != '_') Add(' ');
|
||||
if(strRanges[8] != '_') Add(PwCharSet.Brackets);
|
||||
if(strRanges[9] != '_') Add(m_strHighAnsi);
|
||||
if(strRanges[9] != '_') Add(PwCharSet.Latin1S);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -42,7 +42,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Utility functions for generating random passwords.
|
||||
/// Password generator.
|
||||
/// </summary>
|
||||
public static class PwGenerator
|
||||
{
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -252,15 +252,15 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
if((ch >= 'A') && (ch <= 'Z')) pcs.Add(PwCharSet.UpperCase);
|
||||
else if((ch >= 'a') && (ch <= 'z')) pcs.Add(PwCharSet.LowerCase);
|
||||
else if((ch >= '0') && (ch <= '9')) pcs.Add(PwCharSet.Digits);
|
||||
else if(PwCharSet.SpecialChars.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.SpecialChars);
|
||||
else if(PwCharSet.Special.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.Special);
|
||||
else if(ch == ' ') pcs.Add(' ');
|
||||
else if(ch == '-') pcs.Add('-');
|
||||
else if(ch == '_') pcs.Add('_');
|
||||
else if(PwCharSet.Brackets.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.Brackets);
|
||||
else if(PwCharSet.HighAnsiChars.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.HighAnsiChars);
|
||||
else if(PwCharSet.Latin1S.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.Latin1S);
|
||||
else pcs.Add(ch);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -39,7 +39,7 @@ namespace ModernKeePassLib.Cryptography
|
||||
internal const char UpperAlpha = 'U';
|
||||
internal const char Digit = 'D';
|
||||
internal const char Special = 'S';
|
||||
internal const char High = 'H';
|
||||
internal const char Latin1S = 'H';
|
||||
internal const char Other = 'X';
|
||||
|
||||
internal const char Dictionary = 'W';
|
||||
@@ -295,7 +295,7 @@ namespace ModernKeePassLib.Cryptography
|
||||
else strSpecial = strSpecial + " ";
|
||||
|
||||
int nSp = strSpecial.Length;
|
||||
int nHi = PwCharSet.HighAnsiChars.Length;
|
||||
int nL1S = PwCharSet.Latin1S.Length;
|
||||
|
||||
m_lCharTypes = new List<QeCharType>();
|
||||
|
||||
@@ -307,10 +307,10 @@ namespace ModernKeePassLib.Cryptography
|
||||
PwCharSet.Digits, true));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.Special,
|
||||
strSpecial, false));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.High,
|
||||
PwCharSet.HighAnsiChars, false));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.Latin1S,
|
||||
PwCharSet.Latin1S, false));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.Other,
|
||||
0x10000 - (2 * 26) - 10 - nSp - nHi));
|
||||
0x10000 - (2 * 26) - 10 - nSp - nL1S));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -92,6 +92,8 @@ namespace ModernKeePassLib.Cryptography
|
||||
TestHmacOtp();
|
||||
|
||||
TestProtectedObjects(r);
|
||||
TestNativeLib();
|
||||
|
||||
TestMemUtil(r);
|
||||
TestStrUtil();
|
||||
TestUrlUtil();
|
||||
@@ -796,94 +798,6 @@ namespace ModernKeePassLib.Cryptography
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void TestMemUtil(Random r)
|
||||
{
|
||||
#if DEBUG
|
||||
byte[] pb = CryptoRandom.Instance.GetRandomBytes((uint)r.Next(
|
||||
0, 0x2FFFF));
|
||||
|
||||
byte[] pbCompressed = MemUtil.Compress(pb);
|
||||
if(!MemUtil.ArraysEqual(MemUtil.Decompress(pbCompressed), pb))
|
||||
throw new InvalidOperationException("GZip");
|
||||
|
||||
Encoding enc = StrUtil.Utf8;
|
||||
pb = enc.GetBytes("012345678901234567890a");
|
||||
byte[] pbN = enc.GetBytes("9012");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 9)
|
||||
throw new InvalidOperationException("MemUtil-1");
|
||||
pbN = enc.GetBytes("01234567890123");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 0)
|
||||
throw new InvalidOperationException("MemUtil-2");
|
||||
pbN = enc.GetBytes("a");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 21)
|
||||
throw new InvalidOperationException("MemUtil-3");
|
||||
pbN = enc.GetBytes("0a");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 20)
|
||||
throw new InvalidOperationException("MemUtil-4");
|
||||
pbN = enc.GetBytes("1");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 1)
|
||||
throw new InvalidOperationException("MemUtil-5");
|
||||
pbN = enc.GetBytes("b");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) >= 0)
|
||||
throw new InvalidOperationException("MemUtil-6");
|
||||
pbN = enc.GetBytes("012b");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) >= 0)
|
||||
throw new InvalidOperationException("MemUtil-7");
|
||||
|
||||
byte[] pbRes = MemUtil.ParseBase32("MY======");
|
||||
byte[] pbExp = Encoding.UTF8.GetBytes("f");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-1");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXQ====");
|
||||
pbExp = Encoding.UTF8.GetBytes("fo");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-2");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6===");
|
||||
pbExp = Encoding.UTF8.GetBytes("foo");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-3");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YQ=");
|
||||
pbExp = Encoding.UTF8.GetBytes("foob");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-4");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YTB");
|
||||
pbExp = Encoding.UTF8.GetBytes("fooba");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-5");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YTBOI======");
|
||||
pbExp = Encoding.UTF8.GetBytes("foobar");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-6");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("JNSXSIDQOJXXM2LEMVZCAYTBONSWIIDPNYQG63TFFV2GS3LFEBYGC43TO5XXEZDTFY======");
|
||||
pbExp = Encoding.UTF8.GetBytes("Key provider based on one-time passwords.");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-7");
|
||||
|
||||
int i = 0 - 0x10203040;
|
||||
pbRes = MemUtil.Int32ToBytes(i);
|
||||
if(MemUtil.ByteArrayToHexString(pbRes) != "C0CFDFEF")
|
||||
throw new Exception("MemUtil-8"); // Must be little-endian
|
||||
if(MemUtil.BytesToUInt32(pbRes) != (uint)i)
|
||||
throw new Exception("MemUtil-9");
|
||||
if(MemUtil.BytesToInt32(pbRes) != i)
|
||||
throw new Exception("MemUtil-10");
|
||||
|
||||
ArrayHelperEx<char> ah = MemUtil.ArrayHelperExOfChar;
|
||||
for(int j = 0; j < 30; ++j)
|
||||
{
|
||||
string strA = r.Next(30).ToString();
|
||||
string strB = r.Next(30).ToString();
|
||||
char[] vA = strA.ToCharArray();
|
||||
char[] vB = strB.ToCharArray();
|
||||
|
||||
if(ah.Equals(vA, vB) != string.Equals(strA, strB))
|
||||
throw new Exception("MemUtil-11");
|
||||
if((vA.Length == vB.Length) && (Math.Sign(ah.Compare(vA, vB)) !=
|
||||
Math.Sign(string.CompareOrdinal(strA, strB))))
|
||||
throw new Exception("MemUtil-12");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void TestHmacOtp()
|
||||
{
|
||||
#if (DEBUG && !KeePassLibSD)
|
||||
@@ -999,6 +913,119 @@ namespace ModernKeePassLib.Cryptography
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void TestNativeLib()
|
||||
{
|
||||
#if DEBUG && !ModernKeePassLib
|
||||
if(NativeLib.IsUnix())
|
||||
{
|
||||
if(NativeLib.EncodeDataToArgs("A\"B C\\D") !=
|
||||
"A\\\"B C\\\\D")
|
||||
throw new Exception("NativeLib-Args-U");
|
||||
}
|
||||
else // Windows
|
||||
{
|
||||
if(NativeLib.EncodeDataToArgs("A\"B C\\D \\\\ \\\" \\\\\" \\\\\\\" \\\\\\") !=
|
||||
"A\\\"B C\\D \\\\ \\\\\\\" \\\\\\\\\\\" \\\\\\\\\\\\\\\" \\\\\\")
|
||||
throw new Exception("NativeLib-Args-W");
|
||||
}
|
||||
|
||||
string strOrg = "A\\B\\\\C\\\\\\D E\"F\"\"G\"\"\"H I\'J\'\'K\'\'\'L " +
|
||||
"M\\\"N\\\\\"O\\\\\\\"P\\\\\\\\\\\"Q R\\\'S T\\\\\'U \\\\\\";
|
||||
string strArgs = NativeLib.EncodeDataToArgs(strOrg);
|
||||
string strDec = NativeLib.DecodeArgsToData(strArgs);
|
||||
if(strDec != strOrg)
|
||||
throw new Exception("NativeLib-Args-EncDec");
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void TestMemUtil(Random r)
|
||||
{
|
||||
#if DEBUG
|
||||
byte[] pb = CryptoRandom.Instance.GetRandomBytes((uint)r.Next(
|
||||
0, 0x2FFFF));
|
||||
|
||||
byte[] pbCompressed = MemUtil.Compress(pb);
|
||||
if(!MemUtil.ArraysEqual(MemUtil.Decompress(pbCompressed), pb))
|
||||
throw new InvalidOperationException("GZip");
|
||||
|
||||
Encoding enc = StrUtil.Utf8;
|
||||
pb = enc.GetBytes("012345678901234567890a");
|
||||
byte[] pbN = enc.GetBytes("9012");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 9)
|
||||
throw new InvalidOperationException("MemUtil-1");
|
||||
pbN = enc.GetBytes("01234567890123");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 0)
|
||||
throw new InvalidOperationException("MemUtil-2");
|
||||
pbN = enc.GetBytes("a");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 21)
|
||||
throw new InvalidOperationException("MemUtil-3");
|
||||
pbN = enc.GetBytes("0a");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 20)
|
||||
throw new InvalidOperationException("MemUtil-4");
|
||||
pbN = enc.GetBytes("1");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 1)
|
||||
throw new InvalidOperationException("MemUtil-5");
|
||||
pbN = enc.GetBytes("b");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) >= 0)
|
||||
throw new InvalidOperationException("MemUtil-6");
|
||||
pbN = enc.GetBytes("012b");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) >= 0)
|
||||
throw new InvalidOperationException("MemUtil-7");
|
||||
|
||||
byte[] pbRes = MemUtil.ParseBase32("MY======");
|
||||
byte[] pbExp = Encoding.ASCII.GetBytes("f");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-1");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXQ====");
|
||||
pbExp = Encoding.ASCII.GetBytes("fo");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-2");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6===");
|
||||
pbExp = Encoding.ASCII.GetBytes("foo");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-3");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YQ=");
|
||||
pbExp = Encoding.ASCII.GetBytes("foob");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-4");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YTB");
|
||||
pbExp = Encoding.ASCII.GetBytes("fooba");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-5");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YTBOI======");
|
||||
pbExp = Encoding.ASCII.GetBytes("foobar");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-6");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("JNSXSIDQOJXXM2LEMVZCAYTBONSWIIDPNYQG63TFFV2GS3LFEBYGC43TO5XXEZDTFY======");
|
||||
pbExp = Encoding.ASCII.GetBytes("Key provider based on one-time passwords.");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-7");
|
||||
|
||||
int i = 0 - 0x10203040;
|
||||
pbRes = MemUtil.Int32ToBytes(i);
|
||||
if(MemUtil.ByteArrayToHexString(pbRes) != "C0CFDFEF")
|
||||
throw new Exception("MemUtil-8"); // Must be little-endian
|
||||
if(MemUtil.BytesToUInt32(pbRes) != (uint)i)
|
||||
throw new Exception("MemUtil-9");
|
||||
if(MemUtil.BytesToInt32(pbRes) != i)
|
||||
throw new Exception("MemUtil-10");
|
||||
|
||||
ArrayHelperEx<char> ah = MemUtil.ArrayHelperExOfChar;
|
||||
for(int j = 0; j < 30; ++j)
|
||||
{
|
||||
string strA = r.Next(30).ToString();
|
||||
string strB = r.Next(30).ToString();
|
||||
char[] vA = strA.ToCharArray();
|
||||
char[] vB = strB.ToCharArray();
|
||||
|
||||
if(ah.Equals(vA, vB) != string.Equals(strA, strB))
|
||||
throw new Exception("MemUtil-11");
|
||||
if((vA.Length == vB.Length) && (Math.Sign(ah.Compare(vA, vB)) !=
|
||||
Math.Sign(string.CompareOrdinal(strA, strB))))
|
||||
throw new Exception("MemUtil-12");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void TestStrUtil()
|
||||
{
|
||||
#if DEBUG
|
||||
@@ -1128,6 +1155,21 @@ namespace ModernKeePassLib.Cryptography
|
||||
Debug.Assert(Uri.UriSchemeHttps.Equals("https", StrUtil.CaseIgnoreCmp));
|
||||
#endif
|
||||
|
||||
string str = UrlUtil.FilterFileName(" A \"*:?/\\|<>B.txt . ");
|
||||
if(!str.StartsWith(" A ")) throw new Exception("UrlUtil-FFN1");
|
||||
if(!str.EndsWith("B.txt")) throw new Exception("UrlUtil-FFN2");
|
||||
if(str.IndexOfAny(new char[] { '\"', '*', ':', '?', '/', '\\', '|', '<', '>' }) >= 0)
|
||||
throw new Exception("UrlUtil-FFN3");
|
||||
|
||||
if(UrlUtil.GetScheme("cmdG://\"Test.txt\"") != "cmdG")
|
||||
throw new Exception("UrlUtil-GS");
|
||||
if(UrlUtil.RemoveScheme("cmdX://\"T\":A") != "\"T\":A")
|
||||
throw new Exception("UrlUtil-RS1");
|
||||
if(UrlUtil.RemoveScheme("cmdY:/\"T\":A") != "/\"T\":A")
|
||||
throw new Exception("UrlUtil-RS2");
|
||||
if(UrlUtil.RemoveScheme("cmdZ:\"T\":A") != "\"T\":A")
|
||||
throw new Exception("UrlUtil-RS3");
|
||||
|
||||
if(UrlUtil.GetHost(@"scheme://domain:port/path?query_string#fragment_id") !=
|
||||
"domain")
|
||||
throw new InvalidOperationException("UrlUtil-H1");
|
||||
@@ -1145,13 +1187,25 @@ namespace ModernKeePassLib.Cryptography
|
||||
if(UrlUtil.GetHost(@"s://u:p@d.tld:p/p?q#f") != "d.tld")
|
||||
throw new InvalidOperationException("UrlUtil-H7");
|
||||
|
||||
if(!NativeLib.IsUnix()) // Windows
|
||||
{
|
||||
if(UrlUtil.FileUrlToPath("file:///C:/Windows/Win.ini") !=
|
||||
"C:\\Windows\\Win.ini")
|
||||
throw new Exception("UrlUtil-FUTP-W");
|
||||
}
|
||||
else // Unix
|
||||
{
|
||||
if(UrlUtil.FileUrlToPath("file:///etc/fstab") != "/etc/fstab")
|
||||
throw new Exception("UrlUtil-FUTP-U");
|
||||
}
|
||||
|
||||
if(NativeLib.IsUnix()) return;
|
||||
|
||||
string strBase = "\\\\HOMESERVER\\Apps\\KeePass\\KeePass.exe";
|
||||
string strDoc = "\\\\HOMESERVER\\Documents\\KeePass\\NewDatabase.kdbx";
|
||||
string strRel = "..\\..\\Documents\\KeePass\\NewDatabase.kdbx";
|
||||
|
||||
string str = UrlUtil.MakeRelativePath(strBase, strDoc);
|
||||
str = UrlUtil.MakeRelativePath(strBase, strDoc);
|
||||
if(!str.Equals(strRel)) throw new InvalidOperationException("UrlUtil-R1");
|
||||
|
||||
str = UrlUtil.MakeAbsolutePath(strBase, strRel);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -179,15 +179,15 @@ namespace ModernKeePassLib.Keys
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new, random key-file.
|
||||
/// </summary>
|
||||
/// <param name="strFilePath">Path where the key-file should be saved to.
|
||||
/// If the file exists already, it will be overwritten.</param>
|
||||
/// <param name="pbAdditionalEntropy">Additional entropy used to generate
|
||||
/// the random key. May be <c>null</c> (in this case only the KeePass-internal
|
||||
/// random number generator is used).</param>
|
||||
/// <returns>Returns a <c>FileSaveResult</c> error code.</returns>
|
||||
/// <summary>
|
||||
/// Create a new, random key-file.
|
||||
/// </summary>
|
||||
/// <param name="strFilePath">Path where the key-file should be saved to.
|
||||
/// If the file exists already, it will be overwritten.</param>
|
||||
/// <param name="pbAdditionalEntropy">Additional entropy used to generate
|
||||
/// the random key. May be <c>null</c> (in this case only the KeePass-internal
|
||||
/// random number generator is used).</param>
|
||||
/// <returns>Returns a <c>FileSaveResult</c> error code.</returns>
|
||||
#if ModernKeePassLib
|
||||
public static byte[] Create(byte[] pbAdditionalEntropy)
|
||||
#else
|
||||
@@ -281,7 +281,7 @@ namespace ModernKeePassLib.Keys
|
||||
private static byte[] CreateXmlKeyFile(byte[] pbKeyData)
|
||||
{
|
||||
#else
|
||||
private static void CreateXmlKeyFile(string strFile, byte[] pbKeyData)
|
||||
private static void CreateXmlKeyFile(string strFile, byte[] pbKeyData)
|
||||
{
|
||||
Debug.Assert(strFile != null);
|
||||
if(strFile == null) throw new ArgumentNullException("strFile");
|
||||
@@ -323,6 +323,6 @@ namespace ModernKeePassLib.Keys
|
||||
return ((MemoryStream) s).ToArray();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,9 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>2.42.1.3</Version>
|
||||
<Version>2.44.0</Version>
|
||||
<Authors>Geoffroy Bonneville</Authors>
|
||||
<PackageLicense>https://www.gnu.org/licenses/gpl-3.0.en.html</PackageLicense>
|
||||
<PackageProjectUrl>https://github.com/wismna/ModernKeePassLib</PackageProjectUrl>
|
||||
@@ -12,7 +12,7 @@
|
||||
<Product>ModernKeePassLib</Product>
|
||||
<PackageReleaseNotes>Save corrections</PackageReleaseNotes>
|
||||
<PackageTags>KeePass KeePassLib Portable PCL NetStandard ModernKeePass</PackageTags>
|
||||
<Copyright>Copyright © 2019 Geoffroy Bonneville</Copyright>
|
||||
<Copyright>Copyright © 2020 Geoffroy Bonneville</Copyright>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
@@ -54,9 +54,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0006" />
|
||||
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.3.0" />
|
||||
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="4.5.0" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
|
||||
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
|
||||
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="4.7.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -27,6 +27,16 @@ namespace ModernKeePassLib.Native
|
||||
{
|
||||
if (!string.IsNullOrEmpty(strApp)) return strApp;
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
internal static string EncodeDataToArgs(string v)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static string DecodeArgsToData(string strApp)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -234,7 +234,7 @@ namespace ModernKeePassLib.Native
|
||||
{
|
||||
ProcessStartInfo psi = new ProcessStartInfo();
|
||||
|
||||
psi.FileName = EncodePath(strAppPath);
|
||||
psi.FileName = strAppPath;
|
||||
if(!string.IsNullOrEmpty(strParams)) psi.Arguments = strParams;
|
||||
|
||||
psi.CreateNoWindow = true;
|
||||
@@ -244,7 +244,7 @@ namespace ModernKeePassLib.Native
|
||||
psi.RedirectStandardOutput = bStdOut;
|
||||
if(strStdInput != null) psi.RedirectStandardInput = true;
|
||||
|
||||
Process p = Process.Start(psi);
|
||||
Process p = StartProcessEx(psi);
|
||||
pToDispose = p;
|
||||
|
||||
if(strStdInput != null)
|
||||
@@ -449,19 +449,18 @@ namespace ModernKeePassLib.Native
|
||||
Marshal.FreeHGlobal(kvpPointers.Value);
|
||||
}
|
||||
|
||||
internal static Type GetUwpType(string strType)
|
||||
{
|
||||
if(string.IsNullOrEmpty(strType)) { Debug.Assert(false); return null; }
|
||||
|
||||
// https://referencesource.microsoft.com/#mscorlib/system/runtime/interopservices/windowsruntime/winrtclassactivator.cs
|
||||
return Type.GetType(strType + ", Windows, ContentType=WindowsRuntime", false);
|
||||
}
|
||||
// internal static Type GetUwpType(string strType)
|
||||
// {
|
||||
// if(string.IsNullOrEmpty(strType)) { Debug.Assert(false); return null; }
|
||||
// // https://referencesource.microsoft.com/#mscorlib/system/runtime/interopservices/windowsruntime/winrtclassactivator.cs
|
||||
// return Type.GetType(strType + ", Windows, ContentType=WindowsRuntime", false);
|
||||
// }
|
||||
|
||||
// Cf. DecodeArgsToData
|
||||
internal static string EncodeDataToArgs(string strData)
|
||||
{
|
||||
if(strData == null) { Debug.Assert(false); return string.Empty; }
|
||||
|
||||
// Cf. EncodePath and DecodeArgsToPath
|
||||
if(MonoWorkarounds.IsRequired(3471228285U) && IsUnix())
|
||||
{
|
||||
string str = strData;
|
||||
@@ -479,53 +478,165 @@ namespace ModernKeePassLib.Native
|
||||
return str;
|
||||
}
|
||||
|
||||
// See SHELLEXECUTEINFO structure documentation
|
||||
return strData.Replace("\"", "\"\"\"");
|
||||
// SHELLEXECUTEINFOW structure documentation:
|
||||
// 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>
|
||||
/// Encode a path for <c>Process.Start</c>.
|
||||
/// </summary>
|
||||
internal static string EncodePath(string strPath)
|
||||
// Cf. EncodeDataToArgs
|
||||
internal static string DecodeArgsToData(string strArgs)
|
||||
{
|
||||
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())
|
||||
{
|
||||
string str = strPath;
|
||||
string str = strArgs;
|
||||
|
||||
str = str.Replace("\\", "\\\\");
|
||||
str = str.Replace("\"", "\\\"");
|
||||
|
||||
// '\'' must not be encoded in paths (only in args)
|
||||
// str = str.Replace("\'", "\\\'");
|
||||
str = str.Replace("\\\"", "\"");
|
||||
str = str.Replace("\\\\", "\\");
|
||||
|
||||
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>
|
||||
/// Decode command line arguments to a path for <c>Process.Start</c>.
|
||||
/// </summary>
|
||||
internal static string DecodeArgsToPath(string strArgs)
|
||||
internal static void StartProcess(string strFile)
|
||||
{
|
||||
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
|
||||
// if(MonoWorkarounds.IsRequired(3471228285U) && IsUnix())
|
||||
// {
|
||||
// string strPlh = Guid.NewGuid().ToString();
|
||||
// str = str.Replace("\\\\", strPlh);
|
||||
// str = str.Replace("\\\'", "\'");
|
||||
// str = str.Replace(strPlh, "\\\\"); // Restore
|
||||
// }
|
||||
StartProcess(psi);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
150
ModernKeePassLib/Native/SimpleStat.cs
Normal file
150
ModernKeePassLib/Native/SimpleStat.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -108,7 +108,7 @@ namespace ModernKeePassLib
|
||||
|
||||
private IStatusLogger m_slStatus = null;
|
||||
|
||||
private static string m_strLocalizedAppName = string.Empty;
|
||||
private static string g_strLocalizedAppName = string.Empty;
|
||||
|
||||
// private const string StrBackupExtension = ".bak";
|
||||
|
||||
@@ -116,16 +116,14 @@ namespace ModernKeePassLib
|
||||
/// Get the root group that contains all groups and entries stored in the
|
||||
/// database.
|
||||
/// </summary>
|
||||
/// <returns>Root group. The return value is <c>null</c>, if no database
|
||||
/// has been opened.</returns>
|
||||
/// <returns>Root group. The return value is <c>null</c>, if the database
|
||||
/// is not open.</returns>
|
||||
public PwGroup RootGroup
|
||||
{
|
||||
get { return m_pgRootGroup; }
|
||||
set
|
||||
{
|
||||
Debug.Assert(value != null);
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
|
||||
if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
|
||||
m_pgRootGroup = value;
|
||||
}
|
||||
}
|
||||
@@ -167,8 +165,7 @@ namespace ModernKeePassLib
|
||||
get { return m_pwUserKey; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -187,8 +184,8 @@ namespace ModernKeePassLib
|
||||
get { return m_strName; }
|
||||
set
|
||||
{
|
||||
Debug.Assert(value != null);
|
||||
if(value != null) m_strName = value;
|
||||
if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
|
||||
m_strName = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,8 +203,8 @@ namespace ModernKeePassLib
|
||||
get { return m_strDesc; }
|
||||
set
|
||||
{
|
||||
Debug.Assert(value != null);
|
||||
if(value != null) m_strDesc = value;
|
||||
if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
|
||||
m_strDesc = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,8 +222,8 @@ namespace ModernKeePassLib
|
||||
get { return m_strDefaultUserName; }
|
||||
set
|
||||
{
|
||||
Debug.Assert(value != null);
|
||||
if(value != null) m_strDefaultUserName = value;
|
||||
if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
|
||||
m_strDefaultUserName = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,8 +281,8 @@ namespace ModernKeePassLib
|
||||
get { return m_uuidDataCipher; }
|
||||
set
|
||||
{
|
||||
Debug.Assert(value != null);
|
||||
if(value != null) m_uuidDataCipher = value;
|
||||
if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
|
||||
m_uuidDataCipher = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +309,7 @@ namespace ModernKeePassLib
|
||||
get { return m_kdfParams; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
|
||||
m_kdfParams = value;
|
||||
}
|
||||
}
|
||||
@@ -325,8 +322,7 @@ namespace ModernKeePassLib
|
||||
get { return m_memProtConfig; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -362,7 +358,7 @@ namespace ModernKeePassLib
|
||||
get { return m_pwLastSelectedGroup; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -372,7 +368,7 @@ namespace ModernKeePassLib
|
||||
get { return m_pwLastTopVisibleGroup; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -388,7 +384,7 @@ namespace ModernKeePassLib
|
||||
get { return m_pwRecycleBin; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -408,7 +404,7 @@ namespace ModernKeePassLib
|
||||
get { return m_pwEntryTemplatesGroup; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -512,8 +508,12 @@ namespace ModernKeePassLib
|
||||
/// </summary>
|
||||
public static string LocalizedAppName
|
||||
{
|
||||
get { return m_strLocalizedAppName; }
|
||||
set { Debug.Assert(value != null); m_strLocalizedAppName = value; }
|
||||
get { return g_strLocalizedAppName; }
|
||||
set
|
||||
{
|
||||
if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
|
||||
g_strLocalizedAppName = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -521,8 +521,6 @@ namespace ModernKeePassLib
|
||||
/// </summary>
|
||||
public PwDatabase()
|
||||
{
|
||||
if(m_bPrimaryCreated == false) m_bPrimaryCreated = true;
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
@@ -682,7 +680,7 @@ namespace ModernKeePassLib
|
||||
#if ModernKeePassLib
|
||||
IOConnectionInfo.Bytes = ((MemoryStream)s).ToArray();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
ft.CommitWrite();
|
||||
}
|
||||
@@ -908,19 +906,18 @@ namespace ModernKeePassLib
|
||||
MergeInLocationChanged(m_pgRootGroup, ppOrg, ppSrc);
|
||||
ppOrg = null; // Pools are now invalid, because the location
|
||||
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
|
||||
// are required for recycle bin and entry template UUIDs
|
||||
MergeInDbProperties(pdSource, mm);
|
||||
@@ -1957,16 +1954,22 @@ namespace ModernKeePassLib
|
||||
return uDeleted;
|
||||
}
|
||||
|
||||
private static List<string> m_lStdFields = null;
|
||||
private static List<string> g_lDupStdFields = null;
|
||||
private static bool DupEntriesEqual(PwEntry a, PwEntry b)
|
||||
{
|
||||
if(m_lStdFields == null) m_lStdFields = PwDefs.GetStandardFields();
|
||||
|
||||
foreach(string strStdKey in m_lStdFields)
|
||||
if(g_lDupStdFields == null)
|
||||
{
|
||||
string strA = a.Strings.ReadSafe(strStdKey);
|
||||
string strB = b.Strings.ReadSafe(strStdKey);
|
||||
if(!strA.Equals(strB)) return false;
|
||||
g_lDupStdFields = PwDefs.GetStandardFields();
|
||||
if(g_lDupStdFields.Remove(PwDefs.PasswordField))
|
||||
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)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -234,9 +234,33 @@ namespace ModernKeePassLib
|
||||
if(strFileVersion == null) { Debug.Assert(false); return string.Empty; }
|
||||
|
||||
if(strFileVersion == "2.39") return "2.39 / 2.39.1";
|
||||
if(strFileVersion == "2.42") return "2.42 / 2.42.1";
|
||||
|
||||
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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -73,7 +73,7 @@ namespace ModernKeePassLib
|
||||
get { return m_uuid; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ namespace ModernKeePassLib
|
||||
get { return m_listStrings; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ namespace ModernKeePassLib
|
||||
get { return m_listBinaries; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ namespace ModernKeePassLib
|
||||
get { return m_listAutoType; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,7 @@ namespace ModernKeePassLib
|
||||
get { return m_listHistory; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,7 @@ namespace ModernKeePassLib
|
||||
get { return m_pwCustomIconID; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -256,7 +256,7 @@ namespace ModernKeePassLib
|
||||
get { return m_strOverrideUrl; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
|
||||
m_strOverrideUrl = value;
|
||||
}
|
||||
}
|
||||
@@ -269,7 +269,7 @@ namespace ModernKeePassLib
|
||||
get { return m_vTags; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
if(value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
|
||||
m_vTags = value;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -82,7 +82,7 @@ namespace ModernKeePassLib
|
||||
get { return m_uuid; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ namespace ModernKeePassLib
|
||||
get { return m_strName; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ namespace ModernKeePassLib
|
||||
get { return m_strNotes; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ namespace ModernKeePassLib
|
||||
get { return m_pwCustomIconID; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -262,7 +262,7 @@ namespace ModernKeePassLib
|
||||
get { return m_strDefaultAutoTypeSequence; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -284,7 +284,7 @@ namespace ModernKeePassLib
|
||||
get { return m_pwLastTopVisibleEntry; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -900,7 +900,7 @@ namespace ModernKeePassLib
|
||||
{
|
||||
RegexOptions ro = RegexOptions.None; // RegexOptions.Compiled
|
||||
if((sp.ComparisonMode == StringComparison.CurrentCultureIgnoreCase) ||
|
||||
#if !ModernKeePassLib && !KeePassRT
|
||||
#if !ModernKeePassLib
|
||||
(sp.ComparisonMode == StringComparison.InvariantCultureIgnoreCase) ||
|
||||
#endif
|
||||
(sp.ComparisonMode == StringComparison.OrdinalIgnoreCase))
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -26,6 +26,9 @@ namespace ModernKeePassLib.Resources
|
||||
{
|
||||
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_strEncDataTooLarge = TryGetEx(dictNew, "EncDataTooLarge", m_strEncDataTooLarge);
|
||||
m_strErrorInClipboard = TryGetEx(dictNew, "ErrorInClipboard", m_strErrorInClipboard);
|
||||
@@ -58,10 +61,14 @@ namespace ModernKeePassLib.Resources
|
||||
m_strMasterSeedLengthInvalid = TryGetEx(dictNew, "MasterSeedLengthInvalid", m_strMasterSeedLengthInvalid);
|
||||
m_strOldFormat = TryGetEx(dictNew, "OldFormat", m_strOldFormat);
|
||||
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_strPwGenFailed = TryGetEx(dictNew, "PwGenFailed", m_strPwGenFailed);
|
||||
m_strStructsTooDeep = TryGetEx(dictNew, "StructsTooDeep", m_strStructsTooDeep);
|
||||
m_strTimeout = TryGetEx(dictNew, "Timeout", m_strTimeout);
|
||||
m_strTryAgainSecs = TryGetEx(dictNew, "TryAgainSecs", m_strTryAgainSecs);
|
||||
m_strUnknownError = TryGetEx(dictNew, "UnknownError", m_strUnknownError);
|
||||
m_strUnknownHeaderId = TryGetEx(dictNew, "UnknownHeaderId", m_strUnknownHeaderId);
|
||||
m_strUnknownKdf = TryGetEx(dictNew, "UnknownKdf", m_strUnknownKdf);
|
||||
m_strUserAccountKeyError = TryGetEx(dictNew, "UserAccountKeyError", m_strUserAccountKeyError);
|
||||
@@ -69,6 +76,9 @@ namespace ModernKeePassLib.Resources
|
||||
}
|
||||
|
||||
private static readonly string[] m_vKeyNames = {
|
||||
"AlgorithmUnknown",
|
||||
"CharSetInvalid",
|
||||
"CharSetTooFewChars",
|
||||
"CryptoStreamFailed",
|
||||
"EncDataTooLarge",
|
||||
"ErrorInClipboard",
|
||||
@@ -101,10 +111,14 @@ namespace ModernKeePassLib.Resources
|
||||
"MasterSeedLengthInvalid",
|
||||
"OldFormat",
|
||||
"Passive",
|
||||
"PathBackslash",
|
||||
"PatternInvalid",
|
||||
"PreAuth",
|
||||
"PwGenFailed",
|
||||
"StructsTooDeep",
|
||||
"Timeout",
|
||||
"TryAgainSecs",
|
||||
"UnknownError",
|
||||
"UnknownHeaderId",
|
||||
"UnknownKdf",
|
||||
"UserAccountKeyError",
|
||||
@@ -116,6 +130,39 @@ namespace ModernKeePassLib.Resources
|
||||
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 =
|
||||
@"Failed to initialize encryption/decryption stream!";
|
||||
/// <summary>
|
||||
@@ -468,6 +515,28 @@ namespace ModernKeePassLib.Resources
|
||||
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 =
|
||||
@"Pre-authenticate";
|
||||
/// <summary>
|
||||
@@ -479,6 +548,17 @@ namespace ModernKeePassLib.Resources
|
||||
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 =
|
||||
@"Structures are nested too deeply.";
|
||||
/// <summary>
|
||||
@@ -512,6 +592,17 @@ namespace ModernKeePassLib.Resources
|
||||
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 =
|
||||
@"Unknown header ID!";
|
||||
/// <summary>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -23,7 +23,7 @@ using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
|
||||
#if (!ModernKeePassLib && !KeePassUAP)
|
||||
using System.Security.AccessControl;
|
||||
#endif
|
||||
|
||||
@@ -45,9 +45,9 @@ namespace ModernKeePassLib.Serialization
|
||||
private bool m_bMadeUnhidden = false;
|
||||
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 const string StrTxfTempSuffix = ".tmp";
|
||||
internal const string StrTxfTempSuffix = ".tmp";
|
||||
|
||||
private static Dictionary<string, bool> g_dEnabled =
|
||||
new Dictionary<string, bool>(StrUtil.CaseIgnoreComparer);
|
||||
@@ -212,6 +212,7 @@ namespace ModernKeePassLib.Serialization
|
||||
byte[] pbSec = null;
|
||||
|
||||
DateTime? otCreation = null;
|
||||
SimpleStat sStat = null;
|
||||
|
||||
bool bBaseExists = IOConnection.FileExists(m_iocBase);
|
||||
if(bBaseExists && m_iocBase.IsLocalFile())
|
||||
@@ -226,6 +227,7 @@ namespace ModernKeePassLib.Serialization
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
#endif
|
||||
otCreation = File.GetCreationTimeUtc(m_iocBase.Path);
|
||||
sStat = SimpleStat.Get(m_iocBase.Path);
|
||||
#if !ModernKeePassLib
|
||||
// May throw with Mono
|
||||
FileSecurity sec = File.GetAccessControl(m_iocBase.Path, acs);
|
||||
@@ -255,6 +257,8 @@ namespace ModernKeePassLib.Serialization
|
||||
if(otCreation.HasValue && (otCreation.Value.Year >= 1971))
|
||||
File.SetCreationTimeUtc(m_iocBase.Path, otCreation.Value);
|
||||
|
||||
if(sStat != null) SimpleStat.Set(m_iocBase.Path, sStat);
|
||||
|
||||
if(bEfsEncrypted)
|
||||
{
|
||||
try { File.Encrypt(m_iocBase.Path); }
|
||||
@@ -328,7 +332,7 @@ namespace ModernKeePassLib.Serialization
|
||||
{
|
||||
if(NativeLib.IsUnix()) return;
|
||||
if(!m_iocBase.IsLocalFile()) return;
|
||||
if(IsOneDriveWorkaroundRequired()) return;
|
||||
if(TxfIsUnusable()) return;
|
||||
|
||||
string strID = StrUtil.AlphaNumericOnly(Convert.ToBase64String(
|
||||
CryptoRandom.Instance.GetRandomBytes(16)));
|
||||
@@ -420,46 +424,35 @@ namespace ModernKeePassLib.Serialization
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
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); }
|
||||
}
|
||||
|
||||
// https://sourceforge.net/p/keepass/discussion/329220/thread/672ffecc65/
|
||||
// https://sourceforge.net/p/keepass/discussion/329221/thread/514786c23a/
|
||||
private bool IsOneDriveWorkaroundRequired()
|
||||
private bool TxfIsUnusable()
|
||||
{
|
||||
#if !ModernKeePassLib
|
||||
if(NativeLib.IsUnix()) return false;
|
||||
|
||||
try
|
||||
{
|
||||
string strReleaseId = (Registry.GetValue(
|
||||
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
|
||||
"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;
|
||||
|
||||
// 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;
|
||||
|
||||
GFunc<string, string, bool> fMatch = delegate(string strRoot, string strSfx)
|
||||
@@ -529,5 +522,28 @@ namespace ModernKeePassLib.Serialization
|
||||
#endif
|
||||
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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
@@ -36,16 +37,16 @@ namespace ModernKeePassLib.Serialization
|
||||
{
|
||||
private const int NbDefaultBufferSize = 1024 * 1024; // 1 MB
|
||||
|
||||
private Stream m_sBaseStream;
|
||||
private bool m_bWriting;
|
||||
private bool m_bVerify;
|
||||
private Stream m_sBase;
|
||||
private readonly bool m_bWriting;
|
||||
private readonly bool m_bVerify;
|
||||
|
||||
private BinaryReader m_brInput = null;
|
||||
private BinaryWriter m_bwOutput = null;
|
||||
|
||||
private bool m_bEos = false;
|
||||
|
||||
private BinaryReader m_brInput;
|
||||
private BinaryWriter m_bwOutput;
|
||||
|
||||
private byte[] m_pbBuffer;
|
||||
private int m_nBufferPos = 0;
|
||||
private int m_iBufferPos = 0;
|
||||
|
||||
private uint m_uBlockIndex = 0;
|
||||
|
||||
@@ -75,50 +76,42 @@ namespace ModernKeePassLib.Serialization
|
||||
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)
|
||||
{
|
||||
Initialize(sBaseStream, bWriting, nBufferSize, bVerify);
|
||||
}
|
||||
|
||||
private void Initialize(Stream sBaseStream, bool bWriting, int nBufferSize,
|
||||
bool bVerify)
|
||||
{
|
||||
if(sBaseStream == null) throw new ArgumentNullException("sBaseStream");
|
||||
if(sBase == null) throw new ArgumentNullException("sBase");
|
||||
if(nBufferSize < 0) throw new ArgumentOutOfRangeException("nBufferSize");
|
||||
|
||||
if(nBufferSize == 0) nBufferSize = NbDefaultBufferSize;
|
||||
|
||||
m_sBaseStream = sBaseStream;
|
||||
m_sBase = sBase;
|
||||
m_bWriting = bWriting;
|
||||
m_bVerify = bVerify;
|
||||
|
||||
UTF8Encoding utf8 = StrUtil.Utf8;
|
||||
if(!m_bWriting) // Reading mode
|
||||
{
|
||||
if(!m_sBaseStream.CanRead)
|
||||
throw new InvalidOperationException();
|
||||
if(!m_sBase.CanRead) throw new InvalidOperationException();
|
||||
|
||||
m_brInput = new BinaryReader(sBaseStream, utf8);
|
||||
m_brInput = new BinaryReader(m_sBase, utf8);
|
||||
|
||||
m_pbBuffer = MemUtil.EmptyByteArray;
|
||||
}
|
||||
else // Writing mode
|
||||
{
|
||||
if(!m_sBaseStream.CanWrite)
|
||||
throw new InvalidOperationException();
|
||||
if(!m_sBase.CanWrite) throw new InvalidOperationException();
|
||||
|
||||
m_bwOutput = new BinaryWriter(sBaseStream, utf8);
|
||||
m_bwOutput = new BinaryWriter(m_sBase, utf8);
|
||||
|
||||
m_pbBuffer = new byte[nBufferSize];
|
||||
}
|
||||
@@ -126,7 +119,7 @@ namespace ModernKeePassLib.Serialization
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if(disposing && (m_sBaseStream != null))
|
||||
if(disposing && (m_sBase != null))
|
||||
{
|
||||
if(!m_bWriting) // Reading mode
|
||||
{
|
||||
@@ -135,12 +128,12 @@ namespace ModernKeePassLib.Serialization
|
||||
}
|
||||
else // Writing mode
|
||||
{
|
||||
if(m_nBufferPos == 0) // No data left in buffer
|
||||
WriteHashedBlock(); // Write terminating block
|
||||
if(m_iBufferPos == 0) // No data left in buffer
|
||||
WriteSafeBlock(); // Write terminating block
|
||||
else
|
||||
{
|
||||
WriteHashedBlock(); // Write remaining buffered data
|
||||
WriteHashedBlock(); // Write terminating block
|
||||
WriteSafeBlock(); // Write remaining buffered data
|
||||
WriteSafeBlock(); // Write terminating block
|
||||
}
|
||||
|
||||
Flush();
|
||||
@@ -148,47 +141,60 @@ namespace ModernKeePassLib.Serialization
|
||||
m_bwOutput = null;
|
||||
}
|
||||
|
||||
m_sBaseStream.Dispose();
|
||||
m_sBaseStream = null;
|
||||
m_sBase.Dispose();
|
||||
m_sBase = null;
|
||||
}
|
||||
|
||||
SetBuffer(MemUtil.EmptyByteArray);
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private void SetBuffer(byte[] pb)
|
||||
{
|
||||
MemUtil.ZeroByteArray(m_pbBuffer); // Erase previous buffer
|
||||
|
||||
m_pbBuffer = pb;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Debug.Assert(false);
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void SetLength(long lValue)
|
||||
{
|
||||
Debug.Assert(false);
|
||||
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();
|
||||
|
||||
int nRemaining = nCount;
|
||||
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
|
||||
}
|
||||
|
||||
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;
|
||||
m_nBufferPos += nCopy;
|
||||
iOffset += nCopy;
|
||||
m_iBufferPos += nCopy;
|
||||
|
||||
nRemaining -= nCopy;
|
||||
}
|
||||
@@ -196,11 +202,11 @@ namespace ModernKeePassLib.Serialization
|
||||
return nCount;
|
||||
}
|
||||
|
||||
private bool ReadHashedBlock()
|
||||
private bool ReadSafeBlock()
|
||||
{
|
||||
if(m_bEos) return false; // End of stream reached already
|
||||
|
||||
m_nBufferPos = 0;
|
||||
m_iBufferPos = 0;
|
||||
|
||||
if(m_brInput.ReadUInt32() != m_uBlockIndex)
|
||||
throw new InvalidDataException();
|
||||
@@ -229,11 +235,11 @@ namespace ModernKeePassLib.Serialization
|
||||
}
|
||||
|
||||
m_bEos = true;
|
||||
m_pbBuffer = MemUtil.EmptyByteArray;
|
||||
SetBuffer(MemUtil.EmptyByteArray);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pbBuffer = m_brInput.ReadBytes(nBufferSize);
|
||||
SetBuffer(m_brInput.ReadBytes(nBufferSize));
|
||||
if((m_pbBuffer == null) || ((m_pbBuffer.Length != nBufferSize) && m_bVerify))
|
||||
throw new InvalidDataException();
|
||||
|
||||
@@ -250,44 +256,45 @@ namespace ModernKeePassLib.Serialization
|
||||
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();
|
||||
|
||||
while(nCount > 0)
|
||||
{
|
||||
if(m_nBufferPos == m_pbBuffer.Length)
|
||||
WriteHashedBlock();
|
||||
if(m_iBufferPos == m_pbBuffer.Length)
|
||||
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;
|
||||
m_nBufferPos += nCopy;
|
||||
iOffset += nCopy;
|
||||
m_iBufferPos += nCopy;
|
||||
|
||||
nCount -= nCopy;
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteHashedBlock()
|
||||
private void WriteSafeBlock()
|
||||
{
|
||||
m_bwOutput.Write(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:
|
||||
// SHA256Managed sha256 = new SHA256Managed();
|
||||
// byte[] pbHash;
|
||||
// if(m_nBufferPos == m_pbBuffer.Length)
|
||||
// if(m_iBufferPos == m_pbBuffer.Length)
|
||||
// pbHash = sha256.ComputeHash(m_pbBuffer);
|
||||
// else
|
||||
// {
|
||||
// byte[] pbData = new byte[m_nBufferPos];
|
||||
// Array.Copy(m_pbBuffer, 0, pbData, 0, m_nBufferPos);
|
||||
// byte[] pbData = new byte[m_iBufferPos];
|
||||
// Array.Copy(m_pbBuffer, 0, pbData, 0, m_iBufferPos);
|
||||
// pbHash = sha256.ComputeHash(pbData);
|
||||
// }
|
||||
|
||||
@@ -301,12 +308,12 @@ namespace ModernKeePassLib.Serialization
|
||||
m_bwOutput.Write((ulong)0);
|
||||
}
|
||||
|
||||
m_bwOutput.Write(m_nBufferPos);
|
||||
m_bwOutput.Write(m_iBufferPos);
|
||||
|
||||
if(m_nBufferPos > 0)
|
||||
m_bwOutput.Write(m_pbBuffer, 0, m_nBufferPos);
|
||||
if(m_iBufferPos != 0)
|
||||
m_bwOutput.Write(m_pbBuffer, 0, m_iBufferPos);
|
||||
|
||||
m_nBufferPos = 0;
|
||||
m_iBufferPos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -119,9 +119,18 @@ namespace ModernKeePassLib.Serialization
|
||||
m_sBase = null;
|
||||
}
|
||||
|
||||
SetBuffer(MemUtil.EmptyByteArray);
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private void SetBuffer(byte[] pb)
|
||||
{
|
||||
MemUtil.ZeroByteArray(m_pbBuffer); // Erase previous buffer
|
||||
|
||||
m_pbBuffer = pb;
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
Debug.Assert(m_sBase != null); // Object should not be disposed
|
||||
@@ -225,7 +234,7 @@ namespace ModernKeePassLib.Serialization
|
||||
|
||||
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))
|
||||
throw new EndOfStreamException(KLRes.FileCorrupted + " " +
|
||||
KLRes.FileIncompleteExpc);
|
||||
@@ -241,7 +250,7 @@ namespace ModernKeePassLib.Serialization
|
||||
h.TransformBlock(pbBlockSize, 0, pbBlockSize.Length,
|
||||
pbBlockSize, 0);
|
||||
|
||||
if(m_pbBuffer.Length > 0)
|
||||
if(m_pbBuffer.Length != 0)
|
||||
h.TransformBlock(m_pbBuffer, 0, m_pbBuffer.Length,
|
||||
m_pbBuffer, 0);
|
||||
|
||||
@@ -302,7 +311,7 @@ namespace ModernKeePassLib.Serialization
|
||||
h.TransformBlock(pbBlockSize, 0, pbBlockSize.Length,
|
||||
pbBlockSize, 0);
|
||||
|
||||
if(cbBlockSize > 0)
|
||||
if(cbBlockSize != 0)
|
||||
h.TransformBlock(m_pbBuffer, 0, cbBlockSize, m_pbBuffer, 0);
|
||||
|
||||
h.TransformFinalBlock(MemUtil.EmptyByteArray, 0, 0);
|
||||
@@ -314,7 +323,7 @@ namespace ModernKeePassLib.Serialization
|
||||
MemUtil.Write(m_sBase, pbBlockHmac);
|
||||
// MemUtil.Write(m_sBase, pbBlockIndex); // Implicit
|
||||
MemUtil.Write(m_sBase, pbBlockSize);
|
||||
if(cbBlockSize > 0)
|
||||
if(cbBlockSize != 0)
|
||||
m_sBase.Write(m_pbBuffer, 0, cbBlockSize);
|
||||
|
||||
++m_uBlockIndex;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -38,7 +38,7 @@ using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Serialization
|
||||
{
|
||||
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
|
||||
#if (!ModernKeePassLib && !KeePassLibSD)
|
||||
internal sealed class IOWebClient : WebClient
|
||||
{
|
||||
private IOConnectionInfo m_ioc;
|
||||
@@ -240,7 +240,7 @@ namespace ModernKeePassLib.Serialization
|
||||
|
||||
public static class IOConnection
|
||||
{
|
||||
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
|
||||
#if (!ModernKeePassLib && !KeePassLibSD)
|
||||
private static ProxyServerType m_pstProxyType = ProxyServerType.System;
|
||||
private static string m_strProxyAddr = string.Empty;
|
||||
private static string m_strProxyPort = string.Empty;
|
||||
@@ -269,7 +269,7 @@ namespace ModernKeePassLib.Serialization
|
||||
|
||||
public static event EventHandler<IOAccessEventArgs> IOAccessPre;
|
||||
|
||||
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
|
||||
#if (!ModernKeePassLib && !KeePassLibSD)
|
||||
// Allow self-signed certificates, expired certificates, etc.
|
||||
private static bool AcceptCertificate(object sender,
|
||||
X509Certificate certificate, X509Chain chain,
|
||||
@@ -598,12 +598,12 @@ namespace ModernKeePassLib.Serialization
|
||||
#if ModernKeePassLib
|
||||
return new MemoryStream(ioc.Bytes);
|
||||
#else
|
||||
return new FileStream(ioc.Path, FileMode.Open, FileAccess.Read,
|
||||
return new FileStream(ioc.Path, FileMode.Open, FileAccess.Read,
|
||||
FileShare.Read);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
|
||||
#if (!ModernKeePassLib && !KeePassLibSD)
|
||||
public static Stream OpenWrite(IOConnectionInfo ioc)
|
||||
{
|
||||
if(ioc == null) { Debug.Assert(false); return null; }
|
||||
@@ -640,7 +640,7 @@ namespace ModernKeePassLib.Serialization
|
||||
return new FileStream(ioc.Path, FileMode.Create, FileAccess.Write,
|
||||
FileShare.None);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public static bool FileExists(IOConnectionInfo ioc)
|
||||
{
|
||||
@@ -718,7 +718,7 @@ namespace ModernKeePassLib.Serialization
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rename/move a file. For local file system and WebDAV, the
|
||||
@@ -740,13 +740,15 @@ namespace ModernKeePassLib.Serialization
|
||||
WebRequest req = CreateWebRequest(iocFrom);
|
||||
if(req != null)
|
||||
{
|
||||
string strToCnc = UrlUtil.GetCanonicalUri(iocTo.Path);
|
||||
|
||||
if(IsHttpWebRequest(req))
|
||||
{
|
||||
#if KeePassUAP
|
||||
throw new NotSupportedException();
|
||||
#else
|
||||
req.Method = "MOVE";
|
||||
req.Headers.Set("Destination", iocTo.Path); // Full URL supported
|
||||
req.Headers.Set("Destination", strToCnc); // Full URL supported
|
||||
#endif
|
||||
}
|
||||
else if(IsFtpWebRequest(req))
|
||||
@@ -755,13 +757,13 @@ namespace ModernKeePassLib.Serialization
|
||||
throw new NotSupportedException();
|
||||
#else
|
||||
req.Method = WebRequestMethods.Ftp.Rename;
|
||||
string strTo = UrlUtil.GetFileName(iocTo.Path);
|
||||
string strToName = UrlUtil.GetFileName(strToCnc);
|
||||
|
||||
// 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
|
||||
// Prepending "./", "%2E/" or "Dummy/../" doesn't work.
|
||||
|
||||
((FtpWebRequest)req).RenameTo = strTo;
|
||||
((FtpWebRequest)req).RenameTo = strToName;
|
||||
#endif
|
||||
}
|
||||
else if(IsFileWebRequest(req))
|
||||
@@ -776,7 +778,7 @@ namespace ModernKeePassLib.Serialization
|
||||
throw new NotSupportedException();
|
||||
#else
|
||||
req.Method = WrmMoveFile;
|
||||
req.Headers.Set(WrhMoveFileTo, iocTo.Path);
|
||||
req.Headers.Set(WrhMoveFileTo, strToCnc);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -800,7 +802,7 @@ namespace ModernKeePassLib.Serialization
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
|
||||
#if (!ModernKeePassLib && !KeePassLibSD)
|
||||
private static bool SendCommand(IOConnectionInfo ioc, string strMethod)
|
||||
{
|
||||
try
|
||||
@@ -835,24 +837,14 @@ namespace ModernKeePassLib.Serialization
|
||||
#endif
|
||||
public static byte[] ReadFile(IOConnectionInfo ioc)
|
||||
{
|
||||
Stream sIn = null;
|
||||
MemoryStream ms = null;
|
||||
try
|
||||
{
|
||||
sIn = IOConnection.OpenRead(ioc);
|
||||
if(sIn == null) return null;
|
||||
|
||||
ms = new MemoryStream();
|
||||
MemUtil.CopyStream(sIn, ms);
|
||||
|
||||
return ms.ToArray();
|
||||
}
|
||||
catch(Exception) { }
|
||||
finally
|
||||
{
|
||||
if(sIn != null) sIn.Dispose();
|
||||
if(ms != null) ms.Dispose();
|
||||
using(Stream s = IOConnection.OpenRead(ioc))
|
||||
{
|
||||
return MemUtil.Read(s);
|
||||
}
|
||||
}
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -63,10 +63,9 @@ namespace ModernKeePassLib.Serialization
|
||||
public sealed class IOConnectionInfo : IDeepCloneable<IOConnectionInfo>
|
||||
{
|
||||
// private IOFileFormatHint m_ioHint = IOFileFormatHint.None;
|
||||
|
||||
public byte[] Bytes { get; set; }
|
||||
|
||||
private string m_strUrl = string.Empty;
|
||||
private string m_strUrl = string.Empty;
|
||||
public string Path
|
||||
{
|
||||
get { return m_strUrl; }
|
||||
@@ -115,8 +114,7 @@ namespace ModernKeePassLib.Serialization
|
||||
}
|
||||
|
||||
private IOCredSaveMode m_ioCredSaveMode = IOCredSaveMode.NoSave;
|
||||
|
||||
public IOCredSaveMode CredSaveMode
|
||||
public IOCredSaveMode CredSaveMode
|
||||
{
|
||||
get { return m_ioCredSaveMode; }
|
||||
set { m_ioCredSaveMode = value; }
|
||||
@@ -333,7 +331,7 @@ namespace ModernKeePassLib.Serialization
|
||||
return ioc;
|
||||
}
|
||||
|
||||
public bool CanProbablyAccess()
|
||||
public bool CanProbablyAccess()
|
||||
{
|
||||
#if ModernKeePassLib
|
||||
if (IsLocalFile()) return Bytes != null;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -53,18 +53,18 @@ namespace ModernKeePassLib.Serialization
|
||||
/// </summary>
|
||||
public sealed partial class KdbxFile
|
||||
{
|
||||
/// <summary>
|
||||
/// Load a KDBX file.
|
||||
/// </summary>
|
||||
/// <param name="strFilePath">File to load.</param>
|
||||
/// <param name="fmt">Format.</param>
|
||||
/// <param name="slLogger">Status logger (optional).</param>
|
||||
/// <summary>
|
||||
/// Load a KDBX file.
|
||||
/// </summary>
|
||||
/// <param name="strFilePath">File to load.</param>
|
||||
/// <param name="fmt">Format.</param>
|
||||
/// <param name="slLogger">Status logger (optional).</param>
|
||||
#if ModernKeePassLib
|
||||
public void Load(byte[] fileContents, KdbxFormat fmt, IStatusLogger slLogger)
|
||||
{
|
||||
IOConnectionInfo ioc = IOConnectionInfo.FromByteArray(fileContents);
|
||||
#else
|
||||
public void Load(string strFilePath, KdbxFormat fmt, IStatusLogger slLogger)
|
||||
public void Load(string strFilePath, KdbxFormat fmt, IStatusLogger slLogger)
|
||||
{
|
||||
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFilePath);
|
||||
#endif
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -842,7 +842,7 @@ namespace ModernKeePassLib.Serialization
|
||||
// string transformation here. By default, language-dependent conversions
|
||||
// should be applied, otherwise characters could be rendered incorrectly
|
||||
// (code page problems).
|
||||
if(m_bLocalizedNames)
|
||||
if(g_bLocalizedNames)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach(char ch in strValue)
|
||||
@@ -853,8 +853,7 @@ namespace ModernKeePassLib.Serialization
|
||||
// page area
|
||||
if(char.IsSymbol(ch) || char.IsSurrogate(ch))
|
||||
{
|
||||
System.Globalization.UnicodeCategory cat =
|
||||
CharUnicodeInfo.GetUnicodeCategory(ch);
|
||||
UnicodeCategory cat = CharUnicodeInfo.GetUnicodeCategory(ch);
|
||||
// Map character to correct position in code page
|
||||
chMapped = (char)((int)cat * 32 + ch);
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -227,7 +227,7 @@ namespace ModernKeePassLib.Serialization
|
||||
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 NeutralLanguageID = NeutralLanguageOffset + NeutralLanguageIDSec;
|
||||
private static bool m_bLocalizedNames = false;
|
||||
private static bool g_bLocalizedNames = false;
|
||||
|
||||
private enum KdbxHeaderFieldID : byte
|
||||
{
|
||||
@@ -312,8 +312,8 @@ namespace ModernKeePassLib.Serialization
|
||||
public static void DetermineLanguageId()
|
||||
{
|
||||
// Test if localized names should be used. If localized names are used,
|
||||
// the m_bLocalizedNames value must be set to true. By default, localized
|
||||
// names should be used! (Otherwise characters could be corrupted
|
||||
// the g_bLocalizedNames value must be set to true. By default, localized
|
||||
// names should be used (otherwise characters could be corrupted
|
||||
// because of different code pages).
|
||||
unchecked
|
||||
{
|
||||
@@ -321,7 +321,7 @@ namespace ModernKeePassLib.Serialization
|
||||
foreach(char ch in PwDatabase.LocalizedAppName)
|
||||
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)
|
||||
|
||||
if(m_pwDatabase.DataCipherUuid.Equals(ChaCha20Engine.ChaCha20Uuid))
|
||||
return FileVersion32;
|
||||
|
||||
AesKdf kdfAes = new AesKdf();
|
||||
if(!kdfAes.Uuid.Equals(m_pwDatabase.KdfParameters.KdfUuid))
|
||||
if(!m_pwDatabase.KdfParameters.KdfUuid.Equals(kdfAes.Uuid))
|
||||
return FileVersion32;
|
||||
|
||||
if(m_pwDatabase.PublicCustomData.Count > 0)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2020 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user