net-ssh 5.0.2 → 7.0.1

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 (122) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.dockerignore +6 -0
  4. data/.github/config/rubocop_linter_action.yml +4 -0
  5. data/.github/workflows/ci-with-docker.yml +44 -0
  6. data/.github/workflows/ci.yml +87 -0
  7. data/.github/workflows/rubocop.yml +13 -0
  8. data/.gitignore +3 -0
  9. data/.rubocop.yml +19 -2
  10. data/.rubocop_todo.yml +623 -511
  11. data/CHANGES.txt +76 -0
  12. data/Dockerfile +27 -0
  13. data/Dockerfile.openssl3 +17 -0
  14. data/Gemfile +2 -0
  15. data/Gemfile.noed25519 +2 -0
  16. data/Manifest +0 -1
  17. data/README.md +293 -0
  18. data/Rakefile +6 -2
  19. data/appveyor.yml +4 -2
  20. data/docker-compose.yml +23 -0
  21. data/lib/net/ssh/authentication/agent.rb +36 -14
  22. data/lib/net/ssh/authentication/certificate.rb +19 -7
  23. data/lib/net/ssh/authentication/constants.rb +0 -1
  24. data/lib/net/ssh/authentication/ed25519.rb +83 -50
  25. data/lib/net/ssh/authentication/ed25519_loader.rb +5 -8
  26. data/lib/net/ssh/authentication/key_manager.rb +74 -33
  27. data/lib/net/ssh/authentication/methods/abstract.rb +12 -3
  28. data/lib/net/ssh/authentication/methods/hostbased.rb +3 -5
  29. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +5 -3
  30. data/lib/net/ssh/authentication/methods/none.rb +6 -9
  31. data/lib/net/ssh/authentication/methods/password.rb +2 -3
  32. data/lib/net/ssh/authentication/methods/publickey.rb +58 -16
  33. data/lib/net/ssh/authentication/pageant.rb +97 -97
  34. data/lib/net/ssh/authentication/pub_key_fingerprint.rb +2 -3
  35. data/lib/net/ssh/authentication/session.rb +27 -23
  36. data/lib/net/ssh/buffer.rb +91 -40
  37. data/lib/net/ssh/buffered_io.rb +24 -26
  38. data/lib/net/ssh/config.rb +99 -53
  39. data/lib/net/ssh/connection/channel.rb +101 -87
  40. data/lib/net/ssh/connection/constants.rb +0 -4
  41. data/lib/net/ssh/connection/event_loop.rb +30 -25
  42. data/lib/net/ssh/connection/keepalive.rb +12 -12
  43. data/lib/net/ssh/connection/session.rb +115 -111
  44. data/lib/net/ssh/connection/term.rb +56 -58
  45. data/lib/net/ssh/errors.rb +12 -12
  46. data/lib/net/ssh/key_factory.rb +108 -22
  47. data/lib/net/ssh/known_hosts.rb +120 -36
  48. data/lib/net/ssh/loggable.rb +10 -11
  49. data/lib/net/ssh/packet.rb +1 -1
  50. data/lib/net/ssh/prompt.rb +9 -11
  51. data/lib/net/ssh/proxy/command.rb +1 -2
  52. data/lib/net/ssh/proxy/errors.rb +2 -4
  53. data/lib/net/ssh/proxy/http.rb +18 -20
  54. data/lib/net/ssh/proxy/https.rb +8 -10
  55. data/lib/net/ssh/proxy/jump.rb +8 -10
  56. data/lib/net/ssh/proxy/socks4.rb +2 -4
  57. data/lib/net/ssh/proxy/socks5.rb +3 -6
  58. data/lib/net/ssh/service/forward.rb +9 -8
  59. data/lib/net/ssh/test/channel.rb +24 -26
  60. data/lib/net/ssh/test/extensions.rb +37 -35
  61. data/lib/net/ssh/test/kex.rb +6 -8
  62. data/lib/net/ssh/test/local_packet.rb +0 -2
  63. data/lib/net/ssh/test/packet.rb +3 -3
  64. data/lib/net/ssh/test/remote_packet.rb +6 -8
  65. data/lib/net/ssh/test/script.rb +25 -27
  66. data/lib/net/ssh/test/socket.rb +12 -15
  67. data/lib/net/ssh/test.rb +12 -12
  68. data/lib/net/ssh/transport/algorithms.rb +177 -118
  69. data/lib/net/ssh/transport/cipher_factory.rb +34 -50
  70. data/lib/net/ssh/transport/constants.rb +13 -9
  71. data/lib/net/ssh/transport/ctr.rb +8 -14
  72. data/lib/net/ssh/transport/hmac/abstract.rb +20 -5
  73. data/lib/net/ssh/transport/hmac/md5.rb +0 -2
  74. data/lib/net/ssh/transport/hmac/md5_96.rb +0 -2
  75. data/lib/net/ssh/transport/hmac/none.rb +0 -2
  76. data/lib/net/ssh/transport/hmac/ripemd160.rb +0 -2
  77. data/lib/net/ssh/transport/hmac/sha1.rb +0 -2
  78. data/lib/net/ssh/transport/hmac/sha1_96.rb +0 -2
  79. data/lib/net/ssh/transport/hmac/sha2_256.rb +7 -11
  80. data/lib/net/ssh/transport/hmac/sha2_256_96.rb +4 -8
  81. data/lib/net/ssh/transport/hmac/sha2_256_etm.rb +12 -0
  82. data/lib/net/ssh/transport/hmac/sha2_512.rb +6 -9
  83. data/lib/net/ssh/transport/hmac/sha2_512_96.rb +4 -8
  84. data/lib/net/ssh/transport/hmac/sha2_512_etm.rb +12 -0
  85. data/lib/net/ssh/transport/hmac.rb +13 -11
  86. data/lib/net/ssh/transport/identity_cipher.rb +11 -13
  87. data/lib/net/ssh/transport/kex/abstract.rb +130 -0
  88. data/lib/net/ssh/transport/kex/abstract5656.rb +72 -0
  89. data/lib/net/ssh/transport/kex/curve25519_sha256.rb +39 -0
  90. data/lib/net/ssh/transport/kex/curve25519_sha256_loader.rb +30 -0
  91. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +5 -19
  92. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha256.rb +11 -0
  93. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +30 -139
  94. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +1 -8
  95. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb +5 -9
  96. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +20 -81
  97. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +5 -4
  98. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +5 -4
  99. data/lib/net/ssh/transport/kex.rb +15 -10
  100. data/lib/net/ssh/transport/key_expander.rb +7 -8
  101. data/lib/net/ssh/transport/openssl.rb +149 -111
  102. data/lib/net/ssh/transport/packet_stream.rb +53 -22
  103. data/lib/net/ssh/transport/server_version.rb +17 -16
  104. data/lib/net/ssh/transport/session.rb +35 -11
  105. data/lib/net/ssh/transport/state.rb +44 -44
  106. data/lib/net/ssh/verifiers/accept_new.rb +7 -2
  107. data/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb +1 -2
  108. data/lib/net/ssh/verifiers/always.rb +10 -4
  109. data/lib/net/ssh/verifiers/never.rb +4 -2
  110. data/lib/net/ssh/version.rb +2 -2
  111. data/lib/net/ssh.rb +17 -9
  112. data/net-ssh-public_cert.pem +18 -19
  113. data/net-ssh.gemspec +9 -7
  114. data/support/ssh_tunnel_bug.rb +3 -3
  115. data.tar.gz.sig +0 -0
  116. metadata +65 -41
  117. metadata.gz.sig +0 -0
  118. data/.travis.yml +0 -52
  119. data/Gemfile.noed25519.lock +0 -41
  120. data/README.rdoc +0 -169
  121. data/lib/net/ssh/ruby_compat.rb +0 -13
  122. data/support/arcfour_check.rb +0 -20
