redcar 0.3.8.3 → 0.3.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. data/CHANGES +6 -0
  2. data/Rakefile +1 -1
  3. data/lib/redcar.rb +1 -1
  4. data/lib/redcar/installer.rb +14 -4
  5. metadata +1 -168
  6. data/lib/openssl/Manifest.txt +0 -99
  7. data/lib/openssl/build.properties +0 -7
  8. data/lib/plugin_manager/plugin_manager.gemspec +0 -33
  9. data/plugins/project/vendor/net-sftp/Manifest +0 -55
  10. data/plugins/project/vendor/net-sftp/Rakefile +0 -30
  11. data/plugins/project/vendor/net-sftp/lib/net/sftp.rb +0 -70
  12. data/plugins/project/vendor/net-sftp/lib/net/sftp/constants.rb +0 -187
  13. data/plugins/project/vendor/net-sftp/lib/net/sftp/errors.rb +0 -39
  14. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/dir.rb +0 -93
  15. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/download.rb +0 -364
  16. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/file.rb +0 -176
  17. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/file_factory.rb +0 -60
  18. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/upload.rb +0 -387
  19. data/plugins/project/vendor/net-sftp/lib/net/sftp/packet.rb +0 -21
  20. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol.rb +0 -32
  21. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/attributes.rb +0 -315
  22. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/base.rb +0 -268
  23. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/name.rb +0 -43
  24. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/02/base.rb +0 -31
  25. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/03/base.rb +0 -35
  26. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/attributes.rb +0 -152
  27. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/base.rb +0 -94
  28. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/name.rb +0 -67
  29. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/05/base.rb +0 -66
  30. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/06/attributes.rb +0 -107
  31. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/06/base.rb +0 -63
  32. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/base.rb +0 -50
  33. data/plugins/project/vendor/net-sftp/lib/net/sftp/request.rb +0 -91
  34. data/plugins/project/vendor/net-sftp/lib/net/sftp/response.rb +0 -76
  35. data/plugins/project/vendor/net-sftp/lib/net/sftp/session.rb +0 -951
  36. data/plugins/project/vendor/net-sftp/lib/net/sftp/version.rb +0 -18
  37. data/plugins/project/vendor/net-sftp/setup.rb +0 -1331
  38. data/plugins/project/vendor/net-sftp/test/common.rb +0 -171
  39. data/plugins/project/vendor/net-sftp/test/protocol/01/test_attributes.rb +0 -97
  40. data/plugins/project/vendor/net-sftp/test/protocol/01/test_base.rb +0 -210
  41. data/plugins/project/vendor/net-sftp/test/protocol/01/test_name.rb +0 -27
  42. data/plugins/project/vendor/net-sftp/test/protocol/02/test_base.rb +0 -26
  43. data/plugins/project/vendor/net-sftp/test/protocol/03/test_base.rb +0 -27
  44. data/plugins/project/vendor/net-sftp/test/protocol/04/test_attributes.rb +0 -148
  45. data/plugins/project/vendor/net-sftp/test/protocol/04/test_base.rb +0 -74
  46. data/plugins/project/vendor/net-sftp/test/protocol/04/test_name.rb +0 -53
  47. data/plugins/project/vendor/net-sftp/test/protocol/05/test_base.rb +0 -62
  48. data/plugins/project/vendor/net-sftp/test/protocol/06/test_attributes.rb +0 -124
  49. data/plugins/project/vendor/net-sftp/test/protocol/06/test_base.rb +0 -51
  50. data/plugins/project/vendor/net-sftp/test/protocol/test_base.rb +0 -42
  51. data/plugins/project/vendor/net-sftp/test/test_all.rb +0 -7
  52. data/plugins/project/vendor/net-sftp/test/test_dir.rb +0 -47
  53. data/plugins/project/vendor/net-sftp/test/test_download.rb +0 -252
  54. data/plugins/project/vendor/net-sftp/test/test_file.rb +0 -159
  55. data/plugins/project/vendor/net-sftp/test/test_file_factory.rb +0 -48
  56. data/plugins/project/vendor/net-sftp/test/test_packet.rb +0 -9
  57. data/plugins/project/vendor/net-sftp/test/test_protocol.rb +0 -17
  58. data/plugins/project/vendor/net-sftp/test/test_request.rb +0 -71
  59. data/plugins/project/vendor/net-sftp/test/test_response.rb +0 -53
  60. data/plugins/project/vendor/net-sftp/test/test_session.rb +0 -741
  61. data/plugins/project/vendor/net-sftp/test/test_upload.rb +0 -219
  62. data/plugins/project/vendor/net-ssh/Manifest +0 -110
  63. data/plugins/project/vendor/net-ssh/Rakefile +0 -85
  64. data/plugins/project/vendor/net-ssh/Rudyfile +0 -96
  65. data/plugins/project/vendor/net-ssh/lib/net/ssh.rb +0 -215
  66. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/agent.rb +0 -179
  67. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/constants.rb +0 -18
  68. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/key_manager.rb +0 -193
  69. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/abstract.rb +0 -60
  70. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/hostbased.rb +0 -71
  71. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/keyboard_interactive.rb +0 -66
  72. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/password.rb +0 -39
  73. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/publickey.rb +0 -92
  74. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/pageant.rb +0 -183
  75. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/session.rb +0 -134
  76. data/plugins/project/vendor/net-ssh/lib/net/ssh/buffer.rb +0 -340
  77. data/plugins/project/vendor/net-ssh/lib/net/ssh/buffered_io.rb +0 -198
  78. data/plugins/project/vendor/net-ssh/lib/net/ssh/config.rb +0 -202
  79. data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/channel.rb +0 -630
  80. data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/constants.rb +0 -33
  81. data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/session.rb +0 -597
  82. data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/term.rb +0 -178
  83. data/plugins/project/vendor/net-ssh/lib/net/ssh/errors.rb +0 -85
  84. data/plugins/project/vendor/net-ssh/lib/net/ssh/key_factory.rb +0 -102
  85. data/plugins/project/vendor/net-ssh/lib/net/ssh/known_hosts.rb +0 -129
  86. data/plugins/project/vendor/net-ssh/lib/net/ssh/loggable.rb +0 -61
  87. data/plugins/project/vendor/net-ssh/lib/net/ssh/packet.rb +0 -102
  88. data/plugins/project/vendor/net-ssh/lib/net/ssh/prompt.rb +0 -93
  89. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/command.rb +0 -75
  90. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/errors.rb +0 -14
  91. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/http.rb +0 -94
  92. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/socks4.rb +0 -70
  93. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/socks5.rb +0 -142
  94. data/plugins/project/vendor/net-ssh/lib/net/ssh/ruby_compat.rb +0 -43
  95. data/plugins/project/vendor/net-ssh/lib/net/ssh/service/forward.rb +0 -288
  96. data/plugins/project/vendor/net-ssh/lib/net/ssh/test.rb +0 -89
  97. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/channel.rb +0 -129
  98. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/extensions.rb +0 -152
  99. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/kex.rb +0 -44
  100. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/local_packet.rb +0 -51
  101. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/packet.rb +0 -81
  102. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/remote_packet.rb +0 -38
  103. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/script.rb +0 -157
  104. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/socket.rb +0 -64
  105. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/algorithms.rb +0 -384
  106. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/cipher_factory.rb +0 -97
  107. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/constants.rb +0 -30
  108. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac.rb +0 -31
  109. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/abstract.rb +0 -79
  110. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/md5.rb +0 -12
  111. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/md5_96.rb +0 -11
  112. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/none.rb +0 -15
  113. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/sha1.rb +0 -13
  114. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/sha1_96.rb +0 -11
  115. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/identity_cipher.rb +0 -55
  116. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex.rb +0 -13
  117. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +0 -208
  118. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +0 -77
  119. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/openssl.rb +0 -128
  120. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/packet_stream.rb +0 -235
  121. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/server_version.rb +0 -71
  122. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/session.rb +0 -276
  123. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/state.rb +0 -206
  124. data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/lenient.rb +0 -30
  125. data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/null.rb +0 -12
  126. data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/strict.rb +0 -53
  127. data/plugins/project/vendor/net-ssh/lib/net/ssh/version.rb +0 -62
  128. data/plugins/project/vendor/net-ssh/net-ssh.gemspec +0 -138
  129. data/plugins/project/vendor/net-ssh/setup.rb +0 -1585
  130. data/plugins/project/vendor/net-ssh/support/arcfour_check.rb +0 -20
  131. data/plugins/project/vendor/net-ssh/support/ssh_tunnel_bug.rb +0 -65
  132. data/plugins/project/vendor/net-ssh/test/README.txt +0 -42
  133. data/plugins/project/vendor/net-ssh/test/authentication/methods/common.rb +0 -28
  134. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_abstract.rb +0 -51
  135. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_hostbased.rb +0 -114
  136. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_keyboard_interactive.rb +0 -98
  137. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_password.rb +0 -50
  138. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_publickey.rb +0 -127
  139. data/plugins/project/vendor/net-ssh/test/authentication/test_agent.rb +0 -205
  140. data/plugins/project/vendor/net-ssh/test/authentication/test_key_manager.rb +0 -105
  141. data/plugins/project/vendor/net-ssh/test/authentication/test_session.rb +0 -93
  142. data/plugins/project/vendor/net-ssh/test/common.rb +0 -107
  143. data/plugins/project/vendor/net-ssh/test/configs/eqsign +0 -3
  144. data/plugins/project/vendor/net-ssh/test/configs/exact_match +0 -8
  145. data/plugins/project/vendor/net-ssh/test/configs/host_plus +0 -10
  146. data/plugins/project/vendor/net-ssh/test/configs/multihost +0 -4
  147. data/plugins/project/vendor/net-ssh/test/configs/nohost +0 -19
  148. data/plugins/project/vendor/net-ssh/test/configs/numeric_host +0 -4
  149. data/plugins/project/vendor/net-ssh/test/configs/wild_cards +0 -14
  150. data/plugins/project/vendor/net-ssh/test/connection/test_channel.rb +0 -467
  151. data/plugins/project/vendor/net-ssh/test/connection/test_session.rb +0 -488
  152. data/plugins/project/vendor/net-ssh/test/manual/test_forward.rb +0 -185
  153. data/plugins/project/vendor/net-ssh/test/test_all.rb +0 -9
  154. data/plugins/project/vendor/net-ssh/test/test_buffer.rb +0 -336
  155. data/plugins/project/vendor/net-ssh/test/test_buffered_io.rb +0 -63
  156. data/plugins/project/vendor/net-ssh/test/test_config.rb +0 -117
  157. data/plugins/project/vendor/net-ssh/test/test_key_factory.rb +0 -67
  158. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_md5.rb +0 -39
  159. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_md5_96.rb +0 -25
  160. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_none.rb +0 -34
  161. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_sha1.rb +0 -34
  162. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_sha1_96.rb +0 -25
  163. data/plugins/project/vendor/net-ssh/test/transport/kex/test_diffie_hellman_group1_sha1.rb +0 -146
  164. data/plugins/project/vendor/net-ssh/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +0 -92
  165. data/plugins/project/vendor/net-ssh/test/transport/test_algorithms.rb +0 -302
  166. data/plugins/project/vendor/net-ssh/test/transport/test_cipher_factory.rb +0 -213
  167. data/plugins/project/vendor/net-ssh/test/transport/test_hmac.rb +0 -34
  168. data/plugins/project/vendor/net-ssh/test/transport/test_identity_cipher.rb +0 -40
  169. data/plugins/project/vendor/net-ssh/test/transport/test_packet_stream.rb +0 -441
  170. data/plugins/project/vendor/net-ssh/test/transport/test_server_version.rb +0 -78
  171. data/plugins/project/vendor/net-ssh/test/transport/test_session.rb +0 -315
  172. data/plugins/project/vendor/net-ssh/test/transport/test_state.rb +0 -173
