Some SlackBuild scripts for Slackware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.3 KiB

commit 5580b0ac2d73582f84cedb8fb16293482818b854
Author: Damien Goutte-Gattat <dgouttegattat@incenp.org>
Date: Sat Feb 29 20:49:03 2020 +0000
scdtotp: Add the -u, --uri option.
Add an option to scdtotp to allow the user to specified a otpauth://
URI directly on the command line, completely bypassing the smartcard.
This is mainly intended for debugging or demo purposes.
diff --git a/man/scdtotp.1.in b/man/scdtotp.1.in
index 880a2f0..32204a1 100644
--- a/man/scdtotp.1.in
+++ b/man/scdtotp.1.in
@@ -19,6 +19,8 @@ scdtotp \- Generate one-time passwords from an OpenPGP smartcard
.IR algo ]
.RB [ \-n | --private-do
.IR N ]
+.RB [ \-u | --uri
+.IR URI ]
.YS
.SH DESCRIPTION
@@ -68,6 +70,10 @@ algorithm is specified on the smartcard.
.BR -n ", " --private-do " " \fiN\fR
Read key from private DO slot #\fiN\fR
(default is @DEFAULT_PRIVATE_DO@.)
+.TP
+.BR -u ", " --uri " " \fiURI\fR
+Use the specified \fiURI\fR directly instead
+of fetching it from a smartcard.
.SH REPORTING BUGS
.PP
diff --git a/src/scdtotp.c b/src/scdtotp.c
index 45517b5..040e2eb 100644
--- a/src/scdtotp.c
+++ b/src/scdtotp.c
@@ -70,6 +70,12 @@ read from the smartcard:\n\
be 'sha1', 'sha256', or 'sha512').\n\
");
+ puts("\
+ -u, --uri URI Use the specified URI directly.\n\
+ No attempt to read a URI from a\n\
+ smartcard will be made.\n\
+");
+
printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
exit(status);
@@ -296,6 +302,7 @@ main(int argc, char **argv)
{ "digits", 1, NULL, 'd' },
{ "mac-algo", 1, NULL, 'm' },
{ "private-do", 1, NULL, 'n' },
+ { "uri", 1, NULL, 'u' },
{ NULL, 0, NULL, 0 }
};
@@ -304,8 +311,9 @@ main(int argc, char **argv)
algo = period = digits = UNSET_PARAM;
privatedo = DEFAULT_PRIVATE_DO;
value = window = 0;
+ otp = NULL;
- while ( (c = getopt_long(argc, argv, "hvt:w:p:d:m:n:",
+ while ( (c = getopt_long(argc, argv, "hvt:w:p:d:m:n:u:",
options, NULL)) != -1 ) {
switch ( c ) {
case 'h':
@@ -354,6 +362,11 @@ main(int argc, char **argv)
case 'w':
window = get_uinteger_or_die(optarg);
break;
+
+ case 'u':
+ if ( ! (otp = otp_parse_uri(optarg)) )
+ err(EXIT_FAILURE, "Cannot parse otpauth:// URI");
+ break;
}
}
@@ -363,11 +376,13 @@ main(int argc, char **argv)
gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
- if ( privatedo > 2 && (e = verify_pin(privatedo == 4)) )
- errx(EXIT_FAILURE, "Cannot get OTP info from token: %s", gcry_strerror(e));
+ if ( ! otp ) {
+ if ( privatedo > 2 && (e = verify_pin(privatedo == 4)) )
+ errx(EXIT_FAILURE, "Cannot get OTP info from token: %s", gcry_strerror(e));
- if ( (e = get_otp_params(privatedo, &otp)) )
- errx(EXIT_FAILURE, "Cannot get OTP info from token: %s", gcry_strerror(e));
+ if ( (e = get_otp_params(privatedo, &otp)) )
+ errx(EXIT_FAILURE, "Cannot get OTP info from token: %s", gcry_strerror(e));
+ }
if ( algo == UNSET_PARAM ) {
if ( otp->algo == OTP_ALGO_SHA1 )