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 fflush (stdout);
00024 }
00025
00026 int main () {
00027 CK_RV rv;
00028
00029 printf ("Version: %08x\n", pkcs11h_getVersion ());
00030 printf ("Features: %08x\n", pkcs11h_getFeatures ());
00031
00032 printf ("Initializing pkcs11-helper\n");
00033
00034 if ((rv = pkcs11h_initialize ()) != CKR_OK) {
00035 fatal ("pkcs11h_initialize failed", rv);
00036 }
00037
00038 printf ("Registering pkcs11-helper hooks\n");
00039
00040 if ((rv = pkcs11h_setLogHook (_pkcs11h_hooks_log, NULL)) != CKR_OK) {
00041 fatal ("pkcs11h_setLogHook failed", rv);
00042 }
00043
00044 pkcs11h_setLogLevel (TEST_LOG_LEVEL);
00045
00046 printf ("Adding provider '%s'\n", TEST_PROVIDER);
00047
00048 if (
00049 (rv = pkcs11h_addProvider (
00050 TEST_PROVIDER,
00051 TEST_PROVIDER,
00052 FALSE,
00053 PKCS11H_PRIVATEMODE_MASK_AUTO,
00054 PKCS11H_SLOTEVENT_METHOD_AUTO,
00055 0,
00056 FALSE
00057 )) != CKR_OK
00058 ) {
00059 fatal ("pkcs11h_addProvider failed", rv);
00060 }
00061
00062 printf ("Terminating pkcs11-helper\n");
00063
00064 if ((rv = pkcs11h_terminate ()) != CKR_OK) {
00065 fatal ("pkcs11h_terminate failed", rv);
00066 }
00067
00068 exit (0);
00069 return 0;
00070 }