diff --git a/Core.py b/Core.py index 3d1afa6..7697925 100644 --- a/Core.py +++ b/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 diff --git a/Setup.py b/Setup.py index a5bda9d..8670e67 100644 --- a/Setup.py +++ b/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") diff --git a/lock.py b/lock.py index 455787d..13784fe 100644 --- a/lock.py +++ b/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 diff --git a/yubikey.py b/yubikey.py index 6325196..a3e2b8b 100644 --- a/yubikey.py +++ b/yubikey.py @@ -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