net-ssh 5.0.2 → 7.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.dockerignore +6 -0
  4. data/.github/config/rubocop_linter_action.yml +4 -0
  5. data/.github/workflows/ci-with-docker.yml +44 -0
  6. data/.github/workflows/ci.yml +87 -0
  7. data/.github/workflows/rubocop.yml +13 -0
  8. data/.gitignore +3 -0
  9. data/.rubocop.yml +19 -2
  10. data/.rubocop_todo.yml +623 -511
  11. data/CHANGES.txt +76 -0
  12. data/Dockerfile +27 -0
  13. data/Dockerfile.openssl3 +17 -0
  14. data/Gemfile +2 -0
  15. data/Gemfile.noed25519 +2 -0
  16. data/Manifest +0 -1
  17. data/README.md +293 -0
  18. data/Rakefile +6 -2
  19. data/appveyor.yml +4 -2
  20. data/docker-compose.yml +23 -0
  21. data/lib/net/ssh/authentication/agent.rb +36 -14
  22. data/lib/net/ssh/authentication/certificate.rb +19 -7
  23. data/lib/net/ssh/authentication/constants.rb +0 -1
  24. data/lib/net/ssh/authentication/ed25519.rb +83 -50
  25. data/lib/net/ssh/authentication/ed25519_loader.rb +5 -8
  26. data/lib/net/ssh/authentication/key_manager.rb +74 -33
  27. data/lib/net/ssh/authentication/methods/abstract.rb +12 -3
  28. data/lib/net/ssh/authentication/methods/hostbased.rb +3 -5
  29. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +5 -3
  30. data/lib/net/ssh/authentication/methods/none.rb +6 -9
  31. data/lib/net/ssh/authentication/methods/password.rb +2 -3
  32. data/lib/net/ssh/authentication/methods/publickey.rb +58 -16
  33. data/lib/net/ssh/authentication/pageant.rb +97 -97
  34. data/lib/net/ssh/authentication/pub_key_fingerprint.rb +2 -3
  35. data/lib/net/ssh/authentication/session.rb +27 -23
  36. data/lib/net/ssh/buffer.rb +91 -40
  37. data/lib/net/ssh/buffered_io.rb +24 -26
  38. data/lib/net/ssh/config.rb +99 -53
  39. data/lib/net/ssh/connection/channel.rb +101 -87
  40. data/lib/net/ssh/connection/constants.rb +0 -4
  41. data/lib/net/ssh/connection/event_loop.rb +30 -25
  42. data/lib/net/ssh/connection/keepalive.rb +12 -12
  43. data/lib/net/ssh/connection/session.rb +115 -111
  44. data/lib/net/ssh/connection/term.rb +56 -58
  45. data/lib/net/ssh/errors.rb +12 -12
  46. data/lib/net/ssh/key_factory.rb +108 -22
  47. data/lib/net/ssh/known_hosts.rb +120 -36
  48. data/lib/net/ssh/loggable.rb +10 -11
  49. data/lib/net/ssh/packet.rb +1 -1
  50. data/lib/net/ssh/prompt.rb +9 -11
  51. data/lib/net/ssh/proxy/command.rb +1 -2
  52. data/lib/net/ssh/proxy/errors.rb +2 -4
  53. data/lib/net/ssh/proxy/http.rb +18 -20
  54. data/lib/net/ssh/proxy/https.rb +8 -10
  55. data/lib/net/ssh/proxy/jump.rb +8 -10
  56. data/lib/net/ssh/proxy/socks4.rb +2 -4
  57. data/lib/net/ssh/proxy/socks5.rb +3 -6
  58. data/lib/net/ssh/service/forward.rb +9 -8
  59. data/lib/net/ssh/test/channel.rb +24 -26
  60. data/lib/net/ssh/test/extensions.rb +37 -35
  61. data/lib/net/ssh/test/kex.rb +6 -8
  62. data/lib/net/ssh/test/local_packet.rb +0 -2
  63. data/lib/net/ssh/test/packet.rb +3 -3
  64. data/lib/net/ssh/test/remote_packet.rb +6 -8
  65. data/lib/net/ssh/test/script.rb +25 -27
  66. data/lib/net/ssh/test/socket.rb +12 -15
  67. data/lib/net/ssh/test.rb +12 -12
  68. data/lib/net/ssh/transport/algorithms.rb +177 -118
  69. data/lib/net/ssh/transport/cipher_factory.rb +34 -50
  70. data/lib/net/ssh/transport/constants.rb +13 -9
  71. data/lib/net/ssh/transport/ctr.rb +8 -14
  72. data/lib/net/ssh/transport/hmac/abstract.rb +20 -5
  73. data/lib/net/ssh/transport/hmac/md5.rb +0 -2
  74. data/lib/net/ssh/transport/hmac/md5_96.rb +0 -2
  75. data/lib/net/ssh/transport/hmac/none.rb +0 -2
  76. data/lib/net/ssh/transport/hmac/ripemd160.rb +0 -2
  77. data/lib/net/ssh/transport/hmac/sha1.rb +0 -2
  78. data/lib/net/ssh/transport/hmac/sha1_96.rb +0 -2
  79. data/lib/net/ssh/transport/hmac/sha2_256.rb +7 -11
  80. data/lib/net/ssh/transport/hmac/sha2_256_96.rb +4 -8
  81. data/lib/net/ssh/transport/hmac/sha2_256_etm.rb +12 -0
  82. data/lib/net/ssh/transport/hmac/sha2_512.rb +6 -9
  83. data/lib/net/ssh/transport/hmac/sha2_512_96.rb +4 -8
  84. data/lib/net/ssh/transport/hmac/sha2_512_etm.rb +12 -0
  85. data/lib/net/ssh/transport/hmac.rb +13 -11
  86. data/lib/net/ssh/transport/identity_cipher.rb +11 -13
  87. data/lib/net/ssh/transport/kex/abstract.rb +130 -0
  88. data/lib/net/ssh/transport/kex/abstract5656.rb +72 -0
  89. data/lib/net/ssh/transport/kex/curve25519_sha256.rb +39 -0
  90. data/lib/net/ssh/transport/kex/curve25519_sha256_loader.rb +30 -0
  91. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +5 -19
  92. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha256.rb +11 -0
  93. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +30 -139
  94. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +1 -8
  95. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb +5 -9
  96. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +20 -81
  97. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +5 -4
  98. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +5 -4
  99. data/lib/net/ssh/transport/kex.rb +15 -10
  100. data/lib/net/ssh/transport/key_expander.rb +7 -8
  101. data/lib/net/ssh/transport/openssl.rb +149 -111
  102. data/lib/net/ssh/transport/packet_stream.rb +53 -22
  103. data/lib/net/ssh/transport/server_version.rb +17 -16
  104. data/lib/net/ssh/transport/session.rb +35 -11
  105. data/lib/net/ssh/transport/state.rb +44 -44
  106. data/lib/net/ssh/verifiers/accept_new.rb +7 -2
  107. data/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb +1 -2
  108. data/lib/net/ssh/verifiers/always.rb +10 -4
  109. data/lib/net/ssh/verifiers/never.rb +4 -2
  110. data/lib/net/ssh/version.rb +2 -2
  111. data/lib/net/ssh.rb +17 -9
  112. data/net-ssh-public_cert.pem +18 -19
  113. data/net-ssh.gemspec +9 -7
  114. data/support/ssh_tunnel_bug.rb +3 -3
  115. data.tar.gz.sig +0 -0
  116. metadata +65 -41
  117. metadata.gz.sig +0 -0
  118. data/.travis.yml +0 -52
  119. data/Gemfile.noed25519.lock +0 -41
  120. data/README.rdoc +0 -169
  121. data/lib/net/ssh/ruby_compat.rb +0 -13
  122. data/support/arcfour_check.rb +0 -20
data/CHANGES.txt CHANGED
@@ -1,3 +1,79 @@
1
+ === 6.3.0 beta1
2
+
3
+ * Support cert based host key auth, fix asterisk in known_hosts [#833]
4
+ * Support kex dh-group14-sha256 [#795]
5
+ * Fix StrictHostKeyChecking ssh config parameter translation [#765]
6
+
7
+ === 6.2.0 rc1
8
+
9
+ === 6.2.0 beta1
10
+
11
+ * rsa-sha2-512, rsa-sha2-256 host_key algs [#771]
12
+ * JRuby aes*-ctr suppport [#767]
13
+
14
+ === 6.1.0
15
+
16
+ * Adapt to ssh's default behaviors when no username is provided.
17
+ When Net::SSH.start user is nil and config has no entry
18
+ we default to Etc.getpwuid.name() instead of Etc.getlogin(). [#749]
19
+
20
+ === 6.1.0.rc1
21
+
22
+ * Make sha2-{256,512}-etm@openssh.com MAC default again [#761]
23
+ * Support algorithm subtraction syntax from ssh_config [#751]
24
+
25
+ === 6.0.2
26
+
27
+ * Fix corrupted hmac issue in etm hmac [#759]
28
+
29
+ === 6.0.1
30
+
31
+ * Make sha2-{256,512}-etm@openssh.com MAC opt-in as they seems to have issues [#757]
32
+
33
+ === 6.0.0
34
+
35
+ * Support empty lines and comments in known_hosts [donoghuc, #742]
36
+ * Add sha2-{256,512}-etm@openssh.com MAC algorithms [graaff, #714]
37
+
38
+ === 6.0.0 beta2
39
+
40
+ * Support :certkeys and CertificateFile configuration option [Anders Carling, #722]
41
+
42
+ === 6.0.0 beta1
43
+
44
+ * curve25519sha256 support [Florian Wininger ,#690]
45
+ * disabled insecure algs [Florian Wininger , #709]
46
+
47
+ === 5.2.0
48
+
49
+ === 5.2.0.rc3
50
+
51
+ * Fix check_host_ip read from config
52
+ * Support ssh-ed25519 in known hosts
53
+
54
+ === 5.2.0.rc2
55
+
56
+ * Read check_host_ip from ssh config files
57
+
58
+ === 5.2.0.rc1
59
+
60
+ * Interpret * and ? in know_hosts file [Romain Tartière, #660]
61
+ * New :check_host_ip so ip checking can be disabled in known hosts [Romain Tartière, #656]
62
+
63
+ === 5.1.0
64
+
65
+ === 5.1.0.rc1
66
+
67
+ * Support new OpenSSH private key format for rsa - bcrypt for rsa (ed25519 already supported) [#646]
68
+ * Support IdentityAgent is ssh config [Frank Groeneveld, #645]
69
+ * Improve Match processing in ssh config [Aleksandrs Ļedovskis, #642]
70
+ * Ignore signature verification when verify_host_key is never [Piotr Kliczewski, #641]
71
+ * Alg preference was changed to prefer stronger encryptions [Tray, #637]
72
+
73
+ === 5.0.2
74
+
75
+ * Fix ctr for jruby [#612]
76
+
1
77
  === 5.0.1
2
78
 
3
79
  * default_keys were not loaded even if no keys or key_data options specified [#607]
data/Dockerfile ADDED
@@ -0,0 +1,27 @@
1
+ ARG RUBY_VERSION=3.1
2
+ FROM ruby:${RUBY_VERSION}
3
+
4
+ RUN apt update && apt install -y openssh-server sudo netcat \
5
+ && useradd --create-home --shell '/bin/bash' --comment 'NetSSH' 'net_ssh_1' \
6
+ && useradd --create-home --shell '/bin/bash' --comment 'NetSSH' 'net_ssh_2' \
7
+ && echo net_ssh_1:foopwd | chpasswd \
8
+ && echo net_ssh_2:foo2pwd | chpasswd \
9
+ && mkdir -p /home/net_ssh_1/.ssh \
10
+ && mkdir -p /home/net_ssh_2/.ssh \
11
+ && echo "net_ssh_1 ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
12
+ && echo "net_ssh_2 ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
13
+ && ssh-keygen -f /etc/ssh/users_ca -N ''
14
+
15
+ ENV INSTALL_PATH="/netssh"
16
+
17
+ WORKDIR $INSTALL_PATH
18
+
19
+ COPY Gemfile net-ssh.gemspec $INSTALL_PATH/
20
+
21
+ COPY lib/net/ssh/version.rb $INSTALL_PATH/lib/net/ssh/version.rb
22
+
23
+ RUN gem install bundler && bundle install
24
+
25
+ COPY . $INSTALL_PATH/
26
+
27
+ CMD service ssh start && rake test && NET_SSH_NO_ED25519=1 rake test
@@ -0,0 +1,17 @@
1
+ FROM ubuntu:22.04
2
+
3
+ ENV INSTALL_PATH="/netssh"
4
+
5
+ RUN apt update && apt install -y openssl ruby ruby-dev git build-essential
6
+
7
+ WORKDIR $INSTALL_PATH
8
+
9
+ COPY Gemfile net-ssh.gemspec $INSTALL_PATH/
10
+
11
+ COPY lib/net/ssh/version.rb $INSTALL_PATH/lib/net/ssh/version.rb
12
+
13
+ RUN ls -l && gem install bundler && bundle install
14
+
15
+ COPY . $INSTALL_PATH/
16
+
17
+ CMD openssl version && ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION' && rake test
data/Gemfile CHANGED
@@ -9,3 +9,5 @@ if ENV["CI"]
9
9
  gem 'codecov', require: false, group: :test
10
10
  gem 'simplecov', require: false, group: :test
11
11
  end
12
+
13
+ gem 'webrick', group: %i[development test] if RUBY_VERSION.split(".")[0].to_i >= 3
data/Gemfile.noed25519 CHANGED
@@ -8,3 +8,5 @@ if ENV["CI"] && !Gem.win_platform?
8
8
  gem 'simplecov', require: false, group: :test
9
9
  gem 'codecov', require: false, group: :test
10
10
  end
11
+
12
+ gem 'webrick', group: %i[development test] if RUBY_VERSION.split(".")[0].to_i >= 3
data/Manifest CHANGED
@@ -33,7 +33,6 @@ lib/net/ssh/proxy/errors.rb
33
33
  lib/net/ssh/proxy/http.rb
34
34
  lib/net/ssh/proxy/socks4.rb
35
35
  lib/net/ssh/proxy/socks5.rb
36
- lib/net/ssh/ruby_compat.rb
37
36
  lib/net/ssh/service/forward.rb
38
37
  lib/net/ssh/test.rb
39
38
  lib/net/ssh/test/channel.rb
data/README.md ADDED
@@ -0,0 +1,293 @@
1
+ [![Gem Version](https://badge.fury.io/rb/net-ssh.svg)](https://badge.fury.io/rb/net-ssh)
2
+ [![Join the chat at https://gitter.im/net-ssh/net-ssh](https://badges.gitter.im/net-ssh/net-ssh.svg)](https://gitter.im/net-ssh/net-ssh?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
3
+ [![Build status](https://github.com/net-ssh/net-ssh/actions/workflows/ci.yml/badge.svg)](https://github.com/net-ssh/net-ssh/actions/workflows/ci.yml)
4
+ [![Coverage status](https://codecov.io/gh/net-ssh/net-ssh/branch/master/graph/badge.svg)](https://codecov.io/gh/net-ssh/net-ssh)
5
+ [![Backers on Open Collective](https://opencollective.com/net-ssh/backers/badge.svg)](#backers])
6
+ [![Sponsors on Open Collective](https://opencollective.com/net-ssh/sponsors/badge.svg)](#sponsors)
7
+
8
+ # Net::SSH 6.x
9
+
10
+ * Docs: http://net-ssh.github.io/net-ssh
11
+ * Issues: https://github.com/net-ssh/net-ssh/issues
12
+ * Codes: https://github.com/net-ssh/net-ssh
13
+ * Email: net-ssh@solutious.com
14
+
15
+ *As of v2.6.4, all gem releases are signed. See [INSTALL](#install).*
16
+
17
+ ## DESCRIPTION:
18
+
19
+ Net::SSH is a pure-Ruby implementation of the SSH2 client protocol.
20
+ It allows you to write programs that invoke and interact with processes on remote servers, via SSH2.
21
+
22
+ ## FEATURES:
23
+
24
+ * Execute processes on remote servers and capture their output
25
+ * Run multiple processes in parallel over a single SSH connection
26
+ * Support for SSH subsystems
27
+ * Forward local and remote ports via an SSH connection
28
+
29
+ ## Supported Algorithms
30
+
31
+ Net::SSH 6.0 disables by default the usage of weak algorithms.
32
+ We strongly recommend that you install a servers's version that supports the latest algorithms.
33
+
34
+ It is possible to return to the previous behavior by adding the option : `append_all_supported_algorithms: true`
35
+
36
+ Unsecure algoritms will definitely be removed in Net::SSH 7.*.
37
+
38
+ ### Host Keys
39
+
40
+ | Name | Support | Details |
41
+ |----------------------|-----------------------|----------|
42
+ | ssh-rsa | OK | |
43
+ | ssh-ed25519 | OK | Require the gem `ed25519` |
44
+ | ecdsa-sha2-nistp521 | OK | [using weak elliptic curves](https://safecurves.cr.yp.to/) |
45
+ | ecdsa-sha2-nistp384 | OK | [using weak elliptic curves](https://safecurves.cr.yp.to/) |
46
+ | ecdsa-sha2-nistp256 | OK | [using weak elliptic curves](https://safecurves.cr.yp.to/) |
47
+ | ssh-dss | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
48
+
49
+ ### Key Exchange
50
+
51
+ | Name | Support | Details |
52
+ |--------------------------------------|-----------------------|----------|
53
+ | curve25519-sha256 | OK | Require the gem `x25519` |
54
+ | ecdh-sha2-nistp521 | OK | [using weak elliptic curves](https://safecurves.cr.yp.to/) |
55
+ | ecdh-sha2-nistp384 | OK | [using weak elliptic curves](https://safecurves.cr.yp.to/) |
56
+ | ecdh-sha2-nistp256 | OK | [using weak elliptic curves](https://safecurves.cr.yp.to/) |
57
+ | diffie-hellman-group1-sha1 | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
58
+ | diffie-hellman-group14-sha1 | OK | |
59
+ | diffie-hellman-group-exchange-sha1 | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
60
+ | diffie-hellman-group-exchange-sha256 | OK | |
61
+
62
+ ### Encryption algorithms (ciphers)
63
+
64
+ | Name | Support | Details |
65
+ |--------------------------------------|-----------------------|----------|
66
+ | aes256-ctr / aes192-ctr / aes128-ctr | OK | |
67
+ | aes256-cbc / aes192-cbc / aes128-cbc | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
68
+ | rijndael-cbc@lysator.liu.se | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
69
+ | blowfish-ctr blowfish-cbc | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
70
+ | cast128-ctr cast128-cbc | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
71
+ | 3des-ctr 3des-cbc | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
72
+ | idea-cbc | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
73
+ | none | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
74
+
75
+ ### Message Authentication Code algorithms
76
+
77
+ | Name | Support | Details |
78
+ |----------------------|-----------------------|----------|
79
+ | hmac-sha2-512-etm | OK | |
80
+ | hmac-sha2-256-etm | OK | |
81
+ | hmac-sha2-512 | OK | |
82
+ | hmac-sha2-256 | OK | |
83
+ | hmac-sha2-512-96 | Deprecated in 6.0 | removed from the specification, will be removed in 7.0 |
84
+ | hmac-sha2-256-96 | Deprecated in 6.0 | removed from the specification, will be removed in 7.0 |
85
+ | hmac-sha1 | OK | for backward compatibility |
86
+ | hmac-sha1-96 | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
87
+ | hmac-ripemd160 | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
88
+ | hmac-md5 | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
89
+ | hmac-md5-96 | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
90
+ | none | Deprecated in 6.0 | unsecure, will be removed in 7.0 |
91
+
92
+ ## SYNOPSIS:
93
+
94
+ In a nutshell:
95
+
96
+ ```ruby
97
+ require 'net/ssh'
98
+
99
+ Net::SSH.start('host', 'user', password: "password") do |ssh|
100
+
101
+ # capture all stderr and stdout output from a remote process
102
+ output = ssh.exec!("hostname")
103
+ puts output
104
+
105
+ # capture only stdout matching a particular pattern
106
+ stdout = ""
107
+ ssh.exec!("ls -l /home/jamis") do |channel, stream, data|
108
+ stdout << data if stream == :stdout && /foo/.match(data)
109
+ end
110
+ puts stdout
111
+
112
+ # run multiple processes in parallel to completion
113
+ ssh.exec "sed ..."
114
+ ssh.exec "awk ..."
115
+ ssh.exec "rm -rf ..."
116
+ ssh.loop
117
+
118
+ # open a new channel and configure a minimal set of callbacks, then run
119
+ # the event loop until the channel finishes (closes)
120
+ channel = ssh.open_channel do |ch|
121
+ ch.exec "/usr/local/bin/ruby /path/to/file.rb" do |ch, success|
122
+ raise "could not execute command" unless success
123
+
124
+ # "on_data" is called when the process writes something to stdout
125
+ ch.on_data do |c, data|
126
+ $stdout.print data
127
+ end
128
+
129
+ # "on_extended_data" is called when the process writes something to stderr
130
+ ch.on_extended_data do |c, type, data|
131
+ $stderr.print data
132
+ end
133
+
134
+ ch.on_close { puts "done!" }
135
+ end
136
+ end
137
+
138
+ channel.wait
139
+
140
+ # forward connections on local port 1234 to port 80 of www.capify.org
141
+ ssh.forward.local(1234, "www.capify.org", 80)
142
+ ssh.loop { true }
143
+ end
144
+ ```
145
+
146
+ See Net::SSH for more documentation, and links to further information.
147
+
148
+ ## REQUIREMENTS:
149
+
150
+ The only requirement you might be missing is the OpenSSL bindings for Ruby with a version greather than `1.0.1`.
151
+ These are built by default on most platforms, but you can verify that they're built and installed on your system by running the following command line:
152
+
153
+ ```sh
154
+ ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'
155
+ ```
156
+
157
+ If that spits out something like `OpenSSL 1.0.1 14 Mar 2012`, then you're set.
158
+ If you get an error, then you'll need to see about rebuilding ruby with OpenSSL support,
159
+ or (if your platform supports it) installing the OpenSSL bindings separately.
160
+
161
+ ## INSTALL:
162
+
163
+ ```sh
164
+ gem install net-ssh # might need sudo privileges
165
+ ```
166
+
167
+ NOTE: If you are running on jruby on windows you need to install `jruby-pageant` manually
168
+ (gemspec doesn't allow for platform specific dependencies at gem installation time).
169
+
170
+ However, in order to be sure the code you're installing hasn't been tampered with,
171
+ it's recommended that you verify the [signature](http://docs.rubygems.org/read/chapter/21).
172
+ To do this, you need to add my public key as a trusted certificate (you only need to do this once):
173
+
174
+ ```sh
175
+ # Add the public key as a trusted certificate
176
+ # (You only need to do this once)
177
+ curl -O https://raw.githubusercontent.com/net-ssh/net-ssh/master/net-ssh-public_cert.pem
178
+ gem cert --add net-ssh-public_cert.pem
179
+ ```
180
+
181
+ Then, when install the gem, do so with high security:
182
+
183
+ ```sh
184
+ gem install net-ssh -P HighSecurity
185
+ ```
186
+
187
+ If you don't add the public key, you'll see an error like "Couldn't verify data signature".
188
+ If you're still having trouble let me know and I'll give you a hand.
189
+
190
+ For ed25519 public key auth support your bundle file should contain `ed25519`, `bcrypt_pbkdf` dependencies.
191
+
192
+ ```sh
193
+ gem install ed25519
194
+ gem install bcrypt_pbkdf
195
+ ```
196
+
197
+ For curve25519-sha256 kex exchange support your bundle file should contain `x25519` dependency.
198
+
199
+ ## RUBY SUPPORT
200
+
201
+ * See [net-ssh.gemspec](https://github.com/net-ssh/net-ssh/blob/master/net-ssh.gemspec) for current versions ruby requirements
202
+
203
+ ## RUNNING TESTS
204
+
205
+ If you want to run the tests or use any of the Rake tasks, you'll need Mocha and
206
+ other dependencies listed in Gemfile
207
+
208
+ Run the test suite from the net-ssh directory with the following command:
209
+
210
+ ```sh
211
+ bundle exec rake test
212
+ ```
213
+
214
+ NOTE : you can run test on all ruby versions with docker :
215
+
216
+ ```
217
+ docker-compose up --build
218
+ ```
219
+
220
+ Run a single test file like this:
221
+
222
+ ```sh
223
+ ruby -Ilib -Itest test/transport/test_server_version.rb
224
+ ```
225
+
226
+ To run integration tests see [here](test/integration/README.md)
227
+
228
+ ### BUILDING GEM
229
+
230
+ ```sh
231
+ rake build
232
+ ```
233
+
234
+ ### GEM SIGNING (for maintainers)
235
+
236
+ If you have the net-ssh private signing key, you will be able to create signed release builds. Make sure the private key path matches the `signing_key` path set in `net-ssh.gemspec` and tell rake to sign the gem by setting the `NET_SSH_BUILDGEM_SIGNED` flag:
237
+
238
+ ```sh
239
+ NET_SSH_BUILDGEM_SIGNED=true rake build
240
+ ```
241
+
242
+ For time to time, the public certificate associated to the private key needs to be renewed. You can do this with the following command:
243
+
244
+ ```sh
245
+ gem cert --build netssh@solutious.com --private-key path/2/net-ssh-private_key.pem
246
+ mv gem-public_cert.pem net-ssh-public_cert.pem
247
+ gem cert --add net-ssh-public_cert.pem
248
+ ```
249
+
250
+ ## CREDITS
251
+
252
+ ### Contributors
253
+
254
+ This project exists thanks to all the people who contribute.
255
+
256
+ [![contributors](https://opencollective.com/net-ssh/contributors.svg?width=890&button=false)](graphs/contributors)
257
+
258
+ ### Backers
259
+
260
+ Thank you to all our backers! 🙏 [Become a backer](https://opencollective.com/net-ssh#backer)
261
+
262
+ [![backers](https://opencollective.com/net-ssh/backers.svg?width=890)](https://opencollective.com/net-ssh#backers)
263
+
264
+ ### Sponsors
265
+
266
+ Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor](https://opencollective.com/net-ssh#sponsor)
267
+
268
+ [![Sponsor](https://opencollective.com/net-ssh/sponsor/0/avatar.svg)](https://opencollective.com/net-ssh/sponsor/0/website)
269
+
270
+ ## LICENSE:
271
+
272
+ (The MIT License)
273
+
274
+ Copyright (c) 2008 Jamis Buck
275
+
276
+ Permission is hereby granted, free of charge, to any person obtaining
277
+ a copy of this software and associated documentation files (the
278
+ 'Software'), to deal in the Software without restriction, including
279
+ without limitation the rights to use, copy, modify, merge, publish,
280
+ distribute, sublicense, and/or sell copies of the Software, and to
281
+ permit persons to whom the Software is furnished to do so, subject to
282
+ the following conditions:
283
+
284
+ The above copyright notice and this permission notice shall be
285
+ included in all copies or substantial portions of the Software.
286
+
287
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
288
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
289
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
290
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
291
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
292
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
293
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  #
3
2
  # Also in your terminal environment run:
4
3
  # $ export LANG=en_US.UTF-8
@@ -32,7 +31,7 @@ RDoc::Task.new do |rdoc|
32
31
  rdoc.rdoc_dir = "rdoc"
33
32
  rdoc.title = "#{name} #{version}"
34
33
  rdoc.generator = 'hanna' # gem install hanna-nouveau
35
- rdoc.main = 'README.rdoc'
34
+ rdoc.main = 'README.md'
36
35
  rdoc.rdoc_files.include("README*")
37
36
  rdoc.rdoc_files.include("bin/*.rb")
38
37
  rdoc.rdoc_files.include("lib/**/*.rb")
@@ -49,6 +48,7 @@ namespace :cert do
49
48
  raw = File.read "net-ssh-public_cert.pem"
50
49
  certificate = OpenSSL::X509::Certificate.new raw
51
50
  raise Exception, "Not yet expired: #{certificate.not_after}" unless certificate.not_after < Time.now
51
+
52
52
  sh "gem cert --build netssh@solutious.com --days 365*5 --private-key /mnt/gem/net-ssh-private_key.pem"
53
53
  sh "mv gem-public_cert.pem net-ssh-public_cert.pem"
54
54
  sh "gem cert --add net-ssh-public_cert.pem"
@@ -95,6 +95,10 @@ Rake::TestTask.new do |t|
95
95
  t.test_files = test_files
96
96
  end
97
97
 
98
+ # We need to enable the OpenSSL 3.0 legacy providers for our test suite
99
+ require 'openssl'
100
+ ENV['OPENSSL_CONF'] = 'test/openssl3.conf' if OpenSSL::OPENSSL_LIBRARY_VERSION.start_with? "OpenSSL 3"
101
+
98
102
  desc "Run tests of Net::SSH:Test"
99
103
  Rake::TestTask.new do |t|
100
104
  t.name = "test_test"
data/appveyor.yml CHANGED
@@ -5,9 +5,11 @@ skip_tags: true
5
5
  environment:
6
6
  matrix:
7
7
  - ruby_version: "jruby-9.1.2.0"
8
+ - ruby_version: "26-x64"
9
+ - ruby_version: "25-x64"
10
+ - ruby_version: "24-x64"
8
11
  - ruby_version: "23"
9
12
  - ruby_version: "23-x64"
10
- - ruby_version: "22-x64"
11
13
 
12
14
  matrix:
13
15
  allow_failures:
@@ -29,7 +31,7 @@ install:
29
31
  - if "%ruby_version%" == "jruby-9.1.2.0" ( cinst jruby --version 9.1.2.0 -i --allow-empty-checksums )
30
32
  - if "%ruby_version%" == "jruby-9.1.2.0" ( SET "PATH=C:\jruby-9.1.2.0\bin\;%PATH%" )
31
33
  - ruby --version
32
- - gem install bundler --no-document --user-install -v 1.16
34
+ - gem install bundler --no-document --user-install -v 1.17
33
35
  - SET BUNDLE_GEMFILE=Gemfile.noed25519
34
36
  - bundle install --retry=3
35
37
  - cinst freesshd
@@ -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
@@ -13,6 +13,7 @@ module Net
13
13
  module Authentication
14
14
  # Class for representing agent-specific errors.
15
15
  class AgentError < Net::SSH::Exception; end
16
+
16
17
  # An exception for indicating that the SSH agent is not available.
17
18
  class AgentNotAvailable < AgentError; end
18
19
 
@@ -39,6 +40,8 @@ module Net
39
40
  SSH2_AGENT_ADD_IDENTITY = 17
40
41
  SSH2_AGENT_REMOVE_IDENTITY = 18
41
42
  SSH2_AGENT_REMOVE_ALL_IDENTITIES = 19
43
+ SSH2_AGENT_LOCK = 22
44
+ SSH2_AGENT_UNLOCK = 23
42
45
  SSH2_AGENT_ADD_ID_CONSTRAINED = 25
43
46
  SSH2_AGENT_FAILURE = 30
44
47
  SSH2_AGENT_VERSION_RESPONSE = 103
@@ -62,16 +65,16 @@ module Net
62
65
 
63
66
  # Instantiates a new agent object, connects to a running SSH agent,
64
67
  # negotiates the agent protocol version, and returns the agent object.
65
- def self.connect(logger=nil, agent_socket_factory = nil)
68
+ def self.connect(logger = nil, agent_socket_factory = nil, identity_agent = nil)
66
69
  agent = new(logger)
67
- agent.connect!(agent_socket_factory)
70
+ agent.connect!(agent_socket_factory, identity_agent)
68
71
  agent.negotiate!
69
72
  agent
70
73
  end
71
74
 
72
75
  # Creates a new Agent object, using the optional logger instance to
73
76
  # report status.
74
- def initialize(logger=nil)
77
+ def initialize(logger = nil)
75
78
  self.logger = logger
76
79
  end
77
80
 
@@ -79,13 +82,15 @@ module Net
79
82
  # given by the attribute writers. If the agent on the other end of the
80
83
  # socket reports that it is an SSH2-compatible agent, this will fail
81
84
  # (it only supports the ssh-agent distributed by OpenSSH).
82
- def connect!(agent_socket_factory = nil)
85
+ def connect!(agent_socket_factory = nil, identity_agent = nil)
83
86
  debug { "connecting to ssh-agent" }
84
87
  @socket =
85
88
  if agent_socket_factory
86
89
  agent_socket_factory.call
90
+ elsif identity_agent
91
+ unix_socket_class.open(File.expand_path(identity_agent))
87
92
  elsif ENV['SSH_AUTH_SOCK'] && unix_socket_class
88
- unix_socket_class.open(ENV['SSH_AUTH_SOCK'])
93
+ unix_socket_class.open(File.expand_path(ENV['SSH_AUTH_SOCK']))
89
94
  elsif Gem.win_platform? && RUBY_ENGINE != "jruby"
90
95
  Pageant::Socket.open
91
96
  else
@@ -103,6 +108,7 @@ module Net
103
108
  type, body = send_and_wait(SSH2_AGENT_REQUEST_VERSION, :string, Transport::ServerVersion::PROTO_VERSION)
104
109
 
105
110
  raise AgentNotAvailable, "SSH2 agents are not yet supported" if type == SSH2_AGENT_VERSION_RESPONSE
111
+
106
112
  if type == SSH2_AGENT_FAILURE
107
113
  debug { "Unexpected response type==#{type}, this will be ignored" }
108
114
  elsif type != SSH_AGENT_RSA_IDENTITIES_ANSWER1 && type != SSH_AGENT_RSA_IDENTITIES_ANSWER2
@@ -124,6 +130,10 @@ module Net
124
130
  comment_str = body.read_string
125
131
  begin
126
132
  key = Buffer.new(key_str).read_key
133
+ if key.nil?
134
+ error { "ignoring invalid key: #{comment_str}" }
135
+ next
136
+ end
127
137
  key.extend(Comment)
128
138
  key.comment = comment_str
129
139
  identities.push key
@@ -167,7 +177,7 @@ module Net
167
177
 
168
178
  req_type = constraints.empty? ? SSH2_AGENT_ADD_IDENTITY : SSH2_AGENT_ADD_ID_CONSTRAINED
169
179
  type, = send_and_wait(req_type, :string, priv_key.ssh_type, :raw, blob_for_add(priv_key),
170
- :string, comment, :raw, constraints)
180
+ :string, comment, :raw, constraints)
171
181
  raise AgentError, "could not add identity to agent" if type != SSH_AGENT_SUCCESS
172
182
  end
173
183
 
@@ -183,6 +193,18 @@ module Net
183
193
  raise AgentError, "could not remove all identity from agent" if type != SSH_AGENT_SUCCESS
184
194
  end
185
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
+
186
208
  private
187
209
 
188
210
  def unix_socket_class
@@ -229,31 +251,31 @@ module Net
229
251
  case priv_key.ssh_type
230
252
  when /^ssh-dss$/
231
253
  Net::SSH::Buffer.from(:bignum, priv_key.p, :bignum, priv_key.q, :bignum, priv_key.g,
232
- :bignum, priv_key.pub_key, :bignum, priv_key.priv_key).to_s
254
+ :bignum, priv_key.pub_key, :bignum, priv_key.priv_key).to_s
233
255
  when /^ssh-dss-cert-v01@openssh\.com$/
234
256
  Net::SSH::Buffer.from(:string, priv_key.to_blob, :bignum, priv_key.key.priv_key).to_s
235
257
  when /^ecdsa\-sha2\-(\w*)$/
236
258
  curve_name = OpenSSL::PKey::EC::CurveNameAliasInv[priv_key.group.curve_name]
237
259
  Net::SSH::Buffer.from(:string, curve_name, :mstring, priv_key.public_key.to_bn.to_s(2),
238
- :bignum, priv_key.private_key).to_s
260
+ :bignum, priv_key.private_key).to_s
239
261
  when /^ecdsa\-sha2\-(\w*)-cert-v01@openssh\.com$/
240
262
  Net::SSH::Buffer.from(:string, priv_key.to_blob, :bignum, priv_key.key.private_key).to_s
241
263
  when /^ssh-ed25519$/
242
264
  Net::SSH::Buffer.from(:string, priv_key.public_key.verify_key.to_bytes,
243
- :string, priv_key.sign_key.keypair).to_s
265
+ :string, priv_key.sign_key.keypair).to_s
244
266
  when /^ssh-ed25519-cert-v01@openssh\.com$/
245
267
  # Unlike the other certificate types, the public key is included after the certifiate.
246
268
  Net::SSH::Buffer.from(:string, priv_key.to_blob,
247
- :string, priv_key.key.public_key.verify_key.to_bytes,
248
- :string, priv_key.key.sign_key.keypair).to_s
269
+ :string, priv_key.key.public_key.verify_key.to_bytes,
270
+ :string, priv_key.key.sign_key.keypair).to_s
249
271
  when /^ssh-rsa$/
250
272
  # `n` and `e` are reversed compared to the ordering in `OpenSSL::PKey::RSA#to_blob`.
251
273
  Net::SSH::Buffer.from(:bignum, priv_key.n, :bignum, priv_key.e, :bignum, priv_key.d,
252
- :bignum, priv_key.iqmp, :bignum, priv_key.p, :bignum, priv_key.q).to_s
274
+ :bignum, priv_key.iqmp, :bignum, priv_key.p, :bignum, priv_key.q).to_s
253
275
  when /^ssh-rsa-cert-v01@openssh\.com$/
254
276
  Net::SSH::Buffer.from(:string, priv_key.to_blob, :bignum, priv_key.key.d,
255
- :bignum, priv_key.key.iqmp, :bignum, priv_key.key.p,
256
- :bignum, priv_key.key.q).to_s
277
+ :bignum, priv_key.key.iqmp, :bignum, priv_key.key.p,
278
+ :bignum, priv_key.key.q).to_s
257
279
  end
258
280
  end
259
281
  end