Compare commits
16 Commits
master
...
python3-su
Author | SHA1 | Date |
---|---|---|
Dorian | bec140c933 | |
Dorian | 3cb91a0e9e | |
Dorian | 9ffd9efb20 | |
Dorian | 3c33c763a7 | |
Dorian | 387f243c1d | |
Dorian | 2c538bd5fe | |
Dorian | 5a9fc81ad9 | |
Dorian | cc2dd9c0f4 | |
Dorian | 1022eec17a | |
Dorian | b94fce4df9 | |
Dorian | b2f74c1291 | |
Dorian | a77054d632 | |
Dorian | 3bad2a13be | |
Dorian | 86fe372a2c | |
Dorian | b1e235d820 | |
Dorian | 0847ac780b |
|
@ -5,3 +5,4 @@ dist/
|
||||||
paramiko.egg-info/
|
paramiko.egg-info/
|
||||||
test.log
|
test.log
|
||||||
docs/
|
docs/
|
||||||
|
.idea/
|
|
@ -18,6 +18,7 @@
|
||||||
# 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.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
@ -32,6 +33,11 @@ import traceback
|
||||||
import paramiko
|
import paramiko
|
||||||
import interactive
|
import interactive
|
||||||
|
|
||||||
|
try:
|
||||||
|
input = raw_input
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def agent_auth(transport, username):
|
def agent_auth(transport, username):
|
||||||
"""
|
"""
|
||||||
|
@ -45,24 +51,24 @@ def agent_auth(transport, username):
|
||||||
return
|
return
|
||||||
|
|
||||||
for key in agent_keys:
|
for key in agent_keys:
|
||||||
print 'Trying ssh-agent key %s' % hexlify(key.get_fingerprint()),
|
print('Trying ssh-agent key %s' % hexlify(key.get_fingerprint()), end=' ')
|
||||||
try:
|
try:
|
||||||
transport.auth_publickey(username, key)
|
transport.auth_publickey(username, key)
|
||||||
print '... success!'
|
print('... success!')
|
||||||
return
|
return
|
||||||
except paramiko.SSHException:
|
except paramiko.SSHException:
|
||||||
print '... nope.'
|
print('... nope.')
|
||||||
|
|
||||||
|
|
||||||
def manual_auth(username, hostname):
|
def manual_auth(username, hostname):
|
||||||
default_auth = 'p'
|
default_auth = 'p'
|
||||||
auth = raw_input('Auth by (p)assword, (r)sa key, or (d)ss key? [%s] ' % default_auth)
|
auth = input('Auth by (p)assword, (r)sa key, or (d)ss key? [%s] ' % default_auth)
|
||||||
if len(auth) == 0:
|
if len(auth) == 0:
|
||||||
auth = default_auth
|
auth = default_auth
|
||||||
|
|
||||||
if auth == 'r':
|
if auth == 'r':
|
||||||
default_path = os.path.join(os.environ['HOME'], '.ssh', 'id_rsa')
|
default_path = os.path.join(os.environ['HOME'], '.ssh', 'id_rsa')
|
||||||
path = raw_input('RSA key [%s]: ' % default_path)
|
path = input('RSA key [%s]: ' % default_path)
|
||||||
if len(path) == 0:
|
if len(path) == 0:
|
||||||
path = default_path
|
path = default_path
|
||||||
try:
|
try:
|
||||||
|
@ -73,7 +79,7 @@ def manual_auth(username, hostname):
|
||||||
t.auth_publickey(username, key)
|
t.auth_publickey(username, key)
|
||||||
elif auth == 'd':
|
elif auth == 'd':
|
||||||
default_path = os.path.join(os.environ['HOME'], '.ssh', 'id_dsa')
|
default_path = os.path.join(os.environ['HOME'], '.ssh', 'id_dsa')
|
||||||
path = raw_input('DSS key [%s]: ' % default_path)
|
path = input('DSS key [%s]: ' % default_path)
|
||||||
if len(path) == 0:
|
if len(path) == 0:
|
||||||
path = default_path
|
path = default_path
|
||||||
try:
|
try:
|
||||||
|
@ -96,9 +102,9 @@ if len(sys.argv) > 1:
|
||||||
if hostname.find('@') >= 0:
|
if hostname.find('@') >= 0:
|
||||||
username, hostname = hostname.split('@')
|
username, hostname = hostname.split('@')
|
||||||
else:
|
else:
|
||||||
hostname = raw_input('Hostname: ')
|
hostname = input('Hostname: ')
|
||||||
if len(hostname) == 0:
|
if len(hostname) == 0:
|
||||||
print '*** Hostname required.'
|
print('*** Hostname required.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
port = 22
|
port = 22
|
||||||
if hostname.find(':') >= 0:
|
if hostname.find(':') >= 0:
|
||||||
|
@ -109,8 +115,8 @@ if hostname.find(':') >= 0:
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.connect((hostname, port))
|
sock.connect((hostname, port))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print '*** Connect failed: ' + str(e)
|
print('*** Connect failed: ' + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -119,7 +125,7 @@ try:
|
||||||
try:
|
try:
|
||||||
t.start_client()
|
t.start_client()
|
||||||
except paramiko.SSHException:
|
except paramiko.SSHException:
|
||||||
print '*** SSH negotiation failed.'
|
print('*** SSH negotiation failed.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -128,25 +134,25 @@ try:
|
||||||
try:
|
try:
|
||||||
keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
|
keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
|
||||||
except IOError:
|
except IOError:
|
||||||
print '*** Unable to open host keys file'
|
print('*** Unable to open host keys file')
|
||||||
keys = {}
|
keys = {}
|
||||||
|
|
||||||
# check server's host key -- this is important.
|
# check server's host key -- this is important.
|
||||||
key = t.get_remote_server_key()
|
key = t.get_remote_server_key()
|
||||||
if not keys.has_key(hostname):
|
if not keys.has_key(hostname):
|
||||||
print '*** WARNING: Unknown host key!'
|
print('*** WARNING: Unknown host key!')
|
||||||
elif not keys[hostname].has_key(key.get_name()):
|
elif not keys[hostname].has_key(key.get_name()):
|
||||||
print '*** WARNING: Unknown host key!'
|
print('*** WARNING: Unknown host key!')
|
||||||
elif keys[hostname][key.get_name()] != key:
|
elif keys[hostname][key.get_name()] != key:
|
||||||
print '*** WARNING: Host key has changed!!!'
|
print('*** WARNING: Host key has changed!!!')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print '*** Host key OK.'
|
print('*** Host key OK.')
|
||||||
|
|
||||||
# get username
|
# get username
|
||||||
if username == '':
|
if username == '':
|
||||||
default_username = getpass.getuser()
|
default_username = getpass.getuser()
|
||||||
username = raw_input('Username [%s]: ' % default_username)
|
username = input('Username [%s]: ' % default_username)
|
||||||
if len(username) == 0:
|
if len(username) == 0:
|
||||||
username = default_username
|
username = default_username
|
||||||
|
|
||||||
|
@ -154,21 +160,21 @@ try:
|
||||||
if not t.is_authenticated():
|
if not t.is_authenticated():
|
||||||
manual_auth(username, hostname)
|
manual_auth(username, hostname)
|
||||||
if not t.is_authenticated():
|
if not t.is_authenticated():
|
||||||
print '*** Authentication failed. :('
|
print('*** Authentication failed. :(')
|
||||||
t.close()
|
t.close()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
chan = t.open_session()
|
chan = t.open_session()
|
||||||
chan.get_pty()
|
chan.get_pty()
|
||||||
chan.invoke_shell()
|
chan.invoke_shell()
|
||||||
print '*** Here we go!'
|
print('*** Here we go!')
|
||||||
print
|
print()
|
||||||
interactive.interactive_shell(chan)
|
interactive.interactive_shell(chan)
|
||||||
chan.close()
|
chan.close()
|
||||||
t.close()
|
t.close()
|
||||||
|
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print '*** Caught exception: ' + str(e.__class__) + ': ' + str(e)
|
print('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
try:
|
||||||
t.close()
|
t.close()
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# 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.
|
||||||
from __future__ import with_statement
|
|
||||||
|
from __future__ import print_function, with_statement
|
||||||
|
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
|
@ -47,16 +48,16 @@ key_dispatch_table = {
|
||||||
def progress(arg=None):
|
def progress(arg=None):
|
||||||
|
|
||||||
if not arg:
|
if not arg:
|
||||||
print '0%\x08\x08\x08',
|
print('0%\x08\x08\x08', end=' ')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
elif arg[0] == 'p':
|
elif arg[0] == 'p':
|
||||||
print '25%\x08\x08\x08\x08',
|
print('25%\x08\x08\x08\x08', end=' ')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
elif arg[0] == 'h':
|
elif arg[0] == 'h':
|
||||||
print '50%\x08\x08\x08\x08',
|
print('50%\x08\x08\x08\x08', end=' ')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
elif arg[0] == 'x':
|
elif arg[0] == 'x':
|
||||||
print '75%\x08\x08\x08\x08',
|
print('75%\x08\x08\x08\x08', end=' ')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -121,7 +122,7 @@ if __name__ == '__main__':
|
||||||
f.write(" %s" % comment)
|
f.write(" %s" % comment)
|
||||||
|
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print "done."
|
print("done.")
|
||||||
|
|
||||||
hash = hexlify(pub.get_fingerprint())
|
hash = hexlify(pub.get_fingerprint())
|
||||||
print "Fingerprint: %d %s %s.pub (%s)" % (bits, ":".join([ hash[i:2+i] for i in range(0, len(hash), 2)]), filename, string.upper(ktype))
|
print("Fingerprint: %d %s %s.pub (%s)" % (bits, ":".join([ hash[i:2 + i] for i in range(0, len(hash), 2)]), filename, string.upper(ktype)))
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
# 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.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
import os
|
import os
|
||||||
|
@ -35,7 +37,7 @@ paramiko.util.log_to_file('demo_server.log')
|
||||||
host_key = paramiko.RSAKey(filename='test_rsa.key')
|
host_key = paramiko.RSAKey(filename='test_rsa.key')
|
||||||
#host_key = paramiko.DSSKey(filename='test_dss.key')
|
#host_key = paramiko.DSSKey(filename='test_dss.key')
|
||||||
|
|
||||||
print 'Read key: ' + hexlify(host_key.get_fingerprint())
|
print('Read key: ' + hexlify(host_key.get_fingerprint()))
|
||||||
|
|
||||||
|
|
||||||
class Server (paramiko.ServerInterface):
|
class Server (paramiko.ServerInterface):
|
||||||
|
@ -61,7 +63,7 @@ class Server (paramiko.ServerInterface):
|
||||||
return paramiko.AUTH_FAILED
|
return paramiko.AUTH_FAILED
|
||||||
|
|
||||||
def check_auth_publickey(self, username, key):
|
def check_auth_publickey(self, username, key):
|
||||||
print 'Auth attempt with key: ' + hexlify(key.get_fingerprint())
|
print('Auth attempt with key: ' + hexlify(key.get_fingerprint()))
|
||||||
if (username == 'robey') and (key == self.good_pub_key):
|
if (username == 'robey') and (key == self.good_pub_key):
|
||||||
return paramiko.AUTH_SUCCESSFUL
|
return paramiko.AUTH_SUCCESSFUL
|
||||||
return paramiko.AUTH_FAILED
|
return paramiko.AUTH_FAILED
|
||||||
|
@ -83,47 +85,47 @@ try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
sock.bind(('', 2200))
|
sock.bind(('', 2200))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print '*** Bind failed: ' + str(e)
|
print('*** Bind failed: ' + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sock.listen(100)
|
sock.listen(100)
|
||||||
print 'Listening for connection ...'
|
print('Listening for connection ...')
|
||||||
client, addr = sock.accept()
|
client, addr = sock.accept()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print '*** Listen/accept failed: ' + str(e)
|
print('*** Listen/accept failed: ' + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print 'Got a connection!'
|
print('Got a connection!')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
t = paramiko.Transport(client)
|
t = paramiko.Transport(client)
|
||||||
try:
|
try:
|
||||||
t.load_server_moduli()
|
t.load_server_moduli()
|
||||||
except:
|
except:
|
||||||
print '(Failed to load moduli -- gex will be unsupported.)'
|
print('(Failed to load moduli -- gex will be unsupported.)')
|
||||||
raise
|
raise
|
||||||
t.add_server_key(host_key)
|
t.add_server_key(host_key)
|
||||||
server = Server()
|
server = Server()
|
||||||
try:
|
try:
|
||||||
t.start_server(server=server)
|
t.start_server(server=server)
|
||||||
except paramiko.SSHException, x:
|
except paramiko.SSHException as x:
|
||||||
print '*** SSH negotiation failed.'
|
print('*** SSH negotiation failed.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# wait for auth
|
# wait for auth
|
||||||
chan = t.accept(20)
|
chan = t.accept(20)
|
||||||
if chan is None:
|
if chan is None:
|
||||||
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.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
chan.send('\r\n\r\nWelcome to my dorky little BBS!\r\n\r\n')
|
chan.send('\r\n\r\nWelcome to my dorky little BBS!\r\n\r\n')
|
||||||
|
@ -135,8 +137,8 @@ try:
|
||||||
chan.send('\r\nI don\'t like you, ' + username + '.\r\n')
|
chan.send('\r\nI don\'t like you, ' + username + '.\r\n')
|
||||||
chan.close()
|
chan.close()
|
||||||
|
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print '*** Caught exception: ' + str(e.__class__) + ': ' + str(e)
|
print('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
try:
|
||||||
t.close()
|
t.close()
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
# based on code provided by raymond mosteller (thanks!)
|
# based on code provided by raymond mosteller (thanks!)
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import getpass
|
import getpass
|
||||||
import os
|
import os
|
||||||
|
@ -30,6 +32,11 @@ import traceback
|
||||||
import paramiko
|
import paramiko
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
input = raw_input
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
|
|
||||||
# setup logging
|
# setup logging
|
||||||
paramiko.util.log_to_file('demo_sftp.log')
|
paramiko.util.log_to_file('demo_sftp.log')
|
||||||
|
|
||||||
|
@ -40,9 +47,9 @@ if len(sys.argv) > 1:
|
||||||
if hostname.find('@') >= 0:
|
if hostname.find('@') >= 0:
|
||||||
username, hostname = hostname.split('@')
|
username, hostname = hostname.split('@')
|
||||||
else:
|
else:
|
||||||
hostname = raw_input('Hostname: ')
|
hostname = input('Hostname: ')
|
||||||
if len(hostname) == 0:
|
if len(hostname) == 0:
|
||||||
print '*** Hostname required.'
|
print('*** Hostname required.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
port = 22
|
port = 22
|
||||||
if hostname.find(':') >= 0:
|
if hostname.find(':') >= 0:
|
||||||
|
@ -53,7 +60,7 @@ if hostname.find(':') >= 0:
|
||||||
# get username
|
# get username
|
||||||
if username == '':
|
if username == '':
|
||||||
default_username = getpass.getuser()
|
default_username = getpass.getuser()
|
||||||
username = raw_input('Username [%s]: ' % default_username)
|
username = input('Username [%s]: ' % default_username)
|
||||||
if len(username) == 0:
|
if len(username) == 0:
|
||||||
username = default_username
|
username = default_username
|
||||||
password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
|
password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
|
||||||
|
@ -69,13 +76,13 @@ except IOError:
|
||||||
# try ~/ssh/ too, because windows can't have a folder named ~/.ssh/
|
# try ~/ssh/ too, because windows can't have a folder named ~/.ssh/
|
||||||
host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
|
host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
|
||||||
except IOError:
|
except IOError:
|
||||||
print '*** Unable to open host keys file'
|
print('*** Unable to open host keys file')
|
||||||
host_keys = {}
|
host_keys = {}
|
||||||
|
|
||||||
if host_keys.has_key(hostname):
|
if host_keys.has_key(hostname):
|
||||||
hostkeytype = host_keys[hostname].keys()[0]
|
hostkeytype = host_keys[hostname].keys()[0]
|
||||||
hostkey = host_keys[hostname][hostkeytype]
|
hostkey = host_keys[hostname][hostkeytype]
|
||||||
print 'Using host key of type %s' % hostkeytype
|
print('Using host key of type %s' % hostkeytype)
|
||||||
|
|
||||||
|
|
||||||
# now, connect and use paramiko Transport to negotiate SSH2 across the connection
|
# now, connect and use paramiko Transport to negotiate SSH2 across the connection
|
||||||
|
@ -86,22 +93,22 @@ try:
|
||||||
|
|
||||||
# dirlist on remote host
|
# dirlist on remote host
|
||||||
dirlist = sftp.listdir('.')
|
dirlist = sftp.listdir('.')
|
||||||
print "Dirlist:", dirlist
|
print("Dirlist:", dirlist)
|
||||||
|
|
||||||
# copy this demo onto the server
|
# copy this demo onto the server
|
||||||
try:
|
try:
|
||||||
sftp.mkdir("demo_sftp_folder")
|
sftp.mkdir("demo_sftp_folder")
|
||||||
except IOError:
|
except IOError:
|
||||||
print '(assuming demo_sftp_folder/ already exists)'
|
print('(assuming demo_sftp_folder/ already exists)')
|
||||||
sftp.open('demo_sftp_folder/README', 'w').write('This was created by demo_sftp.py.\n')
|
sftp.open('demo_sftp_folder/README', 'w').write('This was created by demo_sftp.py.\n')
|
||||||
data = open('demo_sftp.py', 'r').read()
|
data = open('demo_sftp.py', 'r').read()
|
||||||
sftp.open('demo_sftp_folder/demo_sftp.py', 'w').write(data)
|
sftp.open('demo_sftp_folder/demo_sftp.py', 'w').write(data)
|
||||||
print 'created demo_sftp_folder/ on the server'
|
print('created demo_sftp_folder/ on the server')
|
||||||
|
|
||||||
# copy the README back here
|
# copy the README back here
|
||||||
data = sftp.open('demo_sftp_folder/README', 'r').read()
|
data = sftp.open('demo_sftp_folder/README', 'r').read()
|
||||||
open('README_demo_sftp', 'w').write(data)
|
open('README_demo_sftp', 'w').write(data)
|
||||||
print 'copied README back here'
|
print('copied README back here')
|
||||||
|
|
||||||
# BETTER: use the get() and put() methods
|
# BETTER: use the get() and put() methods
|
||||||
sftp.put('demo_sftp.py', 'demo_sftp_folder/demo_sftp.py')
|
sftp.put('demo_sftp.py', 'demo_sftp_folder/demo_sftp.py')
|
||||||
|
@ -109,8 +116,8 @@ try:
|
||||||
|
|
||||||
t.close()
|
t.close()
|
||||||
|
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print '*** Caught exception: %s: %s' % (e.__class__, e)
|
print('*** Caught exception: %s: %s' % (e.__class__, e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
try:
|
||||||
t.close()
|
t.close()
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
# 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.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import getpass
|
import getpass
|
||||||
|
@ -29,6 +30,10 @@ import traceback
|
||||||
import paramiko
|
import paramiko
|
||||||
import interactive
|
import interactive
|
||||||
|
|
||||||
|
try:
|
||||||
|
input = raw_input
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
|
|
||||||
# setup logging
|
# setup logging
|
||||||
paramiko.util.log_to_file('demo_simple.log')
|
paramiko.util.log_to_file('demo_simple.log')
|
||||||
|
@ -40,9 +45,9 @@ if len(sys.argv) > 1:
|
||||||
if hostname.find('@') >= 0:
|
if hostname.find('@') >= 0:
|
||||||
username, hostname = hostname.split('@')
|
username, hostname = hostname.split('@')
|
||||||
else:
|
else:
|
||||||
hostname = raw_input('Hostname: ')
|
hostname = input('Hostname: ')
|
||||||
if len(hostname) == 0:
|
if len(hostname) == 0:
|
||||||
print '*** Hostname required.'
|
print('*** Hostname required.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
port = 22
|
port = 22
|
||||||
if hostname.find(':') >= 0:
|
if hostname.find(':') >= 0:
|
||||||
|
@ -53,7 +58,7 @@ if hostname.find(':') >= 0:
|
||||||
# get username
|
# get username
|
||||||
if username == '':
|
if username == '':
|
||||||
default_username = getpass.getuser()
|
default_username = getpass.getuser()
|
||||||
username = raw_input('Username [%s]: ' % default_username)
|
username = input('Username [%s]: ' % default_username)
|
||||||
if len(username) == 0:
|
if len(username) == 0:
|
||||||
username = default_username
|
username = default_username
|
||||||
password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
|
password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
|
||||||
|
@ -64,18 +69,18 @@ try:
|
||||||
client = paramiko.SSHClient()
|
client = paramiko.SSHClient()
|
||||||
client.load_system_host_keys()
|
client.load_system_host_keys()
|
||||||
client.set_missing_host_key_policy(paramiko.WarningPolicy)
|
client.set_missing_host_key_policy(paramiko.WarningPolicy)
|
||||||
print '*** Connecting...'
|
print('*** Connecting...')
|
||||||
client.connect(hostname, port, username, password)
|
client.connect(hostname, port, username, password)
|
||||||
chan = client.invoke_shell()
|
chan = client.invoke_shell()
|
||||||
print repr(client.get_transport())
|
print(repr(client.get_transport()))
|
||||||
print '*** Here we go!'
|
print('*** Here we go!')
|
||||||
print
|
print()
|
||||||
interactive.interactive_shell(chan)
|
interactive.interactive_shell(chan)
|
||||||
chan.close()
|
chan.close()
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print '*** Caught exception: %s: %s' % (e.__class__, e)
|
print('*** Caught exception: %s: %s' % (e.__class__, e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
try:
|
||||||
client.close()
|
client.close()
|
||||||
|
|
|
@ -26,6 +26,8 @@ forwarding (the openssh -L option) from a local port through a tunneled
|
||||||
connection to a destination reachable from the SSH server machine.
|
connection to a destination reachable from the SSH server machine.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import getpass
|
import getpass
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
@ -54,7 +56,7 @@ class Handler (SocketServer.BaseRequestHandler):
|
||||||
chan = self.ssh_transport.open_channel('direct-tcpip',
|
chan = self.ssh_transport.open_channel('direct-tcpip',
|
||||||
(self.chain_host, self.chain_port),
|
(self.chain_host, self.chain_port),
|
||||||
self.request.getpeername())
|
self.request.getpeername())
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
verbose('Incoming request to %s:%d failed: %s' % (self.chain_host,
|
verbose('Incoming request to %s:%d failed: %s' % (self.chain_host,
|
||||||
self.chain_port,
|
self.chain_port,
|
||||||
repr(e)))
|
repr(e)))
|
||||||
|
@ -96,7 +98,7 @@ def forward_tunnel(local_port, remote_host, remote_port, transport):
|
||||||
|
|
||||||
def verbose(s):
|
def verbose(s):
|
||||||
if g_verbose:
|
if g_verbose:
|
||||||
print s
|
print(s)
|
||||||
|
|
||||||
|
|
||||||
HELP = """\
|
HELP = """\
|
||||||
|
@ -163,8 +165,8 @@ def main():
|
||||||
try:
|
try:
|
||||||
client.connect(server[0], server[1], username=options.user, key_filename=options.keyfile,
|
client.connect(server[0], server[1], username=options.user, key_filename=options.keyfile,
|
||||||
look_for_keys=options.look_for_keys, password=password)
|
look_for_keys=options.look_for_keys, password=password)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print '*** Failed to connect to %s:%d: %r' % (server[0], server[1], e)
|
print('*** Failed to connect to %s:%d: %r' % (server[0], server[1], e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
verbose('Now forwarding port %d to %s:%d ...' % (options.port, remote[0], remote[1]))
|
verbose('Now forwarding port %d to %s:%d ...' % (options.port, remote[0], remote[1]))
|
||||||
|
@ -172,7 +174,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
forward_tunnel(options.port, remote[0], remote[1], client.get_transport())
|
forward_tunnel(options.port, remote[0], remote[1], client.get_transport())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print 'C-c: Port forwarding stopped.'
|
print('C-c: Port forwarding stopped.')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
# 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.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
@ -51,7 +52,7 @@ def posix_shell(chan):
|
||||||
try:
|
try:
|
||||||
x = chan.recv(1024)
|
x = chan.recv(1024)
|
||||||
if len(x) == 0:
|
if len(x) == 0:
|
||||||
print '\r\n*** EOF\r\n',
|
print('\r\n*** EOF\r\n', end=' ')
|
||||||
break
|
break
|
||||||
sys.stdout.write(x)
|
sys.stdout.write(x)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
|
@ -26,6 +26,8 @@ forwarding (the openssh -R option) from a remote port through a tunneled
|
||||||
connection to a destination reachable from the local machine.
|
connection to a destination reachable from the local machine.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import getpass
|
import getpass
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
@ -46,7 +48,7 @@ def handler(chan, host, port):
|
||||||
sock = socket.socket()
|
sock = socket.socket()
|
||||||
try:
|
try:
|
||||||
sock.connect((host, port))
|
sock.connect((host, port))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
verbose('Forwarding request to %s:%d failed: %r' % (host, port, e))
|
verbose('Forwarding request to %s:%d failed: %r' % (host, port, e))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -82,7 +84,7 @@ def reverse_forward_tunnel(server_port, remote_host, remote_port, transport):
|
||||||
|
|
||||||
def verbose(s):
|
def verbose(s):
|
||||||
if g_verbose:
|
if g_verbose:
|
||||||
print s
|
print(s)
|
||||||
|
|
||||||
|
|
||||||
HELP = """\
|
HELP = """\
|
||||||
|
@ -150,8 +152,8 @@ def main():
|
||||||
try:
|
try:
|
||||||
client.connect(server[0], server[1], username=options.user, key_filename=options.keyfile,
|
client.connect(server[0], server[1], username=options.user, key_filename=options.keyfile,
|
||||||
look_for_keys=options.look_for_keys, password=password)
|
look_for_keys=options.look_for_keys, password=password)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print '*** Failed to connect to %s:%d: %r' % (server[0], server[1], e)
|
print('*** Failed to connect to %s:%d: %r' % (server[0], server[1], e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
verbose('Now forwarding remote port %d to %s:%d ...' % (options.port, remote[0], remote[1]))
|
verbose('Now forwarding remote port %d to %s:%d ...' % (options.port, remote[0], remote[1]))
|
||||||
|
@ -159,7 +161,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
reverse_forward_tunnel(options.port, remote[0], remote[1], client.get_transport())
|
reverse_forward_tunnel(options.port, remote[0], remote[1], client.get_transport())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print 'C-c: Port forwarding stopped.'
|
print('C-c: Port forwarding stopped.')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ Website: U{https://github.com/paramiko/paramiko/}
|
||||||
Mailing list: U{paramiko@librelist.com<mailto:paramiko@librelist.com>}
|
Mailing list: U{paramiko@librelist.com<mailto:paramiko@librelist.com>}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if sys.version_info < (2, 5):
|
if sys.version_info < (2, 5):
|
||||||
|
@ -61,32 +62,36 @@ __version__ = "1.11.0"
|
||||||
__license__ = "GNU Lesser General Public License (LGPL)"
|
__license__ = "GNU Lesser General Public License (LGPL)"
|
||||||
|
|
||||||
|
|
||||||
from transport import SecurityOptions, Transport
|
from paramiko.transport import SecurityOptions, Transport
|
||||||
from client import SSHClient, MissingHostKeyPolicy, AutoAddPolicy, RejectPolicy, WarningPolicy
|
from paramiko.client import SSHClient, MissingHostKeyPolicy, AutoAddPolicy, RejectPolicy, WarningPolicy
|
||||||
from auth_handler import AuthHandler
|
from paramiko.auth_handler import AuthHandler
|
||||||
from channel import Channel, ChannelFile
|
from paramiko.channel import Channel, ChannelFile
|
||||||
from ssh_exception import SSHException, PasswordRequiredException, \
|
from paramiko.ssh_exception import SSHException, PasswordRequiredException, \
|
||||||
BadAuthenticationType, ChannelException, BadHostKeyException, \
|
BadAuthenticationType, ChannelException, BadHostKeyException, \
|
||||||
AuthenticationException, ProxyCommandFailure
|
AuthenticationException, ProxyCommandFailure
|
||||||
from server import ServerInterface, SubsystemHandler, InteractiveQuery
|
from paramiko.server import ServerInterface, SubsystemHandler, InteractiveQuery
|
||||||
from rsakey import RSAKey
|
from paramiko.rsakey import RSAKey
|
||||||
from dsskey import DSSKey
|
from paramiko.dsskey import DSSKey
|
||||||
from sftp import SFTPError, BaseSFTP
|
from paramiko.sftp import SFTPError, BaseSFTP
|
||||||
from sftp_client import SFTP, SFTPClient
|
from paramiko.sftp_client import SFTP, SFTPClient
|
||||||
from sftp_server import SFTPServer
|
from paramiko.sftp_server import SFTPServer
|
||||||
from sftp_attr import SFTPAttributes
|
from paramiko.sftp_attr import SFTPAttributes
|
||||||
from sftp_handle import SFTPHandle
|
from paramiko.sftp_handle import SFTPHandle
|
||||||
from sftp_si import SFTPServerInterface
|
from paramiko.sftp_si import SFTPServerInterface
|
||||||
from sftp_file import SFTPFile
|
from paramiko.sftp_file import SFTPFile
|
||||||
from message import Message
|
from paramiko.message import Message
|
||||||
from packet import Packetizer
|
from paramiko.packet import Packetizer
|
||||||
from file import BufferedFile
|
from paramiko.file import BufferedFile
|
||||||
from agent import Agent, AgentKey
|
from paramiko.agent import Agent, AgentKey
|
||||||
from pkey import PKey
|
from paramiko.pkey import PKey
|
||||||
from hostkeys import HostKeys
|
from paramiko.hostkeys import HostKeys
|
||||||
from config import SSHConfig
|
from paramiko.config import SSHConfig
|
||||||
from proxy import ProxyCommand
|
from paramiko.proxy import ProxyCommand
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
|
if not six.PY3:
|
||||||
|
# Skipping port to Python 3 since, Epydoc has not been ported to Python 3.
|
||||||
# fix module names for epydoc
|
# fix module names for epydoc
|
||||||
for c in locals().values():
|
for c in locals().values():
|
||||||
if issubclass(type(c), type) or type(c).__name__ == 'classobj':
|
if issubclass(type(c), type) or type(c).__name__ == 'classobj':
|
||||||
|
@ -94,14 +99,14 @@ for c in locals().values():
|
||||||
c.__module__ = __name__
|
c.__module__ = __name__
|
||||||
del c
|
del c
|
||||||
|
|
||||||
from common import AUTH_SUCCESSFUL, AUTH_PARTIALLY_SUCCESSFUL, AUTH_FAILED, \
|
from paramiko.common import AUTH_SUCCESSFUL, AUTH_PARTIALLY_SUCCESSFUL, AUTH_FAILED, \
|
||||||
OPEN_SUCCEEDED, OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED, OPEN_FAILED_CONNECT_FAILED, \
|
OPEN_SUCCEEDED, OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED, OPEN_FAILED_CONNECT_FAILED, \
|
||||||
OPEN_FAILED_UNKNOWN_CHANNEL_TYPE, OPEN_FAILED_RESOURCE_SHORTAGE
|
OPEN_FAILED_UNKNOWN_CHANNEL_TYPE, OPEN_FAILED_RESOURCE_SHORTAGE
|
||||||
|
|
||||||
from sftp import SFTP_OK, SFTP_EOF, SFTP_NO_SUCH_FILE, SFTP_PERMISSION_DENIED, SFTP_FAILURE, \
|
from paramiko.sftp import SFTP_OK, SFTP_EOF, SFTP_NO_SUCH_FILE, SFTP_PERMISSION_DENIED, SFTP_FAILURE, \
|
||||||
SFTP_BAD_MESSAGE, SFTP_NO_CONNECTION, SFTP_CONNECTION_LOST, SFTP_OP_UNSUPPORTED
|
SFTP_BAD_MESSAGE, SFTP_NO_CONNECTION, SFTP_CONNECTION_LOST, SFTP_OP_UNSUPPORTED
|
||||||
|
|
||||||
from common import io_sleep
|
from paramiko.common import io_sleep
|
||||||
|
|
||||||
__all__ = [ 'Transport',
|
__all__ = [ 'Transport',
|
||||||
'SSHClient',
|
'SSHClient',
|
||||||
|
|
|
@ -8,7 +8,7 @@ in jaraco.windows and asking the author to port the fixes back here.
|
||||||
|
|
||||||
import ctypes
|
import ctypes
|
||||||
import ctypes.wintypes
|
import ctypes.wintypes
|
||||||
import __builtin__
|
from six.moves import builtins
|
||||||
|
|
||||||
######################
|
######################
|
||||||
# jaraco.windows.error
|
# jaraco.windows.error
|
||||||
|
@ -53,7 +53,7 @@ def format_system_message(errno):
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
class WindowsError(__builtin__.WindowsError):
|
class WindowsError(builtins.WindowsError):
|
||||||
"more info about errors at http://msdn.microsoft.com/en-us/library/ms681381(VS.85).aspx"
|
"more info about errors at http://msdn.microsoft.com/en-us/library/ms681381(VS.85).aspx"
|
||||||
|
|
||||||
def __init__(self, value=None):
|
def __init__(self, value=None):
|
||||||
|
@ -118,7 +118,7 @@ class MemoryMap(object):
|
||||||
FILE_MAP_WRITE = 0x2
|
FILE_MAP_WRITE = 0x2
|
||||||
filemap = ctypes.windll.kernel32.CreateFileMappingW(
|
filemap = ctypes.windll.kernel32.CreateFileMappingW(
|
||||||
INVALID_HANDLE_VALUE, p_SA, PAGE_READWRITE, 0, self.length,
|
INVALID_HANDLE_VALUE, p_SA, PAGE_READWRITE, 0, self.length,
|
||||||
unicode(self.name))
|
builtins.unicode(self.name))
|
||||||
handle_nonzero_success(filemap)
|
handle_nonzero_success(filemap)
|
||||||
if filemap == INVALID_HANDLE_VALUE:
|
if filemap == INVALID_HANDLE_VALUE:
|
||||||
raise Exception("Failed to create file mapping")
|
raise Exception("Failed to create file mapping")
|
||||||
|
|
|
@ -215,7 +215,7 @@ class AgentClientProxy(object):
|
||||||
# probably a dangling env var: the ssh agent is gone
|
# probably a dangling env var: the ssh agent is gone
|
||||||
return
|
return
|
||||||
elif sys.platform == 'win32':
|
elif sys.platform == 'win32':
|
||||||
import win_pageant
|
from paramiko import win_pageant
|
||||||
if win_pageant.can_talk_to_agent():
|
if win_pageant.can_talk_to_agent():
|
||||||
conn = win_pageant.PageantConnection()
|
conn = win_pageant.PageantConnection()
|
||||||
else:
|
else:
|
||||||
|
@ -334,7 +334,7 @@ class Agent(AgentSSH):
|
||||||
# probably a dangling env var: the ssh agent is gone
|
# probably a dangling env var: the ssh agent is gone
|
||||||
return
|
return
|
||||||
elif sys.platform == 'win32':
|
elif sys.platform == 'win32':
|
||||||
import win_pageant
|
from paramiko import win_pageant
|
||||||
if win_pageant.can_talk_to_agent():
|
if win_pageant.can_talk_to_agent():
|
||||||
conn = win_pageant.PageantConnection()
|
conn = win_pageant.PageantConnection()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -25,6 +25,7 @@ import weakref
|
||||||
|
|
||||||
# this helps freezing utils
|
# this helps freezing utils
|
||||||
import encodings.utf_8
|
import encodings.utf_8
|
||||||
|
import six
|
||||||
|
|
||||||
from paramiko.common import *
|
from paramiko.common import *
|
||||||
from paramiko import util
|
from paramiko import util
|
||||||
|
@ -198,7 +199,7 @@ class AuthHandler (object):
|
||||||
if self.auth_method == 'password':
|
if self.auth_method == 'password':
|
||||||
m.add_boolean(False)
|
m.add_boolean(False)
|
||||||
password = self.password
|
password = self.password
|
||||||
if isinstance(password, unicode):
|
if isinstance(password, six.text_type):
|
||||||
password = password.encode('UTF-8')
|
password = password.encode('UTF-8')
|
||||||
m.add_string(password)
|
m.add_string(password)
|
||||||
elif self.auth_method == 'publickey':
|
elif self.auth_method == 'publickey':
|
||||||
|
@ -308,7 +309,7 @@ class AuthHandler (object):
|
||||||
keyblob = m.get_string()
|
keyblob = m.get_string()
|
||||||
try:
|
try:
|
||||||
key = self.transport._key_info[keytype](Message(keyblob))
|
key = self.transport._key_info[keytype](Message(keyblob))
|
||||||
except SSHException, e:
|
except SSHException as e:
|
||||||
self.transport._log(INFO, 'Auth rejected: public key: %s' % str(e))
|
self.transport._log(INFO, 'Auth rejected: public key: %s' % str(e))
|
||||||
key = None
|
key = None
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -16,8 +16,10 @@
|
||||||
# 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.
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from paramiko import util
|
||||||
|
|
||||||
import util
|
import six
|
||||||
|
|
||||||
|
|
||||||
class BERException (Exception):
|
class BERException (Exception):
|
||||||
|
@ -112,7 +114,7 @@ class BER(object):
|
||||||
self.encode_tlv(1, '\xff')
|
self.encode_tlv(1, '\xff')
|
||||||
else:
|
else:
|
||||||
self.encode_tlv(1, '\x00')
|
self.encode_tlv(1, '\x00')
|
||||||
elif (type(x) is int) or (type(x) is long):
|
elif isinstance(x, six.integer_types):
|
||||||
self.encode_tlv(2, util.deflate_long(x))
|
self.encode_tlv(2, util.deflate_long(x))
|
||||||
elif type(x) is str:
|
elif type(x) is str:
|
||||||
self.encode_tlv(4, x)
|
self.encode_tlv(4, x)
|
||||||
|
|
|
@ -615,7 +615,7 @@ class Channel (object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
out = self.in_buffer.read(nbytes, self.timeout)
|
out = self.in_buffer.read(nbytes, self.timeout)
|
||||||
except PipeTimeout, e:
|
except PipeTimeout as e:
|
||||||
raise socket.timeout()
|
raise socket.timeout()
|
||||||
|
|
||||||
ack = self._check_add_window(len(out))
|
ack = self._check_add_window(len(out))
|
||||||
|
@ -665,7 +665,7 @@ class Channel (object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
out = self.in_stderr_buffer.read(nbytes, self.timeout)
|
out = self.in_stderr_buffer.read(nbytes, self.timeout)
|
||||||
except PipeTimeout, e:
|
except PipeTimeout as e:
|
||||||
raise socket.timeout()
|
raise socket.timeout()
|
||||||
|
|
||||||
ack = self._check_add_window(len(out))
|
ack = self._check_add_window(len(out))
|
||||||
|
|
|
@ -25,6 +25,7 @@ import getpass
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import warnings
|
import warnings
|
||||||
|
import six
|
||||||
|
|
||||||
from paramiko.agent import Agent
|
from paramiko.agent import Agent
|
||||||
from paramiko.common import *
|
from paramiko.common import *
|
||||||
|
@ -335,7 +336,7 @@ class SSHClient (object):
|
||||||
|
|
||||||
if key_filename is None:
|
if key_filename is None:
|
||||||
key_filenames = []
|
key_filenames = []
|
||||||
elif isinstance(key_filename, (str, unicode)):
|
elif isinstance(key_filename, (six.binary_type, six.text_type)):
|
||||||
key_filenames = [ key_filename ]
|
key_filenames = [ key_filename ]
|
||||||
else:
|
else:
|
||||||
key_filenames = key_filename
|
key_filenames = key_filename
|
||||||
|
@ -452,7 +453,7 @@ class SSHClient (object):
|
||||||
two_factor = (allowed_types == ['password'])
|
two_factor = (allowed_types == ['password'])
|
||||||
if not two_factor:
|
if not two_factor:
|
||||||
return
|
return
|
||||||
except SSHException, e:
|
except SSHException as e:
|
||||||
saved_exception = e
|
saved_exception = e
|
||||||
|
|
||||||
if not two_factor:
|
if not two_factor:
|
||||||
|
@ -466,7 +467,7 @@ class SSHClient (object):
|
||||||
if not two_factor:
|
if not two_factor:
|
||||||
return
|
return
|
||||||
break
|
break
|
||||||
except SSHException, e:
|
except SSHException as e:
|
||||||
saved_exception = e
|
saved_exception = e
|
||||||
|
|
||||||
if not two_factor and allow_agent:
|
if not two_factor and allow_agent:
|
||||||
|
@ -482,7 +483,7 @@ class SSHClient (object):
|
||||||
if not two_factor:
|
if not two_factor:
|
||||||
return
|
return
|
||||||
break
|
break
|
||||||
except SSHException, e:
|
except SSHException as e:
|
||||||
saved_exception = e
|
saved_exception = e
|
||||||
|
|
||||||
if not two_factor:
|
if not two_factor:
|
||||||
|
@ -514,16 +515,16 @@ class SSHClient (object):
|
||||||
if not two_factor:
|
if not two_factor:
|
||||||
return
|
return
|
||||||
break
|
break
|
||||||
except SSHException, e:
|
except SSHException as e:
|
||||||
saved_exception = e
|
saved_exception = e
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
saved_exception = e
|
saved_exception = e
|
||||||
|
|
||||||
if password is not None:
|
if password is not None:
|
||||||
try:
|
try:
|
||||||
self._transport.auth_password(username, password)
|
self._transport.auth_password(username, password)
|
||||||
return
|
return
|
||||||
except SSHException, e:
|
except SSHException as e:
|
||||||
saved_exception = e
|
saved_exception = e
|
||||||
elif two_factor:
|
elif two_factor:
|
||||||
raise SSHException('Two-factor authentication requires a password')
|
raise SSHException('Two-factor authentication requires a password')
|
||||||
|
|
|
@ -20,6 +20,10 @@
|
||||||
L{DSSKey}
|
L{DSSKey}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
from Crypto.PublicKey import DSA
|
from Crypto.PublicKey import DSA
|
||||||
from Crypto.Hash import SHA
|
from Crypto.Hash import SHA
|
||||||
|
|
||||||
|
@ -184,7 +188,7 @@ class DSSKey (PKey):
|
||||||
# DSAPrivateKey = { version = 0, p, q, g, y, x }
|
# DSAPrivateKey = { version = 0, p, q, g, y, x }
|
||||||
try:
|
try:
|
||||||
keylist = BER(data).decode()
|
keylist = BER(data).decode()
|
||||||
except BERException, x:
|
except BERException as x:
|
||||||
raise SSHException('Unable to parse key file: ' + str(x))
|
raise SSHException('Unable to parse key file: ' + str(x))
|
||||||
if (type(keylist) is not list) or (len(keylist) < 6) or (keylist[0] != 0):
|
if (type(keylist) is not list) or (len(keylist) < 6) or (keylist[0] != 0):
|
||||||
raise SSHException('not a valid DSA private key file (bad ber encoding)')
|
raise SSHException('not a valid DSA private key file (bad ber encoding)')
|
||||||
|
|
|
@ -20,7 +20,10 @@
|
||||||
BufferedFile.
|
BufferedFile.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
except ImportError:
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
|
||||||
class BufferedFile (object):
|
class BufferedFile (object):
|
||||||
|
|
|
@ -23,7 +23,10 @@ L{HostKeys}
|
||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
from Crypto.Hash import SHA, HMAC
|
from Crypto.Hash import SHA, HMAC
|
||||||
import UserDict
|
try:
|
||||||
|
from UserDict import DictMixin
|
||||||
|
except ImportError:
|
||||||
|
from collections import MutableMapping as DictMixin
|
||||||
|
|
||||||
from paramiko.common import *
|
from paramiko.common import *
|
||||||
from paramiko.dsskey import DSSKey
|
from paramiko.dsskey import DSSKey
|
||||||
|
@ -84,7 +87,7 @@ class HostKeyEntry:
|
||||||
else:
|
else:
|
||||||
log.info("Unable to handle key of type %s" % (keytype,))
|
log.info("Unable to handle key of type %s" % (keytype,))
|
||||||
return None
|
return None
|
||||||
except binascii.Error, e:
|
except binascii.Error as e:
|
||||||
raise InvalidHostKey(line, e)
|
raise InvalidHostKey(line, e)
|
||||||
|
|
||||||
return cls(names, key)
|
return cls(names, key)
|
||||||
|
@ -105,7 +108,7 @@ class HostKeyEntry:
|
||||||
return '<HostKeyEntry %r: %r>' % (self.hostnames, self.key)
|
return '<HostKeyEntry %r: %r>' % (self.hostnames, self.key)
|
||||||
|
|
||||||
|
|
||||||
class HostKeys (UserDict.DictMixin):
|
class HostKeys (DictMixin):
|
||||||
"""
|
"""
|
||||||
Representation of an openssh-style "known hosts" file. Host keys can be
|
Representation of an openssh-style "known hosts" file. Host keys can be
|
||||||
read from one or more files, and then individual hosts can be looked up to
|
read from one or more files, and then individual hosts can be looked up to
|
||||||
|
@ -211,7 +214,7 @@ class HostKeys (UserDict.DictMixin):
|
||||||
@return: keys associated with this host (or C{None})
|
@return: keys associated with this host (or C{None})
|
||||||
@rtype: dict(str, L{PKey})
|
@rtype: dict(str, L{PKey})
|
||||||
"""
|
"""
|
||||||
class SubDict (UserDict.DictMixin):
|
class SubDict (DictMixin):
|
||||||
def __init__(self, hostname, entries, hostkeys):
|
def __init__(self, hostname, entries, hostkeys):
|
||||||
self._hostname = hostname
|
self._hostname = hostname
|
||||||
self._entries = entries
|
self._entries = entries
|
||||||
|
|
|
@ -28,11 +28,14 @@ from paramiko import util
|
||||||
from paramiko.message import Message
|
from paramiko.message import Message
|
||||||
from paramiko.ssh_exception import SSHException
|
from paramiko.ssh_exception import SSHException
|
||||||
|
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
_MSG_KEXDH_INIT, _MSG_KEXDH_REPLY = range(30, 32)
|
_MSG_KEXDH_INIT, _MSG_KEXDH_REPLY = range(30, 32)
|
||||||
|
|
||||||
# draft-ietf-secsh-transport-09.txt, page 17
|
# draft-ietf-secsh-transport-09.txt, page 17
|
||||||
P = 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFFL
|
P = long(0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF)
|
||||||
G = 2
|
G = 2
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,9 +45,9 @@ class KexGroup1(object):
|
||||||
|
|
||||||
def __init__(self, transport):
|
def __init__(self, transport):
|
||||||
self.transport = transport
|
self.transport = transport
|
||||||
self.x = 0L
|
self.x = 0
|
||||||
self.e = 0L
|
self.e = 0
|
||||||
self.f = 0L
|
self.f = 0
|
||||||
|
|
||||||
def start_kex(self):
|
def start_kex(self):
|
||||||
self._generate_x()
|
self._generate_x()
|
||||||
|
|
|
@ -20,8 +20,15 @@
|
||||||
Implementation of an SSH2 "message".
|
Implementation of an SSH2 "message".
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
import cStringIO
|
try:
|
||||||
|
from cStringIO import StringIO
|
||||||
|
except ImportError:
|
||||||
|
from io import StringIO
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
from paramiko import util
|
from paramiko import util
|
||||||
|
|
||||||
|
@ -46,9 +53,9 @@ class Message (object):
|
||||||
@type content: string
|
@type content: string
|
||||||
"""
|
"""
|
||||||
if content != None:
|
if content != None:
|
||||||
self.packet = cStringIO.StringIO(content)
|
self.packet = StringIO(content)
|
||||||
else:
|
else:
|
||||||
self.packet = cStringIO.StringIO()
|
self.packet = StringIO()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""
|
"""
|
||||||
|
@ -274,13 +281,17 @@ class Message (object):
|
||||||
def _add(self, i):
|
def _add(self, i):
|
||||||
if type(i) is str:
|
if type(i) is str:
|
||||||
return self.add_string(i)
|
return self.add_string(i)
|
||||||
elif type(i) is int:
|
|
||||||
|
elif type(i) in six.integer_types:
|
||||||
|
|
||||||
|
if type(i) is int and not six.PY3:
|
||||||
return self.add_int(i)
|
return self.add_int(i)
|
||||||
elif type(i) is long:
|
else:
|
||||||
if i > 0xffffffffL:
|
if i > long(0xffffffff):
|
||||||
return self.add_mpint(i)
|
return self.add_mpint(i)
|
||||||
else:
|
else:
|
||||||
return self.add_int(i)
|
return self.add_int(i)
|
||||||
|
|
||||||
elif type(i) is bool:
|
elif type(i) is bool:
|
||||||
return self.add_boolean(i)
|
return self.add_boolean(i)
|
||||||
elif type(i) is list:
|
elif type(i) is list:
|
||||||
|
|
|
@ -27,6 +27,10 @@ import struct
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
from paramiko.common import *
|
from paramiko.common import *
|
||||||
from paramiko import util
|
from paramiko import util
|
||||||
from paramiko.ssh_exception import SSHException, ProxyCommandFailure
|
from paramiko.ssh_exception import SSHException, ProxyCommandFailure
|
||||||
|
@ -94,8 +98,8 @@ class Packetizer (object):
|
||||||
self.__mac_key_in = ''
|
self.__mac_key_in = ''
|
||||||
self.__compress_engine_out = None
|
self.__compress_engine_out = None
|
||||||
self.__compress_engine_in = None
|
self.__compress_engine_in = None
|
||||||
self.__sequence_number_out = 0L
|
self.__sequence_number_out = 0
|
||||||
self.__sequence_number_in = 0L
|
self.__sequence_number_in = 0
|
||||||
|
|
||||||
# lock around outbound writes (packet computation)
|
# lock around outbound writes (packet computation)
|
||||||
self.__write_lock = threading.RLock()
|
self.__write_lock = threading.RLock()
|
||||||
|
@ -219,7 +223,7 @@ class Packetizer (object):
|
||||||
n -= len(x)
|
n -= len(x)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
got_timeout = True
|
got_timeout = True
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
# on Linux, sometimes instead of socket.timeout, we get
|
# on Linux, sometimes instead of socket.timeout, we get
|
||||||
# EAGAIN. this is a bug in recent (> 2.6.9) kernels but
|
# EAGAIN. this is a bug in recent (> 2.6.9) kernels but
|
||||||
# we need to work around it.
|
# we need to work around it.
|
||||||
|
@ -248,7 +252,7 @@ class Packetizer (object):
|
||||||
n = self.__socket.send(out)
|
n = self.__socket.send(out)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
retry_write = True
|
retry_write = True
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
if (type(e.args) is tuple) and (len(e.args) > 0) and (e.args[0] == errno.EAGAIN):
|
if (type(e.args) is tuple) and (len(e.args) > 0) and (e.args[0] == errno.EAGAIN):
|
||||||
retry_write = True
|
retry_write = True
|
||||||
elif (type(e.args) is tuple) and (len(e.args) > 0) and (e.args[0] == errno.EINTR):
|
elif (type(e.args) is tuple) and (len(e.args) > 0) and (e.args[0] == errno.EINTR):
|
||||||
|
@ -315,7 +319,7 @@ class Packetizer (object):
|
||||||
if self.__block_engine_out != None:
|
if self.__block_engine_out != None:
|
||||||
payload = struct.pack('>I', self.__sequence_number_out) + packet
|
payload = struct.pack('>I', self.__sequence_number_out) + packet
|
||||||
out += compute_hmac(self.__mac_key_out, payload, self.__mac_engine_out)[:self.__mac_size_out]
|
out += compute_hmac(self.__mac_key_out, payload, self.__mac_engine_out)[:self.__mac_size_out]
|
||||||
self.__sequence_number_out = (self.__sequence_number_out + 1) & 0xffffffffL
|
self.__sequence_number_out = (self.__sequence_number_out + 1) & long(0xffffffff)
|
||||||
self.write_all(out)
|
self.write_all(out)
|
||||||
|
|
||||||
self.__sent_bytes += len(out)
|
self.__sent_bytes += len(out)
|
||||||
|
@ -343,7 +347,7 @@ class Packetizer (object):
|
||||||
if self.__block_engine_in != None:
|
if self.__block_engine_in != None:
|
||||||
header = self.__block_engine_in.decrypt(header)
|
header = self.__block_engine_in.decrypt(header)
|
||||||
if self.__dump_packets:
|
if self.__dump_packets:
|
||||||
self._log(DEBUG, util.format_binary(header, 'IN: '));
|
self._log(DEBUG, util.format_binary(header, 'IN: '))
|
||||||
packet_size = struct.unpack('>I', header[:4])[0]
|
packet_size = struct.unpack('>I', header[:4])[0]
|
||||||
# leftover contains decrypted bytes from the first block (after the length field)
|
# leftover contains decrypted bytes from the first block (after the length field)
|
||||||
leftover = header[4:]
|
leftover = header[4:]
|
||||||
|
@ -355,7 +359,7 @@ class Packetizer (object):
|
||||||
if self.__block_engine_in != None:
|
if self.__block_engine_in != None:
|
||||||
packet = self.__block_engine_in.decrypt(packet)
|
packet = self.__block_engine_in.decrypt(packet)
|
||||||
if self.__dump_packets:
|
if self.__dump_packets:
|
||||||
self._log(DEBUG, util.format_binary(packet, 'IN: '));
|
self._log(DEBUG, util.format_binary(packet, 'IN: '))
|
||||||
packet = leftover + packet
|
packet = leftover + packet
|
||||||
|
|
||||||
if self.__mac_size_in > 0:
|
if self.__mac_size_in > 0:
|
||||||
|
@ -375,7 +379,7 @@ class Packetizer (object):
|
||||||
|
|
||||||
msg = Message(payload[1:])
|
msg = Message(payload[1:])
|
||||||
msg.seqno = self.__sequence_number_in
|
msg.seqno = self.__sequence_number_in
|
||||||
self.__sequence_number_in = (self.__sequence_number_in + 1) & 0xffffffffL
|
self.__sequence_number_in = (self.__sequence_number_in + 1) & long(0xffffffff)
|
||||||
|
|
||||||
# check for rekey
|
# check for rekey
|
||||||
raw_packet_size = packet_size + self.__mac_size_in + 4
|
raw_packet_size = packet_size + self.__mac_size_in + 4
|
||||||
|
@ -473,7 +477,7 @@ class Packetizer (object):
|
||||||
break
|
break
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
pass
|
pass
|
||||||
except EnvironmentError, e:
|
except EnvironmentError as e:
|
||||||
if ((type(e.args) is tuple) and (len(e.args) > 0) and
|
if ((type(e.args) is tuple) and (len(e.args) > 0) and
|
||||||
(e.args[0] == errno.EINTR)):
|
(e.args[0] == errno.EINTR)):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -26,6 +26,7 @@ import os
|
||||||
|
|
||||||
from Crypto.Hash import MD5
|
from Crypto.Hash import MD5
|
||||||
from Crypto.Cipher import DES3, AES
|
from Crypto.Cipher import DES3, AES
|
||||||
|
import six
|
||||||
|
|
||||||
from paramiko.common import *
|
from paramiko.common import *
|
||||||
from paramiko import util
|
from paramiko import util
|
||||||
|
@ -303,8 +304,8 @@ class PKey (object):
|
||||||
end += 1
|
end += 1
|
||||||
# if we trudged to the end of the file, just try to cope.
|
# if we trudged to the end of the file, just try to cope.
|
||||||
try:
|
try:
|
||||||
data = base64.decodestring(''.join(lines[start:end]))
|
data = base64.decodestring(six.b(''.join(lines[start:end])))
|
||||||
except base64.binascii.Error, e:
|
except base64.binascii.Error as e:
|
||||||
raise SSHException('base64 decoding error: ' + str(e))
|
raise SSHException('base64 decoding error: ' + str(e))
|
||||||
if 'proc-type' not in headers:
|
if 'proc-type' not in headers:
|
||||||
# unencryped: done
|
# unencryped: done
|
||||||
|
@ -346,9 +347,9 @@ class PKey (object):
|
||||||
|
|
||||||
@raise IOError: if there was an error writing the file.
|
@raise IOError: if there was an error writing the file.
|
||||||
"""
|
"""
|
||||||
f = open(filename, 'w', 0600)
|
f = open(filename, 'w', 0o600)
|
||||||
# grrr... the mode doesn't always take hold
|
# grrr... the mode doesn't always take hold
|
||||||
os.chmod(filename, 0600)
|
os.chmod(filename, 0o600)
|
||||||
self._write_private_key(tag, f, data, password)
|
self._write_private_key(tag, f, data, password)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
Utility functions for dealing with primes.
|
Utility functions for dealing with primes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
from Crypto.Util import number
|
from Crypto.Util import number
|
||||||
|
|
||||||
from paramiko import util
|
from paramiko import util
|
||||||
|
|
|
@ -59,7 +59,7 @@ class ProxyCommand(object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.process.stdin.write(content)
|
self.process.stdin.write(content)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
# There was a problem with the child process. It probably
|
# There was a problem with the child process. It probably
|
||||||
# died and we can't proceed. The best option here is to
|
# died and we can't proceed. The best option here is to
|
||||||
# raise an exception informing the user that the informed
|
# raise an exception informing the user that the informed
|
||||||
|
@ -79,7 +79,7 @@ class ProxyCommand(object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return os.read(self.process.stdout.fileno(), size)
|
return os.read(self.process.stdout.fileno(), size)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
raise BadProxyCommand(' '.join(self.cmd), e.strerror)
|
raise BadProxyCommand(' '.join(self.cmd), e.strerror)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|
|
@ -20,6 +20,10 @@
|
||||||
L{RSAKey}
|
L{RSAKey}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
from Crypto.Hash import SHA, MD5
|
from Crypto.Hash import SHA, MD5
|
||||||
from Crypto.Cipher import DES3
|
from Crypto.Cipher import DES3
|
||||||
|
|
|
@ -21,6 +21,8 @@ L{ServerInterface} is an interface to override for server support.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
import six
|
||||||
|
|
||||||
from paramiko.common import *
|
from paramiko.common import *
|
||||||
from paramiko import util
|
from paramiko import util
|
||||||
|
|
||||||
|
@ -48,7 +50,7 @@ class InteractiveQuery (object):
|
||||||
self.instructions = instructions
|
self.instructions = instructions
|
||||||
self.prompts = []
|
self.prompts = []
|
||||||
for x in prompts:
|
for x in prompts:
|
||||||
if (type(x) is str) or (type(x) is unicode):
|
if isinstance(x, (six.binary_type, six.text_type)):
|
||||||
self.add_prompt(x)
|
self.add_prompt(x)
|
||||||
else:
|
else:
|
||||||
self.add_prompt(x[0], x[1])
|
self.add_prompt(x[0], x[1])
|
||||||
|
@ -602,7 +604,7 @@ class SubsystemHandler (threading.Thread):
|
||||||
try:
|
try:
|
||||||
self.__transport._log(DEBUG, 'Starting handler for subsystem %s' % self.__name)
|
self.__transport._log(DEBUG, 'Starting handler for subsystem %s' % self.__name)
|
||||||
self.start_subsystem(self.__name, self.__transport, self.__channel)
|
self.start_subsystem(self.__name, self.__transport, self.__channel)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.__transport._log(ERROR, 'Exception in subsystem handler for "%s": %s' %
|
self.__transport._log(ERROR, 'Exception in subsystem handler for "%s": %s' %
|
||||||
(self.__name, str(e)))
|
(self.__name, str(e)))
|
||||||
self.__transport._log(ERROR, util.tb_strings())
|
self.__transport._log(ERROR, util.tb_strings())
|
||||||
|
|
|
@ -180,7 +180,7 @@ class BaseSFTP (object):
|
||||||
size = struct.unpack('>I', x)[0]
|
size = struct.unpack('>I', x)[0]
|
||||||
data = self._read_all(size)
|
data = self._read_all(size)
|
||||||
if self.ultra_debug:
|
if self.ultra_debug:
|
||||||
self._log(DEBUG, util.format_binary(data, 'IN: '));
|
self._log(DEBUG, util.format_binary(data, 'IN: '))
|
||||||
if size > 0:
|
if size > 0:
|
||||||
t = ord(data[0])
|
t = ord(data[0])
|
||||||
#self._log(DEBUG2, 'read: %s (len=%d)' % (CMD_NAMES.get(t), '0x%02x' % t, len(data)-1))
|
#self._log(DEBUG2, 'read: %s (len=%d)' % (CMD_NAMES.get(t), '0x%02x' % t, len(data)-1))
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
# 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 six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
import stat
|
import stat
|
||||||
import time
|
import time
|
||||||
from paramiko.common import *
|
from paramiko.common import *
|
||||||
|
@ -44,7 +48,7 @@ class SFTPAttributes (object):
|
||||||
FLAG_UIDGID = 2
|
FLAG_UIDGID = 2
|
||||||
FLAG_PERMISSIONS = 4
|
FLAG_PERMISSIONS = 4
|
||||||
FLAG_AMTIME = 8
|
FLAG_AMTIME = 8
|
||||||
FLAG_EXTENDED = 0x80000000L
|
FLAG_EXTENDED = long(0x80000000)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
|
@ -194,13 +198,13 @@ class SFTPAttributes (object):
|
||||||
ks = 's'
|
ks = 's'
|
||||||
else:
|
else:
|
||||||
ks = '?'
|
ks = '?'
|
||||||
ks += self._rwx((self.st_mode & 0700) >> 6, self.st_mode & stat.S_ISUID)
|
ks += self._rwx((self.st_mode & 0o700) >> 6, self.st_mode & stat.S_ISUID)
|
||||||
ks += self._rwx((self.st_mode & 070) >> 3, self.st_mode & stat.S_ISGID)
|
ks += self._rwx((self.st_mode & 0o70) >> 3, self.st_mode & stat.S_ISGID)
|
||||||
ks += self._rwx(self.st_mode & 7, self.st_mode & stat.S_ISVTX, True)
|
ks += self._rwx(self.st_mode & 7, self.st_mode & stat.S_ISVTX, True)
|
||||||
else:
|
else:
|
||||||
ks = '?---------'
|
ks = '?---------'
|
||||||
# compute display date
|
# compute display date
|
||||||
if (self.st_mtime is None) or (self.st_mtime == 0xffffffffL):
|
if (self.st_mtime is None) or (self.st_mtime == long(0xffffffff)):
|
||||||
# shouldn't really happen
|
# shouldn't really happen
|
||||||
datestr = '(unknown date)'
|
datestr = '(unknown date)'
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -20,6 +20,10 @@
|
||||||
Client-mode SFTP support.
|
Client-mode SFTP support.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
import errno
|
import errno
|
||||||
import os
|
import os
|
||||||
|
@ -85,7 +89,7 @@ class SFTPClient (BaseSFTP):
|
||||||
self.ultra_debug = transport.get_hexdump()
|
self.ultra_debug = transport.get_hexdump()
|
||||||
try:
|
try:
|
||||||
server_version = self._send_version()
|
server_version = self._send_version()
|
||||||
except EOFError, x:
|
except EOFError as x:
|
||||||
raise SSHException('EOF during negotiation')
|
raise SSHException('EOF during negotiation')
|
||||||
self._log(INFO, 'Opened sftp connection (server version %d)' % server_version)
|
self._log(INFO, 'Opened sftp connection (server version %d)' % server_version)
|
||||||
|
|
||||||
|
@ -178,7 +182,7 @@ class SFTPClient (BaseSFTP):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
t, msg = self._request(CMD_READDIR, handle)
|
t, msg = self._request(CMD_READDIR, handle)
|
||||||
except EOFError, e:
|
except EOFError as e:
|
||||||
# done with handle
|
# done with handle
|
||||||
break
|
break
|
||||||
if t != CMD_NAME:
|
if t != CMD_NAME:
|
||||||
|
@ -285,10 +289,10 @@ class SFTPClient (BaseSFTP):
|
||||||
self._log(DEBUG, 'rename(%r, %r)' % (oldpath, newpath))
|
self._log(DEBUG, 'rename(%r, %r)' % (oldpath, newpath))
|
||||||
self._request(CMD_RENAME, oldpath, newpath)
|
self._request(CMD_RENAME, oldpath, newpath)
|
||||||
|
|
||||||
def mkdir(self, path, mode=0777):
|
def mkdir(self, path, mode= 0o777):
|
||||||
"""
|
"""
|
||||||
Create a folder (directory) named C{path} with numeric mode C{mode}.
|
Create a folder (directory) named C{path} with numeric mode C{mode}.
|
||||||
The default mode is 0777 (octal). On some systems, mode is ignored.
|
The default mode is 0o777 (octal). On some systems, mode is ignored.
|
||||||
Where it is used, the current umask value is first masked out.
|
Where it is used, the current umask value is first masked out.
|
||||||
|
|
||||||
@param path: name of the folder to create
|
@param path: name of the folder to create
|
||||||
|
@ -369,7 +373,7 @@ class SFTPClient (BaseSFTP):
|
||||||
"""
|
"""
|
||||||
dest = self._adjust_cwd(dest)
|
dest = self._adjust_cwd(dest)
|
||||||
self._log(DEBUG, 'symlink(%r, %r)' % (source, dest))
|
self._log(DEBUG, 'symlink(%r, %r)' % (source, dest))
|
||||||
if type(source) is unicode:
|
if isinstance(source, six.text_type):
|
||||||
source = source.encode('utf-8')
|
source = source.encode('utf-8')
|
||||||
self._request(CMD_SYMLINK, source, dest)
|
self._request(CMD_SYMLINK, source, dest)
|
||||||
|
|
||||||
|
@ -717,7 +721,7 @@ class SFTPClient (BaseSFTP):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
t, data = self._read_packet()
|
t, data = self._read_packet()
|
||||||
except EOFError, e:
|
except EOFError as e:
|
||||||
raise SSHException('Server connection dropped: %s' % (str(e),))
|
raise SSHException('Server connection dropped: %s' % (str(e),))
|
||||||
msg = Message(data)
|
msg = Message(data)
|
||||||
num = msg.get_int()
|
num = msg.get_int()
|
||||||
|
@ -770,7 +774,7 @@ class SFTPClient (BaseSFTP):
|
||||||
Return an adjusted path if we're emulating a "current working
|
Return an adjusted path if we're emulating a "current working
|
||||||
directory" for the server.
|
directory" for the server.
|
||||||
"""
|
"""
|
||||||
if type(path) is unicode:
|
if isinstance(path, six.text_type):
|
||||||
path = path.encode('utf-8')
|
path = path.encode('utf-8')
|
||||||
if self._cwd is None:
|
if self._cwd is None:
|
||||||
return path
|
return path
|
||||||
|
|
|
@ -20,6 +20,10 @@
|
||||||
L{SFTPFile}
|
L{SFTPFile}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
from collections import deque
|
from collections import deque
|
||||||
import socket
|
import socket
|
||||||
|
@ -464,7 +468,7 @@ class SFTPFile (BufferedFile):
|
||||||
# save exception and re-raise it on next file operation
|
# save exception and re-raise it on next file operation
|
||||||
try:
|
try:
|
||||||
self.sftp._convert_status(msg)
|
self.sftp._convert_status(msg)
|
||||||
except Exception, x:
|
except Exception as x:
|
||||||
self._saved_exception = x
|
self._saved_exception = x
|
||||||
return
|
return
|
||||||
if t != CMD_DATA:
|
if t != CMD_DATA:
|
||||||
|
|
|
@ -100,7 +100,7 @@ class SFTPHandle (object):
|
||||||
readfile.seek(offset)
|
readfile.seek(offset)
|
||||||
self.__tell = offset
|
self.__tell = offset
|
||||||
data = readfile.read(length)
|
data = readfile.read(length)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
self.__tell = None
|
self.__tell = None
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
self.__tell += len(data)
|
self.__tell += len(data)
|
||||||
|
@ -139,7 +139,7 @@ class SFTPHandle (object):
|
||||||
self.__tell = offset
|
self.__tell = offset
|
||||||
writefile.write(data)
|
writefile.write(data)
|
||||||
writefile.flush()
|
writefile.flush()
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
self.__tell = None
|
self.__tell = None
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
if self.__tell is not None:
|
if self.__tell is not None:
|
||||||
|
|
|
@ -92,7 +92,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
|
||||||
except EOFError:
|
except EOFError:
|
||||||
self._log(DEBUG, 'EOF -- end of session')
|
self._log(DEBUG, 'EOF -- end of session')
|
||||||
return
|
return
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self._log(DEBUG, 'Exception on channel: ' + str(e))
|
self._log(DEBUG, 'Exception on channel: ' + str(e))
|
||||||
self._log(DEBUG, util.tb_strings())
|
self._log(DEBUG, util.tb_strings())
|
||||||
return
|
return
|
||||||
|
@ -100,7 +100,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
|
||||||
request_number = msg.get_int()
|
request_number = msg.get_int()
|
||||||
try:
|
try:
|
||||||
self._process(t, request_number, msg)
|
self._process(t, request_number, msg)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self._log(DEBUG, 'Exception in server processing: ' + str(e))
|
self._log(DEBUG, 'Exception in server processing: ' + str(e))
|
||||||
self._log(DEBUG, util.tb_strings())
|
self._log(DEBUG, util.tb_strings())
|
||||||
# send some kind of failure message, at least
|
# send some kind of failure message, at least
|
||||||
|
|
|
@ -25,10 +25,15 @@ import socket
|
||||||
import string
|
import string
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
import paramiko
|
import paramiko
|
||||||
from paramiko import util
|
from paramiko import util
|
||||||
from paramiko.auth_handler import AuthHandler
|
from paramiko.auth_handler import AuthHandler
|
||||||
|
@ -78,7 +83,8 @@ class SecurityOptions (object):
|
||||||
C{ValueError} will be raised. If you try to assign something besides a
|
C{ValueError} will be raised. If you try to assign something besides a
|
||||||
tuple to one of the fields, C{TypeError} will be raised.
|
tuple to one of the fields, C{TypeError} will be raised.
|
||||||
"""
|
"""
|
||||||
__slots__ = [ 'ciphers', 'digests', 'key_types', 'kex', 'compression', '_transport' ]
|
# TODO: Come up a more elegant fix...
|
||||||
|
#__slots__ = [ 'ciphers', 'digests', 'key_types', 'kex', 'compression', '_transport' ]
|
||||||
|
|
||||||
def __init__(self, transport):
|
def __init__(self, transport):
|
||||||
self._transport = transport
|
self._transport = transport
|
||||||
|
@ -274,7 +280,7 @@ class Transport (threading.Thread):
|
||||||
@param sock: a socket or socket-like object to create the session over.
|
@param sock: a socket or socket-like object to create the session over.
|
||||||
@type sock: socket
|
@type sock: socket
|
||||||
"""
|
"""
|
||||||
if isinstance(sock, (str, unicode)):
|
if isinstance(sock, (six.binary_type, six.text_type)):
|
||||||
# convert "host:port" into (host, port)
|
# convert "host:port" into (host, port)
|
||||||
hl = sock.split(':', 1)
|
hl = sock.split(':', 1)
|
||||||
if len(hl) == 1:
|
if len(hl) == 1:
|
||||||
|
@ -292,7 +298,7 @@ class Transport (threading.Thread):
|
||||||
sock = socket.socket(af, socket.SOCK_STREAM)
|
sock = socket.socket(af, socket.SOCK_STREAM)
|
||||||
try:
|
try:
|
||||||
retry_on_signal(lambda: sock.connect((hostname, port)))
|
retry_on_signal(lambda: sock.connect((hostname, port)))
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
reason = str(e)
|
reason = str(e)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
@ -374,7 +380,8 @@ class Transport (threading.Thread):
|
||||||
|
|
||||||
@rtype: str
|
@rtype: str
|
||||||
"""
|
"""
|
||||||
out = '<paramiko.Transport at %s' % hex(long(id(self)) & 0xffffffffL)
|
|
||||||
|
out = '<paramiko.Transport at %s' % hex(long(id(self)) & long(0xffffffff))
|
||||||
if not self.active:
|
if not self.active:
|
||||||
out += ' (unconnected)'
|
out += ' (unconnected)'
|
||||||
else:
|
else:
|
||||||
|
@ -691,17 +698,17 @@ class Transport (threading.Thread):
|
||||||
"""
|
"""
|
||||||
return self.open_channel('auth-agent@openssh.com')
|
return self.open_channel('auth-agent@openssh.com')
|
||||||
|
|
||||||
def open_forwarded_tcpip_channel(self, (src_addr, src_port), (dest_addr, dest_port)):
|
def open_forwarded_tcpip_channel(self, src, dest):
|
||||||
"""
|
"""
|
||||||
Request a new channel back to the client, of type C{"forwarded-tcpip"}.
|
Request a new channel back to the client, of type C{"forwarded-tcpip"}.
|
||||||
This is used after a client has requested port forwarding, for sending
|
This is used after a client has requested port forwarding, for sending
|
||||||
incoming connections back to the client.
|
incoming connections back to the client.
|
||||||
|
|
||||||
@param src_addr: originator's address
|
@param src: tuple of the originator (address, port)
|
||||||
@param src_port: originator's port
|
@param dest: tuple of the local (server) connected (address, port)
|
||||||
@param dest_addr: local (server) connected address
|
|
||||||
@param dest_port: local (server) connected port
|
|
||||||
"""
|
"""
|
||||||
|
src_addr, src_port = src
|
||||||
|
dest_addr, dest_port = dest
|
||||||
return self.open_channel('forwarded-tcpip', (dest_addr, dest_port), (src_addr, src_port))
|
return self.open_channel('forwarded-tcpip', (dest_addr, dest_port), (src_addr, src_port))
|
||||||
|
|
||||||
def open_channel(self, kind, dest_addr=None, src_addr=None):
|
def open_channel(self, kind, dest_addr=None, src_addr=None):
|
||||||
|
@ -756,7 +763,7 @@ class Transport (threading.Thread):
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
self._send_user_message(m)
|
self._send_user_message(m)
|
||||||
while True:
|
while True:
|
||||||
event.wait(0.1);
|
event.wait(0.1)
|
||||||
if not self.active:
|
if not self.active:
|
||||||
e = self.get_exception()
|
e = self.get_exception()
|
||||||
if e is None:
|
if e is None:
|
||||||
|
@ -811,7 +818,9 @@ class Transport (threading.Thread):
|
||||||
if port == 0:
|
if port == 0:
|
||||||
port = response.get_int()
|
port = response.get_int()
|
||||||
if handler is None:
|
if handler is None:
|
||||||
def default_handler(channel, (src_addr, src_port), (dest_addr, dest_port)):
|
def default_handler(channel, src, dest):
|
||||||
|
src_addr, src_port = src
|
||||||
|
dest_addr, dest_port = dest
|
||||||
self._queue_incoming_channel(channel)
|
self._queue_incoming_channel(channel)
|
||||||
handler = default_handler
|
handler = default_handler
|
||||||
self._tcp_handler = handler
|
self._tcp_handler = handler
|
||||||
|
@ -1181,7 +1190,7 @@ class Transport (threading.Thread):
|
||||||
return []
|
return []
|
||||||
try:
|
try:
|
||||||
return self.auth_handler.wait_for_response(my_event)
|
return self.auth_handler.wait_for_response(my_event)
|
||||||
except BadAuthenticationType, x:
|
except BadAuthenticationType as x:
|
||||||
# if password auth isn't allowed, but keyboard-interactive *is*, try to fudge it
|
# if password auth isn't allowed, but keyboard-interactive *is*, try to fudge it
|
||||||
if not fallback or ('keyboard-interactive' not in x.allowed_types):
|
if not fallback or ('keyboard-interactive' not in x.allowed_types):
|
||||||
raise
|
raise
|
||||||
|
@ -1197,7 +1206,7 @@ class Transport (threading.Thread):
|
||||||
return []
|
return []
|
||||||
return [ password ]
|
return [ password ]
|
||||||
return self.auth_interactive(username, handler)
|
return self.auth_interactive(username, handler)
|
||||||
except SSHException, ignored:
|
except SSHException as ignored:
|
||||||
# attempt failed; just raise the original exception
|
# attempt failed; just raise the original exception
|
||||||
raise x
|
raise x
|
||||||
return None
|
return None
|
||||||
|
@ -1511,7 +1520,8 @@ class Transport (threading.Thread):
|
||||||
# only called if a channel has turned on x11 forwarding
|
# only called if a channel has turned on x11 forwarding
|
||||||
if handler is None:
|
if handler is None:
|
||||||
# by default, use the same mechanism as accept()
|
# by default, use the same mechanism as accept()
|
||||||
def default_handler(channel, (src_addr, src_port)):
|
def default_handler(channel, src):
|
||||||
|
src_addr, src_port = src
|
||||||
self._queue_incoming_channel(channel)
|
self._queue_incoming_channel(channel)
|
||||||
self._x11_handler = default_handler
|
self._x11_handler = default_handler
|
||||||
else:
|
else:
|
||||||
|
@ -1546,9 +1556,9 @@ class Transport (threading.Thread):
|
||||||
# active=True occurs before the thread is launched, to avoid a race
|
# active=True occurs before the thread is launched, to avoid a race
|
||||||
_active_threads.append(self)
|
_active_threads.append(self)
|
||||||
if self.server_mode:
|
if self.server_mode:
|
||||||
self._log(DEBUG, 'starting thread (server mode): %s' % hex(long(id(self)) & 0xffffffffL))
|
self._log(DEBUG, 'starting thread (server mode): %s' % hex(long(id(self)) & long(0xffffffff)))
|
||||||
else:
|
else:
|
||||||
self._log(DEBUG, 'starting thread (client mode): %s' % hex(long(id(self)) & 0xffffffffL))
|
self._log(DEBUG, 'starting thread (client mode): %s' % hex(long(id(self)) & long(0xffffffff)))
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
self.packetizer.write_all(self.local_version + '\r\n')
|
self.packetizer.write_all(self.local_version + '\r\n')
|
||||||
|
@ -1602,22 +1612,22 @@ class Transport (threading.Thread):
|
||||||
msg.add_byte(chr(MSG_UNIMPLEMENTED))
|
msg.add_byte(chr(MSG_UNIMPLEMENTED))
|
||||||
msg.add_int(m.seqno)
|
msg.add_int(m.seqno)
|
||||||
self._send_message(msg)
|
self._send_message(msg)
|
||||||
except SSHException, e:
|
except SSHException as e:
|
||||||
self._log(ERROR, 'Exception: ' + str(e))
|
self._log(ERROR, 'Exception: ' + str(e))
|
||||||
self._log(ERROR, util.tb_strings())
|
self._log(ERROR, util.tb_strings())
|
||||||
self.saved_exception = e
|
self.saved_exception = e
|
||||||
except EOFError, e:
|
except EOFError as e:
|
||||||
self._log(DEBUG, 'EOF in transport thread')
|
self._log(DEBUG, 'EOF in transport thread')
|
||||||
#self._log(DEBUG, util.tb_strings())
|
#self._log(DEBUG, util.tb_strings())
|
||||||
self.saved_exception = e
|
self.saved_exception = e
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
if type(e.args) is tuple:
|
if type(e.args) is tuple:
|
||||||
emsg = '%s (%d)' % (e.args[1], e.args[0])
|
emsg = '%s (%d)' % (e.args[1], e.args[0])
|
||||||
else:
|
else:
|
||||||
emsg = e.args
|
emsg = e.args
|
||||||
self._log(ERROR, 'Socket exception: ' + emsg)
|
self._log(ERROR, 'Socket exception: ' + emsg)
|
||||||
self.saved_exception = e
|
self.saved_exception = e
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self._log(ERROR, 'Unknown exception: ' + str(e))
|
self._log(ERROR, 'Unknown exception: ' + str(e))
|
||||||
self._log(ERROR, util.tb_strings())
|
self._log(ERROR, util.tb_strings())
|
||||||
self.saved_exception = e
|
self.saved_exception = e
|
||||||
|
@ -1677,7 +1687,7 @@ class Transport (threading.Thread):
|
||||||
buf = self.packetizer.readline(timeout)
|
buf = self.packetizer.readline(timeout)
|
||||||
except ProxyCommandFailure:
|
except ProxyCommandFailure:
|
||||||
raise
|
raise
|
||||||
except Exception, x:
|
except Exception as x:
|
||||||
raise SSHException('Error reading SSH protocol banner' + str(x))
|
raise SSHException('Error reading SSH protocol banner' + str(x))
|
||||||
if buf[:4] == 'SSH-':
|
if buf[:4] == 'SSH-':
|
||||||
break
|
break
|
||||||
|
|
|
@ -25,7 +25,7 @@ from __future__ import generators
|
||||||
import array
|
import array
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
import errno
|
import errno
|
||||||
import sys
|
|
||||||
import struct
|
import struct
|
||||||
import traceback
|
import traceback
|
||||||
import threading
|
import threading
|
||||||
|
@ -33,6 +33,9 @@ import threading
|
||||||
from paramiko.common import *
|
from paramiko.common import *
|
||||||
from paramiko.config import SSHConfig
|
from paramiko.config import SSHConfig
|
||||||
|
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
# Change by RogerB - python < 2.3 doesn't have enumerate so we implement it
|
# Change by RogerB - python < 2.3 doesn't have enumerate so we implement it
|
||||||
if sys.version_info < (2,3):
|
if sys.version_info < (2,3):
|
||||||
|
@ -48,7 +51,7 @@ if sys.version_info < (2,3):
|
||||||
|
|
||||||
def inflate_long(s, always_positive=False):
|
def inflate_long(s, always_positive=False):
|
||||||
"turns a normalized byte string into a long-int (adapted from Crypto.Util.number)"
|
"turns a normalized byte string into a long-int (adapted from Crypto.Util.number)"
|
||||||
out = 0L
|
out = 0
|
||||||
negative = 0
|
negative = 0
|
||||||
if not always_positive and (len(s) > 0) and (ord(s[0]) >= 0x80):
|
if not always_positive and (len(s) > 0) and (ord(s[0]) >= 0x80):
|
||||||
negative = 1
|
negative = 1
|
||||||
|
@ -60,7 +63,7 @@ def inflate_long(s, always_positive=False):
|
||||||
for i in range(0, len(s), 4):
|
for i in range(0, len(s), 4):
|
||||||
out = (out << 32) + struct.unpack('>I', s[i:i+4])[0]
|
out = (out << 32) + struct.unpack('>I', s[i:i+4])[0]
|
||||||
if negative:
|
if negative:
|
||||||
out -= (1L << (8 * len(s)))
|
out -= (long(1) << (8 * len(s)))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def deflate_long(n, add_sign_padding=True):
|
def deflate_long(n, add_sign_padding=True):
|
||||||
|
@ -69,7 +72,7 @@ def deflate_long(n, add_sign_padding=True):
|
||||||
s = ''
|
s = ''
|
||||||
n = long(n)
|
n = long(n)
|
||||||
while (n != 0) and (n != -1):
|
while (n != 0) and (n != -1):
|
||||||
s = struct.pack('>I', n & 0xffffffffL) + s
|
s = struct.pack('>I', n & long(0xffffffff)) + s
|
||||||
n = n >> 32
|
n = n >> 32
|
||||||
# strip off leading zeros, FFs
|
# strip off leading zeros, FFs
|
||||||
for i in enumerate(s):
|
for i in enumerate(s):
|
||||||
|
@ -276,13 +279,13 @@ def retry_on_signal(function):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
return function()
|
return function()
|
||||||
except EnvironmentError, e:
|
except EnvironmentError as e:
|
||||||
if e.errno != errno.EINTR:
|
if e.errno != errno.EINTR:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
class Counter (object):
|
class Counter (object):
|
||||||
"""Stateful counter for CTR mode crypto"""
|
"""Stateful counter for CTR mode crypto"""
|
||||||
def __init__(self, nbits, initial_value=1L, overflow=0L):
|
def __init__(self, nbits, initial_value=long(1), overflow=0):
|
||||||
self.blocksize = nbits / 8
|
self.blocksize = nbits / 8
|
||||||
self.overflow = overflow
|
self.overflow = overflow
|
||||||
# start with value - 1 so we don't have to store intermediate values when counting
|
# start with value - 1 so we don't have to store intermediate values when counting
|
||||||
|
@ -306,6 +309,6 @@ class Counter (object):
|
||||||
self.value = array.array('c', '\x00' * (self.blocksize - len(x)) + x)
|
self.value = array.array('c', '\x00' * (self.blocksize - len(x)) + x)
|
||||||
return self.value.tostring()
|
return self.value.tostring()
|
||||||
|
|
||||||
def new(cls, nbits, initial_value=1L, overflow=0L):
|
def new(cls, nbits, initial_value=long(1), overflow=0):
|
||||||
return cls(nbits, initial_value=initial_value, overflow=overflow)
|
return cls(nbits, initial_value=initial_value, overflow=overflow)
|
||||||
new = classmethod(new)
|
new = classmethod(new)
|
||||||
|
|
|
@ -38,7 +38,7 @@ class StubSFTPHandle (SFTPHandle):
|
||||||
def stat(self):
|
def stat(self):
|
||||||
try:
|
try:
|
||||||
return SFTPAttributes.from_stat(os.fstat(self.readfile.fileno()))
|
return SFTPAttributes.from_stat(os.fstat(self.readfile.fileno()))
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
|
|
||||||
def chattr(self, attr):
|
def chattr(self, attr):
|
||||||
|
@ -47,7 +47,7 @@ class StubSFTPHandle (SFTPHandle):
|
||||||
try:
|
try:
|
||||||
SFTPServer.set_file_attr(self.filename, attr)
|
SFTPServer.set_file_attr(self.filename, attr)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,21 +69,21 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
attr.filename = fname
|
attr.filename = fname
|
||||||
out.append(attr)
|
out.append(attr)
|
||||||
return out
|
return out
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
|
|
||||||
def stat(self, path):
|
def stat(self, path):
|
||||||
path = self._realpath(path)
|
path = self._realpath(path)
|
||||||
try:
|
try:
|
||||||
return SFTPAttributes.from_stat(os.stat(path))
|
return SFTPAttributes.from_stat(os.stat(path))
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
|
|
||||||
def lstat(self, path):
|
def lstat(self, path):
|
||||||
path = self._realpath(path)
|
path = self._realpath(path)
|
||||||
try:
|
try:
|
||||||
return SFTPAttributes.from_stat(os.lstat(path))
|
return SFTPAttributes.from_stat(os.lstat(path))
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
|
|
||||||
def open(self, path, flags, attr):
|
def open(self, path, flags, attr):
|
||||||
|
@ -95,10 +95,10 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
if mode is not None:
|
if mode is not None:
|
||||||
fd = os.open(path, flags, mode)
|
fd = os.open(path, flags, mode)
|
||||||
else:
|
else:
|
||||||
# os.open() defaults to 0777 which is
|
# os.open() defaults to 0o777 which is
|
||||||
# an odd default mode for files
|
# an odd default mode for files
|
||||||
fd = os.open(path, flags, 0666)
|
fd = os.open(path, flags, 0o666)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
if (flags & os.O_CREAT) and (attr is not None):
|
if (flags & os.O_CREAT) and (attr is not None):
|
||||||
attr._flags &= ~attr.FLAG_PERMISSIONS
|
attr._flags &= ~attr.FLAG_PERMISSIONS
|
||||||
|
@ -118,7 +118,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
fstr = 'rb'
|
fstr = 'rb'
|
||||||
try:
|
try:
|
||||||
f = os.fdopen(fd, fstr)
|
f = os.fdopen(fd, fstr)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
fobj = StubSFTPHandle(flags)
|
fobj = StubSFTPHandle(flags)
|
||||||
fobj.filename = path
|
fobj.filename = path
|
||||||
|
@ -130,7 +130,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
path = self._realpath(path)
|
path = self._realpath(path)
|
||||||
try:
|
try:
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
newpath = self._realpath(newpath)
|
newpath = self._realpath(newpath)
|
||||||
try:
|
try:
|
||||||
os.rename(oldpath, newpath)
|
os.rename(oldpath, newpath)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
if attr is not None:
|
if attr is not None:
|
||||||
SFTPServer.set_file_attr(path, attr)
|
SFTPServer.set_file_attr(path, attr)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
path = self._realpath(path)
|
path = self._realpath(path)
|
||||||
try:
|
try:
|
||||||
os.rmdir(path)
|
os.rmdir(path)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
path = self._realpath(path)
|
path = self._realpath(path)
|
||||||
try:
|
try:
|
||||||
SFTPServer.set_file_attr(path, attr)
|
SFTPServer.set_file_attr(path, attr)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
target_path = '<error>'
|
target_path = '<error>'
|
||||||
try:
|
try:
|
||||||
os.symlink(target_path, path)
|
os.symlink(target_path, path)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
path = self._realpath(path)
|
path = self._realpath(path)
|
||||||
try:
|
try:
|
||||||
symlink = os.readlink(path)
|
symlink = os.readlink(path)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
# if it's absolute, remove the root
|
# if it's absolute, remove the root
|
||||||
if os.path.isabs(symlink):
|
if os.path.isabs(symlink):
|
||||||
|
|
|
@ -27,6 +27,10 @@ from paramiko.kex_group1 import KexGroup1
|
||||||
from paramiko.kex_gex import KexGex
|
from paramiko.kex_gex import KexGex
|
||||||
from paramiko import Message
|
from paramiko import Message
|
||||||
|
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
|
|
||||||
class FakeRng (object):
|
class FakeRng (object):
|
||||||
def read(self, n):
|
def read(self, n):
|
||||||
|
@ -41,7 +45,7 @@ class FakeKey (object):
|
||||||
|
|
||||||
|
|
||||||
class FakeModulusPack (object):
|
class FakeModulusPack (object):
|
||||||
P = 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFFL
|
P = long(0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF)
|
||||||
G = 2
|
G = 2
|
||||||
def get_modulus(self, min, ask, max):
|
def get_modulus(self, min, ask, max):
|
||||||
return self.G, self.P
|
return self.G, self.P
|
||||||
|
@ -75,7 +79,7 @@ class FakeTransport (object):
|
||||||
|
|
||||||
class KexTest (unittest.TestCase):
|
class KexTest (unittest.TestCase):
|
||||||
|
|
||||||
K = 14730343317708716439807310032871972459448364195094179797249681733965528989482751523943515690110179031004049109375612685505881911274101441415545039654102474376472240501616988799699744135291070488314748284283496055223852115360852283821334858541043710301057312858051901453919067023103730011648890038847384890504L
|
K = long(14730343317708716439807310032871972459448364195094179797249681733965528989482751523943515690110179031004049109375612685505881911274101441415545039654102474376472240501616988799699744135291070488314748284283496055223852115360852283821334858541043710301057312858051901453919067023103730011648890038847384890504)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
@ -204,7 +208,7 @@ class KexTest (unittest.TestCase):
|
||||||
msg.add_mpint(12345)
|
msg.add_mpint(12345)
|
||||||
msg.rewind()
|
msg.rewind()
|
||||||
kex.parse_next(paramiko.kex_gex._MSG_KEXDH_GEX_INIT, msg)
|
kex.parse_next(paramiko.kex_gex._MSG_KEXDH_GEX_INIT, msg)
|
||||||
K = 67592995013596137876033460028393339951879041140378510871612128162185209509220726296697886624612526735888348020498716482757677848959420073720160491114319163078862905400020959196386947926388406687288901564192071077389283980347784184487280885335302632305026248574716290537036069329724382811853044654824945750581L
|
K = long(67592995013596137876033460028393339951879041140378510871612128162185209509220726296697886624612526735888348020498716482757677848959420073720160491114319163078862905400020959196386947926388406687288901564192071077389283980347784184487280885335302632305026248574716290537036069329724382811853044654824945750581)
|
||||||
H = 'CE754197C21BF3452863B4F44D0B3951F12516EF'
|
H = 'CE754197C21BF3452863B4F44D0B3951F12516EF'
|
||||||
x = '210000000866616B652D6B6579000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D40000000866616B652D736967'
|
x = '210000000866616B652D6B6579000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D40000000866616B652D736967'
|
||||||
self.assertEquals(K, transport._K)
|
self.assertEquals(K, transport._K)
|
||||||
|
@ -231,7 +235,7 @@ class KexTest (unittest.TestCase):
|
||||||
msg.add_mpint(12345)
|
msg.add_mpint(12345)
|
||||||
msg.rewind()
|
msg.rewind()
|
||||||
kex.parse_next(paramiko.kex_gex._MSG_KEXDH_GEX_INIT, msg)
|
kex.parse_next(paramiko.kex_gex._MSG_KEXDH_GEX_INIT, msg)
|
||||||
K = 67592995013596137876033460028393339951879041140378510871612128162185209509220726296697886624612526735888348020498716482757677848959420073720160491114319163078862905400020959196386947926388406687288901564192071077389283980347784184487280885335302632305026248574716290537036069329724382811853044654824945750581L
|
K = long(67592995013596137876033460028393339951879041140378510871612128162185209509220726296697886624612526735888348020498716482757677848959420073720160491114319163078862905400020959196386947926388406687288901564192071077389283980347784184487280885335302632305026248574716290537036069329724382811853044654824945750581)
|
||||||
H = 'B41A06B2E59043CEFC1AE16EC31F1E2D12EC455B'
|
H = 'B41A06B2E59043CEFC1AE16EC31F1E2D12EC455B'
|
||||||
x = '210000000866616B652D6B6579000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D40000000866616B652D736967'
|
x = '210000000866616B652D6B6579000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D40000000866616B652D736967'
|
||||||
self.assertEquals(K, transport._K)
|
self.assertEquals(K, transport._K)
|
||||||
|
|
|
@ -20,6 +20,10 @@
|
||||||
Some unit tests for ssh protocol message blocks.
|
Some unit tests for ssh protocol message blocks.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from paramiko.message import Message
|
from paramiko.message import Message
|
||||||
|
|
||||||
|
@ -50,10 +54,10 @@ class MessageTest (unittest.TestCase):
|
||||||
|
|
||||||
msg = Message()
|
msg = Message()
|
||||||
msg.add_int64(5)
|
msg.add_int64(5)
|
||||||
msg.add_int64(0xf5e4d3c2b109L)
|
msg.add_int64(long(0xf5e4d3c2b109))
|
||||||
msg.add_mpint(17)
|
msg.add_mpint(17)
|
||||||
msg.add_mpint(0xf5e4d3c2b109L)
|
msg.add_mpint(long(0xf5e4d3c2b109))
|
||||||
msg.add_mpint(-0x65e4d3c2b109L)
|
msg.add_mpint(long(-0x65e4d3c2b109))
|
||||||
self.assertEquals(str(msg), self.__c)
|
self.assertEquals(str(msg), self.__c)
|
||||||
|
|
||||||
def test_2_decode(self):
|
def test_2_decode(self):
|
||||||
|
@ -73,15 +77,15 @@ class MessageTest (unittest.TestCase):
|
||||||
|
|
||||||
msg = Message(self.__c)
|
msg = Message(self.__c)
|
||||||
self.assertEquals(msg.get_int64(), 5)
|
self.assertEquals(msg.get_int64(), 5)
|
||||||
self.assertEquals(msg.get_int64(), 0xf5e4d3c2b109L)
|
self.assertEquals(msg.get_int64(), long(0xf5e4d3c2b109))
|
||||||
self.assertEquals(msg.get_mpint(), 17)
|
self.assertEquals(msg.get_mpint(), 17)
|
||||||
self.assertEquals(msg.get_mpint(), 0xf5e4d3c2b109L)
|
self.assertEquals(msg.get_mpint(), long(0xf5e4d3c2b109))
|
||||||
self.assertEquals(msg.get_mpint(), -0x65e4d3c2b109L)
|
self.assertEquals(msg.get_mpint(), long(-0x65e4d3c2b109))
|
||||||
|
|
||||||
def test_3_add(self):
|
def test_3_add(self):
|
||||||
msg = Message()
|
msg = Message()
|
||||||
msg.add(5)
|
msg.add(5)
|
||||||
msg.add(0x1122334455L)
|
msg.add(long(0x1122334455))
|
||||||
msg.add(True)
|
msg.add(True)
|
||||||
msg.add('cat')
|
msg.add('cat')
|
||||||
msg.add(['a', 'b'])
|
msg.add(['a', 'b'])
|
||||||
|
@ -90,7 +94,7 @@ class MessageTest (unittest.TestCase):
|
||||||
def test_4_misc(self):
|
def test_4_misc(self):
|
||||||
msg = Message(self.__d)
|
msg = Message(self.__d)
|
||||||
self.assertEquals(msg.get_int(), 5)
|
self.assertEquals(msg.get_int(), 5)
|
||||||
self.assertEquals(msg.get_mpint(), 0x1122334455L)
|
self.assertEquals(msg.get_mpint(), long(0x1122334455))
|
||||||
self.assertEquals(msg.get_so_far(), self.__d[:13])
|
self.assertEquals(msg.get_so_far(), self.__d[:13])
|
||||||
self.assertEquals(msg.get_remainder(), self.__d[13:])
|
self.assertEquals(msg.get_remainder(), self.__d[13:])
|
||||||
msg.rewind()
|
msg.rewind()
|
||||||
|
|
|
@ -21,7 +21,10 @@ Some unit tests for public/private key objects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
import StringIO
|
try:
|
||||||
|
from StringIO import StringIO
|
||||||
|
except ImportError:
|
||||||
|
from io import StringIO
|
||||||
import unittest
|
import unittest
|
||||||
from paramiko import RSAKey, DSSKey, Message, util
|
from paramiko import RSAKey, DSSKey, Message, util
|
||||||
from paramiko.common import rng
|
from paramiko.common import rng
|
||||||
|
@ -90,7 +93,7 @@ class KeyTest (unittest.TestCase):
|
||||||
self.assertEquals(PUB_RSA.split()[1], key.get_base64())
|
self.assertEquals(PUB_RSA.split()[1], key.get_base64())
|
||||||
self.assertEquals(1024, key.get_bits())
|
self.assertEquals(1024, key.get_bits())
|
||||||
|
|
||||||
s = StringIO.StringIO()
|
s = StringIO()
|
||||||
key.write_private_key(s)
|
key.write_private_key(s)
|
||||||
self.assertEquals(RSA_PRIVATE_OUT, s.getvalue())
|
self.assertEquals(RSA_PRIVATE_OUT, s.getvalue())
|
||||||
s.seek(0)
|
s.seek(0)
|
||||||
|
@ -115,7 +118,7 @@ class KeyTest (unittest.TestCase):
|
||||||
self.assertEquals(PUB_DSS.split()[1], key.get_base64())
|
self.assertEquals(PUB_DSS.split()[1], key.get_base64())
|
||||||
self.assertEquals(1024, key.get_bits())
|
self.assertEquals(1024, key.get_bits())
|
||||||
|
|
||||||
s = StringIO.StringIO()
|
s = StringIO()
|
||||||
key.write_private_key(s)
|
key.write_private_key(s)
|
||||||
self.assertEquals(DSS_PRIVATE_OUT, s.getvalue())
|
self.assertEquals(DSS_PRIVATE_OUT, s.getvalue())
|
||||||
s.seek(0)
|
s.seek(0)
|
||||||
|
|
|
@ -23,6 +23,7 @@ a real actual sftp server is contacted, and a new folder is created there to
|
||||||
do test file operations in (so no existing files will be harmed).
|
do test file operations in (so no existing files will be harmed).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
@ -31,7 +32,10 @@ import warnings
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import unittest
|
import unittest
|
||||||
import StringIO
|
try:
|
||||||
|
from StringIO import StringIO
|
||||||
|
except ImportError:
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
import paramiko
|
import paramiko
|
||||||
from stub_sftp import StubServer, StubSFTPServer
|
from stub_sftp import StubServer, StubSFTPServer
|
||||||
|
@ -300,16 +304,16 @@ class SFTPTest (unittest.TestCase):
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
stat = sftp.stat(FOLDER + '/special')
|
stat = sftp.stat(FOLDER + '/special')
|
||||||
sftp.chmod(FOLDER + '/special', (stat.st_mode & ~0777) | 0600)
|
sftp.chmod(FOLDER + '/special', (stat.st_mode & ~0o777) | 0o600)
|
||||||
stat = sftp.stat(FOLDER + '/special')
|
stat = sftp.stat(FOLDER + '/special')
|
||||||
expected_mode = 0600
|
expected_mode = 0o600
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
# chmod not really functional on windows
|
# chmod not really functional on windows
|
||||||
expected_mode = 0666
|
expected_mode = 0o666
|
||||||
if sys.platform == 'cygwin':
|
if sys.platform == 'cygwin':
|
||||||
# even worse.
|
# even worse.
|
||||||
expected_mode = 0644
|
expected_mode = 0o644
|
||||||
self.assertEqual(stat.st_mode & 0777, expected_mode)
|
self.assertEqual(stat.st_mode & 0o777, expected_mode)
|
||||||
self.assertEqual(stat.st_size, 1024)
|
self.assertEqual(stat.st_size, 1024)
|
||||||
|
|
||||||
mtime = stat.st_mtime - 3600
|
mtime = stat.st_mtime - 3600
|
||||||
|
@ -340,17 +344,17 @@ class SFTPTest (unittest.TestCase):
|
||||||
|
|
||||||
f = sftp.open(FOLDER + '/special', 'r+')
|
f = sftp.open(FOLDER + '/special', 'r+')
|
||||||
stat = f.stat()
|
stat = f.stat()
|
||||||
f.chmod((stat.st_mode & ~0777) | 0600)
|
f.chmod((stat.st_mode & ~0o777) | 0o600)
|
||||||
stat = f.stat()
|
stat = f.stat()
|
||||||
|
|
||||||
expected_mode = 0600
|
expected_mode = 0o600
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
# chmod not really functional on windows
|
# chmod not really functional on windows
|
||||||
expected_mode = 0666
|
expected_mode = 0o666
|
||||||
if sys.platform == 'cygwin':
|
if sys.platform == 'cygwin':
|
||||||
# even worse.
|
# even worse.
|
||||||
expected_mode = 0644
|
expected_mode = 0o644
|
||||||
self.assertEqual(stat.st_mode & 0777, expected_mode)
|
self.assertEqual(stat.st_mode & 0o777, expected_mode)
|
||||||
self.assertEqual(stat.st_size, 1024)
|
self.assertEqual(stat.st_size, 1024)
|
||||||
|
|
||||||
mtime = stat.st_mtime - 3600
|
mtime = stat.st_mtime - 3600
|
||||||
|
@ -644,7 +648,7 @@ class SFTPTest (unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
sftp.rename(FOLDER + '/something', FOLDER + u'/\u00fcnic\u00f8de')
|
sftp.rename(FOLDER + '/something', FOLDER + u'/\u00fcnic\u00f8de')
|
||||||
sftp.open(FOLDER + '/\xc3\xbcnic\xc3\xb8\x64\x65', 'r')
|
sftp.open(FOLDER + '/\xc3\xbcnic\xc3\xb8\x64\x65', 'r')
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.fail('exception ' + e)
|
self.fail('exception ' + e)
|
||||||
sftp.unlink(FOLDER + '/\xc3\xbcnic\xc3\xb8\x64\x65')
|
sftp.unlink(FOLDER + '/\xc3\xbcnic\xc3\xb8\x64\x65')
|
||||||
|
|
||||||
|
@ -731,7 +735,7 @@ class SFTPTest (unittest.TestCase):
|
||||||
Send an empty file and confirm it is sent.
|
Send an empty file and confirm it is sent.
|
||||||
"""
|
"""
|
||||||
target = FOLDER + '/empty file.txt'
|
target = FOLDER + '/empty file.txt'
|
||||||
stream = StringIO.StringIO()
|
stream = StringIO()
|
||||||
try:
|
try:
|
||||||
attrs = sftp.putfo(stream, target)
|
attrs = sftp.putfo(stream, target)
|
||||||
# the returned attributes should not be null
|
# the returned attributes should not be null
|
||||||
|
|
|
@ -68,7 +68,7 @@ class BigSFTPTest (unittest.TestCase):
|
||||||
f = sftp.open('%s/file%d.txt' % (FOLDER, i), 'w', 1)
|
f = sftp.open('%s/file%d.txt' % (FOLDER, i), 'w', 1)
|
||||||
f.write('this is file #%d.\n' % i)
|
f.write('this is file #%d.\n' % i)
|
||||||
f.close()
|
f.close()
|
||||||
sftp.chmod('%s/file%d.txt' % (FOLDER, i), 0660)
|
sftp.chmod('%s/file%d.txt' % (FOLDER, i), 0o660)
|
||||||
|
|
||||||
# now make sure every file is there, by creating a list of filenmes
|
# now make sure every file is there, by creating a list of filenmes
|
||||||
# and reading them in random order.
|
# and reading them in random order.
|
||||||
|
|
|
@ -29,6 +29,10 @@ import threading
|
||||||
import unittest
|
import unittest
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
from paramiko import Transport, SecurityOptions, ServerInterface, RSAKey, DSSKey, \
|
from paramiko import Transport, SecurityOptions, ServerInterface, RSAKey, DSSKey, \
|
||||||
SSHException, BadAuthenticationType, InteractiveQuery, ChannelException
|
SSHException, BadAuthenticationType, InteractiveQuery, ChannelException
|
||||||
from paramiko import AUTH_FAILED, AUTH_PARTIALLY_SUCCESSFUL, AUTH_SUCCESSFUL
|
from paramiko import AUTH_FAILED, AUTH_PARTIALLY_SUCCESSFUL, AUTH_SUCCESSFUL
|
||||||
|
@ -158,7 +162,7 @@ class TransportTest(ParamikoTest):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_2_compute_key(self):
|
def test_2_compute_key(self):
|
||||||
self.tc.K = 123281095979686581523377256114209720774539068973101330872763622971399429481072519713536292772709507296759612401802191955568143056534122385270077606457721553469730659233569339356140085284052436697480759510519672848743794433460113118986816826624865291116513647975790797391795651716378444844877749505443714557929L
|
self.tc.K = long(123281095979686581523377256114209720774539068973101330872763622971399429481072519713536292772709507296759612401802191955568143056534122385270077606457721553469730659233569339356140085284052436697480759510519672848743794433460113118986816826624865291116513647975790797391795651716378444844877749505443714557929)
|
||||||
self.tc.H = unhexlify('0C8307CDE6856FF30BA93684EB0F04C2520E9ED3')
|
self.tc.H = unhexlify('0C8307CDE6856FF30BA93684EB0F04C2520E9ED3')
|
||||||
self.tc.session_id = self.tc.H
|
self.tc.session_id = self.tc.H
|
||||||
key = self.tc._compute_key('C', 32)
|
key = self.tc._compute_key('C', 32)
|
||||||
|
@ -249,7 +253,7 @@ class TransportTest(ParamikoTest):
|
||||||
try:
|
try:
|
||||||
chan.exec_command('no')
|
chan.exec_command('no')
|
||||||
self.assert_(False)
|
self.assert_(False)
|
||||||
except SSHException, x:
|
except SSHException as x:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
chan = self.tc.open_session()
|
chan = self.tc.open_session()
|
||||||
|
@ -302,7 +306,7 @@ class TransportTest(ParamikoTest):
|
||||||
try:
|
try:
|
||||||
chan = self.tc.open_channel('bogus')
|
chan = self.tc.open_channel('bogus')
|
||||||
self.fail('expected exception')
|
self.fail('expected exception')
|
||||||
except ChannelException, x:
|
except ChannelException as x:
|
||||||
self.assert_(x.code == OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED)
|
self.assert_(x.code == OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED)
|
||||||
|
|
||||||
def test_9_exit_status(self):
|
def test_9_exit_status(self):
|
||||||
|
@ -444,7 +448,8 @@ class TransportTest(ParamikoTest):
|
||||||
schan = self.ts.accept(1.0)
|
schan = self.ts.accept(1.0)
|
||||||
|
|
||||||
requested = []
|
requested = []
|
||||||
def handler(c, (addr, port)):
|
def handler(c, remote):
|
||||||
|
addr, port = remote
|
||||||
requested.append((addr, port))
|
requested.append((addr, port))
|
||||||
self.tc._queue_incoming_channel(c)
|
self.tc._queue_incoming_channel(c)
|
||||||
|
|
||||||
|
@ -479,7 +484,9 @@ class TransportTest(ParamikoTest):
|
||||||
schan = self.ts.accept(1.0)
|
schan = self.ts.accept(1.0)
|
||||||
|
|
||||||
requested = []
|
requested = []
|
||||||
def handler(c, (origin_addr, origin_port), (server_addr, server_port)):
|
def handler(c, origin, server):
|
||||||
|
origin_addr, origin_port = origin
|
||||||
|
server_addr, server_port = server
|
||||||
requested.append((origin_addr, origin_port))
|
requested.append((origin_addr, origin_port))
|
||||||
requested.append((server_addr, server_port))
|
requested.append((server_addr, server_port))
|
||||||
self.tc._queue_incoming_channel(c)
|
self.tc._queue_incoming_channel(c)
|
||||||
|
|
|
@ -21,7 +21,10 @@ Some unit tests for utility functions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
import cStringIO
|
try:
|
||||||
|
from cStringIO import StringIO
|
||||||
|
except ImportError:
|
||||||
|
from io import StringIO
|
||||||
import errno
|
import errno
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -101,7 +104,7 @@ class UtilTest(ParamikoTest):
|
||||||
|
|
||||||
def test_2_parse_config(self):
|
def test_2_parse_config(self):
|
||||||
global test_config_file
|
global test_config_file
|
||||||
f = cStringIO.StringIO(test_config_file)
|
f = StringIO(test_config_file)
|
||||||
config = paramiko.util.parse_ssh_config(f)
|
config = paramiko.util.parse_ssh_config(f)
|
||||||
self.assertEquals(config._config,
|
self.assertEquals(config._config,
|
||||||
[{'host': ['*'], 'config': {}}, {'host': ['*'], 'config': {'identityfile': ['~/.ssh/id_rsa'], 'user': 'robey'}},
|
[{'host': ['*'], 'config': {}}, {'host': ['*'], 'config': {'identityfile': ['~/.ssh/id_rsa'], 'user': 'robey'}},
|
||||||
|
@ -111,7 +114,7 @@ class UtilTest(ParamikoTest):
|
||||||
|
|
||||||
def test_3_host_config(self):
|
def test_3_host_config(self):
|
||||||
global test_config_file
|
global test_config_file
|
||||||
f = cStringIO.StringIO(test_config_file)
|
f = StringIO(test_config_file)
|
||||||
config = paramiko.util.parse_ssh_config(f)
|
config = paramiko.util.parse_ssh_config(f)
|
||||||
|
|
||||||
for host, values in {
|
for host, values in {
|
||||||
|
@ -172,7 +175,7 @@ Host *.example.com
|
||||||
Host *
|
Host *
|
||||||
Port 3333
|
Port 3333
|
||||||
"""
|
"""
|
||||||
f = cStringIO.StringIO(test_config_file)
|
f = StringIO(test_config_file)
|
||||||
config = paramiko.util.parse_ssh_config(f)
|
config = paramiko.util.parse_ssh_config(f)
|
||||||
host = 'www13.example.com'
|
host = 'www13.example.com'
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
|
@ -216,7 +219,7 @@ Host space-delimited
|
||||||
Host equals-delimited
|
Host equals-delimited
|
||||||
ProxyCommand=foo bar=biz baz
|
ProxyCommand=foo bar=biz baz
|
||||||
"""
|
"""
|
||||||
f = cStringIO.StringIO(conf)
|
f = StringIO(conf)
|
||||||
config = paramiko.util.parse_ssh_config(f)
|
config = paramiko.util.parse_ssh_config(f)
|
||||||
for host in ('space-delimited', 'equals-delimited'):
|
for host in ('space-delimited', 'equals-delimited'):
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
|
@ -228,7 +231,7 @@ Host equals-delimited
|
||||||
"""
|
"""
|
||||||
ProxyCommand should perform interpolation on the value
|
ProxyCommand should perform interpolation on the value
|
||||||
"""
|
"""
|
||||||
config = paramiko.util.parse_ssh_config(cStringIO.StringIO("""
|
config = paramiko.util.parse_ssh_config(StringIO("""
|
||||||
Host specific
|
Host specific
|
||||||
Port 37
|
Port 37
|
||||||
ProxyCommand host %h port %p lol
|
ProxyCommand host %h port %p lol
|
||||||
|
@ -264,7 +267,7 @@ Host www13.*
|
||||||
Host *
|
Host *
|
||||||
Port 3333
|
Port 3333
|
||||||
"""
|
"""
|
||||||
f = cStringIO.StringIO(test_config_file)
|
f = StringIO(test_config_file)
|
||||||
config = paramiko.util.parse_ssh_config(f)
|
config = paramiko.util.parse_ssh_config(f)
|
||||||
host = 'www13.example.com'
|
host = 'www13.example.com'
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
|
@ -293,7 +296,7 @@ ProxyCommand foo=bar:%h-%p
|
||||||
'foo=bar:proxy-without-equal-divisor-22'}
|
'foo=bar:proxy-without-equal-divisor-22'}
|
||||||
}.items():
|
}.items():
|
||||||
|
|
||||||
f = cStringIO.StringIO(test_config_file)
|
f = StringIO(test_config_file)
|
||||||
config = paramiko.util.parse_ssh_config(f)
|
config = paramiko.util.parse_ssh_config(f)
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
paramiko.util.lookup_ssh_host_config(host, config),
|
paramiko.util.lookup_ssh_host_config(host, config),
|
||||||
|
@ -323,7 +326,7 @@ IdentityFile id_dsa22
|
||||||
'identityfile': ['id_dsa0', 'id_dsa1', 'id_dsa22']}
|
'identityfile': ['id_dsa0', 'id_dsa1', 'id_dsa22']}
|
||||||
}.items():
|
}.items():
|
||||||
|
|
||||||
f = cStringIO.StringIO(test_config_file)
|
f = StringIO(test_config_file)
|
||||||
config = paramiko.util.parse_ssh_config(f)
|
config = paramiko.util.parse_ssh_config(f)
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
paramiko.util.lookup_ssh_host_config(host, config),
|
paramiko.util.lookup_ssh_host_config(host, config),
|
||||||
|
|
Loading…
Reference in New Issue