net-ssh-kerberos 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.sw?
2
+ .buildpath
3
+ .project
4
+ .DS_Store
5
+ coverage
6
+ doc
7
+ rdoc
8
+ pkg
data/Rakefile CHANGED
@@ -43,33 +43,36 @@ rescue LoadError
43
43
  end
44
44
 
45
45
  # These are new tasks
46
- begin
47
- require 'rake/contrib/sshpublisher'
48
- namespace :rubyforge do
49
-
50
- desc "Release gem and RDoc documentation to RubyForge"
51
- task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
52
-
53
- namespace :release do
54
- desc "Publish RDoc to RubyForge."
55
- task :docs => [:rdoc] do
56
- config = YAML.load(
57
- File.read(File.expand_path('~/.rubyforge/user-config.yml'))
58
- )
59
-
60
- host = "#{config['username']}@rubyforge.org"
61
- remote_dir = "/var/www/gforge-projects/net-ssh-krb/"
62
- local_dir = 'doc'
63
-
64
- Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
65
- end
66
- end
67
- end
68
- rescue LoadError
69
- puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
46
+ #begin
47
+ # require 'rake/contrib/sshpublisher'
48
+ # namespace :rubyforge do
49
+ #
50
+ # desc "Release gem and RDoc documentation to RubyForge"
51
+ # task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
52
+ #
53
+ # namespace :release do
54
+ # desc "Publish RDoc to RubyForge."
55
+ # task :docs => [:rdoc] do
56
+ # config = YAML.load(
57
+ # File.read(File.expand_path('~/.rubyforge/user-config.yml'))
58
+ # )
59
+ #
60
+ # host = "#{config['username']}@rubyforge.org"
61
+ # remote_dir = "/var/www/gforge-projects/net-ssh-krb/"
62
+ # local_dir = 'doc'
63
+ #
64
+ # Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
65
+ # end
66
+ # end
67
+ # end
68
+ #rescue LoadError
69
+ # puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
70
+ #end
71
+ #
72
+ Jeweler::RubyforgeTasks.new do |rubyforge|
73
+ rubyforge.doc_task = "rdoc"
70
74
  end
71
75
 
72
-
73
76
  task :default => :test
74
77
 
75
78
  require 'rake/rdoctask'
@@ -84,7 +87,7 @@ Rake::RDocTask.new do |rdoc|
84
87
  '--main' << 'README.rdoc' <<
85
88
  '--charset' << 'utf-8'
86
89
 
87
- rdoc.rdoc_dir = 'doc'
90
+ rdoc.rdoc_dir = 'rdoc'
88
91
  rdoc.title = "Net::SSH::Kerberos #{version}"
89
92
  rdoc.rdoc_files.include('README*')
90
93
  rdoc.rdoc_files.include('lib/**/*.rb')
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :major: 0
3
2
  :minor: 2
