rubyntlm 0.6.4 → 0.6.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e8301388316487463cdc7dece7772084e18b8935407fe769dc57c073a4d092a
4
- data.tar.gz: eb6610456e83f88a4a7ffc8f8372770efc601f8398ce85bd99240296ce0ed3bf
3
+ metadata.gz: 12b18439c86b30b978043850938e3ec611230d2e0783828d6db337dfe4ea97ad
4
+ data.tar.gz: 872a21844c21c9f64815abd312156c3fcddb8ebedc5185ec128106b6714b8521
5
5
  SHA512:
6
- metadata.gz: e77ad737f9292ee7662ae65ea6cceb137d3780e95831e1ff44a1a2f9b79dded84a1a80f84c4be8c1b1930991140b18ebb385f926a1f86ba11d9a981eb154bb2f
7
- data.tar.gz: d7f817bf3750b9cd8a47249f665dc618e40d94ec6b0bff410dbde2bc2906b53bf7a4f79f65f424d1d613e20a2055679254a779b0941d1284595a1bc10fa1d727
6
+ metadata.gz: 03df0639b70648b2db81684060ce732d46f21a392590f4995ddb4c97399036ffc8d9a47fd1460b64441a34bebdbabfbd1f3d625bf1246a9e178a0901770f0ee5
7
+ data.tar.gz: e3ff9341eb1738c501fe90d9456a8203e5771af2c459bb53f0168e24cbdd549540a0369d9a83f2864dce4fac86595cca4c7207b88f11a1b843d9fdbf52b59b20
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.6.5 (2024-06-11)
4
+
5
+ * Update available NegotiateFlags during authentication
6
+ * Fix NTLMv2 hash when username contains non-ASCII characters by @cdelafuente-r7 in https://github.com/WinRb/rubyntlm/pull/56
7
+
3
8
  ## 0.6.4 (2024-06-06)
4
9
 
5
10
  * Fix applying DES-CBC when using OpenSSL 3 by @paulvt in https://github.com/WinRb/rubyntlm/pull/51
@@ -39,7 +39,7 @@ module NTLM
39
39
  # the function will convert the string bytes to UTF-16LE and note the encoding as UTF-8 so that byte
40
40
  # concatination works seamlessly.
41
41
  def self.encode_utf16le(str)
42
- str.dup.force_encoding('UTF-8').encode(Encoding::UTF_16LE, Encoding::UTF_8).force_encoding('UTF-8')
42
+ str.dup.force_encoding('UTF-8').encode(Encoding::UTF_16LE, Encoding::UTF_8).force_encoding('ASCII-8BIT')
43
43
  end
44
44
  end
45
45
  end
@@ -3,28 +3,36 @@ module NTLM
3
3
 
4
4
  SSP_SIGN = "NTLMSSP\0"
5
5
 
6
+ # See [2.2.2.5 NEGOTIATE](https://msdn.microsoft.com/en-us/library/cc236650.aspx)
6
7
  FLAGS = {
7
8
  :UNICODE => 0x00000001,
8
9
  :OEM => 0x00000002,
9
10
  :REQUEST_TARGET => 0x00000004,
10
- :MBZ9 => 0x00000008,
11
11
  :SIGN => 0x00000010,
12
12
  :SEAL => 0x00000020,
13
13
  :NEG_DATAGRAM => 0x00000040,
14
- :NETWARE => 0x00000100,
14
+ :NEG_LM_KEY => 0x00000080,
15
15
  :NTLM => 0x00000200,
16
- :NEG_NT_ONLY => 0x00000400,
17
- :MBZ7 => 0x00000800,
16
+ :NEG_ANONYMOUS => 0x00000800,
18
17
  :DOMAIN_SUPPLIED => 0x00001000,
19
18
  :WORKSTATION_SUPPLIED => 0x00002000,
20
- :LOCAL_CALL => 0x00004000,
21
19
  :ALWAYS_SIGN => 0x00008000,
22
20
  :TARGET_TYPE_DOMAIN => 0x00010000,
21
+ :TARGET_TYPE_SERVER => 0x00020000,
23
22
  :NTLM2_KEY => 0x00080000,
23
+ :NEG_IDENTIFY => 0x00100000,
24
+ :NON_NT_SESSION_KEY => 0x00400000,
24
25
  :TARGET_INFO => 0x00800000,
26
+ :NEG_VERSION => 0x02000000,
25
27
  :KEY128 => 0x20000000,
26
28
  :KEY_EXCHANGE => 0x40000000,
27
- :KEY56 => 0x80000000
29
+ :KEY56 => 0x80000000,
30
+ # Undocumented flags:
31
+ :MBZ9 => 0x00000008,
32
+ :NETWARE => 0x00000100,
33
+ :NEG_NT_ONLY => 0x00000400,
34
+ :MBZ7 => 0x00000800, # alias for :NEG_ANONYMOUS
35
+ :LOCAL_CALL => 0x00004000,
28
36
  }.freeze
