[BACK]Return to skey.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / skey

Annotation of src/usr.bin/skey/skey.c, Revision 1.4

1.4     ! millert     1: /* * $OpenBSD: skey.c,v 1.3 1996/09/27 15:41:36 millert Exp $*/
1.1       deraadt     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>
1.3       millert    27: #include <err.h>
                     28: #include <unistd.h>
                     29: #include <skey.h>
1.1       deraadt    30:
                     31: void    usage __P((char *));
                     32:
                     33: int
                     34: main(argc, argv)
                     35:        int     argc;
                     36:        char    *argv[];
                     37: {
1.3       millert    38:        int     n, i, cnt = 1, pass = 0, hexmode = 0;
1.1       deraadt    39:        char    passwd[256], key[8], buf[33], *seed, *slash;
                     40:
1.3       millert    41:        while ((i = getopt(argc, argv, "n:p:x45")) != EOF) {
1.1       deraadt    42:                switch (i) {
                     43:                case 'n':
                     44:                        cnt = atoi(optarg);
                     45:                        break;
                     46:                case 'p':
                     47:                        strcpy(passwd, optarg);
                     48:                        pass = 1;
                     49:                        break;
1.3       millert    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;
1.1       deraadt    59:                }
                     60:        }
                     61:
1.4     ! millert    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:
1.1       deraadt    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) {
1.3       millert    85:                        warnx("%s not positive", argv[optind]);
1.1       deraadt    86:                        usage(argv[0]);
                     87:                }
                     88:        } else {
                     89:                if ((n = atoi(argv[optind])) < 0) {
1.3       millert    90:                        warnx("%s not positive", argv[optind]);
1.1       deraadt    91:                        usage(argv[0]);
                     92:                }
                     93:                seed = argv[++optind];
                     94:        }
                     95:
                     96:        /* Get user's secret password */
                     97:        if (!pass) {
1.3       millert    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);
1.1       deraadt   100:                readpass(passwd, sizeof(passwd));
                    101:        }
                    102:        rip(passwd);
                    103:
                    104:        /* Crunch seed and password into starting key */
1.3       millert   105:        if (keycrunch(key, seed, passwd) != 0)
                    106:                errx(1, "key crunch failed");
                    107:
1.1       deraadt   108:        if (cnt == 1) {
                    109:                while (n-- != 0)
                    110:                        f(key);
1.3       millert   111:                (void)puts(hexmode ? put8(buf, key) : btoe(buf, key));
1.1       deraadt   112:        } else {
                    113:                for (i = 0; i <= n - cnt; i++)
                    114:                        f(key);
                    115:                for (; i <= n; i++) {
1.3       millert   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));
1.1       deraadt   121:                        f(key);
                    122:                }
                    123:        }
                    124:        exit(0);
                    125: }
                    126:
                    127: void
                    128: usage(s)
                    129:        char   *s;
                    130: {
1.4     ! millert   131:        (void)fprintf(stderr, "Usage: %s [-x] [-4|-5] [-n count] [-p password] [MD4|MD5] sequence# [/] key", s);
1.1       deraadt   132:        exit(1);
                    133: }