1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <string.h> |
---|
4 | #include "esteid_certinfo.h" |
---|
5 | #include "esteid_sign.h" |
---|
6 | |
---|
7 | extern char EstEID_error[1024]; |
---|
8 | extern int EstEID_errorCode; |
---|
9 | |
---|
10 | char *promptForPIN(void *unused, const char *message, const char *name) { |
---|
11 | return strdup("01497"); |
---|
12 | } |
---|
13 | |
---|
14 | void showAlert(void *nativeWindowHandle, const char *message) { |
---|
15 | |
---|
16 | } |
---|
17 | |
---|
18 | void sign(const char* hash, EstEID_Certs *certs) { |
---|
19 | for (unsigned int i = 0; i < certs->certCount; i++) { |
---|
20 | EstEID_CertInfo *certInfo = certs->certs + i; |
---|
21 | if (certInfo->usageNonRepudiation) { |
---|
22 | printf("signing!\n"); |
---|
23 | EstEID_PINPromptData pinPromptData = { promptForPIN, showAlert, NULL }; |
---|
24 | char *signature; |
---|
25 | if (EstEID_signHashHex(&signature, certInfo, hash, pinPromptData)) { |
---|
26 | printf("signature: %s\n", signature); |
---|
27 | free(signature); |
---|
28 | } |
---|
29 | else { |
---|
30 | printf("error: %s (error code: %i)\n", EstEID_error, EstEID_errorCode); |
---|
31 | } |
---|
32 | } |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | int main(int argc, const char **argv) { |
---|
37 | |
---|
38 | EstEID_Certs *certs = EstEID_loadCerts(NULL); |
---|
39 | if (certs != NULL) { |
---|
40 | EstEID_printCerts(certs); |
---|
41 | while(1) { |
---|
42 | printf("tokensChanged: %i\n", EstEID_tokensChanged()); |
---|
43 | getchar(); |
---|
44 | } |
---|
45 | //EstEID_waitForSlotEvent(); |
---|
46 | if (argc == 2) sign(argv[1], certs); |
---|
47 | EstEID_freeCerts(certs); |
---|
48 | } |
---|
49 | else { |
---|
50 | printf("error: %s (error code: %i)\n", EstEID_error, EstEID_errorCode); |
---|
51 | } |
---|
52 | } |
---|