2 * Test MS-CHAPv1 library code.
4 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
5 * Use is subject to license terms.
7 * Originally from the README.MSCHAP80 file written by:
8 * Eric Rosenquist rosenqui@strataware.com
9 * (updated by Paul Mackerras)
10 * (updated by Al Longyear)
11 * (updated by Farrell Woods)
21 show_response(chap_state
*cstate
, const char *str
)
25 printf("%s -- %d bytes:", str
, cstate
->resp_length
);
27 for (i
= 0; i
< cstate
->resp_length
; i
++) {
30 printf("%02X ", (unsigned int)cstate
->response
[i
]);
41 int challengeInt
[sizeof(challenge
)];
46 fprintf(stderr
, "Usage: %s <16-hexchar challenge> <password>\n",
50 sscanf(argv
[1], "%2x%2x%2x%2x%2x%2x%2x%2x",
51 challengeInt
+ 0, challengeInt
+ 1, challengeInt
+ 2,
52 challengeInt
+ 3, challengeInt
+ 4, challengeInt
+ 5,
53 challengeInt
+ 6, challengeInt
+ 7);
55 for (i
= 0; i
< sizeof(challenge
); i
++)
56 challenge
[i
] = (u_char
)challengeInt
[i
];
58 BZERO(&cstate
, sizeof(cstate
));
59 ChapMS(&cstate
, challenge
, sizeof(challenge
), argv
[2], strlen(argv
[2]));
61 show_response(&cstate
, "MS-CHAPv1 with LAN Manager");
63 show_response(&cstate
, "MS-CHAPv1");
66 cstate
.chal_len
= sizeof(challenge
);
67 BCOPY(challenge
, cstate
.challenge
, cstate
.chal_len
);
68 if (!ChapMSValidate(&cstate
, cstate
.response
, cstate
.resp_length
,
69 argv
[2], strlen(argv
[2])))
70 printf("Cannot validate own MS-CHAPv1 response.\n");
73 cstate
.response
[MS_CHAP_RESPONSE_LEN
-1] = '\0';
74 if (!ChapMSValidate(&cstate
, cstate
.response
, cstate
.resp_length
,
75 argv
[2], strlen(argv
[2])))
76 printf("Cannot validate own LAN Manager response.\n");
80 cstate
.resp_name
= "joe user";
81 ChapMSv2(&cstate
, cstate
.challenge
, 16, argv
[2], strlen(argv
[2]));
82 show_response(&cstate
, "MS-CHAPv2");
83 if (!ChapMSv2Validate(&cstate
, cstate
.resp_name
, cstate
.response
,
84 cstate
.resp_length
, argv
[2], strlen(argv
[2])))
85 printf("Cannot validate own MS-CHAPv2 response.\n");