the content of cmd1 is
‘openssl req -nodes -new -out /Users/mk/CA_test/base.domain.csr -config /Users/mk/CA_test/req.base.domain.conf’
the result if the subprocess.run is
CompletedProcess(args=[‘openssl req -nodes -new -out /Users/mk/CA_test/base.domain.csr -config /Users/mk/CA_test/req.base.domain.conf’], returncode=0)
entering the cmd1 at the command line the .key file is created, but not with the subprocess.run
while with the next lines in my code
Rather then use a single string as the command line it’s recommended to use a list of args. This then avoid issues with parsing the string into args, as you made the args explicit. For example:
That is one command openssl with a lot of args if I split them openssl does not accept that. On the other side the next openssl command is much longer and works
The smal test creates a command line that does the same as the subprocess line.
The command line creates the .key file, the subprocess line does not
While the other subprocess lines creates the files.
Appreciate any help
Sorry Guys, it works but not as expected. The .key and .crt Files etc. are created but not where expected in the certificate directory but in the program directory
Have a nice Sunday
Rainer
It was a little bit tricky to find. In the commands I had everywhere the full path, but in one of the generated conf files I forgot to enter the path variable at one entry.
Now everything works.
What it does generated a self signed CA and then to create certificates signed by this CA as much as you want for internal use.
create a CA and a first certificate in less than one minute in GUI
All entries are re checked if valid
Is some one is interested let me know, it will be availabe at GIT soon
by the way I use another solution now. I write the full command to disk, make this file executable and execute it then. Positive is that I can whats really done for debug purpose by displaying the command file.
# create certificate if not exists
def create_certificate ():
# check cert exists
global ca_base_folder
if os.path.exists(f"{ca_base_folder}/{cert_common_name}.crt"): # Cert exists
show_error(data_frame,"!!! CERTIFICATE EXIST WE STOP HERE !!!")
sys.exit()
# conf file for new cert
create_req_base_domain_conf_file()
create_sign_cert_conf_file()
subprocess.run([f"rm {ca_base_folder}/cmd*"], shell=True)
try:
with open(f"{ca_base_folder}/cmd1", 'w') as f1: # try open
f1.write( f"openssl req -nodes -new -out {ca_base_folder}/base.domain.csr -config {ca_base_folder}/req.base.domain.conf\n") # read
f1.close() # close
except IOError as e:
print("An error occurred:", e)
subprocess.run([f"chmod +x {ca_base_folder}/cmd1"], shell=True)
subprocess.run([f"{ca_base_folder}/cmd1"], shell=True)
#
try:
with open(f"{ca_base_folder}/cmd2", 'w') as f2: # try open
f2.write(f"openssl ca -batch -config {ca_base_folder}/sign.cert.conf -extfile {ca_base_folder}/req.base.domain.conf -extensions my_extensions -out {ca_base_folder}/{cert_common_name}.crt -infiles {ca_base_folder}/base.domain.csr\n") # read
f2.close() # close
except IOError as e:
print("An error occurred:", e)
subprocess.run([f"chmod +x {ca_base_folder}/cmd2"], shell=True)
subprocess.run([f"{ca_base_folder}/cmd2"], shell=True)