net-ssh 3.2.0.rc2 → 7.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +2 -2
- data/.dockerignore +6 -0
- data/.github/config/rubocop_linter_action.yml +4 -0
- data/.github/workflows/ci-with-docker.yml +44 -0
- data/.github/workflows/ci.yml +87 -0
- data/.github/workflows/rubocop.yml +16 -0
- data/.gitignore +13 -0
- data/.rubocop.yml +22 -0
- data/.rubocop_todo.yml +1081 -0
- data/CHANGES.txt +228 -7
- data/Dockerfile +27 -0
- data/Dockerfile.openssl3 +17 -0
- data/Gemfile +13 -0
- data/Gemfile.noed25519 +12 -0
- data/ISSUE_TEMPLATE.md +30 -0
- data/Manifest +4 -5
- data/README.md +297 -0
- data/Rakefile +125 -74
- data/SECURITY.md +4 -0
- data/appveyor.yml +58 -0
- data/docker-compose.yml +23 -0
- data/lib/net/ssh/authentication/agent.rb +279 -18
- data/lib/net/ssh/authentication/certificate.rb +183 -0
- data/lib/net/ssh/authentication/constants.rb +17 -15
- data/lib/net/ssh/authentication/ed25519.rb +186 -0
- data/lib/net/ssh/authentication/ed25519_loader.rb +31 -0
- data/lib/net/ssh/authentication/key_manager.rb +86 -39
- data/lib/net/ssh/authentication/methods/abstract.rb +67 -48
- data/lib/net/ssh/authentication/methods/hostbased.rb +34 -37
- data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +13 -13
- data/lib/net/ssh/authentication/methods/none.rb +16 -19
- data/lib/net/ssh/authentication/methods/password.rb +27 -17
- data/lib/net/ssh/authentication/methods/publickey.rb +96 -55
- data/lib/net/ssh/authentication/pageant.rb +471 -367
- data/lib/net/ssh/authentication/pub_key_fingerprint.rb +43 -0
- data/lib/net/ssh/authentication/session.rb +131 -121
- data/lib/net/ssh/buffer.rb +399 -300
- data/lib/net/ssh/buffered_io.rb +154 -150
- data/lib/net/ssh/config.rb +308 -185
- data/lib/net/ssh/connection/channel.rb +635 -613
- data/lib/net/ssh/connection/constants.rb +29 -29
- data/lib/net/ssh/connection/event_loop.rb +123 -0
- data/lib/net/ssh/connection/keepalive.rb +55 -51
- data/lib/net/ssh/connection/session.rb +620 -551
- data/lib/net/ssh/connection/term.rb +125 -123
- data/lib/net/ssh/errors.rb +101 -99
- data/lib/net/ssh/key_factory.rb +197 -105
- data/lib/net/ssh/known_hosts.rb +214 -127
- data/lib/net/ssh/loggable.rb +50 -49
- data/lib/net/ssh/packet.rb +83 -79
- data/lib/net/ssh/prompt.rb +50 -81
- data/lib/net/ssh/proxy/command.rb +105 -90
- data/lib/net/ssh/proxy/errors.rb +12 -10
- data/lib/net/ssh/proxy/http.rb +82 -79
- data/lib/net/ssh/proxy/https.rb +50 -0
- data/lib/net/ssh/proxy/jump.rb +54 -0
- data/lib/net/ssh/proxy/socks4.rb +2 -6
- data/lib/net/ssh/proxy/socks5.rb +14 -17
- data/lib/net/ssh/service/forward.rb +370 -317
- data/lib/net/ssh/test/channel.rb +145 -136
- data/lib/net/ssh/test/extensions.rb +131 -110
- data/lib/net/ssh/test/kex.rb +34 -32
- data/lib/net/ssh/test/local_packet.rb +46 -44
- data/lib/net/ssh/test/packet.rb +89 -70
- data/lib/net/ssh/test/remote_packet.rb +32 -30
- data/lib/net/ssh/test/script.rb +156 -142
- data/lib/net/ssh/test/socket.rb +49 -48
- data/lib/net/ssh/test.rb +82 -77
- data/lib/net/ssh/transport/algorithms.rb +441 -360
- data/lib/net/ssh/transport/cipher_factory.rb +96 -98
- data/lib/net/ssh/transport/constants.rb +32 -24
- data/lib/net/ssh/transport/ctr.rb +42 -22
- data/lib/net/ssh/transport/hmac/abstract.rb +81 -63
- data/lib/net/ssh/transport/hmac/md5.rb +0 -2
- data/lib/net/ssh/transport/hmac/md5_96.rb +0 -2
- data/lib/net/ssh/transport/hmac/none.rb +0 -2
- data/lib/net/ssh/transport/hmac/ripemd160.rb +0 -2
- data/lib/net/ssh/transport/hmac/sha1.rb +0 -2
- data/lib/net/ssh/transport/hmac/sha1_96.rb +0 -2
- data/lib/net/ssh/transport/hmac/sha2_256.rb +7 -11
- data/lib/net/ssh/transport/hmac/sha2_256_96.rb +4 -8
- data/lib/net/ssh/transport/hmac/sha2_256_etm.rb +12 -0
- data/lib/net/ssh/transport/hmac/sha2_512.rb +6 -9
- data/lib/net/ssh/transport/hmac/sha2_512_96.rb +4 -8
- data/lib/net/ssh/transport/hmac/sha2_512_etm.rb +12 -0
- data/lib/net/ssh/transport/hmac.rb +14 -12
- data/lib/net/ssh/transport/identity_cipher.rb +54 -52
- data/lib/net/ssh/transport/kex/abstract.rb +130 -0
- data/lib/net/ssh/transport/kex/abstract5656.rb +72 -0
- data/lib/net/ssh/transport/kex/curve25519_sha256.rb +39 -0
- data/lib/net/ssh/transport/kex/curve25519_sha256_loader.rb +30 -0
- data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +33 -40
- data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha256.rb +11 -0
- data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +119 -213
- data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -61
- data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb +5 -9
- data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +36 -90
- data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +18 -10
- data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +18 -10
- data/lib/net/ssh/transport/kex.rb +15 -12
- data/lib/net/ssh/transport/key_expander.rb +24 -20
- data/lib/net/ssh/transport/openssl.rb +161 -124
- data/lib/net/ssh/transport/packet_stream.rb +225 -185
- data/lib/net/ssh/transport/server_version.rb +55 -56
- data/lib/net/ssh/transport/session.rb +306 -255
- data/lib/net/ssh/transport/state.rb +178 -176
- data/lib/net/ssh/verifiers/accept_new.rb +33 -0
- data/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb +33 -0
- data/lib/net/ssh/verifiers/always.rb +58 -0
- data/lib/net/ssh/verifiers/never.rb +19 -0
- data/lib/net/ssh/version.rb +55 -53
- data/lib/net/ssh.rb +110 -47
- data/net-ssh-public_cert.pem +18 -18
- data/net-ssh.gemspec +36 -205
- data/support/ssh_tunnel_bug.rb +5 -5
- data.tar.gz.sig +0 -0
- metadata +153 -118
- metadata.gz.sig +0 -0
- data/.travis.yml +0 -18
- data/README.rdoc +0 -182
- data/lib/net/ssh/authentication/agent/java_pageant.rb +0 -85
- data/lib/net/ssh/authentication/agent/socket.rb +0 -178
- data/lib/net/ssh/ruby_compat.rb +0 -46
- data/lib/net/ssh/verifiers/lenient.rb +0 -30
- data/lib/net/ssh/verifiers/null.rb +0 -12
- data/lib/net/ssh/verifiers/secure.rb +0 -52
- data/lib/net/ssh/verifiers/strict.rb +0 -24
- data/setup.rb +0 -1585
- data/support/arcfour_check.rb +0 -20
- data/test/README.txt +0 -18
- data/test/authentication/methods/common.rb +0 -28
- data/test/authentication/methods/test_abstract.rb +0 -51
- data/test/authentication/methods/test_hostbased.rb +0 -114
- data/test/authentication/methods/test_keyboard_interactive.rb +0 -121
- data/test/authentication/methods/test_none.rb +0 -41
- data/test/authentication/methods/test_password.rb +0 -95
- data/test/authentication/methods/test_publickey.rb +0 -148
- data/test/authentication/test_agent.rb +0 -232
- data/test/authentication/test_key_manager.rb +0 -240
- data/test/authentication/test_session.rb +0 -107
- data/test/common.rb +0 -125
- data/test/configs/auth_off +0 -5
- data/test/configs/auth_on +0 -4
- data/test/configs/empty +0 -0
- data/test/configs/eqsign +0 -3
- data/test/configs/exact_match +0 -8
- data/test/configs/host_plus +0 -10
- data/test/configs/multihost +0 -4
- data/test/configs/negative_match +0 -6
- data/test/configs/nohost +0 -19
- data/test/configs/numeric_host +0 -4
- data/test/configs/proxy_remote_user +0 -2
- data/test/configs/send_env +0 -2
- data/test/configs/substitutes +0 -8
- data/test/configs/wild_cards +0 -14
- data/test/connection/test_channel.rb +0 -487
- data/test/connection/test_session.rb +0 -564
- data/test/integration/README.txt +0 -17
- data/test/integration/Vagrantfile +0 -12
- data/test/integration/common.rb +0 -63
- data/test/integration/playbook.yml +0 -56
- data/test/integration/test_forward.rb +0 -637
- data/test/integration/test_id_rsa_keys.rb +0 -96
- data/test/integration/test_proxy.rb +0 -93
- data/test/known_hosts/github +0 -1
- data/test/known_hosts/github_hash +0 -1
- data/test/manual/test_pageant.rb +0 -37
- data/test/start/test_connection.rb +0 -53
- data/test/start/test_options.rb +0 -57
- data/test/start/test_transport.rb +0 -28
- data/test/start/test_user_nil.rb +0 -27
- data/test/test_all.rb +0 -12
- data/test/test_buffer.rb +0 -433
- data/test/test_buffered_io.rb +0 -63
- data/test/test_config.rb +0 -268
- data/test/test_key_factory.rb +0 -191
- data/test/test_known_hosts.rb +0 -66
- data/test/transport/hmac/test_md5.rb +0 -41
- data/test/transport/hmac/test_md5_96.rb +0 -27
- data/test/transport/hmac/test_none.rb +0 -34
- data/test/transport/hmac/test_ripemd160.rb +0 -36
- data/test/transport/hmac/test_sha1.rb +0 -36
- data/test/transport/hmac/test_sha1_96.rb +0 -27
- data/test/transport/hmac/test_sha2_256.rb +0 -37
- data/test/transport/hmac/test_sha2_256_96.rb +0 -27
- data/test/transport/hmac/test_sha2_512.rb +0 -37
- data/test/transport/hmac/test_sha2_512_96.rb +0 -27
- data/test/transport/kex/test_diffie_hellman_group14_sha1.rb +0 -13
- data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +0 -150
- data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +0 -96
- data/test/transport/kex/test_diffie_hellman_group_exchange_sha256.rb +0 -19
- data/test/transport/kex/test_ecdh_sha2_nistp256.rb +0 -161
- data/test/transport/kex/test_ecdh_sha2_nistp384.rb +0 -38
- data/test/transport/kex/test_ecdh_sha2_nistp521.rb +0 -38
- data/test/transport/test_algorithms.rb +0 -328
- data/test/transport/test_cipher_factory.rb +0 -443
- data/test/transport/test_hmac.rb +0 -34
- data/test/transport/test_identity_cipher.rb +0 -40
- data/test/transport/test_packet_stream.rb +0 -1762
- data/test/transport/test_server_version.rb +0 -74
- data/test/transport/test_session.rb +0 -331
- data/test/transport/test_state.rb +0 -181
- data/test/verifiers/test_secure.rb +0 -40
@@ -1,178 +0,0 @@
|
|
1
|
-
require 'net/ssh/transport/server_version'
|
2
|
-
|
3
|
-
# Only load pageant on Windows
|
4
|
-
if Net::SSH::Authentication::PLATFORM == :win32
|
5
|
-
require 'net/ssh/authentication/pageant'
|
6
|
-
end
|
7
|
-
|
8
|
-
module Net; module SSH; module Authentication
|
9
|
-
|
10
|
-
# This class implements a simple client for the ssh-agent protocol. It
|
11
|
-
# does not implement any specific protocol, but instead copies the
|
12
|
-
# behavior of the ssh-agent functions in the OpenSSH library (3.8).
|
13
|
-
#
|
14
|
-
# This means that although it behaves like a SSH1 client, it also has
|
15
|
-
# some SSH2 functionality (like signing data).
|
16
|
-
class Agent
|
17
|
-
include Loggable
|
18
|
-
|
19
|
-
# A simple module for extending keys, to allow comments to be specified
|
20
|
-
# for them.
|
21
|
-
module Comment
|
22
|
-
attr_accessor :comment
|
23
|
-
end
|
24
|
-
|
25
|
-
SSH2_AGENT_REQUEST_VERSION = 1
|
26
|
-
SSH2_AGENT_REQUEST_IDENTITIES = 11
|
27
|
-
SSH2_AGENT_IDENTITIES_ANSWER = 12
|
28
|
-
SSH2_AGENT_SIGN_REQUEST = 13
|
29
|
-
SSH2_AGENT_SIGN_RESPONSE = 14
|
30
|
-
SSH2_AGENT_FAILURE = 30
|
31
|
-
SSH2_AGENT_VERSION_RESPONSE = 103
|
32
|
-
|
33
|
-
SSH_COM_AGENT2_FAILURE = 102
|
34
|
-
|
35
|
-
SSH_AGENT_REQUEST_RSA_IDENTITIES = 1
|
36
|
-
SSH_AGENT_RSA_IDENTITIES_ANSWER1 = 2
|
37
|
-
SSH_AGENT_RSA_IDENTITIES_ANSWER2 = 5
|
38
|
-
SSH_AGENT_FAILURE = 5
|
39
|
-
|
40
|
-
# The underlying socket being used to communicate with the SSH agent.
|
41
|
-
attr_reader :socket
|
42
|
-
|
43
|
-
# Instantiates a new agent object, connects to a running SSH agent,
|
44
|
-
# negotiates the agent protocol version, and returns the agent object.
|
45
|
-
def self.connect(logger=nil, agent_socket_factory = nil)
|
46
|
-
agent = new(logger)
|
47
|
-
agent.connect!(agent_socket_factory)
|
48
|
-
agent.negotiate!
|
49
|
-
agent
|
50
|
-
end
|
51
|
-
|
52
|
-
# Creates a new Agent object, using the optional logger instance to
|
53
|
-
# report status.
|
54
|
-
def initialize(logger=nil)
|
55
|
-
self.logger = logger
|
56
|
-
end
|
57
|
-
|
58
|
-
# Connect to the agent process using the socket factory and socket name
|
59
|
-
# given by the attribute writers. If the agent on the other end of the
|
60
|
-
# socket reports that it is an SSH2-compatible agent, this will fail
|
61
|
-
# (it only supports the ssh-agent distributed by OpenSSH).
|
62
|
-
def connect!(agent_socket_factory = nil)
|
63
|
-
begin
|
64
|
-
debug { "connecting to ssh-agent" }
|
65
|
-
@socket = agent_socket_factory.nil? ? socket_class.open(ENV['SSH_AUTH_SOCK']) : agent_socket_factory.call
|
66
|
-
rescue
|
67
|
-
error { "could not connect to ssh-agent" }
|
68
|
-
raise AgentNotAvailable, $!.message
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# Attempts to negotiate the SSH agent protocol version. Raises an error
|
73
|
-
# if the version could not be negotiated successfully.
|
74
|
-
def negotiate!
|
75
|
-
# determine what type of agent we're communicating with
|
76
|
-
type, body = send_and_wait(SSH2_AGENT_REQUEST_VERSION, :string, Transport::ServerVersion::PROTO_VERSION)
|
77
|
-
|
78
|
-
if type == SSH2_AGENT_VERSION_RESPONSE
|
79
|
-
raise AgentNotAvailable, "SSH2 agents are not yet supported"
|
80
|
-
elsif type == SSH2_AGENT_FAILURE
|
81
|
-
debug { "Unexpected response type==#{type}, this will be ignored" }
|
82
|
-
elsif type != SSH_AGENT_RSA_IDENTITIES_ANSWER1 && type != SSH_AGENT_RSA_IDENTITIES_ANSWER2
|
83
|
-
raise AgentNotAvailable, "unknown response from agent: #{type}, #{body.to_s.inspect}"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# Return an array of all identities (public keys) known to the agent.
|
88
|
-
# Each key returned is augmented with a +comment+ property which is set
|
89
|
-
# to the comment returned by the agent for that key.
|
90
|
-
def identities
|
91
|
-
type, body = send_and_wait(SSH2_AGENT_REQUEST_IDENTITIES)
|
92
|
-
raise AgentError, "could not get identity count" if agent_failed(type)
|
93
|
-
raise AgentError, "bad authentication reply: #{type}" if type != SSH2_AGENT_IDENTITIES_ANSWER
|
94
|
-
|
95
|
-
identities = []
|
96
|
-
body.read_long.times do
|
97
|
-
key_str = body.read_string
|
98
|
-
comment_str = body.read_string
|
99
|
-
begin
|
100
|
-
key = Buffer.new(key_str).read_key
|
101
|
-
key.extend(Comment)
|
102
|
-
key.comment = comment_str
|
103
|
-
identities.push key
|
104
|
-
rescue NotImplementedError => e
|
105
|
-
error { "ignoring unimplemented key:#{e.message} #{comment_str}" }
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
return identities
|
110
|
-
end
|
111
|
-
|
112
|
-
# Closes this socket. This agent reference is no longer able to
|
113
|
-
# query the agent.
|
114
|
-
def close
|
115
|
-
@socket.close
|
116
|
-
end
|
117
|
-
|
118
|
-
# Using the agent and the given public key, sign the given data. The
|
119
|
-
# signature is returned in SSH2 format.
|
120
|
-
def sign(key, data)
|
121
|
-
type, reply = send_and_wait(SSH2_AGENT_SIGN_REQUEST, :string, Buffer.from(:key, key), :string, data, :long, 0)
|
122
|
-
|
123
|
-
if agent_failed(type)
|
124
|
-
raise AgentError, "agent could not sign data with requested identity"
|
125
|
-
elsif type != SSH2_AGENT_SIGN_RESPONSE
|
126
|
-
raise AgentError, "bad authentication response #{type}"
|
127
|
-
end
|
128
|
-
|
129
|
-
return reply.read_string
|
130
|
-
end
|
131
|
-
|
132
|
-
private
|
133
|
-
|
134
|
-
# Returns the agent socket factory to use.
|
135
|
-
def socket_class
|
136
|
-
if Net::SSH::Authentication::PLATFORM == :win32
|
137
|
-
Pageant::Socket
|
138
|
-
else
|
139
|
-
UNIXSocket
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
# Send a new packet of the given type, with the associated data.
|
144
|
-
def send_packet(type, *args)
|
145
|
-
buffer = Buffer.from(*args)
|
146
|
-
data = [buffer.length + 1, type.to_i, buffer.to_s].pack("NCA*")
|
147
|
-
debug { "sending agent request #{type} len #{buffer.length}" }
|
148
|
-
@socket.send data, 0
|
149
|
-
end
|
150
|
-
|
151
|
-
# Read the next packet from the agent. This will return a two-part
|
152
|
-
# tuple consisting of the packet type, and the packet's body (which
|
153
|
-
# is returned as a Net::SSH::Buffer).
|
154
|
-
def read_packet
|
155
|
-
buffer = Net::SSH::Buffer.new(@socket.read(4))
|
156
|
-
buffer.append(@socket.read(buffer.read_long))
|
157
|
-
type = buffer.read_byte
|
158
|
-
debug { "received agent packet #{type} len #{buffer.length-4}" }
|
159
|
-
return type, buffer
|
160
|
-
end
|
161
|
-
|
162
|
-
# Send the given packet and return the subsequent reply from the agent.
|
163
|
-
# (See #send_packet and #read_packet).
|
164
|
-
def send_and_wait(type, *args)
|
165
|
-
send_packet(type, *args)
|
166
|
-
read_packet
|
167
|
-
end
|
168
|
-
|
169
|
-
# Returns +true+ if the parameter indicates a "failure" response from
|
170
|
-
# the agent, and +false+ otherwise.
|
171
|
-
def agent_failed(type)
|
172
|
-
type == SSH_AGENT_FAILURE ||
|
173
|
-
type == SSH2_AGENT_FAILURE ||
|
174
|
-
type == SSH_COM_AGENT2_FAILURE
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
end; end; end
|
data/lib/net/ssh/ruby_compat.rb
DELETED
@@ -1,46 +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
|
-
def setbyte(index, c)
|
9
|
-
self[index] = c
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module Net; module SSH
|
15
|
-
|
16
|
-
# This class contains miscellaneous patches and workarounds
|
17
|
-
# for different ruby implementations.
|
18
|
-
class Compat
|
19
|
-
|
20
|
-
# A workaround for an IO#select threading bug in certain versions of MRI 1.8.
|
21
|
-
# See: http://net-ssh.lighthouseapp.com/projects/36253/tickets/1-ioselect-threading-bug-in-ruby-18
|
22
|
-
# The root issue is documented here: http://redmine.ruby-lang.org/issues/show/1993
|
23
|
-
if RUBY_VERSION >= '1.9' || RUBY_PLATFORM == 'java'
|
24
|
-
def self.io_select(*params)
|
25
|
-
IO.select(*params)
|
26
|
-
end
|
27
|
-
else
|
28
|
-
SELECT_MUTEX = Mutex.new
|
29
|
-
def self.io_select(*params)
|
30
|
-
# It should be safe to wrap calls in a mutex when the timeout is 0
|
31
|
-
# (that is, the call is not supposed to block).
|
32
|
-
# We leave blocking calls unprotected to avoid causing deadlocks.
|
33
|
-
# This should still catch the main case for Capistrano users.
|
34
|
-
if params[3] == 0
|
35
|
-
SELECT_MUTEX.synchronize do
|
36
|
-
IO.select(*params)
|
37
|
-
end
|
38
|
-
else
|
39
|
-
IO.select(*params)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
end; end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'net/ssh/verifiers/strict'
|
2
|
-
|
3
|
-
module Net; module SSH; module Verifiers
|
4
|
-
|
5
|
-
# Basically the same as the Strict verifier, but does not try to actually
|
6
|
-
# verify a connection if the server is the localhost and the port is a
|
7
|
-
# nonstandard port number. Those two conditions will typically mean the
|
8
|
-
# connection is being tunnelled through a forwarded port, so the known-hosts
|
9
|
-
# file will not be helpful (in general).
|
10
|
-
class Lenient < Strict
|
11
|
-
# Tries to determine if the connection is being tunnelled, and if so,
|
12
|
-
# returns true. Otherwise, performs the standard strict verification.
|
13
|
-
def verify(arguments)
|
14
|
-
return true if tunnelled?(arguments)
|
15
|
-
super
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
# A connection is potentially being tunnelled if the port is not 22,
|
21
|
-
# and the ip refers to the localhost.
|
22
|
-
def tunnelled?(args)
|
23
|
-
return false if args[:session].port == Net::SSH::Transport::Session::DEFAULT_PORT
|
24
|
-
|
25
|
-
ip = args[:session].peer[:ip]
|
26
|
-
return ip == "127.0.0.1" || ip == "::1"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end; end; end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module Net; module SSH; module Verifiers
|
2
|
-
|
3
|
-
# The Null host key verifier simply allows every key it sees, without
|
4
|
-
# bothering to verify. This is simple, but is not particularly secure.
|
5
|
-
class Null
|
6
|
-
# Returns true.
|
7
|
-
def verify(arguments)
|
8
|
-
true
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
end; end; end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'net/ssh/errors'
|
2
|
-
require 'net/ssh/known_hosts'
|
3
|
-
|
4
|
-
module Net; module SSH; module Verifiers
|
5
|
-
|
6
|
-
# Does a strict host verification, looking the server up in the known
|
7
|
-
# host files to see if a key has already been seen for this server. If this
|
8
|
-
# server does not appear in any host file, an exception will be raised
|
9
|
-
# (HostKeyUnknown). This is in contrast to the "Strict" class, which will
|
10
|
-
# silently add the key to your known_hosts file. If the server does appear at
|
11
|
-
# least once, but the key given does not match any known for the server, an
|
12
|
-
# exception will be raised (HostKeyMismatch).
|
13
|
-
# Otherwise, this returns true.
|
14
|
-
class Secure
|
15
|
-
def verify(arguments)
|
16
|
-
host_keys = arguments[:session].host_keys
|
17
|
-
|
18
|
-
# We've never seen this host before, so raise an exception.
|
19
|
-
if host_keys.empty?
|
20
|
-
process_cache_miss(host_keys, arguments, HostKeyUnknown, "is unknown")
|
21
|
-
end
|
22
|
-
|
23
|
-
# If we found any matches, check to see that the key type and
|
24
|
-
# blob also match.
|
25
|
-
found = host_keys.any? do |key|
|
26
|
-
key.ssh_type == arguments[:key].ssh_type &&
|
27
|
-
key.to_blob == arguments[:key].to_blob
|
28
|
-
end
|
29
|
-
|
30
|
-
# If a match was found, return true. Otherwise, raise an exception
|
31
|
-
# indicating that the key was not recognized.
|
32
|
-
unless found
|
33
|
-
process_cache_miss(host_keys, arguments, HostKeyMismatch, "does not match")
|
34
|
-
end
|
35
|
-
|
36
|
-
found
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def process_cache_miss(host_keys, args, exc_class, message)
|
42
|
-
exception = exc_class.new("fingerprint #{args[:fingerprint]} " +
|
43
|
-
"#{message} for #{host_keys.host.inspect}")
|
44
|
-
exception.data = args
|
45
|
-
exception.callback = Proc.new do
|
46
|
-
host_keys.add_host_key(args[:key])
|
47
|
-
end
|
48
|
-
raise exception
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end; end; end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'net/ssh/errors'
|
2
|
-
require 'net/ssh/known_hosts'
|
3
|
-
require 'net/ssh/verifiers/secure'
|
4
|
-
|
5
|
-
module Net; module SSH; module Verifiers
|
6
|
-
|
7
|
-
# Does a strict host verification, looking the server up in the known
|
8
|
-
# host files to see if a key has already been seen for this server. If this
|
9
|
-
# server does not appear in any host file, this will silently add the
|
10
|
-
# server. If the server does appear at least once, but the key given does
|
11
|
-
# not match any known for the server, an exception will be raised (HostKeyMismatch).
|
12
|
-
# Otherwise, this returns true.
|
13
|
-
class Strict < Secure
|
14
|
-
def verify(arguments)
|
15
|
-
begin
|
16
|
-
super
|
17
|
-
rescue HostKeyUnknown => err
|
18
|
-
err.remember_host!
|
19
|
-
return true
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end; end; end
|