diff --git a/cli.py b/cli.py index 7ed80ec..9750b88 100644 --- a/cli.py +++ b/cli.py @@ -1,12 +1,10 @@ #!/usr/bin/env python3 import argparse, logging, sys, getpass, tempfile, os -import zope.component from certbot._internal.plugins import disco as plugins_disco from certbot._internal.plugins import selection as plug_sel from certbot._internal import cli from certbot._internal import main as certbot_main -from certbot._internal import reporter from certbot._internal import log from certbot._internal.display import obj as display_obj from certbot.display import util as display_util @@ -22,30 +20,29 @@ from cryptography.hazmat.primitives import serialization, hashes from cryptography.hazmat.primitives.serialization import pkcs12, Encoding -logger = logging.getLogger(__name__) - +logger = logging.getLogger(__name__) + def prepare_cli_args(args): cli_args = [] command = args.command.lower() if (args.config_dir): cli_args.extend(['--config-dir',args.config_dir]) if (args.work_dir): cli_args.extend(['--work-dir',args.work_dir]) if (args.logs_dir): cli_args.extend(['--logs-dir',args.logs_dir]) - + if (command == 'cert'): cli_args.extend(['certonly']) else: cli_args.extend([command]) - + if (args.test): cli_args.extend(['--server','https://acme-staging.castle.cloud/acme/directory']) else: cli_args.extend(['--server','https://acme.castle.cloud/acme/directory']) - + if (args.non_interactive): cli_args.extend(['-n']) - + return cli_args -def prepare_config(cli_args): +def prepare_config(cli_args): plugins = plugins_disco.PluginsRegistry.find_all() cargs = cli.prepare_and_parse_args(plugins, cli_args) config = configuration.NamespaceConfig(cargs) - zope.component.provideUtility(config, interfaces.IConfig) return config,plugins def root_cert_advise(): @@ -65,7 +62,7 @@ def request_cert(args, config): key, csr = csr_util.prepare(args.email, config, key_path=args.key_path, usage=args.usage) ## Reparse for including --csr arguments cli_args = prepare_cli_args(args) - if (args.dry_run): + if (args.dry_run): cli_args.extend(['--dry-run']) for email in args.email: cli_args.extend(['-d',email]) @@ -107,14 +104,14 @@ def request_cert(args, config): elif (args.passphrase): cli_args.extend(['--castle-installer-passphrase',args.passphrase]) cli_args.extend(['-m',args.contact]) - if (args.agree_tos): + if (args.agree_tos): cli_args.extend(['--agree-tos']) config,plugins = prepare_config(cli_args) - + config.cert_path = config.live_dir+'/cert.pem' config.chain_path = config.live_dir+'/ca.pem' config.fullchain_path = config.live_dir+'/chain.pem' - + config.key_path = key.file try: # installers are used in auth mode to determine domain names @@ -133,7 +130,7 @@ def request_cert(args, config): certbot_main._install_cert(config, le_client, args.email) else: util.safely_remove(csr.file) - + def try_open_p12(file,passphrase=None): with open(args.cert_path,'rb') as p12: (private_key, certificate, _) = pkcs12.load_key_and_certificates(p12.read(),passphrase) @@ -145,7 +142,7 @@ def try_open_p12(file,passphrase=None): temp_pkey.close() return temp_pkey.name,temp_cert.name return None,None - + def revoke_cert(args, config): cli_args = prepare_cli_args(args) if (args.reason): @@ -156,7 +153,7 @@ def revoke_cert(args, config): key_path,cert_path = try_open_p12(args.cert_path) cli_args.extend(['--cert-path',cert_path]) cli_args.extend(['--key-path',key_path]) - except ValueError as e: + except ValueError as e: if ('Invalid password' in str(e)): passphrase = None if (args.passphrase): @@ -184,7 +181,7 @@ def revoke_cert(args, config): os.unlink(key_path) if (cert_path): os.unlink(cert_path) - + def main(args): ## Prepare storage system command = args.command.lower() @@ -198,9 +195,6 @@ def main(args): certbot_main.make_or_verify_needed_dirs(config) except errors.Error: raise - report = reporter.Reporter(config) - zope.component.provideUtility(report, interfaces.IReporter) - util.atexit_register(report.print_messages) with certbot_main.make_displayer(config) as displayer: display_obj.set_display(displayer) @@ -208,7 +202,7 @@ def main(args): request_cert(args, config) elif (command == 'revoke'): revoke_cert(args, config) - + def process_args(args): if args.email: for e in args.email: @@ -228,28 +222,28 @@ def parse_args(): parser.add_argument('--contact', help='Contact e-mail for important account notifications') parser.add_argument('--imap', help='Uses IMAP Authenticator for automatic reply', action='store_true') parser.add_argument('command',choices=['cert','revoke','renew']) - + parser.add_argument('--login',help='IMAP login',required='--imap' in sys.argv) parser.add_argument('--password',help='IMAP password',required='--imap' in sys.argv) parser.add_argument('--host',help='IMAP server host',required='--imap' in sys.argv) parser.add_argument('--port',help='IMAP server port. If empty, it will be auto-detected') parser.add_argument('--ssl',help='IMAP SSL connection',action='store_true') - + parser.add_argument('--smtp-method',help='SMTP method {STARTTLS,SSL,plain}',choices= ['STARTTLS','SSL','plain']) parser.add_argument('--smtp-login',help='SMTP login. If empty, IMAP login will be used') parser.add_argument('--smtp-password',help='SMTP password. If empty, IMAP password will be used') parser.add_argument('--smtp-host',help='SMTP server host',required='--imap' in sys.argv) parser.add_argument('--smtp-port',help='SMTP server port. If empty, it will be auto-detected') - + parser.add_argument('--no-passphrase',help='PKCS12 is stored without passphrase. Use with CAUTION: the PKCS12 contains the private key',action='store_true') parser.add_argument('--passphrase',help='Passphrase to use for the PKCS12 generation. This passpharse will be used for private key encryption') - + parser.add_argument('--usage', help='Key usage for certificate. Multiple usages can be specified', choices=['digitalSignature','contentCommitment','keyEncipherment','keyAgreement'], action='append') parser.add_argument('--cert-path',help='Path where certificate is located',required='revoke' in sys.argv) parser.add_argument('--reason',help='Reason of revocation',choices=['unspecified','keycompromise','affiliationchanged','superseded','cessationofoperation']) parser.add_argument('--key-path',help='Path of private key location') - + parser.add_argument('--outlook', help='Uses MAPI (Outlook) Authenticator for automatic reply', action='store_true') parser.add_argument('--outlook-account', help='Outlook account where the challenge is processed', required='--outlook' in sys.argv) @@ -260,12 +254,11 @@ def parse_args(): args = parser.parse_args() process_args(args) - + return args if __name__ == "__main__": - + args = parse_args() main(args) - \ No newline at end of file diff --git a/setup.py b/setup.py index b620e71..5adeefe 100644 --- a/setup.py +++ b/setup.py @@ -10,12 +10,11 @@ version = mo.group(1) else: raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,)) - + INSTALL_REQUIRES = [ 'certbot>=1.20.0', 'acme>=1.20.0', 'setuptools', - 'zope.interface', 'imapclient', 'dkimpy', 'cryptography>=3.3',