@@ -1,7 +1,6 @@
1
- module Net
2
- module SSH
1
+ module Net
2
+ module SSH
3
3
  module Connection
4
-
5
4
  # These constants are used when requesting a pseudo-terminal (via
6
5
  # Net::SSH::Connection::Channel#request_pty). The descriptions for each are
7
6
  # taken directly from RFC 4254 ("The Secure Shell (SSH) Connection Protocol"),
@@ -10,173 +9,172 @@ module Net
10
9
  # Interrupt character; 255 if none. Similarly for the other characters.
11
10
  # Not all of these characters are supported on all systems.
12
11
  VINTR = 1
13
-
12
+
14
13
  # The quit character (sends SIGQUIT signal on POSIX systems).
15
14
  VQUIT = 2
16
-
15
+
17
16
  # Erase the character to left of the cursor.
18
17
  VERASE = 3
19
-
18
+
20
19
  # Kill the current input line.
21
20
  VKILL = 4
22
-
21
+
23
22
  # End-of-file character (sends EOF from the terminal).
24
23
  VEOF = 5
25
-
24
+
26
25
  # End-of-line character in addition to carriage return and/or linefeed.
27
26
  VEOL = 6
28
-
27
+
29
28
  # Additional end-of-line character.
30
29
  VEOL2 = 7
