summaryrefslogtreecommitdiffhomepage
path: root/demo_server.py
diff options
context:
space:
mode:
authorRobey Pointer <robey@lag.net>2003-12-30 22:24:21 +0000
committerRobey Pointer <robey@lag.net>2003-12-30 22:24:21 +0000
commitdaa8a2ec0d6d3706ea3864fcab5ed56597f3612a (patch)
tree73b01cd33f631034448bc6b1779fdda4a542794e /demo_server.py
parent48c7d888a22a6810a32f6d25cdd6b561803166cd (diff)
[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-18]
added public-key support to server mode, more docs added public-key support to server mode (it can now verify a client signature) and added a demo of that to the demo_server.py script (user_rsa_key). in the process, cleaned up the API of PKey so that now it only has to know about signing and verifying ssh2 blobs, and can be hashed and compared with other keys (comparing & hashing only the public parts of the key). keys can also be created from strings now too. some more documentation and hiding private methods.
Diffstat (limited to 'demo_server.py')
-rwxr-xr-xdemo_server.py25
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