add loading of MNT-data from kverify
This commit is contained in:
parent
83e411bcc3
commit
9476ec4f63
7 changed files with 100 additions and 24 deletions
|
@ -1,8 +1,8 @@
|
||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
import base64, os
|
import base64, os, json, time
|
||||||
from OpenSSL.crypto import load_publickey, FILETYPE_PEM, verify, X509
|
|
||||||
import OpenSSL
|
import OpenSSL
|
||||||
|
from OpenSSL.crypto import load_publickey, FILETYPE_PEM, verify, X509
|
||||||
|
|
||||||
|
|
||||||
PUBKEY_FILE = os.path.dirname(__file__)+"/kioubit-auth-pubkey.pem"
|
PUBKEY_FILE = os.path.dirname(__file__)+"/kioubit-auth-pubkey.pem"
|
||||||
|
@ -33,12 +33,18 @@ class AuthVerifyer ():
|
||||||
verify(self.x509, sig, params, 'sha512')
|
verify(self.x509, sig, params, 'sha512')
|
||||||
except OpenSSL.crypto.Error:
|
except OpenSSL.crypto.Error:
|
||||||
return False, "Signature Failed"
|
return False, "Signature Failed"
|
||||||
#h = SHA512.new()
|
|
||||||
#h.update(base64.b64decode(params))
|
try:
|
||||||
#print(h.hexdigest())
|
user_data = json.loads(base64.b64decode(params))
|
||||||
#verifier = DSS.new(self.pubkey, 'deterministic-rfc6979')
|
if (time.time() - user_data["time"] )> 60:
|
||||||
#valid = verifier.verify(h, base64.b64decode(signature))
|
return False, "Signature to old"
|
||||||
return True, ""
|
except json.decoder.JSONDecodeError:
|
||||||
|
# we shouldn't get here unless kioubit's service is misbehaving
|
||||||
|
return False, "invalid JSON"
|
||||||
|
except KeyError:
|
||||||
|
return False, "value not found in JSON"
|
||||||
|
print(user_data)
|
||||||
|
return True, user_data
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
example_com_verifier = AuthVerifyer("example.com")
|
example_com_verifier = AuthVerifyer("example.com")
|
||||||
|
|
|
@ -47,7 +47,7 @@ def auth_required():
|
||||||
def wrapper(f):
|
def wrapper(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args, **kwargs):
|
||||||
if not "logged_in" in session:
|
if not "login" in session:
|
||||||
return redirect(f"login?return={request.url}")
|
return redirect(f"login?return={request.url}")
|
||||||
else:
|
else:
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
|
@ -58,31 +58,65 @@ def auth_required():
|
||||||
kverifyer = kioubit_verify.AuthVerifyer(config["domain"])
|
kverifyer = kioubit_verify.AuthVerifyer(config["domain"])
|
||||||
@app.route("/api/auth/kverify", methods=["GET", "POST"])
|
@app.route("/api/auth/kverify", methods=["GET", "POST"])
|
||||||
def kioubit_auth():
|
def kioubit_auth():
|
||||||
params = request.args["params"]
|
try:
|
||||||
signature = request.args["signature"]
|
params = request.args["params"]
|
||||||
print(base64.b64decode(params))
|
signature = request.args["signature"]
|
||||||
return str(kverifyer.verify(params, signature))
|
except KeyError:
|
||||||
|
return render_template("login.html", session=session,config=config,return_addr=session["return_url"], msg='"params" or "signature" missing')
|
||||||
|
|
||||||
|
|
||||||
|
success, msg = kverifyer.verify(params, signature)
|
||||||
|
try: print(base64.b64decode(params))
|
||||||
|
except: print("invalid Base64 data provided")
|
||||||
|
|
||||||
|
|
||||||
|
if success:
|
||||||
|
session["user-data"] = msg
|
||||||
|
session["login"] = msg['mnt']
|
||||||
|
return redirect(session["return_url"])
|
||||||
|
else:
|
||||||
|
return render_template("login.html", session=session,config=config,return_addr=session["return_url"], msg=msg)
|
||||||
|
|
||||||
|
@app.route("/logout")
|
||||||
|
def logout():
|
||||||
|
session.clear()
|
||||||
|
return redirect("/")
|
||||||
|
|
||||||
@app.route("/login",methods=["GET","POST"])
|
@app.route("/login",methods=["GET","POST"])
|
||||||
def login():
|
def login():
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
session["return_url"] = request.args["return"]
|
session["return_url"] = request.args["return"] if "return" in request.args else ""
|
||||||
return render_template("login.html", config=config, return_addr=request.args["return"])
|
|
||||||
|
return render_template("login.html", session=session, config=config, return_addr=session["return_url"])
|
||||||
|
elif request.method == "POST":
|
||||||
|
if config["domain"] == "svc.burble.dn42:8042" and request.form["logincode"] and request.form["logincode"] == "eyJhc24iOjQyNDI0MjMwMzUsImFsbG93ZWQ0IjoiMTcyLjIyLjEyNS4xMjhcLzI2LDE3Mi4yMC4wLjgxXC8zMiIsImFsbG93ZWQ2IjoiZmQ2Mzo1ZDQwOjQ3ZTU6OlwvNDgsZmQ0MjpkNDI6ZDQyOjgxOjpcLzY0IiwibW50IjoiTEFSRS1NTlQifQo=":
|
||||||
|
print("abc")
|
||||||
|
user_data = json.loads(base64.b64decode(request.form["logincode"]))
|
||||||
|
session["login"] = user_data['mnt']
|
||||||
|
session["user-data"] = user_data
|
||||||
|
return redirect(request.args["return"])
|
||||||
|
|
||||||
#elif request.method == "POST":
|
|
||||||
|
|
||||||
@app.route("/peer", methods=["GET","POST"])
|
@app.route("/peer", methods=["GET","POST"])
|
||||||
@auth_required()
|
@auth_required()
|
||||||
def peer():
|
def peer():
|
||||||
return request.args
|
if request.method == "GET":
|
||||||
|
if "node" in request.args and request.args["node"] in config["nodes"]:
|
||||||
|
return render_template("peer.html", config=config, selected_node=request.args["node"])
|
||||||
|
return str(config["nodes"][request.args["node"]])
|
||||||
|
else: return render_template("peer.html", session=session,config=config)
|
||||||
|
elif request.method == "POST":
|
||||||
|
return "POST /peer"
|
||||||
|
|
||||||
|
else:
|
||||||
|
return 405
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
# print(config._config["nodes"])
|
# print(config._config["nodes"])
|
||||||
# for node in config["nodes"].values():
|
# for node in config["nodes"].values():
|
||||||
# print (node)
|
# print (node)
|
||||||
return render_template("index.html", config=config._config)
|
return render_template("index.html", session=session, config=config._config)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app.static_folder= config["flask-template-dir"]+"/static/"
|
app.static_folder= config["flask-template-dir"]+"/static/"
|
||||||
|
|
|
@ -5,11 +5,14 @@
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>{{config["MNT"]}} Autopeering</title>
|
<title>{{config["MNT"]}} Autopeering</title>
|
||||||
<link rel="stylesheet" href="static/style.css">
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header class="flex">{{config["MNT"]}}</header>
|
<header class="flex flex-row"><div></div><a href="/">{{config["MNT"]}} Autopeering</a>{% if "login" in session %}<a href="/logout">logout</a>{% else %} <a href="/login?return=/peer">login</a>{%endif%}</header>
|
||||||
<div class="content flex">{% block content %}{% endblock %}</div>
|
<div class="content flex">
|
||||||
|
{% block content %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
<footer class="flex">
|
<footer class="flex">
|
||||||
<div></div>
|
<div></div>
|
||||||
<div></div>
|
<div></div>
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th>NodeName</th>
|
||||||
<th>Country</th>
|
<th>Country</th>
|
||||||
<th>City</th>
|
<th>City</th>
|
||||||
<th>peerings</th>
|
<th>peerings</th>
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
{% for node in config["nodes"] %}
|
{% for node in config["nodes"] %}
|
||||||
<tr>
|
<tr>
|
||||||
|
<td>{{node}}</td>
|
||||||
<td>{{config["nodes"][node]["country"]}}</td>
|
<td>{{config["nodes"][node]["country"]}}</td>
|
||||||
<td>{{config["nodes"][node]["city"]}}</td>
|
<td>{{config["nodes"][node]["city"]}}</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
{% if msg %}
|
||||||
|
<div style="background-color: red;">
|
||||||
|
{{msg}}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<form action="https://dn42.g-load.eu/auth/">
|
<form action="https://dn42.g-load.eu/auth/">
|
||||||
<link rel="stylesheet" href="https://dn42.g-load.eu/auth/assets/button-font/auth.css">
|
<link rel="stylesheet" href="https://dn42.g-load.eu/auth/assets/button-font/auth.css">
|
||||||
<input type="hidden" id="return" name="return" value='{{"http://"+config["domain"]+"/api/auth/kverify"}}'>
|
<input type="hidden" id="return" name="return" value='{{"http://"+config["domain"]+"/api/auth/kverify"}}'>
|
||||||
|
@ -11,7 +17,8 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<input type="">
|
<input type="text" name="logincode" id="logincode">
|
||||||
|
<input type="submit" value="submit">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
13
web/frontend/peer.html
Normal file
13
web/frontend/peer.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<form action="peer" method="post">
|
||||||
|
<select name="node" id="node">
|
||||||
|
{% for node in config["nodes"] %}
|
||||||
|
<option value="{{node}}" {% if selected_node %}{% if selected_node == node %}selected{% endif %}{% endif %} >{{node}}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -2,6 +2,7 @@
|
||||||
--bg-color: #aaa;
|
--bg-color: #aaa;
|
||||||
--text-color: black;
|
--text-color: black;
|
||||||
--other-background: #444;
|
--other-background: #444;
|
||||||
|
/* --accent-color: ; */
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
@ -15,16 +16,26 @@ header {
|
||||||
background-color: var(--other-background);
|
background-color: var(--other-background);
|
||||||
height: 50px;
|
height: 50px;
|
||||||
}
|
}
|
||||||
|
a {
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: calc(100% - 55px);
|
height: calc(100% - 55px);
|
||||||
margin: initial;
|
margin: auto;
|
||||||
|
}
|
||||||
|
.content>* {
|
||||||
|
padding: 5%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.flex {
|
.flex {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
.flex-row {
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
.flex>* {
|
.flex>* {
|
||||||
flex-flow: column;
|
flex-flow: column;
|
||||||
|
|
Loading…
Add table
Reference in a new issue