net-ssh 3.2.0.rc2 → 7.1.0
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 +2 -2
- 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 +16 -0
- data/.gitignore +13 -0
- data/.rubocop.yml +22 -0
- data/.rubocop_todo.yml +1081 -0
- data/CHANGES.txt +228 -7
- data/Dockerfile +27 -0
- data/Dockerfile.openssl3 +17 -0
- data/Gemfile +13 -0
- data/Gemfile.noed25519 +12 -0
- data/ISSUE_TEMPLATE.md +30 -0
- data/Manifest +4 -5
- data/README.md +297 -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 +441 -360
- data/lib/net/ssh/transport/cipher_factory.rb +96 -98
- 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 -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 +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/packet_stream.rb +225 -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 +110 -47
- data/net-ssh-public_cert.pem +18 -18
- data/net-ssh.gemspec +36 -205
- data/support/ssh_tunnel_bug.rb +5 -5
- data.tar.gz.sig +0 -0
- metadata +153 -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
@@ -13,381 +13,485 @@ else
|
|
13
13
|
# For now map DL to Fiddler versus updating all the code below
|
14
14
|
module DL
|
15
15
|
CPtr ||= Fiddle::Pointer
|
16
|
-
|
16
|
+
if RUBY_PLATFORM != "java"
|
17
|
+
RUBY_FREE ||= Fiddle::RUBY_FREE
|
18
|
+
end
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
22
|
require 'net/ssh/errors'
|
21
23
|
|
22
|
-
module Net
|
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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
24
|
+
module Net
|
25
|
+
module SSH
|
26
|
+
module Authentication
|
27
|
+
# This module encapsulates the implementation of a socket factory that
|
28
|
+
# uses the PuTTY "pageant" utility to obtain information about SSH
|
29
|
+
# identities.
|
30
|
+
#
|
31
|
+
# This code is a slightly modified version of the original implementation
|
32
|
+
# by Guillaume Marçais (guillaume.marcais@free.fr). It is used and
|
33
|
+
# relicensed by permission.
|
34
|
+
module Pageant
|
35
|
+
# From Putty pageant.c
|
36
|
+
AGENT_MAX_MSGLEN = 8192
|
37
|
+
AGENT_COPYDATA_ID = 0x804e50ba
|
38
|
+
|
39
|
+
# The definition of the Windows methods and data structures used in
|
40
|
+
# communicating with the pageant process.
|
41
|
+
module Win # rubocop:disable Metrics/ModuleLength
|
42
|
+
# Compatibility on initialization
|
43
|
+
if RUBY_VERSION < "1.9"
|
44
|
+
extend DL::Importable
|
45
|
+
|
46
|
+
dlload 'user32.dll'
|
47
|
+
dlload 'kernel32.dll'
|
48
|
+
dlload 'advapi32.dll'
|
49
|
+
|
50
|
+
SIZEOF_DWORD = DL.sizeof('L')
|
51
|
+
elsif RUBY_VERSION < "2.1"
|
52
|
+
extend DL::Importer
|
53
|
+
dlload 'user32.dll', 'kernel32.dll', 'advapi32.dll'
|
54
|
+
include DL::Win32Types
|
55
|
+
|
56
|
+
SIZEOF_DWORD = DL::SIZEOF_LONG
|
57
|
+
else
|
58
|
+
extend Fiddle::Importer
|
59
|
+
dlload 'user32.dll', 'kernel32.dll', 'advapi32.dll'
|
60
|
+
include Fiddle::Win32Types
|
61
|
+
SIZEOF_DWORD = Fiddle::SIZEOF_LONG
|
62
|
+
end
|
63
|
+
|
64
|
+
if RUBY_ENGINE == "jruby"
|
65
|
+
typealias("HANDLE", "void *") # From winnt.h
|
66
|
+
typealias("PHANDLE", "void *") # From winnt.h
|
67
|
+
typealias("ULONG_PTR", "unsigned long*")
|
68
|
+
end
|
69
|
+
typealias("LPCTSTR", "char *") # From winnt.h
|
70
|
+
typealias("LPVOID", "void *") # From winnt.h
|
71
|
+
typealias("LPCVOID", "const void *") # From windef.h
|
72
|
+
typealias("LRESULT", "long") # From windef.h
|
73
|
+
typealias("WPARAM", "unsigned int *") # From windef.h
|
74
|
+
typealias("LPARAM", "long *") # From windef.h
|
75
|
+
typealias("PDWORD_PTR", "long *") # From basetsd.h
|
76
|
+
typealias("USHORT", "unsigned short") # From windef.h
|
77
|
+
|
78
|
+
# From winbase.h, winnt.h
|
79
|
+
INVALID_HANDLE_VALUE = -1
|
80
|
+
NULL = nil
|
81
|
+
PAGE_READWRITE = 0x0004
|
82
|
+
FILE_MAP_WRITE = 2
|
83
|
+
WM_COPYDATA = 74
|
84
|
+
|
85
|
+
SMTO_NORMAL = 0 # From winuser.h
|
86
|
+
|
87
|
+
SUFFIX = if RUBY_ENGINE == "jruby"
|
88
|
+
"A"
|
89
|
+
else
|
90
|
+
""
|
91
|
+
end
|
92
|
+
|
93
|
+
# args: lpClassName, lpWindowName
|
94
|
+
extern "HWND FindWindow#{SUFFIX}(LPCTSTR, LPCTSTR)"
|
95
|
+
|
96
|
+
# args: none
|
97
|
+
extern 'DWORD GetCurrentThreadId()'
|
98
|
+
|
99
|
+
# args: hFile, (ignored), flProtect, dwMaximumSizeHigh,
|
100
|
+
# dwMaximumSizeLow, lpName
|
101
|
+
extern "HANDLE CreateFileMapping#{SUFFIX}(HANDLE, void *, DWORD, " +
|
102
|
+
"DWORD, DWORD, LPCTSTR)"
|
103
|
+
|
104
|
+
# args: hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh,
|
105
|
+
# dwfileOffsetLow, dwNumberOfBytesToMap
|
106
|
+
extern 'LPVOID MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, DWORD)'
|
107
|
+
|
108
|
+
# args: lpBaseAddress
|
109
|
+
extern 'BOOL UnmapViewOfFile(LPCVOID)'
|
110
|
+
|
111
|
+
# args: hObject
|
112
|
+
extern 'BOOL CloseHandle(HANDLE)'
|
113
|
+
|
114
|
+
# args: hWnd, Msg, wParam, lParam, fuFlags, uTimeout, lpdwResult
|
115
|
+
extern "LRESULT SendMessageTimeout#{SUFFIX}(HWND, UINT, WPARAM, LPARAM, " +
|
116
|
+
"UINT, UINT, PDWORD_PTR)"
|
117
|
+
|
118
|
+
# args: none
|
119
|
+
extern 'DWORD GetLastError()'
|
120
|
+
|
121
|
+
# args: none
|
122
|
+
extern 'HANDLE GetCurrentProcess()'
|
123
|
+
|
124
|
+
# args: hProcessHandle, dwDesiredAccess, (out) phNewTokenHandle
|
125
|
+
extern 'BOOL OpenProcessToken(HANDLE, DWORD, PHANDLE)'
|
126
|
+
|
127
|
+
# args: hTokenHandle, uTokenInformationClass,
|
128
|
+
# (out) lpTokenInformation, dwTokenInformationLength
|
129
|
+
# (out) pdwInfoReturnLength
|
130
|
+
extern 'BOOL GetTokenInformation(HANDLE, UINT, LPVOID, DWORD, ' +
|
131
|
+
'PDWORD)'
|
132
|
+
|
133
|
+
# args: (out) lpSecurityDescriptor, dwRevisionLevel
|
134
|
+
extern 'BOOL InitializeSecurityDescriptor(LPVOID, DWORD)'
|
135
|
+
|
136
|
+
# args: (out) lpSecurityDescriptor, lpOwnerSid, bOwnerDefaulted
|
137
|
+
extern 'BOOL SetSecurityDescriptorOwner(LPVOID, LPVOID, BOOL)'
|
138
|
+
|
139
|
+
# args: pSecurityDescriptor
|
140
|
+
extern 'BOOL IsValidSecurityDescriptor(LPVOID)'
|
141
|
+
|
142
|
+
# Constants needed for security attribute retrieval.
|
143
|
+
# Specifies the access mask corresponding to the desired access
|
144
|
+
# rights.
|
145
|
+
TOKEN_QUERY = 0x8
|
146
|
+
|
147
|
+
# The value of TOKEN_USER from the TOKEN_INFORMATION_CLASS enum.
|
148
|
+
TOKEN_USER_INFORMATION_CLASS = 1
|
149
|
+
|
150
|
+
# The initial revision level assigned to the security descriptor.
|
151
|
+
REVISION = 1
|
152
|
+
|
153
|
+
# Structs for security attribute functions.
|
154
|
+
# Holds the retrieved user access token.
|
155
|
+
TOKEN_USER = struct ['void * SID', 'DWORD ATTRIBUTES']
|
156
|
+
|
157
|
+
# Contains the security descriptor, this gets passed to the
|
158
|
+
# function that constructs the shared memory map.
|
159
|
+
SECURITY_ATTRIBUTES = struct ['DWORD nLength',
|
160
|
+
'LPVOID lpSecurityDescriptor',
|
161
|
+
'BOOL bInheritHandle']
|
162
|
+
|
163
|
+
# The security descriptor holds security information.
|
164
|
+
SECURITY_DESCRIPTOR = struct ['UCHAR Revision', 'UCHAR Sbz1',
|
165
|
+
'USHORT Control', 'LPVOID Owner',
|
166
|
+
'LPVOID Group', 'LPVOID Sacl',
|
167
|
+
'LPVOID Dacl']
|
168
|
+
|
169
|
+
# The COPYDATASTRUCT is used to send WM_COPYDATA messages
|
170
|
+
COPYDATASTRUCT = if RUBY_ENGINE == "jruby"
|
171
|
+
struct ['ULONG_PTR dwData', 'DWORD cbData', 'LPVOID lpData']
|
172
|
+
else
|
173
|
+
struct ['uintptr_t dwData', 'DWORD cbData', 'LPVOID lpData']
|
174
|
+
end
|
175
|
+
|
176
|
+
# Compatibility for security attribute retrieval.
|
177
|
+
if RUBY_VERSION < "1.9"
|
178
|
+
# Alias functions to > 1.9 capitalization
|
179
|
+
%w[findWindow
|
180
|
+
getCurrentProcess
|
181
|
+
initializeSecurityDescriptor
|
182
|
+
setSecurityDescriptorOwner
|
183
|
+
isValidSecurityDescriptor
|
184
|
+
openProcessToken
|
185
|
+
getTokenInformation
|
186
|
+
getLastError
|
187
|
+
getCurrentThreadId
|
188
|
+
createFileMapping
|
189
|
+
mapViewOfFile
|
190
|
+
sendMessageTimeout
|
191
|
+
unmapViewOfFile
|
192
|
+
closeHandle].each do |name|
|
193
|
+
new_name = name[0].chr.upcase + name[1..name.length]
|
194
|
+
alias_method new_name, name
|
195
|
+
module_function new_name
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.malloc_ptr(size)
|
199
|
+
return DL.malloc(size)
|
200
|
+
end
|
201
|
+
|
202
|
+
def self.get_ptr(data)
|
203
|
+
return data.to_ptr
|
204
|
+
end
|
205
|
+
|
206
|
+
def self.set_ptr_data(ptr, data)
|
207
|
+
ptr[0] = data
|
208
|
+
end
|
209
|
+
elsif RUBY_ENGINE == "jruby"
|
210
|
+
%w[FindWindow CreateFileMapping SendMessageTimeout].each do |name|
|
211
|
+
alias_method name, name + "A"
|
212
|
+
module_function name
|
213
|
+
end
|
214
|
+
# :nodoc:
|
215
|
+
module LibC
|
216
|
+
extend FFI::Library
|
217
|
+
ffi_lib FFI::Library::LIBC
|
218
|
+
attach_function :malloc, [:size_t], :pointer
|
219
|
+
attach_function :free, [:pointer], :void
|
220
|
+
end
|
221
|
+
|
222
|
+
def self.malloc_ptr(size)
|
223
|
+
Fiddle::Pointer.new(LibC.malloc(size), size, LibC.method(:free))
|
224
|
+
end
|
225
|
+
|
226
|
+
def self.get_ptr(ptr)
|
227
|
+
return data.address
|
228
|
+
end
|
229
|
+
|
230
|
+
def self.set_ptr_data(ptr, data)
|
231
|
+
ptr.write_string_length(data, data.size)
|
232
|
+
end
|
233
|
+
else
|
234
|
+
def self.malloc_ptr(size)
|
235
|
+
return DL::CPtr.malloc(size, DL::RUBY_FREE)
|
236
|
+
end
|
237
|
+
|
238
|
+
def self.get_ptr(data)
|
239
|
+
return DL::CPtr.to_ptr data
|
240
|
+
end
|
241
|
+
|
242
|
+
def self.set_ptr_data(ptr, data)
|
243
|
+
DL::CPtr.new(ptr)[0, data.size] = data
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.get_security_attributes_for_user
|
248
|
+
user = get_current_user
|
249
|
+
|
250
|
+
psd_information = malloc_ptr(Win::SECURITY_DESCRIPTOR.size)
|
251
|
+
raise_error_if_zero(
|
252
|
+
Win.InitializeSecurityDescriptor(psd_information,
|
253
|
+
Win::REVISION)
|
254
|
+
)
|
255
|
+
raise_error_if_zero(
|
256
|
+
Win.SetSecurityDescriptorOwner(psd_information, get_sid_ptr(user),
|
257
|
+
0)
|
258
|
+
)
|
259
|
+
raise_error_if_zero(
|
260
|
+
Win.IsValidSecurityDescriptor(psd_information)
|
261
|
+
)
|
262
|
+
|
263
|
+
sa = Win::SECURITY_ATTRIBUTES.new(to_struct_ptr(malloc_ptr(Win::SECURITY_ATTRIBUTES.size)))
|
264
|
+
sa.nLength = Win::SECURITY_ATTRIBUTES.size
|
265
|
+
sa.lpSecurityDescriptor = psd_information.to_i
|
266
|
+
sa.bInheritHandle = 1
|
267
|
+
|
268
|
+
return sa
|
269
|
+
end
|
270
|
+
|
271
|
+
if RUBY_ENGINE == "jruby"
|
272
|
+
def self.ptr_to_s(ptr, size)
|
273
|
+
ret = ptr.to_s(size)
|
274
|
+
ret << "\x00" while ret.size < size
|
275
|
+
ret
|
276
|
+
end
|
277
|
+
|
278
|
+
def self.ptr_to_handle(phandle)
|
279
|
+
phandle.ptr
|
280
|
+
end
|
281
|
+
|
282
|
+
def self.ptr_to_dword(ptr)
|
283
|
+
first = ptr.ptr.to_i
|
284
|
+
second = ptr_to_s(ptr, Win::SIZEOF_DWORD).unpack('L')[0]
|
285
|
+
raise "Error" unless first == second
|
286
|
+
|
287
|
+
first
|
288
|
+
end
|
289
|
+
|
290
|
+
def self.to_token_user(ptoken_information)
|
291
|
+
TOKEN_USER.new(ptoken_information.to_ptr)
|
292
|
+
end
|
293
|
+
|
294
|
+
def self.to_struct_ptr(ptr)
|
295
|
+
ptr.to_ptr
|
296
|
+
end
|
297
|
+
|
298
|
+
def self.get_sid(user)
|
299
|
+
ptr_to_s(user.to_ptr.ptr, Win::SIZEOF_DWORD).unpack('L')[0]
|
300
|
+
end
|
301
|
+
|
302
|
+
def self.get_sid_ptr(user)
|
303
|
+
user.to_ptr.ptr
|
304
|
+
end
|
305
|
+
else
|
306
|
+
def self.get_sid(user)
|
307
|
+
user.SID
|
308
|
+
end
|
309
|
+
|
310
|
+
def self.ptr_to_handle(phandle)
|
311
|
+
phandle.ptr.to_i
|
312
|
+
end
|
313
|
+
|
314
|
+
def self.to_struct_ptr(ptr)
|
315
|
+
ptr
|
316
|
+
end
|
317
|
+
|
318
|
+
def self.ptr_to_dword(ptr)
|
319
|
+
ptr.to_s(Win::SIZEOF_DWORD).unpack('L')[0]
|
320
|
+
end
|
321
|
+
|
322
|
+
def self.to_token_user(ptoken_information)
|
323
|
+
TOKEN_USER.new(ptoken_information)
|
324
|
+
end
|
325
|
+
|
326
|
+
def self.get_sid_ptr(user)
|
327
|
+
user.SID
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
def self.get_current_user
|
332
|
+
token_handle = open_process_token(Win.GetCurrentProcess,
|
333
|
+
Win::TOKEN_QUERY)
|
334
|
+
token_user = get_token_information(token_handle,
|
335
|
+
Win::TOKEN_USER_INFORMATION_CLASS)
|
336
|
+
return token_user
|
337
|
+
end
|
338
|
+
|
339
|
+
def self.open_process_token(process_handle, desired_access)
|
340
|
+
ptoken_handle = malloc_ptr(Win::SIZEOF_DWORD)
|
341
|
+
|
342
|
+
raise_error_if_zero(
|
343
|
+
Win.OpenProcessToken(process_handle, desired_access,
|
344
|
+
ptoken_handle)
|
345
|
+
)
|
346
|
+
token_handle = ptr_to_handle(ptoken_handle)
|
347
|
+
return token_handle
|
348
|
+
end
|
349
|
+
|
350
|
+
def self.get_token_information(token_handle,
|
351
|
+
token_information_class)
|
352
|
+
# Hold the size of the information to be returned
|
353
|
+
preturn_length = malloc_ptr(Win::SIZEOF_DWORD)
|
354
|
+
|
355
|
+
# Going to throw an INSUFFICIENT_BUFFER_ERROR, but that is ok
|
356
|
+
# here. This is retrieving the size of the information to be
|
357
|
+
# returned.
|
358
|
+
Win.GetTokenInformation(token_handle,
|
359
|
+
token_information_class,
|
360
|
+
Win::NULL, 0, preturn_length)
|
361
|
+
ptoken_information = malloc_ptr(ptr_to_dword(preturn_length))
|
362
|
+
|
363
|
+
# This call is going to write the requested information to
|
364
|
+
# the memory location referenced by token_information.
|
365
|
+
raise_error_if_zero(
|
366
|
+
Win.GetTokenInformation(token_handle,
|
367
|
+
token_information_class,
|
368
|
+
ptoken_information,
|
369
|
+
ptoken_information.size,
|
370
|
+
preturn_length)
|
371
|
+
)
|
372
|
+
|
373
|
+
return to_token_user(ptoken_information)
|
374
|
+
end
|
375
|
+
|
376
|
+
def self.raise_error_if_zero(result)
|
377
|
+
if result == 0
|
378
|
+
raise "Windows error: #{Win.GetLastError}"
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
# Get a null-terminated string given a string.
|
383
|
+
def self.get_cstr(str)
|
384
|
+
return str + "\000"
|
385
|
+
end
|
306
386
|
end
|
307
387
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
388
|
+
# This is the pseudo-socket implementation that mimics the interface of
|
389
|
+
# a socket, translating each request into a Windows messaging call to
|
390
|
+
# the pageant daemon. This allows pageant support to be implemented
|
391
|
+
# simply by replacing the socket factory used by the Agent class.
|
392
|
+
class Socket
|
393
|
+
private_class_method :new
|
394
|
+
|
395
|
+
# The factory method for creating a new Socket instance.
|
396
|
+
def self.open
|
397
|
+
new
|
398
|
+
end
|
399
|
+
|
400
|
+
# Create a new instance that communicates with the running pageant
|
401
|
+
# instance. If no such instance is running, this will cause an error.
|
402
|
+
def initialize
|
403
|
+
@win = Win.FindWindow("Pageant", "Pageant")
|
404
|
+
|
405
|
+
if @win.to_i == 0
|
406
|
+
raise Net::SSH::Exception,
|
407
|
+
"pageant process not running"
|
408
|
+
end
|
409
|
+
|
410
|
+
@input_buffer = Net::SSH::Buffer.new
|
411
|
+
@output_buffer = Net::SSH::Buffer.new
|
412
|
+
end
|
413
|
+
|
414
|
+
# Forwards the data to #send_query, ignoring any arguments after
|
415
|
+
# the first.
|
416
|
+
def send(data, *args)
|
417
|
+
@input_buffer.append(data)
|
418
|
+
|
419
|
+
ret = data.length
|
420
|
+
|
421
|
+
while true
|
422
|
+
return ret if @input_buffer.length < 4
|
423
|
+
|
424
|
+
msg_length = @input_buffer.read_long + 4
|
425
|
+
@input_buffer.reset!
|
426
|
+
|
427
|
+
return ret if @input_buffer.length < msg_length
|
428
|
+
|
429
|
+
msg = @input_buffer.read!(msg_length)
|
430
|
+
@output_buffer.append(send_query(msg))
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
# Reads +n+ bytes from the cached result of the last query. If +n+
|
435
|
+
# is +nil+, returns all remaining data from the last query.
|
436
|
+
def read(n = nil)
|
437
|
+
@output_buffer.read(n)
|
438
|
+
end
|
439
|
+
|
440
|
+
def close; end
|
441
|
+
|
442
|
+
# Packages the given query string and sends it to the pageant
|
443
|
+
# process via the Windows messaging subsystem. The result is
|
444
|
+
# cached, to be returned piece-wise when #read is called.
|
445
|
+
def send_query(query)
|
446
|
+
res = nil
|
447
|
+
filemap = 0
|
448
|
+
ptr = nil
|
449
|
+
id = Win.malloc_ptr(Win::SIZEOF_DWORD)
|
450
|
+
|
451
|
+
mapname = "PageantRequest%08x" % Win.GetCurrentThreadId()
|
452
|
+
security_attributes = Win.get_ptr Win.get_security_attributes_for_user
|
453
|
+
|
454
|
+
filemap = Win.CreateFileMapping(Win::INVALID_HANDLE_VALUE,
|
455
|
+
security_attributes,
|
456
|
+
Win::PAGE_READWRITE, 0,
|
457
|
+
AGENT_MAX_MSGLEN, mapname)
|
458
|
+
|
459
|
+
if filemap == 0 || filemap == Win::INVALID_HANDLE_VALUE
|
460
|
+
raise Net::SSH::Exception,
|
461
|
+
"Creation of file mapping failed with error: #{Win.GetLastError}"
|
462
|
+
end
|
463
|
+
|
464
|
+
ptr = Win.MapViewOfFile(filemap, Win::FILE_MAP_WRITE, 0, 0,
|
465
|
+
0)
|
466
|
+
|
467
|
+
if ptr.nil? || ptr.null?
|
468
|
+
raise Net::SSH::Exception, "Mapping of file failed"
|
469
|
+
end
|
470
|
+
|
471
|
+
Win.set_ptr_data(ptr, query)
|
472
|
+
|
473
|
+
# using struct to achieve proper alignment and field size on 64-bit platform
|
474
|
+
cds = Win::COPYDATASTRUCT.new(Win.malloc_ptr(Win::COPYDATASTRUCT.size))
|
475
|
+
cds.dwData = AGENT_COPYDATA_ID
|
476
|
+
cds.cbData = mapname.size + 1
|
477
|
+
cds.lpData = Win.get_cstr(mapname)
|
478
|
+
succ = Win.SendMessageTimeout(@win, Win::WM_COPYDATA, Win::NULL,
|
479
|
+
cds.to_ptr, Win::SMTO_NORMAL, 5000, id)
|
480
|
+
|
481
|
+
if succ > 0
|
482
|
+
retlen = 4 + ptr.to_s(4).unpack("N")[0]
|
483
|
+
res = ptr.to_s(retlen)
|
484
|
+
else
|
485
|
+
raise Net::SSH::Exception, "Message failed with error: #{Win.GetLastError}"
|
486
|
+
end
|
487
|
+
|
488
|
+
return res
|
489
|
+
ensure
|
490
|
+
Win.UnmapViewOfFile(ptr) unless ptr.nil? || ptr.null?
|
491
|
+
Win.CloseHandle(filemap) if filemap != 0
|
492
|
+
end
|
327
493
|
end
|
328
494
|
end
|
329
|
-
|
330
|
-
# Reads +n+ bytes from the cached result of the last query. If +n+
|
331
|
-
# is +nil+, returns all remaining data from the last query.
|
332
|
-
def read(n = nil)
|
333
|
-
@output_buffer.read(n)
|
334
|
-
end
|
335
|
-
|
336
|
-
def close
|
337
|
-
end
|
338
|
-
|
339
|
-
# Packages the given query string and sends it to the pageant
|
340
|
-
# process via the Windows messaging subsystem. The result is
|
341
|
-
# cached, to be returned piece-wise when #read is called.
|
342
|
-
def send_query(query)
|
343
|
-
res = nil
|
344
|
-
filemap = 0
|
345
|
-
ptr = nil
|
346
|
-
id = Win.malloc_ptr(Win::SIZEOF_DWORD)
|
347
|
-
|
348
|
-
mapname = "PageantRequest%08x" % Win.GetCurrentThreadId()
|
349
|
-
security_attributes = Win.get_ptr Win.get_security_attributes_for_user
|
350
|
-
|
351
|
-
filemap = Win.CreateFileMapping(Win::INVALID_HANDLE_VALUE,
|
352
|
-
security_attributes,
|
353
|
-
Win::PAGE_READWRITE, 0,
|
354
|
-
AGENT_MAX_MSGLEN, mapname)
|
355
|
-
|
356
|
-
if filemap == 0 || filemap == Win::INVALID_HANDLE_VALUE
|
357
|
-
raise Net::SSH::Exception,
|
358
|
-
"Creation of file mapping failed with error: #{Win.GetLastError}"
|
359
|
-
end
|
360
|
-
|
361
|
-
ptr = Win.MapViewOfFile(filemap, Win::FILE_MAP_WRITE, 0, 0,
|
362
|
-
0)
|
363
|
-
|
364
|
-
if ptr.nil? || ptr.null?
|
365
|
-
raise Net::SSH::Exception, "Mapping of file failed"
|
366
|
-
end
|
367
|
-
|
368
|
-
Win.set_ptr_data(ptr, query)
|
369
|
-
|
370
|
-
# using struct to achieve proper alignment and field size on 64-bit platform
|
371
|
-
cds = Win::COPYDATASTRUCT.new(Win.malloc_ptr(Win::COPYDATASTRUCT.size))
|
372
|
-
cds.dwData = AGENT_COPYDATA_ID
|
373
|
-
cds.cbData = mapname.size + 1
|
374
|
-
cds.lpData = Win.get_cstr(mapname)
|
375
|
-
succ = Win.SendMessageTimeout(@win, Win::WM_COPYDATA, Win::NULL,
|
376
|
-
cds.to_ptr, Win::SMTO_NORMAL, 5000, id)
|
377
|
-
|
378
|
-
if succ > 0
|
379
|
-
retlen = 4 + ptr.to_s(4).unpack("N")[0]
|
380
|
-
res = ptr.to_s(retlen)
|
381
|
-
else
|
382
|
-
raise Net::SSH::Exception, "Message failed with error: #{Win.GetLastError}"
|
383
|
-
end
|
384
|
-
|
385
|
-
return res
|
386
|
-
ensure
|
387
|
-
Win.UnmapViewOfFile(ptr) unless ptr.nil? || ptr.null?
|
388
|
-
Win.CloseHandle(filemap) if filemap != 0
|
389
|
-
end
|
390
495
|
end
|
391
496
|
end
|
392
|
-
|
393
|
-
end; end; end
|
497
|
+
end
|