1
# -*- test-case-name: twisted.conch.test.test_default -*-
2
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
3
# See LICENSE for details.
6
Accesses the key agent for user authentication.
8
Maintainer: Paul Swartz
13
from twisted.conch.ssh import agent, channel, keys
14
from twisted.internet import protocol, reactor
15
from twisted.python import log
19
class SSHAgentClient(agent.SSHAgentClient):
22
agent.SSHAgentClient.__init__(self)
26
def getPublicKeys(self):
27
return self.requestIdentities().addCallback(self._cbPublicKeys)
30
def _cbPublicKeys(self, blobcomm):
31
log.msg('got %i public keys' % len(blobcomm))
32
self.blobs = [x[0] for x in blobcomm]
35
def getPublicKey(self):
37
Return a L{Key} from the first blob in C{self.blobs}, if any, or
41
return keys.Key.fromString(self.blobs.pop(0))
46
class SSHAgentForwardingChannel(channel.SSHChannel):
48
def channelOpen(self, specificData):
49
cc = protocol.ClientCreator(reactor, SSHAgentForwardingLocal)
50
d = cc.connectUNIX(os.environ['SSH_AUTH_SOCK'])
51
d.addCallback(self._cbGotLocal)
52
d.addErrback(lambda x:self.loseConnection())
56
def _cbGotLocal(self, local):
58
self.dataReceived = self.local.transport.write
59
self.local.dataReceived = self.write
62
def dataReceived(self, data):
68
self.local.loseConnection()
72
class SSHAgentForwardingLocal(protocol.Protocol):