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)
20 #pragma ident "%Z%%M% %I% %E% SMI"
23 show_response(chap_state
*cstate
, const char *str
)
27 printf("%s -- %d bytes:", str
, cstate
->resp_length
);
29 for (i
= 0; i
< cstate
->resp_length
; i
++) {
32 printf("%02X ", (unsigned int)cstate
->response
[i
]);
43 int challengeInt
[sizeof(challenge
)];
48 fprintf(stderr
, "Usage: %s <16-hexchar challenge> <password>\n",
52 sscanf(argv
[1], "%2x%2x%2x%2x%2x%2x%2x%2x",
53 challengeInt
+ 0, challengeInt
+ 1, challengeInt
+ 2,
54 challengeInt
+ 3, challengeInt
+ 4, challengeInt
+ 5,
55 challengeInt
+ 6, challengeInt
+ 7);
57 for (i
= 0; i
< sizeof(challenge
); i
++)
58 challenge
[i
] = (u_char
)challengeInt
[i
];
60 BZERO(&cstate
, sizeof(cstate
));
61 ChapMS(&cstate
, challenge
, sizeof(challenge
), argv
[2], strlen(argv
[2]));
63 show_response(&cstate
, "MS-CHAPv1 with LAN Manager");
65 show_response(&cstate
, "MS-CHAPv1");
68 cstate
.chal_len
= sizeof(challenge
);
69 BCOPY(challenge
, cstate
.challenge
, cstate
.chal_len
);
70 if (!ChapMSValidate(&cstate
, cstate
.response
, cstate
.resp_length
,
71 argv
[2], strlen(argv
[2])))
72 printf("Cannot validate own MS-CHAPv1 response.\n");
75 cstate
.response
[MS_CHAP_RESPONSE_LEN
-1] = '\0';
76 if (!ChapMSValidate(&cstate
, cstate
.response
, cstate
.resp_length
,
77 argv
[2], strlen(argv
[2])))
78 printf("Cannot validate own LAN Manager response.\n");
82 cstate
.resp_name
= "joe user";
83 ChapMSv2(&cstate
, cstate
.challenge
, 16, argv
[2], strlen(argv
[2]));
84 show_response(&cstate
, "MS-CHAPv2");
85 if (!ChapMSv2Validate(&cstate
, cstate
.resp_name
, cstate
.response
,
86 cstate
.resp_length
, argv
[2], strlen(argv
[2])))
87 printf("Cannot validate own MS-CHAPv2 response.\n");