diff options
Diffstat (limited to 'BuildTools')
-rw-r--r-- | BuildTools/AutoUpdateBuilder/Program.cs | 89 |
1 files changed, 51 insertions, 38 deletions
diff --git a/BuildTools/AutoUpdateBuilder/Program.cs b/BuildTools/AutoUpdateBuilder/Program.cs index de961dea8..4a7fdeba7 100644 --- a/BuildTools/AutoUpdateBuilder/Program.cs +++ b/BuildTools/AutoUpdateBuilder/Program.cs @@ -8,6 +8,9 @@ namespace AutoUpdateBuilder { private static RSACryptoServiceProvider privkey; + private static string keyfile; + private static string keyfilepassword; + private static void CompareToManifestPublicKey() { if (Duplicati.Library.AutoUpdater.AutoUpdateSettings.SignKey == null || privkey.ToXmlString(false) != Duplicati.Library.AutoUpdater.AutoUpdateSettings.SignKey.ToXmlString(false)) @@ -19,6 +22,21 @@ namespace AutoUpdateBuilder } } + private static void LoadKeyFromFile() + { + using (var enc = new Duplicati.Library.Encryption.AESEncryption(keyfilepassword, new Dictionary<string, string>())) + using (var ms = new System.IO.MemoryStream()) + using (var fs = System.IO.File.OpenRead(keyfile)) + { + enc.Decrypt(fs, ms); + ms.Position = 0; + + using (var sr = new System.IO.StreamReader(ms)) + privkey.FromXmlString(sr.ReadToEnd()); + } + } + + public static int Main(string[] _args) { var args = new List<string>(_args); @@ -26,10 +44,8 @@ namespace AutoUpdateBuilder string inputfolder; string outputfolder; - string keyfile; string manifestfile; - string keyfilepassword; - string gpgkeyfile; + string gpgkeyfile; string gpgpath; string allowNewKey; @@ -42,7 +58,7 @@ namespace AutoUpdateBuilder opts.TryGetValue("gpgkeyfile", out gpgkeyfile); opts.TryGetValue("gpgpath", out gpgpath); - var usedoptions = new string[] { "allow-new-key", "input", "output", "keyfile", "manifest", "keyfile-password", "gpgkeyfile", "gpgpath" }; + var usedoptions = new [] { "allow-new-key", "input", "output", "keyfile", "manifest", "keyfile-password", "gpgkeyfile", "gpgpath" }; if (string.IsNullOrWhiteSpace(inputfolder)) { @@ -89,16 +105,7 @@ namespace AutoUpdateBuilder privkey = (RSACryptoServiceProvider) RSA.Create(); - using(var enc = new Duplicati.Library.Encryption.AESEncryption(keyfilepassword, new Dictionary<string, string>())) - using(var ms = new System.IO.MemoryStream()) - using(var fs = System.IO.File.OpenRead(keyfile)) - { - enc.Decrypt(fs, ms); - ms.Position = 0; - - using(var sr = new System.IO.StreamReader(ms)) - privkey.FromXmlString(sr.ReadToEnd()); - } + LoadKeyFromFile(); if (!Boolean.TryParse(allowNewKey, out Boolean newKeyAllowed) || !newKeyAllowed) { @@ -144,38 +151,44 @@ namespace AutoUpdateBuilder using (var jr = new Newtonsoft.Json.JsonTextReader(sr)) updateInfo = new Newtonsoft.Json.JsonSerializer().Deserialize<Duplicati.Library.AutoUpdater.UpdateInfo>(jr); - var isopts = new Dictionary<string, string>(opts, StringComparer.InvariantCultureIgnoreCase); foreach (var usedopt in usedoptions) + { isopts.Remove(usedopt); + } foreach (var k in updateInfo.GetType().GetFields()) - if (isopts.ContainsKey(k.Name)) + { + if (!isopts.ContainsKey(k.Name)) + { + continue; + } + try + { + //Console.WriteLine("Setting {0} to {1}", k.Name, isopts[k.Name]); + if (k.FieldType == typeof(string[])) + k.SetValue(updateInfo, isopts[k.Name].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); + else if (k.FieldType == typeof(Version)) + k.SetValue(updateInfo, new Version(isopts[k.Name])); + else if (k.FieldType == typeof(int)) + k.SetValue(updateInfo, int.Parse(isopts[k.Name])); + else if (k.FieldType == typeof(long)) + k.SetValue(updateInfo, long.Parse(isopts[k.Name])); + else + k.SetValue(updateInfo, isopts[k.Name]); + } + catch (Exception ex) { - try - { - //Console.WriteLine("Setting {0} to {1}", k.Name, isopts[k.Name]); - if (k.FieldType == typeof(string[])) - k.SetValue(updateInfo, isopts[k.Name].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); - else if (k.FieldType == typeof(Version)) - k.SetValue(updateInfo, new Version(isopts[k.Name])); - else if (k.FieldType == typeof(int)) - k.SetValue(updateInfo, int.Parse(isopts[k.Name])); - else if (k.FieldType == typeof(long)) - k.SetValue(updateInfo, long.Parse(isopts[k.Name])); - else - k.SetValue(updateInfo, isopts[k.Name]); - } - catch (Exception ex) - { - Console.WriteLine("Failed setting {0} to {1}: {2}", k.Name, isopts[k.Name], ex.Message); - } - - isopts.Remove(k.Name); + Console.WriteLine("Failed setting {0} to {1}: {2}", k.Name, isopts[k.Name], ex.Message); } - foreach(var opt in isopts) - Console.WriteLine("Warning! unused option: {0} = {1}", opt.Key, opt.Value); + isopts.Remove(k.Name); + } + + foreach (var opt in isopts) + { + Console.WriteLine("Warning! unused option: {0} = {1}", opt.Key, opt.Value); + } using (var tf = new Duplicati.Library.Utility.TempFile()) { |