]> www.average.org Git - pam_pcsc_cr.git/blob - test_chalresp.c
base64: check sizes
[pam_pcsc_cr.git] / test_chalresp.c
1 /*
2 Copyright (c) 2013 Eugene Crosser
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12     1. The origin of this software must not be misrepresented; you must
13     not claim that you wrote the original software. If you use this
14     software in a product, an acknowledgment in the product documentation
15     would be appreciated but is not required.
16
17     2. Altered source versions must be plainly marked as such, and must
18     not be misrepresented as being the original software.
19
20     3. This notice may not be removed or altered from any source
21     distribution.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include "pcsc_cr.h"
32
33 static void usage(const char const *cmd)
34 {
35         fprintf(stderr,
36                 "usage: %s [-o backend:name=value] ... \"challenge\"\n",
37                 cmd);
38 }
39
40 int main(int argc, char *argv[])
41 {
42         unsigned char chal[64];
43         int csize;
44         unsigned char rbuf[20];
45         int rsize = sizeof(rbuf);
46         int i;
47         long rc;
48         int c;
49
50         while ((c = getopt(argc, argv, "ho:")) != -1) switch (c) {
51         case 'h':
52                 usage(argv[0]);
53                 exit(0);
54         case 'o':
55                 if (pcsc_option(optarg)) {
56                         fprintf(stderr, "Option \"%s\" bad\n", optarg);
57                         exit(1);
58                 }
59                 break;
60         default:
61                 usage(argv[0]);
62                 exit(1);
63         }
64         if (optind != (argc - 1)) {
65                 usage(argv[0]);
66                 exit(1);
67         }
68
69         csize = strlen(argv[optind]);
70         if (csize > sizeof(chal)) {
71                 fprintf(stderr, "Challenge longer than %d, cannot do that\n",
72                         csize);
73                 exit(1);
74         }
75 #if 0
76         printf("\nIf the key is set to \"Jefe\" like this:\n"
77         "$ ykpersonalize -2 -o chal-resp -o chal-hmac -o hmac-lt64 \\\n"
78         "\t-a 4a65666500000000000000000000000000000000\n"
79         "and the challenge is \"what do ya want for nothing?\"\n"
80         "the result must be                  "
81         "\"ef fc df 6a e5 eb 2f a2 d2 74 16 d5 f1 84 df 9c 25 9a 7c 79\"\n");
82 #endif
83         memset(chal, 0x00, sizeof(chal));
84         memcpy(chal, argv[optind], csize);
85         
86         memset(rbuf, 0xFE, sizeof(rbuf));
87         rc = pcsc_cr(chal, csize, rbuf, &rsize);
88         printf("rc=%ld (%s) rsize=%d:", rc, pcsc_errstr(rc), rsize);
89         for (i = 0; i < rsize; i++) printf(" %02x", rbuf[i]);
90         printf("\n");
91         return rc;
92 }