net-ssh 4.2.0 → 7.0.1
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/config/rubocop_linter_action.yml +4 -0
- data/.github/workflows/ci-with-docker.yml +44 -0
- data/.github/workflows/ci.yml +87 -0
- data/.github/workflows/rubocop.yml +13 -0
- data/.gitignore +7 -0
- data/.rubocop.yml +19 -2
- data/.rubocop_todo.yml +619 -667
- data/CHANGES.txt +110 -1
- data/Dockerfile +27 -0
- data/Dockerfile.openssl3 +17 -0
- data/Gemfile +3 -7
- data/{Gemfile.norbnacl → Gemfile.noed25519} +3 -1
- data/Manifest +4 -5
- data/README.md +293 -0
- data/Rakefile +45 -29
- data/appveyor.yml +8 -6
- data/docker-compose.yml +23 -0
- data/lib/net/ssh/authentication/agent.rb +248 -223
- data/lib/net/ssh/authentication/certificate.rb +178 -164
- data/lib/net/ssh/authentication/constants.rb +17 -15
- data/lib/net/ssh/authentication/ed25519.rb +141 -116
- data/lib/net/ssh/authentication/ed25519_loader.rb +28 -28
- data/lib/net/ssh/authentication/key_manager.rb +79 -36
- data/lib/net/ssh/authentication/methods/abstract.rb +62 -47
- data/lib/net/ssh/authentication/methods/hostbased.rb +34 -37
- data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +3 -3
- data/lib/net/ssh/authentication/methods/none.rb +16 -19
- data/lib/net/ssh/authentication/methods/password.rb +15 -16
- data/lib/net/ssh/authentication/methods/publickey.rb +96 -55
- data/lib/net/ssh/authentication/pageant.rb +468 -465
- data/lib/net/ssh/authentication/pub_key_fingerprint.rb +43 -0
- data/lib/net/ssh/authentication/session.rb +131 -122
- data/lib/net/ssh/buffer.rb +385 -332
- data/lib/net/ssh/buffered_io.rb +150 -151
- data/lib/net/ssh/config.rb +316 -239
- 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 +104 -95
- data/lib/net/ssh/connection/keepalive.rb +55 -51
- data/lib/net/ssh/connection/session.rb +614 -611
- data/lib/net/ssh/connection/term.rb +125 -123
- data/lib/net/ssh/errors.rb +101 -99
- data/lib/net/ssh/key_factory.rb +194 -108
- data/lib/net/ssh/known_hosts.rb +212 -134
- data/lib/net/ssh/loggable.rb +50 -49
- data/lib/net/ssh/packet.rb +83 -79
- data/lib/net/ssh/prompt.rb +51 -51
- data/lib/net/ssh/proxy/command.rb +105 -91
- data/lib/net/ssh/proxy/errors.rb +12 -10
- data/lib/net/ssh/proxy/http.rb +81 -81
- data/lib/net/ssh/proxy/https.rb +37 -36
- data/lib/net/ssh/proxy/jump.rb +49 -48
- 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 +365 -362
- data/lib/net/ssh/test/channel.rb +145 -143
- data/lib/net/ssh/test/extensions.rb +131 -127
- 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 +87 -84
- data/lib/net/ssh/test/remote_packet.rb +32 -30
- data/lib/net/ssh/test/script.rb +155 -155
- data/lib/net/ssh/test/socket.rb +49 -48
- data/lib/net/ssh/test.rb +82 -80
- data/lib/net/ssh/transport/algorithms.rb +433 -364
- data/lib/net/ssh/transport/cipher_factory.rb +95 -91
- data/lib/net/ssh/transport/constants.rb +32 -24
- data/lib/net/ssh/transport/ctr.rb +37 -15
- data/lib/net/ssh/transport/hmac/abstract.rb +81 -63
- data/lib/net/ssh/transport/hmac/md5.rb +0 -2
- data/lib/net/ssh/transport/hmac/md5_96.rb +0 -2
- data/lib/net/ssh/transport/hmac/none.rb +0 -2
- data/lib/net/ssh/transport/hmac/ripemd160.rb +0 -2
- data/lib/net/ssh/transport/hmac/sha1.rb +0 -2
- data/lib/net/ssh/transport/hmac/sha1_96.rb +0 -2
- data/lib/net/ssh/transport/hmac/sha2_256.rb +7 -11
- data/lib/net/ssh/transport/hmac/sha2_256_96.rb +4 -8
- data/lib/net/ssh/transport/hmac/sha2_256_etm.rb +12 -0
- data/lib/net/ssh/transport/hmac/sha2_512.rb +6 -9
- data/lib/net/ssh/transport/hmac/sha2_512_96.rb +4 -8
- data/lib/net/ssh/transport/hmac/sha2_512_etm.rb +12 -0
- data/lib/net/ssh/transport/hmac.rb +14 -12
- data/lib/net/ssh/transport/identity_cipher.rb +54 -52
- data/lib/net/ssh/transport/kex/abstract.rb +130 -0
- data/lib/net/ssh/transport/kex/abstract5656.rb +72 -0
- data/lib/net/ssh/transport/kex/curve25519_sha256.rb +39 -0
- data/lib/net/ssh/transport/kex/curve25519_sha256_loader.rb +30 -0
- data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +33 -40
- data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha256.rb +11 -0
- data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +112 -217
- data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -63
- 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 -21
- data/lib/net/ssh/transport/openssl.rb +158 -133
- data/lib/net/ssh/transport/packet_stream.rb +223 -191
- data/lib/net/ssh/transport/server_version.rb +55 -56
- data/lib/net/ssh/transport/session.rb +306 -259
- 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 +47 -34
- data/net-ssh-public_cert.pem +18 -19
- data/net-ssh.gemspec +12 -11
- data/support/ssh_tunnel_bug.rb +5 -5
- data.tar.gz.sig +0 -0
- metadata +78 -73
- metadata.gz.sig +0 -0
- data/.travis.yml +0 -51
- data/Gemfile.norbnacl.lock +0 -41
- data/README.rdoc +0 -169
- data/lib/net/ssh/ruby_compat.rb +0 -24
- 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/support/arcfour_check.rb +0 -20
@@ -3,97 +3,101 @@ require 'net/ssh/transport/ctr.rb'
|
|
3
3
|
require 'net/ssh/transport/key_expander'
|
4
4
|
require 'net/ssh/transport/identity_cipher'
|
5
5
|
|
6
|
-
module Net
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
6
|
+
module Net
|
7
|
+
module SSH
|
8
|
+
module Transport
|
9
|
+
# Implements a factory of OpenSSL cipher algorithms.
|
10
|
+
class CipherFactory
|
11
|
+
# Maps the SSH name of a cipher to it's corresponding OpenSSL name
|
12
|
+
SSH_TO_OSSL = {
|
13
|
+
"3des-cbc" => "des-ede3-cbc",
|
14
|
+
"blowfish-cbc" => "bf-cbc",
|
15
|
+
"aes256-cbc" => "aes-256-cbc",
|
16
|
+
"aes192-cbc" => "aes-192-cbc",
|
17
|
+
"aes128-cbc" => "aes-128-cbc",
|
18
|
+
"idea-cbc" => "idea-cbc",
|
19
|
+
"cast128-cbc" => "cast-cbc",
|
20
|
+
"rijndael-cbc@lysator.liu.se" => "aes-256-cbc",
|
21
|
+
"3des-ctr" => "des-ede3",
|
22
|
+
"blowfish-ctr" => "bf-ecb",
|
23
|
+
|
24
|
+
"aes256-ctr" => ::OpenSSL::Cipher.ciphers.include?("aes-256-ctr") ? "aes-256-ctr" : "aes-256-ecb",
|
25
|
+
"aes192-ctr" => ::OpenSSL::Cipher.ciphers.include?("aes-192-ctr") ? "aes-192-ctr" : "aes-192-ecb",
|
26
|
+
"aes128-ctr" => ::OpenSSL::Cipher.ciphers.include?("aes-128-ctr") ? "aes-128-ctr" : "aes-128-ecb",
|
27
|
+
'cast128-ctr' => 'cast5-ecb',
|
28
|
+
|
29
|
+
'none' => 'none'
|
30
|
+
}
|
31
|
+
|
32
|
+
# Returns true if the underlying OpenSSL library supports the given cipher,
|
33
|
+
# and false otherwise.
|
34
|
+
def self.supported?(name)
|
35
|
+
ossl_name = SSH_TO_OSSL[name] or raise NotImplementedError, "unimplemented cipher `#{name}'"
|
36
|
+
return true if ossl_name == "none"
|
37
|
+
|
38
|
+
return OpenSSL::Cipher.ciphers.include?(ossl_name)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Retrieves a new instance of the named algorithm. The new instance
|
42
|
+
# will be initialized using an iv and key generated from the given
|
43
|
+
# iv, key, shared, hash and digester values. Additionally, the
|
44
|
+
# cipher will be put into encryption or decryption mode, based on the
|
45
|
+
# value of the +encrypt+ parameter.
|
46
|
+
def self.get(name, options = {})
|
47
|
+
ossl_name = SSH_TO_OSSL[name] or raise NotImplementedError, "unimplemented cipher `#{name}'"
|
48
|
+
return IdentityCipher if ossl_name == "none"
|
49
|
+
|
50
|
+
cipher = OpenSSL::Cipher.new(ossl_name)
|
51
|
+
|
52
|
+
cipher.send(options[:encrypt] ? :encrypt : :decrypt)
|
53
|
+
|
54
|
+
cipher.padding = 0
|
55
|
+
|
56
|
+
if name =~ /-ctr(@openssh.org)?$/
|
57
|
+
if ossl_name !~ /-ctr/
|
58
|
+
cipher.extend(Net::SSH::Transport::CTR)
|
59
|
+
else
|
60
|
+
cipher = Net::SSH::Transport::OpenSSLAESCTR.new(cipher)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
cipher.iv = Net::SSH::Transport::KeyExpander.expand_key(cipher.iv_len, options[:iv], options)
|
64
|
+
|
65
|
+
key_len = cipher.key_len
|
66
|
+
cipher.key_len = key_len
|
67
|
+
cipher.key = Net::SSH::Transport::KeyExpander.expand_key(key_len, options[:key], options)
|
68
|
+
|
69
|
+
return cipher
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns a two-element array containing the [ key-length,
|
73
|
+
# block-size ] for the named cipher algorithm. If the cipher
|
74
|
+
# algorithm is unknown, or is "none", 0 is returned for both elements
|
75
|
+
# of the tuple.
|
76
|
+
# if :iv_len option is supplied the third return value will be ivlen
|
77
|
+
def self.get_lengths(name, options = {})
|
78
|
+
ossl_name = SSH_TO_OSSL[name]
|
79
|
+
if ossl_name.nil? || ossl_name == "none"
|
80
|
+
result = [0, 0]
|
81
|
+
result << 0 if options[:iv_len]
|
82
|
+
else
|
83
|
+
cipher = OpenSSL::Cipher.new(ossl_name)
|
84
|
+
key_len = cipher.key_len
|
85
|
+
cipher.key_len = key_len
|
86
|
+
|
87
|
+
block_size =
|
88
|
+
case ossl_name
|
89
|
+
when /\-ctr/
|
90
|
+
Net::SSH::Transport::OpenSSLAESCTR.block_size
|
91
|
+
else
|
92
|
+
cipher.block_size
|
93
|
+
end
|
94
|
+
|
95
|
+
result = [key_len, block_size]
|
96
|
+
result << cipher.iv_len if options[:iv_len]
|
97
|
+
end
|
98
|
+
result
|
99
|
+
end
|
94
100
|
end
|
95
|
-
result
|
96
101
|
end
|
97
102
|
end
|
98
|
-
|
99
|
-
end; end; end
|
103
|
+
end
|
@@ -1,32 +1,40 @@
|
|
1
|
-
module Net
|
2
|
-
module
|
1
|
+
module Net
|
2
|
+
module SSH
|
3
|
+
module Transport
|
4
|
+
module Constants
|
5
|
+
#--
|
6
|
+
# Transport layer generic messages
|
7
|
+
#++
|
3
8
|
|
4
|
-
|
5
|
-
|
6
|
-
|
9
|
+
DISCONNECT = 1
|
10
|
+
IGNORE = 2
|
11
|
+
UNIMPLEMENTED = 3
|
12
|
+
DEBUG = 4
|
13
|
+
SERVICE_REQUEST = 5
|
14
|
+
SERVICE_ACCEPT = 6
|
7
15
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
DEBUG = 4
|
12
|
-
SERVICE_REQUEST = 5
|
13
|
-
SERVICE_ACCEPT = 6
|
16
|
+
#--
|
17
|
+
# Algorithm negotiation messages
|
18
|
+
#++
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
#++
|
20
|
+
KEXINIT = 20
|
21
|
+
NEWKEYS = 21
|
18
22
|
|
19
|
-
|
20
|
-
|
23
|
+
#--
|
24
|
+
# Key exchange method specific messages
|
25
|
+
#++
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
#++
|
27
|
+
KEXDH_INIT = 30
|
28
|
+
KEXDH_REPLY = 31
|
25
29
|
|
26
|
-
|
27
|
-
|
30
|
+
KEXECDH_INIT = 30
|
31
|
+
KEXECDH_REPLY = 31
|
28
32
|
|
29
|
-
|
30
|
-
|
33
|
+
KEXDH_GEX_GROUP = 31
|
34
|
+
KEXDH_GEX_INIT = 32
|
35
|
+
KEXDH_GEX_REPLY = 33
|
36
|
+
KEXDH_GEX_REQUEST = 34
|
37
|
+
end
|
38
|
+
end
|
31
39
|
end
|
32
|
-
end
|
40
|
+
end
|
@@ -1,18 +1,43 @@
|
|
1
1
|
require 'openssl'
|
2
|
+
require 'delegate'
|
2
3
|
|
3
4
|
module Net::SSH::Transport
|
5
|
+
# :nodoc:
|
6
|
+
class OpenSSLAESCTR < SimpleDelegator
|
7
|
+
def initialize(original)
|
8
|
+
super
|
9
|
+
@was_reset = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def block_size
|
13
|
+
16
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.block_size
|
17
|
+
16
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset
|
21
|
+
@was_reset = true
|
22
|
+
end
|
4
23
|
|
24
|
+
def iv=(iv_s)
|
25
|
+
super unless @was_reset
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# :nodoc:
|
5
30
|
# Pure-Ruby implementation of Stateful Decryption Counter(SDCTR) Mode
|
6
31
|
# for Block Ciphers. See RFC4344 for detail.
|
7
32
|
module CTR
|
8
33
|
def self.extended(orig)
|
9
34
|
orig.instance_eval {
|
10
|
-
@remaining =
|
35
|
+
@remaining = String.new
|
11
36
|
@counter = nil
|
12
37
|
@counter_len = orig.block_size
|
13
38
|
orig.encrypt
|
14
39
|
orig.padding = 0
|
15
|
-
|
40
|
+
|
16
41
|
singleton_class.send(:alias_method, :_update, :update)
|
17
42
|
singleton_class.send(:private, :_update)
|
18
43
|
singleton_class.send(:undef_method, :update)
|
@@ -42,38 +67,35 @@ module Net::SSH::Transport
|
|
42
67
|
end
|
43
68
|
|
44
69
|
def reset
|
45
|
-
@remaining =
|
70
|
+
@remaining = String.new
|
46
71
|
end
|
47
72
|
|
48
73
|
def update(data)
|
49
74
|
@remaining += data
|
50
75
|
|
51
|
-
encrypted =
|
76
|
+
encrypted = String.new
|
52
77
|
|
53
|
-
|
54
|
-
|
78
|
+
offset = 0
|
79
|
+
while (@remaining.bytesize - offset) >= block_size
|
80
|
+
encrypted += xor!(@remaining.slice(offset, block_size),
|
55
81
|
_update(@counter))
|
56
82
|
increment_counter!
|
83
|
+
offset += block_size
|
57
84
|
end
|
85
|
+
@remaining = @remaining.slice(offset..-1)
|
58
86
|
|
59
87
|
encrypted
|
60
88
|
end
|
61
89
|
|
62
90
|
def final
|
63
|
-
|
64
|
-
|
65
|
-
else
|
66
|
-
s = ""
|
67
|
-
end
|
68
|
-
|
69
|
-
@remaining = ""
|
70
|
-
|
91
|
+
s = @remaining.empty? ? '' : xor!(@remaining, _update(@counter))
|
92
|
+
@remaining = String.new
|
71
93
|
s
|
72
94
|
end
|
73
95
|
|
74
96
|
def xor!(s1, s2)
|
75
97
|
s = []
|
76
|
-
s1.unpack('Q*').zip(s2.unpack('Q*')) {|a,b| s.push(a^b) }
|
98
|
+
s1.unpack('Q*').zip(s2.unpack('Q*')) {|a, b| s.push(a ^ b) }
|
77
99
|
s.pack('Q*')
|
78
100
|
end
|
79
101
|
singleton_class.send(:private, :xor!)
|
@@ -1,79 +1,97 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
require 'openssl/digest'
|
3
3
|
|
4
|
-
module Net
|
4
|
+
module Net
|
5
|
+
module SSH
|
6
|
+
module Transport
|
7
|
+
module HMAC
|
8
|
+
# The base class of all OpenSSL-based HMAC algorithm wrappers.
|
9
|
+
class Abstract
|
10
|
+
class << self
|
11
|
+
def etm(*v)
|
12
|
+
@etm = false if !defined?(@etm)
|
13
|
+
if v.empty?
|
14
|
+
@etm = superclass.etm if @etm.nil? && superclass.respond_to?(:etm)
|
15
|
+
return @etm
|
16
|
+
elsif v.length == 1
|
17
|
+
@etm = v.first
|
18
|
+
else
|
19
|
+
raise ArgumentError, "wrong number of arguments (#{v.length} for 1)"
|
20
|
+
end
|
21
|
+
end
|
5
22
|
|
6
|
-
|
7
|
-
|
23
|
+
def key_length(*v)
|
24
|
+
@key_length = nil if !defined?(@key_length)
|
25
|
+
if v.empty?
|
26
|
+
@key_length = superclass.key_length if @key_length.nil? && superclass.respond_to?(:key_length)
|
27
|
+
return @key_length
|
28
|
+
elsif v.length == 1
|
29
|
+
@key_length = v.first
|
30
|
+
else
|
31
|
+
raise ArgumentError, "wrong number of arguments (#{v.length} for 1)"
|
32
|
+
end
|
33
|
+
end
|
8
34
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
35
|
+
def mac_length(*v)
|
36
|
+
@mac_length = nil if !defined?(@mac_length)
|
37
|
+
if v.empty?
|
38
|
+
@mac_length = superclass.mac_length if @mac_length.nil? && superclass.respond_to?(:mac_length)
|
39
|
+
return @mac_length
|
40
|
+
elsif v.length == 1
|
41
|
+
@mac_length = v.first
|
42
|
+
else
|
43
|
+
raise ArgumentError, "wrong number of arguments (#{v.length} for 1)"
|
44
|
+
end
|
45
|
+
end
|
21
46
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
47
|
+
def digest_class(*v)
|
48
|
+
@digest_class = nil if !defined?(@digest_class)
|
49
|
+
if v.empty?
|
50
|
+
@digest_class = superclass.digest_class if @digest_class.nil? && superclass.respond_to?(:digest_class)
|
51
|
+
return @digest_class
|
52
|
+
elsif v.length == 1
|
53
|
+
@digest_class = v.first
|
54
|
+
else
|
55
|
+
raise ArgumentError, "wrong number of arguments (#{v.length} for 1)"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
33
59
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@digest_class = superclass.digest_class if @digest_class.nil? && superclass.respond_to?(:digest_class)
|
38
|
-
return @digest_class
|
39
|
-
elsif v.length == 1
|
40
|
-
@digest_class = v.first
|
41
|
-
else
|
42
|
-
raise ArgumentError, "wrong number of arguments (#{v.length} for 1)"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
60
|
+
def etm
|
61
|
+
self.class.etm
|
62
|
+
end
|
46
63
|
|
47
|
-
|
48
|
-
|
49
|
-
|
64
|
+
def key_length
|
65
|
+
self.class.key_length
|
66
|
+
end
|
50
67
|
|
51
|
-
|
52
|
-
|
53
|
-
|
68
|
+
def mac_length
|
69
|
+
self.class.mac_length
|
70
|
+
end
|
54
71
|
|
55
|
-
|
56
|
-
|
57
|
-
|
72
|
+
def digest_class
|
73
|
+
self.class.digest_class
|
74
|
+
end
|
58
75
|
|
59
|
-
|
60
|
-
|
76
|
+
# The key in use for this instance.
|
77
|
+
attr_reader :key
|
61
78
|
|
62
|
-
|
63
|
-
|
64
|
-
|
79
|
+
def initialize(key = nil)
|
80
|
+
self.key = key
|
81
|
+
end
|
65
82
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
83
|
+
# Sets the key to the given value, truncating it so that it is the correct
|
84
|
+
# length.
|
85
|
+
def key=(value)
|
86
|
+
@key = value ? value.to_s[0, key_length] : nil
|
87
|
+
end
|
71
88
|
|
72
|
-
|
73
|
-
|
74
|
-
|
89
|
+
# Compute the HMAC digest for the given data string.
|
90
|
+
def digest(data)
|
91
|
+
OpenSSL::HMAC.digest(digest_class.new, key, data)[0, mac_length]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
75
95
|
end
|
76
|
-
|
77
96
|
end
|
78
|
-
|
79
|
-
end; end; end; end
|
97
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'net/ssh/transport/hmac/abstract'
|
2
2
|
|
3
3
|
module Net::SSH::Transport::HMAC
|
4
|
-
|
5
4
|
# The "none" algorithm. This has a key and mac length of 0.
|
6
5
|
class None < Abstract
|
7
6
|
key_length 0
|
@@ -11,5 +10,4 @@ module Net::SSH::Transport::HMAC
|
|
11
10
|
""
|
12
11
|
end
|
13
12
|
end
|
14
|
-
|
15
13
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'net/ssh/transport/hmac/abstract'
|
2
2
|
|
3
3
|
module Net::SSH::Transport::HMAC
|
4
|
-
|
5
4
|
# The RIPEMD-160 HMAC algorithm. This has a mac and key length of 20, and
|
6
5
|
# uses the RIPEMD-160 digest algorithm.
|
7
6
|
class RIPEMD160 < Abstract
|
@@ -9,5 +8,4 @@ module Net::SSH::Transport::HMAC
|
|
9
8
|
key_length 20
|
10
9
|
digest_class OpenSSL::Digest::RIPEMD160
|
11
10
|
end
|
12
|
-
|
13
11
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'net/ssh/transport/hmac/abstract'
|
2
2
|
|
3
3
|
module Net::SSH::Transport::HMAC
|
4
|
-
|
5
4
|
# The SHA1 HMAC algorithm. This has a mac and key length of 20, and
|
6
5
|
# uses the SHA1 digest algorithm.
|
7
6
|
class SHA1 < Abstract
|
@@ -9,5 +8,4 @@ module Net::SSH::Transport::HMAC
|
|
9
8
|
key_length 20
|
10
9
|
digest_class OpenSSL::Digest::SHA1
|
11
10
|
end
|
12
|
-
|
13
11
|
end
|
@@ -1,15 +1,11 @@
|
|
1
1
|
require 'net/ssh/transport/hmac/abstract'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
key_length 32
|
11
|
-
digest_class OpenSSL::Digest::SHA256
|
12
|
-
end
|
13
|
-
|
3
|
+
module Net::SSH::Transport::HMAC
|
4
|
+
# The SHA-256 HMAC algorithm. This has a mac and key length of 32, and
|
5
|
+
# uses the SHA-256 digest algorithm.
|
6
|
+
class SHA2_256 < Abstract
|
7
|
+
mac_length 32
|
8
|
+
key_length 32
|
9
|
+
digest_class OpenSSL::Digest::SHA256
|
14
10
|
end
|
15
11
|
end
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require 'net/ssh/transport/hmac/abstract'
|
2
2
|
|
3
3
|
module Net::SSH::Transport::HMAC
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
class SHA2_256_96 < SHA2_256
|
9
|
-
mac_length 12
|
10
|
-
end
|
4
|
+
# The SHA256-96 HMAC algorithm. This returns only the first 12 bytes of
|
5
|
+
# the digest.
|
6
|
+
class SHA2_256_96 < SHA2_256
|
7
|
+
mac_length 12
|
11
8
|
end
|
12
|
-
|
13
9
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'net/ssh/transport/hmac/abstract'
|
2
|
+
|
3
|
+
module Net::SSH::Transport::HMAC
|
4
|
+
# The SHA-256 Encrypt-Then-Mac HMAC algorithm. This has a mac and
|
5
|
+
# key length of 32, and uses the SHA-256 digest algorithm.
|
6
|
+
class SHA2_256_Etm < Abstract
|
7
|
+
etm true
|
8
|
+
mac_length 32
|
9
|
+
key_length 32
|
10
|
+
digest_class OpenSSL::Digest::SHA256
|
11
|
+
end
|
12
|
+
end
|