31
-
30
+
32
31
  # Continues paused output (normally control-Q).
33
32
  VSTART = 8
34
-
33
+
35
34
  # Pauses output (normally control-S).
36
35
  VSTOP = 9
37
-
36
+
38
37
  # Suspends the current program.
39
38
  VSUSP = 10
40
-
39
+
41
40
  # Another suspend character.
42
41
  VDSUSP = 11
43
-
42
+
44
43
  # Reprints the current input line.
45
44
  VREPRINT = 12
46
-
45
+
47
46
  # Erases a word left of cursor.
48
47
  VWERASE = 13
49
-
48
+
50
49
  # Enter the next character typed literally, even if it is a special
51
50
  # character.
52
51
  VLNEXT = 14
53
-
52
+
54
53
  # Character to flush output.
55
54
  VFLUSH = 15
56
-
55
+
57
56
  # Switch to a different shell layer.
58
57
  VSWITCH = 16
59
-
58
+
60
59
  # Prints system status line (load, command, pid, etc).
61
60
  VSTATUS = 17
62
-
61
+
63
62
  # Toggles the flushing of terminal output.
64
63
  VDISCARD = 18
65
-
64
+
66
65
  # The ignore parity flag. The parameter SHOULD be 0 if this flag is FALSE,
67
66
  # and 1 if it is TRUE.
68
67
  IGNPAR = 30
69
-
68
+
70
69
  # Mark parity and framing errors.
71
70
  PARMRK = 31
72
-
71
+
73
72
  # Enable checking of parity errors.
74
73
  INPCK = 32
75
-
74
+
76
75
  # Strip 8th bit off characters.
77
76
  ISTRIP = 33
78
-
77
+
79
78
  # Map NL into CR on input.
80
79
  INCLR = 34
81
-
80
+
82
81
  # Ignore CR on input.
83
82
  IGNCR = 35
84
-
83
+
85
84
  # Map CR to NL on input.
86
85
  ICRNL = 36
87
-
86
+
88
87
  # Translate uppercase characters to lowercase.
89
88
  IUCLC = 37
90
-
89
+
91
90
  # Enable output flow control.
92
91
  IXON = 38
93
-
92
+
94
93
  # Any char will restart after stop.
95
94
  IXANY = 39
96
-
95
+
97
96
  # Enable input flow control.
98
97
  IXOFF = 40
99
-
98
+
100
99
  # Ring bell on input queue full.
101
100
  IMAXBEL = 41
102
-
101
+
103
102
  # Enable signals INTR, QUIT, [D]SUSP.
104
103
  ISIG = 50
105
-
104
+
106
105
  # Canonicalize input lines.
107
106
  ICANON = 51
108
-
107
+
109
108
  # Enable input and output of uppercase characters by preceding their
110
109
  # lowercase equivalents with "\".
111
110
  XCASE = 52
112
-
111
+
113
112
  # Enable echoing.
114
113
  ECHO = 53
115
-
114
+
116
115
  # Visually erase chars.
117
116
  ECHOE = 54
118
-
117
+
119
118
  # Kill character discards current line.
120
119
  ECHOK = 55
121
-
120
+
122
121
  # Echo NL even if ECHO is off.
123
122
  ECHONL = 56
124
-
123
+
125
124
  # Don't flush after interrupt.
126
125
  NOFLSH = 57
127
-
126
+
128
127
  # Stop background jobs from output.
129
128
  TOSTOP = 58
130
-
129
+
131
130
  # Enable extensions.
132
131
  IEXTEN = 59
133
-
132
+
134
133
  # Echo control characters as ^(Char).
135
134
  ECHOCTL = 60
136
-
135
+
137
136
  # Visual erase for line kill.
138
137
  ECHOKE = 61
139
-
138
+
140
139
  # Retype pending input.
141
140
  PENDIN = 62
142
-
141
+
143
142
  # Enable output processing.
