net-ssh 8.0.0.rc3 → 8.0.0.rc5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +4 -1
  3. data/.github/pull_request_template.md +1 -0
  4. data/.github/workflows/changelog.yml +43 -0
  5. data/CHANGES.txt +40 -0
  6. data/CONTRIBUTING.md +35 -0
  7. data/README.md +65 -48
  8. data/Rakefile +48 -0
  9. data/changelog.d/README.md +1 -0
  10. data/lib/net/ssh/authentication/agent.rb +4 -1
  11. data/lib/net/ssh/authentication/ed25519.rb +1 -1
  12. data/lib/net/ssh/authentication/key_manager.rb +22 -12
  13. data/lib/net/ssh/authentication/methods/abstract.rb +2 -8
  14. data/lib/net/ssh/authentication/methods/publickey.rb +3 -1
  15. data/lib/net/ssh/authentication/security_key.rb +71 -0
  16. data/lib/net/ssh/authentication/session.rb +29 -17
  17. data/lib/net/ssh/buffer.rb +6 -1
  18. data/lib/net/ssh/buffered_io.rb +40 -3
  19. data/lib/net/ssh/config.rb +16 -1
  20. data/lib/net/ssh/connection/channel.rb +49 -2
  21. data/lib/net/ssh/connection/session.rb +58 -8
  22. data/lib/net/ssh/errors.rb +24 -6
  23. data/lib/net/ssh/key_factory.rb +7 -1
  24. data/lib/net/ssh/known_hosts.rb +18 -8
  25. data/lib/net/ssh/multiplex/client.rb +162 -0
  26. data/lib/net/ssh/multiplex/control_path.rb +120 -0
  27. data/lib/net/ssh/multiplex/proxy_transport.rb +218 -0
  28. data/lib/net/ssh/multiplex.rb +130 -0
  29. data/lib/net/ssh/proxy/jump.rb +40 -2
  30. data/lib/net/ssh/service/forward.rb +26 -21
  31. data/lib/net/ssh/test.rb +2 -1
  32. data/lib/net/ssh/transport/algorithms.rb +71 -23
  33. data/lib/net/ssh/transport/hmac/sha1_etm.rb +12 -0
  34. data/lib/net/ssh/transport/hmac.rb +2 -0
  35. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +8 -0
  36. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +45 -15
  37. data/lib/net/ssh/transport/openssl.rb +2 -1
  38. data/lib/net/ssh/transport/session.rb +21 -44
  39. data/lib/net/ssh/verifiers/always.rb +0 -3
  40. data/lib/net/ssh/version.rb +1 -1
  41. data/lib/net/ssh.rb +132 -56
  42. data/net-ssh.gemspec +1 -1
  43. data/rakelib/changelog.rb +229 -0
  44. data.tar.gz.sig +0 -0
  45. metadata +23 -6
  46. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03f0ed4c48532bcfa337a176d655407155043de284d1428cd51a4bf2b7cb2f58
4
- data.tar.gz: 49e8bbef56ac3139f5bb05cfad70afb33dda44227e9ce17f4424bd5aed749b95
3
+ metadata.gz: fc2758b484a06811ec2853426957b79679aa701a9d2f1c8eada66af175f4184b
4
+ data.tar.gz: a784146c91fadc72022221fe35a81dcbcefda0f4adcf49a54864209de8043335
5
5
  SHA512:
