[IMP] More improvements
This commit is contained in:
@@ -95,19 +95,21 @@ class TisPKI:
|
||||
|
||||
|
||||
|
||||
def check_directories(path):
|
||||
def check_directories(path,verbose=False):
|
||||
print('Check directories')
|
||||
|
||||
directories_list = ['certs','config','crl','newcerts','private','csr','crl','p12']
|
||||
|
||||
if not os.path.isdir(path):
|
||||
print(f'Create { path } directory')
|
||||
if verbose:
|
||||
Printing.information(f'Create { path } directory')
|
||||
os.makedirs(path)
|
||||
|
||||
for directory in directories_list:
|
||||
directory_path = os.path.join(path,directory)
|
||||
if not os.path.isdir(directory_path):
|
||||
print(f'Create { directory_path } directory')
|
||||
if verbose:
|
||||
Printing.information(f'Create { directory_path } directory')
|
||||
os.makedirs(directory_path)
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'index.txt')):
|
||||
@@ -116,18 +118,18 @@ def check_directories(path):
|
||||
|
||||
|
||||
def create_openssl_config(verbose=False):
|
||||
print('Check Root CA OpenSSL Config')
|
||||
Printing.information('Check Root CA OpenSSL Config')
|
||||
|
||||
if config.get('general','pki_dir'):
|
||||
check_directories(path=config.get('general','pki_dir'))
|
||||
check_directories(path=config.get('general','pki_dir'),verbose)
|
||||
else:
|
||||
print('No pki_dir set in samba-pki-tools.ini')
|
||||
Printing.error('No pki_dir set in samba-pki-tools.ini')
|
||||
sys.exit(1)
|
||||
|
||||
root_ca_config = os.path.join(TisPKI.pki_dir(),'config','openssl_root_ca.ini')
|
||||
|
||||
if not os.path.isfile(root_ca_config):
|
||||
print('Root CA OpenSSL configfile not exist. Creating...')
|
||||
Printing.information('Root CA OpenSSL configfile not exist. Creating...')
|
||||
template_dir = os.path.join('templates')
|
||||
jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir))
|
||||
root_ca_tmpl = jinja_env.get_template('openssl_root_ca.tmpl')
|
||||
@@ -148,13 +150,13 @@ def create_openssl_config(verbose=False):
|
||||
with open(root_ca_config,'wt') as file:
|
||||
file.write(config_string)
|
||||
if os.path.isfile(root_ca_config):
|
||||
print('Root CA OpenSSL config file is correctly generated !')
|
||||
Printing.success('Root CA OpenSSL config file is correctly generated !')
|
||||
else:
|
||||
print('Root CA OpenSSL config already exist. Skip.')
|
||||
Printing.warning('Root CA OpenSSL config already exist. Skip.')
|
||||
|
||||
# Generate privkey and cert for Root CA
|
||||
if not os.path.isfile(TisPKI.root_ca_keyfile()) or not os.path.isfile(TisPKI.root_ca_certfile()):
|
||||
print('Generate Root CA private key')
|
||||
Printing.information('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=False, executable='/bin/bash')
|
||||
|
||||
if gen_root_ca.returncode == 0:
|
||||
@@ -163,13 +165,13 @@ def create_openssl_config(verbose=False):
|
||||
Printing.information(f'Root CA Certfile is stored in {TisPKI.root_ca_certfile()}')
|
||||
input("Press Enter to continue...")
|
||||
else:
|
||||
print('Error on generating Root CA private key')
|
||||
Printing.error('Error on generating Root CA private key')
|
||||
os.remove(TisPKI.root_ca_keyfile())
|
||||
retry = input('If you want to retry, press Y')
|
||||
retry = input('If you want to retry, press Y : ')
|
||||
if retry == "y" or retry == 'Y':
|
||||
create_openssl_config()
|
||||
else:
|
||||
print('Root CA private key and certificate already exist. Skip.')
|
||||
Printing.warning('Root CA private key and certificate already exist. Skip.')
|
||||
|
||||
|
||||
def create_openssl_intermediate():
|
||||
|
||||
Reference in New Issue
Block a user