forked from scollovati/Aegis-decrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aegis-decrypt.py
57 lines (47 loc) · 1.79 KB
/
aegis-decrypt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
"""
usage: aegis-decrypt.py [-h] --vault VAULT [--entryname ENTRYNAME] [--output {None,csv,qrcode,json,otp}]
password: test
"""
import argparse
import getpass
from src.AegisDB import AegisDB
from src.Output import Output
def main():
parser = argparse.ArgumentParser(prog="aegis-decrypt.py",
description="Decrypt an Aegis vault and produce an output as requested", add_help=True)
parser.add_argument("--vault", dest="vault", required=True, help="The encrypted Aegis vault file")
# optional args
parser.add_argument("--entryname", dest="entryname", required=False,
help="The name of the entry for which you want to generate the OTP code")
parser.add_argument("--output", dest="output", required=False, choices=[None, 'csv', 'qrcode', 'json', 'otp'],
help="The output format (default is stdout)")
parser.add_argument("--password", dest="password", required=False,
help="The encryption password")
args = parser.parse_args()
if args.password is None:
password = getpass.getpass().encode("utf-8")
else:
password = args.password.encode("utf-8")
db = AegisDB(args.vault, password)
if args.entryname is None:
entries = db.getAll()
else:
entries = db.getByName(args.entryname)
if entries:
output = Output(entries, args.entryname)
match args.output:
case 'csv':
output.csv()
case 'qrcode':
output.qrcode()
case 'json':
output.json()
case 'otp':
output.otp()
case _:
output.stdout()
else:
print("No entries found")
if __name__ == '__main__':
main()