Skip to content

Commit

Permalink
Factor fingerprint data out of class
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Sep 6, 2014
1 parent 7d72ce5 commit d8047a2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
from paramiko.common import PY2, b


FINGERPRINTS = {
'ssh-dss': '44:78:f0:b9:a2:3c:c5:18:20:09:ff:75:5b:c1:d2:6c',
'ssh-rsa': '60:73:38:44:cb:51:86:65:7f:de:da:a2:2b:5a:57:d5',
'ecdsa-sha2-nistp256': '25:19:eb:55:e6:a1:47:ff:4f:38:d2:75:6f:a5:d5:60',
}

def _fingerprint_to_bytes(fingerprint):
"""
Takes ssh-keygen style fingerprint, returns hex-y bytestring.
Expand All @@ -44,11 +50,6 @@ class NullServer (paramiko.ServerInterface):
def __init__(self, *args, **kwargs):
# Allow tests to enable/disable specific key types
self.__allowed_keys = kwargs.pop('allowed_keys', [])
self.__fingerprints = {
'ssh-dss': '44:78:f0:b9:a2:3c:c5:18:20:09:ff:75:5b:c1:d2:6c',
'ssh-rsa': '60:73:38:44:cb:51:86:65:7f:de:da:a2:2b:5a:57:d5',
'ecdsa-sha2-nistp256': '25:19:eb:55:e6:a1:47:ff:4f:38:d2:75:6f:a5:d5:60',
}
super(NullServer, self).__init__(*args, **kwargs)

def get_allowed_auths(self, username):
Expand All @@ -64,7 +65,7 @@ def check_auth_password(self, username, password):
def check_auth_publickey(self, username, key):
# TODO: honor allowed_keys
try:
expected = self.__fingerprints[key.get_name()]
expected = FINGERPRINTS[key.get_name()]
except KeyError:
return paramiko.AUTH_FAILED
if key.get_fingerprint() == _fingerprint_to_bytes(expected):
Expand Down

0 comments on commit d8047a2

Please sign in to comment.