Advence of Core, add yubi on setup program, fix an error on lock, test on Yubikey
This commit is contained in:
parent
dea22875e6
commit
e86e861ba5
4 changed files with 48 additions and 5 deletions
16
Core.py
16
Core.py
|
@ -1,9 +1,19 @@
|
|||
import shelve
|
||||
import shelve, subprocess
|
||||
from os.path import isfile
|
||||
|
||||
class Main:
|
||||
def __init__(self):
|
||||
if not isfile("Settings.conf"):
|
||||
setup()
|
||||
subprocess.check_call(["sudo", "yhsm-generate-keys", "-D", "/etc/yubico/yhsm/keys.json", "--key-handle", "1", "--start-public-id", "interncccccc", "-c", "10"])
|
||||
out = str(subprocess.check_output(["sudo", "ykval-gen-clients", "--urandom", "10"]))
|
||||
out = out[2:-1].split("\\n")
|
||||
keys = dict()
|
||||
for i in out:
|
||||
id = i.find(",")
|
||||
keys[i[:id]] = i[id:] #Risque d'y avoir un \n ?
|
||||
with shelve.open("Settings.conf") as settings:
|
||||
settings["keys"] = keys
|
||||
settings["register"] = list()
|
||||
|
||||
else:
|
||||
isconnection()
|
||||
pass
|
||||
|
|
26
Setup.py
26
Setup.py
|
@ -40,5 +40,31 @@ def web_setup():
|
|||
return "Cant connect"
|
||||
return "Done"
|
||||
|
||||
@app.route("/addyubi")
|
||||
def add_yubi():
|
||||
out = subprocess.check_output(["sudo", "yhsm-decrypt-aead", "--aes-key", "000102030405060708090a0b0c0d0e0f", "--key-handle", "1", "--format", "yubikey-csv", "/var/cache/yubikey-ksm/aeads/"])
|
||||
out = out[2:][:-1].split("\\n")
|
||||
del out[-1]
|
||||
dico = dict()
|
||||
for i in out:
|
||||
id = i.find(",")
|
||||
publicid = i.find(",", id+1)
|
||||
privateid = i.find(",", publicid+1)
|
||||
secretkey = i.find(",", privateid+1)
|
||||
dico[i[:id]] = {"publicid": i[id+1:publicid], "privateid": i[publicid+1:privateid], "secretkey": i[privateid+1:secretkey]}
|
||||
|
||||
with shelve.open("Settings.conf") as settings:
|
||||
id = settings["register"][-1] + 1
|
||||
|
||||
if id > dico.keys()[-1]:
|
||||
return "Error, too many yubikeys"
|
||||
|
||||
#Verifier si une yubikey est connecter !
|
||||
|
||||
subprocess.check_call(["ykpersonalize", "-1", f"-ofixed={dico[id]["publicid"]}", f"-ouid={dico[id]["privateid"]}", f"-a{dico[id]["secretkey"]}"])
|
||||
|
||||
return "Ok"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True, port=6000, host="0.0.0.0")
|
||||
|
|
3
lock.py
3
lock.py
|
@ -4,6 +4,9 @@ import shelve
|
|||
led = LED(17)
|
||||
|
||||
def state(current : bool = None):
|
||||
with shelve.open("Settings.conf") as settings:
|
||||
if not "state" in settings:
|
||||
settings["state"] = False
|
||||
if current != None:
|
||||
with shelve.open("Settings.conf") as settings:
|
||||
settings["state"] = current
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
from yubico_client import Yubico
|
||||
import lock, shelve
|
||||
|
||||
with shelve.open("Settings.conf") as settings:
|
||||
client = Yubico(settings["id"], settings["secret"], api_urls=('http://localhost/wsapi/2.0/verify',))
|
||||
ids = {"interncccccc": 1, "interncccccd": 2}
|
||||
|
||||
while True:
|
||||
try:
|
||||
id = ids[input(">")[:12]]
|
||||
with shelve.open("Settings.conf") as settings:
|
||||
#client = Yubico(id, settings["keys"][id], api_urls=('http://localhost/wsapi/2.0/verify',))
|
||||
client = Yubico(1, "QMho+Y4mtsY+KbCYu1gRKtDtwAM=", api_urls=('http://localhost/wsapi/2.0/verify',))
|
||||
client.verify(input())
|
||||
except:
|
||||
pass
|
||||
|
|
Reference in a new issue