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.

options.py 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. #
  4. from twisted.conch.ssh.transport import SSHClientTransport, SSHCiphers
  5. from twisted.python import usage
  6. from twisted.python.compat import unicode
  7. import sys
  8. class ConchOptions(usage.Options):
  9. optParameters = [['user', 'l', None, 'Log in using this user name.'],
  10. ['identity', 'i', None],
  11. ['ciphers', 'c', None],
  12. ['macs', 'm', None],
  13. ['port', 'p', None, 'Connect to this port. Server must be on the same port.'],
  14. ['option', 'o', None, 'Ignored OpenSSH options'],
  15. ['host-key-algorithms', '', None],
  16. ['known-hosts', '', None, 'File to check for host keys'],
  17. ['user-authentications', '', None, 'Types of user authentications to use.'],
  18. ['logfile', '', None, 'File to log to, or - for stdout'],
  19. ]
  20. optFlags = [['version', 'V', 'Display version number only.'],
  21. ['compress', 'C', 'Enable compression.'],
  22. ['log', 'v', 'Enable logging (defaults to stderr)'],
  23. ['nox11', 'x', 'Disable X11 connection forwarding (default)'],
  24. ['agent', 'A', 'Enable authentication agent forwarding'],
  25. ['noagent', 'a', 'Disable authentication agent forwarding (default)'],
  26. ['reconnect', 'r', 'Reconnect to the server if the connection is lost.'],
  27. ]
  28. compData = usage.Completions(
  29. mutuallyExclusive=[("agent", "noagent")],
  30. optActions={
  31. "user": usage.CompleteUsernames(),
  32. "ciphers": usage.CompleteMultiList(
  33. SSHCiphers.cipherMap.keys(),
  34. descr='ciphers to choose from'),
  35. "macs": usage.CompleteMultiList(
  36. SSHCiphers.macMap.keys(),
  37. descr='macs to choose from'),
  38. "host-key-algorithms": usage.CompleteMultiList(
  39. SSHClientTransport.supportedPublicKeys,
  40. descr='host key algorithms to choose from'),
  41. #"user-authentications": usage.CompleteMultiList(?
  42. # descr='user authentication types' ),
  43. },
  44. extraActions=[usage.CompleteUserAtHost(),
  45. usage.Completer(descr="command"),
  46. usage.Completer(descr='argument',
  47. repeat=True)]
  48. )
  49. def __init__(self, *args, **kw):
  50. usage.Options.__init__(self, *args, **kw)
  51. self.identitys = []
  52. self.conns = None
  53. def opt_identity(self, i):
  54. """Identity for public-key authentication"""
  55. self.identitys.append(i)
  56. def opt_ciphers(self, ciphers):
  57. "Select encryption algorithms"
  58. ciphers = ciphers.split(',')
  59. for cipher in ciphers:
  60. if cipher not in SSHCiphers.cipherMap:
  61. sys.exit("Unknown cipher type '%s'" % cipher)
  62. self['ciphers'] = ciphers
  63. def opt_macs(self, macs):
  64. "Specify MAC algorithms"
  65. if isinstance(macs, unicode):
  66. macs = macs.encode("utf-8")
  67. macs = macs.split(b',')
  68. for mac in macs:
  69. if mac not in SSHCiphers.macMap:
  70. sys.exit("Unknown mac type '%r'" % mac)
  71. self['macs'] = macs
  72. def opt_host_key_algorithms(self, hkas):
  73. "Select host key algorithms"
  74. if isinstance(hkas, unicode):
  75. hkas = hkas.encode("utf-8")
  76. hkas = hkas.split(b',')
  77. for hka in hkas:
  78. if hka not in SSHClientTransport.supportedPublicKeys:
  79. sys.exit("Unknown host key type '%r'" % hka)
  80. self['host-key-algorithms'] = hkas
  81. def opt_user_authentications(self, uas):
  82. "Choose how to authenticate to the remote server"
  83. if isinstance(uas, unicode):
  84. uas = uas.encode("utf-8")
  85. self['user-authentications'] = uas.split(b',')
  86. # def opt_compress(self):
  87. # "Enable compression"
  88. # self.enableCompression = 1
  89. # SSHClientTransport.supportedCompressions[0:1] = ['zlib']