blob: 3fe5438c70010eaa5e1d01e1a5e0c50e475fce40 [file] [log] [blame]
Filip Pytloun3668cd02015-11-18 16:16:32 +01001#!/usr/bin/env python
2
3import base64
4import hashlib
5
6
7def main():
8 host_keys = {
9 'rsa': '/etc/ssh/ssh_host_rsa_key.pub',
10 'dsa': '/etc/ssh/ssh_host_dsa_key.pub',
11 'ecdsa': '/etc/ssh/ssh_host_ecdsa_key.pub',
12 }
13
14 ssh_fingerprints = {}
15 for key_type, filename in host_keys.iteritems():
16 try:
17 ssh_fingerprints[key_type] = _get_ssh_fingerprint(filename)
18 except IOError:
19 pass
20
21 if ssh_fingerprints:
22 return {
23 'ssh_fingerprints': ssh_fingerprints
24 }
25 else:
26 return None
27
28
29def _get_ssh_fingerprint(filename):
30 with open(filename, 'r') as fh:
31 key = base64.b64decode(fh.read().strip().split()[1].encode('ascii'))
32 fp_plain = hashlib.md5(key).hexdigest()
33 return ':'.join(a+b for a, b in zip(fp_plain[::2], fp_plain[1::2]))