Skip to content

Instantly share code, notes, and snippets.

@thannaske
Created November 14, 2016 21:27
Show Gist options
  • Save thannaske/b5ac831f7048ee0ab08882dcd1fd41cc to your computer and use it in GitHub Desktop.
Save thannaske/b5ac831f7048ee0ab08882dcd1fd41cc to your computer and use it in GitHub Desktop.
Combine Let's Encrypt certificate files to a fully combined PEM certificate that is compatible with LiveConfig
import argparse
parser = argparse.ArgumentParser(description='Combines Let\'s Encrypt certificate to a fully PEM certificate file to use with LiveConfig.')
parser.add_argument('private_key', action='store', help='Path to private key file')
parser.add_argument('full_chain', action='store', help='Path to full chain certificate file')
parser.add_argument('output', action='store', help='Output file for combined PEM certificate')
args = parser.parse_args()
try:
a = open(args.private_key)
except Exception as e:
print("Error: Could not read private key file. Does the file exist and do you have sufficient rights to read from this file?")
exit(1)
try:
b = open(args.full_chain)
except Exception as e:
print("Error: Could not read full chain certificate file. Does the file exist and do you have sufficient rights to read from this file?")
exit(1)
try:
c = open(args.output, "w")
except Exception as e:
print("Error: Could not create output file. Do you have sufficient rights to write in target directory?")
exit(1)
try:
private_key = a.read()
full_chain = b.read()
except Exception as e:
print("Error: Could not read private key or full chain certificate file. Are the files existant and readable?")
exit(1)
combined = private_key + full_chain
try:
c.write(combined)
except Exception as e:
print("Error: Could not write into output file. Do you have sufficient rights to write into target file?")
exit(1)
print("Successfully wrote combined PEM certificate file.")
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment