sfax509 will run openssl x509 on all parts of a gid
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 13 Jan 2017 11:47:48 +0000 (12:47 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 13 Jan 2017 11:47:48 +0000 (12:47 +0100)
clientbin/sfadump.py
clientbin/sfax509.py [new file with mode: 0755]
debian/sfa-client.install
sfa.spec

index 617635b..d325bdd 100755 (executable)
@@ -1,5 +1,4 @@
 #! /usr/bin/env python
-from __future__ import with_statement
 
 import sys
 import os, os.path
diff --git a/clientbin/sfax509.py b/clientbin/sfax509.py
new file mode 100755 (executable)
index 0000000..0d64808
--- /dev/null
@@ -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()
index ced96ba..26951b5 100644 (file)
@@ -6,3 +6,4 @@ usr/bin/setRecord.py*
 usr/bin/sfascan.py*
 #usr/bin/sfascan
 usr/bin/sfadump.py*
+usr/bin/sfax509.py*
index 047de43..3742f01 100644 (file)
--- a/sfa.spec
+++ b/sfa.spec
@@ -187,6 +187,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_bindir}/sfascan.py*
 %{_bindir}/sfascan
 %{_bindir}/sfadump.py*
+%{_bindir}/sfax509.py*
 
 %files plc
 %defattr(-,root,root)