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
data/Rakefile
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: UTF-8
|
2
1
|
#
|
3
2
|
# Also in your terminal environment run:
|
4
3
|
# $ export LANG=en_US.UTF-8
|
@@ -8,105 +7,157 @@
|
|
8
7
|
require "rubygems"
|
9
8
|
require "rake"
|
10
9
|
require "rake/clean"
|
11
|
-
|
12
|
-
require "rdoc/task"
|
13
|
-
|
14
|
-
task :default => ["build"]
|
15
|
-
CLEAN.include [ 'pkg', 'rdoc' ]
|
16
|
-
name = "net-ssh"
|
10
|
+
require "bundler/gem_tasks"
|
17
11
|
|
18
|
-
|
19
|
-
require "net/ssh"
|
20
|
-
version = Net::SSH::Version::CURRENT
|
12
|
+
require "rdoc/task"
|
21
13
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
s.name = name
|
27
|
-
s.rubyforge_project = s.name
|
28
|
-
s.summary = "Net::SSH: a pure-Ruby implementation of the SSH2 client protocol."
|
29
|
-
s.description = s.summary + " It allows you to write programs that invoke and interact with processes on remote servers, via SSH2."
|
30
|
-
s.email = "net-ssh@solutious.com"
|
31
|
-
s.homepage = "https://github.com/net-ssh/net-ssh"
|
32
|
-
s.authors = ["Jamis Buck", "Delano Mandelbaum", "Miklós Fazekas"]
|
33
|
-
s.required_ruby_version = '>= 2.0'
|
34
|
-
|
35
|
-
# Note: this is run at package time not install time so if you are
|
36
|
-
# running on jruby, you need to install jruby-pageant manually.
|
37
|
-
if RUBY_PLATFORM == "java"
|
38
|
-
s.add_dependency 'jruby-pageant', ">=1.1.1"
|
39
|
-
end
|
14
|
+
desc "When releasing make sure NET_SSH_BUILDGEM_SIGNED is set"
|
15
|
+
task :check_NET_SSH_BUILDGEM_SIGNED do
|
16
|
+
raise "NET_SSH_BUILDGEM_SIGNED should be set to release" unless ENV['NET_SSH_BUILDGEM_SIGNED']
|
17
|
+
end
|
40
18
|
|
41
|
-
|
42
|
-
|
19
|
+
Rake::Task[:release].enhance [:check_NET_SSH_BUILDGEM_SIGNED]
|
20
|
+
Rake::Task[:release].prerequisites.unshift(:check_NET_SSH_BUILDGEM_SIGNED)
|
43
21
|
|
44
|
-
|
22
|
+
task default: ["build"]
|
23
|
+
CLEAN.include ['pkg', 'rdoc']
|
24
|
+
name = "net-ssh"
|
45
25
|
|
46
|
-
|
47
|
-
|
48
|
-
s.signing_key = File.join('/mnt/gem/', 'net-ssh-private_key.pem')
|
49
|
-
s.cert_chain = ['net-ssh-public_cert.pem']
|
50
|
-
unless (Rake.application.top_level_tasks & ['build','install']).empty?
|
51
|
-
raise "No key found at #{signing_key} for signing, use rake <taskname> NET_SSH_NOKEY=1 to build without key" unless File.exist?(signing_key)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
Jeweler::RubygemsDotOrgTasks.new
|
56
|
-
rescue LoadError
|
57
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
58
|
-
end
|
26
|
+
require_relative "lib/net/ssh/version"
|
27
|
+
version = Net::SSH::Version::CURRENT
|
59
28
|
|
60
|
-
extra_files = %w[LICENSE.txt THANKS.txt CHANGES.txt
|
29
|
+
extra_files = %w[LICENSE.txt THANKS.txt CHANGES.txt]
|
61
30
|
RDoc::Task.new do |rdoc|
|
62
31
|
rdoc.rdoc_dir = "rdoc"
|
63
32
|
rdoc.title = "#{name} #{version}"
|
64
33
|
rdoc.generator = 'hanna' # gem install hanna-nouveau
|
65
|
-
rdoc.main = 'README.
|
34
|
+
rdoc.main = 'README.md'
|
66
35
|
rdoc.rdoc_files.include("README*")
|
67
36
|
rdoc.rdoc_files.include("bin/*.rb")
|
68
37
|
rdoc.rdoc_files.include("lib/**/*.rb")
|
69
38
|
extra_files.each { |file|
|
70
|
-
rdoc.rdoc_files.include(file) if File.
|
39
|
+
rdoc.rdoc_files.include(file) if File.exist?(file)
|
71
40
|
}
|
72
41
|
end
|
42
|
+
|
43
|
+
namespace :cert do
|
44
|
+
desc "Update public cert from private - only run if public is expired"
|
45
|
+
task :update_public_when_expired do
|
46
|
+
require 'openssl'
|
47
|
+
require 'time'
|
48
|
+
raw = File.read "net-ssh-public_cert.pem"
|
49
|
+
certificate = OpenSSL::X509::Certificate.new raw
|
50
|
+
raise Exception, "Not yet expired: #{certificate.not_after}" unless certificate.not_after < Time.now
|
51
|
+
|
52
|
+
sh "gem cert --build netssh@solutious.com --days 365*5 --private-key /mnt/gem/net-ssh-private_key.pem"
|
53
|
+
sh "mv gem-public_cert.pem net-ssh-public_cert.pem"
|
54
|
+
sh "gem cert --add net-ssh-public_cert.pem"
|
55
|
+
end
|
73
56
|
end
|
74
57
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
58
|
+
def change_version(&block)
|
59
|
+
version_file = 'lib/net/ssh/version.rb'
|
60
|
+
require_relative version_file
|
61
|
+
pre = Net::SSH::Version::PRE
|
62
|
+
result = block[pre: pre]
|
63
|
+
raise "Version change logic should always return a pre", ArgumentError unless result.key?(:pre)
|
64
|
+
|
65
|
+
new_pre = result[:pre]
|
66
|
+
found = false
|
67
|
+
File.open("#{version_file}.new", "w") do |f|
|
68
|
+
File.readlines(version_file).each do |line|
|
69
|
+
match = /^(\s+PRE\s+=\s+")#{pre}("\s*)$/.match(line)
|
70
|
+
if match
|
71
|
+
prefix = match[1]
|
72
|
+
postfix = match[2]
|
73
|
+
if new_pre.nil?
|
74
|
+
prefix.delete_suffix!('"')
|
75
|
+
postfix.delete_prefix!('"')
|
76
|
+
end
|
77
|
+
new_line = "#{prefix}#{new_pre.inspect}#{postfix}"
|
78
|
+
puts "Changing:\n - #{line} + #{new_line}"
|
79
|
+
line = new_line
|
80
|
+
found = true
|
81
|
+
end
|
82
|
+
f.write(line)
|
83
|
+
end
|
84
|
+
raise ArugmentError, "Cound not find line: PRE = \"#{pre}\" in #{version_file}" unless found
|
86
85
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
86
|
+
|
87
|
+
FileUtils.mv version_file, "#{version_file}.old"
|
88
|
+
FileUtils.mv "#{version_file}.new", version_file
|
89
|
+
end
|
90
|
+
|
91
|
+
namespace :vbump do
|
92
|
+
desc "Final release"
|
93
|
+
task :final do
|
94
|
+
change_version do |pre:|
|
95
|
+
raise ArgumentError, "Unexpected pre: #{pre}" if pre.nil?
|
96
|
+
|
97
|
+
{ pre: nil }
|
98
|
+
end
|
92
99
|
end
|
93
|
-
|
94
|
-
|
95
|
-
|
100
|
+
|
101
|
+
desc "Increment prerelease"
|
102
|
+
task :pre do
|
103
|
+
change_version do |pre:|
|
104
|
+
match = /^([a-z]+)(\d+)/.match(pre)
|
105
|
+
raise ArgumentError, "Unexpected pre: #{pre}" if match.nil?
|
106
|
+
|
107
|
+
{ pre: "#{match[1]}#{match[2].to_i + 1}" }
|
108
|
+
end
|
96
109
|
end
|
97
110
|
end
|
111
|
+
|
112
|
+
namespace :rdoc do
|
113
|
+
desc "Update gh-pages branch"
|
114
|
+
task :publish do
|
115
|
+
# copy/checkout
|
116
|
+
rm_rf "/tmp/net-ssh-rdoc"
|
117
|
+
rm_rf "/tmp/net-ssh-gh-pages"
|
118
|
+
cp_r "./rdoc", "/tmp/net-ssh-rdoc"
|
119
|
+
mkdir "/tmp/net-ssh-gh-pages"
|
120
|
+
Dir.chdir "/tmp/net-ssh-gh-pages" do
|
121
|
+
sh "git clone --branch gh-pages --single-branch https://github.com/net-ssh/net-ssh"
|
122
|
+
rm_rf "/tmp/net-ssh-gh-pages/net-ssh/*"
|
123
|
+
end
|
124
|
+
# update
|
125
|
+
sh "cp -rf ./rdoc/* /tmp/net-ssh-gh-pages/net-ssh/"
|
126
|
+
Dir.chdir "/tmp/net-ssh-gh-pages/net-ssh" do
|
127
|
+
sh "git add -A ."
|
128
|
+
sh "git commit -m \"Update docs\""
|
129
|
+
end
|
130
|
+
# publish
|
131
|
+
Dir.chdir "/tmp/net-ssh-gh-pages/net-ssh" do
|
132
|
+
sh "git push origin gh-pages"
|
133
|
+
end
|
134
|
+
end
|
98
135
|
end
|
99
136
|
|
100
137
|
require 'rake/testtask'
|
138
|
+
|
101
139
|
Rake::TestTask.new do |t|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
140
|
+
t.libs = ["lib", "test"]
|
141
|
+
t.libs << "test/integration" if ENV['NET_SSH_RUN_INTEGRATION_TESTS']
|
142
|
+
t.libs << "test/win_integration" if ENV['NET_SSH_RUN_WIN_INTEGRATION_TESTS']
|
143
|
+
test_files = FileList['test/**/test_*.rb']
|
144
|
+
test_files -= FileList['test/integration/**/test_*.rb'] unless ENV['NET_SSH_RUN_INTEGRATION_TESTS']
|
145
|
+
test_files -= FileList['test/win_integration/**/test_*.rb'] unless ENV['NET_SSH_RUN_WIN_INTEGRATION_TESTS']
|
146
|
+
test_files -= FileList['test/manual/test_*.rb']
|
147
|
+
test_files -= FileList['test/test_pageant.rb']
|
148
|
+
test_files -= FileList['test/test/**/test_*.rb']
|
149
|
+
t.test_files = test_files
|
107
150
|
end
|
108
151
|
|
109
|
-
|
110
|
-
|
111
|
-
|
152
|
+
# We need to enable the OpenSSL 3.0 legacy providers for our test suite
|
153
|
+
require 'openssl'
|
154
|
+
ENV['OPENSSL_CONF'] = 'test/openssl3.conf' if OpenSSL::OPENSSL_LIBRARY_VERSION.start_with? "OpenSSL 3"
|
155
|
+
|
156
|
+
desc "Run tests of Net::SSH:Test"
|
157
|
+
Rake::TestTask.new do |t|
|
158
|
+
t.name = "test_test"
|
159
|
+
# we need to run test/test separatedly as it hacks io + other modules
|
160
|
+
t.libs = ["lib", "test"]
|
161
|
+
test_files = FileList['test/test/**/test_*.rb']
|
162
|
+
t.test_files = test_files
|
112
163
|
end
|
data/SECURITY.md
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
## Security contact information
|
2
|
+
|
3
|
+
To report a security vulnerability, please use the
|
4
|
+
[GitHub private vulnerability reporting feature](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing/privately-reporting-a-security-vulnerability).
|
data/appveyor.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
version: '{build}'
|
2
|
+
|
3
|
+
skip_tags: true
|
4
|
+
|
5
|
+
environment:
|
6
|
+
matrix:
|
7
|
+
- ruby_version: "jruby-9.1.2.0"
|
8
|
+
- ruby_version: "26-x64"
|
9
|
+
- ruby_version: "25-x64"
|
10
|
+
- ruby_version: "24-x64"
|
11
|
+
- ruby_version: "23"
|
12
|
+
- ruby_version: "23-x64"
|
13
|
+
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- ruby_version: "jruby-9.1.2.0"
|
17
|
+
|
18
|
+
#init:
|
19
|
+
# - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
|
20
|
+
|
21
|
+
#on_finish:
|
22
|
+
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
|
23
|
+
|
24
|
+
|
25
|
+
platform:
|
26
|
+
- x86
|
27
|
+
|
28
|
+
install:
|
29
|
+
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
30
|
+
- if "%ruby_version%" == "jruby-9.1.2.0" ( cinst javaruntime -i )
|
31
|
+
- if "%ruby_version%" == "jruby-9.1.2.0" ( cinst jruby --version 9.1.2.0 -i --allow-empty-checksums )
|
32
|
+
- if "%ruby_version%" == "jruby-9.1.2.0" ( SET "PATH=C:\jruby-9.1.2.0\bin\;%PATH%" )
|
33
|
+
- ruby --version
|
34
|
+
- gem install bundler --no-document --user-install -v 1.17
|
35
|
+
- SET BUNDLE_GEMFILE=Gemfile.noed25519
|
36
|
+
- bundle install --retry=3
|
37
|
+
- cinst freesshd
|
38
|
+
- cinst putty --allow-empty-checksums
|
39
|
+
- ps: |
|
40
|
+
if ($env:Processor_Architecture -eq "x86")
|
41
|
+
{
|
42
|
+
dir 'C:\Program Files\'
|
43
|
+
dir 'C:\Program Files\freeSSHd'
|
44
|
+
cp 'test\win_integration\FreeSSHDService.ini' 'C:\Program Files\freeSSHd\FreeSSHDService.ini'
|
45
|
+
& 'C:\Program Files\freeSSHd\FreeSSHDService.exe'
|
46
|
+
} else {
|
47
|
+
dir 'C:\Program Files (x86)\'
|
48
|
+
dir 'C:\Program Files (x86)\freeSSHd'
|
49
|
+
cp 'test\win_integration\FreeSSHDService32.ini' 'C:\Program Files (x86)\freeSSHd\FreeSSHDService.ini'
|
50
|
+
& 'C:\Program Files (x86)\freeSSHd\FreeSSHDService.exe'
|
51
|
+
}
|
52
|
+
|
53
|
+
test_script:
|
54
|
+
- SET BUNDLE_GEMFILE=Gemfile.noed25519
|
55
|
+
- SET NET_SSH_RUN_WIN_INTEGRATION_TESTS=YES
|
56
|
+
- bundle exec rake test
|
57
|
+
|
58
|
+
build: off
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
version: '3'
|
2
|
+
|
3
|
+
services:
|
4
|
+
ruby-3.1:
|
5
|
+
build:
|
6
|
+
context: .
|
7
|
+
args:
|
8
|
+
RUBY_VERSION: 3.1
|
9
|
+
ruby-3.0:
|
10
|
+
build:
|
11
|
+
context: .
|
12
|
+
args:
|
13
|
+
RUBY_VERSION: 3.0
|
14
|
+
ruby-2.7:
|
15
|
+
build:
|
16
|
+
context: .
|
17
|
+
args:
|
18
|
+
RUBY_VERSION: 2.7
|
19
|
+
ruby-2.6:
|
20
|
+
build:
|
21
|
+
context: .
|
22
|
+
args:
|
23
|
+
RUBY_VERSION: 2.6
|
@@ -2,22 +2,283 @@ require 'net/ssh/buffer'
|
|
2
2
|
require 'net/ssh/errors'
|
3
3
|
require 'net/ssh/loggable'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
5
|
+
require 'net/ssh/transport/server_version'
|
6
|
+
require 'socket'
|
7
|
+
require 'rubygems'
|
8
|
+
|
9
|
+
require 'net/ssh/authentication/pageant' if Gem.win_platform? && RUBY_PLATFORM != "java"
|
10
|
+
|
11
|
+
module Net
|
12
|
+
module SSH
|
13
|
+
module Authentication
|
14
|
+
# Class for representing agent-specific errors.
|
15
|
+
class AgentError < Net::SSH::Exception; end
|
16
|
+
|
17
|
+
# An exception for indicating that the SSH agent is not available.
|
18
|
+
class AgentNotAvailable < AgentError; end
|
19
|
+
|
20
|
+
# This class implements a simple client for the ssh-agent protocol. It
|
21
|
+
# does not implement any specific protocol, but instead copies the
|
22
|
+
# behavior of the ssh-agent functions in the OpenSSH library (3.8).
|
23
|
+
#
|
24
|
+
# This means that although it behaves like a SSH1 client, it also has
|
25
|
+
# some SSH2 functionality (like signing data).
|
26
|
+
class Agent
|
27
|
+
include Loggable
|
28
|
+
|
29
|
+
# A simple module for extending keys, to allow comments to be specified
|
30
|
+
# for them.
|
31
|
+
module Comment
|
32
|
+
attr_accessor :comment
|
33
|
+
end
|
34
|
+
|
35
|
+
SSH2_AGENT_REQUEST_VERSION = 1
|
36
|
+
SSH2_AGENT_REQUEST_IDENTITIES = 11
|
37
|
+
SSH2_AGENT_IDENTITIES_ANSWER = 12
|
38
|
+
SSH2_AGENT_SIGN_REQUEST = 13
|
39
|
+
SSH2_AGENT_SIGN_RESPONSE = 14
|
40
|
+
SSH2_AGENT_ADD_IDENTITY = 17
|
41
|
+
SSH2_AGENT_REMOVE_IDENTITY = 18
|
42
|
+
SSH2_AGENT_REMOVE_ALL_IDENTITIES = 19
|
43
|
+
SSH2_AGENT_LOCK = 22
|
44
|
+
SSH2_AGENT_UNLOCK = 23
|
45
|
+
SSH2_AGENT_ADD_ID_CONSTRAINED = 25
|
46
|
+
SSH2_AGENT_FAILURE = 30
|
47
|
+
SSH2_AGENT_VERSION_RESPONSE = 103
|
48
|
+
|
49
|
+
SSH_COM_AGENT2_FAILURE = 102
|
50
|
+
|
51
|
+
SSH_AGENT_REQUEST_RSA_IDENTITIES = 1
|
52
|
+
SSH_AGENT_RSA_IDENTITIES_ANSWER1 = 2
|
53
|
+
SSH_AGENT_RSA_IDENTITIES_ANSWER2 = 5
|
54
|
+
SSH_AGENT_FAILURE = 5
|
55
|
+
SSH_AGENT_SUCCESS = 6
|
56
|
+
|
57
|
+
SSH_AGENT_CONSTRAIN_LIFETIME = 1
|
58
|
+
SSH_AGENT_CONSTRAIN_CONFIRM = 2
|
59
|
+
|
60
|
+
SSH_AGENT_RSA_SHA2_256 = 0x02
|
61
|
+
SSH_AGENT_RSA_SHA2_512 = 0x04
|
62
|
+
|
63
|
+
# The underlying socket being used to communicate with the SSH agent.
|
64
|
+
attr_reader :socket
|
65
|
+
|
66
|
+
# Instantiates a new agent object, connects to a running SSH agent,
|
67
|
+
# negotiates the agent protocol version, and returns the agent object.
|
68
|
+
def self.connect(logger = nil, agent_socket_factory = nil, identity_agent = nil)
|
69
|
+
agent = new(logger)
|
70
|
+
agent.connect!(agent_socket_factory, identity_agent)
|
71
|
+
agent.negotiate!
|
72
|
+
agent
|
73
|
+
end
|
74
|
+
|
75
|
+
# Creates a new Agent object, using the optional logger instance to
|
76
|
+
# report status.
|
77
|
+
def initialize(logger = nil)
|
78
|
+
self.logger = logger
|
79
|
+
end
|
80
|
+
|
81
|
+
# Connect to the agent process using the socket factory and socket name
|
82
|
+
# given by the attribute writers. If the agent on the other end of the
|
83
|
+
# socket reports that it is an SSH2-compatible agent, this will fail
|
84
|
+
# (it only supports the ssh-agent distributed by OpenSSH).
|
85
|
+
def connect!(agent_socket_factory = nil, identity_agent = nil)
|
86
|
+
debug { "connecting to ssh-agent" }
|
87
|
+
@socket =
|
88
|
+
if agent_socket_factory
|
89
|
+
agent_socket_factory.call
|
90
|
+
elsif identity_agent
|
91
|
+
unix_socket_class.open(File.expand_path(identity_agent))
|
92
|
+
elsif ENV['SSH_AUTH_SOCK'] && unix_socket_class
|
93
|
+
unix_socket_class.open(File.expand_path(ENV['SSH_AUTH_SOCK']))
|
94
|
+
elsif Gem.win_platform? && RUBY_ENGINE != "jruby"
|
95
|
+
Pageant::Socket.open
|
96
|
+
else
|
97
|
+
raise AgentNotAvailable, "Agent not configured"
|
98
|
+
end
|
99
|
+
rescue StandardError => e
|
100
|
+
error { "could not connect to ssh-agent: #{e.message}" }
|
101
|
+
raise AgentNotAvailable, $!.message
|
102
|
+
end
|
103
|
+
|
104
|
+
# Attempts to negotiate the SSH agent protocol version. Raises an error
|
105
|
+
# if the version could not be negotiated successfully.
|
106
|
+
def negotiate!
|
107
|
+
# determine what type of agent we're communicating with
|
108
|
+
type, body = send_and_wait(SSH2_AGENT_REQUEST_VERSION, :string, Transport::ServerVersion::PROTO_VERSION)
|
109
|
+
|
110
|
+
raise AgentNotAvailable, "SSH2 agents are not yet supported" if type == SSH2_AGENT_VERSION_RESPONSE
|
111
|
+
|
112
|
+
if type == SSH2_AGENT_FAILURE
|
113
|
+
debug { "Unexpected response type==#{type}, this will be ignored" }
|
114
|
+
elsif type != SSH_AGENT_RSA_IDENTITIES_ANSWER1 && type != SSH_AGENT_RSA_IDENTITIES_ANSWER2
|
115
|
+
raise AgentNotAvailable, "unknown response from agent: #{type}, #{body.to_s.inspect}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Return an array of all identities (public keys) known to the agent.
|
120
|
+
# Each key returned is augmented with a +comment+ property which is set
|
121
|
+
# to the comment returned by the agent for that key.
|
122
|
+
def identities
|
123
|
+
type, body = send_and_wait(SSH2_AGENT_REQUEST_IDENTITIES)
|
124
|
+
raise AgentError, "could not get identity count" if agent_failed(type)
|
125
|
+
raise AgentError, "bad authentication reply: #{type}" if type != SSH2_AGENT_IDENTITIES_ANSWER
|
126
|
+
|
127
|
+
identities = []
|
128
|
+
body.read_long.times do
|
129
|
+
key_str = body.read_string
|
130
|
+
comment_str = body.read_string
|
131
|
+
begin
|
132
|
+
key = Buffer.new(key_str).read_key
|
133
|
+
if key.nil?
|
134
|
+
error { "ignoring invalid key: #{comment_str}" }
|
135
|
+
next
|
136
|
+
end
|
137
|
+
key.extend(Comment)
|
138
|
+
key.comment = comment_str
|
139
|
+
identities.push key
|
140
|
+
rescue NotImplementedError => e
|
141
|
+
error { "ignoring unimplemented key:#{e.message} #{comment_str}" }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
return identities
|
146
|
+
end
|
147
|
+
|
148
|
+
# Closes this socket. This agent reference is no longer able to
|
149
|
+
# query the agent.
|
150
|
+
def close
|
151
|
+
@socket.close
|
152
|
+
end
|
153
|
+
|
154
|
+
# Using the agent and the given public key, sign the given data. The
|
155
|
+
# signature is returned in SSH2 format.
|
156
|
+
def sign(key, data, flags = 0)
|
157
|
+
type, reply = send_and_wait(SSH2_AGENT_SIGN_REQUEST, :string, Buffer.from(:key, key), :string, data, :long, flags)
|
158
|
+
|
159
|
+
raise AgentError, "agent could not sign data with requested identity" if agent_failed(type)
|
160
|
+
raise AgentError, "bad authentication response #{type}" if type != SSH2_AGENT_SIGN_RESPONSE
|
161
|
+
|
162
|
+
return reply.read_string
|
163
|
+
end
|
164
|
+
|
165
|
+
# Adds the private key with comment to the agent.
|
166
|
+
# If lifetime is given, the key will automatically be removed after lifetime
|
167
|
+
# seconds.
|
168
|
+
# If confirm is true, confirmation will be required for each agent signing
|
169
|
+
# operation.
|
170
|
+
def add_identity(priv_key, comment, lifetime: nil, confirm: false)
|
171
|
+
constraints = Buffer.new
|
172
|
+
if lifetime
|
173
|
+
constraints.write_byte(SSH_AGENT_CONSTRAIN_LIFETIME)
|
174
|
+
constraints.write_long(lifetime)
|
175
|
+
end
|
176
|
+
constraints.write_byte(SSH_AGENT_CONSTRAIN_CONFIRM) if confirm
|
177
|
+
|
178
|
+
req_type = constraints.empty? ? SSH2_AGENT_ADD_IDENTITY : SSH2_AGENT_ADD_ID_CONSTRAINED
|
179
|
+
type, = send_and_wait(req_type, :string, priv_key.ssh_type, :raw, blob_for_add(priv_key),
|
180
|
+
:string, comment, :raw, constraints)
|
181
|
+
raise AgentError, "could not add identity to agent" if type != SSH_AGENT_SUCCESS
|
182
|
+
end
|
183
|
+
|
184
|
+
# Removes key from the agent.
|
185
|
+
def remove_identity(key)
|
186
|
+
type, = send_and_wait(SSH2_AGENT_REMOVE_IDENTITY, :string, key.to_blob)
|
187
|
+
raise AgentError, "could not remove identity from agent" if type != SSH_AGENT_SUCCESS
|
188
|
+
end
|
189
|
+
|
190
|
+
# Removes all identities from the agent.
|
191
|
+
def remove_all_identities
|
192
|
+
type, = send_and_wait(SSH2_AGENT_REMOVE_ALL_IDENTITIES)
|
193
|
+
raise AgentError, "could not remove all identity from agent" if type != SSH_AGENT_SUCCESS
|
194
|
+
end
|
195
|
+
|
196
|
+
# lock the ssh agent with password
|
197
|
+
def lock(password)
|
198
|
+
type, = send_and_wait(SSH2_AGENT_LOCK, :string, password)
|
199
|
+
raise AgentError, "could not lock agent" if type != SSH_AGENT_SUCCESS
|
200
|
+
end
|
201
|
+
|
202
|
+
# unlock the ssh agent with password
|
203
|
+
def unlock(password)
|
204
|
+
type, = send_and_wait(SSH2_AGENT_UNLOCK, :string, password)
|
205
|
+
raise AgentError, "could not unlock agent" if type != SSH_AGENT_SUCCESS
|
206
|
+
end
|
207
|
+
|
208
|
+
private
|
209
|
+
|
210
|
+
def unix_socket_class
|
211
|
+
defined?(UNIXSocket) && UNIXSocket
|
212
|
+
end
|
213
|
+
|
214
|
+
# Send a new packet of the given type, with the associated data.
|
215
|
+
def send_packet(type, *args)
|
216
|
+
buffer = Buffer.from(*args)
|
217
|
+
data = [buffer.length + 1, type.to_i, buffer.to_s].pack("NCA*")
|
218
|
+
debug { "sending agent request #{type} len #{buffer.length}" }
|
219
|
+
@socket.send data, 0
|
220
|
+
end
|
221
|
+
|
222
|
+
# Read the next packet from the agent. This will return a two-part
|
223
|
+
# tuple consisting of the packet type, and the packet's body (which
|
224
|
+
# is returned as a Net::SSH::Buffer).
|
225
|
+
def read_packet
|
226
|
+
buffer = Net::SSH::Buffer.new(@socket.read(4))
|
227
|
+
buffer.append(@socket.read(buffer.read_long))
|
228
|
+
type = buffer.read_byte
|
229
|
+
debug { "received agent packet #{type} len #{buffer.length - 4}" }
|
230
|
+
return type, buffer
|
231
|
+
end
|
232
|
+
|
233
|
+
# Send the given packet and return the subsequent reply from the agent.
|
234
|
+
# (See #send_packet and #read_packet).
|
235
|
+
def send_and_wait(type, *args)
|
236
|
+
send_packet(type, *args)
|
237
|
+
read_packet
|
238
|
+
end
|
239
|
+
|
240
|
+
# Returns +true+ if the parameter indicates a "failure" response from
|
241
|
+
# the agent, and +false+ otherwise.
|
242
|
+
def agent_failed(type)
|
243
|
+
type == SSH_AGENT_FAILURE ||
|
244
|
+
type == SSH2_AGENT_FAILURE ||
|
245
|
+
type == SSH_COM_AGENT2_FAILURE
|
246
|
+
end
|
247
|
+
|
248
|
+
def blob_for_add(priv_key)
|
249
|
+
# Ideally we'd have something like `to_private_blob` on the various key types, but the
|
250
|
+
# nuances with encoding (e.g. `n` and `e` are reversed for RSA keys) make this impractical.
|
251
|
+
case priv_key.ssh_type
|
252
|
+
when /^ssh-dss$/
|
253
|
+
Net::SSH::Buffer.from(:bignum, priv_key.p, :bignum, priv_key.q, :bignum, priv_key.g,
|
254
|
+
:bignum, priv_key.pub_key, :bignum, priv_key.priv_key).to_s
|
255
|
+
when /^ssh-dss-cert-v01@openssh\.com$/
|
256
|
+
Net::SSH::Buffer.from(:string, priv_key.to_blob, :bignum, priv_key.key.priv_key).to_s
|
257
|
+
when /^ecdsa\-sha2\-(\w*)$/
|
258
|
+
curve_name = OpenSSL::PKey::EC::CurveNameAliasInv[priv_key.group.curve_name]
|
259
|
+
Net::SSH::Buffer.from(:string, curve_name, :mstring, priv_key.public_key.to_bn.to_s(2),
|
260
|
+
:bignum, priv_key.private_key).to_s
|
261
|
+
when /^ecdsa\-sha2\-(\w*)-cert-v01@openssh\.com$/
|
262
|
+
Net::SSH::Buffer.from(:string, priv_key.to_blob, :bignum, priv_key.key.private_key).to_s
|
263
|
+
when /^ssh-ed25519$/
|
264
|
+
Net::SSH::Buffer.from(:string, priv_key.public_key.verify_key.to_bytes,
|
265
|
+
:string, priv_key.sign_key.keypair).to_s
|
266
|
+
when /^ssh-ed25519-cert-v01@openssh\.com$/
|
267
|
+
# Unlike the other certificate types, the public key is included after the certifiate.
|
268
|
+
Net::SSH::Buffer.from(:string, priv_key.to_blob,
|
269
|
+
:string, priv_key.key.public_key.verify_key.to_bytes,
|
270
|
+
:string, priv_key.key.sign_key.keypair).to_s
|
271
|
+
when /^ssh-rsa$/
|
272
|
+
# `n` and `e` are reversed compared to the ordering in `OpenSSL::PKey::RSA#to_blob`.
|
273
|
+
Net::SSH::Buffer.from(:bignum, priv_key.n, :bignum, priv_key.e, :bignum, priv_key.d,
|
274
|
+
:bignum, priv_key.iqmp, :bignum, priv_key.p, :bignum, priv_key.q).to_s
|
275
|
+
when /^ssh-rsa-cert-v01@openssh\.com$/
|
276
|
+
Net::SSH::Buffer.from(:string, priv_key.to_blob, :bignum, priv_key.key.d,
|
277
|
+
:bignum, priv_key.key.iqmp, :bignum, priv_key.key.p,
|
278
|
+
:bignum, priv_key.key.q).to_s
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
23
284
|
end
|