1
1
/* tool.c --- Command line interface to libykclient.
3
* Written by Simon Josefsson <simon@josefsson.org>.
4
3
* Copyright (c) 2006, 2007, 2008, 2009, 2011 Yubico AB
5
4
* All rights reserved.
48
47
" --url URL Validation service URL (eg: \"http://api.yubico.com/wsapi/verify?id=%%d&otp=%%s\")\n"
48
" --apikey Key API key for HMAC validation of request/response\n";
51
50
static struct option long_options[] = {
52
51
{"url", 1, 0, 'u'},
52
{"apikey", 1, 0, 'a'},
56
56
/* Parse command line parameters. */
58
parse_args(int argc, char *argv[],
58
parse_args (int argc, char *argv[],
59
int *client_id, char **token, char **url, char **api_key)
67
63
int option_index = 0;
69
int c = getopt_long(argc, argv, "",
70
long_options, &option_index);
65
int c = getopt_long (argc, argv, "",
66
long_options, &option_index);
73
if (strlen (optarg) < 16)
76
"error: API key must be at least 16 characters");
77
if (strncmp ("http://", optarg, 7) != 0 && strncmp ("https://", optarg, 8) != 0)
78
errx (EXIT_FAILURE, "error: validation url must be http or https.");
82
if (strncmp ("http://", optarg, 7) != 0
83
&& strncmp ("https://", optarg, 8) != 0)
85
fprintf (stderr, "error: validation url must be http or https");
84
93
if (argc - optind != 2)
86
errx (EXIT_FAILURE, usage);
95
fprintf (stderr, "%s", usage);
89
99
/* Now get mandatory numeric client_id */
90
100
*client_id = atoi (argv[optind++]);
92
102
if (*client_id <= 0)
93
errx (EXIT_FAILURE, "error: client identity must be a non-zero integer.");
104
fprintf (stderr, "error: client identity must be a non-zero integer.");
95
108
/* Likewise mandatory OTP token */
96
109
*token = argv[optind++];
97
110
if (strlen (*token) < 32)
99
errx (EXIT_FAILURE, "error: ModHex encoded token must be at least 32 characters.");
113
"error: modhex encoded token must be at least 32 characters");
107
122
char *token, *url = NULL, *api_key = NULL;
110
parse_args (argc, argv,
125
parse_args (argc, argv, &client_id, &token, &url, &api_key);
118
128
fprintf (stderr, "Input:\n");
120
130
fprintf (stderr, " validation URL: %s\n", url);
121
131
fprintf (stderr, " client id: %d\n", client_id);
122
132
fprintf (stderr, " token: %s\n", token);
134
fprintf (stderr, " api key: %s\n", api_key);
124
ret = ykclient_verify_otp_v2 (NULL, token, client_id, NULL, 1, (const char **) &url, api_key);
137
ykclient_verify_otp_v2 (NULL, token, client_id, NULL, 1,
138
(const char **) &url, api_key);
126
140
printf ("Verification output (%d): %s\n", ret, ykclient_strerror (ret));