Class: NTLM::Message

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/ntlm/message.rb

Direct Known Subclasses

Authenticate, Challenge, Negotiate

Defined Under Namespace

Classes: Authenticate, Challenge, Negotiate, ParseError

Constant Summary collapse

SSP_SIGNATURE =
"NTLMSSP\0"
FLAGS =
MS-NLMP

2.2.2.5

{
  :NEGOTIATE_UNICODE           => 0x00000001,  # Unicode character set encoding
  :NEGOTIATE_OEM               => 0x00000002,  # OEM character set encoding
  :REQUEST_TARGET              => 0x00000004,  # TargetName is supplied in challenge message
  :UNUSED10                    => 0x00000008,
  :NEGOTIATE_SIGN              => 0x00000010,  # Session key negotiation for message signatures
  :NEGOTIATE_SEAL              => 0x00000020,  # Session key negotiation for message confidentiality
  :NEGOTIATE_DATAGRAM          => 0x00000040,  # Connectionless authentication
  :NEGOTIATE_LM_KEY            => 0x00000080,  # LAN Manager session key computation
  :UNUSED9                     => 0x00000100,
  :NEGOTIATE_NTLM              => 0x00000200,  # NTLM v1 protocol
  :UNUSED8                     => 0x00000400,
  :ANONYMOUS                   => 0x00000800,  # Anonymous connection
  :OEM_DOMAIN_SUPPLIED         => 0x00001000,  # Domain field is present
  :OEM_WORKSTATION_SUPPLIED    => 0x00002000,  # Workstations field is present
  :UNUSED7                     => 0x00004000,
  :NEGOTIATE_ALWAYS_SIGN       => 0x00008000,
  :TARGET_TYPE_DOMAIN          => 0x00010000,  # TargetName is domain name
  :TARGET_TYPE_SERVER          => 0x00020000,  # TargetName is server name
  :UNUSED6                     => 0x00040000,
  :NEGOTIATE_EXTENDED_SECURITY => 0x00080000,  # NTLM v2 session security
  :NEGOTIATE_IDENTIFY          => 0x00100000,  # Requests identify level token
  :UNUSED5                     => 0x00200000,
  :REQUEST_NON_NT_SESSION_KEY  => 0x00400000,  # LM session key is used
  :NEGOTIATE_TARGET_INFO       => 0x00800000,  # Requests TargetInfo
  :UNUSED4                     => 0x01000000,
  :NEGOTIATE_VERSION           => 0x02000000,  # Version field is present
  :UNUSED3                     => 0x04000000,
  :UNUSED2                     => 0x08000000,
  :UNUSED1                     => 0x10000000,
  :NEGOTIATE_128               => 0x20000000,  # 128bit encryption
  :NEGOTIATE_KEY_EXCH          => 0x40000000,  # Explicit key exchange
  :NEGOTIATE_56                => 0x80000000,  # 56bit encryption
}
AV_PAIRS =
MS-NLMP

2.2.2.1

{
  :AV_EOL               => 0,
  :AV_NB_COMPUTER_NAME  => 1,
  :AV_NB_DOMAIN_NAME    => 2,
  :AV_DNS_COMPUTER_NAME => 3,
  :AV_DNS_DOMAIN_NAME   => 4,
  :AV_DNS_TREE_NAME     => 5,
  :AV_FLAGS             => 6,
  :AV_TIMESTAMP         => 7,
  :AV_RESTRICTIONS      => 8,
  :AV_TARGET_NAME       => 9,
  :AV_CHANNEL_BINDINGS  => 10,
}
AV_PAIR_NAMES =
AV_PAIRS.invert

Constants included from Util

Util::LM_MAGIC_TEXT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

create_des_keys, #decode_utf16, #encode_utf16, encrypt, lm_v1_hash, nt_v1_hash, nt_v2_hash, ntlm_v1_response, ntlm_v2_response

Constructor Details

#initialize(args = {}) ⇒ Message

Returns a new instance of Message.



81
82
83
84
85
86
87
88
89
# File 'lib/ntlm/message.rb', line 81

def initialize(args = {})
  @buffer = ''
  @offset  = 0
  @flag    = args[:flag] || self.class::DEFAULT_FLAGS

  self.class::ATTRIBUTES.each do |key|
    instance_variable_set("@#{key}", args[key]) if args[key]
  end
end

Instance Attribute Details

#flagObject

Returns the value of attribute flag.



74
75
76
# File 'lib/ntlm/message.rb', line 74

def flag
  @flag
end

Class Method Details

.parse(*args) ⇒ Object



77
78
79
# File 'lib/ntlm/message.rb', line 77

def self.parse(*args)
  new.parse(*args)
end

Instance Method Details

#clear(symbol) ⇒ Object



109
110
111
# File 'lib/ntlm/message.rb', line 109

def clear(symbol)
  @flag &= ~FLAGS[symbol]
end

#has_flag?(symbol) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/ntlm/message.rb', line 101

def has_flag?(symbol)
  (@flag & FLAGS[symbol]) != 0
end

#inspectObject



125
126
127
128
# File 'lib/ntlm/message.rb', line 125

def inspect
  variables = (instance_variables.map(&:to_sym) - [:@offset, :@buffer, :@flag]).sort.map {|name| "#{name}=#{instance_variable_get(name).inspect}, " }.join
  "\#<#{self.class.name} #{variables}@flag=#{inspect_flags}>"
end

#inspect_flagsObject



117
118
119
120
121
122
123
# File 'lib/ntlm/message.rb', line 117

def inspect_flags
  flags = []
  FLAGS.sort_by(&:last).each do |name, val|
    flags << name if (@flag & val).nonzero?
  end
  "[#{flags.join(', ')}]"
end

#serialize_to_base64Object Also known as: to_base64



95
96
97
# File 'lib/ntlm/message.rb', line 95

def serialize_to_base64
  [serialize].pack('m').delete("\r\n")
end

#set(symbol) ⇒ Object



105
106
107
# File 'lib/ntlm/message.rb', line 105

def set(symbol)
  @flag |= FLAGS[symbol]
end

#to_sObject



91
92
93
# File 'lib/ntlm/message.rb', line 91

def to_s
  serialize
end

#unicode?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/ntlm/message.rb', line 113

def unicode?
  has_flag?(:NEGOTIATE_UNICODE)
end