From dea8df630c1f972beaf2424aa9bbfd6873b1c749 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Thu, 29 Jan 2015 11:56:00 +0100 Subject: [PATCH] Misc work on Reset Password --- ...ansmission.NotificationPayload.Designer.cs | 16 ++-- ...ions.Transmission.NotificationPayload.resx | 12 +-- Logic/Communications/OutboundComm.cs | 11 +++ .../Transmission/NotificationPayload.cs | 23 +++--- Logic/Support/General.cs | 16 ++++ Logic/Support/SystemSettings.cs | 11 +++ Site5/App_GlobalResources/GeographyNames.resx | 2 +- Site5/App_GlobalResources/Global.resx | 3 + Site5/App_GlobalResources/Pages.Security.resx | 5 +- Site5/Pages/v5/Init/Default.aspx.cs | 17 +---- Site5/Security/RequestPasswordReset.aspx | 73 ++++++++++--------- Site5/Security/RequestPasswordReset.aspx.cs | 45 ++++++++++++ 12 files changed, 159 insertions(+), 75 deletions(-) diff --git a/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.Designer.cs b/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.Designer.cs index 869f3d6b..11ca2921 100644 --- a/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.Designer.cs +++ b/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.Designer.cs @@ -401,13 +401,13 @@ namespace Swarmops.Logic.App_GlobalResources { } /// - /// Looks up a localized string similar to Your password at [OrganizationName] was changed. + /// Looks up a localized string similar to Your [InstallationName] password was changed at [ExternalUrl]. /// ///If you did not just perform this password change, there has been a security breach. If this is the case, please block your account IMMEDIATELY by clicking the following link: /// - ///[ExternalUrl]Security/LockoutAccount?Email=[EmailAddress]&Ticket=[LockoutTicket] + ///[ExternalUrl]Security/LockoutAccount?Mail=[MailAddress]&Ticket=[LockoutTicket] /// - ///For security purposes, there will not be a confirmation dialog: your account will be locked the instant you go to this link, and administrators will contact you to verify what happened and work with [rest of string was truncated]";. + ///For security purposes, there will not be a confirmation dialog: your account will be locked the instant you go to this link, and administrators will contact you to verify what happened a [rest of string was truncated]";. /// internal static string Password_Changed_Body { get { @@ -416,7 +416,7 @@ namespace Swarmops.Logic.App_GlobalResources { } /// - /// Looks up a localized string similar to [[OrganizationName]] Password was changed. + /// Looks up a localized string similar to [[InstallationName]] Password was changed. /// internal static string Password_Changed_Subject { get { @@ -449,11 +449,11 @@ namespace Swarmops.Logic.App_GlobalResources { } /// - /// Looks up a localized string similar to Somebody, most likely you, requested a reset of the password associated with this email address at [OrganizationName]. If this was you, please follow the link below in the next 60 minutes to complete the password reset procedure: + /// Looks up a localized string similar to Somebody, most likely you, requested a reset of the password associated with this email address at [InstallationName]. If this was you, please follow the link below in the next 60 minutes to complete the password reset procedure: /// - ///[ExternalUrl]Security/ResetPassword?Ticket=[ResetPasswordTicket] + ///[ExternalUrl]Security/ResetPassword?Ticket=[TicketCode] /// - ///If you did NOT request a password reset, you can (and should) ignore this mail. The password reset request will expire in one hour. (If you are getting a large number of these password reset links that you did n [rest of string was truncated]";. + ///If you did NOT request a password reset, you can (and should) ignore this mail. The password reset request will expire in one hour. (If you are getting a large number of these password reset links that you did not reques [rest of string was truncated]";. /// internal static string Password_ResetOnRequest_Body { get { @@ -462,7 +462,7 @@ namespace Swarmops.Logic.App_GlobalResources { } /// - /// Looks up a localized string similar to [[OrganizationName]] Password Reset Ticket. + /// Looks up a localized string similar to [[InstallationName]] Password Reset Ticket. /// internal static string Password_ResetOnRequest_Subject { get { diff --git a/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.resx b/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.resx index 845967b9..a8c29806 100644 --- a/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.resx +++ b/Logic/App_GlobalResources/Logic.Communications.Transmission.NotificationPayload.resx @@ -254,18 +254,18 @@ Thank you for your understanding. [[OrganizationName]] Cannot Reset Password - Your password at [OrganizationName] was changed. + Your [InstallationName] password was changed at [ExternalUrl]. If you did not just perform this password change, there has been a security breach. If this is the case, please block your account IMMEDIATELY by clicking the following link: -[ExternalUrl]Security/LockoutAccount?Email=[EmailAddress]&Ticket=[LockoutTicket] +[ExternalUrl]Security/LockoutAccount?Mail=[MailAddress]&Ticket=[LockoutTicket] For security purposes, there will not be a confirmation dialog: your account will be locked the instant you go to this link, and administrators will contact you to verify what happened and work with you to re-enable your account. However, if it was you yourself who changed the password, and thereby caused this notification to be sent, everything is obviously fine and just as it should be. Carry on. - [[OrganizationName]] Password was changed + [[InstallationName]] Password was changed People at [OrganizationName] have issued a password reset ticket to your account, presumably at your request. This ticket is valid for the next 24 hours. @@ -280,14 +280,14 @@ This ticket will expire in 24 hours. If you do not reset your password in this t [[OrganizationName]] Password Reset Ticket - Somebody, most likely you, requested a reset of the password associated with this email address at [OrganizationName]. If this was you, please follow the link below in the next 60 minutes to complete the password reset procedure: + Somebody, most likely you, requested a reset of the password associated with this email address at [InstallationName]. If this was you, please follow the link below in the next 60 minutes to complete the password reset procedure: -[ExternalUrl]Security/ResetPassword?Ticket=[ResetPasswordTicket] +[ExternalUrl]Security/ResetPassword?Ticket=[TicketCode] If you did NOT request a password reset, you can (and should) ignore this mail. The password reset request will expire in one hour. (If you are getting a large number of these password reset links that you did not request, please notify the administrator.) - [[OrganizationName]] Password Reset Ticket + [[InstallationName]] Password Reset Ticket Receipts have been filed that need validation for their financial processes to continue. diff --git a/Logic/Communications/OutboundComm.cs b/Logic/Communications/OutboundComm.cs index b4a112da..8efb1dc4 100644 --- a/Logic/Communications/OutboundComm.cs +++ b/Logic/Communications/OutboundComm.cs @@ -246,6 +246,17 @@ namespace Swarmops.Logic.Communications } + public static OutboundComm CreateSecurityNotifcation (Person concernedPerson, Person actingPerson, string ticket, + NotificationResource notification) + { + NotificationPayload payload = new NotificationPayload(notification.ToString()); + payload.Strings[NotificationString.ActingPersonName] = actingPerson.Name; + payload.Strings[NotificationString.ConcernedPersonName] = actingPerson.Name; + payload.Strings[NotificationString.] + + } + + public void AddRecipient (Person person) { if (person == null) diff --git a/Logic/Communications/Transmission/NotificationPayload.cs b/Logic/Communications/Transmission/NotificationPayload.cs index d32dfaa2..08835a17 100644 --- a/Logic/Communications/Transmission/NotificationPayload.cs +++ b/Logic/Communications/Transmission/NotificationPayload.cs @@ -61,7 +61,8 @@ namespace Swarmops.Logic.Communications.Transmission input = input.Replace ("[HostName]", Dns.GetHostName()); input = input.Replace ("[DbVersion]", SwarmDb.DbVersionExpected.ToString(CultureInfo.InvariantCulture)); input = input.Replace ("[SwarmopsVersion]", Formatting.SwarmopsVersion); - input = input.Replace ("[ExternalUrl]", SystemSettings.ExternalUrl); + input = input.Replace("[InstallationName]", SystemSettings.InstallationName); + input = input.Replace("[ExternalUrl]", SystemSettings.ExternalUrl); // Loop through supplied strings and replace them in the resource. Not very efficient but who cares @@ -131,21 +132,21 @@ namespace Swarmops.Logic.Communications.Transmission public enum NotificationString { Unknown = 0, - ConcernedPersonName, ActingPersonName, - TertiaryPersonName, - OrganizationName, + BudgetAmountFloat, + BudgetName, + ConcernedPersonName, + CurrencyCode, DateTime, DateTimeExpiry, - BudgetName, - BudgetAmountFloat, - CurrencyCode, + Description, EmbeddedPreformattedText, + OrganizationName, + MailAddress, RequestPurpose, - HostName, - SwarmopsVersion, - Supplier, - Description + TertiaryPersonName, + TicketCode, + Supplier } [Serializable] diff --git a/Logic/Support/General.cs b/Logic/Support/General.cs index 4be36ddd..442a0123 100644 --- a/Logic/Support/General.cs +++ b/Logic/Support/General.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Net.Security; +using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; @@ -19,5 +20,20 @@ namespace Swarmops.Logic.Support System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; } + + public static string GenerateSecureRandomKey(int bytelength) + { + byte[] buffer = new byte[bytelength]; + RNGCryptoServiceProvider devRandom = new RNGCryptoServiceProvider(); + devRandom.GetBytes(buffer); + + StringBuilder result = new StringBuilder(bytelength * 2); + for (int loop = 0; loop < buffer.Length; loop++) + { + result.AppendFormat("{0:X2}", buffer[loop]); + } + return result.ToString(); + } + } } diff --git a/Logic/Support/SystemSettings.cs b/Logic/Support/SystemSettings.cs index cd2f0f6e..314be7b4 100644 --- a/Logic/Support/SystemSettings.cs +++ b/Logic/Support/SystemSettings.cs @@ -79,6 +79,17 @@ namespace Swarmops.Logic.Support } } + static public string InstallationId + { + get { return Persistence.Key["SwarmopsInstallationId"]; } // no setter - intentional + } + + static public string InstallationName + { + get { return GetDefaultedPersistedKey ("InstallationName", "Swarmops"); } + set { Persistence.Key["InstallationName"] = value; } + } + static private string GetDefaultedPersistedKey (string key, string defaultValue) { string result = Persistence.Key[key]; diff --git a/Site5/App_GlobalResources/GeographyNames.resx b/Site5/App_GlobalResources/GeographyNames.resx index 78a52db0..5393baa1 100644 --- a/Site5/App_GlobalResources/GeographyNames.resx +++ b/Site5/App_GlobalResources/GeographyNames.resx @@ -201,7 +201,7 @@ Western Europe - World + Global Root geography \ No newline at end of file diff --git a/Site5/App_GlobalResources/Global.resx b/Site5/App_GlobalResources/Global.resx index afb482ab..b4ec1ded 100644 --- a/Site5/App_GlobalResources/Global.resx +++ b/Site5/App_GlobalResources/Global.resx @@ -552,4 +552,7 @@ Postal Code + + There was a general, unspecified error contacting the Swarmops server. Is the still network operational and the server available? + \ No newline at end of file diff --git a/Site5/App_GlobalResources/Pages.Security.resx b/Site5/App_GlobalResources/Pages.Security.resx index 3ad7065f..c959163b 100644 --- a/Site5/App_GlobalResources/Pages.Security.resx +++ b/Site5/App_GlobalResources/Pages.Security.resx @@ -223,6 +223,9 @@ You're resetting the password for a user account. Enter your new password twice to set it and login. + + Enter your mail account to send instructions to that address on how to proceed with the password reset procedure. It will contain a unique and expiring code that you will need to use to proceed. + The new password cannot be empty. @@ -248,6 +251,6 @@ Ticket - If the email was associated with an account on this Swarmops installation, a reset ticket has now been sent. Open that mail and click the link in the mail to reset your password. (If the email did not exist, nothing was sent.)<br/><br/>You may close this browser tab. It is not needed anymore. + If the email was associated with an account on this Swarmops installation, a <strong>reset ticket has been sent.</strong> Open that mail and click the link in the mail to reset your password. (If the email did not exist, nothing was sent.)<br/><br/>You may close this browser tab. It is not needed anymore. \ No newline at end of file diff --git a/Site5/Pages/v5/Init/Default.aspx.cs b/Site5/Pages/v5/Init/Default.aspx.cs index 34fdf832..996eb289 100644 --- a/Site5/Pages/v5/Init/Default.aspx.cs +++ b/Site5/Pages/v5/Init/Default.aspx.cs @@ -439,26 +439,13 @@ public partial class Pages_v5_Init_Default : Page { StringBuilder machineKey = new StringBuilder(); machineKey.Append("\n"); return machineKey.ToString(); } - public static string GetRandomKey(int bytelength) - { - byte[] buffer = new byte[bytelength]; - RNGCryptoServiceProvider devRandom = new RNGCryptoServiceProvider(); - devRandom.GetBytes(buffer); - - StringBuilder result = new StringBuilder(bytelength * 2); - for (int loop = 0; loop < buffer.Length; loop++) - { - result.AppendFormat ("{0:X2}", buffer[loop]); - } - return result.ToString(); - } /// /// This function copies the schemas and geography data off an existing Swarmops installation. Runs in its own thread. diff --git a/Site5/Security/RequestPasswordReset.aspx b/Site5/Security/RequestPasswordReset.aspx index 80217f44..ce48eec6 100644 --- a/Site5/Security/RequestPasswordReset.aspx +++ b/Site5/Security/RequestPasswordReset.aspx @@ -26,6 +26,9 @@ @@ -41,12 +44,37 @@ }); + function resetPassword() { + var jsonData = {}; + jsonData.mailAddress = $('#<%=this.TextMailAddress.ClientID%>').val(); + + $.ajax({ + type: "POST", + url: "/Security/RequestPasswordReset.aspx/RequestTicket", + data: $.toJSON(jsonData), + contentType: "application/json; charset=utf-8", + dataType: "json", + async: false, // blocks until function returns - race conditions otherwise + success: function (msg) { + if (msg.d) { + $('#DivSuccessMaybe').slideDown(); + $('#DivMailEntry').slideUp(); + } // ignore a "false" for now - it means an invalid (syntactically wrong) mail addr + }, + error: function(msg) { + alertify.error("<%=Resources.Global.Error_AjaxCallException%>"); + } + }); + + return false; // prevent page submission + } + - +
|
| 
| 
Swarmops Logo
@@ -59,53 +87,32 @@

