]> www.average.org Git - pam_pcsc_cr.git/blob - test_auth.c
421c8b93149e3c232cf3e36673b9433f3e515ef0
[pam_pcsc_cr.git] / test_auth.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include "authobj.h"
5 #include "crypto.h"
6
7 int main(int argc, char *argv[])
8 {
9         const char *id = "testuser";
10         const char *pass = "testpassword";
11         const char *nonce = "1";
12         const unsigned char secret[] = {0xb4, 0x62, 0xf2, 0x60, 0x87,
13                                         0x78, 0x16, 0x87, 0xde, 0xce,
14                                         0x80, 0x09, 0x24, 0x0b, 0x93,
15                                         0xfc, 0xa0, 0xfc, 0x56, 0x56};
16         const unsigned char *payload = (unsigned char *)
17                                         "To authorize or not to authorize?";
18         int i;
19         struct _auth_obj ao;
20         struct _auth_obj nao;
21
22         printf("using crypto %s\n", crypto_init(0));
23         ao = new_authobj(id, pass, nonce, secret, sizeof(secret),
24                         payload, strlen((char *)payload));
25         printf("new_authobj err=%s\n", ao.err?ao.err:"<no error>");
26         printf("data(%d):", ao.datasize);
27         for (i = 0; i < ao.datasize; i++) printf(" %02x", ao.data[i]);
28         printf("\npayload(%d): \"%.*s\"\n", ao.paylsize, ao.paylsize,
29                 ao.payload?(char*)ao.payload:"");
30         if (ao.err) {
31                 if (ao.buffer) free(ao.buffer);
32                 return 1;
33         }
34
35         nao = verify_authobj(id, pass, nonce, nonce, ao.data, ao.datasize);
36         printf("verify_authobj err=%s\n", nao.err?nao.err:"<no error>");
37         printf("data(%d):", nao.datasize);
38         for (i = 0; i < nao.datasize; i++) printf(" %02x", nao.data[i]);
39         printf("\npayload(%d): \"%.*s\"\n", nao.paylsize, nao.paylsize,
40                 nao.payload?(char*)nao.payload:"");
41         if (nao.err) {
42                 if (nao.buffer) free(nao.buffer);
43                 return 1;
44         }
45         if (ao.paylsize != nao.paylsize ||
46                         memcmp(ao.payload, nao.payload, ao.paylsize)) {
47                 printf("payload does not match");
48                 return 1;
49         }
50
51         if (ao.buffer) free(ao.buffer);
52         if (nao.buffer) free(nao.buffer);
53         return 0;
54 }