xref: /titanic_51/usr/src/cmd/cmd-inet/usr.bin/pppd/mschap_test.c (revision eedefb957fd12dc52be22145a83874a71050e784)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Test MS-CHAPv1 library code.
37c478bd9Sstevel@tonic-gate  *
4*eedefb95Sdarrenm  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
5*eedefb95Sdarrenm  * Use is subject to license terms.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * Originally from the README.MSCHAP80 file written by:
87c478bd9Sstevel@tonic-gate  *	Eric Rosenquist          rosenqui@strataware.com
97c478bd9Sstevel@tonic-gate  *	(updated by Paul Mackerras)
107c478bd9Sstevel@tonic-gate  *	(updated by Al Longyear)
117c478bd9Sstevel@tonic-gate  *	(updated by Farrell Woods)
127c478bd9Sstevel@tonic-gate  */
137c478bd9Sstevel@tonic-gate 
147c478bd9Sstevel@tonic-gate #include <stdio.h>
157c478bd9Sstevel@tonic-gate 
167c478bd9Sstevel@tonic-gate #include "pppd.h"
177c478bd9Sstevel@tonic-gate #include "chap.h"
187c478bd9Sstevel@tonic-gate #include "chap_ms.h"
197c478bd9Sstevel@tonic-gate 
207c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate static void
237c478bd9Sstevel@tonic-gate show_response(chap_state *cstate, const char *str)
247c478bd9Sstevel@tonic-gate {
257c478bd9Sstevel@tonic-gate     int i;
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate     printf("%s -- %d bytes:", str, cstate->resp_length);
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate     for (i = 0; i < cstate->resp_length; i++) {
307c478bd9Sstevel@tonic-gate         if (i % 8 == 0)
317c478bd9Sstevel@tonic-gate             putchar('\n');
327c478bd9Sstevel@tonic-gate         printf("%02X ", (unsigned int)cstate->response[i]);
337c478bd9Sstevel@tonic-gate     }
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate     putchar('\n');
367c478bd9Sstevel@tonic-gate }
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate int main(argc, argv)
397c478bd9Sstevel@tonic-gate     int     argc;
407c478bd9Sstevel@tonic-gate     char    *argv[];
417c478bd9Sstevel@tonic-gate {
427c478bd9Sstevel@tonic-gate     u_char          challenge[8];
437c478bd9Sstevel@tonic-gate     int             challengeInt[sizeof(challenge)];
447c478bd9Sstevel@tonic-gate     chap_state      cstate;
457c478bd9Sstevel@tonic-gate     int             i;
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate     if (argc != 3) {
487c478bd9Sstevel@tonic-gate         fprintf(stderr, "Usage: %s <16-hexchar challenge> <password>\n",
497c478bd9Sstevel@tonic-gate         argv[0]); exit(1);
507c478bd9Sstevel@tonic-gate     }
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate     sscanf(argv[1], "%2x%2x%2x%2x%2x%2x%2x%2x",
537c478bd9Sstevel@tonic-gate            challengeInt + 0, challengeInt + 1, challengeInt + 2,
547c478bd9Sstevel@tonic-gate            challengeInt + 3, challengeInt + 4, challengeInt + 5,
557c478bd9Sstevel@tonic-gate            challengeInt + 6, challengeInt + 7);
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate     for (i = 0; i < sizeof(challenge); i++)
587c478bd9Sstevel@tonic-gate         challenge[i] = (u_char)challengeInt[i];
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate     BZERO(&cstate, sizeof(cstate));
617c478bd9Sstevel@tonic-gate     ChapMS(&cstate, challenge, sizeof(challenge), argv[2], strlen(argv[2]));
627c478bd9Sstevel@tonic-gate #ifdef MSLANMAN
637c478bd9Sstevel@tonic-gate     show_response(&cstate, "MS-CHAPv1 with LAN Manager");
647c478bd9Sstevel@tonic-gate #else
657c478bd9Sstevel@tonic-gate     show_response(&cstate, "MS-CHAPv1");
667c478bd9Sstevel@tonic-gate #endif
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate     cstate.chal_len = sizeof(challenge);
697c478bd9Sstevel@tonic-gate     BCOPY(challenge, cstate.challenge, cstate.chal_len);
707c478bd9Sstevel@tonic-gate     if (!ChapMSValidate(&cstate, cstate.response, cstate.resp_length,
717c478bd9Sstevel@tonic-gate 	argv[2], strlen(argv[2])))
727c478bd9Sstevel@tonic-gate 	printf("Cannot validate own MS-CHAPv1 response.\n");
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #ifdef MSLANMAN
757c478bd9Sstevel@tonic-gate     cstate.response[MS_CHAP_RESPONSE_LEN-1] = '\0';
767c478bd9Sstevel@tonic-gate     if (!ChapMSValidate(&cstate, cstate.response, cstate.resp_length,
777c478bd9Sstevel@tonic-gate 	argv[2], strlen(argv[2])))
787c478bd9Sstevel@tonic-gate 	printf("Cannot validate own LAN Manager response.\n");
797c478bd9Sstevel@tonic-gate #endif
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #ifdef CHAPMSV2
827c478bd9Sstevel@tonic-gate     cstate.resp_name = "joe user";
837c478bd9Sstevel@tonic-gate     ChapMSv2(&cstate, cstate.challenge, 16, argv[2], strlen(argv[2]));
847c478bd9Sstevel@tonic-gate     show_response(&cstate, "MS-CHAPv2");
857c478bd9Sstevel@tonic-gate     if (!ChapMSv2Validate(&cstate, cstate.resp_name, cstate.response,
867c478bd9Sstevel@tonic-gate 	cstate.resp_length, argv[2], strlen(argv[2])))
877c478bd9Sstevel@tonic-gate 	printf("Cannot validate own MS-CHAPv2 response.\n");
887c478bd9Sstevel@tonic-gate #endif
897c478bd9Sstevel@tonic-gate 
90*eedefb95Sdarrenm     return (0);
917c478bd9Sstevel@tonic-gate }
92