summaryrefslogtreecommitdiff
path: root/paramiko/agent.py
diff options
context:
space:
mode:
authorJeremy T. Bouse <jbouse@debian.org>2009-11-27 16:20:13 -0500
committerJeremy T. Bouse <jbouse@debian.org>2009-11-27 16:20:13 -0500
commitd04355ae59eba8a96d4341ec3db9d81470344703 (patch)
treeeba8c41ff15e11805b51fe959cd0906c86bb0ede /paramiko/agent.py
parentb30290e934385616ea48a55ecae5912f651b0bf7 (diff)
parented280d5ac360e2af796e9bd973d7b4df89f0c449 (diff)
downloadpython-paramiko-d04355ae59eba8a96d4341ec3db9d81470344703.tar
python-paramiko-d04355ae59eba8a96d4341ec3db9d81470344703.tar.gz
Merge branch 'upstream'
Diffstat (limited to 'paramiko/agent.py')
-rw-r--r--paramiko/agent.py39
1 files changed, 26 insertions, 13 deletions
diff --git a/paramiko/agent.py b/paramiko/agent.py
index 3555512..71de8b8 100644
--- a/paramiko/agent.py
+++ b/paramiko/agent.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2003-2005 John Rochester <john@jrochester.org>
+# Copyright (C) 2003-2007 John Rochester <john@jrochester.org>
#
# This file is part of paramiko.
#
@@ -55,20 +55,33 @@ class Agent:
@raise SSHException: if an SSH agent is found, but speaks an
incompatible protocol
"""
+ self.keys = ()
if ('SSH_AUTH_SOCK' in os.environ) and (sys.platform != 'win32'):
conn = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- conn.connect(os.environ['SSH_AUTH_SOCK'])
+ try:
+ conn.connect(os.environ['SSH_AUTH_SOCK'])
+ except:
+ # probably a dangling env var: the ssh agent is gone
+ return
self.conn = conn
- type, result = self._send_message(chr(SSH2_AGENTC_REQUEST_IDENTITIES))
- if type != SSH2_AGENT_IDENTITIES_ANSWER:
- raise SSHException('could not get keys from ssh-agent')
- keys = []
- for i in range(result.get_int()):
- keys.append(AgentKey(self, result.get_string()))
- result.get_string()
- self.keys = tuple(keys)
+ elif sys.platform == 'win32':
+ import win_pageant
+ if win_pageant.can_talk_to_agent():
+ self.conn = win_pageant.PageantConnection()
+ else:
+ return
else:
- self.keys = ()
+ # no agent support
+ return
+
+ ptype, result = self._send_message(chr(SSH2_AGENTC_REQUEST_IDENTITIES))
+ if ptype != SSH2_AGENT_IDENTITIES_ANSWER:
+ raise SSHException('could not get keys from ssh-agent')
+ keys = []
+ for i in range(result.get_int()):
+ keys.append(AgentKey(self, result.get_string()))
+ result.get_string()
+ self.keys = tuple(keys)
def close(self):
"""
@@ -132,7 +145,7 @@ class AgentKey(PKey):
msg.add_string(self.blob)
msg.add_string(data)
msg.add_int(0)
- type, result = self.agent._send_message(msg)
- if type != SSH2_AGENT_SIGN_RESPONSE:
+ ptype, result = self.agent._send_message(msg)
+ if ptype != SSH2_AGENT_SIGN_RESPONSE:
raise SSHException('key cannot be used for signing')
return result.get_string()