Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / cmd / cmd-inet / usr.bin / pppd / mschap_test.c
blob72b17d65e59527b5d1447e68717d403372e410ee
1 /*
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)
14 #include <stdio.h>
16 #include "pppd.h"
17 #include "chap.h"
18 #include "chap_ms.h"
20 static void
21 show_response(chap_state *cstate, const char *str)
23 int i;
25 printf("%s -- %d bytes:", str, cstate->resp_length);
27 for (i = 0; i < cstate->resp_length; i++) {
28 if (i % 8 == 0)
29 putchar('\n');
30 printf("%02X ", (unsigned int)cstate->response[i]);
33 putchar('\n');
36 int main(argc, argv)
37 int argc;
38 char *argv[];
40 u_char challenge[8];
41 int challengeInt[sizeof(challenge)];
42 chap_state cstate;
43 int i;
45 if (argc != 3) {
46 fprintf(stderr, "Usage: %s <16-hexchar challenge> <password>\n",
47 argv[0]); exit(1);
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]));
60 #ifdef MSLANMAN
61 show_response(&cstate, "MS-CHAPv1 with LAN Manager");
62 #else
63 show_response(&cstate, "MS-CHAPv1");
64 #endif
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");
72 #ifdef MSLANMAN
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");
77 #endif
79 #ifdef CHAPMSV2
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");
86 #endif
88 return (0);