From 011c7fda756a6a7b0df87dd9e0ad5b8129d3094f Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 4 Jan 2016 18:53:06 +0100 Subject: [PATCH] Ninja update --- .../templates/control-backend-sprint.template | 2 +- .../templates/control-common-sprint.template | 2 +- .../Payload/NotificationPayload.cs | 2 + Logic/Financial/BitcoinUtility.cs | 28 ++++++++++++-- ...ansmission.NotificationPayload.Designer.cs | 38 +++++++++++++++++++ ...ions.Transmission.NotificationPayload.resx | 14 +++++++ .../Communications/CommsTransmitterMail.cs | 9 +++++ 7 files changed, 90 insertions(+), 5 deletions(-) diff --git a/BuildFiles/Packaging/templates/control-backend-sprint.template b/BuildFiles/Packaging/templates/control-backend-sprint.template index 91d27c33..aea5ed10 100644 --- a/BuildFiles/Packaging/templates/control-backend-sprint.template +++ b/BuildFiles/Packaging/templates/control-backend-sprint.template @@ -2,7 +2,7 @@ Package: swarmops-backend Version: --BuildNumber-- Architecture: all Maintainer: Rick Falkvinge (swarmops-maintain@falkvinge.net) -Depends: swarmops-common (>= --BuildNumber--),mono-runtime (>= 3.2.8),libmono-corlib4.0-cil (>= 3.2.8),libmono-posix4.0-cil (>= 3.2.8),libmono-system-data4.0-cil (>= 3.2.8),libmono-system-web-http4.0-cil (>= 3.2.8) +Depends: swarmops-common (>= --BuildNumber--),mono-runtime (>= 3.2.8),libmono-corlib4.0-cil (>= 3.2.8),libmono-posix4.0-cil (>= 3.2.8),libmono-system-data4.0-cil (>= 3.2.8),libmono-system-web-http4.0-cil (>= 3.2.8),libmono-system-numerics4.0-cil Conflicts: swarmops-backend-internal,swarmops-backend-stable Homepage: http://swarmops.com/ Description: Swarmops Backend diff --git a/BuildFiles/Packaging/templates/control-common-sprint.template b/BuildFiles/Packaging/templates/control-common-sprint.template index cc912b7b..58fc1968 100644 --- a/BuildFiles/Packaging/templates/control-common-sprint.template +++ b/BuildFiles/Packaging/templates/control-common-sprint.template @@ -2,7 +2,7 @@ Package: swarmops-common Version: --BuildNumber-- Architecture: all Maintainer: Rick Falkvinge (swarmops-maintain@falkvinge.net) -Depends: libmono-system-componentmodel-composition4.0-cil (>= 3.2.8),libmono-system-web-services4.0-cil (>= 3.2.8),libmono-system-web-extensions4.0-cil (>= 3.2.8),libmono-system-componentmodel-composition4.0-cil (>= 3.2.8),fonts-liberation +Depends: libmono-system-componentmodel-composition4.0-cil (>= 3.2.8),libmono-system-web-services4.0-cil (>= 3.2.8),libmono-system-web-extensions4.0-cil (>= 3.2.8),libmono-system-componentmodel-composition4.0-cil (>= 3.2.8),fonts-liberation,libmono-system-numerics4.0-cil Conflicts: swarmops-common-internal,swarmops-common-stable Homepage: http://swarmops.com/ Description: Swarmops Common diff --git a/Logic/Communications/Payload/NotificationPayload.cs b/Logic/Communications/Payload/NotificationPayload.cs index 9c6816a0..4ed163ae 100644 --- a/Logic/Communications/Payload/NotificationPayload.cs +++ b/Logic/Communications/Payload/NotificationPayload.cs @@ -144,6 +144,8 @@ namespace Swarmops.Logic.Communications.Payload System_DatabaseSchemaUpgraded, System_DatabaseUpgradeFailed, System_MailServerTest, + System_PublicRootReset, + System_UnrecognizedPayload, CashAdvance_Requested, CashAdvance_Attested, CashAdvance_Deattested, diff --git a/Logic/Financial/BitcoinUtility.cs b/Logic/Financial/BitcoinUtility.cs index 55bf0399..b397981e 100644 --- a/Logic/Financial/BitcoinUtility.cs +++ b/Logic/Financial/BitcoinUtility.cs @@ -13,6 +13,8 @@ using NBitcoin; using NBitcoin.BouncyCastle.Asn1.Ocsp; using Newtonsoft.Json.Linq; using Swarmops.Database; +using Swarmops.Logic.Communications; +using Swarmops.Logic.Communications.Payload; using Swarmops.Logic.Structure; using Swarmops.Logic.Support; @@ -36,7 +38,11 @@ namespace Swarmops.Logic.Financial ExtKey privateRoot = new ExtKey(); File.WriteAllText(SystemSettings.EtcFolder + Path.DirectorySeparatorChar + "hotwallet", privateRoot.GetWif(Network.Main).ToWif(), Encoding.ASCII); File.WriteAllText(SystemSettings.EtcFolder + Path.DirectorySeparatorChar + "hotwallet-created-" + DateTime.UtcNow.ToString("yyyy-MM-dd--HH-mm-ss--fff.backup"), privateRoot.GetWif(Network.Main).ToWif(), Encoding.ASCII); // an extra backup - Persistence.Key["BitcoinHotPublicRoot"] = privateRoot.Neuter().GetWif(Network.Main).ToWif(); + + if (String.IsNullOrEmpty (Persistence.Key["BitcoinHotPublicRoot"])) + { + Persistence.Key["BitcoinHotPublicRoot"] = privateRoot.Neuter().GetWif (Network.Main).ToWif(); + } } else { @@ -52,6 +58,19 @@ namespace Swarmops.Logic.Financial // TODO: Log some sort of exception (the sandbox db is reset every night, so it's ok to lose the public key from there) } } + + // Is the hotwallet public root equal to the private root, while in production environment? + + // ReSharper disable once RedundantCheckBeforeAssignment + if (Persistence.Key["BitcoinHotPublicRoot"] != + BitcoinHotPrivateRoot.Neuter().GetWif (Network.Main).ToWif() && !Debugger.IsAttached) + { + // SERIOUS CONDITION - the public root key did not match the private root key. This needs to be logged somewhere. + OutboundComm.CreateNotification (NotificationResource.System_PublicRootReset); + + // Reset it + Persistence.Key["BitcoinHotPublicRoot"] = BitcoinHotPrivateRoot.Neuter().GetWif(Network.Main).ToWif(); + } } } @@ -228,15 +247,18 @@ namespace Swarmops.Logic.Financial foreach (var tx in addressData["txs"]) { string blockchainTransactionId = (string) tx["hash"]; + FinancialTransaction ourTx = null; try { - FinancialTransaction ourTx = FinancialTransaction.FromBlockchainHash(parent.Organization, blockchainTransactionId); - // If the transaction was fetched fine, we have already seen this transaction, and all is fine + ourTx = FinancialTransaction.FromBlockchainHash(parent.Organization, blockchainTransactionId); + // If the transaction was fetched fine, we have already seen this transaction, but need to re-check it } catch (ArgumentException) { // We didn't have this transaction, so we need to create it + + // ourTx = FinancialTransaction.Create (parent.Organization, DateTime, Description) // Did we lose or gain money? // Find all in- and outpoints, determine which are ours (hot and cold wallet) and which aren't diff --git a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs index 58b0ccf1..04c5d8a7 100644 --- a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs +++ b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs @@ -787,6 +787,24 @@ namespace Swarmops.Logic.Resources { } } + /// + /// Looks up a localized string similar to The bitcoin public root key in the MySql database was not a match for the bitcoin private root key stored in /etc/swarmops on [HostName]. This is a potentially serious condition, and should never ever happen, so the public root key was rederived from the private key and re-written to the database over what was there before.. + /// + internal static string System_PublicRootReset_Body { + get { + return ResourceManager.GetString("System_PublicRootReset_Body", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Swarmops: Hotwallet public root key reset. + /// + internal static string System_PublicRootReset_Subject { + get { + return ResourceManager.GetString("System_PublicRootReset_Subject", resourceCulture); + } + } + /// /// Looks up a localized string similar to Swarmops Backend version [SwarmopsVersion] on host [HostName] has successfully started and connected to database and notification frameworks.. /// @@ -804,5 +822,25 @@ namespace Swarmops.Logic.Resources { return ResourceManager.GetString("System_Startup_Subject", resourceCulture); } } + + /// + /// Looks up a localized string similar to The Swarmops transmission engine on [HostName] has encountered an unknown payload type ([UnrecognizedPayloadType]). This should only happen at very rare occasions in conjunction with upgrades where an upgraded version has to take care of something that changed names in the process, itself a rare phenomenon. + /// + ///If this error is recurring, you may have a badly installed plugin or something similar. In any case, the unrecognized message has been discarded and won't be transmitted, since Swarmops doesn't know h [rest of string was truncated]";. + /// + internal static string System_UnrecognizedPayload_Body { + get { + return ResourceManager.GetString("System_UnrecognizedPayload_Body", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Swarmops: Unrecognized comms payload. + /// + internal static string System_UnrecognizedPayload_Subject { + get { + return ResourceManager.GetString("System_UnrecognizedPayload_Subject", resourceCulture); + } + } } } diff --git a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx index eb643cf0..a8576878 100644 --- a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx +++ b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx @@ -435,10 +435,24 @@ The upgrade will be retried every hour. Some functionality may be disabled until Swarmops Mail Server Test + + The bitcoin public root key in the MySql database was not a match for the bitcoin private root key stored in /etc/swarmops on [HostName]. This is a potentially serious condition, and should never ever happen, so the public root key was rederived from the private key and re-written to the database over what was there before. + + + Swarmops: Hotwallet public root key reset + Swarmops Backend version [SwarmopsVersion] on host [HostName] has successfully started and connected to database and notification frameworks. Swarmops Backend operational + + The Swarmops transmission engine on [HostName] has encountered an unknown payload type ([UnrecognizedPayloadType]). This should only happen at very rare occasions in conjunction with upgrades where an upgraded version has to take care of something that changed names in the process, itself a rare phenomenon. + +If this error is recurring, you may have a badly installed plugin or something similar. In any case, the unrecognized message has been discarded and won't be transmitted, since Swarmops doesn't know how. + + + Swarmops: Unrecognized comms payload + \ No newline at end of file diff --git a/Utility/Communications/CommsTransmitterMail.cs b/Utility/Communications/CommsTransmitterMail.cs index f1cef0c8..0d55843b 100644 --- a/Utility/Communications/CommsTransmitterMail.cs +++ b/Utility/Communications/CommsTransmitterMail.cs @@ -28,6 +28,15 @@ namespace Swarmops.Utility.Communications Assembly assembly = typeof(PayloadEnvelope).Assembly; Type payloadType = assembly.GetType(envelope.PayloadClass); + if (payloadType == null) + { + NotificationCustomStrings customStrings = new NotificationCustomStrings(); + customStrings["UnrecognizedPayloadType"] = envelope.PayloadClass; + OutboundComm.CreateNotification (null, NotificationResource.System_UnrecognizedPayload, customStrings); + + throw new OutboundCommTransmitException("Unrecognized or uninstantiable payload type: " + envelope.PayloadClass); + } + var methodInfo = payloadType.GetMethod("FromXml", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); ICommsRenderer renderer = (ICommsRenderer)(methodInfo.Invoke(null, new object[] { envelope.PayloadXml }));