1 #! /usr/bin/env python3
4 Takes a certificate from the awful, often used form of a single line of text and turns
5 it into a real PEM file.
6 This assumes the input file has one single line of text that needs to be formatted
18 def split_lines(unsplit_line: str) -> None:
20 Takes text as input and breaks it up at the prescribed 64 character boundaries
25 splits = [(unsplit_line[i : i + size]) for i in range(0, len(unsplit_line), size)]
27 #print("splits:", splits)
28 for split_line in splits:
29 if len(split_line) > 0:
37 # make sure they gave us a filename.
41 This script needs a filename to operate on. The file is expected to contain\n\
42 one line of certificate data, which this script will reformat into a standard\n\
43 PEM file format. The PEM file will be output on the console.")
46 filename = sys.argv[1]
48 # make sure the filename is valid.
49 if not os.path.isfile(filename):
50 print("The filename provided does not seem to be a readable file:", filename)
53 file = open(filename, "r")
55 cert_line = file.readline()
56 cert_line = cert_line.strip('\r\n')
58 #ugh, no extra noise needed.
60 #print("below is the properly formatted output sourced from:", filename)
63 print("-----BEGIN CERTIFICATE-----")
64 split_lines(cert_line)
65 print("-----END CERTIFICATE-----")
69 if __name__ == "__main__":