-
+
- ​
- + ​
+
+
- +

diff --git a/Site5/Security/RequestPasswordReset.aspx.cs b/Site5/Security/RequestPasswordReset.aspx.cs index db433888..cf82ed20 100644 --- a/Site5/Security/RequestPasswordReset.aspx.cs +++ b/Site5/Security/RequestPasswordReset.aspx.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.Linq; using System.Web; +using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; +using Swarmops.Logic.Support; namespace Swarmops.Pages.Security { @@ -11,7 +13,50 @@ namespace Swarmops.Pages.Security { protected void Page_Load(object sender, EventArgs e) { + this.Title = Resources.Pages.Security.ResetPassword_PageTitle; + this.ImageCultureIndicator.Style[HtmlTextWriterStyle.MarginTop] = "-3px"; + this.ImageCultureIndicator.Style[HtmlTextWriterStyle.MarginRight] = "3px"; + if (!Page.IsPostBack) + { + Localize(); + } } + + private void Localize() + { + // Normal template + this.LabelSidebarInfoContent.Text = Resources.Pages.Security.ResetPassword_Info; + this.LabelSidebarInfoHeader.Text = Resources.Global.Sidebar_Information; + this.LabelCurrentOrganizationName.Text = Resources.Global.Global_Organization; + this.LabelCurrentUserName.Text = Resources.Global.Global_NoOwner; + this.LabelPreferences.Text = Resources.Global.CurrentUserInfo_Preferences; + + // Page specific + this.LabelContentTitle.Text = Resources.Pages.Security.ResetPassword_PageTitle; + this.LabelMail.Text = Resources.Pages.Security.ResetPassword_Email; + this.LabelSuccessMaybe.Text = Resources.Pages.Security.ResetPassword_TicketSentMaybe; + this.ButtonRequest.Text = Resources.Pages.Security.ResetPassword_Reset; + } + + [WebMethod] + public static bool RequestTicket (string mailAddress) + { + mailAddress = mailAddress.Trim(); + + if (string.IsNullOrEmpty (mailAddress)) + { + return false; // this is the only case when we return false: a _syntactically_invalid_ address + } + + string resetTicket = SupportFunctions.GenerateSecureRandomKey (16); // 16 bytes = 128 bits random key, more than good enough + + // Create notification + + // Create log entry + + return true; + } + } } \ No newline at end of file