29
37
 
30
38
  FLAG_KEYS = FLAGS.keys.sort{|a, b| FLAGS[a] <=> FLAGS[b] }
@@ -4,7 +4,7 @@ module Net
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 6
7
- TINY = 4
7
+ TINY = 5
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
10
10
  end
data/lib/net/ntlm.rb CHANGED
@@ -166,7 +166,18 @@ module Net
166
166
  else
167
167
  ntlmhash = ntlm_hash(password, opt)
168
168
  end
169
- userdomain = user.upcase + target
169
+
170
+ if opt[:unicode]
171
+ # Uppercase operation on username containing non-ASCI characters
172
+ # after behing unicode encoded with `EncodeUtil.encode_utf16le`
173
+ # doesn't play well. Upcase should be done before encoding.
174
+ user_upcase = EncodeUtil.decode_utf16le(user).upcase
175
+ user_upcase = EncodeUtil.encode_utf16le(user_upcase)
176
+ else
177
+ user_upcase = user.upcase
178
+ end
179
+ userdomain = user_upcase + target
180
+
170
181
  unless opt[:unicode]
171
182
  userdomain = EncodeUtil.encode_utf16le(userdomain)
172
183
  end
@@ -222,7 +222,28 @@ describe Net::NTLM::Message::Type3 do
222
222
 
223
223
  end
224
224
 
225
- describe '.serialize' do
225
+ describe '#serialize' do
226
+ context 'when the username contains non-ASCI characters' do
227
+ let(:t3) {
228
+ t2 = Net::NTLM::Message::Type2.new
229
+ t2.response(
230
+ {
231
+ :user => 'Hélène',
232
+ :password => '123456',
233
+ :domain => ''
234
+ },
235
+ {
236
+ :ntlmv2 => true,
237
+ :workstation => 'testlab.local'
238
+ }
239
+ )
240
+ }
241
+
242
+ it 'serializes without error' do
243
+ expect { t3.serialize }.not_to raise_error
244
+ end
245
+ end
246
+
226
247
  subject(:message) { described_class.create(opts) }
227
248
  context 'with the UNICODE flag set' do
228
249
  let(:opts) { {lm_response: "\x00".b, ntlm_response: '', domain: '', workstation: '', user: '', flag: Net::NTLM::DEFAULT_FLAGS[:TYPE3] | Net::NTLM::FLAGS[:UNICODE] } }
@@ -59,6 +59,14 @@ describe Net::NTLM do
59
59
  end
60
60
  end
61
61
 
62
+ context 'when the username contains non-ASCI characters' do
63
+ let(:user) { 'юзер' }
64
+
65
+ it 'should return the correct ntlmv2 hash' do
66
+ expect(Net::NTLM::ntlmv2_hash(user, passwd, domain, { unicode: true })).to eq(["a0f4b914a37faeaee884b6b04a20faf0"].pack("H*"))
67
+ end
68
+ end
69
+
62
70
  it 'should generate an lm_response' do
63
71
  expect(Net::NTLM::lm_response(
64
72
  {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyntlm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Kajimoto
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-06-06 00:00:00.000000000 Z
12
+ date: 2024-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: github_changelog_generator