Skip to content

Commit fac6cde

Browse files
committed
Merge branch '1.11' into 1.12
Conflicts: paramiko/hostkeys.py
2 parents 0965eaa + 72a73f5 commit fac6cde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2140
-2398
lines changed

fabfile.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

paramiko/__init__.py

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,10 @@
1616
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
1717
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
1818

19-
"""
20-
I{Paramiko} (a combination of the esperanto words for "paranoid" and "friend")
21-
is a module for python 2.5 or greater that implements the SSH2 protocol for
22-
secure (encrypted and authenticated) connections to remote machines. Unlike
23-
SSL (aka TLS), the SSH2 protocol does not require hierarchical certificates
24-
signed by a powerful central authority. You may know SSH2 as the protocol that
25-
replaced C{telnet} and C{rsh} for secure access to remote shells, but the
26-
protocol also includes the ability to open arbitrary channels to remote
27-
services across an encrypted tunnel. (This is how C{sftp} works, for example.)
28-
29-
The high-level client API starts with creation of an L{SSHClient} object.
30-
For more direct control, pass a socket (or socket-like object) to a
31-
L{Transport}, and use L{start_server <Transport.start_server>} or
32-
L{start_client <Transport.start_client>} to negoatite
33-
with the remote host as either a server or client. As a client, you are
34-
responsible for authenticating using a password or private key, and checking
35-
the server's host key. I{(Key signature and verification is done by paramiko,
36-
but you will need to provide private keys and check that the content of a
37-
public key matches what you expected to see.)} As a server, you are
38-
responsible for deciding which users, passwords, and keys to allow, and what
39-
kind of channels to allow.
40-
41-
Once you have finished, either side may request flow-controlled L{Channel}s to
42-
the other side, which are python objects that act like sockets, but send and
43-
receive data over the encrypted session.
44-
45-
Paramiko is written entirely in python (no C or platform-dependent code) and is
46-
released under the GNU Lesser General Public License (LGPL).
47-
48-
Website: U{https://github.com/paramiko/paramiko/}
49-
50-
Mailing list: U{[email protected]<mailto:[email protected]>}
51-
"""
52-
5319
import sys
5420

5521
if sys.version_info < (2, 5):
56-
raise RuntimeError('You need python 2.5+ for this module.')
22+
raise RuntimeError('You need Python 2.5+ for this module.')
5723

5824

5925
__author__ = "Jeff Forcier <[email protected]>"
@@ -89,13 +55,6 @@
8955
from config import SSHConfig
9056
from proxy import ProxyCommand
9157

92-
# fix module names for epydoc
93-
for c in locals().values():
94-
if issubclass(type(c), type) or type(c).__name__ == 'classobj':
95-
# classobj for exceptions :/
96-
c.__module__ = __name__
97-
del c
98-
9958
from common import AUTH_SUCCESSFUL, AUTH_PARTIALLY_SUCCESSFUL, AUTH_FAILED, \
10059
OPEN_SUCCEEDED, OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED, OPEN_FAILED_CONNECT_FAILED, \
10160
OPEN_FAILED_UNKNOWN_CHANNEL_TYPE, OPEN_FAILED_RESOURCE_SHORTAGE

paramiko/agent.py

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
1818

1919
"""
20-
SSH Agent interface for Unix clients.
20+
SSH Agent interface
2121
"""
2222

2323
import os
@@ -40,17 +40,8 @@
4040
SSH2_AGENTC_REQUEST_IDENTITIES, SSH2_AGENT_IDENTITIES_ANSWER, \
4141
SSH2_AGENTC_SIGN_REQUEST, SSH2_AGENT_SIGN_RESPONSE = range(11, 15)
4242

