1 /* 2 * Test MS-CHAPv1 library code. 3 * 4 * Copyright (c) 2000 by Sun Microsystems, Inc. 5 * All rights reserved. 6 * 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) 12 */ 13 14 #include <stdio.h> 15 16 #include "pppd.h" 17 #include "chap.h" 18 #include "chap_ms.h" 19 20 #pragma ident "%Z%%M% %I% %E% SMI" 21 22 static void 23 show_response(chap_state *cstate, const char *str) 24 { 25 int i; 26 27 printf("%s -- %d bytes:", str, cstate->resp_length); 28 29 for (i = 0; i < cstate->resp_length; i++) { 30 if (i % 8 == 0) 31 putchar('\n'); 32 printf("%02X ", (unsigned int)cstate->response[i]); 33 } 34 35 putchar('\n'); 36 } 37 38 int main(argc, argv) 39 int argc; 40 char *argv[]; 41 { 42 u_char challenge[8]; 43 int challengeInt[sizeof(challenge)]; 44 chap_state cstate; 45 int i; 46 47 if (argc != 3) { 48 fprintf(stderr, "Usage: %s <16-hexchar challenge> <password>\n", 49 argv[0]); exit(1); 50 } 51 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); 56 57 for (i = 0; i < sizeof(challenge); i++) 58 challenge[i] = (u_char)challengeInt[i]; 59 60 BZERO(&cstate, sizeof(cstate)); 61 ChapMS(&cstate, challenge, sizeof(challenge), argv[2], strlen(argv[2])); 62 #ifdef MSLANMAN 63 show_response(&cstate, "MS-CHAPv1 with LAN Manager"); 64 #else 65 show_response(&cstate, "MS-CHAPv1"); 66 #endif 67 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"); 73 74 #ifdef MSLANMAN 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"); 79 #endif 80 81 #ifdef CHAPMSV2 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"); 88 #endif 89 90 exit(0); 91 } 92