| 1 |
lars |
1 |
--TEST--
|
|
|
2 |
Crypt_CHAP: simple test
|
|
|
3 |
--SKIPIF--
|
|
|
4 |
<?php if (!extension_loaded("hash")) echo 'skip'; ?>
|
|
|
5 |
--FILE--
|
|
|
6 |
<?php
|
|
|
7 |
/*
|
|
|
8 |
Copyright (c) 2003-2007, Michael Bretterklieber <michael@bretterklieber.com>
|
|
|
9 |
All rights reserved.
|
|
|
10 |
|
|
|
11 |
Redistribution and use in source and binary forms, with or without
|
|
|
12 |
modification, are permitted provided that the following conditions
|
|
|
13 |
are met:
|
|
|
14 |
|
|
|
15 |
1. Redistributions of source code must retain the above copyright
|
|
|
16 |
notice, this list of conditions and the following disclaimer.
|
|
|
17 |
2. Redistributions in binary form must reproduce the above copyright
|
|
|
18 |
notice, this list of conditions and the following disclaimer in the
|
|
|
19 |
documentation and/or other materials provided with the distribution.
|
|
|
20 |
3. The names of the authors may not be used to endorse or promote products
|
|
|
21 |
derived from this software without specific prior written permission.
|
|
|
22 |
|
|
|
23 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
24 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
25 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
26 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
|
27 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
28 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
29 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
|
30 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
31 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
|
32 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
33 |
|
|
|
34 |
This code cannot simply be copied and put under the GNU Public License or
|
|
|
35 |
any other GPL-like (LGPL, GPL2) License.
|
|
|
36 |
|
|
|
37 |
$Id: chaptest.php 231819 2007-03-14 07:39:07Z mbretter $
|
|
|
38 |
*/
|
|
|
39 |
chdir (dirname(__FILE__));
|
|
|
40 |
if (file_exists('../CHAP.php')) {
|
|
|
41 |
require_once '../CHAP.php';
|
|
|
42 |
} else {
|
|
|
43 |
require_once 'Crypt/CHAP.php';
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
echo "CHAP-MD5 TEST\n";
|
|
|
47 |
$crpt = new Crypt_CHAP_MD5;
|
|
|
48 |
$crpt->password = 'MyPw';
|
|
|
49 |
$crpt->chapid = 1;
|
|
|
50 |
$crpt->challenge = pack('H*', '102DB5DF085D3041');
|
|
|
51 |
printf ("ChallResp : %s\n", bin2hex($crpt->challengeResponse()));
|
|
|
52 |
echo "\n";
|
|
|
53 |
|
|
|
54 |
echo "CHAP-MD5 TEST 2\n";
|
|
|
55 |
$crpt = new Crypt_CHAP_MD5;
|
|
|
56 |
$crpt->password = 'sepp';
|
|
|
57 |
$crpt->chapid = 1;
|
|
|
58 |
$crpt->challenge = pack('H*', '102DB5DF085D3041');
|
|
|
59 |
printf ("ChallResp : %s\n", bin2hex($crpt->challengeResponse()));
|
|
|
60 |
echo "\n";
|
|
|
61 |
|
|
|
62 |
echo "MS-CHAPv1 str2unicode\n";
|
|
|
63 |
$crpt = new Crypt_CHAP_MSv1;
|
|
|
64 |
printf("Passed 123 as Number:%s\n", bin2hex($crpt->str2unicode(123)));
|
|
|
65 |
printf("Passed 123 as String:%s\n", bin2hex($crpt->str2unicode('123')));
|
|
|
66 |
echo "\n";
|
|
|
67 |
|
|
|
68 |
echo "MS-CHAPv1 TEST\n";
|
|
|
69 |
$crpt->password = 'MyPw';
|
|
|
70 |
$crpt->challenge = pack('H*', '102DB5DF085D3041');
|
|
|
71 |
$unipw = $crpt->str2unicode($crpt->password);
|
|
|
72 |
printf ("Unicode PW: %s\n", bin2hex($unipw));
|
|
|
73 |
printf ("NT HASH : %s\n", bin2hex($crpt->ntPasswordHash()));
|
|
|
74 |
printf ("NT Resp : %s\n", bin2hex($crpt->challengeResponse()));
|
|
|
75 |
printf ("LM HASH : %s\n", bin2hex($crpt->lmPasswordHash()));
|
|
|
76 |
printf ("LM Resp : %s\n", bin2hex($crpt->lmChallengeResponse()));
|
|
|
77 |
//printf ("Response : %s\nexpected : unknown\n", bin2hex($crpt->response()));
|
|
|
78 |
echo "\n";
|
|
|
79 |
|
|
|
80 |
echo "MS-CHAPv2 TEST\n";
|
|
|
81 |
$crpt = new Crypt_CHAP_MSv2;
|
|
|
82 |
$crpt->username = 'User';
|
|
|
83 |
$crpt->password = 'clientPass';
|
|
|
84 |
printf ("Username : %s\n", bin2hex($crpt->username));
|
|
|
85 |
$crpt->authChallenge = pack('H*', '5b5d7c7d7b3f2f3e3c2c602132262628');
|
|
|
86 |
$crpt->peerChallenge = pack('H*', '21402324255E262A28295F2B3A337C7E');
|
|
|
87 |
$nthash = $crpt->ntPasswordHash();
|
|
|
88 |
printf ("NT HASH : %s\n", bin2hex($nthash));
|
|
|
89 |
$nthashhash = $crpt->ntPasswordHashHash($nthash);
|
|
|
90 |
printf ("NT HASH-HASH : %s\n", bin2hex($nthashhash));
|
|
|
91 |
printf ("ChallResp : %s\n", bin2hex($crpt->challengeResponse()));
|
|
|
92 |
printf ("Challenge : %s\n", bin2hex($crpt->challenge));
|
|
|
93 |
echo "\n";
|
|
|
94 |
?>
|
|
|
95 |
--EXPECT--
|
|
|
96 |
CHAP-MD5 TEST
|
|
|
97 |
ChallResp : 8f028814450d66d94c72331ef455a172
|
|
|
98 |
|
|
|
99 |
CHAP-MD5 TEST 2
|
|
|
100 |
ChallResp : d39bfaf5d6855a948c8c81a85947502c
|
|
|
101 |
|
|
|
102 |
MS-CHAPv1 str2unicode
|
|
|
103 |
Passed 123 as Number:310032003300
|
|
|
104 |
Passed 123 as String:310032003300
|
|
|
105 |
|
|
|
106 |
MS-CHAPv1 TEST
|
|
|
107 |
Unicode PW: 4d00790050007700
|
|
|
108 |
NT HASH : fc156af7edcd6c0edde3337d427f4eac
|
|
|
109 |
NT Resp : 4e9d3c8f9cfd385d5bf4d3246791956ca4c351ab409a3d61
|
|
|
110 |
LM HASH : 75ba30198e6d1975aad3b435b51404ee
|
|
|
111 |
LM Resp : 91881d0152ab0c33c524135ec24a95ee64e23cdc2d33347d
|
|
|
112 |
|
|
|
113 |
MS-CHAPv2 TEST
|
|
|
114 |
Username : 55736572
|
|
|
115 |
NT HASH : 44ebba8d5312b8d611474411f56989ae
|
|
|
116 |
NT HASH-HASH : 41c00c584bd2d91c4017a2a12fa59f3f
|
|
|
117 |
ChallResp : 82309ecd8d708b5ea08faa3981cd83544233114a3d85d6df
|
|
|
118 |
Challenge : d02e4386bce91226
|
|
|
119 |
|