2024-11-12 10:26:56 +00:00
|
|
|
#!/bin/python3
|
|
|
|
import sys
|
|
|
|
import logging
|
2024-11-17 19:37:41 +00:00
|
|
|
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):
|
|
|
|
|
2024-11-17 19:37:41 +00:00
|
|
|
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)
|
2024-11-17 19:37:41 +00:00
|
|
|
|
|
|
|
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-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
|
|
|
|