BitID might just possibly work now

This commit is contained in:
Falkvinge
2016-11-24 12:24:03 +01:00
parent 78a049a10f
commit 92e3aa8615
7 changed files with 182 additions and 13 deletions
+32
View File
@@ -1473,6 +1473,38 @@ namespace Resources {
}
}
/// <summary>
/// Looks up a localized string similar to &lt;strong&gt;BITID SUCCESSFULLY ENABLED&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;When logging on to this system from now on, you need to use the BitId application you just used to scan the code..
/// </summary>
internal static string Master_BitIdRegistered {
get {
return ResourceManager.GetString("Master_BitIdRegistered", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to BitID two-factor authentication has not been enabled..
/// </summary>
internal static string Master_BitIdRegister_Fail {
get {
return ResourceManager.GetString("Master_BitIdRegister_Fail", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt;h3&gt;What is this?&lt;/h3&gt;
/// &lt;p&gt;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.&lt;/p&gt;
/// &lt;h3&gt;Doesn&apos;t this require my phone to be protected also?&lt;/h3&gt;
/// &lt;p&gt;Well, yes. It&apos;s your phone and your phone&apos;s access protection. But your phone should always be access protected.&lt;/p&gt;
/// &lt;h3&gt;Do I need an app for this?&lt;/h3&gt;
/// [rest of string was truncated]&quot;;.
/// </summary>
internal static string Master_BitIdRegister_Sidebar {
get {
return ResourceManager.GetString("Master_BitIdRegister_Sidebar", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Two-factor authentication (disabling quarantines login).
/// </summary>
+17
View File
@@ -816,6 +816,23 @@
<data name="Timespan_Selection_TwoWeeks" xml:space="preserve">
<value>Two weeks</value>
</data>
<data name="Master_BitIdRegistered" xml:space="preserve">
<value>&lt;strong&gt;BITID SUCCESSFULLY ENABLED&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;When logging on to this system from now on, you need to use the BitId application you just used to scan the code.</value>
</data>
<data name="Master_BitIdRegister_Fail" xml:space="preserve">
<value>BitID two-factor authentication has not been enabled.</value>
</data>
<data name="Master_BitIdRegister_Sidebar" xml:space="preserve">
<value>&lt;h3&gt;What is this?&lt;/h3&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;h3&gt;Doesn't this require my phone to be protected also?&lt;/h3&gt;
&lt;p&gt;Well, yes. It's your phone and your phone's access protection. But your phone should always be access protected.&lt;/p&gt;
&lt;h3&gt;Do I need an app for this?&lt;/h3&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;h3&gt;How do I enable BitID?&lt;/h3&gt;
&lt;p&gt;Just use the phone app to scan this code. After that, you can scan a similar code to log in.&lt;/p&gt;</value>
<comment>This text is displayed as a sidebar when registering a BitID address.</comment>
</data>
<data name="Master_EditPersonNewPassword_CannotChange_SecurityError" xml:space="preserve">
<value>Unable to set new password: The old password is incorrect.</value>
</data>
+24
View File
@@ -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
};
}
}
}
}
+45 -5
View File
@@ -359,12 +359,13 @@
</DialogCode>
</Swarmops5:ModalDialog>
<Swarmops5:ModalDialog ID="ModalMasterEnableBitId" runat="server">
<Swarmops5:ModalDialog ID="ModalMasterEnableBitId" runat="server" OnClientClose="onBitIdRegisterFail">
<DialogCode>
<h2>Scan this code to enable BitId login</h2>
<div id="divBitIdEnable" style="height: 400px; margin: 50px; float:left"></div>Info: blah blah blah
Todo: Blah blah blah
Where to get: blah blah blah
<div id="divBitIdEnable" style="height: 280px; margin: 50px; float:left"></div>
<div class="modal-sidebar" style="margin-top:50px">
</div>
</DialogCode>
</Swarmops5:ModalDialog>
@@ -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;
</script>
+54
View File
@@ -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; }
}
}
}
+9 -8
View File
@@ -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,
+1
View File
@@ -1736,6 +1736,7 @@
<Content Include="Scripts\jquery.toggles.js" />
<Content Include="Scripts\jquery.toggles.min.js" />
<Content Include="Scripts\jquery.ui.widget.min.js" />
<Content Include="Scripts\kjua-0.1.1.min.js" />
<Content Include="Scripts\qrcode.js" />
<Content Include="Scripts\qrcode.min.js" />
<Content Include="Scripts\ScriptLicenses.txt" />