diff options
Diffstat (limited to 'demo_server.py')
-rwxr-xr-x | demo_server.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/demo_server.py b/demo_server.py index 7fd25ad3..65b45cf7 100755 --- a/demo_server.py +++ b/demo_server.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import sys, os, socket, threading, logging, traceback +import sys, os, socket, threading, logging, traceback, base64 import paramiko # setup logging @@ -18,10 +18,14 @@ if len(l.handlers) == 0: host_key = paramiko.DSSKey() host_key.read_private_key_file('demo_dss_key') -print 'Read key: ' + paramiko.hexify(host_key.get_fingerprint()) +print 'Read key: ' + paramiko.util.hexify(host_key.get_fingerprint()) class ServerTransport(paramiko.Transport): + # 'data' is the output of base64.encodestring(str(key)) + data = 'AAAAB3NzaC1yc2EAAAABIwAAAIEAyO4it3fHlmGZWJaGrfeHOVY7RWO3P9M7hpfAu7jJ2d7eothvfeuoRFtJwhUmZDluRdFyhFY/hFAh76PJKGAusIqIQKlkJxMCKDqIexkgHAfID/6mqvmnSJf0b5W8v5h2pI/stOSwTQ+pxVhwJ9ctYDhRSlF0iTUWT10hcuO4Ks8=' + good_pub_key = paramiko.RSAKey(data=base64.decodestring(data)) + def check_channel_request(self, kind, chanid): if kind == 'session': return ServerChannel(chanid) @@ -32,6 +36,11 @@ class ServerTransport(paramiko.Transport): return self.AUTH_SUCCESSFUL return self.AUTH_FAILED + def check_auth_publickey(self, username, key): + if (username == 'robey') and (key == self.good_pub_key): + return self.AUTH_SUCCESSFUL + return self.AUTH_FAILED + class ServerChannel(paramiko.Channel): "Channel descendant that pretends to understand pty and shell requests" @@ -79,11 +88,13 @@ try: t.add_server_key(host_key) t.ultra_debug = 0 t.start_server(event) - # print repr(t) - event.wait(10) - if not t.is_active(): - print '*** SSH negotiation failed.' - sys.exit(1) + while 1: + event.wait(0.1) + if not t.is_active(): + print '*** SSH negotiation failed.' + sys.exit(1) + if event.isSet(): + break # print repr(t) # wait for auth |