net-ssh 5.0.0.beta1 → 5.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.rubocop_todo.yml +98 -258
- data/CHANGES.txt +8 -0
- data/Gemfile +1 -3
- data/Rakefile +37 -39
- data/lib/net/ssh.rb +26 -25
- data/lib/net/ssh/authentication/agent.rb +228 -225
- data/lib/net/ssh/authentication/certificate.rb +166 -164
- data/lib/net/ssh/authentication/constants.rb +17 -14
- data/lib/net/ssh/authentication/ed25519.rb +107 -104
- data/lib/net/ssh/authentication/ed25519_loader.rb +32 -28
- data/lib/net/ssh/authentication/key_manager.rb +5 -3
- data/lib/net/ssh/authentication/methods/abstract.rb +53 -47
- data/lib/net/ssh/authentication/methods/hostbased.rb +32 -33
- data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +2 -4
- data/lib/net/ssh/authentication/methods/none.rb +10 -10
- data/lib/net/ssh/authentication/methods/password.rb +13 -13
- data/lib/net/ssh/authentication/methods/publickey.rb +54 -55
- data/lib/net/ssh/authentication/pageant.rb +468 -465
- data/lib/net/ssh/authentication/pub_key_fingerprint.rb +44 -0
- data/lib/net/ssh/authentication/session.rb +127 -123
- data/lib/net/ssh/buffer.rb +305 -303
- data/lib/net/ssh/buffered_io.rb +163 -162
- data/lib/net/ssh/config.rb +230 -227
- data/lib/net/ssh/connection/channel.rb +659 -654
- data/lib/net/ssh/connection/constants.rb +30 -26
- data/lib/net/ssh/connection/event_loop.rb +108 -104
- data/lib/net/ssh/connection/keepalive.rb +54 -50
- data/lib/net/ssh/connection/session.rb +677 -678
- data/lib/net/ssh/connection/term.rb +180 -176
- data/lib/net/ssh/errors.rb +101 -99
- data/lib/net/ssh/key_factory.rb +108 -108
- data/lib/net/ssh/known_hosts.rb +148 -154
- data/lib/net/ssh/loggable.rb +56 -54
- data/lib/net/ssh/packet.rb +82 -78
- data/lib/net/ssh/prompt.rb +55 -53
- data/lib/net/ssh/proxy/command.rb +103 -102
- data/lib/net/ssh/proxy/errors.rb +12 -8
- data/lib/net/ssh/proxy/http.rb +92 -91
- data/lib/net/ssh/proxy/https.rb +42 -39
- data/lib/net/ssh/proxy/jump.rb +50 -47
- data/lib/net/ssh/proxy/socks4.rb +0 -2
- data/lib/net/ssh/proxy/socks5.rb +11 -11
- data/lib/net/ssh/ruby_compat.rb +1 -0
- data/lib/net/ssh/service/forward.rb +364 -362
- data/lib/net/ssh/test.rb +85 -83
- data/lib/net/ssh/test/channel.rb +146 -142
- data/lib/net/ssh/test/extensions.rb +148 -146
- data/lib/net/ssh/test/kex.rb +35 -31
- data/lib/net/ssh/test/local_packet.rb +48 -44
- data/lib/net/ssh/test/packet.rb +87 -84
- data/lib/net/ssh/test/remote_packet.rb +35 -31
- data/lib/net/ssh/test/script.rb +173 -171
- data/lib/net/ssh/test/socket.rb +59 -55
- data/lib/net/ssh/transport/algorithms.rb +413 -412
- data/lib/net/ssh/transport/cipher_factory.rb +108 -105
- data/lib/net/ssh/transport/constants.rb +35 -31
- data/lib/net/ssh/transport/ctr.rb +1 -1
- data/lib/net/ssh/transport/hmac.rb +1 -1
- data/lib/net/ssh/transport/hmac/abstract.rb +67 -64
- data/lib/net/ssh/transport/hmac/sha2_256_96.rb +1 -1
- data/lib/net/ssh/transport/hmac/sha2_512_96.rb +1 -1
- data/lib/net/ssh/transport/identity_cipher.rb +55 -51
- data/lib/net/ssh/transport/kex.rb +2 -4
- data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +47 -40
- data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +201 -197
- data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -56
- data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +94 -87
- data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +17 -10
- data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +17 -10
- data/lib/net/ssh/transport/key_expander.rb +29 -25
- data/lib/net/ssh/transport/openssl.rb +17 -30
- data/lib/net/ssh/transport/packet_stream.rb +193 -192
- data/lib/net/ssh/transport/server_version.rb +64 -66
- data/lib/net/ssh/transport/session.rb +286 -284
- data/lib/net/ssh/transport/state.rb +198 -196
- data/lib/net/ssh/verifiers/lenient.rb +29 -25
- data/lib/net/ssh/verifiers/null.rb +13 -9
- data/lib/net/ssh/verifiers/secure.rb +45 -45
- data/lib/net/ssh/verifiers/strict.rb +20 -16
- data/lib/net/ssh/version.rb +55 -53
- data/net-ssh.gemspec +4 -4
- data/support/ssh_tunnel_bug.rb +2 -2
- metadata +25 -24
- metadata.gz.sig +0 -0
@@ -17,66 +17,63 @@ module Net::SSH::Transport::Kex
|
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
# Compute the number of bits needed for the given number of bytes.
|
21
|
+
def compute_need_bits
|
22
|
+
# for Compatibility: OpenSSH requires (need_bits * 2 + 1) length of parameter
|
23
|
+
need_bits = data[:need_bytes] * 8 * 2 + 1
|
22
24
|
|
23
|
-
|
24
|
-
need_bits = data[:need_bytes] * 8 * 2 + 1
|
25
|
+
data[:minimum_dh_bits] ||= MINIMUM_BITS
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
elsif need_bits > MAXIMUM_BITS
|
31
|
-
need_bits = MAXIMUM_BITS
|
32
|
-
end
|
33
|
-
|
34
|
-
data[:need_bits ] = need_bits
|
35
|
-
data[:need_bytes] = need_bits / 8
|
27
|
+
if need_bits < data[:minimum_dh_bits]
|
28
|
+
need_bits = data[:minimum_dh_bits]
|
29
|
+
elsif need_bits > MAXIMUM_BITS
|
30
|
+
need_bits = MAXIMUM_BITS
|
36
31
|
end
|
37
32
|
|
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
|
-
|
78
|
-
|
79
|
-
|
33
|
+
data[:need_bits] = need_bits
|
34
|
+
data[:need_bytes] = need_bits / 8
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns the DH key parameters for the given session.
|
38
|
+
def get_parameters
|
39
|
+
compute_need_bits
|
40
|
+
|
41
|
+
# request the DH key parameters for the given number of bits.
|
42
|
+
buffer = Net::SSH::Buffer.from(:byte, KEXDH_GEX_REQUEST, :long, data[:minimum_dh_bits],
|
43
|
+
:long, data[:need_bits], :long, MAXIMUM_BITS)
|
44
|
+
connection.send_message(buffer)
|
45
|
+
|
46
|
+
buffer = connection.next_message
|
47
|
+
raise Net::SSH::Exception, "expected KEXDH_GEX_GROUP, got #{buffer.type}" unless buffer.type == KEXDH_GEX_GROUP
|
48
|
+
|
49
|
+
p = buffer.read_bignum
|
50
|
+
g = buffer.read_bignum
|
51
|
+
|
52
|
+
[p, g]
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns the INIT/REPLY constants used by this algorithm.
|
56
|
+
def get_message_types
|
57
|
+
[KEXDH_GEX_INIT, KEXDH_GEX_REPLY]
|
58
|
+
end
|
59
|
+
|
60
|
+
# Build the signature buffer to use when verifying a signature from
|
61
|
+
# the server.
|
62
|
+
def build_signature_buffer(result)
|
63
|
+
response = Net::SSH::Buffer.new
|
64
|
+
response.write_string data[:client_version_string],
|
65
|
+
data[:server_version_string],
|
66
|
+
data[:client_algorithm_packet],
|
67
|
+
data[:server_algorithm_packet],
|
68
|
+
result[:key_blob]
|
69
|
+
response.write_long MINIMUM_BITS,
|
70
|
+
data[:need_bits],
|
71
|
+
MAXIMUM_BITS
|
72
|
+
response.write_bignum dh.p, dh.g, dh.pub_key,
|
73
|
+
result[:server_dh_pubkey],
|
74
|
+
result[:shared_secret]
|
75
|
+
response
|
76
|
+
end
|
80
77
|
end
|
81
78
|
|
82
79
|
end
|
@@ -1,93 +1,100 @@
|
|
1
1
|
require 'net/ssh/transport/constants'
|
2
2
|
require 'net/ssh/transport/kex/diffie_hellman_group1_sha1'
|
3
3
|
|
4
|
-
module Net
|
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
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
4
|
+
module Net
|
5
|
+
module SSH
|
6
|
+
module Transport
|
7
|
+
module Kex
|
8
|
+
|
9
|
+
# A key-exchange service implementing the "ecdh-sha2-nistp256"
|
10
|
+
# key-exchange algorithm. (defined in RFC 5656)
|
11
|
+
class EcdhSHA2NistP256 < DiffieHellmanGroup1SHA1
|
12
|
+
include Loggable
|
13
|
+
include Constants
|
14
|
+
|
15
|
+
attr_reader :ecdh
|
16
|
+
|
17
|
+
def digester
|
18
|
+
OpenSSL::Digest::SHA256
|
19
|
+
end
|
20
|
+
|
21
|
+
def curve_name
|
22
|
+
OpenSSL::PKey::EC::CurveNameAlias['nistp256']
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(algorithms, connection, data)
|
26
|
+
@algorithms = algorithms
|
27
|
+
@connection = connection
|
28
|
+
|
29
|
+
@digester = digester
|
30
|
+
@data = data.dup
|
31
|
+
@ecdh = generate_key
|
32
|
+
@logger = @data.delete(:logger)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def get_message_types
|
38
|
+
[KEXECDH_INIT, KEXECDH_REPLY]
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_signature_buffer(result)
|
42
|
+
response = Net::SSH::Buffer.new
|
43
|
+
response.write_string data[:client_version_string],
|
44
|
+
data[:server_version_string],
|
45
|
+
data[:client_algorithm_packet],
|
46
|
+
data[:server_algorithm_packet],
|
47
|
+
result[:key_blob],
|
48
|
+
ecdh.public_key.to_bn.to_s(2),
|
49
|
+
result[:server_ecdh_pubkey]
|
50
|
+
response.write_bignum result[:shared_secret]
|
51
|
+
response
|
52
|
+
end
|
53
|
+
|
54
|
+
def generate_key #:nodoc:
|
55
|
+
OpenSSL::PKey::EC.new(curve_name).generate_key
|
56
|
+
end
|
57
|
+
|
58
|
+
def send_kexinit #:nodoc:
|
59
|
+
init, reply = get_message_types
|
60
|
+
|
61
|
+
# send the KEXECDH_INIT message
|
62
|
+
## byte SSH_MSG_KEX_ECDH_INIT
|
63
|
+
## string Q_C, client's ephemeral public key octet string
|
64
|
+
buffer = Net::SSH::Buffer.from(:byte, init, :mstring, ecdh.public_key.to_bn.to_s(2))
|
65
|
+
connection.send_message(buffer)
|
66
|
+
|
67
|
+
# expect the following KEXECDH_REPLY message
|
68
|
+
## byte SSH_MSG_KEX_ECDH_REPLY
|
69
|
+
## string K_S, server's public host key
|
70
|
+
## string Q_S, server's ephemeral public key octet string
|
71
|
+
## string the signature on the exchange hash
|
72
|
+
buffer = connection.next_message
|
73
|
+
raise Net::SSH::Exception, "expected REPLY" unless buffer.type == reply
|
74
|
+
|
75
|
+
result = Hash.new
|
76
|
+
result[:key_blob] = buffer.read_string
|
77
|
+
result[:server_key] = Net::SSH::Buffer.new(result[:key_blob]).read_key
|
78
|
+
result[:server_ecdh_pubkey] = buffer.read_string
|
79
|
+
|
80
|
+
# compute shared secret from server's public key and client's private key
|
81
|
+
pk = OpenSSL::PKey::EC::Point.new(OpenSSL::PKey::EC.new(curve_name).group,
|
82
|
+
OpenSSL::BN.new(result[:server_ecdh_pubkey], 2))
|
83
|
+
result[:shared_secret] = OpenSSL::BN.new(ecdh.dh_compute_key(pk), 2)
|
84
|
+
|
85
|
+
sig_buffer = Net::SSH::Buffer.new(buffer.read_string)
|
86
|
+
sig_type = sig_buffer.read_string
|
87
|
+
if sig_type != algorithms.host_key
|
88
|
+
raise Net::SSH::Exception,
|
89
|
+
"host key algorithm mismatch for signature " +
|
90
|
+
"'#{sig_type}' != '#{algorithms.host_key}'"
|
91
|
+
end
|
92
|
+
result[:server_sig] = sig_buffer.read_string
|
93
|
+
|
94
|
+
return result
|
95
|
+
end
|
96
|
+
end
|
87
97
|
end
|
88
|
-
result[:server_sig] = sig_buffer.read_string
|
89
|
-
|
90
|
-
return result
|
91
98
|
end
|
92
99
|
end
|
93
|
-
end
|
100
|
+
end
|
@@ -1,13 +1,20 @@
|
|
1
|
-
module Net
|
1
|
+
module Net
|
2
|
+
module SSH
|
3
|
+
module Transport
|
4
|
+
module Kex
|
2
5
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
# A key-exchange service implementing the "ecdh-sha2-nistp256"
|
7
|
+
# key-exchange algorithm. (defined in RFC 5656)
|
8
|
+
class EcdhSHA2NistP384 < EcdhSHA2NistP256
|
9
|
+
def digester
|
10
|
+
OpenSSL::Digest::SHA384
|
11
|
+
end
|
12
|
+
|
13
|
+
def curve_name
|
14
|
+
OpenSSL::PKey::EC::CurveNameAlias['nistp384']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
11
18
|
end
|
12
19
|
end
|
13
|
-
end
|
20
|
+
end
|
@@ -1,13 +1,20 @@
|
|
1
|
-
module Net
|
1
|
+
module Net
|
2
|
+
module SSH
|
3
|
+
module Transport
|
4
|
+
module Kex
|
2
5
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
# A key-exchange service implementing the "ecdh-sha2-nistp521"
|
7
|
+
# key-exchange algorithm. (defined in RFC 5656)
|
8
|
+
class EcdhSHA2NistP521 < EcdhSHA2NistP256
|
9
|
+
def digester
|
10
|
+
OpenSSL::Digest::SHA512
|
11
|
+
end
|
12
|
+
|
13
|
+
def curve_name
|
14
|
+
OpenSSL::PKey::EC::CurveNameAlias['nistp521']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
11
18
|
end
|
12
19
|
end
|
13
|
-
end
|
20
|
+
end
|
@@ -1,27 +1,31 @@
|
|
1
|
-
module Net
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module Net
|
2
|
+
module SSH
|
3
|
+
module Transport
|
4
|
+
module KeyExpander
|
5
|
+
|
6
|
+
# Generate a key value in accordance with the SSH2 specification.
|
7
|
+
# (RFC4253 7.2. "Output from Key Exchange")
|
8
|
+
def self.expand_key(bytes, start, options={})
|
9
|
+
if bytes == 0
|
10
|
+
return ""
|
11
|
+
end
|
12
|
+
|
13
|
+
k = start[0, bytes]
|
14
|
+
return k if k.length >= bytes
|
15
|
+
|
16
|
+
digester = options[:digester] or raise 'No digester supplied'
|
17
|
+
shared = options[:shared] or raise 'No shared secret supplied'
|
18
|
+
hash = options[:hash] or raise 'No hash supplied'
|
19
|
+
|
20
|
+
while k.length < bytes
|
21
|
+
step = digester.digest(shared + hash + k)
|
22
|
+
bytes_needed = bytes - k.length
|
23
|
+
k << step[0, bytes_needed]
|
24
|
+
end
|
25
|
+
|
26
|
+
return k
|
27
|
+
end
|
28
|
+
end
|
9
29
|
end
|
10
|
-
|
11
|
-
k = start[0, bytes]
|
12
|
-
return k if k.length >= bytes
|
13
|
-
|
14
|
-
digester = options[:digester] or raise 'No digester supplied'
|
15
|
-
shared = options[:shared] or raise 'No shared secret supplied'
|
16
|
-
hash = options[:hash] or raise 'No hash supplied'
|
17
|
-
|
18
|
-
while k.length < bytes
|
19
|
-
step = digester.digest(shared + hash + k)
|
20
|
-
bytes_needed = bytes - k.length
|
21
|
-
k << step[0, bytes_needed]
|
22
|
-
end
|
23
|
-
|
24
|
-
return k
|
25
|
-
end
|
26
30
|
end
|
27
|
-
end
|
31
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
require 'openssl'
|
2
|
+
require 'net/ssh/authentication/pub_key_fingerprint'
|
3
3
|
|
4
4
|
module OpenSSL
|
5
5
|
|
@@ -7,7 +7,6 @@ module OpenSSL
|
|
7
7
|
# have been added to it by the Net::SSH module for convenience in dealing with
|
8
8
|
# SSH functionality.
|
9
9
|
class BN
|
10
|
-
|
11
10
|
# Converts a BN object to a string. The format used is that which is
|
12
11
|
# required by the SSH2 protocol.
|
13
12
|
def to_ssh
|
@@ -16,44 +15,38 @@ module OpenSSL
|
|
16
15
|
else
|
17
16
|
buf = to_s(2)
|
18
17
|
if buf.getbyte(0)[7] == 1
|
19
|
-
return [buf.length+1, 0, buf].pack("NCA*")
|
18
|
+
return [buf.length + 1, 0, buf].pack("NCA*")
|
20
19
|
else
|
21
20
|
return [buf.length, buf].pack("NA*")
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
25
|
-
|
26
24
|
end
|
27
25
|
|
28
26
|
module PKey
|
29
27
|
|
30
28
|
class PKey
|
31
|
-
|
32
|
-
@fingerprint ||= OpenSSL::Digest::MD5.hexdigest(to_blob).scan(/../).join(":")
|
33
|
-
end
|
29
|
+
include Net::SSH::Authentication::PubKeyFingerprint
|
34
30
|
end
|
35
31
|
|
36
32
|
# This class is originally defined in the OpenSSL module. As needed, methods
|
37
33
|
# have been added to it by the Net::SSH module for convenience in dealing
|
38
34
|
# with SSH functionality.
|
39
35
|
class DH
|
40
|
-
|
41
36
|
# Determines whether the pub_key for this key is valid. (This algorithm
|
42
37
|
# lifted more-or-less directly from OpenSSH, dh.c, dh_pub_is_valid.)
|
43
38
|
def valid?
|
44
39
|
return false if pub_key.nil? || pub_key < 0
|
45
40
|
bits_set = 0
|
46
41
|
pub_key.num_bits.times { |i| bits_set += 1 if pub_key.bit_set?(i) }
|
47
|
-
return (
|
42
|
+
return (bits_set > 1 && pub_key < p)
|
48
43
|
end
|
49
|
-
|
50
44
|
end
|
51
45
|
|
52
46
|
# This class is originally defined in the OpenSSL module. As needed, methods
|
53
47
|
# have been added to it by the Net::SSH module for convenience in dealing
|
54
48
|
# with SSH functionality.
|
55
49
|
class RSA
|
56
|
-
|
57
50
|
# Returns "ssh-rsa", which is the description of this key type used by the
|
58
51
|
# SSH2 protocol.
|
59
52
|
def ssh_type
|
@@ -84,7 +77,6 @@ module OpenSSL
|
|
84
77
|
# have been added to it by the Net::SSH module for convenience in dealing
|
85
78
|
# with SSH functionality.
|
86
79
|
class DSA
|
87
|
-
|
88
80
|
# Returns "ssh-dss", which is the description of this key type used by the
|
89
81
|
# SSH2 protocol.
|
90
82
|
def ssh_type
|
@@ -114,18 +106,16 @@ module OpenSSL
|
|
114
106
|
|
115
107
|
# Signs the given data.
|
116
108
|
def ssh_do_sign(data)
|
117
|
-
sig = sign(
|
118
|
-
a1sig = OpenSSL::ASN1.decode(
|
109
|
+
sig = sign(OpenSSL::Digest::SHA1.new, data)
|
110
|
+
a1sig = OpenSSL::ASN1.decode(sig)
|
119
111
|
|
120
112
|
sig_r = a1sig.value[0].value.to_s(2)
|
121
113
|
sig_s = a1sig.value[1].value.to_s(2)
|
122
114
|
|
123
|
-
if sig_r.length > 20 || sig_s.length > 20
|
124
|
-
raise OpenSSL::PKey::DSAError, "bad sig size"
|
125
|
-
end
|
115
|
+
raise OpenSSL::PKey::DSAError, "bad sig size" if sig_r.length > 20 || sig_s.length > 20
|
126
116
|
|
127
|
-
sig_r = "\0" * (
|
128
|
-
sig_s = "\0" * (
|
117
|
+
sig_r = "\0" * (20 - sig_r.length) + sig_r if sig_r.length < 20
|
118
|
+
sig_s = "\0" * (20 - sig_s.length) + sig_s if sig_s.length < 20
|
129
119
|
|
130
120
|
return sig_r + sig_s
|
131
121
|
end
|
@@ -139,20 +129,18 @@ module OpenSSL
|
|
139
129
|
CurveNameAlias = {
|
140
130
|
"nistp256" => "prime256v1",
|
141
131
|
"nistp384" => "secp384r1",
|
142
|
-
"nistp521" => "secp521r1"
|
132
|
+
"nistp521" => "secp521r1"
|
143
133
|
}
|
144
134
|
|
145
135
|
CurveNameAliasInv = {
|
146
136
|
"prime256v1" => "nistp256",
|
147
137
|
"secp384r1" => "nistp384",
|
148
|
-
"secp521r1" => "nistp521"
|
138
|
+
"secp521r1" => "nistp521"
|
149
139
|
}
|
150
140
|
|
151
141
|
def self.read_keyblob(curve_name_in_type, buffer)
|
152
142
|
curve_name_in_key = buffer.read_string
|
153
|
-
unless curve_name_in_type == curve_name_in_key
|
154
|
-
raise Net::SSH::Exception, "curve name mismatched (`#{curve_name_in_key}' with `#{curve_name_in_type}')"
|
155
|
-
end
|
143
|
+
raise Net::SSH::Exception, "curve name mismatched (`#{curve_name_in_key}' with `#{curve_name_in_type}')" unless curve_name_in_type == curve_name_in_key
|
156
144
|
public_key_oct = buffer.read_string
|
157
145
|
begin
|
158
146
|
key = OpenSSL::PKey::EC.new(OpenSSL::PKey::EC::CurveNameAlias[curve_name_in_key])
|
@@ -164,7 +152,6 @@ module OpenSSL
|
|
164
152
|
rescue OpenSSL::PKey::ECError
|
165
153
|
raise NotImplementedError, "unsupported key type `#{type}'"
|
166
154
|
end
|
167
|
-
|
168
155
|
end
|
169
156
|
|
170
157
|
# Returns the description of this key type used by the
|
@@ -208,16 +195,16 @@ module OpenSSL
|
|
208
195
|
|
209
196
|
begin
|
210
197
|
sig_r_len = sig[0,4].unpack("H*")[0].to_i(16)
|
211
|
-
sig_l_len = sig[4+sig_r_len,4].unpack("H*")[0].to_i(16)
|
198
|
+
sig_l_len = sig[4 + sig_r_len,4].unpack("H*")[0].to_i(16)
|
212
199
|
|
213
200
|
sig_r = sig[4,sig_r_len].unpack("H*")[0]
|
214
|
-
sig_s = sig[4+sig_r_len+4,sig_l_len].unpack("H*")[0]
|
201
|
+
sig_s = sig[4 + sig_r_len + 4,sig_l_len].unpack("H*")[0]
|
215
202
|
|
216
203
|
a1sig = OpenSSL::ASN1::Sequence([
|
217
204
|
OpenSSL::ASN1::Integer(sig_r.to_i(16)),
|
218
|
-
OpenSSL::ASN1::Integer(sig_s.to_i(16))
|
205
|
+
OpenSSL::ASN1::Integer(sig_s.to_i(16))
|
219
206
|
])
|
220
|
-
rescue
|
207
|
+
rescue StandardError
|
221
208
|
end
|
222
209
|
|
223
210
|
if a1sig == nil
|
@@ -231,7 +218,7 @@ module OpenSSL
|
|
231
218
|
def ssh_do_sign(data)
|
232
219
|
digest = digester.digest(data)
|
233
220
|
sig = dsa_sign_asn1(digest)
|
234
|
-
a1sig = OpenSSL::ASN1.decode(
|
221
|
+
a1sig = OpenSSL::ASN1.decode(sig)
|
235
222
|
|
236
223
|
sig_r = a1sig.value[0].value
|
237
224
|
sig_s = a1sig.value[1].value
|