1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
module Net
module NTLM
class Client
DEFAULT_FLAGS = NTLM::FLAGS[:UNICODE] | NTLM::FLAGS[:OEM] |
NTLM::FLAGS[:SIGN] | NTLM::FLAGS[:SEAL] | NTLM::FLAGS[:REQUEST_TARGET] |
NTLM::FLAGS[:NTLM] | NTLM::FLAGS[:ALWAYS_SIGN] | NTLM::FLAGS[:NTLM2_KEY] |
NTLM::FLAGS[:KEY128] | NTLM::FLAGS[:KEY_EXCHANGE] | NTLM::FLAGS[:KEY56]
attr_reader :username, :password, :domain, :workstation, :flags
# @note All string parameters should be encoded in UTF-8. The proper
# final encoding for placing in the various {Message messages} will be
# chosen based on negotiation with the server.
#
# @param username [String]
# @param password [String]
# @option opts [String] :domain where we're authenticating to
# @option opts [String] :workstation local workstation name
# @option opts [Fixnum] :flags (DEFAULT_FLAGS) see Net::NTLM::Message::Type1.flag
def initialize(username, password, opts = {})
@username = username
@password = password
@domain = opts[:domain] || nil
@workstation = opts[:workstation] || nil
@flags = opts[:flags] || DEFAULT_FLAGS
end
# @return [NTLM::Message]
def init_context(resp = nil, channel_binding = nil)
if resp.nil?
@session = nil
type1_message
else
@session = Client::Session.new(self, Net::NTLM::Message.decode64(resp), channel_binding)
@session.authenticate!
end
end
# @return [Client::Session]
def session
@session
end
def session_key
@session.exported_session_key
end
private
# @return [Message::Type1]
def type1_message
type1 = Message::Type1.new
type1[:flag].value = flags
type1.domain = domain if domain
type1.workstation = workstation if workstation
type1
end
end
end
end
require "net/ntlm/client/session"
|