144
143
  OPOST = 70
145
-
144
+
146
145
  # Convert lowercase to uppercase.
147
146
  OLCUC = 71
148
-
147
+
149
148
  # Map NL to CR-NL.
150
149
  ONLCR = 72
151
-
150
+
152
151
  # Translate carriage return to newline (output).
153
152
  OCRNL = 73
154
-
153
+
155
154
  # Translate newline to carriage return-newline (output).
156
155
  ONOCR = 74
157
-
156
+
158
157
  # Newline performs a carriage return (output).
159
158
  ONLRET = 75
160
-
159
+
161
160
  # 7 bit mode.
162
161
  CS7 = 90
163
-
162
+
164
163
  # 8 bit mode.
165
164
  CS8 = 91
166
-
165
+
167
166
  # Parity enable.
168
167
  PARENB = 92
169
-
168
+
170
169
  # Odd parity, else even.
171
170
  PARODD = 93
172
-
171
+
173
172
  # Specifies the input baud rate in bits per second.
174
173
  TTY_OP_ISPEED = 128
175
-
174
+
176
175
  # Specifies the output baud rate in bits per second.
177
176
  TTY_OP_OSPEED = 129
178
177
  end
179
-
180
178
  end
181
179
  end
182
180
  end
@@ -1,4 +1,4 @@
1
- module Net
1
+ module Net
2
2
  module SSH
3
3
  # A general exception class, to act as the ancestor of all other Net::SSH
4
4
  # exception classes.
@@ -33,7 +33,7 @@ module Net
33
33
  # a "channel open failed" message.
34
34
  class ChannelOpenFailed < Net::SSH::Exception
35
35
  attr_reader :code, :reason
36
-
36
+
37
37
  def initialize(code, reason)
38
38
  @code, @reason = code, reason
39
39
  super "#{reason} (#{code})"
@@ -45,43 +45,43 @@ module Net
45
45
  # the remember_host! method on the exception, and then retry.
46
46
  class HostKeyError < Net::SSH::Exception
47
47
  # the callback to use when #remember_host! is called
48
- attr_writer :callback #:nodoc:
49
-
48
+ attr_writer :callback # :nodoc:
49
+
50
50
  # situation-specific data describing the host (see #host, #port, etc.)
51
- attr_writer :data #:nodoc:
52
-
51
+ attr_writer :data # :nodoc:
52
+
53
53
  # An accessor for getting at the data that was used to look up the host
54
54
  # (see also #fingerprint, #host, #port, #ip, and #key).
55
55
  def [](key)
56
56
  @data && @data[key]
57
57
  end
58
-
58
+
59
59
  # Returns the fingerprint of the key for the host, which either was not
60
60
  # found or did not match.
61
61
  def fingerprint
62
62
  @data && @data[:fingerprint]
63
63
  end
64
-
64
+
65
65
  # Returns the host name for the remote host, as reported by the socket.
66
66
  def host
67
67
  @data && @data[:peer] && @data[:peer][:host]
68
68
  end
69
-
69
+
70
70
  # Returns the port number for the remote host, as reported by the socket.
71
71
  def port
72
72
  @data && @data[:peer] && @data[:peer][:port]
73
73
  end
74
-
74
+
75
75
  # Returns the IP address of the remote host, as reported by the socket.
76
76
  def ip
77
77
  @data && @data[:peer] && @data[:peer][:ip]
78
78
  end
79
-
79
+
80
80
  # Returns the key itself, as reported by the remote host.
81
81
  def key
82
82
  @data && @data[:key]
83
83
  end
84
-
84
+
85
85
  # Tell Net::SSH to record this host and key in the known hosts file, so
86
86
  # that subsequent connections will remember them.
87
87
  def remember_host!
@@ -5,7 +5,6 @@ require 'net/ssh/authentication/ed25519_loader'
5
5
 
6
6
  module Net
7
7
  module SSH
8
-
9
8
  # A factory class for returning new Key classes. It is used for obtaining
10
9
  # OpenSSL key instances via their SSH names, and for loading both public and
11
10
  # private keys. It used used primarily by Net::SSH itself, internally, and
@@ -18,16 +17,14 @@ module Net
18
17
  class KeyFactory
19
18
  # Specifies the mapping of SSH names to OpenSSL key classes.
