1 /* $NetBSD: skey.c,v 1.16 2004/01/05 23:23:36 jmmv Exp $ */
7 * Neil M. Haller <nmh@thumper.bellcore.com>
8 * Philip R. Karn <karn@chicago.qualcomm.com>
9 * John S. Walden <jsw@thumper.bellcore.com>
10 * Scott Chasin <chasin@crimelab.com>
13 * Stand-alone program for computing responses to S/Key challenges.
14 * Takes the iteration count and seed as command line args, prompts
15 * for the user's key, and produces both word and hex format responses.
20 * OMEN US HORN OMIT BACK AHOY
24 #include <sys/cdefs.h>
26 __RCSID("$NetBSD: skey.c,v 1.16 2004/01/05 23:23:36 jmmv Exp $");
38 int main(int, char **);
42 main(int argc
, char **argv
)
44 int n
, cnt
, i
, pass
= 0, hexmode
= 0;
45 char passwd
[SKEY_MAX_PW_LEN
+1], key
[SKEY_BINKEY_SIZE
];
46 char buf
[33], *seed
, *slash
, *t
;
50 while ((i
= getopt(argc
, argv
, "fn:p:t:x")) != -1) {
53 /* this option is ignored now */
59 if (strlcpy(passwd
, optarg
, sizeof(passwd
)) >=
61 errx(1, "Password too long");
65 if (skey_set_algorithm(optarg
) == NULL
) {
66 errx(1, "Unknown hash algorithm %s", optarg
);
78 /* could be in the form <number>/<seed> */
79 if (argc
<= optind
+ 1) {
80 /* look for / in it */
83 slash
= strchr(argv
[optind
], '/');
89 if ((n
= atoi(argv
[optind
])) < 0) {
90 fprintf(stderr
, "%s not positive\n", argv
[optind
]);
92 } else if (n
> SKEY_MAX_SEQ
) {
93 warnx("%d is larger than max (%d)", n
, SKEY_MAX_SEQ
);
98 if ((n
= atoi(argv
[optind
])) < 0) {
99 fprintf(stderr
, "%s not positive\n", argv
[optind
]);
101 } else if (n
> SKEY_MAX_SEQ
) {
102 warnx("%d is larger than max (%d)", n
, SKEY_MAX_SEQ
);
105 seed
= argv
[++optind
];
108 for(t
= seed
; *t
; t
++) {
109 if(!isalnum((unsigned char)*t
))
110 errx(1, "seed must be alphanumeric");
113 if(!*seed
|| strlen(seed
) > SKEY_MAX_SEED_LEN
)
114 errx(1, "seed must be between 1 and %d long", SKEY_MAX_SEED_LEN
);
116 /* Get user's secret password */
118 (void)fputs("Reminder - Do not use this program while "
119 "logged in via telnet or rlogin.\n", stderr
);
120 fprintf(stderr
, "Enter secret password: ");
121 readpass(passwd
, sizeof(passwd
));
122 if (passwd
[0] == '\0')
126 if (strlen(passwd
) < SKEY_MIN_PW_LEN
)
128 "password should be at least %d characters long according to RFC2289",
131 /* Crunch seed and password into starting key */
132 if (keycrunch(key
, seed
, passwd
) != 0)
133 errx(1, "key crunch failed");
138 (void)puts(hexmode
? put8(buf
, key
) : btoe(buf
, key
));
140 for (i
= 0; i
<= n
- cnt
; i
++)
142 for (; i
<= n
; i
++) {
143 (void)printf("%3d: %-29s", i
, btoe(buf
, key
));
145 (void)printf("\t%s", put8(buf
, key
));
158 "usage: %s [-n count] [-p password] [-t hash] [-x] sequence# [/] key\n",