Last active
July 15, 2024 05:44
-
-
Save jackylamhk/ff6fe1233bc788aba5539af902da7db7 to your computer and use it in GitHub Desktop.
Convert AndOTP JSON export to Aegis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import logging | |
import sys | |
import json | |
import uuid | |
logger = logging.getLogger("andotp-to-aegis") | |
def main(andotp_file: str, aegis_file: str): | |
with open(andotp_file, "r") as f: | |
try: | |
ANDOTP_DATA: list[dict[str, str]] = json.load(f) | |
except json.JSONDecodeError as e: | |
logger.error(f"Incorrect JSON format: {e} in {andotp_file}") | |
exit(1) | |
try: | |
AEGIS_DATA = { | |
"version": 1, | |
"header": {"slots": None, "params": None}, | |
"db": { | |
"version": 3, | |
"entries": [ | |
{ | |
"type": e["type"].lower(), | |
"uuid": str(uuid.uuid4()), | |
"name": e["issuer"], | |
"issuer": e["issuer"], | |
"note": e["label"], | |
"info": { | |
"secret": e["secret"], | |
"algo": e["algorithm"], | |
"digits": e["digits"], | |
"period": e["period"], | |
}, | |
"groups": [], | |
} | |
for e in ANDOTP_DATA | |
], | |
"groups": [], | |
}, | |
} | |
except KeyError as e: | |
logger.error(f"Missing key {e} in an entry in {andotp_file}") | |
exit(1) | |
with open(aegis_file, "w") as f: | |
json.dump(AEGIS_DATA, f, indent=2) | |
logger.info(f"Exported {len(ANDOTP_DATA)} entries to {aegis_file}") | |
if __name__ == "__main__": | |
if len(sys.argv) < 2 or sys.argv[1] in ("-h", "--help"): | |
print(f"Usage: {sys.argv[0]} <andotp.json> [aegis.json]") | |
exit() | |
ANDOTP_FILE = sys.argv[1] | |
AEGIS_FILE = sys.argv[2] if len(sys.argv) > 2 else "aegis.json" | |
logging.basicConfig(level=logging.INFO) | |
main(ANDOTP_FILE, AEGIS_FILE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment