Misc work on Reset Password

This commit is contained in:
Rick Falkvinge
2015-01-29 11:56:00 +01:00
parent f335c035be
commit dea8df630c
12 changed files with 159 additions and 75 deletions
@@ -401,13 +401,13 @@ namespace Swarmops.Logic.App_GlobalResources {
}
/// <summary>
/// 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]&amp;Ticket=[LockoutTicket]
///[ExternalUrl]Security/LockoutAccount?Mail=[MailAddress]&amp;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]&quot;;.
///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]&quot;;.
/// </summary>
internal static string Password_Changed_Body {
get {
@@ -416,7 +416,7 @@ namespace Swarmops.Logic.App_GlobalResources {
}
/// <summary>
/// Looks up a localized string similar to [[OrganizationName]] Password was changed.
/// Looks up a localized string similar to [[InstallationName]] Password was changed.
/// </summary>
internal static string Password_Changed_Subject {
get {
@@ -449,11 +449,11 @@ namespace Swarmops.Logic.App_GlobalResources {
}
/// <summary>
/// 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]&quot;;.
///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]&quot;;.
/// </summary>
internal static string Password_ResetOnRequest_Body {
get {
@@ -462,7 +462,7 @@ namespace Swarmops.Logic.App_GlobalResources {
}
/// <summary>
/// Looks up a localized string similar to [[OrganizationName]] Password Reset Ticket.
/// Looks up a localized string similar to [[InstallationName]] Password Reset Ticket.
/// </summary>
internal static string Password_ResetOnRequest_Subject {
get {
@@ -254,18 +254,18 @@ Thank you for your understanding.</value>
<value>[[OrganizationName]] Cannot Reset Password</value>
</data>
<data name="Password_Changed_Body" xml:space="preserve">
<value>Your password at [OrganizationName] was changed.
<value>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]&amp;Ticket=[LockoutTicket]
[ExternalUrl]Security/LockoutAccount?Mail=[MailAddress]&amp;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.</value>
</data>
<data name="Password_Changed_Subject" xml:space="preserve">
<value>[[OrganizationName]] Password was changed</value>
<value>[[InstallationName]] Password was changed</value>
</data>
<data name="Password_ResetByCrew_Body" xml:space="preserve">
<value>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
<value>[[OrganizationName]] Password Reset Ticket</value>
</data>
<data name="Password_ResetOnRequest_Body" xml:space="preserve">
<value>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:
<value>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.)</value>
</data>
<data name="Password_ResetOnRequest_Subject" xml:space="preserve">
<value>[[OrganizationName]] Password Reset Ticket</value>
<value>[[InstallationName]] Password Reset Ticket</value>
</data>
<data name="Receipts_Filed_Body" xml:space="preserve">
<value>Receipts have been filed that need validation for their financial processes to continue.
+11
View File
@@ -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)
@@ -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]
+16
View File
@@ -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();
}
}
}
+11
View File
@@ -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];
@@ -201,7 +201,7 @@
<value>Western Europe</value>
</data>
<data name="World" xml:space="preserve">
<value>World</value>
<value>Global</value>
<comment>Root geography</comment>
</data>
</root>
+3
View File
@@ -552,4 +552,7 @@
<data name="Global_PostalCode" xml:space="preserve">
<value>Postal Code</value>
</data>
<data name="Error_AjaxCallException" xml:space="preserve">
<value>There was a general, unspecified error contacting the Swarmops server. Is the still network operational and the server available?</value>
</data>
</root>
@@ -223,6 +223,9 @@
<data name="ResetPassword_Info" xml:space="preserve">
<value>You're resetting the password for a user account. Enter your new password twice to set it and login.</value>
</data>
<data name="ResetPassword_InfoRequest" xml:space="preserve">
<value>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.</value>
</data>
<data name="ResetPassword_NoEmpty" xml:space="preserve">
<value>The new password cannot be empty.</value>
</data>
@@ -248,6 +251,6 @@
<value>Ticket</value>
</data>
<data name="ResetPassword_TicketSentMaybe" xml:space="preserve">
<value>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.)&lt;br/&gt;&lt;br/&gt;You may close this browser tab. It is not needed anymore.</value>
<value>If the email was associated with an account on this Swarmops installation, a &lt;strong&gt;reset ticket has been sent.&lt;/strong&gt; Open that mail and click the link in the mail to reset your password. (If the email did not exist, nothing was sent.)&lt;br/&gt;&lt;br/&gt;You may close this browser tab. It is not needed anymore.</value>
</data>
</root>
+2 -15
View File
@@ -439,26 +439,13 @@ public partial class Pages_v5_Init_Default : Page
{
StringBuilder machineKey = new StringBuilder();
machineKey.Append("<machineKey \n");
machineKey.Append("validationKey=\"" + GetRandomKey (64) + "\"\n");
machineKey.Append("decryptionKey=\"" + GetRandomKey (32) + "\"\n");
machineKey.Append("validationKey=\"" + SupportFunctions.GenerateSecureRandomKey (64) + "\"\n");
machineKey.Append("decryptionKey=\"" + SupportFunctions.GenerateSecureRandomKey (32) + "\"\n");
machineKey.Append("validation=\"HMACSHA512\" decryption=\"AES\"\n");
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();
}
/// <summary>
/// This function copies the schemas and geography data off an existing Swarmops installation. Runs in its own thread.
+40 -33
View File
@@ -26,6 +26,9 @@
<style type="text/css">
div#DivSuccessMaybe {
display: none;
}
</style>
@@ -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
}
</script>
<!-- Main menu, emptied out here -->
<div class="center980px">
<div class="currentuserinfo"><div style="background-image: url('/Images/Icons/iconshock-user-16px.png'); background-repeat: no-repeat; padding-left: 16px; float: left"><asp:Label ID="LabelCurrentUserName" runat="server" /> | </div><div style="background-image: url('/Images/Icons/iconshock-workchair-16px.png'); background-repeat: no-repeat; padding-left: 17px; float: left"><asp:Label ID="LabelCurrentOrganizationName" runat="server" /> |&nbsp;</div><div style="background-image: url('/Images/Icons/iconshock-gamepad-16px.png'); background-repeat: no-repeat; padding-left: 20px; float: left"><asp:Label ID="LabelPreferences" runat="server" /> |&nbsp;</div><asp:Image ID="ImageCultureIndicator" runat="server" ImageUrl="~/Images/Flags/uk-24px.png" /></div>
<div class="logoimage"><a href="/"><img style="border: none" src="/Security/Images/Swarmops-Logo.png" alt="Swarmops Logo" /></a></div>
@@ -59,53 +87,32 @@
<div class="box">
<div class="content">
<h2><asp:Label ID="LabelContentTitle" runat="server" /></h2>
<div id="DivEmail">
<div id="DivMailEntry">
<div class="entryFields">
<asp:TextBox runat="server" ID="TextEmail" />&#8203;<br/>
<!-- button -->
<asp:TextBox runat="server" ID="TextMailAddress" />&#8203;<br/>
<asp:Button ID="ButtonRequest" runat="server" CssClass="buttonAccentColor NoInputFocus" OnClientClick="return resetPassword();" Text="XYZ Request"/>
</div>
<div class="entryLabels">
<asp:Label ID="LabelMail" runat="server" /><br />
</div>
</div>
<div style="clear:both"></div>
<div id="DivSuccessMaybe">
<asp:Label ID="LabelSuccessMaybe" runat="server" />
<asp:Label ID="LabelSuccessMaybe" runat="server" /><br/><br/><!-- some ugly formatting solutions on the one-off pages -->
</div>
</div>
</div>
</div>
<div class="sidebar">
<h2 class="blue"><asp:Label ID="LabelSidebarInfoHeader" runat="server" /><span class="arrow"></span></h2>
<h2 class="blue"><asp:Label ID="LabelSidebarInfoHeader" runat="server" /><span class="arrow"></span></h2>
<div class="box">
<div class="content">
<asp:Label ID="LabelSidebarInfoContent" runat="server" />
</div>
</div>
<h2 class="blue"><asp:Label ID="LabelSidebarManualLoginHeader" runat="server" /><span class="arrow"></span></h2>
<div class="box">
<div class="content" style="line-height: 24px">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td><asp:Literal ID="LiteralCredentialsUser" runat="server" />&nbsp;&nbsp;</td><td align="right"><input id="TextLogin" class="InputManualCredentials" type="text" /></td></tr>
<tr><td><asp:Literal ID="LiteralCredentialsPass" runat="server" />&nbsp;&nbsp;</td><td align="right"><input id="TextPass" class="InputManualCredentials" type="password" /></td></tr>
<tr style="display: none"><td><asp:Literal id="LiteralCredentials2FA" runat="server" />&nbsp;&nbsp;</td><td><input id="Text2FA" class="InputManualCredentials" type="password" /></td></tr>
</table>
</div>
</div>
<h2 class="orange"><asp:Label ID="LabelSidebarHelpHeader" runat="server" /><span class="arrow"></span></h2>
<div class="box">
<div class="content">
<div class="link-row-encaps" onclick=" return false; " >
<div class="link-row-icon" style="background-image: url('/Images/Icons/iconshock-databaseconnect-16px.png')"></div>
<asp:Label ID="LabelSidebarResetPassword" runat="server" />
<div class="box">
<div class="content">
<asp:Label ID="LabelSidebarInfoContent" runat="server" />
</div>
</div>
</div>
</div>
</div>
</div>
@@ -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;
}
}
}