Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

agent.py 1.7KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # -*- test-case-name: twisted.conch.test.test_default -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """
  5. Accesses the key agent for user authentication.
  6. Maintainer: Paul Swartz
  7. """
  8. import os
  9. from twisted.conch.ssh import agent, channel, keys
  10. from twisted.internet import protocol, reactor
  11. from twisted.logger import Logger
  12. class SSHAgentClient(agent.SSHAgentClient):
  13. _log = Logger()
  14. def __init__(self):
  15. agent.SSHAgentClient.__init__(self)
  16. self.blobs = []
  17. def getPublicKeys(self):
  18. return self.requestIdentities().addCallback(self._cbPublicKeys)
  19. def _cbPublicKeys(self, blobcomm):
  20. self._log.debug("got {num_keys} public keys", num_keys=len(blobcomm))
  21. self.blobs = [x[0] for x in blobcomm]
  22. def getPublicKey(self):
  23. """
  24. Return a L{Key} from the first blob in C{self.blobs}, if any, or
  25. return L{None}.
  26. """
  27. if self.blobs:
  28. return keys.Key.fromString(self.blobs.pop(0))
  29. return None
  30. class SSHAgentForwardingChannel(channel.SSHChannel):
  31. def channelOpen(self, specificData):
  32. cc = protocol.ClientCreator(reactor, SSHAgentForwardingLocal)
  33. d = cc.connectUNIX(os.environ["SSH_AUTH_SOCK"])
  34. d.addCallback(self._cbGotLocal)
  35. d.addErrback(lambda x: self.loseConnection())
  36. self.buf = ""
  37. def _cbGotLocal(self, local):
  38. self.local = local
  39. self.dataReceived = self.local.transport.write
  40. self.local.dataReceived = self.write
  41. def dataReceived(self, data):
  42. self.buf += data
  43. def closed(self):
  44. if self.local:
  45. self.local.loseConnection()
  46. self.local = None
  47. class SSHAgentForwardingLocal(protocol.Protocol):
  48. pass