sio-2425/delivery1/client/bin/rep_subject_credentials

42 lines
999 B
Plaintext
Raw Normal View History

2024-11-12 10:26:56 +00:00
#!/bin/python3
2024-11-19 19:06:54 +00:00
import os
2024-11-12 10:26:56 +00:00
import sys
import logging
import argparse
2024-11-17 20:18:02 +00:00
from lib import key_pair
2024-11-12 10:26:56 +00:00
logging.basicConfig(format='%(levelname)s\t- %(message)s')
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# Generate a key pair for a subject
2024-11-17 20:18:02 +00:00
# password - file for public key, file for private key
2024-11-12 10:26:56 +00:00
def generateKeyPair(args):
parser = argparse.ArgumentParser()
parser.add_argument('password', nargs='?', default=None)
2024-11-17 20:18:02 +00:00
parser.add_argument('pubfile', nargs='?', default=None)
parser.add_argument('privfile', nargs='?', default=None)
args = parser.parse_args()
2024-11-17 20:18:02 +00:00
if len(args) != 3:
2024-11-12 10:26:56 +00:00
logger.error("Need password and file to store keys")
sys.exit(-1)
#Generate the key pair
2024-11-17 20:18:02 +00:00
key_pair.generate_key_pair(args.pubfile, args.privfile, 2048, args.password)
2024-11-12 10:26:56 +00:00
2024-11-19 19:06:54 +00:00
#Save key files in environment
os.environ['PRIV_KEY'] = args.privfile
os.environ['PUB_KEY'] = args.pubfile
2024-11-17 20:18:02 +00:00
return 0
2024-11-12 10:26:56 +00:00
if __name__ == '__main__':
2024-11-17 20:18:02 +00:00
generateKeyPair(sys.argv[1:])
2024-11-12 10:26:56 +00:00