20
19
  MAP = {
21
- "dh" => OpenSSL::PKey::DH,
22
- "rsa" => OpenSSL::PKey::RSA,
23
- "dsa" => OpenSSL::PKey::DSA
20
+ 'dh' => OpenSSL::PKey::DH,
21
+ 'rsa' => OpenSSL::PKey::RSA,
22
+ 'dsa' => OpenSSL::PKey::DSA,
23
+ 'ecdsa' => OpenSSL::PKey::EC
24
24
  }
25
- if defined?(OpenSSL::PKey::EC)
26
- MAP["ecdsa"] = OpenSSL::PKey::EC
27
- MAP["ed25519"] = Net::SSH::Authentication::ED25519::PrivKey if defined? Net::SSH::Authentication::ED25519
28
- end
25
+ MAP["ed25519"] = Net::SSH::Authentication::ED25519::PrivKey if defined? Net::SSH::Authentication::ED25519
29
26
 
30
- class <<self
27
+ class << self
31
28
  # Fetch an OpenSSL key instance by its SSH name. It will be a new,
32
29
  # empty key of the given type.
33
30
  def get(name)
@@ -39,7 +36,7 @@ module Net
39
36
  # appropriately. The new key is returned. If the key itself is
40
37
  # encrypted (requiring a passphrase to use), the user will be
41
38
  # prompted to enter their password unless passphrase works.
42
- def load_private_key(filename, passphrase=nil, ask_passphrase=true, prompt=Prompt.default)
39
+ def load_private_key(filename, passphrase = nil, ask_passphrase = true, prompt = Prompt.default)
43
40
  data = File.read(File.expand_path(filename))
44
41
  load_data_private_key(data, passphrase, ask_passphrase, filename, prompt)
45
42
  end
@@ -49,17 +46,18 @@ module Net
49
46
  # appropriately. The new key is returned. If the key itself is
50
47
  # encrypted (requiring a passphrase to use), the user will be
51
48
  # prompted to enter their password unless passphrase works.
52
- def load_data_private_key(data, passphrase=nil, ask_passphrase=true, filename="", prompt=Prompt.default)
53
- key_read, error_classes = classify_key(data, filename)
49
+ def load_data_private_key(data, passphrase = nil, ask_passphrase = true, filename = "", prompt = Prompt.default)
50
+ key_type = classify_key(data, filename)
54
51
 
55
- encrypted_key = data.match(/ENCRYPTED/)
52
+ encrypted_key = nil
56
53
  tries = 0
57
54
 
58
55
  prompter = nil
59
56
  result =
60
57
  begin
61
- key_read[data, passphrase || 'invalid']
62
- rescue *error_classes
58
+ key_type.read(data, passphrase || 'invalid')
59
+ rescue *key_type.error_classes => e
60
+ encrypted_key = !!key_type.encrypted_key?(data, e) if encrypted_key.nil?
63
61
  if encrypted_key && ask_passphrase
64
62
  tries += 1
65
63
  if tries <= 3
@@ -88,7 +86,7 @@ module Net
88
86
  # Loads a public key. It will correctly determine whether
89
87
  # the file describes an RSA or DSA key, and will load it
90
88
  # appropriately. The new public key is returned.
91
- def load_data_public_key(data, filename="")
89
+ def load_data_public_key(data, filename = "")
92
90
  fields = data.split(/ /)
93
91
 
94
92
  blob = nil
@@ -106,20 +104,108 @@ module Net
106
104
 
107
105
  private
108
106
 
