2000-09-14 23:18:24 +04:00
|
|
|
/* $NetBSD: skey.c,v 1.13 2000/09/14 19:18:24 mjl Exp $ */
|
1996-09-19 23:39:36 +04:00
|
|
|
|
1994-05-24 10:47:42 +04:00
|
|
|
/*
|
|
|
|
* S/KEY v1.1b (skey.c)
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Neil M. Haller <nmh@thumper.bellcore.com>
|
|
|
|
* Philip R. Karn <karn@chicago.qualcomm.com>
|
|
|
|
* John S. Walden <jsw@thumper.bellcore.com>
|
|
|
|
* Scott Chasin <chasin@crimelab.com>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Stand-alone program for computing responses to S/Key challenges.
|
|
|
|
* Takes the iteration count and seed as command line args, prompts
|
|
|
|
* for the user's key, and produces both word and hex format responses.
|
|
|
|
*
|
|
|
|
* Usage example:
|
|
|
|
* >skey 88 ka9q2
|
|
|
|
* Enter password:
|
|
|
|
* OMEN US HORN OMIT BACK AHOY
|
|
|
|
* >
|
|
|
|
*/
|
|
|
|
|
1997-10-20 03:20:15 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2000-09-14 23:18:24 +04:00
|
|
|
__RCSID("$NetBSD: skey.c,v 1.13 2000/09/14 19:18:24 mjl Exp $");
|
1997-10-20 03:20:15 +04:00
|
|
|
#endif
|
|
|
|
|
2000-07-07 19:45:00 +04:00
|
|
|
#include <ctype.h>
|
2000-07-07 19:18:14 +04:00
|
|
|
#include <err.h>
|
1994-05-24 10:47:42 +04:00
|
|
|
#include <fcntl.h>
|
1998-02-03 07:08:01 +03:00
|
|
|
#include <stdio.h>
|
1997-06-22 22:51:47 +04:00
|
|
|
#include <skey.h>
|
1998-02-03 07:08:01 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
1994-05-24 10:47:42 +04:00
|
|
|
|
2000-09-14 23:18:24 +04:00
|
|
|
int main(int, char **);
|
|
|
|
void usage(char *);
|
1994-05-24 10:47:42 +04:00
|
|
|
|
1995-06-05 23:55:40 +04:00
|
|
|
int
|
2000-07-07 19:18:14 +04:00
|
|
|
main(int argc, char **argv)
|
1994-05-24 10:47:42 +04:00
|
|
|
{
|
2000-09-14 23:18:24 +04:00
|
|
|
int n, cnt, i, pass = 0, hexmode = 0, force = 0;
|
2000-07-07 19:18:14 +04:00
|
|
|
char passwd[SKEY_MAX_PW_LEN+1], key[SKEY_BINKEY_SIZE];
|
2000-07-07 19:45:00 +04:00
|
|
|
char buf[33], *seed, *slash, *t;
|
1994-05-24 10:47:42 +04:00
|
|
|
|
|
|
|
cnt = 1;
|
|
|
|
|
2000-09-14 23:18:24 +04:00
|
|
|
while ((i = getopt(argc, argv, "fn:p:t:x")) != -1) {
|
1994-05-24 10:47:42 +04:00
|
|
|
switch (i) {
|
2000-09-14 23:18:24 +04:00
|
|
|
case 'f':
|
|
|
|
force = 1;
|
|
|
|
break;
|
|
|
|
|
1994-05-24 10:47:42 +04:00
|
|
|
case 'n':
|
|
|
|
cnt = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'p':
|
2000-09-14 19:26:42 +04:00
|
|
|
if (strlcpy(passwd, optarg, sizeof(passwd)) >=
|
2000-07-07 19:18:14 +04:00
|
|
|
sizeof(passwd))
|
|
|
|
errx(1, "Password too long");
|
1994-05-24 10:47:42 +04:00
|
|
|
pass = 1;
|
|
|
|
break;
|
2000-07-07 19:18:14 +04:00
|
|
|
case 't':
|
|
|
|
if (skey_set_algorithm(optarg) == NULL) {
|
|
|
|
errx(1, "Unknown hash algorithm %s", optarg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
hexmode = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(argv[0]);
|
|
|
|
break;
|
1994-05-24 10:47:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* could be in the form <number>/<seed> */
|
|
|
|
if (argc <= optind + 1) {
|
|
|
|
/* look for / in it */
|
1994-12-29 02:17:52 +03:00
|
|
|
if (argc <= optind)
|
1994-05-24 10:47:42 +04:00
|
|
|
usage(argv[0]);
|
|
|
|
slash = strchr(argv[optind], '/');
|
1994-12-29 02:17:52 +03:00
|
|
|
if (slash == NULL)
|
1994-05-24 10:47:42 +04:00
|
|
|
usage(argv[0]);
|
|
|
|
*slash++ = '\0';
|
|
|
|
seed = slash;
|
|
|
|
|
|
|
|
if ((n = atoi(argv[optind])) < 0) {
|
1994-12-29 02:17:52 +03:00
|
|
|
fprintf(stderr, "%s not positive\n", argv[optind]);
|
1994-05-24 10:47:42 +04:00
|
|
|
usage(argv[0]);
|
2000-07-07 19:18:14 +04:00
|
|
|
} else if (n > SKEY_MAX_SEQ) {
|
|
|
|
warnx("%d is larger than max (%d)", n, SKEY_MAX_SEQ);
|
|
|
|
usage(argv[0]);
|
1994-05-24 10:47:42 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ((n = atoi(argv[optind])) < 0) {
|
1994-12-29 02:17:52 +03:00
|
|
|
fprintf(stderr, "%s not positive\n", argv[optind]);
|
1994-05-24 10:47:42 +04:00
|
|
|
usage(argv[0]);
|
2000-07-07 19:18:14 +04:00
|
|
|
} else if (n > SKEY_MAX_SEQ) {
|
|
|
|
warnx("%d is larger than max (%d)", n, SKEY_MAX_SEQ);
|
|
|
|
usage(argv[0]);
|
1994-05-24 10:47:42 +04:00
|
|
|
}
|
|
|
|
seed = argv[++optind];
|
|
|
|
}
|
|
|
|
|
2000-07-07 19:45:00 +04:00
|
|
|
for(t = seed; *t; t++) {
|
|
|
|
if(!isalnum(*t))
|
|
|
|
errx(1, "seed must be alphanumeric");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!*seed || strlen(seed) > SKEY_MAX_SEED_LEN)
|
|
|
|
errx(1, "seed must be between 1 and %d long", SKEY_MAX_SEED_LEN);
|
|
|
|
|
1994-05-24 10:47:42 +04:00
|
|
|
/* Get user's secret password */
|
|
|
|
if (!pass) {
|
2000-07-07 19:18:14 +04:00
|
|
|
(void)fputs("Reminder - Do not use this program while "
|
|
|
|
"logged in via telnet or rlogin.\n", stderr);
|
1994-12-29 02:17:52 +03:00
|
|
|
fprintf(stderr, "Enter secret password: ");
|
1994-05-24 10:47:42 +04:00
|
|
|
readpass(passwd, sizeof(passwd));
|
2000-07-07 19:18:14 +04:00
|
|
|
if (passwd[0] == '\0')
|
|
|
|
exit(1);
|
1994-05-24 10:47:42 +04:00
|
|
|
}
|
|
|
|
|
2000-09-14 23:18:24 +04:00
|
|
|
if(strlen(passwd) < SKEY_MIN_PW_LEN && !force)
|
2000-07-07 19:45:00 +04:00
|
|
|
errx(1, "password must be at least %d long", SKEY_MIN_PW_LEN);
|
|
|
|
|
1994-05-24 10:47:42 +04:00
|
|
|
/* Crunch seed and password into starting key */
|
2000-07-07 19:18:14 +04:00
|
|
|
if (keycrunch(key, seed, passwd) != 0)
|
|
|
|
errx(1, "key crunch failed");
|
|
|
|
|
1994-05-24 10:47:42 +04:00
|
|
|
if (cnt == 1) {
|
|
|
|
while (n-- != 0)
|
|
|
|
f(key);
|
2000-07-07 19:18:14 +04:00
|
|
|
(void)puts(hexmode ? put8(buf, key) : btoe(buf, key));
|
1994-05-24 10:47:42 +04:00
|
|
|
} else {
|
|
|
|
for (i = 0; i <= n - cnt; i++)
|
|
|
|
f(key);
|
|
|
|
for (; i <= n; i++) {
|
2000-07-07 19:18:14 +04:00
|
|
|
(void)printf("%3d: %-29s", i, btoe(buf, key));
|
|
|
|
if (hexmode)
|
|
|
|
(void)printf("\t%s", put8(buf, key));
|
|
|
|
puts("");
|
1994-05-24 10:47:42 +04:00
|
|
|
f(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-07 19:18:14 +04:00
|
|
|
usage(char *s)
|
1994-05-24 10:47:42 +04:00
|
|
|
{
|
1994-12-29 02:17:52 +03:00
|
|
|
|
|
|
|
fprintf(stderr,
|
2000-09-14 23:18:24 +04:00
|
|
|
"Usage: %s [-f] [-n count] [-p password ] [-t hash] [-x] sequence#"
|
2000-07-07 19:18:14 +04:00
|
|
|
"[/] key\n", s);
|
1994-12-29 02:17:52 +03:00
|
|
|
exit(1);
|
1994-05-24 10:47:42 +04:00
|
|
|
}
|