X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=contrib%2Fkh2reg.py;h=503dd6e34fc291640d56d9050de5c5f18c8826b6;hb=ced3a46c3f993e6257ec25337395d0c6bf6dbf59;hp=c6752eb3fee47e7159cba9b079b65239cbf6315b;hpb=a90f643907c7a98dd72e74952bc64454cfb39259;p=PuTTY.git diff --git a/contrib/kh2reg.py b/contrib/kh2reg.py index c6752eb3..503dd6e3 100755 --- a/contrib/kh2reg.py +++ b/contrib/kh2reg.py @@ -1,12 +1,11 @@ #! /usr/bin/env python -# $Id: kh2reg.py,v 1.2 2003/10/14 23:23:28 jacob Exp $ # Convert OpenSSH known_hosts and known_hosts2 files to "new format" PuTTY # host keys. # usage: -# kh2reg.py [ -win ] known_hosts1 2 3 4 ... > hosts.reg +# kh2reg.py [ --win ] known_hosts1 2 3 4 ... > hosts.reg # Creates a Windows .REG file (double-click to install). -# kh2reg.py -unix known_hosts1 2 3 4 ... > sshhostkeys +# kh2reg.py --unix known_hosts1 2 3 4 ... > sshhostkeys # Creates data suitable for storing in ~/.putty/sshhostkeys (Unix). # Line endings are someone else's problem as is traditional. # Developed for Python 1.5.2. @@ -87,7 +86,7 @@ for line in fileinput.input(args): # is second field entirely decimal digits? if re.match (r"\d*$", fields[1]): - # Treat as SSH1-type host key. + # Treat as SSH-1-type host key. # Format: hostpat bits10 exp10 mod10 comment... # (PuTTY doesn't store the number of bits.) magicnumbers = map (long, fields[2:4]) @@ -95,7 +94,7 @@ for line in fileinput.input(args): else: - # Treat as SSH2-type host key. + # Treat as SSH-2-type host key. # Format: hostpat keytype keyblob64 comment... sshkeytype, blob = fields[1], base64.decodestring (fields[2]) @@ -128,10 +127,17 @@ for line in fileinput.input(args): sys.stderr.write("Skipping wildcard host pattern '%s'\n" % host) continue + elif re.match (r"\|", host): + sys.stderr.write("Skipping hashed hostname '%s'\n" % host) + continue else: - # Slightly bizarre key format: 'type@port:hostname' - # As far as I know, the input never specifies a port. - port = 22 + m = re.match (r"\[([^]]*)\]:(\d*)$", host) + if m: + (host, port) = m.group(1,2) + port = int(port) + else: + port = 22 + # Slightly bizarre output key format: 'type@port:hostname' # XXX: does PuTTY do anything useful with literal IP[v4]s? key = keytype + ("@%d:%s" % (port, host)) value = string.join (map (longtohex, magicnumbers), ',')