43-
class AgentSSH(object):
44-
"""
45-
Client interface for using private keys from an SSH agent running on the
46-
local machine. If an SSH agent is running, this class can be used to
47-
connect to it and retreive L{PKey} objects which can be used when
48-
attempting to authenticate to remote SSH servers.
4943

50-
Because the SSH agent protocol uses environment variables and unix-domain
51-
sockets, this probably doesn't work on Windows. It does work on most
52-
posix platforms though (Linux and MacOS X, for example).
53-
"""
44+
class AgentSSH(object):
5445
def __init__(self):
5546
self._conn = None
5647
self._keys = ()
@@ -61,8 +52,9 @@ def get_keys(self):
6152
no SSH agent was running (or it couldn't be contacted), an empty list
6253
will be returned.
6354
64-
@return: a list of keys available on the SSH agent
65-
@rtype: tuple of L{AgentKey}
55+
:return:
56+
a tuple of `.AgentKey` objects representing keys available on the
57+
SSH agent
6658
"""
6759
return self._keys
6860

@@ -100,8 +92,11 @@ def _read_all(self, wanted):
10092
result += extra
10193
return result
10294

95+
10396
class AgentProxyThread(threading.Thread):
104-
""" Class in charge of communication between two chan """
97+
"""
98+
Class in charge of communication between two channels.
99+
"""
105100
def __init__(self, agent):
106101
threading.Thread.__init__(self, target=self.run)
107102
self._agent = agent
@@ -146,6 +141,7 @@ def _close(self):
146141
self.__inr.close()
147142
self._agent._conn.close()
148143

144+
149145
class AgentLocalProxy(AgentProxyThread):
150146
"""
151147
Class to be used when wanting to ask a local SSH Agent being
@@ -155,8 +151,10 @@ def __init__(self, agent):
155151
AgentProxyThread.__init__(self, agent)
156152

157153
def get_connection(self):
158-
""" Return a pair of socket object and string address
159-
May Block !
154+
"""
155+
Return a pair of socket object and string address.
156+
157+
May block!
160158
"""
161159
conn = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
162160
try:
@@ -168,6 +166,7 @@ def get_connection(self):
168166
raise
169167
return None
170168

169+
171170
class AgentRemoteProxy(AgentProxyThread):
172171
"""
173172
Class to be used when wanting to ask a remote SSH Agent
@@ -177,22 +176,20 @@ def __init__(self, agent, chan):
177176
self.__chan = chan
178177

179178
def get_connection(self):
180-
"""
181-
Class to be used when wanting to ask a local SSH Agent being
182-
asked from a remote fake agent (so use a unix socket for ex.)
183-
"""
184179
return (self.__chan, None)
185180

181+
186182
class AgentClientProxy(object):
187183
"""
188184
Class proxying request as a client:
189-
-> client ask for a request_forward_agent()
190-
-> server creates a proxy and a fake SSH Agent
191-
-> server ask for establishing a connection when needed,
185+
186+
#. client ask for a request_forward_agent()
187+
#. server creates a proxy and a fake SSH Agent
188+
#. server ask for establishing a connection when needed,
192189
calling the forward_agent_handler at client side.
193-
-> the forward_agent_handler launch a thread for connecting
190+
#. the forward_agent_handler launch a thread for connecting
194191
the remote fake agent and the local agent
195-
-> Communication occurs ...
192+
#. Communication occurs ...
196193
"""
197194
def __init__(self, chanRemote):
198195
self._conn = None
@@ -205,7 +202,7 @@ def __del__(self):
205202

206203
def connect(self):
207204
"""
208-
Method automatically called by the run() method of the AgentProxyThread
205+
Method automatically called by ``AgentProxyThread.run``.
209206
"""
210207
if ('SSH_AUTH_SOCK' in os.environ) and (sys.platform != 'win32'):
211208
conn = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -236,11 +233,12 @@ def close(self):
236233
if self._conn is not None:
237234
self._conn.close()
238235

236+
239237
class AgentServerProxy(AgentSSH):
240238
"""
241-
@param t : transport used for the Forward for SSH Agent communication
239+
:param .Transport t: Transport used for SSH Agent communication forwarding
242240
243-
@raise SSHException: mostly if we lost the agent
241+
:raises SSHException: mostly if we lost the agent
244242
"""
245243
def __init__(self, t):
246244
AgentSSH.__init__(self)
@@ -276,8 +274,8 @@ def get_env(self):
276274
"""
277275
Helper for the environnement under unix
278276
279-
@return: the SSH_AUTH_SOCK Environnement variables
280-
@rtype: dict
277+
:return:
278+
a dict containing the ``SSH_AUTH_SOCK`` environnement variables
281279
"""
282280
env = {}
283281
env['SSH_AUTH_SOCK'] = self._get_filename()
@@ -286,6 +284,7 @@ def get_env(self):
286284
def _get_filename(self):
287285
return self._file
288286

287+
289288
class AgentRequestHandler(object):
290289
def __init__(self, chanClient):
291290
self._conn = None
@@ -303,27 +302,22 @@ def close(self):
303302
for p in self.__clientProxys:
304303
p.close()
305304

305+
306306
class Agent(AgentSSH):
307307
"""
308308
Client interface for using private keys from an SSH agent running on the
309309
local machine. If an SSH agent is running, this class can be used to
310-
connect to it and retreive L{PKey} objects which can be used when
310+
connect to it and retreive `.PKey` objects which can be used when
311311
attempting to authenticate to remote SSH servers.
312312
313-
Because the SSH agent protocol uses environment variables and unix-domain
314-
sockets, this probably doesn't work on Windows. It does work on most
315-
posix platforms though (Linux and MacOS X, for example).
316-
"""
313+
Upon initialization, a session with the local machine's SSH agent is
314+
opened, if one is running. If no agent is running, initialization will
315+
succeed, but `get_keys` will return an empty tuple.
317316
317+
:raises SSHException:
318+
if an SSH agent is found, but speaks an incompatible protocol
319+
"""
318320
def __init__(self):
319-
"""
320-
Open a session with the local machine's SSH agent, if one is running.
321-
If no agent is running, initialization will succeed, but L{get_keys}
322-
will return an empty tuple.
323-
324-
@raise SSHException: if an SSH agent is found, but speaks an
325-
incompatible protocol
326-
"""
327321
AgentSSH.__init__(self)
328322

329323
if ('SSH_AUTH_SOCK' in os.environ) and (sys.platform != 'win32'):
@@ -350,13 +344,13 @@ def close(self):
350344
"""
351345
self._close()
352346

347+
353348
class AgentKey(PKey):
354349
"""
355350
Private key held in a local SSH agent. This type of key can be used for
356351
authenticating to a remote server (signing). Most other key operations
357352
work as expected.
358353
"""
359-
360354
def __init__(self, agent, blob):
361355
self.agent = agent
362356
self.blob = blob

paramiko/auth_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
1818

1919
"""
20-
L{AuthHandler}
20+
`.AuthHandler`
2121
"""
2222

2323
import threading
@@ -167,7 +167,7 @@ def wait_for_response(self, event):
167167
e = self.transport.get_exception()
168168
if e is None:
169169
e = AuthenticationException('Authentication failed.')
170-
# this is horrible. python Exception isn't yet descended from
170+
# this is horrible. Python Exception isn't yet descended from
171171
# object, so type(e) won't work. :(
172172
if issubclass(e.__class__, PartialAuthentication):
173173
return e.allowed_types

0 commit comments

Comments
 (0)