4
- :patch: 1
3
+ :patch: 2
4
+ :major: 0
data/example/Capfile ADDED
@@ -0,0 +1,3 @@
1
+ require 'net/ssh/kerberos'
2
+ set :ssh_options, { :auth_methods => %w(gssapi-with-mic publickey hostbased password keyboard-interactive) }
3
+
data/example/gss.rb ADDED
@@ -0,0 +1,91 @@
1
+ require 'socket'
2
+ require 'rubygems'
3
+ gem 'net-ssh'
4
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+ require 'net/ssh'
6
+ require 'net/ssh/errors'
7
+ require 'net/ssh/kerberos'
8
+
9
+ unless Net::SSH::Kerberos::Drivers.available.include? 'GSS'
10
+ $stderr.puts "No drivers supporting GSSAPI could be loaded."
11
+ exit 1
12
+ end
13
+
14
+ include Net::SSH::Kerberos::Drivers::GSS
15
+ include Net::SSH::Kerberos::Constants
16
+
17
+ result = API.gss_acquire_cred nil, 60, nil, GSS_C_INITIATE, nil, nil, 0
18
+ if result.ok?
19
+ creds = API._args_[4]
20
+ $stderr.puts "gss_acquire_cred: (#{result}) => #{creds.to_i}"
21
+ begin
22
+ result = API.gss_inquire_cred creds, nil, 0, 0, nil
23
+ if result.ok?
24
+ name, oids = API._args_[1], API._args_[4]
25
+ $stderr.puts "gss_inquire_cred: (#{result}) #{oids.inspect}"
26
+ begin
27
+ result = API.gss_display_name name, buffer=API::GssBuffer.malloc, nil
28
+ if result.ok?
29
+ oid = API._args_[2]
30
+ $stderr.puts "gss_display_name: (#{result}) #{buffer} #{oid.inspect}"
31
+ result = API.gss_release_buffer buffer
32
+ $stderr.puts "gss_release_buffer: (#{result})"
33
+ else
34
+ $stderr.puts "gss_display_name failed : (#{result})"
35
+ end
36
+ ensure
37
+ result = API.gss_release_oid_set oids
38
+ $stderr.puts "gss_release_oid_set: (#{result})"
39
+ result = API.gss_release_name name
40
+ $stderr.puts "gss_release_name: (#{result})"
41
+ end
42
+ else
43
+ $stderr.puts "gss_inquire_cred failed: (#{result})"
44
+ end
45
+
46
+
47
+ target_name = 'host@'+Socket.gethostbyname(`hostname || echo "localhost"`.strip)[0]
48
+ buffer = API::GssBuffer.malloc
49
+ buffer.value = target_name
50
+ buffer.length = target_name.length
51
+ API.gss_import_name buffer, GSS_C_NT_HOSTBASED_SERVICE, nil
52
+ if result.ok?
53
+ target = API._args_[2]
54
+ $stderr.puts "gss_import_name: (#{result}) #{target.to_i}"
55
+ begin
56
+ result = API.gss_display_name target, buffer, nil
57
+ if result.ok?
58
+ oid = API._args_[2]
59
+ $stderr.puts "gss_display_name: (#{result}) #{buffer} #{oid.inspect}"
60
+ result = API.gss_release_buffer buffer
61
+ $stderr.puts "gss_release_buffer: (#{result})"
62
+ else
63
+ $stderr.puts "gss_display_name failed : (#{result})"
64
+ end
65
+ result = API.gss_init_sec_context creds, GSS_C_NO_CONTEXT, target, GSS_C_KRB5,
66
+ GSS_C_DELEG_FLAG | GSS_C_MUTUAL_FLAG | GSS_C_INTEG_FLAG, 60,
67
+ GSS_C_NO_CHANNEL_BINDINGS, GSS_C_NO_BUFFER, nil, buffer, 0, 0
68
+ if result.ok?
69
+ context, actual_mech = API._args_[1], API._args_[8]
70
+ $stderr.puts "gss_init_sec_context: (#{result}) token.length=#{buffer.length}, #{actual_mech.inspect}"
71
+ result = API.gss_release_buffer buffer
72
+ $stderr.puts "gss_release_buffer: (#{result})"
73
+ result = API.gss_delete_sec_context context, nil
74
+ $stderr.puts "gss_delete_sec_context: (#{result})"
75
+ else
76
+ $stderr.puts "gss_init_sec_context failed : (#{result})"
77
+ end
78
+ ensure
79
+ result = API.gss_release_name target
80
+ $stderr.puts "gss_release_name: (#{result})"
81
+ end
82
+ else
83
+ $stderr.puts "gss_import_name failed: (#{result})"
84
+ end
85
+ ensure
86
+ result = API.gss_release_cred creds
87
+ $stderr.puts "gss_release_cred: (#{result})"
88
+ end
89
+ else
90
+ $stderr.puts "gss_acquire_cred failed: (#{result})"
91
+ end
data/example/sspi.rb ADDED
@@ -0,0 +1,73 @@
1
+ #$DEBUG = 1
2
+
3
+ require 'socket'
4
+ require 'rubygems'
5
+ gem 'net-ssh'
6
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
+ require 'net/ssh'
8
+ require 'net/ssh/errors'
9
+ require 'net/ssh/kerberos'
10
+
11
+ unless Net::SSH::Kerberos::Drivers.available.include? 'SSPI'
12
+ $stderr.puts "No drivers supporting SSPI could be loaded."
13
+ exit 1
14
+ end
15
+
16
+ include Net::SSH::Kerberos::Drivers::SSPI
17
+ include Net::SSH::Kerberos::Constants
18
+
19
+ result = API.querySecurityPackageInfo "Kerberos", nil
20
+ if result.ok?
21
+ pkg_info = API._args_[1]
22
+ $stderr.puts "querySecurityPackageInfo: (#{result}) #{pkg_info.comment} (max_token=#{pkg_info.max_token})"
23
+ @max_token = pkg_info.max_token
24
+ result = API.freeContextBuffer pkg_info
25
+ $stderr.puts "freeContextBuffer: (#{result})"
26
+ else
27
+ $stderr.puts "querySecurityPackageInfo: (#{result})"
28
+ end
29
+
30
+ result = API.acquireCredentialsHandle nil, "Kerberos", SECPKG_CRED_OUTBOUND, nil, nil, nil, nil,
31
+ creds=API::SecHandle.malloc, ts=API::TimeStamp.malloc
32
+ if result.ok?
33
+ $stderr.puts "acquireCredentialsHandle: (#{result})"
34
+ begin
35
+ result = API.queryCredentialsAttributes creds, SECPKG_ATTR_NAMES, nil
36
+ if result.ok?
37
+ names = API._args_[2]
38
+ $stderr.puts "queryCredentialsAttributes: (#{result}) #{names.to_s}"
39
+ result = API.freeContextBuffer names
40
+ $stderr.puts "freeContextBuffer: (#{result})"
41
+
42
+ token = API::SecBuffer.malloc
43
+ token.type = SECBUFFER_TOKEN
44
+ token.data = "\0" * @max_token
45
+ token.length = @max_token
46
+ output = API::SecBufferDesc.malloc
47
+ output.version = 0
48
+ output.count = 1
49
+ output.buffers = token.to_ptr
50
+ result = API.initializeSecurityContext creds, nil, 'host/'+Socket.gethostbyname('localhost')[0],
51
+ ISC_REQ_DELEGATE | ISC_REQ_MUTUAL_AUTH | ISC_REQ_INTEGRITY, 0, SECURITY_NATIVE_DREP,
52
+ nil, 0, ctx=API::SecHandle.malloc, output, 0, ts=API::TimeStamp.malloc
53
+ if result.ok?
54
+ $stderr.puts "initializeSecurityContext: (#{result}) ctx=#{! ctx.nil?} token.length=#{output.buffer(0).length}"
55
+ result = API.freeContextBuffer token.data
56
+ $stderr.puts "freeContextBuffer: (#{result})"
57
+ result = API.deleteSecurityContext ctx
58
+ $stderr.puts "deleteSecurityContext: (#{result})"
59
+ else
60
+ $stderr.puts "initializeSecurityContext: (#{result})"
61
+ end
62
+ else
63
+ $stderr.puts "queryCredentialsAttributes: (#{result})"
64
+ end
65
+ ensure
66
+ result = API.freeCredentialsHandle creds
67
+ $stderr.puts "freeCredentialsHandle : (#{result})"
68
+ end
69
+ else
70
+ $stderr.puts "acquireCredentialsHandle: (#{result})"
71
+ end
72
+
73
+
@@ -68,22 +68,51 @@ EOCODE
68
68
  end
