rubyntlm 0.3.4 → 0.4.0

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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +3 -0
  3. data/.travis.yml +0 -1
  4. data/LICENSE +20 -0
  5. data/Rakefile +8 -15
  6. data/lib/net/ntlm.rb +22 -654
  7. data/lib/net/ntlm/blob.rb +17 -0
  8. data/lib/net/ntlm/encode_util.rb +49 -0
  9. data/lib/net/ntlm/field.rb +35 -0
  10. data/lib/net/ntlm/field_set.rb +125 -0
  11. data/lib/net/ntlm/int16_le.rb +26 -0
  12. data/lib/net/ntlm/int32_le.rb +25 -0
  13. data/lib/net/ntlm/int64_le.rb +26 -0
  14. data/lib/net/ntlm/message.rb +115 -0
  15. data/lib/net/ntlm/message/type0.rb +16 -0
  16. data/lib/net/ntlm/message/type1.rb +43 -0
  17. data/lib/net/ntlm/message/type2.rb +126 -0
  18. data/lib/net/ntlm/message/type3.rb +68 -0
  19. data/lib/net/ntlm/security_buffer.rb +48 -0
  20. data/lib/net/ntlm/string.rb +35 -0
  21. data/lib/net/ntlm/version.rb +11 -0
  22. data/rubyntlm.gemspec +4 -1
  23. data/spec/lib/net/ntlm/blob_spec.rb +16 -0
  24. data/spec/lib/net/ntlm/encode_util_spec.rb +16 -0
  25. data/spec/lib/net/ntlm/field_set_spec.rb +33 -0
  26. data/spec/lib/net/ntlm/field_spec.rb +34 -0
  27. data/spec/lib/net/ntlm/int16_le_spec.rb +18 -0
  28. data/spec/lib/net/ntlm/int32_le_spec.rb +19 -0
  29. data/spec/lib/net/ntlm/int64_le_spec.rb +19 -0
  30. data/spec/lib/net/ntlm/message/type0_spec.rb +21 -0
  31. data/spec/lib/net/ntlm/message/type1_spec.rb +42 -0
  32. data/spec/lib/net/ntlm/message/type2_spec.rb +88 -0
  33. data/spec/lib/net/ntlm/message/type3_spec.rb +20 -0
  34. data/spec/lib/net/ntlm/message_spec.rb +17 -0
  35. data/spec/lib/net/ntlm/security_buffer_spec.rb +64 -0
  36. data/spec/lib/net/ntlm/string_spec.rb +72 -0
  37. data/spec/lib/net/ntlm/version_spec.rb +26 -0
  38. data/spec/lib/net/ntlm_spec.rb +121 -0
  39. data/spec/spec_helper.rb +21 -0
  40. data/spec/support/shared/examples/net/ntlm/field_shared.rb +25 -0
  41. data/spec/support/shared/examples/net/ntlm/fieldset_shared.rb +239 -0
  42. data/spec/support/shared/examples/net/ntlm/int_shared.rb +43 -0
  43. data/spec/support/shared/examples/net/ntlm/message_shared.rb +35 -0
  44. metadata +77 -5
  45. data/spec/unit/ntlm_spec.rb +0 -183
