diff --git a/Site/App_GlobalResources/Global.designer.cs b/Site/App_GlobalResources/Global.designer.cs
index ad6c6598..643352b7 100644
--- a/Site/App_GlobalResources/Global.designer.cs
+++ b/Site/App_GlobalResources/Global.designer.cs
@@ -1473,6 +1473,38 @@ namespace Resources {
}
}
+ ///
+ /// Looks up a localized string similar to <strong>BITID SUCCESSFULLY ENABLED</strong><br/><br/>When logging on to this system from now on, you need to use the BitId application you just used to scan the code..
+ ///
+ internal static string Master_BitIdRegistered {
+ get {
+ return ResourceManager.GetString("Master_BitIdRegistered", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to BitID two-factor authentication has not been enabled..
+ ///
+ internal static string Master_BitIdRegister_Fail {
+ get {
+ return ResourceManager.GetString("Master_BitIdRegister_Fail", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to <h3>What is this?</h3>
+ /// <p>BitID is a way to log on securely with less hassle than entering a password. Its simplicitly cannot be explained, only experienced, and it is a two-factor authentication since it uses your phone.</p>
+ /// <h3>Doesn't this require my phone to be protected also?</h3>
+ /// <p>Well, yes. It's your phone and your phone's access protection. But your phone should always be access protected.</p>
+ /// <h3>Do I need an app for this?</h3>
+ /// [rest of string was truncated]";.
+ ///
+ internal static string Master_BitIdRegister_Sidebar {
+ get {
+ return ResourceManager.GetString("Master_BitIdRegister_Sidebar", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Two-factor authentication (disabling quarantines login).
///
diff --git a/Site/App_GlobalResources/Global.resx b/Site/App_GlobalResources/Global.resx
index 568a6b2e..a84e451d 100644
--- a/Site/App_GlobalResources/Global.resx
+++ b/Site/App_GlobalResources/Global.resx
@@ -816,6 +816,23 @@
Two weeks
+
+ <strong>BITID SUCCESSFULLY ENABLED</strong><br/><br/>When logging on to this system from now on, you need to use the BitId application you just used to scan the code.
+
+
+ BitID two-factor authentication has not been enabled.
+
+
+ <h3>What is this?</h3>
+ <p>BitID is a way to log on securely with less hassle than entering a password. Its simplicitly cannot be explained, only experienced, and it is a two-factor authentication since it uses your phone.</p>
+ <h3>Doesn't this require my phone to be protected also?</h3>
+ <p>Well, yes. It's your phone and your phone's access protection. But your phone should always be access protected.</p>
+ <h3>Do I need an app for this?</h3>
+ <p>Maybe. Some mobile bitcoin wallets have BitID built in. The most common one hasn't. If yours doesn't, look for an app called "BitID Authenticator" or similar.</p>
+ <h3>How do I enable BitID?</h3>
+ <p>Just use the phone app to scan this code. After that, you can scan a similar code to log in.</p>
+ This text is displayed as a sidebar when registering a BitID address.
+
Unable to set new password: The old password is incorrect.
diff --git a/Site/Automation/SwarmFunctions.aspx.cs b/Site/Automation/SwarmFunctions.aspx.cs
index 76010a2d..ab2011c3 100644
--- a/Site/Automation/SwarmFunctions.aspx.cs
+++ b/Site/Automation/SwarmFunctions.aspx.cs
@@ -14,6 +14,7 @@ using Swarmops.Logic.Support.LogEntries;
using Swarmops.Logic.Swarm;
using Swarmops.Common.Exceptions;
using Swarmops.Frontend;
+using Swarmops.Logic.Cache;
namespace Swarmops.Frontend.Automation
@@ -471,5 +472,28 @@ namespace Swarmops.Frontend.Automation
DisplayMessage = displayMessage
};
}
+
+ [WebMethod]
+ public static AjaxCallResult TestBitIdRegister()
+ {
+ AuthenticationData authData = GetAuthenticationDataAndCulture();
+
+ if (!string.IsNullOrEmpty(authData.CurrentUser.BitIdAddress))
+ {
+ return new AjaxCallResult
+ {
+ Success = true,
+ DisplayMessage = Resources.Global.Master_BitIdRegistered
+ };
+ }
+ else
+ {
+ return new AjaxCallResult
+ {
+ Success = false
+ };
+ }
+ }
+
}
}
\ No newline at end of file
diff --git a/Site/Master-v5.master b/Site/Master-v5.master
index 77c92f6a..e577bee7 100644
--- a/Site/Master-v5.master
+++ b/Site/Master-v5.master
@@ -359,12 +359,13 @@
-
+
Scan this code to enable BitId login
- Info: blah blah blah
- Todo: Blah blah blah
- Where to get: blah blah blah
+
+
@@ -519,7 +520,7 @@
if (newValue) // this is a boolean, so "== true" is implicit
{
<%= this.ModalMasterEnableBitId.ClientID %>_open();
- $('div#divBitIdEnable').qrcode({ text: "https://falkvinge.net/", size:400, quiet: 4 });
+ onBitIdRegisterOpen();
}
else
{ // The user is requesting their 2FA be removed
@@ -626,6 +627,45 @@
}
+ function onBitIdRegisterOpen() {
+ $('div#divBitIdEnable').empty();
+ $('div#divBitIdEnable').qrcode({ text: "<%=this.GenerateBitIdToken%>", size:400, quiet: 4 });
+ $('div#divBitIdEnable .modal-sidebar').html(SwarmopsJS.unescape('<%=this.Localized_BitIdRegister_Sidebar%>'));
+
+ _master_bitIdRecheckTimer = setTimeout(onBitIdRegisterRecheck, 5000); // First check after 5s
+ }
+
+ function onBitIdRegisterFail() {
+ if (_master_bitIdRecheckTimer != null) {
+ clearTimeout(_master_bitIdRecheckTimer);
+ _master_bitIdRecheckTimer = null;
+ }
+
+ if (_master_PersonEditedId == 0) // editing self
+ {
+ <%=this.MasterEditPerson2FA.ClientID%>_initialize(false);
+ alertify.log(SwarmopsJS.unescape('<%=this.Localized_BitIdRegister_Fail%>'));
+ }
+ }
+
+ function onBitIdRegisterRecheck() {
+ SwarmopsJS.ajaxCall("/Automation/SwarmFunctions.aspx/TestBitIdRegister", {}, function(result) {
+ if (result.Success) {
+ _master_bitIdRecheckTimer = null;
+ <%=this.ModalMasterEnableBitId%>_close();
+ alertify.alert(result.DisplayMessage);
+ } else {
+ // not ready yet
+ _master_bitIdRecheckTimer = setTimeout(onBitIdRegisterRecheck, 2000);
+ }
+ }, function() {
+ // errorfunction: set new check even in case of failure
+ _master_bitIdRecheckTimer = setTimeout(onBitIdRegisterRecheck, 2000);
+ });
+ }
+
+ var _master_bitIdRecheckTimer = null;
+
diff --git a/Site/Master-v5.master.cs b/Site/Master-v5.master.cs
index 58ffc288..2f312aea 100644
--- a/Site/Master-v5.master.cs
+++ b/Site/Master-v5.master.cs
@@ -11,6 +11,7 @@ using System.Web.Security;
using System.Web.UI;
using Resources;
using Swarmops.Interface.Support;
+using Swarmops.Logic.Cache;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
@@ -483,5 +484,58 @@ namespace Swarmops.Frontend
{
get { return CommonV5.JavascriptEscape(Resources.Global.Master_EditPerson2FAEnable_NotRemoved); }
}
+
+ public string Localized_BitIdRegister_Fail
+ {
+ get { return CommonV5.JavascriptEscape(Resources.Global.Master_BitIdRegister_Fail); }
+ }
+
+ public string Localized_BitIdRegister_Sidebar
+ {
+ get { return CommonV5.JavascriptEscape(Resources.Global.Master_BitIdRegister_Sidebar); }
+ }
+
+
+ public string GenerateBitIdToken
+ {
+ get
+ {
+ string cloudFlareVisitorScheme = this.Request.Headers["CF-Visitor"];
+ bool cloudFlareSsl = false;
+
+ if (!string.IsNullOrEmpty(cloudFlareVisitorScheme))
+ {
+ if (cloudFlareVisitorScheme.Contains("\"scheme\":\"https\""))
+ {
+ cloudFlareSsl = true;
+ }
+ }
+
+ Guid guid = Guid.NewGuid();
+ string guidString = guid.ToString().Replace("-", "");
+
+ this.bitIdNonce = guidString + DateTime.UtcNow.Ticks.ToString("x8");
+
+ string hostName = this.Request.Url.Host;
+
+ string bitIdUri = "bitid://" + hostName + "/Security/Login.aspx?x=" + this.bitIdNonce;
+
+ if (this.Request.Url.ToString().StartsWith("http://") && !cloudFlareSsl)
+ {
+ bitIdUri += "&u=1";
+ }
+
+ GuidCache.Set(bitIdUri + "-Intent", "Register"); // Intent: register BitID
+
+ return bitIdUri;
+ }
+ }
+
+ private string bitIdNonce;
+
+ public string GenerateBitIdNonce
+ {
+ get { return this.bitIdNonce; }
+ }
}
}
\ No newline at end of file
diff --git a/Site/Security/Login.aspx.cs b/Site/Security/Login.aspx.cs
index 5aacc3c6..dd4758bb 100644
--- a/Site/Security/Login.aspx.cs
+++ b/Site/Security/Login.aspx.cs
@@ -255,30 +255,30 @@ namespace Swarmops.Pages.Security
}
[WebMethod]
- public static bool TestLogin (string uriEncoded, string nonce)
+ public static bool TestLogin(string uriEncoded, string nonce)
{
try
{
- string uri = HttpUtility.UrlDecode (uriEncoded);
+ string uri = HttpUtility.UrlDecode(uriEncoded);
// a little sloppy nonce and uri checking rather than full parsing
// TODO: Full URI parse, the above is not enough
- if (!uri.Contains (nonce) || !uri.Contains (HttpContext.Current.Request.Url.Host))
+ if (!uri.Contains(nonce) || !uri.Contains(HttpContext.Current.Request.Url.Host))
{
throw new ArgumentException();
}
- string result = (string) GuidCache.Get (uri + "-LoggedOn");
- if (string.IsNullOrEmpty (result))
+ string result = (string)GuidCache.Get(uri + "-LoggedOn");
+ if (string.IsNullOrEmpty(result))
{
return false;
}
// We have a successful login when we get here
- GuidCache.Delete (uri + "-Logon");
- GuidCache.Delete (uri + "-LoggedOn");
- GuidCache.Set (nonce + "-Identity", result);
+ GuidCache.Delete(uri + "-Logon");
+ GuidCache.Delete(uri + "-LoggedOn");
+ GuidCache.Set(nonce + "-Identity", result);
return true;
}
@@ -290,6 +290,7 @@ namespace Swarmops.Pages.Security
}
}
+
[WebMethod]
// ReSharper disable once InconsistentNaming
public static string TestCredentials (string credentialsLogin, string credentialsPass, string credentials2FA,
diff --git a/Site/Site.csproj b/Site/Site.csproj
index f8054f1b..64583c2d 100644
--- a/Site/Site.csproj
+++ b/Site/Site.csproj
@@ -1736,6 +1736,7 @@
+