~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to twisted/conch/client/agent.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-17 14:52:35 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20070117145235-btmig6qfmqfen0om
Tags: 2.5.0-0ubuntu1
New upstream version, compatible with python2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
This module is unstable.
 
9
 
 
10
Maintainer: U{Paul Swartz<mailto:z3p@twistedmatrix.com>}
 
11
"""
 
12
 
 
13
from twisted.conch.ssh import agent, channel
 
14
from twisted.internet import protocol
 
15
from twisted.python import log
 
16
 
 
17
class SSHAgentClient(agent.SSHAgentClient):
 
18
    
 
19
    def __init__(self):
 
20
        agent.SSHAgentClient.__init__(self)
 
21
        self.blobs = []
 
22
 
 
23
    def getPublicKeys(self):
 
24
        return self.requestIdentities().addCallback(self._cbPublicKeys)
 
25
 
 
26
    def _cbPublicKeys(self, blobcomm):
 
27
        log.msg('got %i public keys' % len(blobcomm))
 
28
        self.blobs = [x[0] for x in blobcomm]
 
29
 
 
30
    def getPublicKey(self):
 
31
        if self.blobs:
 
32
            return self.blobs.pop(0)
 
33
        return None
 
34
 
 
35
class SSHAgentForwardingChannel(channel.SSHChannel):
 
36
 
 
37
    def channelOpen(self, specificData):
 
38
        cc = protocol.ClientCreator(reactor, SSHAgentForwardingLocal)
 
39
        d = cc.connectUNIX(os.environ['SSH_AUTH_SOCK'])
 
40
        d.addCallback(self._cbGotLocal)
 
41
        d.addErrback(lambda x:self.loseConnection())
 
42
        self.buf = ''
 
43
 
 
44
    def _cbGotLocal(self, local):
 
45
        self.local = local
 
46
        self.dataReceived = self.local.transport.write
 
47
        self.local.dataReceived = self.write
 
48
   
 
49
    def dataReceived(self, data): 
 
50
        self.buf += data
 
51
 
 
52
    def closed(self):
 
53
        if self.local:
 
54
            self.local.loseConnection()
 
55
            self.local = None
 
56
 
 
57
class SSHAgentForwardingLocal(protocol.Protocol): pass
 
58