summaryrefslogtreecommitdiffstats
path: root/utils-python/seppl-gen-key
diff options
context:
space:
mode:
Diffstat (limited to 'utils-python/seppl-gen-key')
-rwxr-xr-xutils-python/seppl-gen-key110
1 files changed, 110 insertions, 0 deletions
diff --git a/utils-python/seppl-gen-key b/utils-python/seppl-gen-key
new file mode 100755
index 0000000..1690bb1
--- /dev/null
+++ b/utils-python/seppl-gen-key
@@ -0,0 +1,110 @@
+#!/usr/bin/python
+
+# $Id$
+#
+# This file is part of seppl.
+#
+# seppl is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# seppl is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with seppl; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+from seppl_common import *
+import getopt, sys
+
+def genkey(a, name, f):
+
+ n, b = find_alg_by_number(a)
+
+ if b == 0:
+ return -1
+
+ fd = open("/dev/random", "r+")
+ key = fd.read(b/8)
+ fd.close()
+
+ if (len(key) != b/8):
+ sys.stderr("ERROR: Cannot generate randomness.\n")
+ return
+
+ if f == dump_key_xml:
+ print "<seppl-keyring>"
+
+ f(a, name, key)
+
+ if f == dump_key_xml:
+ print "</seppl-keyring>"
+
+ return 0
+
+algorithm = "aes"
+bits = 128
+name = "def"
+func = dump_key_xml
+
+def usage():
+ global algorithm, bits, name, func
+ x = { dump_key_xml : "disable", dump_key_bin : "enable" }
+
+ print "%s:" % sys.argv[0]
+ print " -h --help Show this help"
+ print " -x --no-xml No xml output (%s)" % x[func]
+ print " -a --algorithm ALGORITHM Specify algorithm (%s)" % algorithm
+ print " -b --bits BITS Specify key length (%s)" % bits
+ print " -n --name NAME Specify key name (%s)" % name
+
+
+def main():
+ global algorithm, bits, name, func
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "hxa:b:n:", ["help", "no-xml", "algorithm=", "bits=", "name="])
+ except getopt.GetoptError:
+ usage()
+ sys.exit(1)
+
+ u = 0;
+
+ for o, a in opts:
+ if o in ("-h", "--help"):
+ u = 1
+
+ if o in ("-x", "--no-xml"):
+ func = dump_key_bin
+
+ if o in ("-a", "--algorithm"):
+ algorithm = a
+
+ if o in ("-b", "--bits"):
+ bits = int(a)
+
+ if o in ("-n", "--name"):
+ name = a[:7]
+
+ if u:
+ usage()
+ sys.exit(0)
+
+
+ a = find_alg_by_name(algorithm, bits)
+
+ if a == -1:
+ sys.stderr.write("ERROR: Cipher not available\n")
+ sys.exit(2)
+
+ genkey(a, name, func)
+
+if __name__ == "__main__":
+ main()
+
+
+