Created
March 25, 2017 12:37
-
-
Save mkorthof/b597833189d07bd54b82250cbb763965 to your computer and use it in GitHub Desktop.
ssh fingerprints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# http://stackoverflow.com/questions/6682816/deriving-an-ssh-fingerprint-from-a-public-key-in-python | |
import base64 | |
import hashlib | |
def debug(line, field): | |
# try: print ("DEBUG: line.strip(): %s\n" % line.strip()) | |
# except Exception as e: print ("ERROR: line.strip(): %s \n" % e) | |
# try: print ("DEBUG: line.strip().split()[%i]: %s\n" % (field, line.strip().split()[field])) | |
# except Exception as e: print ("ERROR: line.strip().split()[%i] %s\n" % (field, e)) | |
try: print ("DEBUG: line.strip().split()[%i].encode: %s\n" % (field, line.strip().split()[field].encode('ascii'))) | |
except Exception as e: print ("ERROR: line.strip().split()[%i].encode: %s\n" % (field, e)) | |
def fp(line, field, hash): | |
key = base64.b64decode(line.strip().split()[field].encode('ascii')) | |
if hash == "md5": fp_plain = hashlib.md5(key).hexdigest() | |
if hash == "sha256": fp_plain = hashlib.sha256(key).hexdigest() | |
if hash == "sha512": fp_plain = hashlib.sha256(key).hexdigest() | |
return '(' + hash.upper() + ') ' + ':'.join(a+b for a,b in zip(fp_plain[::2], fp_plain[1::2])) + ' ' + line | |
ssh = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqmEmDTNBC6O8HGCdu0MZ9zLCivDsYSttrrmlq87/YsEBpvwUTiF3UEQuFLaq5Gm+dtgxJewg/UwsZrDFxzpQhCHB6VmqrbKN2hEIkk/HJvCnAmR1ehXv8n2BWw3Jlw7Z+VgWwXAH50f2HWYqTaE4qP4Dxc4RlElxgNmlDPGXw/dYBvChYBG/RvIiTz1L+pYzPD4JR54IMmTOwjcGIJl7nk1VjKvl3D8Wgp6qejv4MfZ7Htdc99SUKcKWAeHYsjPXosSk3GlwKiS/sZi51Yca394GE7T4hZu6HTaXeZoD8+IZ7AijYn89H7EPjuu0iCAa/cjVzBsFHGszQYG+U5KfIw== user@host" | |
#debug(ssh, 1) | |
print ("%s\n" % fp(ssh, 1, "md5")) | |
print ("%s\n" % fp(ssh, 1, "sha256")) | |
print ("%s\n" % fp(ssh, 1, "sha512")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment