Merge pull request #3830 from BlueBlock/gpg-update

Update GPG library and path method
This commit is contained in:
Kenneth Skovhede
2019-09-17 09:53:46 +02:00
committed by GitHub
29 changed files with 223 additions and 106 deletions
+10 -5
View File
@@ -21,6 +21,7 @@ namespace GnupgSigningTool
{
var armorOption = useArmor ? "--armor" : "";
var gpgArgument = string.Format("--pinentry-mode loopback --passphrase-fd 0 --batch --yes {0} -u \"{1}\" --output \"{2}\" --detach-sig \"{3}\"",
armorOption,
gpgkeyid,
@@ -36,6 +37,7 @@ namespace GnupgSigningTool
});
proc.StandardInput.WriteLine(gpgkeypassphrase);
proc.WaitForExit();
}
@@ -45,18 +47,20 @@ namespace GnupgSigningTool
using (var ms = new System.IO.MemoryStream())
using (var fs = System.IO.File.OpenRead(gpgkeyfile))
{
try
{
enc.Decrypt(fs, ms);
} catch (System.Security.Cryptography.CryptographicException e) {
}
catch (System.Security.Cryptography.CryptographicException e)
{
throw new ArgumentException("Failed to decrypt gpg secret credentials file: {0}\n", e.Message);
}
ms.Position = 0;
using (var sr = new System.IO.StreamReader(ms))
{
var lines = sr.ReadToEnd().Split(new [] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
var lines = sr.ReadToEnd().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
gpgkeyid = lines[0];
gpgkeypassphrase = lines[1];
}
@@ -64,7 +68,7 @@ namespace GnupgSigningTool
}
public static void Main(string [] _args)
public static void Main(string[] _args)
{
var args = new List<string>(_args);
var opts = Duplicati.Library.Utility.CommandLineParser.ExtractOptions(args);
@@ -95,7 +99,8 @@ namespace GnupgSigningTool
throw new ArgumentException("Could not fetch gpg key id or gpg passphrase.");
}
gpgpath = gpgpath ?? "gpg";
gpgpath = gpgpath ?? Duplicati.Library.Encryption.GPGEncryption.GetGpgExePath();
SpawnGPG();
}
}
+51 -63
View File
@@ -22,8 +22,8 @@ using System.Collections.Generic;
using System.Linq;
using Duplicati.Library.Localization.Short;
using System.IO;
using Duplicati.Library.Common;
using Duplicati.Library.Logging;
namespace Duplicati.CommandLine
{
public class Program
@@ -48,20 +48,6 @@ namespace Duplicati.CommandLine
FROM_COMMANDLINE = true;
try
{
//If we are on Windows, append the bundled "win-tools" programs to the search path
//We add it last, to allow the user to override with other versions
if (Platform.IsClientWindows)
{
string wintools = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "win-tools");
Environment.SetEnvironmentVariable("PATH",
Environment.GetEnvironmentVariable("PATH") +
System.IO.Path.PathSeparator.ToString() +
wintools +
System.IO.Path.PathSeparator.ToString() +
System.IO.Path.Combine(wintools, "gpg") //GPG needs to be in a subfolder for wrapping reasons
);
}
return RunCommandLine(Console.Out, Console.Error, c => { }, args);
}
finally
@@ -74,51 +60,51 @@ namespace Duplicati.CommandLine
{
get
{
var knownCommands = new Dictionary<string, Func<TextWriter, Action<Library.Main.Controller>, List<string>, Dictionary<string, string>, Library.Utility.IFilter, int>>(StringComparer.OrdinalIgnoreCase);
knownCommands["help"] = Commands.Help;
knownCommands["example"] = Commands.Examples;
knownCommands["examples"] = Commands.Examples;
knownCommands["find"] = Commands.List;
knownCommands["list"] = Commands.List;
knownCommands["delete"] = Commands.Delete;
knownCommands["backup"] = Commands.Backup;
knownCommands["restore"] = Commands.Restore;
knownCommands["repair"] = Commands.Repair;
knownCommands["purge"] = Commands.PurgeFiles;
knownCommands["list-broken-files"] = Commands.ListBrokenFiles;
knownCommands["purge-broken-files"] = Commands.PurgeBrokenFiles;
knownCommands["compact"] = Commands.Compact;
knownCommands["create-report"] = Commands.CreateBugReport;
knownCommands["compare"] = Commands.ListChanges;
knownCommands["test"] = Commands.Test;
knownCommands["verify"] = Commands.Test;
knownCommands["test-filters"] = Commands.TestFilters;
knownCommands["test-filter"] = Commands.TestFilters;
knownCommands["affected"] = Commands.Affected;
knownCommands["vacuum"] = Commands.Vacuum;
knownCommands["system-info"] = Commands.SystemInfo;
knownCommands["systeminfo"] = Commands.SystemInfo;
knownCommands["send-mail"] = Commands.SendMail;
var knownCommands =
new Dictionary<string, Func<TextWriter, Action<Library.Main.Controller>, List<string>,
Dictionary<string, string>, Library.Utility.IFilter, int>>(StringComparer.OrdinalIgnoreCase)
{
["help"] = Commands.Help,
["example"] = Commands.Examples,
["examples"] = Commands.Examples,
["find"] = Commands.List,
["list"] = Commands.List,
["delete"] = Commands.Delete,
["backup"] = Commands.Backup,
["restore"] = Commands.Restore,
["repair"] = Commands.Repair,
["purge"] = Commands.PurgeFiles,
["list-broken-files"] = Commands.ListBrokenFiles,
["purge-broken-files"] = Commands.PurgeBrokenFiles,
["compact"] = Commands.Compact,
["create-report"] = Commands.CreateBugReport,
["compare"] = Commands.ListChanges,
["test"] = Commands.Test,
["verify"] = Commands.Test,
["test-filters"] = Commands.TestFilters,
["test-filter"] = Commands.TestFilters,
["affected"] = Commands.Affected,
["vacuum"] = Commands.Vacuum,
["system-info"] = Commands.SystemInfo,
["systeminfo"] = Commands.SystemInfo,
["send-mail"] = Commands.SendMail
};
return knownCommands;
}
}
public static IEnumerable<string> SupportedCommands { get { return CommandMap.Keys; } }
private static int ShowChangeLog(TextWriter outwriter) {
private static int ShowChangeLog(TextWriter outwriter)
{
var path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "changelog.txt");
outwriter.WriteLine(System.IO.File.ReadAllText(path));
return 0;
}
private static void CheckForUpdates(TextWriter outwriter){
private static void CheckForUpdates(TextWriter outwriter)
{
var update = Library.AutoUpdater.UpdaterManager.LastUpdateCheckVersion;
if (update == null)
update = Library.AutoUpdater.UpdaterManager.CheckForUpdate();
@@ -140,7 +126,8 @@ namespace Duplicati.CommandLine
}
}
private static int ParseCommandLine(TextWriter outwriter, Action<Library.Main.Controller> setup, ref bool verboseErrors, string[] args) {
private static int ParseCommandLine(TextWriter outwriter, Action<Library.Main.Controller> setup, ref bool verboseErrors, string[] args)
{
List<string> cargs = new List<string>(args);
var tmpparsed = Library.Utility.FilterCollector.ExtractOptions(cargs);
@@ -168,7 +155,7 @@ namespace Duplicati.CommandLine
}
// try and parse all parameter file aliases
foreach (string parameterOption in new []{ "parameters-file", "parameters-file", "parameterfile"} )
foreach (string parameterOption in new[] { "parameters-file", "parameters-file", "parameterfile" })
{
if (options.ContainsKey(parameterOption) && !string.IsNullOrEmpty(options[parameterOption]))
{
@@ -305,7 +292,8 @@ namespace Duplicati.CommandLine
string appendfilter = null;
string replacefilter = null;
var tmpparsed = Library.Utility.FilterCollector.ExtractOptions(fargs, (key, value) => {
var tmpparsed = Library.Utility.FilterCollector.ExtractOptions(fargs, (key, value) =>
{
if (key.Equals("source", StringComparison.OrdinalIgnoreCase))
{
newsource.Add(value);
@@ -347,27 +335,27 @@ namespace Duplicati.CommandLine
filter = newfilter;
if (!string.IsNullOrWhiteSpace(prependfilter))
filter = Library.Utility.FilterExpression.Combine(Library.Utility.FilterExpression.Deserialize(prependfilter.Split(new string[] {System.IO.Path.PathSeparator.ToString()}, StringSplitOptions.RemoveEmptyEntries)), filter);
filter = Library.Utility.FilterExpression.Combine(Library.Utility.FilterExpression.Deserialize(prependfilter.Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries)), filter);
if (!string.IsNullOrWhiteSpace(appendfilter))
filter = Library.Utility.FilterExpression.Combine(filter, Library.Utility.FilterExpression.Deserialize(appendfilter.Split(new string[] {System.IO.Path.PathSeparator.ToString()}, StringSplitOptions.RemoveEmptyEntries)));
filter = Library.Utility.FilterExpression.Combine(filter, Library.Utility.FilterExpression.Deserialize(appendfilter.Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries)));
if (!string.IsNullOrWhiteSpace(replacefilter))
filter = Library.Utility.FilterExpression.Deserialize(replacefilter.Split(new string[] {System.IO.Path.PathSeparator.ToString()}, StringSplitOptions.RemoveEmptyEntries));
filter = Library.Utility.FilterExpression.Deserialize(replacefilter.Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries));
foreach (KeyValuePair<String, String> keyvalue in opt)
options[keyvalue.Key] = keyvalue.Value;
if (!string.IsNullOrEmpty(newtarget))
{
if (cargs.Count <= 1)
cargs.Add(newtarget);
else
cargs[1] = newtarget;
}
{
if (cargs.Count <= 1)
cargs.Add(newtarget);
else
cargs[1] = newtarget;
}
if (cargs.Count >= 1 && cargs[0].Equals("backup", StringComparison.OrdinalIgnoreCase))
cargs.AddRange(newsource);
cargs.AddRange(newsource);
else if (newsource.Count > 0)
Library.Logging.Log.WriteVerboseMessage(LOGTAG, "NotUsingBackupSources", Strings.Program.SkippingSourceArgumentsOnNonBackupOperation);
@@ -53,6 +53,10 @@
<Compile Include="Strings.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Duplicati.Library.Common.csproj">
<Project>{d63e53e4-a458-4c2f-914d-92f715f58acf}</Project>
<Name>Duplicati.Library.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Interface\Duplicati.Library.Interface.csproj">
<Project>{c5899f45-b0ff-483c-9d38-24a9fcaab237}</Project>
<Name>Duplicati.Library.Interface</Name>
+15 -2
View File
@@ -21,6 +21,9 @@ using System;
using System.Collections.Generic;
using System.IO;
using Duplicati.Library.Interface;
using Duplicati.Library.Common;
using Duplicati.Library.Logging;
using Duplicati.Library.Utility;
namespace Duplicati.Library.Encryption
{
@@ -95,8 +98,8 @@ namespace Duplicati.Library.Encryption
/// <summary>
/// The PGP program to use, should be with absolute path
/// </summary>
private readonly string m_programpath = "gpg";
private string m_programpath { get; set; } = GetGpgProgramPath();
/// <summary>
/// Commandline switches for encryption
/// </summary>
@@ -272,5 +275,15 @@ namespace Duplicati.Library.Encryption
Utility.Utility.CopyStream((Stream)tmp[0], (Stream)tmp[1]);
((Stream)tmp[1]).Close();
}
/// <summary>
/// Determines the path to the GPG program
/// </summary>
public static string GetGpgProgramPath()
{
Log.WriteInformationMessage("GetGpgProgramPath", "gpg", Platform.IsClientWindows ? WinTools.GetWindowsGpgExePath() : "gpg");
// for Windows return the full path, otherwise just return "gpg"
return Platform.IsClientWindows ? WinTools.GetWindowsGpgExePath() : "gpg";
}
}
}
@@ -50,12 +50,14 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AsyncHttpRequest.cs" />
<Compile Include="WinTools.cs" />
<Compile Include="FilterGroups.cs" />
<Compile Include="KeyGenerator.cs" />
<Compile Include="MD5HashHelper.cs" />
<Compile Include="OverrideableStream.cs" />
<Compile Include="ProgressReportingStream.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RegistryUtility.cs" />
<Compile Include="ReadLimitLengthStream.cs" />
<Compile Include="ShaderStream.cs" />
<Compile Include="Sizeparser.cs" />
@@ -104,6 +106,10 @@
</Target>
-->
<ItemGroup>
<ProjectReference Include="..\Common\Duplicati.Library.Common.csproj">
<Project>{d63e53e4-a458-4c2f-914d-92f715f58acf}</Project>
<Name>Duplicati.Library.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Localization\Duplicati.Library.Localization.csproj">
<Project>{B68F2214-951F-4F78-8488-66E1ED3F50BF}</Project>
<Name>Duplicati.Library.Localization</Name>
@@ -112,10 +118,6 @@
<Project>{C5899F45-B0FF-483C-9D38-24A9FCAAB237}</Project>
<Name>Duplicati.Library.Interface</Name>
</ProjectReference>
<ProjectReference Include="..\Common\Duplicati.Library.Common.csproj">
<Project>{D63E53E4-A458-4C2F-914D-92F715F58ACF}</Project>
<Name>Duplicati.Library.Common</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
</Project>
@@ -0,0 +1,50 @@
#region Disclaimer / License
// Copyright (C) 2019, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
using Microsoft.Win32;
namespace Duplicati.Library.Utility
{
public static class RegistryUtility
{
public static string GetDataByValueName(string parentKeyName, string name)
{
try
{
// check currentUser first, if null, then check LocalMachine
// if a registry item does not exist a null is returned
var cuParentKey = Registry.CurrentUser.OpenSubKey(parentKeyName, RegistryKeyPermissionCheck.ReadSubTree);
if (cuParentKey?.GetValue(name) != null)
{
return cuParentKey.GetValue(name).ToString();
}
var lmParentKey = Registry.LocalMachine.OpenSubKey(parentKeyName, RegistryKeyPermissionCheck.ReadSubTree);
return lmParentKey.GetValue(name).ToString();
}
catch
{
// NOOP
}
return null;
}
}
}
+57
View File
@@ -0,0 +1,57 @@
#region Disclaimer / License
// Copyright (C) 2019, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
using Duplicati.Library.Common;
namespace Duplicati.Library.Utility
{
public static class WinTools
{
public static string GetWindowsGpgExePath()
{
if (!Platform.IsClientWindows)
{
return null;
}
try
{
// return gpg4win if it exists
var location32 = Library.Utility.RegistryUtility.GetDataByValueName(@"SOFTWARE\WOW6432Node\GnuPG", "Install Directory");
var location64 = Library.Utility.RegistryUtility.GetDataByValueName(@"SOFTWARE\GnuPG", "Install Directory");
var gpg4winLocation = string.IsNullOrEmpty(location64) ? location32 : location64;
if (!string.IsNullOrEmpty(gpg4winLocation))
{
return System.IO.Path.Combine(gpg4winLocation, "bin", "gpg.exe");
}
}
catch
{
// NOOP
}
// otherwise return our included win-tools
var wintoolsPath = System.IO.Path.Combine(
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
"win-tools", "gpg.exe");
return string.IsNullOrEmpty(wintoolsPath) ? null : wintoolsPath;
}
}
}
+30 -32
View File
@@ -44,41 +44,36 @@
<Content Include="utility-scripts\README.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="win-tools\gpg.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="win-tools\gpgconf.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="win-tools\libassuan-0.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="win-tools\libgcrypt-20.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="win-tools\libgpg-error-0.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="win-tools\libgpgme-11.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="win-tools\libksba-8.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="win-tools\libnpth-0.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="win-tools\libsqlite3-0.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="win-tools\README.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\thirdparty\gpg\gpg.exe">
<Link>win-tools\gpg.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\thirdparty\gpg\gpgconf.exe">
<Link>win-tools\gpgconf.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\thirdparty\gpg\libadns-1.dll">
<Link>win-tools\libadns-1.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\thirdparty\gpg\libassuan-0.dll">
<Link>win-tools\libassuan-0.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\thirdparty\gpg\libgcrypt-20.dll">
<Link>win-tools\libgcrypt-20.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\thirdparty\gpg\libgpg-error-0.dll">
<Link>win-tools\libgpg-error-0.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\thirdparty\gpg\libiconv-2.dll">
<Link>win-tools\libiconv-2.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\thirdparty\gpg\zlib1.dll">
<Link>win-tools\zlib1.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\thirdparty\mozroots\mozroots.exe">
<Link>utility-scripts\mozroots.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -87,6 +82,9 @@
<Link>utility-scripts\TlsTest.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="win-tools\zlib1.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.