net-ssh 3.2.0 → 7.2.0.rc1
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 +0 -0
- data/.dockerignore +6 -0
- data/.github/FUNDING.yml +1 -0
- data/.github/config/rubocop_linter_action.yml +4 -0
- data/.github/workflows/ci-with-docker.yml +44 -0
- data/.github/workflows/ci.yml +93 -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 +237 -7
- data/DEVELOPMENT.md +23 -0
- data/Dockerfile +27 -0
- data/Dockerfile.openssl3 +17 -0
- data/Gemfile +13 -0
- data/Gemfile.noed25519 +12 -0
- data/Gemfile.norbnacl +12 -0
- data/ISSUE_TEMPLATE.md +30 -0
- data/Manifest +4 -5
- data/README.md +298 -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 +462 -359
- data/lib/net/ssh/transport/chacha20_poly1305_cipher.rb +117 -0
- data/lib/net/ssh/transport/chacha20_poly1305_cipher_loader.rb +17 -0
- data/lib/net/ssh/transport/cipher_factory.rb +122 -99
- 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 -44
- 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/openssl_cipher_extensions.rb +8 -0
- data/lib/net/ssh/transport/packet_stream.rb +246 -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 +111 -47
- data/net-ssh-public_cert.pem +18 -18
- data/net-ssh.gemspec +38 -205
- data/support/ssh_tunnel_bug.rb +5 -5
- data.tar.gz.sig +0 -0
- metadata +173 -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
@@ -3,78 +3,70 @@ require 'net/ssh/transport/constants'
|
|
3
3
|
require 'net/ssh/transport/kex/diffie_hellman_group1_sha1'
|
4
4
|
|
5
5
|
module Net::SSH::Transport::Kex
|
6
|
-
|
7
6
|
# A key-exchange service implementing the
|
8
7
|
# "diffie-hellman-group-exchange-sha1" key-exchange algorithm.
|
9
8
|
class DiffieHellmanGroupExchangeSHA1 < DiffieHellmanGroup1SHA1
|
10
9
|
MINIMUM_BITS = 1024
|
11
10
|
MAXIMUM_BITS = 8192
|
12
11
|
|
13
|
-
KEXDH_GEX_GROUP = 31
|
14
|
-
KEXDH_GEX_INIT = 32
|
15
|
-
KEXDH_GEX_REPLY = 33
|
16
|
-
KEXDH_GEX_REQUEST = 34
|
17
|
-
|
18
12
|
private
|
19
13
|
|
20
|
-
|
21
|
-
|
14
|
+
# Compute the number of bits needed for the given number of bytes.
|
15
|
+
def compute_need_bits
|
16
|
+
# for Compatibility: OpenSSH requires (need_bits * 2 + 1) length of parameter
|
17
|
+
need_bits = data[:need_bytes] * 8 * 2 + 1
|
22
18
|
|
23
|
-
|
24
|
-
need_bits = data[:need_bytes] * 8 * 2 + 1
|
19
|
+
data[:minimum_dh_bits] ||= MINIMUM_BITS
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
data[:need_bits ] = need_bits
|
33
|
-
data[:need_bytes] = need_bits / 8
|
21
|
+
if need_bits < data[:minimum_dh_bits]
|
22
|
+
need_bits = data[:minimum_dh_bits]
|
23
|
+
elsif need_bits > MAXIMUM_BITS
|
24
|
+
need_bits = MAXIMUM_BITS
|
34
25
|
end
|
35
26
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
27
|
+
data[:need_bits] = need_bits
|
28
|
+
data[:need_bytes] = need_bits / 8
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the DH key parameters for the given session.
|
32
|
+
def get_parameters
|
33
|
+
compute_need_bits
|
34
|
+
|
35
|
+
# request the DH key parameters for the given number of bits.
|
36
|
+
buffer = Net::SSH::Buffer.from(:byte, KEXDH_GEX_REQUEST, :long, data[:minimum_dh_bits],
|
37
|
+
:long, data[:need_bits], :long, MAXIMUM_BITS)
|
38
|
+
connection.send_message(buffer)
|
39
|
+
|
40
|
+
buffer = connection.next_message
|
41
|
+
raise Net::SSH::Exception, "expected KEXDH_GEX_GROUP, got #{buffer.type}" unless buffer.type == KEXDH_GEX_GROUP
|
42
|
+
|
43
|
+
p = buffer.read_bignum
|
44
|
+
g = buffer.read_bignum
|
45
|
+
|
46
|
+
[p, g]
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns the INIT/REPLY constants used by this algorithm.
|
50
|
+
def get_message_types
|
51
|
+
[KEXDH_GEX_INIT, KEXDH_GEX_REPLY]
|
52
|
+
end
|
53
|
+
|
54
|
+
# Build the signature buffer to use when verifying a signature from
|
55
|
+
# the server.
|
56
|
+
def build_signature_buffer(result)
|
57
|
+
response = Net::SSH::Buffer.new
|
58
|
+
response.write_string data[:client_version_string],
|
59
|
+
data[:server_version_string],
|
60
|
+
data[:client_algorithm_packet],
|
61
|
+
data[:server_algorithm_packet],
|
62
|
+
result[:key_blob]
|
63
|
+
response.write_long MINIMUM_BITS,
|
64
|
+
data[:need_bits],
|
65
|
+
MAXIMUM_BITS
|
66
|
+
response.write_bignum dh.p, dh.g, dh.pub_key,
|
67
|
+
result[:server_dh_pubkey],
|
68
|
+
result[:shared_secret]
|
69
|
+
response
|
70
|
+
end
|
78
71
|
end
|
79
|
-
|
80
72
|
end
|
@@ -1,15 +1,11 @@
|
|
1
1
|
require 'net/ssh/transport/kex/diffie_hellman_group_exchange_sha1'
|
2
2
|
|
3
3
|
module Net::SSH::Transport::Kex
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
super(*args)
|
10
|
-
|
11
|
-
@digester = OpenSSL::Digest::SHA256
|
12
|
-
end
|
4
|
+
# A key-exchange service implementing the
|
5
|
+
# "diffie-hellman-group-exchange-sha256" key-exchange algorithm.
|
6
|
+
class DiffieHellmanGroupExchangeSHA256 < DiffieHellmanGroupExchangeSHA1
|
7
|
+
def digester
|
8
|
+
OpenSSL::Digest::SHA256
|
13
9
|
end
|
14
10
|
end
|
15
11
|
end
|
@@ -1,93 +1,39 @@
|
|
1
|
-
require 'net/ssh/transport/
|
2
|
-
|
3
|
-
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def build_signature_buffer(result)
|
38
|
-
response = Net::SSH::Buffer.new
|
39
|
-
response.write_string data[:client_version_string],
|
40
|
-
data[:server_version_string],
|
41
|
-
data[:client_algorithm_packet],
|
42
|
-
data[:server_algorithm_packet],
|
43
|
-
result[:key_blob],
|
44
|
-
ecdh.public_key.to_bn.to_s(2),
|
45
|
-
result[:server_ecdh_pubkey]
|
46
|
-
response.write_bignum result[:shared_secret]
|
47
|
-
response
|
48
|
-
end
|
49
|
-
|
50
|
-
def generate_key #:nodoc:
|
51
|
-
OpenSSL::PKey::EC.new(curve_name).generate_key
|
52
|
-
end
|
53
|
-
|
54
|
-
def send_kexinit #:nodoc:
|
55
|
-
init, reply = get_message_types
|
56
|
-
|
57
|
-
# send the KEXECDH_INIT message
|
58
|
-
## byte SSH_MSG_KEX_ECDH_INIT
|
59
|
-
## string Q_C, client's ephemeral public key octet string
|
60
|
-
buffer = Net::SSH::Buffer.from(:byte, init, :string, ecdh.public_key.to_bn.to_s(2))
|
61
|
-
connection.send_message(buffer)
|
62
|
-
|
63
|
-
# expect the following KEXECDH_REPLY message
|
64
|
-
## byte SSH_MSG_KEX_ECDH_REPLY
|
65
|
-
## string K_S, server's public host key
|
66
|
-
## string Q_S, server's ephemeral public key octet string
|
67
|
-
## string the signature on the exchange hash
|
68
|
-
buffer = connection.next_message
|
69
|
-
raise Net::SSH::Exception, "expected REPLY" unless buffer.type == reply
|
70
|
-
|
71
|
-
result = Hash.new
|
72
|
-
result[:key_blob] = buffer.read_string
|
73
|
-
result[:server_key] = Net::SSH::Buffer.new(result[:key_blob]).read_key
|
74
|
-
result[:server_ecdh_pubkey] = buffer.read_string
|
75
|
-
|
76
|
-
# compute shared secret from server's public key and client's private key
|
77
|
-
pk = OpenSSL::PKey::EC::Point.new(OpenSSL::PKey::EC.new(curve_name).group,
|
78
|
-
OpenSSL::BN.new(result[:server_ecdh_pubkey], 2))
|
79
|
-
result[:shared_secret] = OpenSSL::BN.new(ecdh.dh_compute_key(pk), 2)
|
80
|
-
|
81
|
-
sig_buffer = Net::SSH::Buffer.new(buffer.read_string)
|
82
|
-
sig_type = sig_buffer.read_string
|
83
|
-
if sig_type != algorithms.host_key
|
84
|
-
raise Net::SSH::Exception,
|
85
|
-
"host key algorithm mismatch for signature " +
|
86
|
-
"'#{sig_type}' != '#{algorithms.host_key}'"
|
1
|
+
require 'net/ssh/transport/kex/abstract5656'
|
2
|
+
|
3
|
+
module Net
|
4
|
+
module SSH
|
5
|
+
module Transport
|
6
|
+
module Kex
|
7
|
+
# A key-exchange service implementing the "ecdh-sha2-nistp256"
|
8
|
+
# key-exchange algorithm. (defined in RFC 5656)
|
9
|
+
class EcdhSHA2NistP256 < Abstract5656
|
10
|
+
def digester
|
11
|
+
OpenSSL::Digest::SHA256
|
12
|
+
end
|
13
|
+
|
14
|
+
def curve_name
|
15
|
+
OpenSSL::PKey::EC::CurveNameAlias['nistp256']
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def generate_key # :nodoc:
|
21
|
+
OpenSSL::PKey::EC.generate(curve_name)
|
22
|
+
end
|
23
|
+
|
24
|
+
# compute shared secret from server's public key and client's private key
|
25
|
+
def compute_shared_secret(server_ecdh_pubkey)
|
26
|
+
pk = OpenSSL::PKey::EC::Point.new(OpenSSL::PKey::EC.new(curve_name).group,
|
27
|
+
OpenSSL::BN.new(server_ecdh_pubkey, 2))
|
28
|
+
OpenSSL::BN.new(ecdh.dh_compute_key(pk), 2)
|
29
|
+
end
|
30
|
+
|
31
|
+
## string Q_C, client's ephemeral public key octet string
|
32
|
+
def ecdh_public_key_bytes
|
33
|
+
ecdh.public_key.to_bn.to_s(2)
|
34
|
+
end
|
35
|
+
end
|
87
36
|
end
|
88
|
-
result[:server_sig] = sig_buffer.read_string
|
89
|
-
|
90
|
-
return result
|
91
37
|
end
|
92
38
|
end
|
93
|
-
end
|
39
|
+
end
|
@@ -1,13 +1,21 @@
|
|
1
|
-
|
1
|
+
require 'net/ssh/transport/kex/ecdh_sha2_nistp256'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module Net
|
4
|
+
module SSH
|
5
|
+
module Transport
|
6
|
+
module Kex
|
7
|
+
# A key-exchange service implementing the "ecdh-sha2-nistp256"
|
8
|
+
# key-exchange algorithm. (defined in RFC 5656)
|
9
|
+
class EcdhSHA2NistP384 < EcdhSHA2NistP256
|
10
|
+
def digester
|
11
|
+
OpenSSL::Digest::SHA384
|
12
|
+
end
|
13
|
+
|
14
|
+
def curve_name
|
15
|
+
OpenSSL::PKey::EC::CurveNameAlias['nistp384']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
11
19
|
end
|
12
20
|
end
|
13
|
-
end
|
21
|
+
end
|
@@ -1,13 +1,21 @@
|
|
1
|
-
|
1
|
+
require 'net/ssh/transport/kex/ecdh_sha2_nistp256'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module Net
|
4
|
+
module SSH
|
5
|
+
module Transport
|
6
|
+
module Kex
|
7
|
+
# A key-exchange service implementing the "ecdh-sha2-nistp521"
|
8
|
+
# key-exchange algorithm. (defined in RFC 5656)
|
9
|
+
class EcdhSHA2NistP521 < EcdhSHA2NistP256
|
10
|
+
def digester
|
11
|
+
OpenSSL::Digest::SHA512
|
12
|
+
end
|
13
|
+
|
14
|
+
def curve_name
|
15
|
+
OpenSSL::PKey::EC::CurveNameAlias['nistp521']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
11
19
|
end
|
12
20
|
end
|
13
|
-
end
|
21
|
+
end
|
@@ -1,28 +1,31 @@
|
|
1
1
|
require 'net/ssh/transport/kex/diffie_hellman_group1_sha1'
|
2
2
|
require 'net/ssh/transport/kex/diffie_hellman_group14_sha1'
|
3
|
+
require 'net/ssh/transport/kex/diffie_hellman_group14_sha256'
|
3
4
|
require 'net/ssh/transport/kex/diffie_hellman_group_exchange_sha1'
|
4
5
|
require 'net/ssh/transport/kex/diffie_hellman_group_exchange_sha256'
|
6
|
+
require 'net/ssh/transport/kex/ecdh_sha2_nistp256'
|
7
|
+
require 'net/ssh/transport/kex/ecdh_sha2_nistp384'
|
8
|
+
require 'net/ssh/transport/kex/ecdh_sha2_nistp521'
|
9
|
+
require 'net/ssh/transport/kex/curve25519_sha256_loader'
|
5
10
|
|
6
11
|
module Net::SSH::Transport
|
7
12
|
module Kex
|
8
13
|
# Maps the supported key-exchange algorithms as named by the SSH protocol
|
9
14
|
# to their corresponding implementors.
|
10
15
|
MAP = {
|
16
|
+
'diffie-hellman-group1-sha1' => DiffieHellmanGroup1SHA1,
|
17
|
+
'diffie-hellman-group14-sha1' => DiffieHellmanGroup14SHA1,
|
18
|
+
'diffie-hellman-group14-sha256' => DiffieHellmanGroup14SHA256,
|
11
19
|
'diffie-hellman-group-exchange-sha1' => DiffieHellmanGroupExchangeSHA1,
|
12
|
-
'diffie-hellman-
|
13
|
-
'
|
20
|
+
'diffie-hellman-group-exchange-sha256' => DiffieHellmanGroupExchangeSHA256,
|
21
|
+
'ecdh-sha2-nistp256' => EcdhSHA2NistP256,
|
22
|
+
'ecdh-sha2-nistp384' => EcdhSHA2NistP384,
|
23
|
+
'ecdh-sha2-nistp521' => EcdhSHA2NistP521
|
14
24
|
}
|
15
|
-
if defined?(DiffieHellmanGroupExchangeSHA256)
|
16
|
-
MAP['diffie-hellman-group-exchange-sha256'] = DiffieHellmanGroupExchangeSHA256
|
17
|
-
end
|
18
|
-
if defined?(OpenSSL::PKey::EC)
|
19
|
-
require 'net/ssh/transport/kex/ecdh_sha2_nistp256'
|
20
|
-
require 'net/ssh/transport/kex/ecdh_sha2_nistp384'
|
21
|
-
require 'net/ssh/transport/kex/ecdh_sha2_nistp521'
|
22
25
|
|
23
|
-
|
24
|
-
MAP['
|
25
|
-
MAP['
|
26
|
+
if Net::SSH::Transport::Kex::Curve25519Sha256Loader::LOADED
|
27
|
+
MAP['curve25519-sha256'] = Curve25519Sha256
|
28
|
+
MAP['curve25519-sha256@libssh.org'] = Curve25519Sha256
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
@@ -1,26 +1,30 @@
|
|
1
|
-
module Net
|
2
|
-
module
|
1
|
+
module Net
|
2
|
+
module SSH
|
3
|
+
module Transport
|
4
|
+
module KeyExpander
|
5
|
+
# Generate a key value in accordance with the SSH2 specification.
|
6
|
+
# (RFC4253 7.2. "Output from Key Exchange")
|
7
|
+
def self.expand_key(bytes, start, options = {})
|
8
|
+
if bytes == 0
|
9
|
+
return ""
|
10
|
+
end
|
3
11
|
|
4
|
-
|
5
|
-
|
6
|
-
def self.expand_key(bytes, start, options={})
|
7
|
-
if bytes == 0
|
8
|
-
return ""
|
9
|
-
end
|
12
|
+
k = start[0, bytes]
|
13
|
+
return k if k.length >= bytes
|
10
14
|
|
11
|
-
|
15
|
+
digester = options[:digester] or raise 'No digester supplied'
|
16
|
+
shared = options[:shared] or raise 'No shared secret supplied'
|
17
|
+
hash = options[:hash] or raise 'No hash supplied'
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
|
19
|
+
while k.length < bytes
|
20
|
+
step = digester.digest(shared + hash + k)
|
21
|
+
bytes_needed = bytes - k.length
|
22
|
+
k << step[0, bytes_needed]
|
23
|
+
end
|
16
24
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
k << step[0, bytes_needed]
|
25
|
+
return k
|
26
|
+
end
|
27
|
+
end
|
21
28
|
end
|
22
|
-
|
23
|
-
return k
|
24
|
-
end
|
25
29
|
end
|
26
|
-
end
|
30
|
+
end
|