lib/net/ntlm.rb in rubyntlm-0.6.4 vs lib/net/ntlm.rb in rubyntlm-0.6.5
- old
+ new
@@ -164,10 +164,21 @@
decoded_password = EncodeUtil.decode_utf16le(password)
ntlmhash = [decoded_password.upcase[33,65]].pack('H32')
else
ntlmhash = ntlm_hash(password, opt)
end
- userdomain = user.upcase + target
+
+ if opt[:unicode]
+ # Uppercase operation on username containing non-ASCI characters
+ # after behing unicode encoded with `EncodeUtil.encode_utf16le`
+ # doesn't play well. Upcase should be done before encoding.
+ user_upcase = EncodeUtil.decode_utf16le(user).upcase
+ user_upcase = EncodeUtil.encode_utf16le(user_upcase)
+ else
+ user_upcase = user.upcase
+ end
+ userdomain = user_upcase + target
+
unless opt[:unicode]
userdomain = EncodeUtil.encode_utf16le(userdomain)
end
OpenSSL::HMAC.digest(OpenSSL::Digest::MD5.new, ntlmhash, userdomain)
end