initial commit

master
Felix Pankratz 2 years ago
commit ada711f182

2
.gitignore vendored

@ -0,0 +1,2 @@
secret
*.swp

@ -0,0 +1,56 @@
#!/usr/bin/env python3
import random
import secrets
import os
import hashlib
SECRET_FILE = 'secret'
def create_secret():
return secrets.token_hex(128)
def generate_password():
import string
alphabet = string.ascii_letters + string.digits
return ''.join(random.choice(alphabet) for i in range(24))
def month_timestamp():
import datetime
today = datetime.datetime.now()
start_of_month = datetime.datetime(today.year, today.month, 1, 0, 0, 0, 0)
return int(start_of_month.timestamp())
def generate_seed(secret):
m = hashlib.sha256()
m.update(bytes.fromhex(secret))
m.update(str(month_timestamp()).encode())
return m.digest()
def main():
import argparse
parser = argparse.ArgumentParser(prog='Remote Admin Password Solution', description='Generate rotating passwords based on a shared secret')
parser.add_argument('--new-secret', action='store_true', help='generate a new secret')
args = parser.parse_args()
secret = ''
if not os.path.isfile(SECRET_FILE) or args.new_secret:
print('Generating a new secret... ', end='')
secret = create_secret()
with open(SECRET_FILE, 'w') as f:
f.write(secret)
print('done. Send this to the other party:')
print(secret)
else:
secret = open(SECRET_FILE, 'r').read().strip()
print('Secret loaded.')
random.seed(generate_seed(secret))
print('The password of the month is:')
print(generate_password())
if __name__ == '__main__':
main()
Loading…
Cancel
Save