Better Error handling
This commit is contained in:
40
mfa/FIDO2.py
40
mfa/FIDO2.py
@@ -58,9 +58,11 @@ def complete_reg(request):
|
|||||||
uk.save()
|
uk.save()
|
||||||
return HttpResponse(simplejson.dumps({'status': 'OK'}))
|
return HttpResponse(simplejson.dumps({'status': 'OK'}))
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
from raven.contrib.django.raven_compat.models import client
|
try:
|
||||||
import traceback
|
from raven.contrib.django.raven_compat.models import client
|
||||||
client.captureException()
|
client.captureException()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return HttpResponse(simplejson.dumps({'status': 'ERR',"message":"Error on server, please try again later"}))
|
return HttpResponse(simplejson.dumps({'status': 'ERR',"message":"Error on server, please try again later"}))
|
||||||
def start(request):
|
def start(request):
|
||||||
context = csrf(request)
|
context = csrf(request)
|
||||||
@@ -94,15 +96,27 @@ def authenticate_complete(request):
|
|||||||
client_data = ClientData(data['clientDataJSON'])
|
client_data = ClientData(data['clientDataJSON'])
|
||||||
auth_data = AuthenticatorData(data['authenticatorData'])
|
auth_data = AuthenticatorData(data['authenticatorData'])
|
||||||
signature = data['signature']
|
signature = data['signature']
|
||||||
|
try:
|
||||||
cred = server.authenticate_complete(
|
cred = server.authenticate_complete(
|
||||||
request.session.pop('fido_state'),
|
request.session.pop('fido_state'),
|
||||||
credentials,
|
credentials,
|
||||||
credential_id,
|
credential_id,
|
||||||
client_data,
|
client_data,
|
||||||
auth_data,
|
auth_data,
|
||||||
signature
|
signature
|
||||||
)
|
)
|
||||||
|
except ValueError:
|
||||||
|
return HttpResponse(simplejson.dumps({'status': "ERR", "message": "Wrong challenge received, make sure that this is your security and try again."}),
|
||||||
|
content_type = "application/json")
|
||||||
|
except Exception as excep:
|
||||||
|
try:
|
||||||
|
from raven.contrib.django.raven_compat.models import client
|
||||||
|
client.captureException()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return HttpResponse(simplejson.dumps({'status': "ERR",
|
||||||
|
"message": "Err: " + excep.message}),
|
||||||
|
content_type = "application/json")
|
||||||
|
|
||||||
if request.session.get("mfa_recheck",False):
|
if request.session.get("mfa_recheck",False):
|
||||||
import time
|
import time
|
||||||
@@ -123,4 +137,4 @@ def authenticate_complete(request):
|
|||||||
request.session["mfa"] = mfa
|
request.session["mfa"] = mfa
|
||||||
res=login(request)
|
res=login(request)
|
||||||
return HttpResponse(simplejson.dumps({'status':"OK","redirect":res["location"]}),content_type="application/json")
|
return HttpResponse(simplejson.dumps({'status':"OK","redirect":res["location"]}),content_type="application/json")
|
||||||
return HttpResponse(simplejson.dumps({'status': "err"}),content_type="application/json")
|
return HttpResponse(simplejson.dumps({'status': "ERR","message":"Unknown error happened"}),content_type="application/json")
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
{% extends "mfa_auth_base.html" %}
|
{% extends "mfa_auth_base.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<br/>
|
|
||||||
<br/>
|
|
||||||
{% include 'FIDO2/recheck.html' with mode='auth' %}
|
{% include 'FIDO2/recheck.html' with mode='auth' %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<p style="color: green">please press the button on your security key to prove it is you.</p>
|
<p style="color: green">please press the button on your security key to prove it is you.</p>
|
||||||
|
<div id="msgdiv"></div>
|
||||||
{% if mode == "auth" %}
|
{% if mode == "auth" %}
|
||||||
<form id="u2f_login" action="{% url 'fido2_complete_auth' %}" method="post" enctype="multipart/form-data">
|
<form id="u2f_login" action="{% url 'fido2_complete_auth' %}" method="post" enctype="multipart/form-data">
|
||||||
{% elif mode == "recheck" %}
|
{% elif mode == "recheck" %}
|
||||||
@@ -71,17 +72,22 @@
|
|||||||
}).then(function (response) {if (response.ok) return res = response.json()}).then(function (res) {
|
}).then(function (response) {if (response.ok) return res = response.json()}).then(function (res) {
|
||||||
if (res.status=="OK")
|
if (res.status=="OK")
|
||||||
{
|
{
|
||||||
|
$("#msgdiv").addClass("alert alert-success").removeClass("alert-danger")
|
||||||
|
$("#msgdiv").html("Verified....please wait")
|
||||||
{% if mode == "auth" %}
|
{% if mode == "auth" %}
|
||||||
window.location.href=res.redirect;
|
window.location.href=res.redirect;
|
||||||
{% elif mode == "recheck" %}
|
{% elif mode == "recheck" %}
|
||||||
mfa_success_function();
|
mfa_success_function();
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
$("#msgdiv").addClass("alert alert-danger").removeClass("alert-success")
|
||||||
|
$("#res").html("<div class='alert alert-danger'>Verification Failed as " + res["message"] + ", <a href='javascript:void(0)' onclick='authen())'> try again or <a href='javascript:void(0)' onclick='history.back()'> Go Back</a></div>")
|
||||||
|
|
||||||
{% if mode == "auth" %}
|
{% if mode == "auth" %}
|
||||||
alert("Error occured, please try again")
|
|
||||||
login()
|
|
||||||
{% elif mode == "recheck" %}
|
{% elif mode == "recheck" %}
|
||||||
|
|
||||||
mfa_failed_function();
|
mfa_failed_function();
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user