00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include "../../config.h"
00004 #include <pkcs11-helper-1.0/pkcs11h-core.h>
00005
00006 static
00007 void
00008 fatal (const char * const m, CK_RV rv) {
00009 fprintf (stderr, "%s - %08lu - %s\n", m, rv, pkcs11h_getMessage (rv));
00010 exit (1);
00011 }
00012
00013 static
00014 void
00015 _pkcs11h_hooks_log (
00016 IN void * const global_data,
00017 IN unsigned flags,
00018 IN const char * const format,
00019 IN va_list args
00020 ) {
00021 vfprintf (stdout, format, args);
00022 fprintf (stdout, "\n");
00023 }
00024
00025 int main () {
00026 CK_RV rv;
00027
00028 printf ("Version: %08x\n", pkcs11h_getVersion ());
00029 printf ("Features: %08x\n", pkcs11h_getFeatures ());
00030
00031 printf ("Initializing pkcs11-helper\n");
00032
00033 if ((rv = pkcs11h_initialize ()) != CKR_OK) {
00034 fatal ("pkcs11h_initialize failed", rv);
00035 }
00036
00037 printf ("Registering pkcs11-helper hooks\n");
00038
00039 if ((rv = pkcs11h_setLogHook (_pkcs11h_hooks_log, NULL)) != CKR_OK) {
00040 fatal ("pkcs11h_setLogHook failed", rv);
00041 }
00042
00043 pkcs11h_setLogLevel (TEST_LOG_LEVEL);
00044
00045 printf ("Adding provider '%s'\n", TEST_PROVIDER);
00046
00047 if (
00048 (rv = pkcs11h_addProvider (
00049 TEST_PROVIDER,
00050 TEST_PROVIDER,
00051 FALSE,
00052 PKCS11H_PRIVATEMODE_MASK_AUTO,
00053 PKCS11H_SLOTEVENT_METHOD_AUTO,
00054 0,
00055 FALSE
00056 )) != CKR_OK
00057 ) {
00058 fatal ("pkcs11h_terminate failed", rv);
00059 }
00060
00061 printf ("Terminating pkcs11-helper\n");
00062
00063 if ((rv = pkcs11h_terminate ()) != CKR_OK) {
00064 fatal ("pkcs11h_terminate failed", rv);
00065 }
00066
00067 exit (0);
00068 return 0;
00069 }