6
- metadata.gz: 56ec747abdff1eb6a0cbfb03adb3f880246372afe864f421c4241881671b9ce49dc1dc37a30c9e75e52526284b7c05caab1f14d367f94a1cdd422e1cf4aea93d
7
- data.tar.gz: df092fc1f9da4c85eaf3b305890e0635b9d16d72b3bf05711180a9c28652d97a987be3011bbf7610363d0a9412dafa056c527172519a92c2bf77e7f228bcade8
6
+ metadata.gz: 4e0068af7ac00f3cd3f6c5e4a704d85b4dc42970368c9a8882114c8430e01f0d8c8fcc288fd9a4c544995f83bbf17394f65476afedbc394bf3b23ad3db8e505a
7
+ data.tar.gz: 7af8864863409e1d4f3dbe15d51efd7eac78c28a19eb0c54306337c40becfcb5aa620e3c2672b0a45fc20814b1ec59a106c3414c9519a9bb762d3ea14139a739
checksums.yaml.gz.sig CHANGED
@@ -1 +1,4 @@
1
- E��x��~o�$�>�d"W���f��WZ4���VE���[��*{dO�8F��dsd���E��I~���]�uԑL���=����= ]չ�Ӈ���I�>���J���Ç���;q=G� �B=�s,��!���9�-M~����������~�J�V:�a�o�s(�7 D6r|z�+H>� ��y�=���QF�)��R�m��)�E݇AO�-o�c��d�q�.��j�0�t���]�r$� ���щ}5�=d����
1
+ =�R R%�%���w�h�l� ��C�a��(�[�MJv�@tY��4!�A�>����h i�f
2
+ )'��R,?�A�,D+FX��^h�q�섘C�s��Ex#x�q�b_��� �̌9N�f@
3
+ ���� ��y���k
4
+ w6Ղ�G������y|�XX���rmY4&K���2�42}�ż��~u�� }�>�.G ��D�����X�@I6�=ߵr� �}�����*�V��T�l~�@��{����4J��>��̜�T�_�
@@ -0,0 +1 @@
1
+ <!-- After opening the PR, add a changelog.d/<PR number>.<type>.txt fragment (none, change, security, breaking or breaking-security) instead of editing CHANGES.txt; see CONTRIBUTING.md#changelog. -->
@@ -0,0 +1,43 @@
1
+ name: Changelog
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, synchronize, reopened, labeled, unlabeled]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ changelog:
12
+ if: ${{ github.event.pull_request.user.login != 'dependabot[bot]' }}
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ with:
17
+ # HEAD is the PR merged into the base branch; HEAD^1 is the base it was merged into.
18
+ fetch-depth: 2
19
+ - name: Set up Ruby 3.1
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: 3.1
23
+ - name: Validate fragments
24
+ run: rake changelog:check
25
+ - name: Require a fragment
26
+ if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-changelog') }}
27
+ env:
28
+ PR: ${{ github.event.number }}
29
+ run: |
30
+ changed=$(git diff --name-only HEAD^1 HEAD)
31
+ if echo "$changed" | grep -x 'CHANGES\.txt' > /dev/null; then
32
+ echo "::error::Don't edit CHANGES.txt, add a changelog.d/$PR.<type>.txt fragment instead, see CONTRIBUTING.md#changelog"
33
+ exit 1
34
+ fi
35
+ own=$(git diff --name-only --diff-filter=AMR HEAD^1 HEAD -- changelog.d/ | grep -E "^changelog\.d/$PR\.[a-z-]+(\.[0-9]+)?\.txt$" || true)
36
+ if [ -n "$own" ]; then
37
+ echo "Changelog fragments:"; echo "$own"
38
+ elif ! echo "$changed" | grep -v '^changelog\.d/' > /dev/null; then
39
+ echo "Only changelog.d/ changed, no fragment needed"
40
+ else
41
+ echo "::error::Add a changelog fragment named changelog.d/$PR.<type>.txt (use $PR.none.txt if nothing user-visible changed), see CONTRIBUTING.md#changelog"
42
+ exit 1
43
+ fi
data/CHANGES.txt CHANGED
@@ -1,3 +1,43 @@
1
+ === 8.0.0 rc5
2
+
3
+ * BREAKING: Security: a custom `verify_host_key` verifier must now implement `verify_signature` (deprecated since 5.1.0) or ArgumentError is raised; such verifiers were previously wrapped so the server's host key signature was never checked [#1050]
4
+ * BREAKING: Unsupported key types now raise `Net::SSH::UnsupportedKeyType` (a `Net::SSH::Exception`) instead of `NotImplementedError`; code that rescued `NotImplementedError` around key loading or connecting should rescue the new class [#945, #1060]
5
+ * BREAKING: `Net::SSH.start` raises ArgumentError for option values that are `nil` or arrays containing `nil` (deprecated since 4.0.0); omit the option to use the default or ssh_config value, the error names a value that turns it off where one exists (e.g. `proxy: false`, `keys: []`, `config: false`). `password: nil` and `passphrase: nil` are still accepted [#458, #1053]
6
+ * BREAKING: removed the `:paranoid` option (deprecated since 4.2.0); use `:verify_host_key` with the same values. Passing `:paranoid` raises ArgumentError [#1050]
7
+ * BREAKING: removed the `verify_host_key` values `false`, `true`, `:very` and `:secure` (deprecated since 5.0.0); use `:never`, `:accept_new_or_local_tunnel`, `:accept_new` and `:always` respectively. The old values raise ArgumentError naming the replacement [#1050]
8
+ * BREAKING: `Net::SSH::HostKeyEntries::PubKey` (the known_hosts entries returned by `KnownHosts.search_for`) no longer forwards methods to the wrapped key (deprecated since 7.0.0); use `ssh_type`, `to_blob` or `matches_key?`, or the new `key` reader for the wrapped public key [#1050]
9
+ * Security: `append_all_supported_algorithms: true` no longer enables the `none` cipher and MAC; name them explicitly (`encryption: '+none'`, `hmac: '+none'`) to use them [#1051]
10
+ * Security: `diffie-hellman-group-exchange-sha1/sha256` now requires groups of at least 2048 bits and requests sizes from the negotiated ciphers, as OpenSSH since 7.2, and rejects invalid server groups and DH public values; like OpenSSH, the requested group size is capped at 4096 bits for Cisco servers. Pass `minimum_dh_bits: 1024` to connect to legacy servers that only offer 1024-bit groups. `minimum_dh_bits` values other than 1024 no longer fail key exchange with "could not verify server signature" [#1049]
11
+ * Security: `diffie-hellman-group14-sha1` is no longer offered by default for key exchange, as in OpenSSH since 8.2; add `KexAlgorithms +diffie-hellman-group14-sha1` in ssh_config (or `kex: '+diffie-hellman-group14-sha1'`) or pass `append_all_supported_algorithms: true` to re-enable [#705, #1042]
12
+ * Changelog entries are now added as `changelog.d/<PR number>.<type>.txt` fragment files instead of editing CHANGES.txt, and CI requires one per PR; see CONTRIBUTING.md [#1058]
13
+ * `Net::SSH.start(host, user, control_master: :auto)` reuses an already running OpenSSH ControlMaster found via `:control_path` or ssh_config `ControlPath`, falling back to a normal connection when there is none [#443, #1057]
14
+ * Default `max_win_size` is now 2 MB as in OpenSSH (was 128 KB), which avoids truncated output from some devices (e.g. Mikrotik); pass `max_win_size: 0x20000` for the old behaviour [#726, #1055]
15
+ * Added `hmac-sha1-etm@openssh.com`, offered by default after the SHA2 etm MACs as in OpenSSH [#985, #1056]
16
+ * `Net::SSH::Proxy::Jump` `options:` values may be an Array for ssh_config options that can be given more than once (`IdentityFile`, `CertificateFile`, `SendEnv`); each element is passed as its own `-o Key=value`, an empty Array passes nothing, and a `nil` value (alone or in an Array) raises ArgumentError as in `Net::SSH.start` [#1052]
17
+ * `ssh-rsa-cert-v00@openssh.com` host keys are deprecated and warn when named in `host_key`/`HostKeyAlgorithms` or negotiated; net-ssh cannot parse v00 certificates, use `ssh-rsa-cert-v01@openssh.com` or a modern key type [#1051]
18
+ * README: weak algorithms (CBC/3DES/Blowfish ciphers, `ssh-dss`, `diffie-hellman-group1-sha1`, old MACs, ...) stay available as opt-ins for legacy servers rather than being removed in 8.0 [#1051]
19
+ * An ssh-agent that fails while listing keys (e.g. closes the connection) is now skipped and key files are still tried, as in OpenSSH, instead of aborting authentication [#867, #1048]
20
+ * `%r` in a ProxyCommand now defaults to the connection's user, as in OpenSSH, instead of raising unless `:remote_user` is set [#881, #787, #1047]
21
+ * `Net::SSH.start` no longer modifies the options hash passed to it [#989, #1046]
22
+ * `Session#exec!` with a block now returns an empty string with `exitstatus` (like the non-block form) instead of `nil` [#848, #1045]
23
+ * ssh_config `KexAlgorithms` is now honoured and maps to `:kex`, including `+`, `-` and `^`; it was previously ignored [#1042]
24
+ * `Net::SSH::Proxy::Jump.new` accepts `options:`, a Hash of ssh_config options passed to the jump host's ssh command as escaped `-o Key=value` arguments, e.g. `options: { 'StrictHostKeyChecking' => 'no' }` [#915, #1041]
25
+ * `Net::SSH::Proxy::Jump` no longer fails with "unknown key" or substitutes the target host when the `config:` path contains `%` [#1041]
26
+
27
+ === 8.0.0 rc4
28
+
29
+ * Security: RSA signatures using SHA-1 (`ssh-rsa`, `ssh-rsa-cert-v01@openssh.com`) are no longer offered by default for host keys or public key authentication, as in OpenSSH since 8.8; RSA keys keep working via rsa-sha2-256/512. For servers that only support SHA-1 add `HostKeyAlgorithms +ssh-rsa` / `PubkeyAcceptedAlgorithms +ssh-rsa` in ssh_config (or `host_key: '+ssh-rsa'` / `pubkey_algorithms: %w[+ssh-rsa]`), or pass `append_all_supported_algorithms: true` [#1039]
30
+ * Security: ssh_config `PubkeyAcceptedAlgorithms` (and its old name `PubkeyAcceptedKeyTypes`) is now honoured, including `+`, `-` and `^`, and `pubkey_algorithms` now applies to all key types instead of only RSA, adding `rsa-sha2-512`; DSA (`ssh-dss`) keys are no longer offered by default, as in OpenSSH since 7.0 — add `+ssh-dss` or pass `append_all_supported_algorithms: true` to re-enable [#923]
31
+ * Security: ssh_config `Ciphers`, `MACs`, `KexAlgorithms` and `HostKeyAlgorithms` lists starting with `+`, `-` or `^` now append to, remove from or prepend to the default list, as in OpenSSH, instead of silently enabling every supported algorithm including weak ones that are off by default; every listed item is honoured and `-` accepts wildcards. Pass `append_all_supported_algorithms: true` to also get the full supported list [#925]
32
+ * Support agent-backed FIDO/U2F security keys (sk-ecdsa-sha2-nistp256@openssh.com, sk-ssh-ed25519@openssh.com) for publickey auth [#1007]
33
+ * Port forwarding no longer buffers a whole stream in memory when one side reads slowly: like OpenSSH, window is granted only as data is written to the local socket, and the local socket is read only while the remote window has room. An application that writes everything to a forwarded port before reading anything now blocks once the window fills, as it would with `ssh -L` or a direct TCP connection; the old unbounded buffering hid this [#1037, #1003]
34
+ * Data forwarded to a local socket just before the remote end sends EOF or closes the channel is no longer truncated or dropped: it is written out before the socket is shut down or closed, without blocking the event loop until the local application reads [#1037]
35
+ * Multi-factor authentication works when the server's AuthenticationMethods order differs from net-ssh's: after each partial success the allowed methods are tried again, as OpenSSH does [#873, #872]
36
+ * `HostKeyError#host`, `#port` and `#ip` now return the connected host, port and IP (`ip` is nil through a ProxyCommand) instead of always nil [#963]
37
+ * OpenSSH-format private keys with Windows (CRLF) line endings now load [#922, #921]
38
+ * Send CHANNEL_EOF before CHANNEL_CLOSE when closing a session's remaining channels, as OpenSSH does; fixes hangs at close with servers that wait for EOF, such as some SFTP servers [#672]
39
+ * ssh_config: trailing `# comments` are now ignored, as in OpenSSH; a `#` inside quotes or in the middle of a word is kept [#990]
40
+
1
41
  === 8.0.0 rc3
2
42
 
3
43
  * Fix "Calling Net::SSH::Buffer methods on HostKeyEntries PubKey is deprecated" warnings printed on every connection to a host in known_hosts [#1026, #1027]
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,35 @@
1
+ # Contributing to net-ssh
2
+
3
+ Run the unit tests with `bundle exec rake test` and the linter with `bundle exec rubocop`; see [README.md](README.md) and [DEVELOPMENT.md](DEVELOPMENT.md) for integration tests and debugging tips.
4
+
5
+ ## Changelog
6
+
7
+ Don't edit `CHANGES.txt`. Instead, add a fragment file to `changelog.d/` in your PR; the release's version bump (`rake vbump:*`) moves all fragments into a new `=== <version>` section at the top of `CHANGES.txt` and deletes them.
8
+
9
+ A fragment is named `<number>.<type>.txt`, where `<number>` is the PR number (so open the PR first, then add the fragment), and contains a single UTF-8 paragraph: the entry as it should read in `CHANGES.txt`, without the bullet or prefix. Lines are joined, so it can be wrapped. If it doesn't end with a reference list such as `[#985, #1056]`, `[GHSA-xxxx-xxxx-xxxx]` or `[CVE-2024-12345, #1060]`, ` [#<number>]` is appended; write the list yourself to reference issues or advisories too.
10
+
11
+ | Type | Written as | Use for |
12
+ | ------------------- | ------------------------------ | ------------------------------------------------------------ |
13
+ | `breaking-security` | `* BREAKING: Security: <text>` | an incompatible change made for security |
14
+ | `breaking` | `* BREAKING: <text>` | an incompatible change |
15
+ | `security` | `* Security: <text>` | a security fix or hardening |
16
+ | `change` | `* <text>` | any other user-visible fix or feature |
17
+ | `none` | nothing | PRs with no user-visible change (tests, CI, docs, refactors) |
18
+
19
+ Examples:
20
+
21
+ ```sh
22
+ rake "changelog:new[1058,change,Session#exec! now returns the exit status]"
23
+ # changelog.d/1058.change.txt -> * Session#exec! now returns the exit status [#1058]
24
+
25
+ echo 'Removed the `:paranoid` option; use `:verify_host_key` [#1050]' > changelog.d/1050.breaking.txt
26
+ echo 'Reject packet lengths above 256 KB, as OpenSSH does [GHSA-pfqh-p9vh-wx4p]' > changelog.d/1060.security.txt
27
+ echo 'Custom verifiers must implement `verify_signature` [#1050]' > changelog.d/1050.breaking-security.txt
28
+ touch changelog.d/1061.none.txt
29
+ ```
30
+
31
+ For several entries from one PR add a suffix: `1050.breaking.txt`, `1050.breaking.2.txt` (`changelog:new` picks the next free one).
32
+
33
+ In a release section, entries are grouped as `BREAKING: Security:`, `BREAKING:`, `Security:`, then the rest; within a group fragments are ordered by number, newest first, followed by any hand-written entries from an `=== Unreleased` section in their written order. A final release with nothing to report still gets a `=== <version>` section saying `No changes since <previous version>.`
34
+
35
+ `rake changelog:check` validates the fragments and the `=== Unreleased` section, and `rake changelog:preview` prints the section the next release would add. CI fails a PR that edits `CHANGES.txt` or doesn't add or modify a `changelog.d/<PR number>.<type>.txt` fragment, unless it only touches `changelog.d/` or a maintainer adds the `skip-changelog` label; Dependabot PRs are skipped.
data/README.md CHANGED
@@ -28,67 +28,75 @@ It allows you to write programs that invoke and interact with processes on remot
28
28
 
29
29
  ## Supported Algorithms
30
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.
31
+ Net::SSH only offers secure algorithms by default.
32
+ We strongly recommend that you install a server version that supports the latest algorithms.
33
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 8.*.
34
+ Weak algorithms are still supported as opt-ins, so legacy servers such as embedded routers and old network gear stay reachable. To enable one, prefix it with `+` in the matching option, e.g. `encryption: '+aes256-cbc'`, `hmac: '+hmac-sha1-96'`, `kex: '+diffie-hellman-group1-sha1'`, `host_key: '+ssh-dss'`, or in ssh_config with `Ciphers`, `MACs`, `KexAlgorithms`, `HostKeyAlgorithms` and `PubkeyAcceptedAlgorithms` (e.g. `Ciphers +aes256-cbc`). Passing `append_all_supported_algorithms: true` appends every supported algorithm except the `none` cipher and MAC, which are only used when named explicitly (e.g. `encryption: '+none'`, `hmac: '+none'`).
37
35
 
38
36
  ### Host Keys
39
37
 
40
- | Name | Support | Details |
41
- |----------------------|-----------------------|----------|
42
- | ssh-rsa | OK | |
43
- | ssh-ed25519 | OK | Backed by Ruby OpenSSL raw Ed25519 APIs (`openssl >= 3.2.0`) |
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 8.0 |
38
+ | Name | Support | Details |
39
+ |------------------------------------------|------------------------|----------|
40
+ | ssh-ed25519 | OK | Backed by Ruby OpenSSL raw Ed25519 APIs (`openssl >= 3.2.0`) |
41
+ | ssh-ed25519-cert-v01@openssh.com | OK | Backed by Ruby OpenSSL raw Ed25519 APIs (`openssl >= 3.2.0`) |
42
+ | ecdsa-sha2-nistp521/384/256 | OK | [using weak elliptic curves](https://safecurves.cr.yp.to/) |
43
+ | ecdsa-sha2-nistp521/384/256-cert-v01@openssh.com | OK | [using weak elliptic curves](https://safecurves.cr.yp.to/) |
44
+ | rsa-sha2-512 | OK | |
45
+ | rsa-sha2-256 | OK | |
46
+ | ssh-rsa | Not offered by default | SHA-1 signatures, off by default as in OpenSSH 8.8; opt-in for legacy servers with `HostKeyAlgorithms +ssh-rsa` or `host_key: '+ssh-rsa'` |
47
+ | ssh-rsa-cert-v01@openssh.com | Not offered by default | SHA-1 signatures; opt-in for legacy servers |
48
+ | ssh-rsa-cert-v00@openssh.com | Deprecated | not offered by default, warns when used and will be removed; net-ssh cannot parse v00 certificates, use ssh-rsa-cert-v01@openssh.com or a modern key type |
49
+ | ssh-dss | Not offered by default | unsecure, off by default as in OpenSSH 7.0; opt-in for legacy servers |
50
+
51
+ RSA public key authentication likewise uses rsa-sha2-512 or rsa-sha2-256 by default; ssh-rsa and ssh-dss keys are only offered when enabled, e.g. with `PubkeyAcceptedAlgorithms +ssh-rsa` or `pubkey_algorithms: %w[+ssh-rsa]`.
48
52
 
49
53
  ### Key Exchange
50
54
 
51
- | Name | Support | Details |
52
- |--------------------------------------|-----------------------|----------|
53
- | curve25519-sha256 | OK | Backed by Ruby OpenSSL raw X25519 APIs (`openssl >= 3.2.0`) |
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 8.0 |
58
- | diffie-hellman-group14-sha1 | OK | |
59
- | diffie-hellman-group-exchange-sha1 | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
60
- | diffie-hellman-group-exchange-sha256 | OK | |
55
+ | Name | Support | Details |
56
+ |--------------------------------------|------------------------|----------|
57
+ | curve25519-sha256 | OK | Backed by Ruby OpenSSL raw X25519 APIs (`openssl >= 3.2.0`) |
58
+ | curve25519-sha256@libssh.org | OK | Backed by Ruby OpenSSL raw X25519 APIs (`openssl >= 3.2.0`) |
59
+ | ecdh-sha2-nistp521 | OK | [using weak elliptic curves](https://safecurves.cr.yp.to/) |
60
+ | ecdh-sha2-nistp384 | OK | [using weak elliptic curves](https://safecurves.cr.yp.to/) |
61
+ | ecdh-sha2-nistp256 | OK | [using weak elliptic curves](https://safecurves.cr.yp.to/) |
62
+ | diffie-hellman-group-exchange-sha256 | OK | |
63
+ | diffie-hellman-group14-sha256 | OK | |
64
+ | diffie-hellman-group14-sha1 | Not offered by default | SHA-1, off by default as in OpenSSH 8.2; opt-in for legacy servers with `KexAlgorithms +diffie-hellman-group14-sha1` or `kex: '+diffie-hellman-group14-sha1'` |
65
+ | diffie-hellman-group-exchange-sha1 | Not offered by default | unsecure; opt-in for legacy servers |
66
+ | diffie-hellman-group1-sha1 | Not offered by default | unsecure; opt-in for legacy servers |
61
67
 
62
68
  ### Encryption algorithms (ciphers)
63
69
 
64
- | Name | Support | Details |
65
- |--------------------------------------|-----------------------|----------|
66
- | aes256-ctr / aes192-ctr / aes128-ctr | OK | |
67
- | chacha20-poly1305@openssh.com | OK. | Backed by Ruby OpenSSL ChaCha20 and Poly1305 APIs (`openssl >= 3.2.0`) |
68
- | aes256-cbc / aes192-cbc / aes128-cbc | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
69
- | rijndael-cbc@lysator.liu.se | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
70
- | blowfish-ctr blowfish-cbc | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
71
- | cast128-ctr cast128-cbc | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
72
- | 3des-ctr 3des-cbc | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
73
- | idea-cbc | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
74
- | none | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
70
+ | Name | Support | Details |
71
+ |-----------------------------------------|------------------------|----------|
72
+ | chacha20-poly1305@openssh.com | OK | Backed by Ruby OpenSSL ChaCha20 and Poly1305 APIs (`openssl >= 3.2.0`) |
73
+ | aes256-ctr / aes192-ctr / aes128-ctr | OK | |
74
+ | aes256-gcm@openssh.com / aes128-gcm@openssh.com | OK | |
75
+ | aes256-cbc / aes192-cbc / aes128-cbc | Not offered by default | unsecure; opt-in for legacy servers |
76
+ | rijndael-cbc@lysator.liu.se | Not offered by default | unsecure; opt-in for legacy servers |
77
+ | blowfish-ctr blowfish-cbc | Not offered by default | unsecure; opt-in for legacy servers |
78
+ | cast128-ctr cast128-cbc | Not offered by default | unsecure; opt-in for legacy servers |
79
+ | 3des-ctr 3des-cbc | Not offered by default | unsecure; opt-in for legacy servers |
80
+ | idea-cbc | Not offered by default | unsecure; opt-in for legacy servers |
81
+ | none | Not offered by default | no encryption; only used when named explicitly, not added by `append_all_supported_algorithms` |
75
82
 
76
83
  ### Message Authentication Code algorithms
77
84
 
78
- | Name | Support | Details |
79
- |----------------------|-----------------------|----------|
80
- | hmac-sha2-512-etm | OK | |
81
- | hmac-sha2-256-etm | OK | |
82
- | hmac-sha2-512 | OK | |
83
- | hmac-sha2-256 | OK | |
84
- | hmac-sha2-512-96 | Deprecated in 6.0 | removed from the specification, will be removed in 8.0 |
85
- | hmac-sha2-256-96 | Deprecated in 6.0 | removed from the specification, will be removed in 8.0 |
86
- | hmac-sha1 | OK | for backward compatibility |
87
- | hmac-sha1-96 | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
88
- | hmac-ripemd160 | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
89
- | hmac-md5 | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
90
- | hmac-md5-96 | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
91
- | none | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
85
+ | Name | Support | Details |
86
+ |-------------------------------|------------------------|----------|
87
+ | hmac-sha2-512-etm@openssh.com | OK | |
88
+ | hmac-sha2-256-etm@openssh.com | OK | |
89
+ | hmac-sha1-etm@openssh.com | OK | for backward compatibility |
90
+ | hmac-sha2-512 | OK | |
91
+ | hmac-sha2-256 | OK | |
92
+ | hmac-sha1 | OK | for backward compatibility |
93
+ | hmac-sha2-512-96 | Not offered by default | removed from the specification; opt-in for legacy servers |
94
+ | hmac-sha2-256-96 | Not offered by default | removed from the specification; opt-in for legacy servers |
95
+ | hmac-sha1-96 | Not offered by default | unsecure; opt-in for legacy servers |
96
+ | hmac-ripemd160 / hmac-ripemd160@openssh.com | Not offered by default | unsecure; opt-in for legacy servers |
97
+ | hmac-md5 | Not offered by default | unsecure; opt-in for legacy servers |
98
+ | hmac-md5-96 | Not offered by default | unsecure; opt-in for legacy servers |
99
+ | none | Not offered by default | no integrity protection; only used when named explicitly, not added by `append_all_supported_algorithms` |
92
100
 
93
101
  ## SYNOPSIS:
94
102
 
@@ -194,6 +202,11 @@ Ed25519 public key auth is backed by Ruby OpenSSL. The `bcrypt_pbkdf` gem is onl
194
202
  gem install bcrypt_pbkdf
195
203
  ```
196
204
 
205
+ ### FIDO/U2F security keys
206
+
207
+ `sk-ecdsa-sha2-nistp256@openssh.com` and `sk-ssh-ed25519@openssh.com` keys work when held in `ssh-agent`.
208
+ Loading `sk-*` private key files from disk is not supported.
209
+
197
210
  ## RUBY SUPPORT
198
211
 
199
212
  * See [net-ssh.gemspec](https://github.com/net-ssh/net-ssh/blob/master/net-ssh.gemspec) for current versions ruby requirements
@@ -247,6 +260,10 @@ gem cert --add net-ssh-public_cert.pem
247
260
 
248
261
  or `rake cert:update_public_when_expired`
249
262
 
263
+ ## CONTRIBUTING
264
+
265
+ See [CONTRIBUTING.md](CONTRIBUTING.md), including how to add a changelog entry.
266
+
250
267
  ## Security contact information
251
268
 
252
269
  See [SECURITY.md](SECURITY.md)
data/Rakefile CHANGED
@@ -28,6 +28,7 @@ CLEAN.include ['pkg', 'rdoc']
28
28
  name = "net-ssh"
29
29
 
30
30
  require_relative "lib/net/ssh/version"
31
+ require_relative "rakelib/changelog"
31
32
  version = Net::SSH::Version::CURRENT
32
33
 
33
34
  extra_files = %w[LICENSE.txt THANKS.txt CHANGES.txt]
@@ -109,6 +110,15 @@ def change_version(&block)
109
110
  raise ArgumentError, "Cound not find line: TINY = \"#{tiny}\" in #{version_file}" unless found[:tiny] || new_tiny == tiny
110
111
  end
111
112
 
113
+ begin
114
+ heading = Changelog.heading(Net::SSH::Version::MAJOR, Net::SSH::Version::MINOR, new_tiny, new_pre)
115
+ section = Changelog.new(__dir__).release(heading)
116
+ rescue StandardError
117
+ FileUtils.rm_f "#{version_file}.new"
118
+ raise
119
+ end
120
+ puts section ? "Added to CHANGES.txt:\n#{section}" : "Nothing to release for a pre-release, CHANGES.txt unchanged"
121
+
112
122
  FileUtils.mv version_file, "#{version_file}.old"
113
123
  FileUtils.mv "#{version_file}.new", version_file
114
124
  end
@@ -148,6 +158,44 @@ namespace :vbump do
148
158
  end
149
159
  end
150
160
 
161
+ namespace :changelog do
162
+ changelog = Changelog.new(__dir__)
163
+
164
+ desc "Validate the fragments in changelog.d/"
165
+ task :check do
166
+ count = changelog.check.size
167
+ puts "#{count} valid changelog fragment#{'s' unless count == 1}"
168
+ rescue Changelog::Error => e
169
+ abort e.message
170
+ end
171
+
172
+ desc "Print the CHANGES.txt section the next version bump would write"
173
+ task :preview, [:heading] do |_t, args|
174
+ puts changelog.section(args[:heading] || "Unreleased") || "Nothing to release"
175
+ rescue Changelog::Error => e
176
+ abort e.message
177
+ end
178
+
179
+ desc "Create a fragment: rake \"changelog:new[1234,change,Text of the entry]\""
180
+ task :new, [:number, :type] do |_t, args|
181
+ abort "Usage: rake \"changelog:new[<PR number>,<#{Changelog::TYPES.keys.join('|')}>,<text>]\"" unless args[:number] && args[:type]
182
+ # Rake splits arguments on commas and strips the spaces around them, so take the text from the raw task string.
183
+ raw = Rake.application.top_level_tasks.find { |t| t.start_with?("changelog:new[") }
184
+ text = raw&.[](/\A[^\[]*\[[^,]*,[^,]*,\s*(.*)\]\z/m, 1) || args.extras.join(", ")
185
+ puts "Created #{changelog.new_fragment(args[:number], args[:type], text)}"
186
+ rescue Changelog::Error => e
187
+ abort e.message
188
+ end
189
+
190
+ desc "Write the fragments to CHANGES.txt under a heading, e.g. rake \"changelog:release[7.3.4]\" (vbump does this)"
191
+ task :release, [:heading] do |_t, args|
192
+ abort "Usage: rake \"changelog:release[<version heading>]\"" unless args[:heading]
193
+ puts changelog.release(args[:heading]) || "Nothing to release"
194
+ rescue Changelog::Error => e
195
+ abort e.message
196
+ end
197
+ end
198
+
151
199
  namespace :rdoc do
152
200
  desc "Update gh-pages branch"
153
201
  task :publish do
@@ -0,0 +1 @@
1
+ Changelog fragments: one `<PR number>.<type>.txt` file per user-visible change, assembled into `CHANGES.txt` when the version is bumped. See [CONTRIBUTING.md](../CONTRIBUTING.md#changelog).
@@ -152,7 +152,7 @@ module Net
152
152
  key.extend(Comment)
153
153
  key.comment = comment_str
154
154
  identities.push key
155
- rescue NotImplementedError => e
155
+ rescue Net::SSH::UnsupportedKeyType, NotImplementedError => e
156
156
  error { "ignoring unimplemented key:#{e.message} #{comment_str}" }
157
157
  end
158
158
  end
@@ -256,6 +256,9 @@ module Net
256
256
  def send_and_wait(type, *args)
257
257
  send_packet(type, *args)
258
258
  read_packet
259
+ rescue Errno::ECONNRESET, Errno::EPIPE => e
260
+ # Linux reports an agent that closes with our request unread as a reset, not EOF.
261
+ raise AgentClosedConnection, "agent closed the connection (#{e.class})"
259
262
  end
260
263
 
261
264
  # Returns +true+ if the parameter indicates a "failure" response from
@@ -74,7 +74,7 @@ module Net
74
74
  end
75
75
 
76
76
  def self.read(datafull, password)
77
- datafull = datafull.strip
77
+ datafull = datafull.strip.encode(universal_newline: true)
78
78
  raise ArgumentError.new("Expected #{MBEGIN} at start of private key") unless datafull.start_with?(MBEGIN)
79
79
  raise ArgumentError.new("Expected #{MEND} at end of private key") unless datafull.end_with?(MEND)
80
80
 
@@ -124,18 +124,16 @@ module Net
124
124
 
125
125
  user_identities = load_identities(prepared_identities, false, true)
126
126
 
127
- if agent
128
- agent.identities.each do |key|
129
- corresponding_user_identity = user_identities.detect { |identity|
130
- identity[:public_key] && identity[:public_key].to_blob == key.to_blob
131
- }
132
- # By identity: EC::Point#== raises TypeError when compared with other key types.
133
- user_identities.reject! { |identity| identity.equal?(corresponding_user_identity) }
134
-
135
- if !options[:keys_only] || corresponding_user_identity
136
- known_identities[key] = { from: :agent, identity: key }
137
- yield key
138
- end
127
+ agent_identities.each do |key|
128
+ corresponding_user_identity = user_identities.detect { |identity|
129
+ identity[:public_key] && identity[:public_key].to_blob == key.to_blob
130
+ }
131
+ # By identity: EC::Point#== raises TypeError when compared with other key types.
132
+ user_identities.reject! { |identity| identity.equal?(corresponding_user_identity) }
133
+
134
+ if !options[:keys_only] || corresponding_user_identity
135
+ known_identities[key] = { from: :agent, identity: key }
136
+ yield key
139
137
  end
140
138
  end
141
139
 
@@ -247,6 +245,18 @@ module Net
247
245
 
248
246
  private
249
247
 
248
+ # Like OpenSSH's pubkey_prepare, an agent that fails to list its keys is
249
+ # dropped for the session so that key files are still tried.
250
+ def agent_identities
251
+ return [] unless agent
252
+
253
+ agent.identities
254
+ rescue AgentError => e
255
+ error { "could not get identities from agent: #{e.class} (#{e.message})" }
256
+ self.use_agent = false
257
+ []
258
+ end
259
+
250
260
  # Load keycerts from files and data.
251
261
  def keycerts
252
262
  keycert_files.map { |keycert_file| KeyFactory.load_public_key(keycert_file) } +
@@ -20,9 +20,7 @@ module Net
20
20
  # this.
21
21
  attr_reader :key_manager
22
22
 
23
- # So far only affects algorithms used for rsa keys, but can be
24
- # extended to other keys, e.g after reading of
25
- # PubkeyAcceptedAlgorithms option from ssh_config file is implemented.
23
+ # public key algorithms to be used
26
24
  attr_reader :pubkey_algorithms
27
25
 
28
26
  # Instantiates a new authentication method.
@@ -31,11 +29,7 @@ module Net
31
29
  @key_manager = options[:key_manager]
32
30
  @options = options
33
31
  @prompt = options[:password_prompt]
34
- @pubkey_algorithms = options[:pubkey_algorithms] \
35
- || %w[rsa-sha2-256-cert-v01@openssh.com
36
- ssh-rsa-cert-v01@openssh.com
37
- rsa-sha2-256
38
- ssh-rsa]
32
+ @pubkey_algorithms = session.transport.pubkey_algorithms
39
33
  self.logger = session.logger
40
34
  end
41
35
 
@@ -15,6 +15,8 @@ module Net
15
15
  def authenticate(next_service, username, password = nil)
16
16
  return false unless key_manager
17
17
 
18
+ debug { "pubkey_algorithms: #{pubkey_algorithms.join(', ')}" }
19
+
18
20
  key_manager.each_identity do |identity|
19
21
  return true if authenticate_with(identity, next_service, username)
20
22
  end
@@ -123,7 +125,7 @@ module Net
123
125
  end
124
126
  end
125
127
  end
126
- elsif authenticate_with_alg(identity, next_service, username, type)
128
+ elsif pubkey_algorithms.include?(type) && authenticate_with_alg(identity, next_service, username, type)
127
129
  # success
128
130
  return true
129
131
  end
@@ -0,0 +1,71 @@
1
+ require 'net/ssh/errors'
2
+ require 'net/ssh/authentication/pub_key_fingerprint'
3
+
4
+ module Net
5
+ module SSH
6
+ module Authentication
7
+ # FIDO/U2F security keys held by ssh-agent. The agent does the signing (incl. user
8
+ # presence); net-ssh only parses and re-serialises the public key blob (see PROTOCOL.u2f).
9
+ module SecurityKey
10
+ SK_ECDSA_SHA2_NISTP256 = "sk-ecdsa-sha2-nistp256@openssh.com"
11
+ SK_SSH_ED25519 = "sk-ssh-ed25519@openssh.com"
12
+ TYPES = [SK_ECDSA_SHA2_NISTP256, SK_SSH_ED25519].freeze
13
+
14
+ def self.understands?(type)
15
+ TYPES.include?(type)
16
+ end
17
+
18
+ # Public key of an agent-held security key; signing is delegated to the agent.
19
+ class PubKey
20
+ include Net::SSH::Authentication::PubKeyFingerprint
21
+
22
+ attr_reader :ssh_type, :curve, :public_key_data, :application
23
+
24
+ # Wire formats:
25
+ # sk-ecdsa-sha2-nistp256@openssh.com: string curve, string Q, string application
26
+ # sk-ssh-ed25519@openssh.com: string public_key, string application
27
+ def self.read_keyblob(type, buffer)
28
+ case type
29
+ when SK_ECDSA_SHA2_NISTP256
30
+ curve = buffer.read_string
31
+ public_key_data = buffer.read_string
32
+ application = buffer.read_string
33
+ new(type, public_key_data, application, curve: curve)
34
+ when SK_SSH_ED25519
35
+ public_key_data = buffer.read_string
36
+ application = buffer.read_string
37
+ new(type, public_key_data, application)
38
+ else
39
+ raise Net::SSH::UnsupportedKeyType, "unsupported security key type `#{type}'"
40
+ end
41
+ end
42
+
43
+ def initialize(ssh_type, public_key_data, application, curve: nil)
44
+ @ssh_type = ssh_type
45
+ @public_key_data = public_key_data
46
+ @application = application
47
+ @curve = curve
48
+ end
49
+
50
+ def to_blob
51
+ buffer = Net::SSH::Buffer.new
52
+ buffer.write_string(ssh_type)
53
+ buffer.write_string(curve) if curve
54
+ buffer.write_string(public_key_data)
55
+ buffer.write_string(application)
56
+ buffer.to_s
57
+ end
58
+
59
+ def ssh_signature_type
60
+ ssh_type
61
+ end
62
+
63
+ # Only used to de-duplicate identities, so a stable key-specific string suffices.
64
+ def to_pem
65
+ "#{ssh_type} #{[to_blob].pack('m0')}"
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end