]> www.average.org Git - pam_pcsc_cr.git/blob - test_chalresp.c
systematize authobj errors
[pam_pcsc_cr.git] / test_chalresp.c
1 #ifdef HAVE_CONFIG_H
2 # include "config.h"
3 #endif
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <string.h>
8 #include "pcsc_cr.h"
9
10 static void usage(const char const *cmd)
11 {
12         fprintf(stderr,
13                 "usage: %s [-o backend:name=value] ... \"challenge\"\n",
14                 cmd);
15 }
16
17 int main(int argc, char *argv[])
18 {
19         unsigned char chal[64];
20         int csize;
21         unsigned char rbuf[20];
22         int rsize = sizeof(rbuf);
23         int i;
24         long rc;
25         int c;
26
27         while ((c = getopt(argc, argv, "ho:")) != -1) switch (c) {
28         case 'h':
29                 usage(argv[0]);
30                 exit(0);
31         case 'o':
32                 if (pcsc_option(optarg)) {
33                         fprintf(stderr, "Option \"%s\" bad\n", optarg);
34                         exit(1);
35                 }
36                 break;
37         default:
38                 usage(argv[0]);
39                 exit(1);
40         }
41         if (optind != (argc - 1)) {
42                 usage(argv[0]);
43                 exit(1);
44         }
45
46         csize = strlen(argv[optind]);
47         if (csize > sizeof(chal)) {
48                 fprintf(stderr, "Challenge longer than %d, cannot do that\n",
49                         csize);
50                 exit(1);
51         }
52 #if 0
53         printf("\nIf the key is set to \"Jefe\" like this:\n"
54         "$ ykpersonalize -2 -o chal-resp -o chal-hmac -o hmac-lt64 \\\n"
55         "\t-a 4a65666500000000000000000000000000000000\n"
56         "and the challenge is \"what do ya want for nothing?\"\n"
57         "the result must be                  "
58         "\"ef fc df 6a e5 eb 2f a2 d2 74 16 d5 f1 84 df 9c 25 9a 7c 79\"\n");
59 #endif
60         memset(chal, 0x00, sizeof(chal));
61         memcpy(chal, argv[optind], csize);
62         
63         memset(rbuf, 0xFE, sizeof(rbuf));
64         rc = pcsc_cr(chal, csize, rbuf, &rsize);
65         printf("rc=%ld (%s) rsize=%d:", rc, pcsc_errstr(rc), rsize);
66         for (i = 0; i < rsize; i++) printf(" %02x", rbuf[i]);
67         printf("\n");
68         return rc;
69 }