@@ -1,142 +0,0 @@
1
- require 'socket'
2
- require 'net/ssh/ruby_compat'
3
- require 'net/ssh/proxy/errors'
4
-
5
- module Net
6
- module SSH
7
- module Proxy
8
-
9
- # An implementation of a SOCKS5 proxy. To use it, instantiate it, then
10
- # pass the instantiated object via the :proxy key to Net::SSH.start:
11
- #
12
- # require 'net/ssh/proxy/socks5'
13
- #
14
- # proxy = Net::SSH::Proxy::SOCKS5.new('proxy.host', proxy_port,
15
- # :user => 'user', :password => "password")
16
- # Net::SSH.start('host', 'user', :proxy => proxy) do |ssh|
17
- # ...
18
- # end
19
- class SOCKS5
20
- # The SOCKS protocol version used by this class
21
- VERSION = 5
22
-
23
- # The SOCKS authentication type for requests without authentication
24
- METHOD_NO_AUTH = 0
25
-
26
- # The SOCKS authentication type for requests via username/password
27
- METHOD_PASSWD = 2
28
-
29
- # The SOCKS authentication type for when there are no supported
30
- # authentication methods.
31
- METHOD_NONE = 0xFF
32
-
33
- # The SOCKS packet type for requesting a proxy connection.
34
- CMD_CONNECT = 1
35
-
36
- # The SOCKS address type for connections via IP address.
37
- ATYP_IPV4 = 1
38
-
39
- # The SOCKS address type for connections via domain name.
40
- ATYP_DOMAIN = 3
41
-
42
- # The SOCKS response code for a successful operation.
43
- SUCCESS = 0
44
-
45
- # The proxy's host name or IP address
46
- attr_reader :proxy_host
47
-
48
- # The proxy's port number
49
- attr_reader :proxy_port
50
-
51
- # The map of options given at initialization
52
- attr_reader :options
53
-
54
- # Create a new proxy connection to the given proxy host and port.
55
- # Optionally, :user and :password options may be given to
56
- # identify the username and password with which to authenticate.
57
- def initialize(proxy_host, proxy_port=1080, options={})
58
- @proxy_host = proxy_host
59
- @proxy_port = proxy_port
60
- @options = options
61
- end
62
-
63
- # Return a new socket connected to the given host and port via the
64
- # proxy that was requested when the socket factory was instantiated.
65
- def open(host, port)
66
- socket = TCPSocket.new(proxy_host, proxy_port)
67
-
68
- methods = [METHOD_NO_AUTH]
69
- methods << METHOD_PASSWD if options[:user]
70
-
71
- packet = [VERSION, methods.size, *methods].pack("C*")
72
- socket.send packet, 0
73
-
74
- version, method = socket.recv(2).unpack("CC")
75
- if version != VERSION
76
- socket.close
77
- raise Net::SSH::Proxy::Error, "invalid SOCKS version (#{version})"
78
- end
79
-
80
- if method == METHOD_NONE
81
- socket.close
82
- raise Net::SSH::Proxy::Error, "no supported authorization methods"
83
- end
84
-
85
- negotiate_password(socket) if method == METHOD_PASSWD
86
-
87
- packet = [VERSION, CMD_CONNECT, 0].pack("C*")
88
-
89
- if host =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
90
- packet << [ATYP_IPV4, $1.to_i, $2.to_i, $3.to_i, $4.to_i].pack("C*")
91
- else
92
- packet << [ATYP_DOMAIN, host.length, host].pack("CCA*")
93
- end
94
-
95
- packet << [port].pack("n")
96
- socket.send packet, 0
97
-
98
- version, reply, = socket.recv(2).unpack("C*")
99
- socket.recv(1)
100
- address_type = socket.recv(1).getbyte(0)
101
- case address_type
102
- when 1
103
- socket.recv(4) # get four bytes for IPv4 address
104
- when 3
105
- len = socket.recv(1).getbyte(0)
106
- hostname = socket.recv(len)
107
- when 4
108
- ipv6addr hostname = socket.recv(16)
109
- else
110
- socket.close
111
- raise ConnectionError, "Illegal response type"
112
- end
113
- portnum = socket.recv(2)
114
-
115
- unless reply == SUCCESS
116
- socket.close
117
- raise ConnectError, "#{reply}"
118
- end
119
-
120
- return socket
121
- end
122
-
123
- private
124
-
125
- # Simple username/password negotiation with the SOCKS5 server.
126
- def negotiate_password(socket)
127
- packet = [0x01, options[:user].length, options[:user],
128
- options[:password].length, options[:password]].pack("CCA*CA*")
129
- socket.send packet, 0
130
-
131
- version, status = socket.recv(2).unpack("CC")
132
-
133
- if status != SUCCESS
134
- socket.close
135
- raise UnauthorizedError, "could not authorize user"
136
- end
137
- end
138
- end
139
-
140
- end
141
- end
142
- end
@@ -1,43 +0,0 @@
1
- require 'thread'
2
-
3
- class String
4
- if RUBY_VERSION < "1.9"
5
- def getbyte(index)
6
- self[index]
7
- end
8
- end
9
- end
10
-
11
- module Net; module SSH
12
-
13
- # This class contains miscellaneous patches and workarounds
14
- # for different ruby implementations.
15
- class Compat
16
-
17
- # A workaround for an IO#select threading bug in certain versions of MRI 1.8.
18
- # See: http://net-ssh.lighthouseapp.com/projects/36253/tickets/1-ioselect-threading-bug-in-ruby-18
19
- # The root issue is documented here: http://redmine.ruby-lang.org/issues/show/1993
20
- if RUBY_VERSION >= '1.9' || RUBY_PLATFORM == 'java'
21
- def self.io_select(*params)
22
- IO.select(*params)
23
- end
24
- else
25
- SELECT_MUTEX = Mutex.new
26
- def self.io_select(*params)
27
- # It should be safe to wrap calls in a mutex when the timeout is 0
28
- # (that is, the call is not supposed to block).
29
- # We leave blocking calls unprotected to avoid causing deadlocks.
30
- # This should still catch the main case for Capistrano users.
31
- if params[3] == 0
32
- SELECT_MUTEX.synchronize do
33
- IO.select(*params)
34
- end
35
- else
36
- IO.select(*params)
37
- end
38
- end
39
- end
40
-
41
- end
42
-
43
- end; end
@@ -1,288 +0,0 @@
1
- require 'net/ssh/loggable'
2
-
3
- module Net; module SSH; module Service
4
-
5
- # This class implements various port forwarding services for use by
6
- # Net::SSH clients. The Forward class should never need to be instantiated
7
- # directly; instead, it should be accessed via the singleton instance
8
- # returned by Connection::Session#forward:
9
- #
10
- # ssh.forward.local(1234, "www.capify.org", 80)
11
- class Forward
12
- include Loggable
13
-
14
- # The underlying connection service instance that the port-forwarding
15
- # services employ.
16
- attr_reader :session
17
-
18
- # A simple class for representing a requested remote forwarded port.
19
- Remote = Struct.new(:host, :port) #:nodoc:
20
-
21
- # Instantiates a new Forward service instance atop the given connection
22
- # service session. This will register new channel open handlers to handle
23
- # the specialized channels that the SSH port forwarding protocols employ.
24
- def initialize(session)
25
- @session = session
26
- self.logger = session.logger
27
- @remote_forwarded_ports = {}
28
- @local_forwarded_ports = {}
29
- @agent_forwarded = false
30
-
31
- session.on_open_channel('forwarded-tcpip', &method(:forwarded_tcpip))
32
- session.on_open_channel('auth-agent', &method(:auth_agent_channel))
33
- session.on_open_channel('auth-agent@openssh.com', &method(:auth_agent_channel))
34
- end
35
-
36
- # Starts listening for connections on the local host, and forwards them
37
- # to the specified remote host/port via the SSH connection. This method
38
- # accepts either three or four arguments. When four arguments are given,
39
- # they are:
40
- #
41
- # * the local address to bind to
42
- # * the local port to listen on
43
- # * the remote host to forward connections to
44
- # * the port on the remote host to connect to
45
- #
46
- # If three arguments are given, it is as if the local bind address is
47
- # "127.0.0.1", and the rest are applied as above.
48
- #
49
- # ssh.forward.local(1234, "www.capify.org", 80)
50
- # ssh.forward.local("0.0.0.0", 1234, "www.capify.org", 80)
51
- def local(*args)
52
- if args.length < 3 || args.length > 4
53
- raise ArgumentError, "expected 3 or 4 parameters, got #{args.length}"
54
- end
55
-
56
- bind_address = "127.0.0.1"
57
- bind_address = args.shift if args.first.is_a?(String) && args.first =~ /\D/
58
-
59
- local_port = args.shift.to_i
60
- remote_host = args.shift
61
- remote_port = args.shift.to_i
62
-
63
- socket = TCPServer.new(bind_address, local_port)
64
-
65
- @local_forwarded_ports[[local_port, bind_address]] = socket
66
-
67
- session.listen_to(socket) do |server|
68
- client = server.accept
69
- debug { "received connection on #{bind_address}:#{local_port}" }
70
-
71
- channel = session.open_channel("direct-tcpip", :string, remote_host, :long, remote_port, :string, bind_address, :long, local_port) do |achannel|
72
- achannel.info { "direct channel established" }
73
- end
74
-
75
- prepare_client(client, channel, :local)
76
-
77
- channel.on_open_failed do |ch, code, description|
78
- channel.error { "could not establish direct channel: #{description} (#{code})" }
79
- channel[:socket].close
80
- end
81
- end
82
- end
83
-
84
- # Terminates an active local forwarded port. If no such forwarded port
85
- # exists, this will raise an exception. Otherwise, the forwarded connection
86
- # is terminated.
87
- #
88
- # ssh.forward.cancel_local(1234)
89
- # ssh.forward.cancel_local(1234, "0.0.0.0")
90
- def cancel_local(port, bind_address="127.0.0.1")
91
- socket = @local_forwarded_ports.delete([port, bind_address])
92
- socket.shutdown rescue nil
93
- socket.close rescue nil
94
- session.stop_listening_to(socket)
95
- end
96
-
97
- # Returns a list of all active locally forwarded ports. The returned value
98
- # is an array of arrays, where each element is a two-element tuple
99
- # consisting of the local port and bind address corresponding to the
100
- # forwarding port.
101
- def active_locals
102
- @local_forwarded_ports.keys
103
- end
104
-
105
- # Requests that all connections on the given remote-port be forwarded via
106
- # the local host to the given port/host. The last argument describes the
107
- # bind address on the remote host, and defaults to 127.0.0.1.
108
- #
109
- # This method will return immediately, but the port will not actually be
110
- # forwarded immediately. If the remote server is not able to begin the
111
- # listener for this request, an exception will be raised asynchronously.
112
- #
113
- # If you want to know when the connection is active, it will show up in the
114
- # #active_remotes list. If you want to block until the port is active, you
115
- # could do something like this:
116
- #
117
- # ssh.forward.remote(80, "www.google.com", 1234, "0.0.0.0")
118
- # ssh.loop { !ssh.forward.active_remotes.include?([1234, "0.0.0.0"]) }
119
- def remote(port, host, remote_port, remote_host="127.0.0.1")
120
- session.send_global_request("tcpip-forward", :string, remote_host, :long, remote_port) do |success, response|
121
- if success
122
- debug { "remote forward from remote #{remote_host}:#{remote_port} to #{host}:#{port} established" }
123
- @remote_forwarded_ports[[remote_port, remote_host]] = Remote.new(host, port)
124
- else
125
- error { "remote forwarding request failed" }
126
- raise Net::SSH::Exception, "remote forwarding request failed"
127
- end
128
- end
129
- end
130
-
131
- # an alias, for token backwards compatibility with the 1.x API
132
- alias :remote_to :remote
133
-
134
- # Requests that a remote forwarded port be cancelled. The remote forwarded
135
- # port on the remote host, bound to the given address on the remote host,
136
- # will be terminated, but not immediately. This method returns immediately
137
- # after queueing the request to be sent to the server. If for some reason
138
- # the port cannot be cancelled, an exception will be raised (asynchronously).
139
- #
140
- # If you want to know when the connection has been cancelled, it will no
141
- # longer be present in the #active_remotes list. If you want to block until
142
- # the port is no longer active, you could do something like this:
143
- #
144
- # ssh.forward.cancel_remote(1234, "0.0.0.0")
145
- # ssh.loop { ssh.forward.active_remotes.include?([1234, "0.0.0.0"]) }
146
- def cancel_remote(port, host="127.0.0.1")
147
- session.send_global_request("cancel-tcpip-forward", :string, host, :long, port) do |success, response|
148
- if success
149
- @remote_forwarded_ports.delete([port, host])
150
- else
151
- raise Net::SSH::Exception, "could not cancel remote forward request on #{host}:#{port}"
152
- end
153
- end
154
- end
155
-
156
- # Returns all active forwarded remote ports. The returned value is an
157
- # array of two-element tuples, where the first element is the port on the
158
- # remote host and the second is the bind address.
159
- def active_remotes
160
- @remote_forwarded_ports.keys
161
- end
162
-
163
- # Enables SSH agent forwarding on the given channel. The forwarded agent
164
- # will remain active even after the channel closes--the channel is only
165
- # used as the transport for enabling the forwarded connection. You should
166
- # never need to call this directly--it is called automatically the first
167
- # time a session channel is opened, when the connection was created with
168
- # :forward_agent set to true:
169
- #
170
- # Net::SSH.start("remote.host", "me", :forwrd_agent => true) do |ssh|
171
- # ssh.open_channel do |ch|
172
- # # agent will be automatically forwarded by this point
173
- # end
174
- # ssh.loop
175
- # end
176
- def agent(channel)
177
- return if @agent_forwarded
178
- @agent_forwarded = true
179
-
180
- channel.send_channel_request("auth-agent-req@openssh.com") do |achannel, success|
181
- if success
182
- debug { "authentication agent forwarding is active" }
183
- else
184
- achannel.send_channel_request("auth-agent-req") do |a2channel, success2|
185
- if success2
186
- debug { "authentication agent forwarding is active" }
187
- else
188
- error { "could not establish forwarding of authentication agent" }
189
- end
190
- end
191
- end
192
- end
193
- end
194
-
195
- private
196
-
197
- # Perform setup operations that are common to all forwarded channels.
198
- # +client+ is a socket, +channel+ is the channel that was just created,
199
- # and +type+ is an arbitrary string describing the type of the channel.
200
- def prepare_client(client, channel, type)
201
- client.extend(Net::SSH::BufferedIo)
202
- client.extend(Net::SSH::ForwardedBufferedIo)
203
- client.logger = logger
204
-
205
- session.listen_to(client)
206
- channel[:socket] = client
207
-
208
- channel.on_data do |ch, data|
209
- debug { "data:#{data.length} on #{type} forwarded channel" }
210
- ch[:socket].enqueue(data)
211
- end
212
-
213
- # Handles server close on the sending side by Miklós Fazekas
214
- channel.on_eof do |ch|
215
- debug { "eof #{type} on #{type} forwarded channel" }
216
- begin
217
- ch[:socket].send_pending
218
- ch[:socket].shutdown Socket::SHUT_WR
219
- rescue IOError => e
220
- if e.message =~ /closed/ then
221
- debug { "epipe in on_eof => shallowing exception:#{e}" }
222
- else
223
- raise
224
- end
225
- rescue Errno::EPIPE => e
226
- debug { "epipe in on_eof => shallowing exception:#{e}" }
227
- rescue Errno::ENOTCONN => e
228
- debug { "enotconn in on_eof => shallowing exception:#{e}" }
229
- end
230
- end
231
-
232
- channel.on_close do |ch|
233
- debug { "closing #{type} forwarded channel" }
234
- ch[:socket].close if !client.closed?
235
- session.stop_listening_to(ch[:socket])
236
- end
237
-
238
- channel.on_process do |ch|
239
- if ch[:socket].closed?
240
- ch.info { "#{type} forwarded connection closed" }
241
- ch.close
242
- elsif ch[:socket].available > 0
243
- data = ch[:socket].read_available(8192)
244
- ch.debug { "read #{data.length} bytes from client, sending over #{type} forwarded connection" }
245
- ch.send_data(data)
246
- end
247
- end
248
- end
249
-
250
- # The callback used when a new "forwarded-tcpip" channel is requested
251
- # by the server. This will open a new socket to the host/port specified
252
- # when the forwarded connection was first requested.
253
- def forwarded_tcpip(session, channel, packet)
254
- connected_address = packet.read_string
255
- connected_port = packet.read_long
256
- originator_address = packet.read_string
257
- originator_port = packet.read_long
258
-
259
- remote = @remote_forwarded_ports[[connected_port, connected_address]]
260
-
261
- if remote.nil?
262
- raise Net::SSH::ChannelOpenFailed.new(1, "unknown request from remote forwarded connection on #{connected_address}:#{connected_port}")
263
- end
264
-
265
- client = TCPSocket.new(remote.host, remote.port)
266
- info { "connected #{connected_address}:#{connected_port} originator #{originator_address}:#{originator_port}" }
267
-
268
- prepare_client(client, channel, :remote)
269
- rescue SocketError => err
270
- raise Net::SSH::ChannelOpenFailed.new(2, "could not connect to remote host (#{remote.host}:#{remote.port}): #{err.message}")
271
- end
272
-
273
- # The callback used when an auth-agent channel is requested by the server.
274
- def auth_agent_channel(session, channel, packet)
275
- info { "opening auth-agent channel" }
276
- channel[:invisible] = true
277
-
278
- begin
279
- agent = Authentication::Agent.connect(logger)
280
- prepare_client(agent.socket, channel, :agent)
281
- rescue Exception => e
282
- error { "attempted to connect to agent but failed: #{e.class.name} (#{e.message})" }
283
- raise Net::SSH::ChannelOpenFailed.new(2, "could not connect to authentication agent")
284
- end
285
- end
286
- end
287
-
288
- end; end; end