net-ssh 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/manual-html/chapter-1.html +2 -2
- data/doc/manual-html/chapter-2.html +6 -4
- data/doc/manual-html/chapter-3.html +2 -2
- data/doc/manual-html/chapter-4.html +2 -2
- data/doc/manual-html/chapter-5.html +2 -2
- data/doc/manual-html/chapter-6.html +2 -2
- data/doc/manual-html/index.html +2 -2
- data/doc/manual/parts/session_key.txt +4 -2
- data/examples/channel-demo.rb +81 -81
- data/lib/net/ssh.rb +15 -0
- data/lib/net/ssh/service/services.rb +12 -0
- data/lib/net/ssh/session.rb +5 -1
- data/lib/net/ssh/userauth/agent.rb +0 -7
- data/lib/net/ssh/userauth/pageant.rb +197 -0
- data/lib/net/ssh/userauth/services.rb +7 -2
- data/lib/net/ssh/util/openssl.rb +1 -1
- data/lib/net/ssh/version.rb +1 -1
- metadata +3 -3
- data/doc/README +0 -13
@@ -14,8 +14,8 @@
|
|
14
14
|
</div>
|
15
15
|
</td><td valign='middle' align='right'>
|
16
16
|
<div class="info">
|
17
|
-
Net::SSH Version: <strong>0.
|
18
|
-
Manual Last Updated: <strong>2004-
|
17
|
+
Net::SSH Version: <strong>0.6.0</strong><br />
|
18
|
+
Manual Last Updated: <strong>2004-12-02 05:13 GMT</strong>
|
19
19
|
</div>
|
20
20
|
</td></tr>
|
21
21
|
</table>
|
@@ -14,8 +14,8 @@
|
|
14
14
|
</div>
|
15
15
|
</td><td valign='middle' align='right'>
|
16
16
|
<div class="info">
|
17
|
-
Net::SSH Version: <strong>0.
|
18
|
-
Manual Last Updated: <strong>2004-
|
17
|
+
Net::SSH Version: <strong>0.6.0</strong><br />
|
18
|
+
Manual Last Updated: <strong>2004-12-02 05:13 GMT</strong>
|
19
19
|
</div>
|
20
20
|
</td></tr>
|
21
21
|
</table>
|
@@ -303,9 +303,11 @@
|
|
303
303
|
|
304
304
|
<p>The benefit of this is what is known as <em>single sign-on</em>. If any of your keys have a passphrase, this allows you to enter the passphrase <em>once</em> (when the key is loaded by the agent), and then any <span class="caps">SSH</span> program you use will never prompt you for that passphrase again.</p>
|
305
305
|
|
306
|
-
<p>Net::SSH includes support for interfacing with an <span class="caps">SSH</span> agent.
|
306
|
+
<p>Net::SSH includes support for interfacing with an <span class="caps">SSH</span> agent. This includes support for the <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/" title="pageant">PuTTY agent</a> on Windows systems.</p>
|
307
307
|
|
308
|
-
<p>
|
308
|
+
<p>On Unixish systems, you allow your Net::SSH programs to interface with a running agent by making sure that the <code>SSH_AGENT_SOCK</code> environment variable is set to the location of the Unix domain socket that the agent is listening to. Also, make sure you have added all of your keys to the agent (typically by running the <code>ssh-add</code> utility.</p>
|
309
|
+
|
310
|
+
<p>On Windows, the pageant process will be detected automatically, if it is running.</p>
|
309
311
|
|
310
312
|
<p>A future version of Net::SSH may include it’s own agent implementation as well, to make using an agent on a variety of platforms simpler.</p>
|
311
313
|
</div>
|
@@ -14,8 +14,8 @@
|
|
14
14
|
</div>
|
15
15
|
</td><td valign='middle' align='right'>
|
16
16
|
<div class="info">
|
17
|
-
Net::SSH Version: <strong>0.
|
18
|
-
Manual Last Updated: <strong>2004-
|
17
|
+
Net::SSH Version: <strong>0.6.0</strong><br />
|
18
|
+
Manual Last Updated: <strong>2004-12-02 05:13 GMT</strong>
|
19
19
|
</div>
|
20
20
|
</td></tr>
|
21
21
|
</table>
|
@@ -14,8 +14,8 @@
|
|
14
14
|
</div>
|
15
15
|
</td><td valign='middle' align='right'>
|
16
16
|
<div class="info">
|
17
|
-
Net::SSH Version: <strong>0.
|
18
|
-
Manual Last Updated: <strong>2004-
|
17
|
+
Net::SSH Version: <strong>0.6.0</strong><br />
|
18
|
+
Manual Last Updated: <strong>2004-12-02 05:13 GMT</strong>
|
19
19
|
</div>
|
20
20
|
</td></tr>
|
21
21
|
</table>
|
@@ -14,8 +14,8 @@
|
|
14
14
|
</div>
|
15
15
|
</td><td valign='middle' align='right'>
|
16
16
|
<div class="info">
|
17
|
-
Net::SSH Version: <strong>0.
|
18
|
-
Manual Last Updated: <strong>2004-
|
17
|
+
Net::SSH Version: <strong>0.6.0</strong><br />
|
18
|
+
Manual Last Updated: <strong>2004-12-02 05:13 GMT</strong>
|
19
19
|
</div>
|
20
20
|
</td></tr>
|
21
21
|
</table>
|
@@ -14,8 +14,8 @@
|
|
14
14
|
</div>
|
15
15
|
</td><td valign='middle' align='right'>
|
16
16
|
<div class="info">
|
17
|
-
Net::SSH Version: <strong>0.
|
18
|
-
Manual Last Updated: <strong>2004-
|
17
|
+
Net::SSH Version: <strong>0.6.0</strong><br />
|
18
|
+
Manual Last Updated: <strong>2004-12-02 05:13 GMT</strong>
|
19
19
|
</div>
|
20
20
|
</td></tr>
|
21
21
|
</table>
|
data/doc/manual-html/index.html
CHANGED
@@ -14,8 +14,8 @@
|
|
14
14
|
</div>
|
15
15
|
</td><td valign='middle' align='right'>
|
16
16
|
<div class="info">
|
17
|
-
Net::SSH Version: <strong>0.
|
18
|
-
Manual Last Updated: <strong>2004-
|
17
|
+
Net::SSH Version: <strong>0.6.0</strong><br />
|
18
|
+
Manual Last Updated: <strong>2004-12-02 05:13 GMT</strong>
|
19
19
|
</div>
|
20
20
|
</td></tr>
|
21
21
|
</table>
|
@@ -59,8 +59,10 @@ Most SSH clients come with what is called an _agent_. This is a program that is
|
|
59
59
|
|
60
60
|
The benefit of this is what is known as _single sign-on_. If any of your keys have a passphrase, this allows you to enter the passphrase _once_ (when the key is loaded by the agent), and then any SSH program you use will never prompt you for that passphrase again.
|
61
61
|
|
62
|
-
Net::SSH includes support for interfacing with an SSH agent.
|
62
|
+
Net::SSH includes support for interfacing with an SSH agent. This includes support for the "PuTTY agent (pageant)":http://www.chiark.greenend.org.uk/~sgtatham/putty/ on Windows systems.
|
63
63
|
|
64
|
-
|
64
|
+
On Unixish systems, you allow your Net::SSH programs to interface with a running agent by making sure that the @SSH_AGENT_SOCK@ environment variable is set to the location of the Unix domain socket that the agent is listening to. Also, make sure you have added all of your keys to the agent (typically by running the @ssh-add@ utility.
|
65
|
+
|
66
|
+
On Windows, the pageant process will be detected automatically, if it is running.
|
65
67
|
|
66
68
|
A future version of Net::SSH may include it's own agent implementation as well, to make using an agent on a variety of platforms simpler.
|
data/examples/channel-demo.rb
CHANGED
@@ -1,81 +1,81 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SSH
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-ssh website : http://net-ssh.rubyforge.org
|
13
|
-
# project website: http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../lib"
|
18
|
-
require 'net/ssh'
|
19
|
-
|
20
|
-
# This assumes three things:
|
21
|
-
#
|
22
|
-
# 1) That you have an SSH server running on your local machine,
|
23
|
-
# 2) That the USER environment variable is set to your user name, and
|
24
|
-
# 3) That you have public and private keys conigured so that you can log into
|
25
|
-
# your machine via SSH without being prompted for a password.
|
26
|
-
#
|
27
|
-
# If #2 or #3 are not true, you can add your user-name and password as the
|
28
|
-
# second and third parameters (respectively) to Net::SSH.start.
|
29
|
-
|
30
|
-
Net::SSH.start( 'localhost' ) do |session|
|
31
|
-
|
32
|
-
# Note: two things here,
|
33
|
-
#
|
34
|
-
# 1) open_channel does not immediately invoke the associated block. It only
|
35
|
-
# calls the block after the server has confirmed that the channel is valid.
|
36
|
-
# 2) channel.exec does not block--it just sends the request to the server and
|
37
|
-
# returns.
|
38
|
-
#
|
39
|
-
# For these two reasons, you MUST call session.loop, so that packets get
|
40
|
-
# processed and dispatched to the appropriate channel for handling.
|
41
|
-
|
42
|
-
def exec( command )
|
43
|
-
lambda do |channel|
|
44
|
-
channel.exec command
|
45
|
-
channel.on_data do |ch,data|
|
46
|
-
ch[:data] ||= ""
|
47
|
-
ch[:data] << data
|
48
|
-
end
|
49
|
-
channel.on_extended_data do |ch,type,data|
|
50
|
-
ch[:extended_data] ||= []
|
51
|
-
ch[:extended_data][type] ||= ""
|
52
|
-
ch[:extended_data][type] << data
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
channels = []
|
58
|
-
channels.push session.open_channel( &exec( "echo $HOME" ) )
|
59
|
-
channels.push session.open_channel( &exec( "ls -la /" ) )
|
60
|
-
channels.push session.open_channel( &exec( "bogus-command" ) )
|
61
|
-
|
62
|
-
# Process packets from the server and route them to the appropriate channel
|
63
|
-
# for handling.
|
64
|
-
|
65
|
-
session.loop
|
66
|
-
|
67
|
-
# Display the results.
|
68
|
-
|
69
|
-
channels.each do |c|
|
70
|
-
puts "----------------------------------"
|
71
|
-
if c.valid?
|
72
|
-
puts c[:data]
|
73
|
-
if c[:extended_data] && c[:extended_data][1]
|
74
|
-
puts "-- stderr: --"
|
75
|
-
puts c[:extended_data][1]
|
76
|
-
end
|
77
|
-
else
|
78
|
-
puts "channel was not opened: #{c.reason} (#{c.reason_code})"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
7
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SSH
|
10
|
+
# distribution for the texts of these licenses.
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
# net-ssh website : http://net-ssh.rubyforge.org
|
13
|
+
# project website: http://rubyforge.org/projects/net-ssh
|
14
|
+
# =============================================================================
|
15
|
+
#++
|
16
|
+
|
17
|
+
$:.unshift "../lib"
|
18
|
+
require 'net/ssh'
|
19
|
+
|
20
|
+
# This assumes three things:
|
21
|
+
#
|
22
|
+
# 1) That you have an SSH server running on your local machine,
|
23
|
+
# 2) That the USER environment variable is set to your user name, and
|
24
|
+
# 3) That you have public and private keys conigured so that you can log into
|
25
|
+
# your machine via SSH without being prompted for a password.
|
26
|
+
#
|
27
|
+
# If #2 or #3 are not true, you can add your user-name and password as the
|
28
|
+
# second and third parameters (respectively) to Net::SSH.start.
|
29
|
+
|
30
|
+
Net::SSH.start( 'localhost' ) do |session|
|
31
|
+
|
32
|
+
# Note: two things here,
|
33
|
+
#
|
34
|
+
# 1) open_channel does not immediately invoke the associated block. It only
|
35
|
+
# calls the block after the server has confirmed that the channel is valid.
|
36
|
+
# 2) channel.exec does not block--it just sends the request to the server and
|
37
|
+
# returns.
|
38
|
+
#
|
39
|
+
# For these two reasons, you MUST call session.loop, so that packets get
|
40
|
+
# processed and dispatched to the appropriate channel for handling.
|
41
|
+
|
42
|
+
def exec( command )
|
43
|
+
lambda do |channel|
|
44
|
+
channel.exec command
|
45
|
+
channel.on_data do |ch,data|
|
46
|
+
ch[:data] ||= ""
|
47
|
+
ch[:data] << data
|
48
|
+
end
|
49
|
+
channel.on_extended_data do |ch,type,data|
|
50
|
+
ch[:extended_data] ||= []
|
51
|
+
ch[:extended_data][type] ||= ""
|
52
|
+
ch[:extended_data][type] << data
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
channels = []
|
58
|
+
channels.push session.open_channel( &exec( "echo $HOME" ) )
|
59
|
+
channels.push session.open_channel( &exec( "ls -la /" ) )
|
60
|
+
channels.push session.open_channel( &exec( "bogus-command" ) )
|
61
|
+
|
62
|
+
# Process packets from the server and route them to the appropriate channel
|
63
|
+
# for handling.
|
64
|
+
|
65
|
+
session.loop
|
66
|
+
|
67
|
+
# Display the results.
|
68
|
+
|
69
|
+
channels.each do |c|
|
70
|
+
puts "----------------------------------"
|
71
|
+
if c.valid?
|
72
|
+
puts c[:data]
|
73
|
+
if c[:extended_data] && c[:extended_data][1]
|
74
|
+
puts "-- stderr: --"
|
75
|
+
puts c[:extended_data][1]
|
76
|
+
end
|
77
|
+
else
|
78
|
+
puts "channel was not opened: #{c.reason} (#{c.reason_code})"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/net/ssh.rb
CHANGED
@@ -48,5 +48,20 @@ module Net
|
|
48
48
|
end
|
49
49
|
module_function :start
|
50
50
|
|
51
|
+
# A registry of external (i.e., third-party) services that should be made
|
52
|
+
# available to any SSH session.
|
53
|
+
EXTERNAL_SERVICES = Hash.new
|
54
|
+
|
55
|
+
# Used by third-parties to register a service that should be made available
|
56
|
+
# to any SSH session when the session is constructed. The block should take
|
57
|
+
# a two parameters--the dependency injection container that should contain
|
58
|
+
# the services, and the service-point for the service being registered.
|
59
|
+
#
|
60
|
+
# The +name+ parameter should be a symbol.
|
61
|
+
def register_service( name, &block )
|
62
|
+
EXTERNAL_SERVICES[ name ] = block
|
63
|
+
end
|
64
|
+
module_function :register_service
|
65
|
+
|
51
66
|
end
|
52
67
|
end
|
@@ -14,6 +14,8 @@
|
|
14
14
|
# =============================================================================
|
15
15
|
#++
|
16
16
|
|
17
|
+
require 'net/ssh'
|
18
|
+
|
17
19
|
module Net
|
18
20
|
module SSH
|
19
21
|
module Service
|
@@ -36,6 +38,16 @@ module Net
|
|
36
38
|
# Add the services to the services hash.
|
37
39
|
container.services[ :forward ] = container.service.forward.driver
|
38
40
|
container.services[ :process ] = container.service.process.driver
|
41
|
+
|
42
|
+
# Register the external services and add them to the collection of
|
43
|
+
# known services.
|
44
|
+
EXTERNAL_SERVICES.each do |name, block|
|
45
|
+
container.service.register( name,
|
46
|
+
:model => :singleton_deferred,
|
47
|
+
&block )
|
48
|
+
container.services[ name ] = container.service[ name ]
|
49
|
+
end
|
50
|
+
|
39
51
|
end
|
40
52
|
module_function :register_services
|
41
53
|
|
data/lib/net/ssh/session.rb
CHANGED
@@ -94,6 +94,10 @@ module Net
|
|
94
94
|
b.userauth_host_keys { @host_keys }
|
95
95
|
b.userauth_method_order { @auth_methods }
|
96
96
|
|
97
|
+
# Register myself with the registry, so that other services may
|
98
|
+
# access me.
|
99
|
+
b.session( :pipeline => [] ) { self }
|
100
|
+
|
97
101
|
b.prompter do
|
98
102
|
require 'net/ssh/util/prompter'
|
99
103
|
Net::SSH::Util::Prompter.new
|
@@ -169,7 +173,7 @@ module Net
|
|
169
173
|
# and allowing polymorphic argument lists. (See #initialize).
|
170
174
|
def process_arguments( *args )
|
171
175
|
@options = {}
|
172
|
-
@username = ENV['USER']
|
176
|
+
@username = ENV['USER'] || ENV['USERNAME']
|
173
177
|
|
174
178
|
raise ArgumentError,
|
175
179
|
"you must specify the host to connect to" if args.length < 1
|
@@ -30,13 +30,6 @@ module Net
|
|
30
30
|
#
|
31
31
|
# This means that although it behaves like a SSH1 client, it also has
|
32
32
|
# some SSH2 functionality (like signing data).
|
33
|
-
#
|
34
|
-
# Also, this class relies on there being a UNIXSocket that the active
|
35
|
-
# ssh-agent is listening on. It expects that socket to exist at the
|
36
|
-
# location described by the SSH_AUTH_SOCK environment variable. Because
|
37
|
-
# of the dependency on UNIXSocket, the agent is not available under
|
38
|
-
# Windows, and I have no immediate plans to implement support for
|
39
|
-
# PuTTy's "pageant" utility.
|
40
33
|
class Agent
|
41
34
|
SSH2_AGENT_REQUEST_VERSION = 1
|
42
35
|
SSH2_AGENT_REQUEST_IDENTITIES = 11
|
@@ -0,0 +1,197 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Guillaume Mar�ais (guillaume.marcais@free.fr),
|
4
|
+
# Jamis Buck (jgb3@email.byu.edu)
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
8
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
9
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
10
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SSH
|
11
|
+
# distribution for the texts of these licenses.
|
12
|
+
# -----------------------------------------------------------------------------
|
13
|
+
# net-ssh website : http://net-ssh.rubyforge.org
|
14
|
+
# project website: http://rubyforge.org/projects/net-ssh
|
15
|
+
# =============================================================================
|
16
|
+
#++
|
17
|
+
|
18
|
+
require 'dl/import'
|
19
|
+
require 'dl/struct'
|
20
|
+
|
21
|
+
require 'net/ssh/errors'
|
22
|
+
|
23
|
+
module Net
|
24
|
+
module SSH
|
25
|
+
module UserAuth
|
26
|
+
|
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
|
+
|
36
|
+
# From Putty pageant.c
|
37
|
+
AGENT_MAX_MSGLEN = 8192
|
38
|
+
AGENT_COPYDATA_ID = 0x804e50ba
|
39
|
+
|
40
|
+
# The definition of the Windows methods and data structures used in
|
41
|
+
# communicating with the pageant process.
|
42
|
+
module Win
|
43
|
+
extend DL::Importable
|
44
|
+
|
45
|
+
dlload 'user32'
|
46
|
+
dlload 'kernel32'
|
47
|
+
|
48
|
+
typealias("LPCTSTR", "char *") # From winnt.h
|
49
|
+
typealias("LPVOID", "void *") # From winnt.h
|
50
|
+
typealias("LPCVOID", "const void *") # From windef.h
|
51
|
+
typealias("LRESULT", "long") # From windef.h
|
52
|
+
typealias("WPARAM", "unsigned int *") # From windef.h
|
53
|
+
typealias("LPARAM", "long *") # From windef.h
|
54
|
+
typealias("PDWORD_PTR", "long *") # From basetsd.h
|
55
|
+
|
56
|
+
# From winbase.h, winnt.h
|
57
|
+
INVALID_HANDLE_VALUE = -1
|
58
|
+
NULL = nil
|
59
|
+
PAGE_READWRITE = 0x0004
|
60
|
+
FILE_MAP_WRITE = 2
|
61
|
+
WM_COPYDATA = 74
|
62
|
+
|
63
|
+
SMTO_NORMAL = 0 # From winuser.h
|
64
|
+
|
65
|
+
# args: lpClassName, lpWindowName
|
66
|
+
extern 'HWND FindWindow(LPCTSTR, LPCTSTR)'
|
67
|
+
|
68
|
+
# args: none
|
69
|
+
extern 'DWORD GetCurrentThreadId()'
|
70
|
+
|
71
|
+
# args: hFile, (ignored), flProtect, dwMaximumSizeHigh,
|
72
|
+
# dwMaximumSizeLow, lpName
|
73
|
+
extern 'HANDLE CreateFileMapping(HANDLE, void *, DWORD, DWORD, ' +
|
74
|
+
'DWORD, LPCTSTR)'
|
75
|
+
|
76
|
+
# args: hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh,
|
77
|
+
# dwfileOffsetLow, dwNumberOfBytesToMap
|
78
|
+
extern 'LPVOID MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, DWORD)'
|
79
|
+
|
80
|
+
# args: lpBaseAddress
|
81
|
+
extern 'BOOL UnmapViewOfFile(LPCVOID)'
|
82
|
+
|
83
|
+
# args: hObject
|
84
|
+
extern 'BOOL CloseHandle(HANDLE)'
|
85
|
+
|
86
|
+
# args: hWnd, Msg, wParam, lParam, fuFlags, uTimeout, lpdwResult
|
87
|
+
extern 'LRESULT SendMessageTimeout(HWND, UINT, WPARAM, LPARAM, ' +
|
88
|
+
'UINT, UINT, PDWORD_PTR)'
|
89
|
+
end
|
90
|
+
|
91
|
+
# This is the pseudo-socket implementation that mimics the interface of
|
92
|
+
# a socket, translating each request into a Windows messaging call to
|
93
|
+
# the pageant daemon. This allows pageant support to be implemented
|
94
|
+
# simply by replacing the socket factory used by the Agent class.
|
95
|
+
class Socket
|
96
|
+
|
97
|
+
private_class_method :new
|
98
|
+
|
99
|
+
# The factory method for creating a new Socket instance. The location
|
100
|
+
# parameter is ignored, and is only needed for compatibility with
|
101
|
+
# the general Socket interface.
|
102
|
+
def self.open( location=nil )
|
103
|
+
new
|
104
|
+
end
|
105
|
+
|
106
|
+
# Create a new instance that communicates with the running pageant
|
107
|
+
# instance. If no such instance is running, this will cause an error.
|
108
|
+
def initialize
|
109
|
+
@win = Win.findWindow( "Pageant", "Pageant" )
|
110
|
+
|
111
|
+
if @win == 0
|
112
|
+
raise Net::SSH::Exception,
|
113
|
+
"pageant process not running"
|
114
|
+
end
|
115
|
+
|
116
|
+
@res = nil
|
117
|
+
@pos = 0
|
118
|
+
end
|
119
|
+
|
120
|
+
# Forwards the data to #send_query, ignoring any arguments after
|
121
|
+
# the first. Returns 0.
|
122
|
+
def send( data, *args )
|
123
|
+
@res = send_query( data )
|
124
|
+
@pos = 0
|
125
|
+
end
|
126
|
+
|
127
|
+
# Packages the given query string and sends it to the pageant
|
128
|
+
# process via the Windows messaging subsystem. The result is
|
129
|
+
# cached, to be returned piece-wise when #read is called.
|
130
|
+
def send_query( query )
|
131
|
+
res = nil
|
132
|
+
filemap = 0
|
133
|
+
ptr = nil
|
134
|
+
id = DL::PtrData.malloc( DL.sizeof("L") )
|
135
|
+
|
136
|
+
mapname = "PageantRequest%08x\000" % Win.getCurrentThreadId()
|
137
|
+
filemap = Win.createFileMapping(Win::INVALID_HANDLE_VALUE,
|
138
|
+
Win::NULL,
|
139
|
+
Win::PAGE_READWRITE, 0,
|
140
|
+
AGENT_MAX_MSGLEN, mapname)
|
141
|
+
if filemap == 0
|
142
|
+
raise Net::SSH::Exception,
|
143
|
+
"Creation of file mapping failed"
|
144
|
+
end
|
145
|
+
|
146
|
+
ptr = Win.mapViewOfFile( filemap, Win::FILE_MAP_WRITE, 0, 0,
|
147
|
+
AGENT_MAX_MSGLEN )
|
148
|
+
|
149
|
+
if ptr.nil? || ptr.null?
|
150
|
+
raise Net::SSH::Exception, "Mapping of file failed"
|
151
|
+
end
|
152
|
+
|
153
|
+
ptr[0] = query
|
154
|
+
|
155
|
+
cds = [AGENT_COPYDATA_ID, mapname.size + 1, mapname].
|
156
|
+
pack("LLp").to_ptr
|
157
|
+
succ = Win.sendMessageTimeout( @win, Win::WM_COPYDATA, Win::NULL,
|
158
|
+
cds, Win::SMTO_NORMAL, 5000, id )
|
159
|
+
|
160
|
+
if succ > 0
|
161
|
+
retlen = 4 + ptr.to_s(4).unpack("N")[0]
|
162
|
+
res = ptr.to_s(retlen)
|
163
|
+
end
|
164
|
+
|
165
|
+
return res
|
166
|
+
ensure
|
167
|
+
Win.unmapViewOfFile( ptr ) unless ptr.nil? || ptr.null?
|
168
|
+
Win.closeHandle( filemap ) if filemap != 0
|
169
|
+
end
|
170
|
+
|
171
|
+
# Conceptually close the socket. This doesn't really do anthing
|
172
|
+
# significant, but merely complies with the Socket interface.
|
173
|
+
def close
|
174
|
+
@res = nil
|
175
|
+
@pos = 0
|
176
|
+
end
|
177
|
+
|
178
|
+
# Reads +n+ bytes from the cached result of the last query. If +n+
|
179
|
+
# is +nil+, returns all remaining data from the last query.
|
180
|
+
def read(n = nil)
|
181
|
+
return nil unless @res
|
182
|
+
if n.nil?
|
183
|
+
start, @pos = @pos, @res.size
|
184
|
+
return @res[start..-1]
|
185
|
+
else
|
186
|
+
start, @pos = @pos, @pos + n
|
187
|
+
return @res[start, n]
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
@@ -24,8 +24,13 @@ module Net
|
|
24
24
|
b.require 'net/ssh/userauth/methods/services', "#{self}::Methods"
|
25
25
|
|
26
26
|
b.agent_socket_factory do
|
27
|
-
|
28
|
-
|
27
|
+
if File::ALT_SEPARATOR
|
28
|
+
require 'net/ssh/userauth/pageant'
|
29
|
+
Pageant::Socket
|
30
|
+
else
|
31
|
+
require 'socket'
|
32
|
+
defined?( UNIXSocket ) ? UNIXSocket : nil
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
b.default_agent_socket_name { ENV['SSH_AUTH_SOCK'] }
|
data/lib/net/ssh/util/openssl.rb
CHANGED
@@ -122,7 +122,7 @@ module OpenSSL
|
|
122
122
|
return verify(OpenSSL::Digest::DSS1.new, a1sig.to_der, data)
|
123
123
|
end
|
124
124
|
|
125
|
-
#
|
125
|
+
# Signs the given data.
|
126
126
|
def ssh_do_sign( data )
|
127
127
|
sig = sign( OpenSSL::Digest::DSS1.new, data)
|
128
128
|
a1sig = OpenSSL::ASN1.decode( sig )
|
data/lib/net/ssh/version.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: net-ssh
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2004-
|
6
|
+
version: 0.6.0
|
7
|
+
date: 2004-12-01
|
8
8
|
summary: Net::SSH is a pure-Ruby implementation of the SSH2 client protocol.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -26,7 +26,6 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
26
26
|
version:
|
27
27
|
platform: ruby
|
28
28
|
files:
|
29
|
-
- doc/README
|
30
29
|
- doc/LICENSE-RUBY
|
31
30
|
- doc/manual-html
|
32
31
|
- doc/LICENSE-BSD
|
@@ -150,6 +149,7 @@ files:
|
|
150
149
|
- lib/net/ssh/userauth/agent.rb
|
151
150
|
- lib/net/ssh/userauth/driver.rb
|
152
151
|
- lib/net/ssh/userauth/userkeys.rb
|
152
|
+
- lib/net/ssh/userauth/pageant.rb
|
153
153
|
- lib/net/ssh/userauth/methods
|
154
154
|
- lib/net/ssh/userauth/constants.rb
|
155
155
|
- lib/net/ssh/userauth/services.rb
|
data/doc/README
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
= Net::SSH
|
2
|
-
|
3
|
-
<b><em>A pure Ruby module that emulates an SSH client.</em></b>
|
4
|
-
|
5
|
-
<em>Author: Jamis Buck (jgb3@email.byu.edu)</em>
|
6
|
-
|
7
|
-
This is an alpha release of Net::SSH. It absolutely WILL NOT work with the version of Ruby's OpenSSL module currently shipped with Ruby versions < 1.8.2. You must get a patched version of the OpenSSL module and install it (and remove the old module) before using Net::SSH.
|
8
|
-
|
9
|
-
The current release of Net::SSH supports:
|
10
|
-
|
11
|
-
* the execution of processes on the remote host (interactively, or non-interactively)
|
12
|
-
* port forwarding, both from a local port to a remote port, and vice versa
|
13
|
-
* HTTP and SOCKS proxy support (and support for creation of additional proxy types)
|