[IMP] Some improvements

This commit is contained in:
2024-05-07 22:02:44 +02:00
parent c42097adbb
commit f14bb52da5
4 changed files with 17 additions and 11 deletions
+12 -8
View File
@@ -183,13 +183,12 @@ def create_openssl_config(force=False,verbose=False):
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:
Printing.error('Error on generating Root CA private key')
os.remove(TisPKI.root_ca_keyfile())
retry = input('If you want to retry, press Y : ')
if retry == "y" or retry == 'Y':
create_openssl_config()
create_openssl_config(force,verbose)
else:
Printing.warning('Root CA private key and certificate already exist. Skip.')
@@ -266,13 +265,15 @@ def create_openssl_intermediate(name, force=False,verbose=False):
-out {TisPKI.intermediate_ca_certfile(name)}", shell=True, check=True, executable='/bin/bash')
if sign_intermediate_ca.returncode == 0:
if verbose:
subprocess.run(f'openssl x509 -in {TisPKI.intermediate_ca_certfile(name)} -text', shell=True, check=True, executable='/bin/bash')
Printing.success(f'Intermediate CA Certfile is stored in : {TisPKI.intermediate_ca_certfile(name)}')
else:
Printing.error('Error on generating Intermediate CA private key')
sys.exit(1)
os.remove(TisPKI.intermediate_ca_keyfile(name))
retry = input('If you want to retry, press Y : ')
if retry == "y" or retry == 'Y':
create_openssl_intermediate(name, force, verbose)
else:
Printing.warning('Intermediate CA private key and certificate already exist. Skip.')
@@ -308,16 +309,17 @@ def generate_dc_certificate(dc_name=None, ca_name=None, force=False, verbose=Fal
Printing.error('Unable to find dc_guid')
sys.exit(1)
else:
dc_guid = str(subprocess.check_output(f'/bin/bash get_guid.sh',shell=True).decode("utf-8")).strip()
dc_name_guid = dc_name.split('.')[0]
dc_guid = str(subprocess.check_output(f'/bin/bash get_guid.sh {dc_name_guid}',shell=True).decode("utf-8")).strip()
if verbose:
Printing.information(f'{dc_name} GUID is : ', str(dc_guid).strip())
Printing.information(f'{dc_name} GUID is : ' + str(dc_guid).strip())
template_dir = ('templates')
jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir))
dc_tmpl = jinja_env.get_template('openssl_server_cert.tmpl')
dc_tmpl_var = {
'dc_name': f"{dc_name}",
'dc_name': dc_name,
'dc_guid': str(dc_guid),
'crl_uri': crl_uri,
'pki_dir': pki_dir,
@@ -328,7 +330,9 @@ def generate_dc_certificate(dc_name=None, ca_name=None, force=False, verbose=Fal
'organization_name': config.get('openssl_config','organization_name'),
'organization_ou': config.get('openssl_config','organization_ou'),
'dc_ca_keyfile': dc_ca_keyfile,
'dc_ca_certfile': dc_ca_certfile
'dc_ca_certfile': dc_ca_certfile,
'commonName': dc_name
}
config_string = dc_tmpl.render(dc_tmpl_var)