7 unsigned char secret[] = {
8 0xb4, 0x62, 0xf2, 0x60, 0x87, 0x78, 0x16, 0x87, 0xde, 0xce,
9 0x80, 0x09, 0x24, 0x0b, 0x93, 0xfc, 0xa0, 0xfc, 0x56, 0x56
12 static struct _auth_chunk
13 fetch_key(const unsigned char *challenge, const int challengesize)
15 struct _auth_chunk ho = {0};
17 int keysize = sizeof(ho.data);
19 #if 0 /* The "real" fetch_key shall do this: */
20 if ((rc = pcsc_cr(challenge, challengesize, ho.data, &keysize))) {
21 ho.err = pcsc_errstr(rc);
23 #else /* Instead, duplicate make_key so it works without the token */
24 if ((rc = hmac(secret, sizeof(secret), challenge, challengesize,
25 &ho.data, &keysize))) {
26 ho.err = crypto_errstr(rc);
27 } else if (keysize != sizeof(ho.data)) {
28 ho.err = "make_key: hash size is wrong";
34 int main(int argc, char *argv[])
36 const char *id = "testuser";
37 const char *pass = "testpassword";
38 const char *nonce = "1";
39 const unsigned char *payload = (unsigned char *)
40 "To authorize or not to authorize?";
45 if (argc == 2 && strlen(argv[1]) == 40 &&
46 strspn(argv[1], "0123456789abcdefABCDEF") == 40) {
47 for (i = 0; i < sizeof(secret); i++)
48 sscanf(&argv[1][i*2], "%2hhx", &secret[i]);
50 ao = new_authobj(id, pass, nonce, secret, sizeof(secret),
51 payload, strlen((char *)payload));
52 printf("new_authobj err=%s\n", ao.err?ao.err:"<no error>");
53 printf("data(%d):", ao.datasize);
54 for (i = 0; i < ao.datasize; i++) printf(" %02x", ao.data[i]);
55 printf("\npayload(%d): \"%.*s\"\n", ao.paylsize, ao.paylsize,
56 ao.payload?(char*)ao.payload:"");
58 if (ao.buffer) free(ao.buffer);
62 nao = verify_authobj(id, pass, nonce, nonce, ao.data, ao.datasize);
63 printf("verify_authobj err=%s\n", nao.err?nao.err:"<no error>");
64 printf("data(%d):", nao.datasize);
65 for (i = 0; i < nao.datasize; i++) printf(" %02x", nao.data[i]);
66 printf("\npayload(%d): \"%.*s\"\n", nao.paylsize, nao.paylsize,
67 nao.payload?(char*)nao.payload:"");
69 if (nao.buffer) free(nao.buffer);
72 if (ao.paylsize != nao.paylsize ||
73 memcmp(ao.payload, nao.payload, ao.paylsize)) {
74 printf("payload does not match");
78 if (ao.buffer) free(ao.buffer);
79 if (nao.buffer) free(nao.buffer);