From ed4d3201afe82b113094d4b410de019e08e12953 Mon Sep 17 00:00:00 2001 From: Geoffroy BONNEVILLE Date: Fri, 24 Apr 2020 15:35:50 +0200 Subject: [PATCH] Populated readme file Removed version check for XML writes --- .../ModernKeePassLib.Test.csproj | 2 -- ModernKeePassLib.sln | 6 ++++ ModernKeePassLib/ModernKeePassLib.csproj | 4 +-- .../Serialization/KdbxFile.Write.cs | 2 +- ModernKeePassLib/Utility/XmlUtilEx.cs | 20 +++++------- README.md | 31 ++++++++++++++++++- 6 files changed, 47 insertions(+), 18 deletions(-) diff --git a/ModernKeePassLib.Test/ModernKeePassLib.Test.csproj b/ModernKeePassLib.Test/ModernKeePassLib.Test.csproj index 2e97581..3e1be33 100644 --- a/ModernKeePassLib.Test/ModernKeePassLib.Test.csproj +++ b/ModernKeePassLib.Test/ModernKeePassLib.Test.csproj @@ -17,8 +17,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - diff --git a/ModernKeePassLib.sln b/ModernKeePassLib.sln index 6eb5f35..fb481d5 100644 --- a/ModernKeePassLib.sln +++ b/ModernKeePassLib.sln @@ -7,6 +7,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModernKeePassLib.Test", "Mo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModernKeePassLib", "ModernKeePassLib\ModernKeePassLib.csproj", "{85C3EA08-C9C4-4A8E-AB52-BE8A6475B787}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2390E567-E65A-43C1-9D07-6680296D1BE0}" + ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore + README.md = README.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/ModernKeePassLib/ModernKeePassLib.csproj b/ModernKeePassLib/ModernKeePassLib.csproj index 085b22d..d97a961 100644 --- a/ModernKeePassLib/ModernKeePassLib.csproj +++ b/ModernKeePassLib/ModernKeePassLib.csproj @@ -3,7 +3,7 @@ netstandard1.2 Portable KeePass Password Management Library that targets .Net Standard and WinRT. Allows reading, editing and writing to KeePass 2.x databases. - 2.44.2 + 2.44.3 Geoffroy Bonneville wismna https://github.com/wismna/ModernKeePass @@ -55,7 +55,7 @@ - + diff --git a/ModernKeePassLib/Serialization/KdbxFile.Write.cs b/ModernKeePassLib/Serialization/KdbxFile.Write.cs index 095d198..b2e407c 100644 --- a/ModernKeePassLib/Serialization/KdbxFile.Write.cs +++ b/ModernKeePassLib/Serialization/KdbxFile.Write.cs @@ -204,7 +204,7 @@ namespace ModernKeePassLib.Serialization throw new ArgumentOutOfRangeException("fmt"); } - m_xmlWriter = XmlUtilEx.CreateXmlWriter(sXml, m_uFileVersion >= FileVersion32_4); + m_xmlWriter = XmlUtilEx.CreateXmlWriter(sXml); WriteDocument(pgRoot); diff --git a/ModernKeePassLib/Utility/XmlUtilEx.cs b/ModernKeePassLib/Utility/XmlUtilEx.cs index 88689e6..7b8f869 100644 --- a/ModernKeePassLib/Utility/XmlUtilEx.cs +++ b/ModernKeePassLib/Utility/XmlUtilEx.cs @@ -34,11 +34,11 @@ namespace ModernKeePassLib.Utility { XmlDocument d = new XmlDocument(); - // .NET 4.5.2 and newer do not resolve external XML resources - // by default; for older .NET versions, we explicitly - // prevent resolving + // .NET 4.5.2 and newer do not resolve external XML resources + // by default; for older .NET versions, we explicitly + // prevent resolving #if !ModernKeePassLib - d.XmlResolver = null; // Default in old .NET: XmlUrlResolver object + d.XmlResolver = null; // Default in old .NET: XmlUrlResolver object #endif return d; @@ -74,28 +74,24 @@ namespace ModernKeePassLib.Utility return XmlReader.Create(s, CreateXmlReaderSettings()); } - public static XmlWriterSettings CreateXmlWriterSettings(bool isVersionGreaterThan4 = false) + public static XmlWriterSettings CreateXmlWriterSettings() { XmlWriterSettings xws = new XmlWriterSettings(); - xws.CloseOutput = isVersionGreaterThan4; + xws.CloseOutput = false; xws.Encoding = StrUtil.Utf8; xws.Indent = true; xws.IndentChars = "\t"; xws.NewLineOnAttributes = false; -#if ModernKeePassLib - // This is needed for Argon2Kdf write - xws.Async = true; -#endif return xws; } - public static XmlWriter CreateXmlWriter(Stream s, bool isVersionGreaterThan4 = false) + public static XmlWriter CreateXmlWriter(Stream s) { if(s == null) { Debug.Assert(false); throw new ArgumentNullException("s"); } - return XmlWriter.Create(s, CreateXmlWriterSettings(isVersionGreaterThan4)); + return XmlWriter.Create(s, CreateXmlWriterSettings()); } public static void Serialize(Stream s, T t) diff --git a/README.md b/README.md index d79ccb1..acabc2b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,32 @@ ## ModernKeePassLib -[![Build status](https://dev.azure.com/geogeob/ModernKeePass/_apis/build/status/Builds/ModernKeePassLib)](https://dev.azure.com/geogeob/ModernKeePass/_build/latest?definitionId=6) \ No newline at end of file +[![Build status](https://dev.azure.com/geogeob/ModernKeePass/_apis/build/status/Builds/ModernKeePassLib)](https://dev.azure.com/geogeob/ModernKeePass/_build/latest?definitionId=6) + +# What is this ? + +ModernKeePassLib is a port of KeePassLib to .netstandard 1.2, distributed as a nuget package. +The aim was to change as little as possible the original library. However, some workarounds have to be made as .netstandard misses quite a few features of the full .net framework. +Main changes: +- Removed the dependency on the filesystem +- Added a dependency on Windows (I'm working on tring to find a way to remove it altogether) +- Some features are handled by external nuget packages (cryptography, colors, etc.), so it may introduce small differences + +# Usage + +1. Create a IOConnectionInfo from a byte array: +`var ioConnection = IOConnectionInfo.FromByteArray(file);` +2. Create a composite key and add credential information: +`var compositeKey = new CompositeKey(); +// Password +compositeKey.AddUserKey(new KcpPassword("Password"));` +// Key file +compositeKey.AddUserKey(new KcpKeyFile(IOConnectionInfo.FromByteArray(KeyFileContents)));` +3. Use it to open the database: +// You may use whatever logger you choose (here, I use nullstatuslogger) +`PwDatabase.Open(ioConnection, compositeKey, new NullStatusLogger());` +4. Do stuff in you database (create entries, groups, ...) +5. Save your changes: +`PwDatabase.Save(new NullStatusLogger());` +6. At this point, nothing is commited to disk, so you need to retrieve the byte array: +`var contents = PwDatabase.IOConnectionInfo.Bytes;` +7. Write the byte array to a file, to a stream, whatever ! \ No newline at end of file