1994-05-19 18:13:11 +00:00
|
|
|
/* 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
|
|
|
|
* C848 666B 6435 0A93
|
|
|
|
* >
|
|
|
|
*/
|
1997-07-16 06:51:12 +00:00
|
|
|
|
|
|
|
#include <err.h>
|
1994-05-19 18:13:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1997-07-16 06:51:12 +00:00
|
|
|
#include <unistd.h>
|
1994-10-19 00:03:45 +00:00
|
|
|
|
1994-05-19 18:13:11 +00:00
|
|
|
#ifdef __MSDOS__
|
|
|
|
#include <dos.h>
|
|
|
|
#else /* Assume BSD unix */
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
1994-10-19 00:03:45 +00:00
|
|
|
|
1994-06-02 20:25:30 +00:00
|
|
|
#include <skey.h>
|
1994-05-19 18:13:11 +00:00
|
|
|
|
1997-07-16 06:51:12 +00:00
|
|
|
static void usage __P((void));
|
1994-05-19 18:13:11 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(argc,argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
|
|
|
int n,cnt,i;
|
1997-07-16 06:51:12 +00:00
|
|
|
char passwd[256] /* ,passwd2[256] */;
|
1994-05-19 18:13:11 +00:00
|
|
|
char key[8];
|
|
|
|
char *seed;
|
|
|
|
char buf[33];
|
|
|
|
char *slash;
|
|
|
|
|
|
|
|
cnt = 1;
|
1997-03-29 04:34:07 +00:00
|
|
|
while((i = getopt(argc,argv,"n:")) != -1){
|
1994-05-19 18:13:11 +00:00
|
|
|
switch(i){
|
|
|
|
case 'n':
|
|
|
|
cnt = atoi(optarg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* could be in the form <number>/<seed> */
|
|
|
|
if(argc <= optind + 1){
|
|
|
|
/*look for / in it */
|
1997-07-16 06:51:12 +00:00
|
|
|
if(argc <= optind)
|
|
|
|
usage();
|
1994-05-19 18:13:11 +00:00
|
|
|
|
|
|
|
slash = strchr(argv[optind], '/');
|
1997-07-16 06:51:12 +00:00
|
|
|
if(slash == NULL)
|
|
|
|
usage();
|
1994-05-19 18:13:11 +00:00
|
|
|
*slash++ = '\0';
|
|
|
|
seed = slash;
|
|
|
|
|
|
|
|
if((n = atoi(argv[optind])) < 0){
|
|
|
|
fprintf(stderr,"%s not positive\n",argv[optind]);
|
1997-07-16 06:51:12 +00:00
|
|
|
usage();
|
1994-05-19 18:13:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
if((n = atoi(argv[optind])) < 0){
|
|
|
|
fprintf(stderr,"%s not positive\n",argv[optind]);
|
1997-07-16 06:51:12 +00:00
|
|
|
usage();
|
1994-05-19 18:13:11 +00:00
|
|
|
}
|
|
|
|
seed = argv[++optind];
|
|
|
|
}
|
|
|
|
fprintf(stderr,"Reminder - Do not use this program while logged in via telnet or rlogin.\n");
|
|
|
|
|
|
|
|
/* Get user's secret password */
|
|
|
|
for(;;){
|
|
|
|
fprintf(stderr,"Enter secret password: ");
|
|
|
|
readpass(passwd,sizeof(passwd));
|
|
|
|
break;
|
|
|
|
/************
|
|
|
|
fprintf(stderr,"Again secret password: ");
|
|
|
|
readpass(passwd2,sizeof(passwd));
|
|
|
|
if(strcmp(passwd,passwd2) == 0) break;
|
|
|
|
fprintf(stderr, "Sorry no match\n");
|
|
|
|
**************/
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-19 18:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Crunch seed and password into starting key */
|
1997-07-16 06:51:12 +00:00
|
|
|
if(keycrunch(key,seed,passwd) != 0)
|
|
|
|
errx(1, "key crunch failed");
|
1994-05-19 18:13:11 +00:00
|
|
|
if(cnt == 1){
|
|
|
|
while(n-- != 0)
|
|
|
|
f(key);
|
|
|
|
printf("%s\n",btoe(buf,key));
|
|
|
|
#ifdef HEXIN
|
|
|
|
printf("%s\n",put8(buf,key));
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
for(i=0;i<=n-cnt;i++)
|
|
|
|
f(key);
|
|
|
|
for(;i<=n;i++){
|
|
|
|
#ifdef HEXIN
|
|
|
|
printf("%d: %-29s %s\n",i,btoe(buf,key),put8(buf,key));
|
|
|
|
#else
|
|
|
|
printf("%d: %-29s\n",i,btoe(buf,key));
|
|
|
|
#endif
|
1995-05-30 06:41:30 +00:00
|
|
|
f(key);
|
1994-05-19 18:13:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1994-10-19 00:03:45 +00:00
|
|
|
|
1997-07-16 06:51:12 +00:00
|
|
|
static void
|
|
|
|
usage()
|
1994-05-19 18:13:11 +00:00
|
|
|
{
|
1997-07-16 06:51:12 +00:00
|
|
|
fprintf(stderr,"usage: key [-n count] <sequence #>[/] <key>\n");
|
|
|
|
exit(1);
|
1994-05-19 18:13:11 +00:00
|
|
|
}
|