10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * Test MS-CHAPv1 library code.
30Sstevel@tonic-gate *
4*5619Sdarrenm * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
5*5619Sdarrenm * Use is subject to license terms.
60Sstevel@tonic-gate *
70Sstevel@tonic-gate * Originally from the README.MSCHAP80 file written by:
80Sstevel@tonic-gate * Eric Rosenquist rosenqui@strataware.com
90Sstevel@tonic-gate * (updated by Paul Mackerras)
100Sstevel@tonic-gate * (updated by Al Longyear)
110Sstevel@tonic-gate * (updated by Farrell Woods)
120Sstevel@tonic-gate */
130Sstevel@tonic-gate
140Sstevel@tonic-gate #include <stdio.h>
150Sstevel@tonic-gate
160Sstevel@tonic-gate #include "pppd.h"
170Sstevel@tonic-gate #include "chap.h"
180Sstevel@tonic-gate #include "chap_ms.h"
190Sstevel@tonic-gate
200Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
210Sstevel@tonic-gate
220Sstevel@tonic-gate static void
show_response(chap_state * cstate,const char * str)230Sstevel@tonic-gate show_response(chap_state *cstate, const char *str)
240Sstevel@tonic-gate {
250Sstevel@tonic-gate int i;
260Sstevel@tonic-gate
270Sstevel@tonic-gate printf("%s -- %d bytes:", str, cstate->resp_length);
280Sstevel@tonic-gate
290Sstevel@tonic-gate for (i = 0; i < cstate->resp_length; i++) {
300Sstevel@tonic-gate if (i % 8 == 0)
310Sstevel@tonic-gate putchar('\n');
320Sstevel@tonic-gate printf("%02X ", (unsigned int)cstate->response[i]);
330Sstevel@tonic-gate }
340Sstevel@tonic-gate
350Sstevel@tonic-gate putchar('\n');
360Sstevel@tonic-gate }
370Sstevel@tonic-gate
main(argc,argv)380Sstevel@tonic-gate int main(argc, argv)
390Sstevel@tonic-gate int argc;
400Sstevel@tonic-gate char *argv[];
410Sstevel@tonic-gate {
420Sstevel@tonic-gate u_char challenge[8];
430Sstevel@tonic-gate int challengeInt[sizeof(challenge)];
440Sstevel@tonic-gate chap_state cstate;
450Sstevel@tonic-gate int i;
460Sstevel@tonic-gate
470Sstevel@tonic-gate if (argc != 3) {
480Sstevel@tonic-gate fprintf(stderr, "Usage: %s <16-hexchar challenge> <password>\n",
490Sstevel@tonic-gate argv[0]); exit(1);
500Sstevel@tonic-gate }
510Sstevel@tonic-gate
520Sstevel@tonic-gate sscanf(argv[1], "%2x%2x%2x%2x%2x%2x%2x%2x",
530Sstevel@tonic-gate challengeInt + 0, challengeInt + 1, challengeInt + 2,
540Sstevel@tonic-gate challengeInt + 3, challengeInt + 4, challengeInt + 5,
550Sstevel@tonic-gate challengeInt + 6, challengeInt + 7);
560Sstevel@tonic-gate
570Sstevel@tonic-gate for (i = 0; i < sizeof(challenge); i++)
580Sstevel@tonic-gate challenge[i] = (u_char)challengeInt[i];
590Sstevel@tonic-gate
600Sstevel@tonic-gate BZERO(&cstate, sizeof(cstate));
610Sstevel@tonic-gate ChapMS(&cstate, challenge, sizeof(challenge), argv[2], strlen(argv[2]));
620Sstevel@tonic-gate #ifdef MSLANMAN
630Sstevel@tonic-gate show_response(&cstate, "MS-CHAPv1 with LAN Manager");
640Sstevel@tonic-gate #else
650Sstevel@tonic-gate show_response(&cstate, "MS-CHAPv1");
660Sstevel@tonic-gate #endif
670Sstevel@tonic-gate
680Sstevel@tonic-gate cstate.chal_len = sizeof(challenge);
690Sstevel@tonic-gate BCOPY(challenge, cstate.challenge, cstate.chal_len);
700Sstevel@tonic-gate if (!ChapMSValidate(&cstate, cstate.response, cstate.resp_length,
710Sstevel@tonic-gate argv[2], strlen(argv[2])))
720Sstevel@tonic-gate printf("Cannot validate own MS-CHAPv1 response.\n");
730Sstevel@tonic-gate
740Sstevel@tonic-gate #ifdef MSLANMAN
750Sstevel@tonic-gate cstate.response[MS_CHAP_RESPONSE_LEN-1] = '\0';
760Sstevel@tonic-gate if (!ChapMSValidate(&cstate, cstate.response, cstate.resp_length,
770Sstevel@tonic-gate argv[2], strlen(argv[2])))
780Sstevel@tonic-gate printf("Cannot validate own LAN Manager response.\n");
790Sstevel@tonic-gate #endif
800Sstevel@tonic-gate
810Sstevel@tonic-gate #ifdef CHAPMSV2
820Sstevel@tonic-gate cstate.resp_name = "joe user";
830Sstevel@tonic-gate ChapMSv2(&cstate, cstate.challenge, 16, argv[2], strlen(argv[2]));
840Sstevel@tonic-gate show_response(&cstate, "MS-CHAPv2");
850Sstevel@tonic-gate if (!ChapMSv2Validate(&cstate, cstate.resp_name, cstate.response,
860Sstevel@tonic-gate cstate.resp_length, argv[2], strlen(argv[2])))
870Sstevel@tonic-gate printf("Cannot validate own MS-CHAPv2 response.\n");
880Sstevel@tonic-gate #endif
890Sstevel@tonic-gate
90*5619Sdarrenm return (0);
910Sstevel@tonic-gate }
92