69
69
  typealias 'gss_buffer_desc', 'GssBuffer'
70
70
  typealias 'gss_buffer_t', 'gss_buffer_desc *'
71
- GssOID = struct2 [ "OM_uint32 length", "gss_bytes_t elements" ] do
72
- def eql?(oid) !oid.nil? && length==oid.length && to_s==oid.to_s end
71
+ class GssOID
72
+ PACK = (RUBY_PLATFORM =~ /darwin/ ? 'I' : "I@#{DL.sizeof('P')}")+'P'
73
+ ELEMENTS_OFFSET = DL.sizeof(RUBY_PLATFORM =~ /darwin/ ? 'I' : 'P')
74
+ STRUCT_SIZE = ELEMENTS_OFFSET + DL.sizeof('P')
75
+
76
+ def initialize(ptr)
77
+ @ptr = ptr
78
+ end
79
+
80
+ def self.create(bytes)
81
+ v = [bytes.length, bytes]
82
+ o = new v.pack(PACK).to_ptr
83
+ o.instance_variable_set :@unpack, v
84
+ o
85
+ end
86
+
87
+ def length; unpack[0] end
88
+ def elements; unpack[1] end
89
+ alias to_s elements
90
+
91
+ def eql?(oid) !oid.nil? && length==oid.length && to_s==oid.to_s end
73
92
  def ==(oid) !oid.nil? && length==oid.length && to_s==oid.to_s end
