1-
21#include " scitokens.h"
32
43#include < fstream>
@@ -9,7 +8,7 @@ namespace {
98
109const char usage[] =
1110 " \n "
12- " Syntax: %s [--cred cred_file] TOKEN\n "
11+ " Syntax: %s [--cred cred_file] < TOKEN\n "
1312 " \n "
1413 " Options\n "
1514 " -h | --help Display usage\n "
@@ -18,7 +17,8 @@ const char usage[] =
1817 " -K | --keyid <kid> Name of the token key.\n "
1918 " -p | --profile <profile> Profile to enforce (wlcg, scitokens1, "
2019 " scitokens2, atjwt).\n "
21- " \n " ;
20+ " \n "
21+ " The token to verify must be provided via standard input (stdin).\n " ;
2222
2323const struct option long_options[] = {{" help" , no_argument, NULL , ' h' },
2424 {" cred" , required_argument, NULL , ' c' },
@@ -87,18 +87,24 @@ int init_arguments(int argc, char *const argv[]) {
8787} // namespace
8888
8989int main (int argc, char *const *argv) {
90- if (argc < 2 ) {
91- fprintf (stderr,
92- " %s: Insufficient arguments; must at least provide a token.\n " ,
93- argv[0 ]);
94- fprintf (stderr, usage, argv[0 ]);
95- return 1 ;
96- }
90+
9791 if (init_arguments (argc, argv)) {
9892 return 1 ;
9993 }
10094
101- std::string token (argv[argc - 1 ]);
95+ std::string token;
96+ // If a positional argument is present, treat it as the token (with warning)
97+ if (optind < argc) {
98+ fprintf (stderr, " %s: Warning: Providing the token on the command line is insecure. Please use stdin instead.\n " , argv[0 ]);
99+ token = argv[optind];
100+ } else {
101+ // Read token from stdin
102+ std::getline (std::cin, token);
103+ }
104+ if (token.empty ()) {
105+ fprintf (stderr, " %s: No token provided on stdin or command line.\n " , argv[0 ]);
106+ return 1 ;
107+ }
102108
103109 if (!g_issuer.empty ()) {
104110 char *err_msg;
0 commit comments