#! /usr/bin/env python # This is a TOY. Do not fire in anger. import os import sys import base64 import pprint from optparse import OptionParser def main(argv): pp = pprint.PrettyPrinter(indent=4) op = OptionParser( description="gen_key_pair generates pseudo-random 64 byte key pairs for use in testing alcuin") op.add_option( "-r", "--remote-name", help="Name of remote station to include with key pair") op.add_option( "-l", "--local-name", help="Name of local station to include with key pair") op.add_option( "-p", "--remote-port", help="Remote station port number to include with key pair") op.add_option( "-q", "--local-port", help="Local station port number to include with key pair") op.add_option( "-a", "--remote-address", help="Remote station IP address to include with key pair") op.add_option( "-b", "--local-address", help="Local station IP address to include with key pair") (options, args) = op.parse_args(argv[1:]) if options.local_port is None: options.local_port = 7778 if options.remote_port is None: options.remote_port = 7778 if options.local_address is None: options.local_address = "" if options.remote_address is None: options.remote_address = "" key = generate_key() my_config = { "name": options.local_name, "key": key, "address": options.local_address, "port": options.local_port } their_config = { "name": options.remote_name, "key": key, "address": options.remote_address, "port": options.remote_port } pp.pprint(my_config) pp.pprint(their_config) def generate_key(): return base64.b64encode(os.urandom(64)) main(sys.argv)