ruby-ntlm 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3e26c065e9eceacdfec71a78b2c6deefd4fad3a9
4
+ data.tar.gz: 4664f657f8615350873b3991ee93aee2ee365e84
5
+ SHA512:
6
+ metadata.gz: 489944e1a1b4e05385b1699d62002e21facbf910afa5638e923d1c0d23ebb7378f7ab4ab6de589aefa648a3227d06da29df1eb977ae008dc2ff07d0dd82f0d6e
7
+ data.tar.gz: afe5422cae120622ac64e3f6a888e93d795c173695072bfe31dc003e9954f579a8af5a845481bfe672fa580d21425b78172bfb6dbae047dab71f215beb5960af
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ #- 1.8.7
4
+ - 1.9.3
5
+ - 2.2.5
6
+ - 2.3.1
7
+ script: bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ # vim: set ft=ruby:
2
+ source 'https://rubygems.org'
3
+ gemspec
data/README.markdown CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/macks/ruby-ntlm.svg?branch=master)](https://travis-ci.org/macks/ruby-ntlm)
2
+
1
3
  ruby-ntlm
2
4
  =========
3
5
 
@@ -25,13 +27,6 @@ Usage
25
27
  request.ntlm_auth('User', 'Domain', 'Password')
26
28
  response = http.request(request)
27
29
 
28
- ### HTTP (using Mechanize) ###
29
-
30
- require 'ntlm/mechanize'
31
- mech = Mechanize.new
32
- mech.auth('Domain\\User', 'Password')
33
- mech.get('http://www.example.com/index.html')
34
-
35
30
  ### IMAP ###
36
31
 
37
32
  require 'ntlm/imap'
data/Rakefile CHANGED
@@ -1,34 +1,11 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'jeweler'
4
- require 'rake/testtask'
5
-
6
- task :default => :test
1
+ # vim: set ft=ruby:
7
2
 
8
- Jeweler::Tasks.new do |gem|
9
- gem.name = 'ruby-ntlm'
10
- gem.summary = %Q{NTLM implementation for Ruby}
11
- gem.description = %Q{NTLM implementation for Ruby.}
12
- gem.email = 'macksx@gmail.com'
13
- gem.homepage = 'http://github.com/macks/ruby-ntlm'
14
- gem.authors = ['MATSUYAMA Kengo']
15
- end
3
+ require "bundler/gem_tasks"
4
+ require 'rake/testtask'
16
5
 
17
6
  Rake::TestTask.new(:test) do |task|
18
7
  task.libs << 'lib:test'
19
8
  task.pattern = 'test/**/*_test.rb'
20
9
  task.verbose = true
21
- end
22
-
23
- begin
24
- require 'rcov/rcovtask'
25
- Rcov::RcovTask.new do |task|
26
- task.libs << 'lib:test'
27
- task.pattern = 'test/**/*_test.rb'
28
- task.verbose = true
29
- end
30
- rescue LoadError
31
- task :rcov do
32
- abort 'rcov is not available.'
33
- end
10
+ task.warning = true
34
11
  end
data/lib/ntlm/http.rb CHANGED
@@ -23,6 +23,8 @@ module Net
23
23
  end
24
24
 
25
25
  unless started?
26
+ @original_body = req.body
27
+ req.body = nil
26
28
  start do
27
29
  req.delete('connection')
28
30
  return request(req, body, &block)
@@ -30,15 +32,16 @@ module Net
30
32
  end
31
33
 
32
34
  # Negotiation
33
- req['authorization'] = 'NTLM ' + NTLM.negotiate.to_base64
35
+ req['authorization'] = 'NTLM ' + ::NTLM.negotiate.to_base64
34
36
  res = request_without_ntlm_auth(req, body)
35
37
  challenge = res['www-authenticate'][/NTLM (.*)/, 1].unpack('m').first rescue nil
36
38
 
37
39
  if challenge && res.code == '401'
38
40
  # Authentication
39
41
  user, domain, password = req.ntlm_auth_params
40
- req['authorization'] = 'NTLM ' + NTLM.authenticate(challenge, user, domain, password).to_base64
42
+ req['authorization'] = 'NTLM ' + ::NTLM.authenticate(challenge, user, domain, password).to_base64
41
43
  req.body_stream.rewind if req.body_stream
44
+ req.body = @original_body
42
45
  request_without_ntlm_auth(req, body, &block) # We must re-use the connection.
43
46
  else
44
47
  yield res if block_given?
data/lib/ntlm/imap.rb CHANGED
@@ -24,9 +24,9 @@ module Net
24
24
  def process(data)
25
25
  case (@state += 1)
26
26
  when 1
27
- NTLM.negotiate.to_s
27
+ ::NTLM.negotiate.to_s
28
28
  when 2
29
- NTLM.authenticate(data, @user, @domain, @password).to_s
29
+ ::NTLM.authenticate(data, @user, @domain, @password).to_s
30
30
  end
31
31
  end
32
32
  end # NTLMAuthenticator
data/lib/ntlm/message.rb CHANGED
@@ -79,9 +79,15 @@ module NTLM
79
79
  end
80
80
 
81
81
  def initialize(args = {})
82
- @buffer = ''
83
- @offset = 0
84
- @flag = args[:flag] || self.class::DEFAULT_FLAGS
82
+ @buffer = ''
83
+ @offset = 0
84
+ @flag = args[:flag] || self.class::DEFAULT_FLAGS
85
+ @domain = nil
86
+ @workstation = nil
87
+ @version = nil
88
+ @target_info = nil
89
+ @session_key = nil
90
+ @mic = nil
85
91
 
86
92
  self.class::ATTRIBUTES.each do |key|
87
93
  instance_variable_set("@#{key}", args[key]) if args[key]
@@ -147,7 +153,7 @@ module NTLM
147
153
  end
148
154
 
149
155
  def fetch_payload(fields)
150
- size, allocated_size, offset = fields.unpack('vvV')
156
+ size, _, offset = fields.unpack('vvV')
151
157
  return nil if size.zero?
152
158
  @buffer[offset, size]
153
159
  end
@@ -204,7 +210,7 @@ module NTLM
204
210
  ATTRIBUTES = [:domain, :workstation, :version]
205
211
  DEFAULT_FLAGS = [NEGOTIATE_UNICODE, NEGOTIATE_OEM, REQUEST_TARGET, NEGOTIATE_NTLM, NEGOTIATE_ALWAYS_SIGN, NEGOTIATE_EXTENDED_SECURITY].inject(:|)
206
212
 
207
- attr_accessor *ATTRIBUTES
213
+ attr_accessor(*ATTRIBUTES)
208
214
 
209
215
  def parse(string)
210
216
  super
@@ -247,7 +253,7 @@ module NTLM
247
253
  ATTRIBUTES = [:target_name, :challenge, :target_info, :version]
248
254
  DEFAULT_FLAGS = 0
249
255
 
250
- attr_accessor *ATTRIBUTES
256
+ attr_accessor(*ATTRIBUTES)
251
257
 
252
258
  def parse(string)
253
259
  super
@@ -300,7 +306,7 @@ module NTLM
300
306
  ATTRIBUTES = [:lm_response, :nt_response, :domain, :user, :workstation, :session_key, :version, :mic]
301
307
  DEFAULT_FLAGS = [NEGOTIATE_UNICODE, REQUEST_TARGET, NEGOTIATE_NTLM, NEGOTIATE_ALWAYS_SIGN, NEGOTIATE_EXTENDED_SECURITY].inject(:|)
302
308
 
303
- attr_accessor *ATTRIBUTES
309
+ attr_accessor(*ATTRIBUTES)
304
310
 
305
311
  def parse(string)
306
312
  super
data/lib/ntlm/smtp.rb CHANGED
@@ -17,10 +17,10 @@ module Net
17
17
  end
18
18
 
19
19
  res = critical {
20
- r = get_response("AUTH NTLM #{NTLM.negotiate.to_base64}")
20
+ r = get_response("AUTH NTLM #{::NTLM.negotiate.to_base64}")
21
21
  check_auth_continue(r)
22
22
  challenge = r.string.split(/ /, 2).last.unpack('m').first
23
- get_response(NTLM.authenticate(challenge, user, domain, secret).to_base64)
23
+ get_response(::NTLM.authenticate(challenge, user, domain, secret).to_base64)
24
24
  }
25
25
  check_auth_response(res)
26
26
  res
data/lib/ntlm/util.rb CHANGED
@@ -77,7 +77,9 @@ module NTLM
77
77
  # [MS-NLMP] 3.3.1
78
78
  def ntlm_v1_response(challenge, password, options = {})
79
79
  if options[:ntlm_v2_session]
80
+ challenge = challenge.b if challenge.respond_to?(:b)
80
81
  client_challenge = options[:client_challenge] || OpenSSL::Random.random_bytes(8)
82
+ client_challenge = client_challenge.b if client_challenge.respond_to?(:b)
81
83
  hash = OpenSSL::Digest::MD5.digest(challenge + client_challenge)[0, 8]
82
84
  nt_response = encrypt(hash, nt_v1_hash(password), 21)
83
85
  lm_response = client_challenge + ("\0" * 16)
@@ -0,0 +1,5 @@
1
+ # vim: set et sw=2 sts=2:
2
+
3
+ module NTLM
4
+ VERSION = '0.0.3'
5
+ end
data/ruby-ntlm.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ntlm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby-ntlm"
8
+ spec.version = NTLM::VERSION
9
+ spec.authors = ["MATSUYAMA Kengo"]
10
+ spec.email = ["macksx@gmail.com"]
11
+ spec.summary = %q{NTLM implementation for Ruby.}
12
+ spec.description = %q{NTLM implementation for Ruby.}
13
+ spec.homepage = "http://github.com/macks/ruby-ntlm"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "test-unit"
24
+ end
metadata CHANGED
@@ -1,36 +1,69 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-ntlm
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - MATSUYAMA Kengo
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-01-18 00:00:00 +09:00
19
- default_executable:
20
- dependencies: []
21
-
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
22
55
  description: NTLM implementation for Ruby.
23
- email: macksx@gmail.com
56
+ email:
57
+ - macksx@gmail.com
24
58
  executables: []
25
-
26
59
  extensions: []
27
-
28
- extra_rdoc_files:
29
- - README.markdown
30
- files:
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
31
65
  - README.markdown
32
66
  - Rakefile
33
- - VERSION
34
67
  - examples/http.rb
35
68
  - examples/http2.rb
36
69
  - examples/imap.rb
@@ -39,56 +72,42 @@ files:
39
72
  - lib/ntlm.rb
40
73
  - lib/ntlm/http.rb
41
74
  - lib/ntlm/imap.rb
42
- - lib/ntlm/mechanize.rb
43
75
  - lib/ntlm/message.rb
44
76
  - lib/ntlm/smtp.rb
45
77
  - lib/ntlm/util.rb
78
+ - lib/ntlm/version.rb
79
+ - ruby-ntlm.gemspec
46
80
  - test/auth_test.rb
47
81
  - test/function_test.rb
48
82
  - test/test_helper.rb
49
83
  - unused/extconf.rb
50
84
  - unused/http_example.rb
51
85
  - unused/ntlm.c
52
- has_rdoc: true
53
86
  homepage: http://github.com/macks/ruby-ntlm
54
- licenses: []
55
-
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
56
90
  post_install_message:
57
91
  rdoc_options: []
58
-
59
- require_paths:
92
+ require_paths:
60
93
  - lib
61
- required_ruby_version: !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
64
96
  - - ">="
65
- - !ruby/object:Gem::Version
66
- hash: 3
67
- segments:
68
- - 0
69
- version: "0"
70
- required_rubygems_version: !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
73
101
  - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
79
104
  requirements: []
80
-
81
105
  rubyforge_project:
82
- rubygems_version: 1.3.7
106
+ rubygems_version: 2.4.5.1
83
107
  signing_key:
84
- specification_version: 3
85
- summary: NTLM implementation for Ruby
86
- test_files:
87
- - examples/http.rb
88
- - examples/http2.rb
89
- - examples/imap.rb
90
- - examples/mechanize.rb
91
- - examples/smtp.rb
108
+ specification_version: 4
109
+ summary: NTLM implementation for Ruby.
110
+ test_files:
92
111
  - test/auth_test.rb
93
112
  - test/function_test.rb
94
113
  - test/test_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.1
@@ -1,42 +0,0 @@
1
- require 'mechanize'
2
- require 'ntlm/http'
3
-
4
- class Mechanize
5
- class Chain
6
- class AuthHeaders
7
-
8
- unless method_defined?(:handle_without_ntlm)
9
- alias handle_without_ntlm handle
10
- end
11
-
12
- def handle(ctx, params)
13
- if @auth_hash[params[:uri].host] == :ntlm && @user && @password
14
- if @user.index('\\')
15
- domain, user = @user.split('\\', 2)
16
- end
17
- params[:request].ntlm_auth(user, domain, @password)
18
- end
19
- handle_without_ntlm(ctx, params)
20
- end
21
- end
22
- end
23
-
24
- unless private_method_defined?(:fetch_page_without_ntlm)
25
- alias fetch_page_without_ntlm fetch_page
26
- end
27
-
28
- private
29
-
30
- def fetch_page(params)
31
- begin
32
- fetch_page_without_ntlm(params)
33
- rescue Mechanize::ResponseCodeError => e
34
- if e.response_code == '401' && e.page.header['www-authenticate'] =~ /NTLM/ && @auth_hash[e.page.uri.host] != :ntlm
35
- @auth_hash[e.page.uri.host] = :ntlm
36
- fetch_page_without_ntlm(params)
37
- else
38
- raise
39
- end
40
- end
41
- end
42
- end