2009-07-19 22:45:02 -04:00
|
|
|
# Copyright (C) 2003-2007 Robey Pointer <robeypointer@gmail.com>
|
2004-04-05 06:24:33 -04:00
|
|
|
#
|
|
|
|
# This file is part of paramiko.
|
|
|
|
#
|
|
|
|
# Paramiko is free software; you can redistribute it and/or modify it under the
|
|
|
|
# terms of the GNU Lesser General Public License as published by the Free
|
|
|
|
# Software Foundation; either version 2.1 of the License, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# Paramiko is distrubuted in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License
|
2004-06-10 14:12:00 -04:00
|
|
|
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
|
2004-04-05 06:24:33 -04:00
|
|
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Common constants and global variables.
|
|
|
|
"""
|
|
|
|
|
|
|
|
MSG_DISCONNECT, MSG_IGNORE, MSG_UNIMPLEMENTED, MSG_DEBUG, MSG_SERVICE_REQUEST, \
|
2007-11-19 14:44:55 -05:00
|
|
|
MSG_SERVICE_ACCEPT = range(1, 7)
|
2004-04-05 06:24:33 -04:00
|
|
|
MSG_KEXINIT, MSG_NEWKEYS = range(20, 22)
|
|
|
|
MSG_USERAUTH_REQUEST, MSG_USERAUTH_FAILURE, MSG_USERAUTH_SUCCESS, \
|
|
|
|
MSG_USERAUTH_BANNER = range(50, 54)
|
|
|
|
MSG_USERAUTH_PK_OK = 60
|
2005-09-21 18:42:11 -04:00
|
|
|
MSG_USERAUTH_INFO_REQUEST, MSG_USERAUTH_INFO_RESPONSE = range(60, 62)
|
2004-04-05 06:37:18 -04:00
|
|
|
MSG_GLOBAL_REQUEST, MSG_REQUEST_SUCCESS, MSG_REQUEST_FAILURE = range(80, 83)
|
2004-04-05 06:24:33 -04:00
|
|
|
MSG_CHANNEL_OPEN, MSG_CHANNEL_OPEN_SUCCESS, MSG_CHANNEL_OPEN_FAILURE, \
|
2007-11-19 14:44:55 -05:00
|
|
|
MSG_CHANNEL_WINDOW_ADJUST, MSG_CHANNEL_DATA, MSG_CHANNEL_EXTENDED_DATA, \
|
|
|
|
MSG_CHANNEL_EOF, MSG_CHANNEL_CLOSE, MSG_CHANNEL_REQUEST, \
|
|
|
|
MSG_CHANNEL_SUCCESS, MSG_CHANNEL_FAILURE = range(90, 101)
|
2004-04-05 06:24:33 -04:00
|
|
|
|
2005-10-13 14:52:59 -04:00
|
|
|
|
2004-10-31 22:43:28 -05:00
|
|
|
# for debugging:
|
|
|
|
MSG_NAMES = {
|
|
|
|
MSG_DISCONNECT: 'disconnect',
|
|
|
|
MSG_IGNORE: 'ignore',
|
|
|
|
MSG_UNIMPLEMENTED: 'unimplemented',
|
|
|
|
MSG_DEBUG: 'debug',
|
|
|
|
MSG_SERVICE_REQUEST: 'service-request',
|
|
|
|
MSG_SERVICE_ACCEPT: 'service-accept',
|
|
|
|
MSG_KEXINIT: 'kexinit',
|
|
|
|
MSG_NEWKEYS: 'newkeys',
|
2004-11-26 17:07:31 -05:00
|
|
|
30: 'kex30',
|
|
|
|
31: 'kex31',
|
|
|
|
32: 'kex32',
|
|
|
|
33: 'kex33',
|
|
|
|
34: 'kex34',
|
2004-10-31 22:43:28 -05:00
|
|
|
MSG_USERAUTH_REQUEST: 'userauth-request',
|
|
|
|
MSG_USERAUTH_FAILURE: 'userauth-failure',
|
|
|
|
MSG_USERAUTH_SUCCESS: 'userauth-success',
|
|
|
|
MSG_USERAUTH_BANNER: 'userauth--banner',
|
2005-09-21 18:42:11 -04:00
|
|
|
MSG_USERAUTH_PK_OK: 'userauth-60(pk-ok/info-request)',
|
|
|
|
MSG_USERAUTH_INFO_RESPONSE: 'userauth-info-response',
|
2004-10-31 22:43:28 -05:00
|
|
|
MSG_GLOBAL_REQUEST: 'global-request',
|
|
|
|
MSG_REQUEST_SUCCESS: 'request-success',
|
|
|
|
MSG_REQUEST_FAILURE: 'request-failure',
|
|
|
|
MSG_CHANNEL_OPEN: 'channel-open',
|
|
|
|
MSG_CHANNEL_OPEN_SUCCESS: 'channel-open-success',
|
|
|
|
MSG_CHANNEL_OPEN_FAILURE: 'channel-open-failure',
|
|
|
|
MSG_CHANNEL_WINDOW_ADJUST: 'channel-window-adjust',
|
|
|
|
MSG_CHANNEL_DATA: 'channel-data',
|
|
|
|
MSG_CHANNEL_EXTENDED_DATA: 'channel-extended-data',
|
|
|
|
MSG_CHANNEL_EOF: 'channel-eof',
|
|
|
|
MSG_CHANNEL_CLOSE: 'channel-close',
|
|
|
|
MSG_CHANNEL_REQUEST: 'channel-request',
|
|
|
|
MSG_CHANNEL_SUCCESS: 'channel-success',
|
|
|
|
MSG_CHANNEL_FAILURE: 'channel-failure'
|
|
|
|
}
|
2004-04-05 06:24:33 -04:00
|
|
|
|
2004-09-03 18:39:20 -04:00
|
|
|
|
2005-10-13 14:52:59 -04:00
|
|
|
# authentication request return codes:
|
2004-09-03 18:39:20 -04:00
|
|
|
AUTH_SUCCESSFUL, AUTH_PARTIALLY_SUCCESSFUL, AUTH_FAILED = range(3)
|
|
|
|
|
|
|
|
|
2004-04-05 06:24:33 -04:00
|
|
|
# channel request failed reasons:
|
2004-09-03 18:39:20 -04:00
|
|
|
(OPEN_SUCCEEDED,
|
|
|
|
OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED,
|
|
|
|
OPEN_FAILED_CONNECT_FAILED,
|
|
|
|
OPEN_FAILED_UNKNOWN_CHANNEL_TYPE,
|
|
|
|
OPEN_FAILED_RESOURCE_SHORTAGE) = range(0, 5)
|
|
|
|
|
2005-10-13 14:52:59 -04:00
|
|
|
|
2004-04-05 06:24:33 -04:00
|
|
|
CONNECTION_FAILED_CODE = {
|
|
|
|
1: 'Administratively prohibited',
|
|
|
|
2: 'Connect failed',
|
|
|
|
3: 'Unknown channel type',
|
|
|
|
4: 'Resource shortage'
|
|
|
|
}
|
|
|
|
|
2004-09-03 18:39:20 -04:00
|
|
|
|
2004-04-05 06:24:33 -04:00
|
|
|
DISCONNECT_SERVICE_NOT_AVAILABLE, DISCONNECT_AUTH_CANCELLED_BY_USER, \
|
|
|
|
DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE = 7, 13, 14
|
|
|
|
|
2010-08-02 18:13:08 -04:00
|
|
|
from Crypto import Random
|
2004-04-05 06:24:33 -04:00
|
|
|
|
|
|
|
# keep a crypto-strong PRNG nearby
|
2010-08-02 18:13:08 -04:00
|
|
|
rng = Random.new()
|
2004-04-06 04:16:02 -04:00
|
|
|
|
|
|
|
import sys
|
|
|
|
if sys.version_info < (2, 3):
|
2004-04-07 02:07:29 -04:00
|
|
|
try:
|
|
|
|
import logging
|
|
|
|
except:
|
|
|
|
import logging22 as logging
|
2004-04-06 04:16:02 -04:00
|
|
|
import select
|
|
|
|
PY22 = True
|
2004-04-08 01:12:20 -04:00
|
|
|
|
|
|
|
import socket
|
|
|
|
if not hasattr(socket, 'timeout'):
|
|
|
|
class timeout(socket.error): pass
|
|
|
|
socket.timeout = timeout
|
|
|
|
del timeout
|
2004-04-06 04:16:02 -04:00
|
|
|
else:
|
|
|
|
import logging
|
|
|
|
PY22 = False
|
|
|
|
|
2006-01-30 19:56:29 -05:00
|
|
|
|
2004-04-06 04:16:02 -04:00
|
|
|
DEBUG = logging.DEBUG
|
|
|
|
INFO = logging.INFO
|
|
|
|
WARNING = logging.WARNING
|
|
|
|
ERROR = logging.ERROR
|
|
|
|
CRITICAL = logging.CRITICAL
|
2012-01-17 15:10:57 -05:00
|
|
|
|
|
|
|
# Common IO/select/etc sleep period, in seconds
|
|
|
|
io_sleep = 0.01
|