diff options
author | verhoek <30193551+verhoek@users.noreply.github.com> | 2018-12-23 22:32:21 +0300 |
---|---|---|
committer | verhoek <30193551+verhoek@users.noreply.github.com> | 2018-12-23 22:32:21 +0300 |
commit | ae5d6ffcc7f98ea4cd92320ad71c19c405b63828 (patch) | |
tree | 0dc59ba13e882c607e7114038e8c46f5681d8ae8 | |
parent | 94cf55a231f7e72e528bd2e2e97af808d125071c (diff) |
Added option to generate new priv/pub key pair without verifying the manifest.
-rw-r--r-- | BuildTools/AutoUpdateBuilder/Program.cs | 32 | ||||
-rw-r--r-- | Duplicati/Library/AutoUpdater/AutoUpdateSettings.cs | 9 |
2 files changed, 26 insertions, 15 deletions
diff --git a/BuildTools/AutoUpdateBuilder/Program.cs b/BuildTools/AutoUpdateBuilder/Program.cs index d2df70e61..de961dea8 100644 --- a/BuildTools/AutoUpdateBuilder/Program.cs +++ b/BuildTools/AutoUpdateBuilder/Program.cs @@ -1,10 +1,24 @@ using System; using System.Collections.Generic; +using System.Security.Cryptography; namespace AutoUpdateBuilder { public class Program { + private static RSACryptoServiceProvider privkey; + + private static void CompareToManifestPublicKey() + { + if (Duplicati.Library.AutoUpdater.AutoUpdateSettings.SignKey == null || privkey.ToXmlString(false) != Duplicati.Library.AutoUpdater.AutoUpdateSettings.SignKey.ToXmlString(false)) + { + Console.WriteLine("The public key in the project is not the same as the public key from the file"); + Console.WriteLine("Try setting the key to: "); + Console.WriteLine(privkey.ToXmlString(false)); + System.Environment.Exit(5); + } + } + public static int Main(string[] _args) { var args = new List<string>(_args); @@ -17,16 +31,18 @@ namespace AutoUpdateBuilder string keyfilepassword; string gpgkeyfile; string gpgpath; + string allowNewKey; opts.TryGetValue("input", out inputfolder); opts.TryGetValue("output", out outputfolder); + opts.TryGetValue("allow-new-key", out allowNewKey); opts.TryGetValue("keyfile", out keyfile); opts.TryGetValue("manifest", out manifestfile); opts.TryGetValue("keyfile-password", out keyfilepassword); opts.TryGetValue("gpgkeyfile", out gpgkeyfile); opts.TryGetValue("gpgpath", out gpgpath); - var usedoptions = new string[] { "input", "output", "keyfile", "manifest", "keyfile-password", "gpgkeyfile", "gpgpath" }; + var usedoptions = new string[] { "allow-new-key", "input", "output", "keyfile", "manifest", "keyfile-password", "gpgkeyfile", "gpgpath" }; if (string.IsNullOrWhiteSpace(inputfolder)) { @@ -61,7 +77,7 @@ namespace AutoUpdateBuilder if (!System.IO.File.Exists(keyfile)) { Console.WriteLine("Keyfile not found, creating new"); - var newkey = System.Security.Cryptography.RSACryptoServiceProvider.Create().ToXmlString(true); + var newkey = RSA.Create().ToXmlString(true); using (var enc = new Duplicati.Library.Encryption.AESEncryption(keyfilepassword, new Dictionary<string, string>())) using (var fs = System.IO.File.OpenWrite(keyfile)) using (var ms = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(newkey))) @@ -71,7 +87,7 @@ namespace AutoUpdateBuilder if (!System.IO.Directory.Exists(outputfolder)) System.IO.Directory.CreateDirectory(outputfolder); - var privkey = (System.Security.Cryptography.RSACryptoServiceProvider)System.Security.Cryptography.RSACryptoServiceProvider.Create(); + privkey = (RSACryptoServiceProvider) RSA.Create(); using(var enc = new Duplicati.Library.Encryption.AESEncryption(keyfilepassword, new Dictionary<string, string>())) using(var ms = new System.IO.MemoryStream()) @@ -84,16 +100,12 @@ namespace AutoUpdateBuilder privkey.FromXmlString(sr.ReadToEnd()); } - if (Duplicati.Library.AutoUpdater.AutoUpdateSettings.SignKey == null || privkey.ToXmlString(false) != Duplicati.Library.AutoUpdater.AutoUpdateSettings.SignKey.ToXmlString(false)) + if (!Boolean.TryParse(allowNewKey, out Boolean newKeyAllowed) || !newKeyAllowed) { - Console.WriteLine("The public key in the project is not the same as the public key from the file"); - Console.WriteLine("Try setting the key to: "); - Console.WriteLine(privkey.ToXmlString(false)); - return 5; + CompareToManifestPublicKey(); } - - string gpgkeyid = null; + string gpgkeyid = null; string gpgkeypassphrase = null; if (string.IsNullOrWhiteSpace(gpgkeyfile)) diff --git a/Duplicati/Library/AutoUpdater/AutoUpdateSettings.cs b/Duplicati/Library/AutoUpdater/AutoUpdateSettings.cs index aa5209756..7c4ec1289 100644 --- a/Duplicati/Library/AutoUpdater/AutoUpdateSettings.cs +++ b/Duplicati/Library/AutoUpdater/AutoUpdateSettings.cs @@ -66,11 +66,10 @@ namespace Duplicati.Library.AutoUpdater private static string ReadResourceText(string name, string oemname)
{
- string result;
- if (_cache.TryGetValue(name, out result))
+ // First try to read from _cache
+ if (_cache.TryGetValue(name, out string result))
return result;
-
try
{
using (var rd = new System.IO.StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(typeof(AutoUpdateSettings), name)))
@@ -180,11 +179,11 @@ namespace Duplicati.Library.AutoUpdater public static System.Security.Cryptography.RSACryptoServiceProvider SignKey
{
- get
+ get
{
try
{
- var key = System.Security.Cryptography.RSACryptoServiceProvider.Create();
+ var key = System.Security.Cryptography.RSA.Create();
key.FromXmlString(ReadResourceText(UPDATE_KEY, OEM_UPDATE_KEY));
return (System.Security.Cryptography.RSACryptoServiceProvider)key;
}
|