From 5f782aebd679882061064251574e85685e2ae7ae Mon Sep 17 00:00:00 2001 From: James Kasten Date: Wed, 15 May 2013 18:24:28 -0400 Subject: [PATCH] Fixed some API naming issues --- trustify.py | 4 +++- trustify/client/client.py | 28 +++++++++++++++++----------- trustify/client/configurator.py | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/trustify.py b/trustify.py index 7ba3ae9a7..454616a79 100644 --- a/trustify.py +++ b/trustify.py @@ -4,6 +4,7 @@ import getopt import os +import sys from trustify.client import client @@ -21,6 +22,7 @@ def main(): sys.exit(2) server = None + csr = None privkey = None curses = True names = args @@ -43,7 +45,7 @@ def main(): else: server = "ca.theobroma.info" - c = client.client(server, args, csr, privkey, curses) + c = client.Client(server, args, csr, privkey, curses) c.authenticate() def usage(): diff --git a/trustify/client/client.py b/trustify/client/client.py index acf5f634c..91fecccdb 100644 --- a/trustify/client/client.py +++ b/trustify/client/client.py @@ -28,8 +28,18 @@ from trustify.client.CONFIG import SERVER_ROOT, KEY_DIR, CERT_DIR allow_raw_ipv6_server = False RSA_KEY_SIZE = 2048 + class Client(object): + # In case of import, dialog needs scope over the class + dialog = None + def __init__(self, ca_server, domains=[], cert_signing_request=None, private_key=None, use_curses=True): + global dialog + + self.curses = use_curses + if self.curses: + import dialog + # Logger needs to be initialized before Configurator self.init_logger() self.config = configurator.Configurator(SERVER_ROOT) @@ -40,7 +50,7 @@ class Client(object): else: self.names = self.get_all_names() self.csr_file = cert_signing_request - self.key_file = privkey + self.key_file = private_key # If CSR is provided, the private key should also be provided. # TODO: Make sure key was actually used in CSR @@ -49,10 +59,6 @@ class Client(object): logger.fatal("Please provide the private key file used in generating the provided CSR") sys.exit(1) - self.curses = use_curses - if self.curses: - import dialog - self.sanity_check_names([ca_server] + domains) self.upstream = "https://%s/chocolate.py" % self.server @@ -83,11 +89,11 @@ class Client(object): # Perform all "client knows first" challenges for challenge in challenges: - if not challenge.perform(quiet=self.curses): - # TODO: In this case the client should probably send a failure - # to the server. - logger.fatal("challenge failed") - sys.exit(1) + if not challenge.perform(quiet=self.curses): + # TODO: In this case the client should probably send a failure + # to the server. + logger.fatal("challenge failed") + sys.exit(1) logger.info("Configured Apache for challenges; waiting for verification...") r = self.notify_server_of_completion(r) @@ -463,7 +469,7 @@ class Client(object): def sanity_check_names(self, names): for name in names: - assert is_hostname_sane(name), `name` + " is an impossible hostname" + assert self.is_hostname_sane(name), `name` + " is an impossible hostname" def is_hostname_sane(self, hostname): """ diff --git a/trustify/client/configurator.py b/trustify/client/configurator.py index ff2ef211f..b5c106025 100644 --- a/trustify/client/configurator.py +++ b/trustify/client/configurator.py @@ -34,7 +34,7 @@ class VH(object): class Configurator(object): - def __init__(self): + def __init__(self, server_root=SERVER_ROOT): # TODO: this instantiation can be optimized to only load Httd # relevant files # Set Augeas flags to save backup