1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-22 14:39:24 -05:00

kh2reg.py: remove accidental hard tabs.

This commit is contained in:
Jacob Nevins 2016-03-22 00:43:30 +00:00
parent 7332d0567e
commit a5588cd635

View File

@ -50,7 +50,7 @@ def longtohex(n):
def warn(s): def warn(s):
"Warning with file/line number" "Warning with file/line number"
sys.stderr.write("%s:%d: %s\n" sys.stderr.write("%s:%d: %s\n"
% (fileinput.filename(), fileinput.filelineno(), s)) % (fileinput.filename(), fileinput.filelineno(), s))
output_type = 'windows' output_type = 'windows'
@ -78,7 +78,7 @@ class UnknownKeyType(Exception):
class KeyFormatError(Exception): class KeyFormatError(Exception):
def __init__(self, msg): def __init__(self, msg):
self.msg = msg self.msg = msg
# Now process all known_hosts input. # Now process all known_hosts input.
for line in fileinput.input(args): for line in fileinput.input(args):
@ -128,54 +128,54 @@ for line in fileinput.input(args):
blob = blob [struct.calcsize(sizefmt) + size : ] blob = blob [struct.calcsize(sizefmt) + size : ]
# The first field is keytype again. # The first field is keytype again.
if subfields[0] != sshkeytype: if subfields[0] != sshkeytype:
raise KeyFormatError(""" raise KeyFormatError("""
outer and embedded key types do not match: '%s', '%s' outer and embedded key types do not match: '%s', '%s'
""" % (sshkeytype, subfields[1])) """ % (sshkeytype, subfields[1]))
# Translate key type string into something PuTTY can use, and # Translate key type string into something PuTTY can use, and
# munge the rest of the data. # munge the rest of the data.
if sshkeytype == "ssh-rsa": if sshkeytype == "ssh-rsa":
keytype = "rsa2" keytype = "rsa2"
# The rest of the subfields we can treat as an opaque list # The rest of the subfields we can treat as an opaque list
# of bignums (same numbers and order as stored by PuTTY). # of bignums (same numbers and order as stored by PuTTY).
keyparams = map (strtolong, subfields[1:]) keyparams = map (strtolong, subfields[1:])
elif sshkeytype == "ssh-dss": elif sshkeytype == "ssh-dss":
keytype = "dss" keytype = "dss"
# Same again. # Same again.
keyparams = map (strtolong, subfields[1:]) keyparams = map (strtolong, subfields[1:])
elif sshkeytype == "ecdsa-sha2-nistp256" \ elif sshkeytype == "ecdsa-sha2-nistp256" \
or sshkeytype == "ecdsa-sha2-nistp384" \ or sshkeytype == "ecdsa-sha2-nistp384" \
or sshkeytype == "ecdsa-sha2-nistp521": or sshkeytype == "ecdsa-sha2-nistp521":
keytype = sshkeytype keytype = sshkeytype
# Have to parse this a bit. # Have to parse this a bit.
if len(subfields) > 3: if len(subfields) > 3:
raise KeyFormatError("too many subfields in blob") raise KeyFormatError("too many subfields in blob")
(curvename, Q) = subfields[1:] (curvename, Q) = subfields[1:]
# First is yet another copy of the key name. # First is yet another copy of the key name.
if not re.match("ecdsa-sha2-" + re.escape(curvename), if not re.match("ecdsa-sha2-" + re.escape(curvename),
sshkeytype): sshkeytype):
raise KeyFormatError("key type mismatch ('%s' vs '%s')" raise KeyFormatError("key type mismatch ('%s' vs '%s')"
% (sshkeytype, curvename)) % (sshkeytype, curvename))
# Second contains key material X and Y (hopefully). # Second contains key material X and Y (hopefully).
# First a magic octet indicating point compression. # First a magic octet indicating point compression.
if struct.unpack("B", Q[0])[0] != 4: if struct.unpack("B", Q[0])[0] != 4:
# No-one seems to use this. # No-one seems to use this.
raise KeyFormatError("can't convert point-compressed ECDSA") raise KeyFormatError("can't convert point-compressed ECDSA")
# Then two equal-length bignums (X and Y). # Then two equal-length bignums (X and Y).
bnlen = len(Q)-1 bnlen = len(Q)-1
if (bnlen % 1) != 0: if (bnlen % 1) != 0:
raise KeyFormatError("odd-length X+Y") raise KeyFormatError("odd-length X+Y")
bnlen = bnlen / 2 bnlen = bnlen / 2
(x,y) = Q[1:bnlen+1], Q[bnlen+1:2*bnlen+1] (x,y) = Q[1:bnlen+1], Q[bnlen+1:2*bnlen+1]
keyparams = [curvename] + map (strtolong, [x,y]) keyparams = [curvename] + map (strtolong, [x,y])
elif sshkeytype == "ssh-ed25519": elif sshkeytype == "ssh-ed25519":
# FIXME: these are always stored point-compressed, which # FIXME: these are always stored point-compressed, which
# requires actual maths # requires actual maths
raise KeyFormatError("can't convert ssh-ed25519 yet, sorry") raise KeyFormatError("can't convert ssh-ed25519 yet, sorry")
else: else:
raise UnknownKeyType(sshkeytype) raise UnknownKeyType(sshkeytype)
@ -183,10 +183,10 @@ for line in fileinput.input(args):
# Now print out one line per host pattern, discarding wildcards. # Now print out one line per host pattern, discarding wildcards.
for host in string.split (hostpat, ','): for host in string.split (hostpat, ','):
if re.search (r"[*?!]", host): if re.search (r"[*?!]", host):
warn("skipping wildcard host pattern '%s'" % host) warn("skipping wildcard host pattern '%s'" % host)
continue continue
elif re.match (r"\|", host): elif re.match (r"\|", host):
warn("skipping hashed hostname '%s'" % host) warn("skipping hashed hostname '%s'" % host)
continue continue
else: else:
m = re.match (r"\[([^]]*)\]:(\d*)$", host) m = re.match (r"\[([^]]*)\]:(\d*)$", host)
@ -198,11 +198,11 @@ for line in fileinput.input(args):
# Slightly bizarre output key format: 'type@port:hostname' # Slightly bizarre output key format: 'type@port:hostname'
# XXX: does PuTTY do anything useful with literal IP[v4]s? # XXX: does PuTTY do anything useful with literal IP[v4]s?
key = keytype + ("@%d:%s" % (port, host)) key = keytype + ("@%d:%s" % (port, host))
# Most of these are numbers, but there's the occasional # Most of these are numbers, but there's the occasional
# string that needs passing through # string that needs passing through
value = string.join (map ( value = string.join (map (
lambda x: x if isinstance(x, basestring) else longtohex(x), lambda x: x if isinstance(x, basestring) else longtohex(x),
keyparams), ',') keyparams), ',')
if output_type == 'unix': if output_type == 'unix':
# Unix format. # Unix format.
sys.stdout.write('%s %s\n' % (key, value)) sys.stdout.write('%s %s\n' % (key, value))
@ -213,8 +213,8 @@ for line in fileinput.input(args):
% (winmungestr(key), value)) % (winmungestr(key), value))
except UnknownKeyType, k: except UnknownKeyType, k:
warn("unknown SSH key type '%s', skipping" % k.keytype) warn("unknown SSH key type '%s', skipping" % k.keytype)
except KeyFormatError, k: except KeyFormatError, k:
warn("trouble parsing key (%s), skipping" % k.msg) warn("trouble parsing key (%s), skipping" % k.msg)
except BlankInputLine: except BlankInputLine:
pass pass