Added flat certificates output

This commit is contained in:
Daniel Huisman 2017-06-27 15:56:54 +02:00
parent 6aa38b7a93
commit 0f77fa2960
3 changed files with 33 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
certs/ certs/
certs_flat/
data/ data/
# Python ignores # Python ignores

View File

@ -34,4 +34,11 @@ certs/
chain.pem chain.pem
fullchain.pem fullchain.pem
privkey.pem privkey.pem
certs_flat/
example.com.crt
example.com.key
example.com.chain.pem
sub.example.nl.crt
sub.example.nl.key
sub.example.nl.chain.pem
``` ```

View File

@ -53,18 +53,42 @@ class Handler(FileSystemEventHandler):
with open(directory + 'fullchain.pem', 'w') as f: with open(directory + 'fullchain.pem', 'w') as f:
f.write(fullchain) f.write(fullchain)
# Write private key, certificate and chain to flat files
directory = 'certs_flat/'
with open(directory + c['Certificate']['Domain'] + '.key', 'w') as f:
f.write(privatekey)
with open(directory + c['Certificate']['Domain'] + '.crt', 'w') as f:
f.write(fullchain)
with open(directory + c['Certificate']['Domain'] + '.chain.pem', 'w') as f:
f.write(chain)
if c['Domains']['SANs']:
for name in c['Domains']['SANs']:
with open(directory + name + '.key', 'w') as f:
f.write(privatekey)
with open(directory + name + '.crt', 'w') as f:
f.write(fullchain)
with open(directory + name + '.chain.pem', 'w') as f:
f.write(chain)
print('Extracted certificate for: ' + c['Domains']['Main'] + (', ' + ', '.join(c['Domains']['SANs']) if c['Domains']['SANs'] else '')) print('Extracted certificate for: ' + c['Domains']['Main'] + (', ' + ', '.join(c['Domains']['SANs']) if c['Domains']['SANs'] else ''))
if __name__ == "__main__": if __name__ == "__main__":
# Determine path to watch # Determine path to watch
path = sys.argv[1] if len(sys.argv) > 1 else './data' path = sys.argv[1] if len(sys.argv) > 1 else './data'
# Create output directory if it doesn't exist # Create output directories if it doesn't exist
try: try:
os.makedirs('certs') os.makedirs('certs')
except OSError as error: except OSError as error:
if error.errno != errno.EEXIST: if error.errno != errno.EEXIST:
raise raise
try:
os.makedirs('certs_flat')
except OSError as error:
if error.errno != errno.EEXIST:
raise
# Create event handler and observer # Create event handler and observer
event_handler = Handler() event_handler = Handler()