net-ssh 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/LICENSE-BSD +27 -0
- data/doc/LICENSE-GPL +280 -0
- data/doc/LICENSE-RUBY +56 -0
- data/doc/README +13 -0
- data/doc/manual-html/chapter-1.html +333 -0
- data/doc/manual-html/chapter-2.html +455 -0
- data/doc/manual-html/chapter-3.html +413 -0
- data/doc/manual-html/chapter-4.html +353 -0
- data/doc/manual-html/chapter-5.html +393 -0
- data/doc/manual-html/chapter-6.html +296 -0
- data/doc/manual-html/index.html +217 -0
- data/doc/manual-html/manual.css +192 -0
- data/doc/manual/chapter.erb +18 -0
- data/doc/manual/example.erb +18 -0
- data/doc/manual/index.erb +29 -0
- data/doc/manual/manual.css +192 -0
- data/doc/manual/manual.rb +240 -0
- data/doc/manual/manual.yml +67 -0
- data/doc/manual/page.erb +87 -0
- data/doc/manual/parts/channels_callbacks.txt +32 -0
- data/doc/manual/parts/channels_loop.txt +14 -0
- data/doc/manual/parts/channels_open.txt +20 -0
- data/doc/manual/parts/channels_operations.txt +15 -0
- data/doc/manual/parts/channels_types.txt +3 -0
- data/doc/manual/parts/channels_what_are.txt +7 -0
- data/doc/manual/parts/exec_channels.txt +28 -0
- data/doc/manual/parts/exec_open.txt +51 -0
- data/doc/manual/parts/exec_popen3.txt +35 -0
- data/doc/manual/parts/forward_direct.txt +37 -0
- data/doc/manual/parts/forward_handlers.txt +16 -0
- data/doc/manual/parts/forward_intro.txt +18 -0
- data/doc/manual/parts/forward_local.txt +18 -0
- data/doc/manual/parts/forward_remote.txt +14 -0
- data/doc/manual/parts/intro_author.txt +1 -0
- data/doc/manual/parts/intro_getting.txt +39 -0
- data/doc/manual/parts/intro_license.txt +6 -0
- data/doc/manual/parts/intro_support.txt +7 -0
- data/doc/manual/parts/intro_what_is.txt +7 -0
- data/doc/manual/parts/intro_what_is_not.txt +3 -0
- data/doc/manual/parts/proxy_http.txt +52 -0
- data/doc/manual/parts/proxy_intro.txt +1 -0
- data/doc/manual/parts/proxy_socks.txt +23 -0
- data/doc/manual/parts/session_key.txt +66 -0
- data/doc/manual/parts/session_options.txt +42 -0
- data/doc/manual/parts/session_session.txt +14 -0
- data/doc/manual/parts/session_start.txt +49 -0
- data/doc/manual/tutorial.erb +30 -0
- data/examples/channel-demo.rb +81 -0
- data/examples/port-forward.rb +51 -0
- data/examples/process-demo.rb +91 -0
- data/examples/remote-net-port-forward.rb +45 -0
- data/examples/remote-port-forward.rb +80 -0
- data/examples/tail-demo.rb +49 -0
- data/lib/net/ssh.rb +52 -0
- data/lib/net/ssh/connection/channel.rb +411 -0
- data/lib/net/ssh/connection/constants.rb +47 -0
- data/lib/net/ssh/connection/driver.rb +343 -0
- data/lib/net/ssh/connection/services.rb +72 -0
- data/lib/net/ssh/connection/term.rb +90 -0
- data/lib/net/ssh/errors.rb +27 -0
- data/lib/net/ssh/proxy/errors.rb +34 -0
- data/lib/net/ssh/proxy/http.rb +126 -0
- data/lib/net/ssh/proxy/socks4.rb +83 -0
- data/lib/net/ssh/proxy/socks5.rb +160 -0
- data/lib/net/ssh/service/forward/driver.rb +319 -0
- data/lib/net/ssh/service/forward/local-network-handler.rb +74 -0
- data/lib/net/ssh/service/forward/remote-network-handler.rb +81 -0
- data/lib/net/ssh/service/forward/services.rb +76 -0
- data/lib/net/ssh/service/process/driver.rb +153 -0
- data/lib/net/ssh/service/process/open.rb +193 -0
- data/lib/net/ssh/service/process/popen3.rb +160 -0
- data/lib/net/ssh/service/process/services.rb +66 -0
- data/lib/net/ssh/service/services.rb +44 -0
- data/lib/net/ssh/session.rb +242 -0
- data/lib/net/ssh/transport/algorithm-negotiator.rb +267 -0
- data/lib/net/ssh/transport/compress/compressor.rb +53 -0
- data/lib/net/ssh/transport/compress/decompressor.rb +53 -0
- data/lib/net/ssh/transport/compress/none-compressor.rb +39 -0
- data/lib/net/ssh/transport/compress/none-decompressor.rb +39 -0
- data/lib/net/ssh/transport/compress/services.rb +68 -0
- data/lib/net/ssh/transport/compress/zlib-compressor.rb +60 -0
- data/lib/net/ssh/transport/compress/zlib-decompressor.rb +52 -0
- data/lib/net/ssh/transport/constants.rb +66 -0
- data/lib/net/ssh/transport/errors.rb +47 -0
- data/lib/net/ssh/transport/identity-cipher.rb +61 -0
- data/lib/net/ssh/transport/kex/dh-gex.rb +106 -0
- data/lib/net/ssh/transport/kex/dh.rb +231 -0
- data/lib/net/ssh/transport/kex/services.rb +60 -0
- data/lib/net/ssh/transport/ossl/buffer-factory.rb +52 -0
- data/lib/net/ssh/transport/ossl/buffer.rb +87 -0
- data/lib/net/ssh/transport/ossl/cipher-factory.rb +98 -0
- data/lib/net/ssh/transport/ossl/digest-factory.rb +51 -0
- data/lib/net/ssh/transport/ossl/hmac-factory.rb +71 -0
- data/lib/net/ssh/transport/ossl/hmac/hmac.rb +62 -0
- data/lib/net/ssh/transport/ossl/hmac/md5-96.rb +44 -0
- data/lib/net/ssh/transport/ossl/hmac/md5.rb +46 -0
- data/lib/net/ssh/transport/ossl/hmac/none.rb +46 -0
- data/lib/net/ssh/transport/ossl/hmac/services.rb +68 -0
- data/lib/net/ssh/transport/ossl/hmac/sha1-96.rb +44 -0
- data/lib/net/ssh/transport/ossl/hmac/sha1.rb +45 -0
- data/lib/net/ssh/transport/ossl/key-factory.rb +113 -0
- data/lib/net/ssh/transport/ossl/services.rb +149 -0
- data/lib/net/ssh/transport/packet-stream.rb +210 -0
- data/lib/net/ssh/transport/services.rb +146 -0
- data/lib/net/ssh/transport/session.rb +296 -0
- data/lib/net/ssh/transport/version-negotiator.rb +73 -0
- data/lib/net/ssh/userauth/agent.rb +218 -0
- data/lib/net/ssh/userauth/constants.rb +35 -0
- data/lib/net/ssh/userauth/driver.rb +176 -0
- data/lib/net/ssh/userauth/methods/hostbased.rb +119 -0
- data/lib/net/ssh/userauth/methods/password.rb +70 -0
- data/lib/net/ssh/userauth/methods/publickey.rb +137 -0
- data/lib/net/ssh/userauth/methods/services.rb +63 -0
- data/lib/net/ssh/userauth/services.rb +126 -0
- data/lib/net/ssh/userauth/userkeys.rb +258 -0
- data/lib/net/ssh/util/buffer.rb +274 -0
- data/lib/net/ssh/util/openssl.rb +146 -0
- data/lib/net/ssh/util/prompter.rb +73 -0
- data/lib/net/ssh/version.rb +29 -0
- data/test/ALL-TESTS.rb +21 -0
- data/test/connection/tc_channel.rb +136 -0
- data/test/connection/tc_driver.rb +287 -0
- data/test/connection/tc_integration.rb +85 -0
- data/test/proxy/tc_http.rb +209 -0
- data/test/proxy/tc_socks4.rb +148 -0
- data/test/proxy/tc_socks5.rb +214 -0
- data/test/service/forward/tc_driver.rb +289 -0
- data/test/service/forward/tc_local_network_handler.rb +123 -0
- data/test/service/forward/tc_remote_network_handler.rb +108 -0
- data/test/service/process/tc_driver.rb +79 -0
- data/test/service/process/tc_integration.rb +117 -0
- data/test/service/process/tc_open.rb +179 -0
- data/test/service/process/tc_popen3.rb +164 -0
- data/test/tc_integration.rb +79 -0
- data/test/transport/compress/tc_none_compress.rb +41 -0
- data/test/transport/compress/tc_none_decompress.rb +45 -0
- data/test/transport/compress/tc_zlib_compress.rb +61 -0
- data/test/transport/compress/tc_zlib_decompress.rb +48 -0
- data/test/transport/kex/tc_dh.rb +304 -0
- data/test/transport/kex/tc_dh_gex.rb +70 -0
- data/test/transport/ossl/fixtures/dsa-encrypted +15 -0
- data/test/transport/ossl/fixtures/dsa-encrypted-bad +15 -0
- data/test/transport/ossl/fixtures/dsa-unencrypted +12 -0
- data/test/transport/ossl/fixtures/dsa-unencrypted-bad +12 -0
- data/test/transport/ossl/fixtures/dsa-unencrypted.pub +1 -0
- data/test/transport/ossl/fixtures/not-a-private-key +4 -0
- data/test/transport/ossl/fixtures/not-supported +2 -0
- data/test/transport/ossl/fixtures/rsa-encrypted +18 -0
- data/test/transport/ossl/fixtures/rsa-encrypted-bad +18 -0
- data/test/transport/ossl/fixtures/rsa-unencrypted +15 -0
- data/test/transport/ossl/fixtures/rsa-unencrypted-bad +15 -0
- data/test/transport/ossl/fixtures/rsa-unencrypted.pub +1 -0
- data/test/transport/ossl/hmac/tc_hmac.rb +58 -0
- data/test/transport/ossl/hmac/tc_md5.rb +50 -0
- data/test/transport/ossl/hmac/tc_md5_96.rb +50 -0
- data/test/transport/ossl/hmac/tc_none.rb +50 -0
- data/test/transport/ossl/hmac/tc_sha1.rb +50 -0
- data/test/transport/ossl/hmac/tc_sha1_96.rb +50 -0
- data/test/transport/ossl/tc_buffer.rb +97 -0
- data/test/transport/ossl/tc_buffer_factory.rb +67 -0
- data/test/transport/ossl/tc_cipher_factory.rb +84 -0
- data/test/transport/ossl/tc_digest_factory.rb +39 -0
- data/test/transport/ossl/tc_hmac_factory.rb +72 -0
- data/test/transport/ossl/tc_key_factory.rb +199 -0
- data/test/transport/tc_algorithm_negotiator.rb +169 -0
- data/test/transport/tc_identity_cipher.rb +52 -0
- data/test/transport/tc_integration.rb +110 -0
- data/test/transport/tc_packet_stream.rb +183 -0
- data/test/transport/tc_session.rb +283 -0
- data/test/transport/tc_version_negotiator.rb +86 -0
- data/test/userauth/methods/tc_hostbased.rb +136 -0
- data/test/userauth/methods/tc_password.rb +89 -0
- data/test/userauth/methods/tc_publickey.rb +167 -0
- data/test/userauth/tc_agent.rb +223 -0
- data/test/userauth/tc_driver.rb +190 -0
- data/test/userauth/tc_integration.rb +81 -0
- data/test/userauth/tc_userkeys.rb +265 -0
- data/test/util/tc_buffer.rb +217 -0
- metadata +256 -0
@@ -0,0 +1,119 @@
|
|
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
|
+
require 'net/ssh/errors'
|
18
|
+
require 'net/ssh/userauth/constants'
|
19
|
+
|
20
|
+
module Net
|
21
|
+
module SSH
|
22
|
+
module UserAuth
|
23
|
+
module Methods
|
24
|
+
|
25
|
+
# Implements the host-based SSH authentication method.
|
26
|
+
class HostBased
|
27
|
+
include Net::SSH::UserAuth::Constants
|
28
|
+
|
29
|
+
# The messenger to use to send and receive messages.
|
30
|
+
attr_writer :messenger
|
31
|
+
|
32
|
+
# The session-id of the current SSH session.
|
33
|
+
attr_writer :session_id
|
34
|
+
|
35
|
+
# The hostname to report to the server.
|
36
|
+
attr_writer :hostname
|
37
|
+
|
38
|
+
# Create a new
|
39
|
+
def initialize( buffers )
|
40
|
+
@buffers = buffers
|
41
|
+
end
|
42
|
+
|
43
|
+
# Attempts to perform host-based authorization of the user. The data
|
44
|
+
# hash must contain a <tt>:key_manager</tt> key or the call will
|
45
|
+
# fail.
|
46
|
+
def authenticate( next_service, username, data={} )
|
47
|
+
key_manager = data[:key_manager] or return false
|
48
|
+
|
49
|
+
key_manager.host_identities.each do |identity|
|
50
|
+
return true if authenticate_with( identity, next_service,
|
51
|
+
username, key_manager )
|
52
|
+
end
|
53
|
+
|
54
|
+
return false
|
55
|
+
|
56
|
+
ensure
|
57
|
+
key_manager.finish if key_manager
|
58
|
+
end
|
59
|
+
|
60
|
+
# Attempts to perform host-based authentication of the user, using
|
61
|
+
# the given host identity (key).
|
62
|
+
def authenticate_with( identity, next_service, username, key_manager )
|
63
|
+
client_username = ENV['USER'] || username
|
64
|
+
|
65
|
+
req = build_request identity, next_service, username,
|
66
|
+
@hostname+".", client_username
|
67
|
+
|
68
|
+
sig_data = @buffers.writer
|
69
|
+
sig_data.write_string @session_id
|
70
|
+
sig_data.write req
|
71
|
+
|
72
|
+
sig = key_manager.sign( identity, sig_data.to_s )
|
73
|
+
|
74
|
+
message = @buffers.writer
|
75
|
+
message.write req
|
76
|
+
message.write_string sig
|
77
|
+
|
78
|
+
@messenger.send_message message
|
79
|
+
message = @messenger.wait_for_message
|
80
|
+
|
81
|
+
case message.message_type
|
82
|
+
when USERAUTH_SUCCESS
|
83
|
+
return true
|
84
|
+
when USERAUTH_FAILURE
|
85
|
+
return false
|
86
|
+
else
|
87
|
+
raise Net::SSH::Exception,
|
88
|
+
"unexpected server response to USERAUTH_REQUEST: " +
|
89
|
+
message.inspect
|
90
|
+
end
|
91
|
+
end
|
92
|
+
private :authenticate_with
|
93
|
+
|
94
|
+
# Build the "core" hostbased request string.
|
95
|
+
def build_request( identity, next_service, username, hostname,
|
96
|
+
client_username )
|
97
|
+
# begin
|
98
|
+
buf = @buffers.writer
|
99
|
+
buf.write_byte USERAUTH_REQUEST
|
100
|
+
buf.write_string username
|
101
|
+
buf.write_string next_service
|
102
|
+
buf.write_string "hostbased"
|
103
|
+
|
104
|
+
buf.write_string identity.ssh_type
|
105
|
+
blob = @buffers.writer
|
106
|
+
blob.write_key identity
|
107
|
+
buf.write_string blob.to_s
|
108
|
+
|
109
|
+
buf.write_string hostname
|
110
|
+
buf.write_string client_username
|
111
|
+
return buf.to_s
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,70 @@
|
|
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
|
+
require 'net/ssh/errors'
|
18
|
+
require 'net/ssh/userauth/constants'
|
19
|
+
|
20
|
+
module Net
|
21
|
+
module SSH
|
22
|
+
module UserAuth
|
23
|
+
module Methods
|
24
|
+
|
25
|
+
# Implements the "password" SSH authentication method.
|
26
|
+
class Password
|
27
|
+
include Net::SSH::UserAuth::Constants
|
28
|
+
|
29
|
+
# The messenger to use when communicating.
|
30
|
+
attr_writer :messenger
|
31
|
+
|
32
|
+
# Create a new Password authenticator. It will use the given buffers
|
33
|
+
# factory to create new buffer instances.
|
34
|
+
def initialize( buffers )
|
35
|
+
@buffers = buffers
|
36
|
+
end
|
37
|
+
|
38
|
+
# Attempt to authenticate the given user for the given service. The
|
39
|
+
# data hash must specify a <tt>:password</tt> value, otherwise this
|
40
|
+
# will always return false.
|
41
|
+
def authenticate( next_service, username, data={} )
|
42
|
+
return false unless data[:password]
|
43
|
+
|
44
|
+
msg = @buffers.writer
|
45
|
+
msg.write_byte USERAUTH_REQUEST
|
46
|
+
msg.write_string username
|
47
|
+
msg.write_string next_service
|
48
|
+
msg.write_string "password"
|
49
|
+
msg.write_bool false
|
50
|
+
msg.write_string data[:password]
|
51
|
+
@messenger.send_message msg
|
52
|
+
|
53
|
+
message = @messenger.wait_for_message
|
54
|
+
|
55
|
+
case message.message_type
|
56
|
+
when USERAUTH_SUCCESS
|
57
|
+
return true
|
58
|
+
when USERAUTH_FAILURE, USERAUTH_PASSWD_CHANGEREQ
|
59
|
+
return false
|
60
|
+
else
|
61
|
+
raise Net::SSH::Exception,
|
62
|
+
"unexpected reply to USERAUTH_REQUEST: #{message.inspect}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,137 @@
|
|
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
|
+
require 'net/ssh/errors'
|
18
|
+
require 'net/ssh/userauth/constants'
|
19
|
+
|
20
|
+
module Net
|
21
|
+
module SSH
|
22
|
+
module UserAuth
|
23
|
+
module Methods
|
24
|
+
|
25
|
+
# Implements the "publickey" SSH authentication method.
|
26
|
+
class PublicKey
|
27
|
+
include Net::SSH::UserAuth::Constants
|
28
|
+
|
29
|
+
# The messenger instance to use to send and receive messages
|
30
|
+
attr_writer :messenger
|
31
|
+
|
32
|
+
# The session id of the current SSH session
|
33
|
+
attr_writer :session_id
|
34
|
+
|
35
|
+
# Create a new PublicKey instance that uses the given buffer
|
36
|
+
# factory to produce new buffer instances.
|
37
|
+
def initialize( buffers )
|
38
|
+
@buffers = buffers
|
39
|
+
end
|
40
|
+
|
41
|
+
# Attempts to perform public-key authentication for the given
|
42
|
+
# username, trying each identity known to the key manager. If any of
|
43
|
+
# them succeed, returns +true+, otherwise returns +false+. The data
|
44
|
+
# hash must contain a UserKeyManager instance under the
|
45
|
+
# <tt>:key_manager</tt> key.
|
46
|
+
def authenticate( next_service, username, data={} )
|
47
|
+
key_manager = data[:key_manager]
|
48
|
+
return false unless key_manager
|
49
|
+
|
50
|
+
key_manager.identities.each do |identity|
|
51
|
+
return true if authenticate_with( identity, next_service,
|
52
|
+
username, key_manager )
|
53
|
+
end
|
54
|
+
|
55
|
+
return false
|
56
|
+
|
57
|
+
ensure
|
58
|
+
key_manager.finish if key_manager
|
59
|
+
end
|
60
|
+
|
61
|
+
# Builds a Net::SSH::Util::WriterBuffer that contains the request
|
62
|
+
# formatted for sending a public-key request to the server.
|
63
|
+
def build_request( pub_key, username, next_service, has_sig,
|
64
|
+
buffer=nil )
|
65
|
+
# begin
|
66
|
+
buffer ||= @buffers.writer
|
67
|
+
|
68
|
+
buffer.write_byte USERAUTH_REQUEST
|
69
|
+
buffer.write_string username
|
70
|
+
buffer.write_string next_service
|
71
|
+
buffer.write_string "publickey"
|
72
|
+
buffer.write_bool has_sig
|
73
|
+
buffer.write_string pub_key.ssh_type
|
74
|
+
|
75
|
+
blob = @buffers.writer
|
76
|
+
blob.write_key pub_key
|
77
|
+
buffer.write_string blob.to_s
|
78
|
+
|
79
|
+
return buffer
|
80
|
+
end
|
81
|
+
private :build_request
|
82
|
+
|
83
|
+
# Builds and sends a request formatted for a public-key
|
84
|
+
# authentication request.
|
85
|
+
def send_request( pub_key, username, next_service, signature=nil )
|
86
|
+
msg = build_request( pub_key, username, next_service, signature )
|
87
|
+
msg.write_string signature if signature
|
88
|
+
@messenger.send_message msg
|
89
|
+
end
|
90
|
+
private :send_request
|
91
|
+
|
92
|
+
# Attempts to perform public-key authentication for the given
|
93
|
+
# username, with the given identity (public key). Returns +true+ if
|
94
|
+
# successful, or +false+ otherwise.
|
95
|
+
def authenticate_with( identity, next_service, username, key_manager )
|
96
|
+
send_request identity, username, next_service
|
97
|
+
|
98
|
+
message = @messenger.wait_for_message
|
99
|
+
|
100
|
+
case message.message_type
|
101
|
+
when USERAUTH_PK_OK
|
102
|
+
sig_data = @buffers.writer
|
103
|
+
sig_data.write_string @session_id
|
104
|
+
build_request identity, username, next_service, true, sig_data
|
105
|
+
|
106
|
+
sig_blob = key_manager.sign( identity, sig_data )
|
107
|
+
|
108
|
+
send_request identity, username, next_service, sig_blob.to_s
|
109
|
+
message = @messenger.wait_for_message
|
110
|
+
|
111
|
+
case message.message_type
|
112
|
+
when USERAUTH_SUCCESS
|
113
|
+
return true
|
114
|
+
when USERAUTH_FAILURE
|
115
|
+
return false
|
116
|
+
else
|
117
|
+
raise Net::SSH::Exception,
|
118
|
+
"unexpected server response to USERAUTH_REQUEST: " +
|
119
|
+
message.inspect
|
120
|
+
end
|
121
|
+
|
122
|
+
when USERAUTH_FAILURE
|
123
|
+
return false
|
124
|
+
|
125
|
+
else
|
126
|
+
raise Net::SSH::Exception,
|
127
|
+
"unexpected reply to USERAUTH_REQUEST: #{message.inspect}"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
private :authenticate_with
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,63 @@
|
|
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
|
+
module Net
|
18
|
+
module SSH
|
19
|
+
module UserAuth
|
20
|
+
module Methods
|
21
|
+
|
22
|
+
def register_services( container )
|
23
|
+
container.namespace_define :methods do |b|
|
24
|
+
|
25
|
+
b.password do |c,p|
|
26
|
+
require 'net/ssh/userauth/methods/password'
|
27
|
+
method = Password.new( c[:transport][:buffers] )
|
28
|
+
method.messenger = c[:userauth][:driver]
|
29
|
+
method
|
30
|
+
end
|
31
|
+
|
32
|
+
# Just alias keyboard_interactive to password, for now
|
33
|
+
# TODO: keyboard_interactive should probably actually prompt
|
34
|
+
# for a password if one wasn't given...need to read up on this
|
35
|
+
# more.
|
36
|
+
b.keyboard_interactive { b.password }
|
37
|
+
|
38
|
+
b.publickey do |c,p|
|
39
|
+
require 'net/ssh/userauth/methods/publickey'
|
40
|
+
method = PublicKey.new( c[:transport][:buffers] )
|
41
|
+
method.messenger = c[:userauth][:driver]
|
42
|
+
method.session_id = c[:transport][:session].session_id
|
43
|
+
method
|
44
|
+
end
|
45
|
+
|
46
|
+
b.hostbased do |c,p|
|
47
|
+
require 'net/ssh/userauth/methods/hostbased'
|
48
|
+
method = HostBased.new( c[:transport][:buffers] )
|
49
|
+
session = c[:transport][:session]
|
50
|
+
method.messenger = c[:userauth][:driver]
|
51
|
+
method.hostname = session.client_name
|
52
|
+
method.session_id = session.session_id
|
53
|
+
method
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
module_function :register_services
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,126 @@
|
|
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
|
+
module Net
|
18
|
+
module SSH
|
19
|
+
module UserAuth
|
20
|
+
|
21
|
+
def register_services( container )
|
22
|
+
container.namespace_define :userauth do |b|
|
23
|
+
|
24
|
+
b.require 'net/ssh/userauth/methods/services', "#{self}::Methods"
|
25
|
+
|
26
|
+
b.agent_socket_factory do
|
27
|
+
require 'socket'
|
28
|
+
defined?( UNIXSocket ) ? UNIXSocket : nil
|
29
|
+
end
|
30
|
+
|
31
|
+
b.default_agent_socket_name { ENV['SSH_AUTH_SOCK'] }
|
32
|
+
|
33
|
+
b.default_agent_version { 2 }
|
34
|
+
|
35
|
+
b.agent( :model => :prototype ) do |c,p|
|
36
|
+
if ( socket_factory = c[:agent_socket_factory] )
|
37
|
+
require 'net/ssh/userauth/agent'
|
38
|
+
require 'net/ssh/transport/services'
|
39
|
+
|
40
|
+
agent = Agent.new
|
41
|
+
agent.socket_factory = socket_factory
|
42
|
+
agent.socket_name = c[:default_agent_socket_name]
|
43
|
+
agent.version = c[:default_agent_version]
|
44
|
+
agent.buffers = c[:transport][:buffers]
|
45
|
+
agent.keys = c[:transport][:keys]
|
46
|
+
agent.connect!
|
47
|
+
end
|
48
|
+
|
49
|
+
agent
|
50
|
+
end
|
51
|
+
|
52
|
+
b.agent_factory do |c,p|
|
53
|
+
factory = Object.new
|
54
|
+
klass = class << factory; self; end
|
55
|
+
klass.send( :define_method, :open ) { c[:agent] }
|
56
|
+
factory
|
57
|
+
end
|
58
|
+
|
59
|
+
b.default_user_key_locations do
|
60
|
+
[ "#{ENV['HOME']}/.ssh/id_dsa",
|
61
|
+
"#{ENV['HOME']}/.ssh2/id_dsa",
|
62
|
+
"#{ENV['HOME']}/.ssh/id_rsa",
|
63
|
+
"#{ENV['HOME']}/.ssh2/id_rsa" ]
|
64
|
+
end
|
65
|
+
|
66
|
+
b.default_host_key_locations do
|
67
|
+
[ "/etc/ssh/ssh_host_dsa_key",
|
68
|
+
"/etc/ssh/ssh_host_rsa_key" ]
|
69
|
+
end
|
70
|
+
|
71
|
+
b.key_existence_tester { File }
|
72
|
+
|
73
|
+
b.user_keys do |c,p|
|
74
|
+
require 'net/ssh/userauth/userkeys'
|
75
|
+
|
76
|
+
userkeys = UserKeyManager.new
|
77
|
+
userkeys.agent_factory = c[:agent_factory]
|
78
|
+
userkeys.keys = c[:transport][:keys]
|
79
|
+
userkeys.buffers = c[:transport][:buffers]
|
80
|
+
userkeys.log = c[:log_for, p]
|
81
|
+
userkeys.key_existence_tester = b.key_existence_tester
|
82
|
+
|
83
|
+
b.default_user_key_locations.each { |f| userkeys.add f }
|
84
|
+
b.default_host_key_locations.each { |f| userkeys.add_host_key f }
|
85
|
+
|
86
|
+
userkeys
|
87
|
+
end
|
88
|
+
|
89
|
+
b.authentication_method_order do
|
90
|
+
[ "publickey",
|
91
|
+
"keyboard-interactive",
|
92
|
+
"password",
|
93
|
+
"hostbased" ]
|
94
|
+
end
|
95
|
+
|
96
|
+
b.driver do |c,p|
|
97
|
+
require 'net/ssh/userauth/driver'
|
98
|
+
|
99
|
+
driver = Driver.new( c[:log_for, p],
|
100
|
+
c[:transport][:buffers],
|
101
|
+
c[:methods],
|
102
|
+
c[:authentication_method_order] )
|
103
|
+
|
104
|
+
driver.key_manager = c[:user_keys]
|
105
|
+
driver.session = c[:transport][:session]
|
106
|
+
|
107
|
+
if c.knows_key?(:userauth_keys) && c[:userauth_keys]
|
108
|
+
driver.set_key_files c[:userauth_keys]
|
109
|
+
end
|
110
|
+
if c.knows_key?(:userauth_host_keys) && c[:userauth_host_keys]
|
111
|
+
driver.set_host_key_files c[:userauth_host_keys]
|
112
|
+
end
|
113
|
+
if c.knows_key?(:userauth_method_order) && c[:userauth_method_order]
|
114
|
+
driver.set_auth_method_order *c[:userauth_method_order]
|
115
|
+
end
|
116
|
+
|
117
|
+
driver
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
122
|
+
module_function :register_services
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|