diff --git a/common.py b/common.py index fe873e8..0ac7889 100644 --- a/common.py +++ b/common.py @@ -115,7 +115,7 @@ def check_directories(path): pass -def create_openssl_config(): +def create_openssl_config(verbose=False): print('Check Root CA OpenSSL Config') if config.get('general','pki_dir'): @@ -153,12 +153,13 @@ def create_openssl_config(): print('Root CA OpenSSL config already exist. Skip.') # Generate privkey and cert for Root CA - if not os.path.isfile(TisPKI.root_ca_keyfile()) and not os.path.isfile(TisPKI.root_ca_certfile()): + if not os.path.isfile(TisPKI.root_ca_keyfile()) or not os.path.isfile(TisPKI.root_ca_certfile()): print('Generate Root CA private key') - gen_root_ca = subprocess.run(f'/usr/bin/openssl req -x509 -new -sha512 -config {root_ca_config} -days 3650 -extensions v3_ca -keyout {TisPKI.root_ca_keyfile()} -out {TisPKI.root_ca_certfile()}', shell=True, check=True, executable='/bin/bash') + gen_root_ca = subprocess.run(f'/usr/bin/openssl req -x509 -new -sha512 -config {root_ca_config} -days 3650 -extensions v3_ca -keyout {TisPKI.root_ca_keyfile()} -out {TisPKI.root_ca_certfile()}', shell=True, check=False, executable='/bin/bash') if gen_root_ca.returncode == 0: - subprocess.run(f'openssl x509 -in {TisPKI.root_ca_certfile()} -text', shell=True, check=True, executable='/bin/bash') + if verbose: + subprocess.run(f'openssl x509 -in {TisPKI.root_ca_certfile()} -text', shell=True, check=True, executable='/bin/bash') Printing.information(f'Root CA Certfile is stored in {TisPKI.root_ca_certfile()}') input("Press Enter to continue...") else: diff --git a/manage_pki.py b/manage_pki.py index a6e8432..1c73f30 100644 --- a/manage_pki.py +++ b/manage_pki.py @@ -19,11 +19,12 @@ def main(): parser.add_option('--initialize', dest="initialize", action="store_true", help="Create PKI") parser.add_option('--create-intermediate', dest="create_intermediate", action="store_true", help="Create an intermediate CA") parser.add_option('--create-dc-cert', dest="create_dc_cert", action="store_true", help="Create a certificat for a Domain Controler") + parser.add_option('-v', '--verbose', dest="verbose", action="store_true", help="Print all command") (options, args) = parser.parse_args() if options.initialize: - create_openssl_config() + create_openssl_config(verbose=options.verbose) if __name__ == '__main__':