ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ntlm_sasl_client_class Class Reference
+ Collaboration diagram for ntlm_sasl_client_class:

Public Member Functions

 initialize (&$client)
 
 ASCIIToUnicode ($ascii)
 
 typeMsg1 ($domain, $workstation)
 
 NTLMResponse ($challenge, $password)
 
 typeMsg3 ($ntlm_response, $user, $domain, $workstation)
 
 start (&$client, &$message, &$interactions)
 
 step (&$client, $response, &$message, &$interactions)
 

Data Fields

 $credentials = array()
 
 $state = SASL_NTLM_STATE_START
 

Detailed Description

Definition at line 16 of file ntlm_sasl_client.php.

Member Function Documentation

◆ ASCIIToUnicode()

ntlm_sasl_client_class::ASCIIToUnicode (   $ascii)

Definition at line 37 of file ntlm_sasl_client.php.

Referenced by NTLMResponse(), and typeMsg3().

38  {
39  for ($unicode = "", $a = 0; $a < strlen($ascii); $a++) {
40  $unicode .= substr($ascii, $a, 1) . chr(0);
41  }
42  return ($unicode);
43  }
+ Here is the caller graph for this function:

◆ initialize()

ntlm_sasl_client_class::initialize ( $client)

Definition at line 21 of file ntlm_sasl_client.php.

References $client, and array.

22  {
23  if (!function_exists($function = "mcrypt_encrypt")
24  || !function_exists($function = "mhash")
25  ) {
26  $extensions = array(
27  "mcrypt_encrypt" => "mcrypt",
28  "mhash" => "mhash"
29  );
30  $client->error = "the extension " . $extensions[$function] .
31  " required by the NTLM SASL client class is not available in this PHP configuration";
32  return (0);
33  }
34  return (1);
35  }
$client
Create styles array
The data for the language used.

◆ NTLMResponse()

ntlm_sasl_client_class::NTLMResponse (   $challenge,
  $password 
)

Definition at line 66 of file ntlm_sasl_client.php.

References ASCIIToUnicode().

Referenced by step().

