PKCS#11 C_getfunctionlist in a dll

后端 未结 1 928
予麋鹿
予麋鹿 2021-01-24 00:41

I\'m trying to write a dll which will eventually connect to a virtual token. I tried to make an exportable C_getfunctionlist function which will contain pointer adressess to fun

1条回答
  •  迷失自我
    2021-01-24 01:26

    If you want to use a pkcs#11 implementation's functions in your code you have to load the dll which implements the standard and then use functions provided by the dll. Here comes the code I use on Linux system. I hope it helps.

    
    static char const * PKCS11_SO_NAME = "/usr/lib/pkcs11/PKCS11_API.so";
    
    static void * pkcs11_so;
    //list of all pkcs#11 functions
    static CK_FUNCTION_LIST_PTR pkcs11;
    
    CK_RV load_pkcs11() {
      CK_RV rv = CKR_OK;
      CK_RV (*C_GetFunctionList) (CK_FUNCTION_LIST_PTR_PTR) = 0;
    
      pkcs11_so = dlopen(PKCS11_SO_NAME, RTLD_NOW);
      if (!pkcs11_so) {
        fprintf(stderr, "Error loading pkcs#11 so: %s\n", dlerror());
        return CKR_GENERAL_ERROR;
      }
    
      rv = load_symbol((void **)&C_GetFunctionList, "C_GetFunctionList");
      if (CKR_OK != rv) {
        return rv;
      }
    
      rv = C_GetFunctionList(&pkcs11);
      if (CKR_OK != rv) {
        fprintf(stderr, "C_GetFunctionList call failed: 0x%.8lX", rv);
        return rv;
      }
    
      return CKR_OK;
    } 

    0 讨论(0)
提交回复
热议问题