Add the -w, --window option

Add an option to generate several passwords corresponding to N
time steps before and after the current time.
develop
Damien Goutte-Gattat 8 years ago
parent 2d47bc5caa
commit a3586c6af2
  1. 6
      man/scdtotp.1.in
  2. 25
      src/scdtotp.c

@ -11,6 +11,8 @@ scdtotp \- Generate one-time passwords from an OpenPGP smartcard
.IR seconds ]
.RB [ \-p | --period
.IR seconds ]
.RB [ \-w | --window
.IR N ]
.RB [ \-d | --digits
.IR N ]
.RB [ \-m | --mac-algo
@ -47,6 +49,10 @@ instead of current time.
Force a period of \fiN\fR seconds. The default period
is 30 seconds, unless specified otherwise on the card.
.TP
.BR -w ", " --window " " \fiN\fR
Generate password for \fiN\fR time window around the
current time.
.TP
.BR -d ", " --digits " " \fiN\fR
Output a password of
.I N

@ -52,6 +52,8 @@ found in a OpenPGP smartcard.\n\
puts("\
-t, --time SECONDS Generate OTP for the specified time\n\
(in seconds) instead of current time.\n\
-w, --window N Generate OTP for N time windows around\n\
the current time.\n\
");
printf("\
@ -293,8 +295,8 @@ get_uinteger_or_die(const char *arg)
int
main(int argc, char **argv)
{
int c;
unsigned algo, period, digits, privatedo, value;
int c, n;
unsigned algo, period, digits, privatedo, value, window;
time_t secs;
gcry_error_t e;
otp_t *otp;
@ -303,6 +305,7 @@ main(int argc, char **argv)
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "time", 1, NULL, 't' },
{ "window", 1, NULL, 'w' },
{ "period", 1, NULL, 'p' },
{ "digits", 1, NULL, 'd' },
{ "mac-algo", 1, NULL, 'm' },
@ -314,8 +317,9 @@ main(int argc, char **argv)
secs = time(NULL);
algo = period = digits = UNSET_PARAM;
privatedo = DEFAULT_PRIVATE_DO;
value = window = 0;
while ( (c = getopt_long(argc, argv, "hvt:p:d:m:n:",
while ( (c = getopt_long(argc, argv, "hvt:w:p:d:m:n:",
options, NULL)) != -1 ) {
switch ( c ) {
case 'h':
@ -360,6 +364,10 @@ main(int argc, char **argv)
if ( privatedo < 1 || privatedo > 4 )
errx(EXIT_FAILURE, "DO number must be 1, 2, 3, or 4");
break;
case 'w':
window = get_uinteger_or_die(optarg);
break;
}
}
@ -390,11 +398,14 @@ main(int argc, char **argv)
if ( digits == UNSET_PARAM )
digits = otp->digits;
if ( (e = generate_totp(algo, otp->secret, otp->length, secs,
period, digits, &value)) )
errx(EXIT_FAILURE, "Cannot generate OTP: %s", gcry_strerror(e));
for ( n = -window; n < (signed) window + 1; n++ ) {
if ( (e = generate_totp(algo, otp->secret, otp->length,
secs + (n * (signed)period),
period, digits, &value)) )
errx(EXIT_FAILURE, "Cannot generate OTP: %s", gcry_strerror(e));
print_otp(value, digits);
print_otp(value, digits);
}
return EXIT_SUCCESS;
}

Loading…
Cancel
Save