Skip to content

Commit 7ea6070

Browse files
committed
Add to the README
1 parent 2462567 commit 7ea6070

File tree

1 file changed

+68
-4
lines changed

1 file changed

+68
-4
lines changed

README.md

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ secure version of a credential for storage (rather than storing passwords in "pl
1919
## Requirements
2020

2121
- 64-bit PHP runtime (NTLM negotiation bit flags extend beyond the 32-bit integer size)
22-
- PHP `>=5.4.0`
22+
- PHP `>=7.2.0`
2323

2424

2525
## Installation
@@ -29,6 +29,71 @@ secure version of a credential for storage (rather than storing passwords in "pl
2929
3. Include the [Composer autoloader][composer-documentation-autoloading]
3030

3131

32+
## Example Usage
33+
34+
```php
35+
// Using Guzzle
36+
$client = new Client();
37+
$request = new Request('get', 'https://my-exchange-url.com');
38+
$user_name = 'user_name';
39+
$password = 'password';
40+
$target_name = 'target_name';
41+
$host_name = 'host_name';
42+
43+
$encoding_converter = new MbstringEncodingConverter();
44+
$random_byte_generator = new NativeRandomByteGenerator();
45+
$hasher_factory = HasherFactory::createWithDetectedSupportedAlgorithms();
46+
47+
$negotiate_message_encoder = new NegotiateMessageEncoder($encoding_converter);
48+
$challenge_message_decoder = new ChallengeMessageDecoder();
49+
50+
$keyed_hasher_factory = KeyedHasherFactory::createWithDetectedSupportedAlgorithms();
51+
52+
$nt1_hasher = new NtV1Hasher($hasher_factory, $encoding_converter);
53+
$nt2_hasher = new NtV2Hasher($nt1_hasher, $keyed_hasher_factory, $encoding_converter);
54+
55+
$authenticate_message_encoder = new NtlmV2AuthenticateMessageEncoder(
56+
$encoding_converter,
57+
$nt2_hasher,
58+
$random_byte_generator,
59+
$keyed_hasher_factory
60+
);
61+
62+
$negotiate_message = $negotiate_message_encoder->encode(
63+
$target_name,
64+
$host_name
65+
);
66+
67+
// Send negotiate message
68+
$request->setHeader('Authorization', sprintf('NTLM %s', base64_encode($negotiate_message)));
69+
$response = $client->send($request);
70+
71+
// Decode returned challenge message
72+
$authenticate_headers = $response->getHeaderAsArray('WWW-Authenticate');
73+
foreach ($authenticate_headers as $header_string) {
74+
$ntlm_matches = preg_match('/NTLM( (.*))?/', $header_string, $ntlm_header);
75+
76+
if (0 < $ntlm_matches && isset($ntlm_header[2])) {
77+
$raw_server_challenge = base64_decode($ntlm_header[2]);
78+
break;
79+
}
80+
}
81+
$server_challenge = $challenge_message_decoder->decode($raw_server_challenge);
82+
83+
$authenticate_message = $authenticate_message_encoder->encode(
84+
$user_name,
85+
$target_name,
86+
$host_name,
87+
new Password($password),
88+
$server_challenge
89+
);
90+
91+
// Send authenticate message
92+
$request->setHeader('Authorization', sprintf('NTLM %s', base64_encode($authenticate_message)));
93+
$client->send($request);
94+
```
95+
96+
3297
## TODO
3398

3499
- [x] LM hashing
@@ -49,8 +114,7 @@ secure version of a credential for storage (rather than storing passwords in "pl
49114
- [x] Extended session security (NTLM2 session key) support
50115
- [ ] \(Add-on) Encrypted session key exchange support
51116
- [ ] Datagram ("connectionless") support
52-
- [ ] PHP 5.3.x support
53-
- [ ] Tests... ugh.
117+
- [ ] Tests
54118

55119

56120
## License
@@ -59,7 +123,7 @@ secure version of a credential for storage (rather than storing passwords in "pl
59123

60124
--------------------------------------------------------------------------------
61125

62-
Copyright 2015 Robin Powered, Inc.
126+
Copyright 2019 Robin Powered, Inc.
63127

64128
Licensed under the Apache License, Version 2.0 (the "License");
65129
you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)