rubyntlm 0.6.5 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +48 -48
  4. data/lib/net/ntlm/blob.rb +11 -10
  5. data/lib/net/ntlm/channel_binding.rb +13 -9
  6. data/lib/net/ntlm/client/session.rb +34 -141
  7. data/lib/net/ntlm/client/session_crypto.rb +126 -0
  8. data/lib/net/ntlm/client.rb +8 -9
  9. data/lib/net/ntlm/encode_util.rb +39 -38
  10. data/lib/net/ntlm/exceptions.rb +3 -0
  11. data/lib/net/ntlm/field.rb +29 -31
  12. data/lib/net/ntlm/field_set.rb +39 -18
  13. data/lib/net/ntlm/int16_le.rb +8 -8
  14. data/lib/net/ntlm/int32_le.rb +8 -7
  15. data/lib/net/ntlm/int64_le.rb +8 -7
  16. data/lib/net/ntlm/md4.rb +102 -63
  17. data/lib/net/ntlm/message/type0.rb +4 -7
  18. data/lib/net/ntlm/message/type1.rb +8 -9
  19. data/lib/net/ntlm/message/type2.rb +87 -67
  20. data/lib/net/ntlm/message/type3.rb +49 -59
  21. data/lib/net/ntlm/message.rb +116 -111
  22. data/lib/net/ntlm/rc4.rb +51 -44
  23. data/lib/net/ntlm/response.rb +112 -0
  24. data/lib/net/ntlm/security_buffer.rb +13 -15
  25. data/lib/net/ntlm/string.rb +8 -7
  26. data/lib/net/ntlm/target_info.rb +52 -44
  27. data/lib/net/ntlm/version.rb +3 -1
  28. data/lib/net/ntlm.rb +37 -125
  29. data/lib/rubyntlm.rb +3 -1
  30. metadata +10 -141
  31. data/.devcontainer/devcontainer.json +0 -22
  32. data/.github/dependabot.yml +0 -10
  33. data/.github/workflows/build.yml +0 -24
  34. data/.gitignore +0 -5
  35. data/.rspec +0 -2
  36. data/Gemfile +0 -3
  37. data/Rakefile +0 -25
  38. data/examples/http.rb +0 -86
  39. data/examples/imap.rb +0 -73
  40. data/examples/smtp.rb +0 -94
  41. data/rubyntlm.gemspec +0 -31
  42. data/spec/lib/net/ntlm/blob_spec.rb +0 -16
  43. data/spec/lib/net/ntlm/channel_binding_spec.rb +0 -17
  44. data/spec/lib/net/ntlm/client/session_spec.rb +0 -87
  45. data/spec/lib/net/ntlm/client_spec.rb +0 -64
  46. data/spec/lib/net/ntlm/encode_util_spec.rb +0 -16
  47. data/spec/lib/net/ntlm/field_set_spec.rb +0 -33
  48. data/spec/lib/net/ntlm/field_spec.rb +0 -34
  49. data/spec/lib/net/ntlm/int16_le_spec.rb +0 -18
  50. data/spec/lib/net/ntlm/int32_le_spec.rb +0 -19
  51. data/spec/lib/net/ntlm/int64_le_spec.rb +0 -19
  52. data/spec/lib/net/ntlm/message/type0_spec.rb +0 -21
  53. data/spec/lib/net/ntlm/message/type1_spec.rb +0 -131
  54. data/spec/lib/net/ntlm/message/type2_spec.rb +0 -132
  55. data/spec/lib/net/ntlm/message/type3_spec.rb +0 -267
  56. data/spec/lib/net/ntlm/message_spec.rb +0 -17
  57. data/spec/lib/net/ntlm/security_buffer_spec.rb +0 -64
  58. data/spec/lib/net/ntlm/string_spec.rb +0 -72
  59. data/spec/lib/net/ntlm/target_info_spec.rb +0 -76
  60. data/spec/lib/net/ntlm/version_spec.rb +0 -27
  61. data/spec/lib/net/ntlm_spec.rb +0 -135
  62. data/spec/spec_helper.rb +0 -22
  63. data/spec/support/certificates/sha_256_hash.pem +0 -19
  64. data/spec/support/shared/examples/net/ntlm/field_shared.rb +0 -25
  65. data/spec/support/shared/examples/net/ntlm/fieldset_shared.rb +0 -239
  66. data/spec/support/shared/examples/net/ntlm/int_shared.rb +0 -43
  67. data/spec/support/shared/examples/net/ntlm/message_shared.rb +0 -35
data/examples/imap.rb DELETED
@@ -1,73 +0,0 @@
1
- # $Id: imap.rb,v 1.1 2006/10/05 01:36:52 koheik Exp $
2
-
3
- require "net/imap"
4
- $:.unshift(File.dirname(__FILE__) + '/../lib')
5
- require "net/ntlm"
6
-
7
- Net::IMAP::debug = true
8
-
9
- $host = "localhost"
10
- $port = 143
11
- $ssl = false
12
- $user = nil
13
- $passwd = nil
14
-
15
- module Net
16
- class IMAP
17
- class NtlmAuthenticator
18
- def process(data)
19
- case @state
20
- when 1
21
- @state = 2
22
- t1 = Net::NTLM::Message::Type1.new()
23
- return t1.serialize
24
- when 2
25
- @state = 3
26
- t2 = Net::NTLM::Message.parse(data)
27
- t3 = t2.response({:user => @user, :password => @password}, {:ntlmv2 => (@ntlm_type == "ntlmv2")})
28
- return t3.serialize
29
- end
30
- end
31
-
32
- private
33
-
34
- def initialize(user, password, ntlm_type = "ntlmv2")
35
- @user = user
36
- @password = password
37
- @ntlm_type = @ntlm_type
38
- @state = 1
39
- end
40
- end
41
- add_authenticator "NTLM", NtlmAuthenticator
42
-
43
- class ResponseParser
44
- def continue_req
45
- match(T_PLUS)
46
- if lookahead.symbol == T_CRLF # means empty message
47
- return ContinuationRequest.new(ResponseText.new(nil, ""), @str)
48
- end
49
- match(T_SPACE)
50
- return ContinuationRequest.new(resp_text, @str)
51
- end
52
- end
53
- end
54
- end
55
-
56
- unless $user and $passwd
57
- print "User name: "
58
- ($user = $stdin.readline).chomp!
59
- print "Password: "
60
- ($passwd = $stdin.readline).chomp!
61
- end
62
-
63
- imap = Net::IMAP.new($host, $port, $ssl)
64
- imap.authenticate("NTLM", $user, $passwd)
65
- imap.examine("Inbox")
66
- # imap.search(["RECENT"]).each do |message_id|
67
- # envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
68
- # from = envelope.from.nil? ? "" : envelope.from[0].name
69
- # subject = envelope.subject
70
- # puts "#{message_id} #{from}: \t#{subject}"
71
- # end
72
- imap.logout
73
- # imap.disconnect
data/examples/smtp.rb DELETED
@@ -1,94 +0,0 @@
1
- # $Id: smtp.rb,v 1.2 2006/10/05 01:36:52 koheik Exp $
2
- require 'socket'
3
- $:.unshift(File.dirname(__FILE__) + '/../lib')
4
- require 'net/ntlm'
5
-
6
- $user = nil
7
- $passwd = nil
8
-
9
- $host = "localhost"
10
- $port = 25
11
-
12
- $debug = true
13
-
14
- def readline(f)
15
- (l = f.gets).chomp!
16
- puts "srv> " + l if $debug
17
- l
18
- end
19
-
20
- def writeline(f, str)
21
- puts "cli> " + str if $debug
22
- f.print str + "\r\n"
23
- end
24
-
25
- def main
26
- s = TCPSocket.new($host, $port)
27
-
28
- # greetings
29
- readline s
30
- writeline s, "EHLO #{$host}"
31
- while(line = readline(s))
32
- login = true if /^250-AUTH=LOGIN/ =~ line
33
- ntlm = true if /^250-AUTH.+NTLM.*/ =~ line
34
- break if /^250 OK/ =~ line
35
- end
36
- unless ntlm and login
37
- raise RuntimeError, "it looks like the server doesn't support NTLM Login"
38
- end
39
-
40
- # send Type1 Message
41
- t1 = Net::NTLM::Message::Type1.new()
42
- writeline s, "AUTH NTLM " + t1.encode64
43
-
44
- # receive Type2 Message, i hope
45
- line = readline s
46
- unless /334 (.+)/ =~ line
47
- raise RuntimeError, "i don't recognize this: #{line}"
48
- end
49
- t2 = Net::NTLM::Message.decode64($1)
50
-
51
- unless $user and $passwd
52
- target = t2.target_name
53
- target = Net::NTLM::decode_utf16le(target) if t2.has_flag?(:UNICODE)
54
- puts "Target: #{target}"
55
- print "User name: "
56
- ($user = $stdin.readline).chomp!
57
- print "Password: "
58
- ($passwd = $stdin.readline).chomp!
59
- end
60
-
61
- # send Type3 Message
62
- t3 = t2.response({:user => $user, :password => $passwd}, {:ntlmv2 => true})
63
- writeline s, t3.encode64
64
-
65
- # and result is...
66
- line = readline s
67
-
68
- unless /^235(.+)Authentication successful./i =~ line
69
- raise RuntimeError, "sorry, authentication failed."
70
- end
71
-
72
- # do real job here like...
73
- # from = $user
74
- # to = "billg"
75
- # writeline s, "MAIL FROM: #{from}"
76
- # readline s
77
- # writeline s, "RCPT TO: #{to}"
78
- # readline s
79
- # writeline s, "DATA"
80
- # readline s
81
- # writeline s, "From: #{from}"
82
- # writeline s, "To: #{to}"
83
- # writeline s, "blab blab blab..."
84
- # writeline s, "#{from}"
85
- # writeline s, "."
86
- # readline s
87
-
88
- # say bye
89
- writeline s, "QUIT"
90
- s.close
91
- end
92
-
93
- main
94
-
data/rubyntlm.gemspec DELETED
@@ -1,31 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'lib', 'net', 'ntlm', 'version')
2
-
3
- Gem::Specification.new do |s|
4
- s.platform = Gem::Platform::RUBY
5
- s.name = 'rubyntlm'
6
- s.version = Net::NTLM::VERSION::STRING
7
- s.summary = 'Ruby/NTLM library.'
8
- s.description = 'Ruby/NTLM provides message creator and parser for the NTLM authentication.'
9
-
10
- s.authors = ['Kohei Kajimoto','Paul Morton']
11
- s.email = ['koheik@gmail.com','paul.e.morton@gmail.com']
12
- s.homepage = 'https://github.com/winrb/rubyntlm'
13
-
14
-
15
- s.files = `git ls-files`.split($/)
16
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
- s.require_paths = ["lib"]
18
-
19
- s.required_ruby_version = '>= 2.6.0'
20
-
21
- s.license = 'MIT'
22
-
23
- s.add_development_dependency 'github_changelog_generator', '1.14.3'
24
- s.add_development_dependency "pry"
25
- s.add_development_dependency "rake"
26
- s.add_development_dependency "rspec", ">= 2.11"
27
- s.add_development_dependency "simplecov"
28
- s.add_dependency "base64"
29
-
30
- s.metadata["rubygems_mfa_required"] = "true"
31
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::NTLM::Blob do
4
-
5
- fields = [
6
- { :name => :blob_signature, :class => Net::NTLM::Int32LE, :value => 257, :active => true },
7
- { :name => :reserved, :class => Net::NTLM::Int32LE, :value => 0, :active => true },
8
- { :name => :timestamp, :class => Net::NTLM::Int64LE, :value => 0, :active => true },
9
- { :name => :challenge, :class => Net::NTLM::String, :value => '', :active => true },
10
- { :name => :unknown1, :class => Net::NTLM::Int32LE, :value => 0, :active => true },
11
- { :name => :target_info, :class => Net::NTLM::String, :value => '', :active => true },
12
- { :name => :unknown2, :class => Net::NTLM::Int32LE, :value => 0, :active => true },
13
- ]
14
-
15
- it_behaves_like 'a fieldset', fields
16
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::NTLM::ChannelBinding do
4
- let(:certificates_path) { 'spec/support/certificates' }
5
- let(:sha_256_path) { File.join(certificates_path, 'sha_256_hash.pem') }
6
- let(:sha_256_cert) { OpenSSL::X509::Certificate.new(File.read(sha_256_path)) }
7
- let(:cert_hash) { "\x04\x0E\x56\x28\xEC\x4A\x98\x29\x91\x70\x73\x62\x03\x7B\xB2\x3C".force_encoding(Encoding::ASCII_8BIT) }
8
-
9
- subject { Net::NTLM::ChannelBinding.create(sha_256_cert) }
10
-
11
- describe '#channel_binding_token' do
12
-
13
- it 'returns the correct hash' do
14
- expect(subject.channel_binding_token).to eq cert_hash
15
- end
16
- end
17
- end
@@ -1,87 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::NTLM::Client::Session do
4
- let(:t2_challenge) { Net::NTLM::Message.decode64 "TlRMTVNTUAACAAAADAAMADgAAAA1goriAAyk1DmJUnUAAAAAAAAAAFAAUABEAAAABgLwIwAAAA9TAEUAUgBWAEUAUgACAAwAUwBFAFIAVgBFAFIAAQAMAFMARQBSAFYARQBSAAQADABzAGUAcgB2AGUAcgADAAwAcwBlAHIAdgBlAHIABwAIADd7mrNaB9ABAAAAAA==" }
5
- let(:inst) { Net::NTLM::Client::Session.new(nil, t2_challenge) }
6
- let(:user_session_key) {["3c4918ff0b33e2603e5d7ceaf34bb7d5"].pack("H*")}
7
- let(:client_sign_key) {["f7f97a82ec390f9c903dac4f6aceb132"].pack("H*")}
8
- let(:client_seal_key) {["6f0d99535033951cbe499cd1914fe9ee"].pack("H*")}
9
- let(:server_sign_key) {["f7f97a82ec390f9c903dac4f6aceb132"].pack("H*")}
10
- let(:server_seal_key) {["6f0d99535033951cbe499cd1914fe9ee"].pack("H*")}
11
-
12
- describe "#sign_message" do
13
-
14
- it "signs a message and when KEY_EXCHANGE is true" do
15
- expect(inst).to receive(:client_sign_key).and_return(client_sign_key)
16
- expect(inst).to receive(:client_seal_key).and_return(client_seal_key)
17
- expect(inst).to receive(:negotiate_key_exchange?).and_return(true)
18
- sm = inst.sign_message("Test Message")
19
- str = "01000000b35ccd60c110c52f00000000"
20
- expect(sm.unpack("H*")[0]).to eq(str)
21
- end
22
-
23
- end
24
-
25
- describe "#verify_signature" do
26
-
27
- it "verifies a message signature" do
28
- expect(inst).to receive(:server_sign_key).and_return(server_sign_key)
29
- expect(inst).to receive(:server_seal_key).and_return(server_seal_key)
30
- expect(inst).to receive(:negotiate_key_exchange?).and_return(true)
31
- sig = "01000000b35ccd60c110c52f00000000"
32
- sm = inst.verify_signature([sig].pack("H*"), "Test Message")
33
- expect(sm).to be true
34
- end
35
-
36
- end
37
-
38
- describe "#seal_message" do
39
- it "should seal the message" do
40
- expect(inst).to receive(:client_seal_key).and_return(client_seal_key)
41
- emsg = inst.seal_message("rubyntlm")
42
- expect(emsg.unpack("H*")[0]).to eq("d7389b9604f6274f")
43
- end
44
- end
45
-
46
- describe "#unseal_message" do
47
- it "should unseal the message" do
48
- expect(inst).to receive(:server_seal_key).and_return(server_seal_key)
49
- msg = inst.unseal_message(["d7389b9604f6274f"].pack("H*"))
50
- expect(msg).to eq("rubyntlm")
51
- end
52
- end
53
-
54
- describe "#exported_session_key" do
55
- it "returns a random 16-byte key when negotiate_key_exchange? is true" do
56
- expect(inst).to receive(:negotiate_key_exchange?).and_return(true)
57
- expect(inst).not_to receive(:user_session_key)
58
- inst.exported_session_key
59
- end
60
-
61
- it "returns the user_session_key when negotiate_key_exchange? is false" do
62
- expect(inst).to receive(:negotiate_key_exchange?).and_return(false)
63
- expect(inst).to receive(:user_session_key).and_return(user_session_key)
64
- inst.exported_session_key
65
- end
66
- end
67
-
68
- context 'when authenticating anonymously' do
69
- let(:inst) { Net::NTLM::Client::Session.new(Net::NTLM::Client.new('', ''), t2_challenge) }
70
-
71
- describe "#authenticate!" do
72
- it "should set the response fields correctly" do
73
- t3 = inst.authenticate!
74
- expect(t3).to be_a(Net::NTLM::Message::Type3)
75
- expect(t3.lm_response).to eq("\x00".b)
76
- expect(t3.ntlm_response).to eq('')
77
- end
78
- end
79
-
80
- describe "#is_anonymous?" do
81
- it "should be true" do
82
- expect(inst.is_anonymous?).to be_truthy
83
- end
84
- end
85
- end
86
-
87
- end
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::NTLM::Client do
4
- let(:inst) { Net::NTLM::Client.new("test", "test01", :workstation => "testhost") }
5
- let(:user_session_key) {["3c4918ff0b33e2603e5d7ceaf34bb7d5"].pack("H*")}
6
-
7
- describe "#init_context" do
8
-
9
- it "returns a default Type1 message" do
10
- t1 = inst.init_context
11
- expect(t1).to be_instance_of Net::NTLM::Message::Type1
12
- expect(t1.domain).to eq("")
13
- expect(t1.workstation).to eq("testhost")
14
- expect(t1).to have_flag(:UNICODE)
15
- expect(t1).to have_flag(:OEM)
16
- expect(t1).to have_flag(:SIGN)
17
- expect(t1).to have_flag(:SEAL)
18
- expect(t1).to have_flag(:REQUEST_TARGET)
19
- expect(t1).to have_flag(:NTLM)
20
- expect(t1).to have_flag(:ALWAYS_SIGN)
21
- expect(t1).to have_flag(:NTLM2_KEY)
22
- expect(t1).to have_flag(:KEY128)
23
- expect(t1).to have_flag(:KEY_EXCHANGE)
24
- expect(t1).to have_flag(:KEY56)
25
- end
26
-
27
- it "clears session variable on new init_context" do
28
- inst.instance_variable_set :@session, "BADSESSION"
29
- expect(inst.session).to eq("BADSESSION")
30
- inst.init_context
31
- expect(inst.session).to be_nil
32
- end
33
-
34
- it "returns a Type1 message with custom flags" do
35
- flags = Net::NTLM::FLAGS[:UNICODE] | Net::NTLM::FLAGS[:REQUEST_TARGET] | Net::NTLM::FLAGS[:NTLM]
36
- inst = Net::NTLM::Client.new("test", "test01", :workstation => "testhost", :flags => flags)
37
- t1 = inst.init_context
38
- expect(t1).to be_instance_of Net::NTLM::Message::Type1
39
- expect(t1.domain).to eq("")
40
- expect(t1.workstation).to eq("testhost")
41
- expect(t1).to have_flag(:UNICODE)
42
- expect(t1).not_to have_flag(:OEM)
43
- expect(t1).not_to have_flag(:SIGN)
44
- expect(t1).not_to have_flag(:SEAL)
45
- expect(t1).to have_flag(:REQUEST_TARGET)
46
- expect(t1).to have_flag(:NTLM)
47
- expect(t1).not_to have_flag(:ALWAYS_SIGN)
48
- expect(t1).not_to have_flag(:NTLM2_KEY)
49
- expect(t1).not_to have_flag(:KEY128)
50
- expect(t1).not_to have_flag(:KEY_EXCHANGE)
51
- expect(t1).not_to have_flag(:KEY56)
52
- end
53
-
54
- it "calls authenticate! when we receive a Challenge Message" do
55
- t2_challenge = "TlRMTVNTUAACAAAADAAMADgAAAA1goriAAyk1DmJUnUAAAAAAAAAAFAAUABEAAAABgLwIwAAAA9TAEUAUgBWAEUAUgACAAwAUwBFAFIAVgBFAFIAAQAMAFMARQBSAFYARQBSAAQADABzAGUAcgB2AGUAcgADAAwAcwBlAHIAdgBlAHIABwAIADd7mrNaB9ABAAAAAA=="
56
- session = double("session")
57
- expect(session).to receive(:authenticate!)
58
- expect(Net::NTLM::Client::Session).to receive(:new).with(inst, instance_of(Net::NTLM::Message::Type2), nil).and_return(session)
59
- inst.init_context t2_challenge
60
- end
61
-
62
- end
63
-
64
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::NTLM::EncodeUtil do
4
-
5
- context '#encode_utf16le' do
6
- it 'should convert an ASCII string to UTF' do
7
- expect(Net::NTLM::EncodeUtil.encode_utf16le('Test'.encode(::Encoding::ASCII_8BIT).freeze)).to eq("T\x00e\x00s\x00t\x00")
8
- end
9
- end
10
-
11
- context '#decode_utf16le' do
12
- it 'should convert a UTF string to ASCII' do
13
- expect(Net::NTLM::EncodeUtil.decode_utf16le("T\x00e\x00s\x00t\x00".freeze)).to eq('Test')
14
- end
15
- end
16
- end
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::NTLM::FieldSet do
4
-
5
- fields = []
6
-
7
- it_behaves_like 'a fieldset', fields
8
-
9
- subject(:fieldset_class) do
10
- Class.new(Net::NTLM::FieldSet)
11
- end
12
-
13
- context 'an instance' do
14
- subject(:fieldset_object) do
15
- fieldset_class.string(:test_string, { :value => 'Test', :active => true, :size => 4})
16
- fieldset_class.string(:test_string2, { :value => 'Foo', :active => true, :size => 3})
17
- fieldset_class.new
18
- end
19
-
20
- it 'should serialize all the fields' do
21
- expect(fieldset_object.serialize).to eq('TestFoo')
22
- end
23
-
24
- it 'should parse a string across the fields' do
25
- fieldset_object.parse('FooBarBaz')
26
- expect(fieldset_object.serialize).to eq('FooBarB')
27
- end
28
-
29
- it 'should return an aggregate size of all the fields' do
30
- expect(fieldset_object.size).to eq(7)
31
- end
32
- end
33
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::NTLM::Field do
4
-
5
- it_behaves_like 'a field', 'Foo', false
6
-
7
- context 'with no size specified' do
8
- let (:field_without_size) { Net::NTLM::Field.new({ :value => 'Foo', :active => true }) }
9
- it 'should set size to 0 if not active' do
10
- expect(field_without_size.size).to eq(0)
11
- end
12
-
13
- it 'should return 0 if active but no size specified' do
14
- field_without_size.active = true
15
- expect(field_without_size.size).to eq(0)
16
- end
17
- end
18
-
19
- context 'with a size specified' do
20
- let (:field_with_size) { Net::NTLM::Field.new({ :value => 'Foo', :active => true, :size => 100 }) }
21
-
22
- it 'should return the size provided in the initialize options if active' do
23
- expect(field_with_size.size).to eq(100)
24
- end
25
-
26
- it 'should still return 0 if not active' do
27
- field_with_size.active = false
28
- expect(field_with_size.size).to eq(0)
29
- end
30
- end
31
-
32
-
33
-
34
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::NTLM::Int16LE do
4
-
5
- int_values = {
6
- :default => 15,
7
- :default_hex => "\x0F\x00",
8
- :alt => 14,
9
- :alt_hex => "\x0E\x00",
10
- :small => "\x0F",
11
- :size => 2,
12
- :bits => 16
13
- }
14
-
15
- it_behaves_like 'a field', 15, false
16
- it_behaves_like 'an integer field', int_values
17
-
18
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::NTLM::Int32LE do
4
-
5
- int_values = {
6
- :default => 252716124,
7
- :default_hex => "\x5C\x24\x10\x0f",
8
- :alt => 235938908,
9
- :alt_hex => "\x5C\x24\x10\x0e",
10
- :small => "\x0F\x00",
11
- :size => 4,
12
- :bits => 32
13
- }
14
-
15
-
16
- it_behaves_like 'a field', 252716124, false
17
- it_behaves_like 'an integer field', int_values
18
-
19
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::NTLM::Int64LE do
4
-
5
- int_values = {
6
- :default => 5294967295,
7
- :default_hex => [5294967295 & 0x00000000ffffffff, 5294967295 >> 32].pack("V2"),
8
- :alt => 5294967294,
9
- :alt_hex => [5294967294 & 0x00000000ffffffff, 5294967294 >> 32].pack("V2"),
10
- :small => "\x5C\x24\x10\x0f",
11
- :size => 8,
12
- :bits => 64
13
- }
14
-
15
-
16
- it_behaves_like 'a field', 252716124, false
17
- it_behaves_like 'an integer field', int_values
18
-
19
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::NTLM::Message::Type0 do
4
-
5
- fields = [
6
- { :name => :sign, :class => Net::NTLM::String, :value => Net::NTLM::SSP_SIGN, :active => true },
7
- { :name => :type, :class => Net::NTLM::Int32LE, :value => 0, :active => true },
8
- ]
9
- flags = [
10
- :UNICODE,
11
- :OEM,
12
- :REQUEST_TARGET,
13
- :NTLM,
14
- :ALWAYS_SIGN,
15
- :NTLM2_KEY
16
- ]
17
- it_behaves_like 'a fieldset', fields
18
- it_behaves_like 'a message', flags
19
-
20
-
21
- end
@@ -1,131 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::NTLM::Message::Type1 do
4
- fields = [
5
- { :name => :sign, :class => Net::NTLM::String, :value => Net::NTLM::SSP_SIGN, :active => true },
6
- { :name => :type, :class => Net::NTLM::Int32LE, :value => 1, :active => true },
7
- { :name => :flag, :class => Net::NTLM::Int32LE, :value => Net::NTLM::DEFAULT_FLAGS[:TYPE1], :active => true },
8
- { :name => :domain, :class => Net::NTLM::SecurityBuffer, :value => '', :active => true },
9
- { :name => :workstation, :class => Net::NTLM::SecurityBuffer, :value => Socket.gethostname, :active => true },
10
- { :name => :os_version, :class => Net::NTLM::String, :value => '', :active => false },
11
- ]
12
- flags = [
13
- :UNICODE,
14
- :OEM,
15
- :REQUEST_TARGET,
16
- :NTLM,
17
- :ALWAYS_SIGN,
18
- :NTLM2_KEY
19
- ]
20
- it_behaves_like 'a fieldset', fields
21
- it_behaves_like 'a message', flags
22
-
23
- let(:type1_packet) {"TlRMTVNTUAABAAAAB4IIAAAAAAAgAAAAAAAAACAAAAA="}
24
-
25
- it 'should deserialize' do
26
- t1 = Net::NTLM::Message.decode64(type1_packet)
27
- expect(t1.class).to eq(Net::NTLM::Message::Type1)
28
- expect(t1.domain).to eq('')
29
- expect(t1.flag).to eq(557575)
30
- expect(t1.os_version).to eq('')
31
- expect(t1.sign).to eq("NTLMSSP\0")
32
- expect(t1.type).to eq(1)
33
- expect(t1.workstation).to eq('')
34
- end
35
-
36
- it 'should serialize' do
37
- t1 = Net::NTLM::Message::Type1.new
38
- t1.workstation = ''
39
- expect(t1.encode64).to eq(type1_packet)
40
- end
41
-
42
- describe '.parse' do
43
- subject(:message) { described_class.parse(data) }
44
- # http://davenport.sourceforge.net/ntlm.html#appendixC7
45
- context 'NTLM2 Session Response Authentication; NTLM2 Signing and Sealing Using the 128-bit NTLM2 Session Response User Session Key With Key Exchange Negotiated' do
46
- let(:data) do
47
- ['4e544c4d5353500001000000b78208e000000000000000000000000000000000'].pack('H*')
48
- end
49
-
50
- it 'should set the magic' do
51
- expect(message.sign).to eql(Net::NTLM::SSP_SIGN)
52
- end
53
- it 'should set the type' do
54
- expect(message.type).to eq(1)
55
- end
56
- it 'should set the flags' do
57
- expect(message.flag).to eq(0xe00882b7)
58
- expect(message).to have_flag(:UNICODE)
59
- expect(message).to have_flag(:OEM)
60
- expect(message).to have_flag(:REQUEST_TARGET)
61
- expect(message).to have_flag(:SIGN)
62
- expect(message).to have_flag(:SEAL)
63
- expect(message).to have_flag(:NTLM)
64
- expect(message).to have_flag(:ALWAYS_SIGN)
65
- expect(message).to have_flag(:NTLM2_KEY)
66
- expect(message).to have_flag(:KEY128)
67
- expect(message).to have_flag(:KEY_EXCHANGE)
68
- expect(message).to have_flag(:KEY56)
69
- end
70
- it 'should have empty workstation' do
71
- expect(message.workstation).to be_empty
72
- end
73
- it 'should have empty domain' do
74
- expect(message.domain).to be_empty
75
- end
76
-
77
- end
78
-
79
- # http://davenport.sourceforge.net/ntlm.html#appendixC9
80
- context 'NTLMv2 Authentication; NTLM1 Signing and Sealing Using the 40-bit NTLMv2 User Session Key' do
81
- let(:data) { ['4e544c4d53535000010000003782000000000000000000000000000000000000'].pack('H*') }
82
-
83
- it 'should set the magic' do
84
- expect(message.sign).to eql(Net::NTLM::SSP_SIGN)
85
- end
86
- it 'should set the type' do
87
- expect(message.type).to eq(1)
88
- end
89
- it 'should set the flags' do
90
- expect(message.flag).to eq(0x00008237)
91
- expect(message).to have_flag(:UNICODE)
92
- expect(message).to have_flag(:OEM)
93
- expect(message).to have_flag(:REQUEST_TARGET)
94
- expect(message).to have_flag(:SIGN)
95
- expect(message).to have_flag(:SEAL)
96
- expect(message).to have_flag(:NTLM)
97
- expect(message).to have_flag(:ALWAYS_SIGN)
98
- end
99
- it 'should have empty workstation' do
100
- expect(message.workstation).to be_empty
101
- end
102
- it 'should have empty domain' do
103
- expect(message.domain).to be_empty
104
- end
105
- end
106
-
107
- context 'NTLMv2 with OS version' do
108
- let(:data) { ['4e544c4d5353500001000000978208e2000000000000000000000000000000000602f0230000000f'].pack('H*') }
109
-
110
- it 'should set the magic' do
111
- expect(message.sign).to eql(Net::NTLM::SSP_SIGN)
112
- end
113
- it 'should set the type' do
114
- expect(message.type).to eq(1)
115
- end
116
- it 'should have empty workstation' do
117
- expect(message.workstation).to be_empty
118
- end
119
- it 'should have empty domain' do
120
- expect(message.domain).to be_empty
121
- end
122
-
123
- it 'should set OS version info' do
124
- expect(message.os_version).to eq(['0602f0230000000f'].pack('H*'))
125
- end
126
-
127
- end
128
-
129
- end
130
-
131
- end