From 7ec5099b5f5c79419a54a6cdedea618d98b60569 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 5 Nov 2003 10:44:19 +0000 Subject: Commit initial version git-svn-id: file:///home/lennart/svn/public/seppl/trunk@2 91a2fd9b-5dcb-0310-a70a-d71e310228e6 --- utils/seppl-gen-key | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100755 utils/seppl-gen-key (limited to 'utils/seppl-gen-key') diff --git a/utils/seppl-gen-key b/utils/seppl-gen-key new file mode 100755 index 0000000..cc5817e --- /dev/null +++ b/utils/seppl-gen-key @@ -0,0 +1,110 @@ +#!/usr/bin/python + +# $Id: Makefile.am 40 2003-10-27 18:32:45Z lennart $ +# +# 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 "" + + f(a, name, key) + + if f == dump_key_xml: + print "" + + 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() + + + -- cgit