Update of /cvsroot/tmda/tmda/bin
In directory usw-pr-cvs1:/tmp/cvs-serv1905/bin
Modified Files:
ChangeLog tmda-keygen
Log Message:
Add a "batch" (-b) option to output only the CRYPT_KEY line. This
makes it easier to programmatically generate multiple keys.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/bin/ChangeLog,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -r1.71 -r1.72
--- ChangeLog 2001/09/12 23:10:09 1.71
+++ ChangeLog 2001/09/12 23:51:26 1.72
@@ -1,5 +1,8 @@
2001-09-12 Jason R. Mastaler <jasonrm@xxxxxxxxxxxxxxxxxxxxxxxxxx>
+ * tmda-keygen (usage): Add a "batch" (-b) option to output only
+ the CRYPT_KEY line.
+
* tmda-inject (main): Add some error checking. tmda-inject was
failing when the message contained no "From:" header.
Index: tmda-keygen
===================================================================
RCS file: /cvsroot/tmda/tmda/bin/tmda-keygen,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- tmda-keygen 2001/06/06 16:17:55 1.7
+++ tmda-keygen 2001/09/12 23:51:26 1.8
@@ -1,11 +1,48 @@
#!/usr/bin/env python
+"""Generate a unique 160-bit hex key.
+
+Usage: %(program)s [-b] [-h]
+
+Where:
+ -b
+ --batch
+ Output only the CRYPT_KEY line.
+
+ --help
+ -h
+ Print this help message and exit.
+"""
+
+
import commands
+import getopt
import os
import sys
+program = sys.argv[0]
+batch = None
+
+def usage(code, msg=''):
+ print __doc__ % globals()
+ if msg:
+ print msg
+ sys.exit(code)
try:
+ opts, args = getopt.getopt(sys.argv[1:],
+ 'bh', ['batch','help'])
+except getopt.error, msg:
+ usage(1, msg)
+
+for opt, arg in opts:
+ if opt in ('-h', '--help'):
+ usage(0)
+ elif opt in ('-b', '--batch'):
+ batch = 1
+
+
+try:
import paths
except ImportError:
pass
@@ -14,11 +51,10 @@
def keygen():
- """Create and return a unique 160-bit key in hex."""
# Use the kernel's random number generator if available.
if os.path.exists("/dev/urandom"):
key = open("/dev/urandom","rb").read(20)
- # Otherwise generate some pseudo-random data from the command-line
+ # Otherwise generate some pseudo-random data from the system
# and use the SHA of resulting key as the key.
else:
import sha
@@ -41,18 +77,20 @@
key = sha.new(key_data + "key").digest()
return Util.hexlify(key)
-
-print "Generating a unique, 160-bit private key, please wait a moment.."
-print
+if not batch:
+ print "Generating a unique, 160-bit private key, please wait a moment.."
+ print
+
key = keygen()
if len(key) != 40:
print "Oops, generated key is not 40-characters in length, exiting!"
sys.exit()
-
+
print "CRYPT_KEY =", '"' + key + '"'
-print
-print "Now paste this line into your ~/.tmdarc file,"
-print "and make sure to keep your key secret!"
+if not batch:
+ print
+ print "Now paste this line into your ~/.tmdarc file,"
+ print "and make sure to keep your key secret!"
|