From c86c4f3949e2cc6db3c09828b9518e27c6c3a304 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Fri, 27 Aug 2004 00:57:40 +0000 Subject: [project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-66] new ServerInterface class, outbound rekey works, etc. a bunch of changes that i'm too lazy to split out into individual patches: * all the server overrides from transport.py have been moved into a separate class ServerInterface, so server code doesn't have to subclass the whole paramiko library * updated demo_server to subclass ServerInterface * when re-keying during a session, block other messages until the new keys are activated (openssh doensn't like any other traffic during a rekey) * re-key when outbound limits are tripped too (was only counting inbound traffic) * don't log scary things on EOF --- demo_server.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'demo_server.py') diff --git a/demo_server.py b/demo_server.py index 5d6cbb5c..8d889963 100755 --- a/demo_server.py +++ b/demo_server.py @@ -15,7 +15,7 @@ host_key.read_private_key_file('demo_dss_key') print 'Read key: ' + paramiko.util.hexify(host_key.get_fingerprint()) -class ServerTransport(paramiko.Transport): +class Server (paramiko.ServerInterface): # 'data' is the output of base64.encodestring(str(key)) data = 'AAAAB3NzaC1yc2EAAAABIwAAAIEAyO4it3fHlmGZWJaGrfeHOVY7RWO3P9M7hpfAu7jJ2d7eothvfeuoRFtJwhUmZDluRdFyhFY/hFAh76PJKGAusIqIQKlkJxMCKDqIexkgHAfID/6mqvmnSJf0b5W8v5h2pI/stOSwTQ+pxVhwJ9ctYDhRSlF0iTUWT10hcuO4Ks8=' good_pub_key = paramiko.RSAKey(data=base64.decodestring(data)) @@ -23,24 +23,24 @@ class ServerTransport(paramiko.Transport): def check_channel_request(self, kind, chanid): if kind == 'session': return ServerChannel(chanid) - return self.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED + return paramiko.Transport.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED def check_auth_password(self, username, password): if (username == 'robey') and (password == 'foo'): - return self.AUTH_SUCCESSFUL - return self.AUTH_FAILED + return paramiko.Transport.AUTH_SUCCESSFUL + return paramiko.Transport.AUTH_FAILED def check_auth_publickey(self, username, key): print 'Auth attempt with key: ' + paramiko.util.hexify(key.get_fingerprint()) if (username == 'robey') and (key == self.good_pub_key): - return self.AUTH_SUCCESSFUL - return self.AUTH_FAILED + return paramiko.Transport.AUTH_SUCCESSFUL + return paramiko.Transport.AUTH_FAILED def get_allowed_auths(self, username): return 'password,publickey' -class ServerChannel(paramiko.Channel): +class ServerChannel (paramiko.Channel): "Channel descendant that pretends to understand pty and shell requests" def __init__(self, chanid): @@ -61,7 +61,6 @@ try: sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(('', 2200)) except Exception, e: - print '*** Bind failed: ' + str(e) traceback.print_exc() sys.exit(1) @@ -79,14 +78,14 @@ print 'Got a connection!' try: event = threading.Event() - t = ServerTransport(client) + t = paramiko.Transport(client) try: t.load_server_moduli() except: print '(Failed to load moduli -- gex will be unsupported.)' raise t.add_server_key(host_key) - t.start_server(event) + t.start_server(event, Server()) while 1: event.wait(0.1) if not t.is_active(): -- cgit v1.2.3