skey.c revision 1.4
1/* * $OpenBSD: skey.c,v 1.4 1996/09/29 04:33:58 millert Exp $*/ 2/* 3 * S/KEY v1.1b (skey.c) 4 * 5 * Authors: 6 * Neil M. Haller <nmh@thumper.bellcore.com> 7 * Philip R. Karn <karn@chicago.qualcomm.com> 8 * John S. Walden <jsw@thumper.bellcore.com> 9 * Scott Chasin <chasin@crimelab.com> 10 * 11 * 12 * Stand-alone program for computing responses to S/Key challenges. 13 * Takes the iteration count and seed as command line args, prompts 14 * for the user's key, and produces both word and hex format responses. 15 * 16 * Usage example: 17 * >skey 88 ka9q2 18 * Enter password: 19 * OMEN US HORN OMIT BACK AHOY 20 * > 21 * 22 */ 23 24#include <stdio.h> 25#include <stdlib.h> 26#include <string.h> 27#include <err.h> 28#include <unistd.h> 29#include <skey.h> 30 31void usage __P((char *)); 32 33int 34main(argc, argv) 35 int argc; 36 char *argv[]; 37{ 38 int n, i, cnt = 1, pass = 0, hexmode = 0; 39 char passwd[256], key[8], buf[33], *seed, *slash; 40 41 while ((i = getopt(argc, argv, "n:p:x45")) != EOF) { 42 switch (i) { 43 case 'n': 44 cnt = atoi(optarg); 45 break; 46 case 'p': 47 strcpy(passwd, optarg); 48 pass = 1; 49 break; 50 case 'x': 51 hexmode = 1; 52 break; 53 case '4': 54 skey_set_MDX(4); 55 break; 56 case '5': 57 skey_set_MDX(5); 58 break; 59 } 60 } 61 62 /* check for md4/md5 argument */ 63 if (argv[optind]) { 64 if (strcmp(argv[optind], "MD4") == 0) { 65 skey_set_MDX(4); 66 optind++; 67 } else if (strcmp(argv[optind], "MD5") == 0) { 68 skey_set_MDX(5); 69 optind++; 70 } 71 } 72 73 /* could be in the form <number>/<seed> */ 74 if (argc <= optind + 1) { 75 /* look for / in it */ 76 if (argc <= optind) 77 usage(argv[0]); 78 slash = strchr(argv[optind], '/'); 79 if (slash == NULL) 80 usage(argv[0]); 81 *slash++ = '\0'; 82 seed = slash; 83 84 if ((n = atoi(argv[optind])) < 0) { 85 warnx("%s not positive", argv[optind]); 86 usage(argv[0]); 87 } 88 } else { 89 if ((n = atoi(argv[optind])) < 0) { 90 warnx("%s not positive", argv[optind]); 91 usage(argv[0]); 92 } 93 seed = argv[++optind]; 94 } 95 96 /* Get user's secret password */ 97 if (!pass) { 98 (void)fputs("Reminder - Do not use this program while logged in via telnet or rlogin.\n", stderr); 99 (void)fputs("Enter secret password: ", stderr); 100 readpass(passwd, sizeof(passwd)); 101 } 102 rip(passwd); 103 104 /* Crunch seed and password into starting key */ 105 if (keycrunch(key, seed, passwd) != 0) 106 errx(1, "key crunch failed"); 107 108 if (cnt == 1) { 109 while (n-- != 0) 110 f(key); 111 (void)puts(hexmode ? put8(buf, key) : btoe(buf, key)); 112 } else { 113 for (i = 0; i <= n - cnt; i++) 114 f(key); 115 for (; i <= n; i++) { 116 if (hexmode) 117 (void)printf("%d: %-29s %s\n", i, 118 btoe(buf, key), put8(buf, key)); 119 else 120 (void)printf("%d: %-29s\n", i, btoe(buf, key)); 121 f(key); 122 } 123 } 124 exit(0); 125} 126 127void 128usage(s) 129 char *s; 130{ 131 (void)fprintf(stderr, "Usage: %s [-x] [-4|-5] [-n count] [-p password] [MD4|MD5] sequence# [/] key", s); 132 exit(1); 133} 134