| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2001-2004 Twisted Matrix Laboratories. | |
| 2 # See LICENSE for details. | |
| 3 | |
| 4 # | |
| 5 """ | |
| 6 Accesses the key agent for user authentication. | |
| 7 | |
| 8 Maintainer: U{Paul Swartz<mailto:z3p@twistedmatrix.com>} | |
| 9 """ | |
| 10 | |
| 11 from twisted.conch.ssh import agent, channel | |
| 12 from twisted.internet import protocol | |
| 13 from twisted.python import log | |
| 14 | |
| 15 class SSHAgentClient(agent.SSHAgentClient): | |
| 16 | |
| 17 def __init__(self): | |
| 18 agent.SSHAgentClient.__init__(self) | |
| 19 self.blobs = [] | |
| 20 | |
| 21 def getPublicKeys(self): | |
| 22 return self.requestIdentities().addCallback(self._cbPublicKeys) | |
| 23 | |
| 24 def _cbPublicKeys(self, blobcomm): | |
| 25 log.msg('got %i public keys' % len(blobcomm)) | |
| 26 self.blobs = [x[0] for x in blobcomm] | |
| 27 | |
| 28 def getPublicKey(self): | |
| 29 if self.blobs: | |
| 30 return self.blobs.pop(0) | |
| 31 return None | |
| 32 | |
| 33 class SSHAgentForwardingChannel(channel.SSHChannel): | |
| 34 | |
| 35 def channelOpen(self, specificData): | |
| 36 cc = protocol.ClientCreator(reactor, SSHAgentForwardingLocal) | |
| 37 d = cc.connectUNIX(os.environ['SSH_AUTH_SOCK']) | |
| 38 d.addCallback(self._cbGotLocal) | |
| 39 d.addErrback(lambda x:self.loseConnection()) | |
| 40 self.buf = '' | |
| 41 | |
| 42 def _cbGotLocal(self, local): | |
| 43 self.local = local | |
| 44 self.dataReceived = self.local.transport.write | |
| 45 self.local.dataReceived = self.write | |
| 46 | |
| 47 def dataReceived(self, data): | |
| 48 self.buf += data | |
| 49 | |
| 50 def closed(self): | |
| 51 if self.local: | |
| 52 self.local.loseConnection() | |
| 53 self.local = None | |
| 54 | |
| 55 class SSHAgentForwardingLocal(protocol.Protocol): pass | |
| 56 | |
| OLD | NEW |