107
+ # rubocop:disable Style/Documentation, Lint/DuplicateMethods
108
+ class KeyType
109
+ def self.read(key_data, passphrase)
110
+ raise Exception, "TODO subclasses should implement read"
111
+ end
112
+
113
+ def self.error_classes
114
+ raise Exception, "TODO subclasses should implement read"
115
+ end
116
+
117
+ def self.encrypted_key?(data, error)
118
+ raise Exception, "TODO subclasses should implement is_encrypted_key"
119
+ end
120
+ end
121
+
122
+ class OpenSSHPrivateKeyType < KeyType
123
+ def self.read(key_data, passphrase)
124
+ Net::SSH::Authentication::ED25519::OpenSSHPrivateKeyLoader.read(key_data, passphrase)
125
+ end
126
+
127
+ def self.error_classes
128
+ [Net::SSH::Authentication::ED25519::OpenSSHPrivateKeyLoader::DecryptError]
129
+ end
130
+
131
+ def self.encrypted_key?(key_data, decode_error)
132
+ decode_error.is_a?(Net::SSH::Authentication::ED25519::OpenSSHPrivateKeyLoader::DecryptError) && decode_error.encrypted_key?
133
+ end
134
+ end
135
+
136
+ class OpenSSLKeyTypeBase < KeyType
137
+ def self.open_ssl_class
138
+ raise Exception, "TODO: subclasses should implement"
139
+ end
140
+
141
+ def self.read(key_data, passphrase)
142
+ open_ssl_class.new(key_data, passphrase)
143
+ end
144
+
145
+ def self.encrypted_key?(key_data, error)
146
+ key_data.match(/ENCRYPTED/)
147
+ end
148
+ end
149
+
150
+ class OpenSSLPKeyType < OpenSSLKeyTypeBase
151
+ def self.read(key_data, passphrase)
152
+ open_ssl_class.read(key_data, passphrase)
153
+ end
154
+
155
+ def self.open_ssl_class
156
+ OpenSSL::PKey
157
+ end
158
+
159
+ def self.error_classes
160
+ [ArgumentError, OpenSSL::PKey::PKeyError]
161
+ end
162
+ end
163
+
164
+ class OpenSSLDSAKeyType < OpenSSLKeyTypeBase
165
+ def self.open_ssl_class
166
+ OpenSSL::PKey::DSA
167
+ end
168
+
169
+ def self.error_classes
170
+ [OpenSSL::PKey::DSAError]
171
+ end
172
+ end
173
+
174
+ class OpenSSLRSAKeyType < OpenSSLKeyTypeBase
175
+ def self.open_ssl_class
176
+ OpenSSL::PKey::RSA
177
+ end
178
+
179
+ def self.error_classes
180
+ [OpenSSL::PKey::RSAError]
181
+ end
182
+ end
183
+
184
+ class OpenSSLECKeyType < OpenSSLKeyTypeBase
185
+ def self.open_ssl_class
186
+ OpenSSL::PKey::EC
187
+ end
188
+
189
+ def self.error_classes
190
+ [OpenSSL::PKey::ECError]
191
+ end
192
+ end
193
+ # rubocop:enable Style/Documentation, Lint/DuplicateMethods
194
+
109
195
  # Determine whether the file describes an RSA or DSA key, and return how load it
110
196
  # appropriately.
111
197
  def classify_key(data, filename)
112
198
  if data.match(/-----BEGIN OPENSSH PRIVATE KEY-----/)
113
199
  Net::SSH::Authentication::ED25519Loader.raiseUnlessLoaded("OpenSSH keys only supported if ED25519 is available")
114
- return ->(key_data, passphrase) { Net::SSH::Authentication::ED25519::PrivKey.read(key_data, passphrase) }, [ArgumentError]
200
+ return OpenSSHPrivateKeyType
115
201
  elsif OpenSSL::PKey.respond_to?(:read)
116
- return ->(key_data, passphrase) { OpenSSL::PKey.read(key_data, passphrase) }, [ArgumentError, OpenSSL::PKey::PKeyError]
202
+ return OpenSSLPKeyType
117
203
  elsif data.match(/-----BEGIN DSA PRIVATE KEY-----/)
118
- return ->(key_data, passphrase) { OpenSSL::PKey::DSA.new(key_data, passphrase) }, [OpenSSL::PKey::DSAError]
204
+ return OpenSSLDSAKeyType
119
205
  elsif data.match(/-----BEGIN RSA PRIVATE KEY-----/)
120
- return ->(key_data, passphrase) { OpenSSL::PKey::RSA.new(key_data, passphrase) }, [OpenSSL::PKey::RSAError]
121
- elsif data.match(/-----BEGIN EC PRIVATE KEY-----/) && defined?(OpenSSL::PKey::EC)
122
- return ->(key_data, passphrase) { OpenSSL::PKey::EC.new(key_data, passphrase) }, [OpenSSL::PKey::ECError]
206
+ return OpenSSLRSAKeyType
207
+ elsif data.match(/-----BEGIN EC PRIVATE KEY-----/)
208
+ return OpenSSLECKeyType
123
209
  elsif data.match(/-----BEGIN (.+) PRIVATE KEY-----/)
124
210
  raise OpenSSL::PKey::PKeyError, "not a supported key type '#{$1}'"
125
211
  else