74
- def to_s; elements.to_s(length) if length > 0 end
75
- def inspect; 'OID: ' + (to_s.unpack("H2" * length).join(' ') rescue 'nil') end
93
+ def inspect; 'OID: ' + (to_s.unpack("H2" * length).join(' ')) end
94
+ def ptr; @ptr end
95
+ alias to_ptr ptr
96
+
97
+ def self.size; STRUCT_SIZE end
98
+
99
+ private
100
+
101
+ def unpack
102
+ @unpack ||= (begin
103
+ v = @ptr.to_s(4).unpack('I')[0]
104
+ [ v, (@ptr + ELEMENTS_OFFSET).ptr.to_s(v) ]
105
+ end)
106
+ end
76
107
  end
77
- def GssOID.create(bytes) new [bytes.length, bytes].pack("LP#{bytes.length}").to_ptr end
78
108
  typealias 'gss_OID', 'P', PTR_ENC, PTR_DEC(GssOID)
79
109
  typealias 'gss_OID_ref', 'p', PTR_REF_ENC, PTR_REF_DEC(GssOID)
80
- GssOIDSet = struct2 [ "size_t count", "gss_OID elements" ] do
110
+ GssOIDSet = struct2 [ "size_t count", "void *elements" ] do
81
111
  def oids
82
- if @oids.nil? or elements != (@oids.first.to_ptr rescue nil)
83
- @oids = []
84
- 0.upto(count-1) { |n| @oids[n] = GssOID.new(elements + n*GssOID.size) } unless elements.nil?
85
- end
86
- @oids
112
+ return @oids unless @oids.nil?
113
+ @oids, m = [], GssOID.size
114
+ count.nonzero? and 0.upto(count-1) { |n| @oids[n] = GssOID.new(elements + n * m); @oids[n].ptr.size = m }
115
+ @oids
87
116
  end
88
117
  def inspect; 'OIDSet: [' + oids.map {|o| o.inspect }.join(', ') + ']' end
