diff --git a/trustify/client/client.py b/trustify/client/client.py index 183c95104..1a1db19aa 100644 --- a/trustify/client/client.py +++ b/trustify/client/client.py @@ -233,6 +233,12 @@ def gen_https_names(domains): result = result + "https://" + domains[len(domains)-1] return result +def output(outputStr): + if curses: + shower.add(outputStr + "\n") + else: + print outputStr + def authenticate(): """ Main call to do DV_SNI validation and deploy the trustify certificate @@ -266,10 +272,7 @@ def authenticate(): # Check first if mod_ssl is loaded if not config.check_ssl_loaded(): - if curses: - shower.add("Loading mod_ssl into Apache Server\n") - else: - print "Loading mod_ssl into Apache Server" + output("Loading mod_ssl into Apache Server") config.enable_mod_ssl() req_file = csr @@ -281,19 +284,14 @@ def authenticate(): # Generate new private key and corresponding csr! key_pem, csr_pem = make_key_and_csr(names, 2048) key_file, req_file = save_key_csr(key_pem, csr_pem) - if curses: - shower.add("Generating key: " + key_file + "\n") - shower.add("Creating CSR: " + req_file + "\n") - else: - print "Generating key:", key_file - print "Creating CSR:", req_file + output("Generating key: " + key_file) + output("Creating CSR: " + req_file) k=chocolatemessage() m=chocolatemessage() init(k) init(m) - if curses: - shower.add("Creating request; generating hashcash...\n") + output("Creating request; generating hashcash...") make_request(server, m, csr_pem, quiet=curses) sign(key_pem, m) if curses: @@ -304,10 +302,7 @@ def authenticate(): if not curses: print r while r.proceed.IsInitialized(): if r.proceed.polldelay > 60: r.proceed.polldelay = 60 - if curses: - shower.add("Waiting %d seconds...\n" % r.proceed.polldelay) - else: - print "waiting", r.proceed.polldelay + output("Waiting %d seconds..." % r.proceed.polldelay) time.sleep(r.proceed.polldelay) k.session = r.session r = decode(do(upstream, k)) @@ -319,13 +314,12 @@ def authenticate(): sni_todo = [] dn = [] - if curses: - shower.add("Received %s challenges from server.\n" % len(r.challenge)) + output("Received %s challenges from server." % len(r.challenge)) for chall in r.challenge: if not curses: print chall if chall.type == r.DomainValidateSNI: if curses: - shower.add("\tDomainValidateSNI challenge for name %s.\n" % chall.name) + shower.add("\tDomainValidateSNI challenge for name %s." % chall.name) dvsni_nonce, dvsni_y, dvsni_ext = chall.data sni_todo.append( (chall.name, dvsni_y, dvsni_nonce, dvsni_ext) ) dn.append(chall.name) @@ -343,7 +337,7 @@ def authenticate(): if not sni_challenge.perform_sni_cert_challenge(sni_todo, os.path.abspath(req_file), os.path.abspath(key_file), config, quiet=curses): print "sni_challenge failed" sys.exit(1) - if curses: shower.add("Configured Apache for challenge; waiting for verification...\n") + output("Configured Apache for challenge; waiting for verification...") if not curses: print "waiting", 3 time.sleep(3) @@ -365,26 +359,18 @@ def authenticate(): if r.success.chain: with open(chain_file, "w") as f: f.write(r.success.chain) - if curses: - shower.add("Server issued certificate; certificate written to %s\n" % cert_file) - else: - print "Server issued certificate; certificate written to " + cert_file + + output("Server issued certificate; certificate written to %s" % cert_file) if r.success.chain: - if curses: - shower.add("Cert chain written to %s\n" % chain_file) - else: - print "Cert chain written to " + chain_file - # TODO: Uncomment the following assignment when the server - # presents a valid chain - #cert_chain_abspath = os.path.abspath(chain_file) + output("Cert chain written to %s" % chain_file) + + # This expects a valid chain file + cert_chain_abspath = os.path.abspath(chain_file) for host in vhost: config.deploy_cert(host, os.path.abspath(cert_file), os.path.abspath(key_file), cert_chain_abspath) # Enable any vhost that was issued to, but not enabled if not config.is_site_enabled(host.file): - if curses: - shower.add("Enabling Site " + host.file) - else: - print "Enabling Site", host.file + output("Enabling Site " + host.file) config.enable_site(host.file) sni_challenge.apache_restart(quiet=curses)