X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=blobdiff_plain;f=clientbin%2Fsfax509.py;fp=clientbin%2Fsfax509.py;h=0d648085e75db91864770676fc86ec0d4fce7138;hp=0000000000000000000000000000000000000000;hb=6d176c5d65b0efca03780170adab849152986b92;hpb=f857533f5e3535599eb4b74b8ac214e50370a542 diff --git a/clientbin/sfax509.py b/clientbin/sfax509.py new file mode 100755 index 00000000..0d648085 --- /dev/null +++ b/clientbin/sfax509.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python + +from __future__ import print_function + +# something like openssl x509 +# but when used on a gid file we show all the parts + +import os +import argparse + +begin = "-----BEGIN CERTIFICATE-----\n" +end = "-----END CERTIFICATE-----" + +default_openssl_options = "-noout -text" + +tmpfilename = "/tmp/sfax509.pem" + +def openssl_x509_string(string, openssl_options): + + if not string.startswith(begin): + string = begin + string + if not string.endswith(end): + string = string + end + with open(tmpfilename, "w") as f: + f.write(string) + + command = "openssl x509 -in {} {}".format(tmpfilename, openssl_options) + os.system(command) + +# typically on .gids +def openssl_x509_gid(filename, openssl_options): + with open(filename) as f: + pem = f.read() + + # remove begins altogether + pem = pem.replace(begin, "") + # split along end - last item in list is '\n' + parts = pem.split(end)[:-1] + + for part in parts: + print("==============================") + openssl_x509_string(part, openssl_options) + + +example = 'sfax509.py -x "-noout -dates" foo.gid' + +def main(): + parser = argparse.ArgumentParser(usage="example: {}".format(example)) + parser.add_argument("gids", nargs='+') + parser.add_argument("-x", "--openssl-option", action='store', + default=default_openssl_options, dest='openssl_options', + help = "options passed to openssl x509 instead of {}" + .format(default_openssl_options)) + args = parser.parse_args() + + for gid in args.gids: + openssl_x509_gid(gid, openssl_options=args.openssl_options) + +if __name__ == '__main__': + main()