@@ -1,183 +0,0 @@
1
- # encoding: UTF-8
2
- $:.unshift(File.expand_path(File.dirname(__FILE__) << '../lib'))
3
-
4
- describe Net::NTLM::Message do
5
- let(:type1_packet) {"TlRMTVNTUAABAAAAB4IIAAAAAAAgAAAAAAAAACAAAAA="}
6
- let(:type2_packet) {"TlRMTVNTUAACAAAAHAAcADgAAAAFgooCJ+UA1//+ZM4AAAAAAAAAAJAAkABUAAAABgGxHQAAAA9WAEEARwBSAEEATgBUAC0AMgAwADAAOABSADIAAgAcAFYAQQBHAFIAQQBOAFQALQAyADAAMAA4AFIAMgABABwAVgBBAEcAUgBBAE4AVAAtADIAMAAwADgAUgAyAAQAHAB2AGEAZwByAGEAbgB0AC0AMgAwADAAOABSADIAAwAcAHYAYQBnAHIAYQBuAHQALQAyADAAMAA4AFIAMgAHAAgAZBMdFHQnzgEAAAAA"}
7
- let(:type3_packet) {"TlRMTVNTUAADAAAAGAAYAEQAAADAAMAAXAAAAAAAAAAcAQAADgAOABwBAAAUABQAKgEAAAAAAAA+AQAABYKKAgAAAADVS27TfQGmWxSSbXmolTUQyxJmD8ISQuBKKHFKC8GksUZISYc8Ps9RAQEAAAAAAAAANasTdCfOAcsSZg/CEkLgAAAAAAIAHABWAEEARwBSAEEATgBUAC0AMgAwADAAOABSADIAAQAcAFYAQQBHAFIAQQBOAFQALQAyADAAMAA4AFIAMgAEABwAdgBhAGcAcgBhAG4AdAAtADIAMAAwADgAUgAyAAMAHAB2AGEAZwByAGEAbgB0AC0AMgAwADAAOABSADIABwAIAGQTHRR0J84BAAAAAAAAAAB2AGEAZwByAGEAbgB0AGsAbwBiAGUALgBsAG8AYwBhAGwA"}
8
- describe Net::NTLM::Message::Type1 do
9
- it 'should deserialize' do
10
- t1 = Net::NTLM::Message.decode64(type1_packet)
11
- t1.class.should == Net::NTLM::Message::Type1
12
- t1.domain.should == ''
13
- t1.flag.should == 557575
14
- t1.padding.should == ''
15
- t1.sign.should == "NTLMSSP\0"
16
- t1.type.should == 1
17
- t1.workstation.should == ''
18
- end
19
-
20
- it 'should serialize' do
21
- t1 = Net::NTLM::Message::Type1.new
22
- t1.workstation = ''
23
- t1.encode64.should == type1_packet
24
- end
25
- end
26
-
27
- describe Net::NTLM::Message::Type2 do
28
- it 'should deserialize' do
29
- t2 = Net::NTLM::Message.decode64(type2_packet)
30
- t2.class.should == Net::NTLM::Message::Type2
31
- t2.challenge.should == 14872292244261496103
32
- t2.context.should == 0
33
- t2.flag.should == 42631685
34
- if "".respond_to?(:force_encoding)
35
- t2.padding.should == ("\x06\x01\xB1\x1D\0\0\0\x0F".force_encoding('ASCII-8BIT'))
36
- end
37
- t2.sign.should == "NTLMSSP\0"
38
-
39
- t2_target_info = Net::NTLM::EncodeUtil.decode_utf16le(t2.target_info)
40
- if RUBY_VERSION == "1.8.7"
41
- t2_target_info.should == "\x02\x1CVAGRANT-2008R2\x01\x1CVAGRANT-2008R2\x04\x1Cvagrant-2008R2\x03\x1Cvagrant-2008R2\a\b\e$(D+&\e(B\0\0"
42
- else
43
- t2_target_info.should == "\u0002\u001CVAGRANT-2008R2\u0001\u001CVAGRANT-2008R2\u0004\u001Cvagrant-2008R2\u0003\u001Cvagrant-2008R2\a\b፤ᐝ❴ǎ\0\0"
44
- end
45
-
46
- Net::NTLM::EncodeUtil.decode_utf16le(t2.target_name).should == "VAGRANT-2008R2"
47
- t2.type.should == 2
48
- end
49
-
50
- it 'should serialize' do
51
- source = Net::NTLM::Message.decode64(type2_packet)
52
-
53
- t2 = Net::NTLM::Message::Type2.new
54
- t2.challenge = source.challenge
55
- t2.context = source.context
56
- t2.flag = source.flag
57
- t2.padding = source.padding
58
- t2.sign = source.sign
59
- t2.target_info = source.target_info
60
- t2.target_name = source.target_name
61
- t2.type = source.type
62
- t2.enable(:context)
63
- t2.enable(:target_info)
64
- t2.enable(:padding)
65
-
66
- t2.encode64.should == type2_packet
67
- end
68
-
69
- it 'should generate a type 3 response' do
70
- t2 = Net::NTLM::Message.decode64(type2_packet)
71
-
72
- type3_known = Net::NTLM::Message.decode64(type3_packet)
73
- type3_known.flag = 0x028a8205
74
- type3_known.enable(:session_key)
75
- type3_known.enable(:flag)
76
-
77
- t3 = t2.response({:user => 'vagrant', :password => 'vagrant', :domain => ''}, {:ntlmv2 => true, :workstation => 'kobe.local'})
78
- t3.domain.should == type3_known.domain
79
- t3.flag.should == type3_known.flag
80
- t3.sign.should == "NTLMSSP\0"
81
- t3.workstation.should == "k\0o\0b\0e\0.\0l\0o\0c\0a\0l\0"
82
- t3.user.should == "v\0a\0g\0r\0a\0n\0t\0"
83
- t3.session_key.should == ''
84
- end
85
- end
86
- end
87
-
88
-
89
- describe Net::NTLM do
90
- let(:passwd) {"SecREt01"}
91
- let(:user) {"user"}
92
- let(:domain) {"domain"}
93
- let(:challenge) {["0123456789abcdef"].pack("H*")}
94
- let(:client_ch) {["ffffff0011223344"].pack("H*")}
95
- let(:timestamp) {1055844000}
96
- let(:trgt_info) {[
97
- "02000c0044004f004d00410049004e00" +
98
- "01000c00530045005200560045005200" +
99
- "0400140064006f006d00610069006e00" +
100
- "2e0063006f006d000300220073006500" +
101
- "72007600650072002e0064006f006d00" +
102
- "610069006e002e0063006f006d000000" +
103
- "0000"
104
- ].pack("H*")}
105
-
106
- it 'should generate an lm_hash' do
107
- Net::NTLM::lm_hash(passwd).should == ["ff3750bcc2b22412c2265b23734e0dac"].pack("H*")
108
- end
109
-
110
- it 'should generate an ntlm_hash' do
111
- Net::NTLM::ntlm_hash(passwd).should == ["cd06ca7c7e10c99b1d33b7485a2ed808"].pack("H*")
112
- end
113
-
114
- it 'should generate an ntlmv2_hash' do
115
- Net::NTLM::ntlmv2_hash(user, passwd, domain).should == ["04b8e0ba74289cc540826bab1dee63ae"].pack("H*")
116
- end
117
-
118
- it 'should generate an lm_response' do
119
- Net::NTLM::lm_response(
120
- {
121
- :lm_hash => Net::NTLM::lm_hash(passwd),
122
- :challenge => challenge
123
- }
124
- ).should == ["c337cd5cbd44fc9782a667af6d427c6de67c20c2d3e77c56"].pack("H*")
125
- end
126
-
127
- it 'should generate an ntlm_response' do
128
- ntlm_hash = Net::NTLM::ntlm_hash(passwd)
129
- Net::NTLM::ntlm_response(
130
- {
131
- :ntlm_hash => ntlm_hash,
132
- :challenge => challenge
133
- }
134
- ).should == ["25a98c1c31e81847466b29b2df4680f39958fb8c213a9cc6"].pack("H*")
135
- end
136
-
137
- it 'should generate a lvm2_response' do
138
- Net::NTLM::lmv2_response(
139
- {
140
- :ntlmv2_hash => Net::NTLM::ntlmv2_hash(user, passwd, domain),
141
- :challenge => challenge
142
- },
143
- { :client_challenge => client_ch }
144
- ).should == ["d6e6152ea25d03b7c6ba6629c2d6aaf0ffffff0011223344"].pack("H*")
145
- end
146
-
147
- it 'should generate a ntlmv2_response' do
148
- Net::NTLM::ntlmv2_response(
149
- {
150
- :ntlmv2_hash => Net::NTLM::ntlmv2_hash(user, passwd, domain),
151
- :challenge => challenge,
152
- :target_info => trgt_info
153
- },
154
- {
155
- :timestamp => timestamp,
156
- :client_challenge => client_ch
157
- }
158
- ).should == [
159
- "cbabbca713eb795d04c97abc01ee4983" +
160
- "01010000000000000090d336b734c301" +
161
- "ffffff00112233440000000002000c00" +
162
- "44004f004d00410049004e0001000c00" +
163
- "53004500520056004500520004001400" +
164
- "64006f006d00610069006e002e006300" +
165
- "6f006d00030022007300650072007600" +
166
- "650072002e0064006f006d0061006900" +
167
- "6e002e0063006f006d00000000000000" +
168
- "0000"
169
- ].pack("H*")
170
- end
171
-
172
- it 'should generate a ntlm2_session' do
173
- session = Net::NTLM::ntlm2_session(
174
- {
175
- :ntlm_hash => Net::NTLM::ntlm_hash(passwd),
176
- :challenge => challenge
177
- },
178
- { :client_challenge => client_ch }
179
- )
180
- session[0].should == ["ffffff001122334400000000000000000000000000000000"].pack("H*")
181
- session[1].should == ["10d550832d12b2ccb79d5ad1f4eed3df82aca4c3681dd455"].pack("H*")
182
- end
183
- end