67  {
68  $unicode = $this->ASCIIToUnicode($password);
69  $md4 = mhash(MHASH_MD4, $unicode);
70  $padded = $md4 . str_repeat(chr(0), 21 - strlen($md4));
71  $iv_size = mcrypt_get_iv_size(MCRYPT_DES, MCRYPT_MODE_ECB);
72  $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
73  for ($response = "", $third = 0; $third < 21; $third += 7) {
74  for ($packed = "", $p = $third; $p < $third + 7; $p++) {
75  $packed .= str_pad(decbin(ord(substr($padded, $p, 1))), 8, "0", STR_PAD_LEFT);
76  }
77  for ($key = "", $p = 0; $p < strlen($packed); $p += 7) {
78  $s = substr($packed, $p, 7);
79  $b = $s . ((substr_count($s, "1") % 2) ? "0" : "1");
80  $key .= chr(bindec($b));
81  }
82  $ciphertext = mcrypt_encrypt(MCRYPT_DES, $key, $challenge, MCRYPT_MODE_ECB, $iv);
83  $response .= $ciphertext;
84  }
85  return $response;
86  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ start()

ntlm_sasl_client_class::start ( $client,
$message,
$interactions 
)

Definition at line 138 of file ntlm_sasl_client.php.

References $client, array, SASL_CONTINUE, SASL_FAIL, SASL_NTLM_STATE_IDENTIFY_DOMAIN, and SASL_NTLM_STATE_START.

139  {
140  if ($this->state != SASL_NTLM_STATE_START) {
141  $client->error = "NTLM authentication state is not at the start";
142  return (SASL_FAIL);
143  }
144  $this->credentials = array(
145  "user" => "",
146  "password" => "",
147  "realm" => "",
148  "workstation" => ""
149  );
150  $defaults = array();
151  $status = $client->GetCredentials($this->credentials, $defaults, $interactions);
152  if ($status == SASL_CONTINUE) {
153  $this->state = SASL_NTLM_STATE_IDENTIFY_DOMAIN;
154  }
155  unset($message);
156  return ($status);
157  }
const SASL_NTLM_STATE_IDENTIFY_DOMAIN
$client
const SASL_CONTINUE
Create styles array
The data for the language used.
const SASL_FAIL
const SASL_NTLM_STATE_START

◆ step()

ntlm_sasl_client_class::step ( $client,
  $response,
$message,
$interactions 
)

Definition at line 159 of file ntlm_sasl_client.php.

References $client, NTLMResponse(), SASL_CONTINUE, SASL_FAIL, SASL_NTLM_STATE_DONE, SASL_NTLM_STATE_IDENTIFY_DOMAIN, SASL_NTLM_STATE_RESPOND_CHALLENGE, typeMsg1(), and typeMsg3().

160  {
161  switch ($this->state) {
163  $message = $this->typeMsg1($this->credentials["realm"], $this->credentials["workstation"]);
164  $this->state = SASL_NTLM_STATE_RESPOND_CHALLENGE;
165  break;
167  $ntlm_response = $this->NTLMResponse(substr($response, 24, 8), $this->credentials["password"]);
168  $message = $this->typeMsg3(
169  $ntlm_response,
170  $this->credentials["user"],
171  $this->credentials["realm"],
172  $this->credentials["workstation"]
173  );
174  $this->state = SASL_NTLM_STATE_DONE;
175  break;
177  $client->error = "NTLM authentication was finished without success";
178  return (SASL_FAIL);
179  default:
180  $client->error = "invalid NTLM authentication step state";
181  return (SASL_FAIL);
182  }
183  return (SASL_CONTINUE);
184  }
typeMsg1($domain, $workstation)
const SASL_NTLM_STATE_IDENTIFY_DOMAIN
const SASL_NTLM_STATE_DONE
typeMsg3($ntlm_response, $user, $domain, $workstation)
$client
const SASL_CONTINUE
const SASL_NTLM_STATE_RESPOND_CHALLENGE
const SASL_FAIL
NTLMResponse($challenge, $password)
+ Here is the call graph for this function:

◆ typeMsg1()

ntlm_sasl_client_class::typeMsg1 (   $domain,
  $workstation 
)

Definition at line 45 of file ntlm_sasl_client.php.

Referenced by step().

46  {
47  $domain_length = strlen($domain);
48  $workstation_length = strlen($workstation);
49  $workstation_offset = 32;
50  $domain_offset = $workstation_offset + $workstation_length;
51  return (
52  "NTLMSSP\0" .
53  "\x01\x00\x00\x00" .
54  "\x07\x32\x00\x00" .
55  pack("v", $domain_length) .
56  pack("v", $domain_length) .
57  pack("V", $domain_offset) .
58  pack("v", $workstation_length) .
59  pack("v", $workstation_length) .
60  pack("V", $workstation_offset) .
61  $workstation .
62  $domain
63  );
64  }
+ Here is the caller graph for this function:

◆ typeMsg3()

ntlm_sasl_client_class::typeMsg3 (   $ntlm_response,
  $user,
  $domain,
  $workstation 
)

Definition at line 88 of file ntlm_sasl_client.php.

References ASCIIToUnicode().

Referenced by step().

89  {
90  $domain_unicode = $this->ASCIIToUnicode($domain);
91  $domain_length = strlen($domain_unicode);
92  $domain_offset = 64;
93  $user_unicode = $this->ASCIIToUnicode($user);
94  $user_length = strlen($user_unicode);
95  $user_offset = $domain_offset + $domain_length;
96  $workstation_unicode = $this->ASCIIToUnicode($workstation);
97  $workstation_length = strlen($workstation_unicode);
98  $workstation_offset = $user_offset + $user_length;
99  $lm = "";
100  $lm_length = strlen($lm);
101  $lm_offset = $workstation_offset + $workstation_length;
102  $ntlm = $ntlm_response;
103  $ntlm_length = strlen($ntlm);
104  $ntlm_offset = $lm_offset + $lm_length;
105  $session = "";
106  $session_length = strlen($session);
107  $session_offset = $ntlm_offset + $ntlm_length;
108  return (
109  "NTLMSSP\0" .
110  "\x03\x00\x00\x00" .
111  pack("v", $lm_length) .
112  pack("v", $lm_length) .
113  pack("V", $lm_offset) .
114  pack("v", $ntlm_length) .
115  pack("v", $ntlm_length) .
116  pack("V", $ntlm_offset) .
117  pack("v", $domain_length) .
118  pack("v", $domain_length) .
119  pack("V", $domain_offset) .
120  pack("v", $user_length) .
121  pack("v", $user_length) .
122  pack("V", $user_offset) .
123  pack("v", $workstation_length) .
124  pack("v", $workstation_length) .
125  pack("V", $workstation_offset) .
126  pack("v", $session_length) .
127  pack("v", $session_length) .
128  pack("V", $session_offset) .
129  "\x01\x02\x00\x00" .
130  $domain_unicode .
131  $user_unicode .
132  $workstation_unicode .
133  $lm .
134  $ntlm
135  );
136  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $credentials

ntlm_sasl_client_class::$credentials = array()

Definition at line 18 of file ntlm_sasl_client.php.

◆ $state

ntlm_sasl_client_class::$state = SASL_NTLM_STATE_START

Definition at line 19 of file ntlm_sasl_client.php.


The documentation for this class was generated from the following file: