move another demo script in, and do a bit more cleanup
This commit is contained in:
parent
77eada9fb4
commit
b955ee02cc
|
@ -116,8 +116,9 @@ except Exception, e:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
t = paramiko.Transport(sock)
|
t = paramiko.Transport(sock)
|
||||||
t.start_client()
|
try:
|
||||||
if not t.is_active():
|
t.start_client()
|
||||||
|
except SSHException:
|
||||||
print '*** SSH negotiation failed.'
|
print '*** SSH negotiation failed.'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
# Copyright (C) 2003-2005 Robey Pointer <robey@lag.net>
|
# Copyright (C) 2003-2005 Robey Pointer <robey@lag.net>
|
||||||
#
|
#
|
||||||
|
@ -18,21 +18,32 @@
|
||||||
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
|
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||||
|
|
||||||
import sys, os, socket, threading, traceback, base64
|
import base64
|
||||||
|
import os
|
||||||
|
import socket
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
import traceback
|
||||||
|
|
||||||
import paramiko
|
import paramiko
|
||||||
|
|
||||||
|
|
||||||
# setup logging
|
# setup logging
|
||||||
paramiko.util.log_to_file('demo_server.log')
|
paramiko.util.log_to_file('demo_server.log')
|
||||||
|
|
||||||
#host_key = paramiko.RSAKey(filename='tests/test_rsa.key')
|
host_key = paramiko.RSAKey(filename='test_rsa.key')
|
||||||
host_key = paramiko.DSSKey(filename='tests/test_dss.key')
|
#host_key = paramiko.DSSKey(filename='test_dss.key')
|
||||||
|
|
||||||
print 'Read key: ' + paramiko.util.hexify(host_key.get_fingerprint())
|
print 'Read key: ' + paramiko.util.hexify(host_key.get_fingerprint())
|
||||||
|
|
||||||
|
|
||||||
class Server (paramiko.ServerInterface):
|
class Server (paramiko.ServerInterface):
|
||||||
# 'data' is the output of base64.encodestring(str(key))
|
# 'data' is the output of base64.encodestring(str(key))
|
||||||
data = 'AAAAB3NzaC1yc2EAAAABIwAAAIEAyO4it3fHlmGZWJaGrfeHOVY7RWO3P9M7hpfAu7jJ2d7eothvfeuoRFtJwhUmZDluRdFyhFY/hFAh76PJKGAusIqIQKlkJxMCKDqIexkgHAfID/6mqvmnSJf0b5W8v5h2pI/stOSwTQ+pxVhwJ9ctYDhRSlF0iTUWT10hcuO4Ks8='
|
# (using the "user_rsa_key" files)
|
||||||
|
data = 'AAAAB3NzaC1yc2EAAAABIwAAAIEAyO4it3fHlmGZWJaGrfeHOVY7RWO3P9M7hp' + \
|
||||||
|
'fAu7jJ2d7eothvfeuoRFtJwhUmZDluRdFyhFY/hFAh76PJKGAusIqIQKlkJxMC' + \
|
||||||
|
'KDqIexkgHAfID/6mqvmnSJf0b5W8v5h2pI/stOSwTQ+pxVhwJ9ctYDhRSlF0iT' + \
|
||||||
|
'UWT10hcuO4Ks8='
|
||||||
good_pub_key = paramiko.RSAKey(data=base64.decodestring(data))
|
good_pub_key = paramiko.RSAKey(data=base64.decodestring(data))
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -88,7 +99,6 @@ except Exception, e:
|
||||||
print 'Got a connection!'
|
print 'Got a connection!'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
event = threading.Event()
|
|
||||||
t = paramiko.Transport(client)
|
t = paramiko.Transport(client)
|
||||||
try:
|
try:
|
||||||
t.load_server_moduli()
|
t.load_server_moduli()
|
||||||
|
@ -97,15 +107,11 @@ try:
|
||||||
raise
|
raise
|
||||||
t.add_server_key(host_key)
|
t.add_server_key(host_key)
|
||||||
server = Server()
|
server = Server()
|
||||||
t.start_server(event, server)
|
try:
|
||||||
while 1:
|
t.start_server(server=server)
|
||||||
event.wait(0.1)
|
except SSHException, x:
|
||||||
if not t.is_active():
|
print '*** SSH negotiation failed.'
|
||||||
print '*** SSH negotiation failed.'
|
sys.exit(1)
|
||||||
sys.exit(1)
|
|
||||||
if event.isSet():
|
|
||||||
break
|
|
||||||
# print repr(t)
|
|
||||||
|
|
||||||
# wait for auth
|
# wait for auth
|
||||||
chan = t.accept(20)
|
chan = t.accept(20)
|
||||||
|
@ -113,6 +119,7 @@ try:
|
||||||
print '*** No channel.'
|
print '*** No channel.'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
print 'Authenticated!'
|
print 'Authenticated!'
|
||||||
|
|
||||||
server.event.wait(10)
|
server.event.wait(10)
|
||||||
if not server.event.isSet():
|
if not server.event.isSet():
|
||||||
print '*** Client never asked for a shell.'
|
print '*** Client never asked for a shell.'
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIICWgIBAAKBgQDTj1bqB4WmayWNPB+8jVSYpZYk80Ujvj680pOTh2bORBjbIAyz
|
||||||
|
oWGW+GUjzKxTiiPvVmxFgx5wdsFvF03v34lEVVhMpouqPAYQ15N37K/ir5XY+9m/
|
||||||
|
d8ufMCkjeXsQkKqFbAlQcnWMCRnOoPHS3I4vi6hmnDDeeYTSRvfLbW0fhwIBIwKB
|
||||||
|
gBIiOqZYaoqbeD9OS9z2K9KR2atlTxGxOJPXiP4ESqP3NVScWNwyZ3NXHpyrJLa0
|
||||||
|
EbVtzsQhLn6rF+TzXnOlcipFvjsem3iYzCpuChfGQ6SovTcOjHV9z+hnpXvQ/fon
|
||||||
|
soVRZY65wKnF7IAoUwTmJS9opqgrN6kRgCd3DASAMd1bAkEA96SBVWFt/fJBNJ9H
|
||||||
|
tYnBKZGw0VeHOYmVYbvMSstssn8un+pQpUm9vlG/bp7Oxd/m+b9KWEh2xPfv6zqU
|
||||||
|
avNwHwJBANqzGZa/EpzF4J8pGti7oIAPUIDGMtfIcmqNXVMckrmzQ2vTfqtkEZsA
|
||||||
|
4rE1IERRyiJQx6EJsz21wJmGV9WJQ5kCQQDwkS0uXqVdFzgHO6S++tjmjYcxwr3g
|
||||||
|
H0CoFYSgbddOT6miqRskOQF3DZVkJT3kyuBgU2zKygz52ukQZMqxCb1fAkASvuTv
|
||||||
|
qfpH87Qq5kQhNKdbbwbmd2NxlNabazPijWuphGTdW0VfJdWfklyS2Kr+iqrs/5wV
|
||||||
|
HhathJt636Eg7oIjAkA8ht3MQ+XSl9yIJIS8gVpbPxSw5OMfw0PjVE7tBdQruiSc
|
||||||
|
nvuQES5C9BMHjF39LZiGH1iLQy7FgdHyoP+eodI7
|
||||||
|
-----END RSA PRIVATE KEY-----
|
Loading…
Reference in New Issue