introduce a tool to create keys for the client and the server
This commit is contained in:
44
aman/tools/KeyPairCreator.py
Normal file
44
aman/tools/KeyPairCreator.py
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from typing import Tuple
|
||||
import zmq.auth
|
||||
|
||||
# @brief Creates a new keypair for ZMQ encryption
|
||||
# @param[in] directory The location where to store the keys
|
||||
# @return The public and private key tuple
|
||||
def KeyPairCreator(directory: str, server: bool) -> Tuple[str, str]:
|
||||
if not server:
|
||||
print('Creating a new pair for a client...')
|
||||
target = 'client'
|
||||
else:
|
||||
print('Creating a new pair for the server...')
|
||||
target = 'server'
|
||||
|
||||
public, private = zmq.auth.create_certificates(directory, target)
|
||||
return (public, private)
|
||||
|
||||
def str2bool(value):
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
elif value.lower() in ('yes', 'true', 't', 'y', '1'):
|
||||
return True
|
||||
elif value.lower() in ('no', 'false', 'f', 'n', '0'):
|
||||
return False
|
||||
else:
|
||||
raise argparse.ArgumentTypeError('Boolean value expected')
|
||||
|
||||
if __name__ == '__main__':
|
||||
# create the commandline parser
|
||||
parser = argparse.ArgumentParser(description='Create a new key-value pair')
|
||||
parser.add_argument('directory', help='Directory where to store the key pair')
|
||||
parser.add_argument('--server', default=False, action='store_true', help="Creates server key pair")
|
||||
args = parser.parse_args()
|
||||
|
||||
# create the directory if it does not exist
|
||||
if not os.path.exists(args.directory):
|
||||
os.makedirs(args.directory)
|
||||
|
||||
# create the keys
|
||||
KeyPairCreator(args.directory, args.server)
|
||||
Viittaa uudesa ongelmassa
Block a user