5 # something like openssl x509
6 # but when used on a gid file we show all the parts
11 begin = "-----BEGIN CERTIFICATE-----\n"
12 end = "-----END CERTIFICATE-----"
14 default_openssl_options = "-noout -text"
16 tmpfilename = "/tmp/sfax509.pem"
18 def openssl_x509_string(string, openssl_options):
20 if not string.startswith(begin):
21 string = begin + string
22 if not string.endswith(end):
24 with open(tmpfilename, "w") as f:
27 command = "openssl x509 -in {} {}".format(tmpfilename, openssl_options)
31 def openssl_x509_gid(filename, openssl_options):
32 with open(filename) as f:
35 # remove begins altogether
36 pem = pem.replace(begin, "")
37 # split along end - last item in list is '\n'
38 parts = pem.split(end)[:-1]
41 print("==============================")
42 openssl_x509_string(part, openssl_options)
45 example = 'sfax509.py -x "-noout -dates" foo.gid'
48 parser = argparse.ArgumentParser(usage="example: {}".format(example))
49 parser.add_argument("gids", nargs='+')
50 parser.add_argument("-x", "--openssl-option", action='store',
51 default=default_openssl_options, dest='openssl_options',
52 help = "options passed to openssl x509 instead of {}"
53 .format(default_openssl_options))
54 args = parser.parse_args()
57 openssl_x509_gid(gid, openssl_options=args.openssl_options)
59 if __name__ == '__main__':