source: murachi/esteidfirefoxplugin/common/test.c @ c4dd8d1

Last change on this file since c4dd8d1 was 7d3ae3e, checked in by antonioaraujob <aaraujo@…>, 9 years ago

Agregados archivos fuentes del complemento esteidfirefoxplugin de Estonia para firmar electrónicamente un hash.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include "esteid_certinfo.h"
5#include "esteid_sign.h"
6
7extern char EstEID_error[1024];
8extern int EstEID_errorCode;
9
10char *promptForPIN(void *unused, const char *message, const char *name) {
11        return strdup("01497");
12}
13
14void showAlert(void *nativeWindowHandle, const char *message) {
15
16}
17
18void 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
36int 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}
Note: See TracBrowser for help on using the repository browser.