89
118
  end
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{net-ssh-kerberos}
8
+ s.version = "0.2.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Joe Khoobyar"]
12
+ s.date = %q{2009-12-28}
13
+ s.description = %q{Extends Net::SSH by adding Kerberos authentication capability for password-less logins on multiple platforms.
14
+ }
15
+ s.email = %q{joe@ankhcraft.com}
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION.yml",
27
+ "example/Capfile",
28
+ "example/gss.rb",
29
+ "example/sspi.rb",
30
+ "lib/net/ssh/authentication/methods/gssapi_with_mic.rb",
31
+ "lib/net/ssh/kerberos.rb",
32
+ "lib/net/ssh/kerberos/constants.rb",
33
+ "lib/net/ssh/kerberos/context.rb",
34
+ "lib/net/ssh/kerberos/drivers.rb",
35
+ "lib/net/ssh/kerberos/drivers/gss.rb",
36
+ "lib/net/ssh/kerberos/drivers/sspi.rb",
37
+ "lib/net/ssh/kerberos/kex.rb",
38
+ "lib/net/ssh/kerberos/kex/krb5_diffie_hellman_group1_sha1.rb",
39
+ "lib/net/ssh/kerberos/kex/krb5_diffie_hellman_group_exchange_sha1.rb",
40
+ "net-ssh-kerberos.gemspec",
41
+ "test/gss_context_test.rb",
42
+ "test/gss_test.rb",
43
+ "test/net_ssh_kerberos_test.rb",
44
+ "test/sspi_context_test.rb",
45
+ "test/sspi_test.rb",
46
+ "test/test_helper.rb"
47
+ ]
48
+ s.homepage = %q{http://github.com/joekhoobyar/net-ssh-kerberos}
49
+ s.rdoc_options = ["--charset=UTF-8"]
50
+ s.require_paths = ["lib"]
51
+ s.required_ruby_version = Gem::Requirement.new("< 1.9")
52
+ s.rubyforge_project = %q{net-ssh-krb}
53
+ s.rubygems_version = %q{1.3.5}
54
+ s.summary = %q{Add Kerberos support to Net::SSH}
55
+ s.test_files = [
56
+ "test/gss_context_test.rb",
57
+ "test/gss_test.rb",
58
+ "test/net_ssh_kerberos_test.rb",
59
+ "test/sspi_context_test.rb",
60
+ "test/sspi_test.rb",
61
+ "test/test_helper.rb"
62
+ ]
63
+
64
+ if s.respond_to? :specification_version then
65
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
66
+ s.specification_version = 3
67
+
68
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
69
+ s.add_runtime_dependency(%q<net-ssh>, [">= 2.0"])
70
+ else
71
+ s.add_dependency(%q<net-ssh>, [">= 2.0"])
72
+ end
73
+ else
74
+ s.add_dependency(%q<net-ssh>, [">= 2.0"])
75
+ end
76
+ end
77
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-ssh-kerberos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Khoobyar
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-19 00:00:00 -04:00
12
+ date: 2009-12-28 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -34,10 +34,15 @@ extra_rdoc_files:
34
34
  - LICENSE
35
35
  - README.rdoc
36
36
  files:
37
+ - .document
38
+ - .gitignore
37
39
  - LICENSE
38
40
  - README.rdoc
39
41
  - Rakefile
40
42
  - VERSION.yml
43
+ - example/Capfile
44
+ - example/gss.rb
45
+ - example/sspi.rb
41
46
  - lib/net/ssh/authentication/methods/gssapi_with_mic.rb
42
47
  - lib/net/ssh/kerberos.rb
43
48
  - lib/net/ssh/kerberos/constants.rb
@@ -48,6 +53,7 @@ files:
48
53
  - lib/net/ssh/kerberos/kex.rb
49
54
  - lib/net/ssh/kerberos/kex/krb5_diffie_hellman_group1_sha1.rb
50
55
  - lib/net/ssh/kerberos/kex/krb5_diffie_hellman_group_exchange_sha1.rb
56
+ - net-ssh-kerberos.gemspec
51
57
  - test/gss_context_test.rb
52
58
  - test/gss_test.rb
53
59
  - test/net_ssh_kerberos_test.rb
@@ -78,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
84
  requirements: []
79
85
 
80
86
  rubyforge_project: net-ssh-krb
81
- rubygems_version: 1.3.4
87
+ rubygems_version: 1.3.5
82
88
  signing_key:
83
89
  specification_version: 3
84
90
  summary: Add Kerberos support to Net::SSH