Exemplo n.º 1
0
void pkcs11_release_slot(PKCS11_CTX * ctx, PKCS11_SLOT * slot)
{
	PKCS11_SLOT_private *priv = PRIVSLOT(slot);

	if (priv) {
		if (priv->prev_pin) {
			OPENSSL_cleanse(priv->prev_pin, strlen(priv->prev_pin));
			OPENSSL_free(priv->prev_pin);
		}
		CRYPTO_destroy_dynlockid(priv->lockid);
		CRYPTOKI_call(ctx, C_CloseAllSessions(priv->id));
	}
	OPENSSL_free(slot->_private);
	OPENSSL_free(slot->description);
	OPENSSL_free(slot->manufacturer);
	if (slot->token) {
		pkcs11_destroy_token(slot->token);
		OPENSSL_free(slot->token);
	}

	memset(slot, 0, sizeof(*slot));
}
Exemplo n.º 2
0
CK_DEFINE_FUNCTION(CK_RV, C_Finalize)(
    CK_VOID_PTR pReserved
)
{
    UINT32 i;
    if(!g_isCryptokiInitialized) return CKR_CRYPTOKI_NOT_INITIALIZED;
    if(pReserved != NULL        ) return CKR_ARGUMENTS_BAD;


    for(i=0; i<g_CryptokiSlotCount; i++)
    {
        C_CloseAllSessions(i);
        
        if(g_CryptokiSlots[i].Token->TokenState && g_CryptokiSlots[i].Token->TokenState->Uninitialize)
        {
            g_CryptokiSlots[i].Token->TokenState->Uninitialize();
        }
    }

    g_isCryptokiInitialized = FALSE;
    
    return CKR_OK;
}
Exemplo n.º 3
0
/* C_Finalize indicates that an application is done with the
 * Cryptoki library. */
CK_DEFINE_FUNCTION(CK_RV, C_Finalize)(
        CK_VOID_PTR pReserved
)
{
  CK_RV rv = CKR_OK;
  CK_SLOT_ID_PTR slot_list =NULL_PTR;
  CK_ULONG slot_num =0;
  CK_ULONG i;

  CI_LogEntry("C_Finalize", "starting...", rv, 1);

    /* make sure we are initialized */
  if (!(CK_I_global_flags & CK_IGF_INITIALIZED)) 
    return CKR_CRYPTOKI_NOT_INITIALIZED;

  if(pReserved != NULL_PTR)
    return CKR_ARGUMENTS_BAD;

  /* there can only be sessions on slot that have token */
  rv = C_GetSlotList(TRUE,NULL_PTR,&slot_num);
  if(rv != CKR_OK)
    {
      CI_LogEntry("C_Finalize", "getting count of slots", rv, 0);
      return rv;
    }

  slot_list = TC_malloc(slot_num*sizeof(CK_SLOT_ID_PTR));
  if( slot_list == NULL_PTR)
    {
      rv = CKR_HOST_MEMORY;
      CI_LogEntry("C_Finalize", "getting space for slot list", rv, 0);
      return rv;
    }

  rv = C_GetSlotList(TRUE,slot_list,&slot_num);
  if(rv != CKR_OK)
    {
      CI_LogEntry("C_Finalize", "getting slots list", rv, 0);
      return rv;
    }
  
  for(i =0 ; i< slot_num ; i++)
    {
      /* Deallocate all Sessions */
      rv = C_CloseAllSessions(slot_list[i]);
      if(rv != CKR_OK)
	{
	  CI_VarLogEntry("C_Finalize", "removing all sessions in slot %i", rv, 0,
			 slot_list[i]);
	  return rv;
	}

      /* Call CI_FinalizeToken in all Tokens */
      rv = CI_RemoveToken(slot_list[i]);
      if(rv != CKR_OK)
	{
	  CI_VarLogEntry("C_Finalize", "finalizing token in slot %i", rv, 0,
			 slot_list[i]);
	  return rv;
	}
    }
  TC_free(slot_list);

  //CI_DestroyHashtable(CK_I_app_table.session_table);
  if (CK_I_app_table.session_table != NULL_PTR)
  {
  CI_DestroyHashtable(CK_I_app_table.session_table);
  CK_I_app_table.session_table = NULL_PTR;
  }

  /**** assert that there are no remaining objects ****/
  rv = CI_ObjFinalize();
  if(rv != CKR_OK) 
    {
       CI_LogEntry("CI_InternalCloseSession",
		  "failed to clear objects",rv,0);
      return rv;
    }

#ifdef CK_GENERIC
  /* The call for the Win32 code will be done from DllMain() */
  rv = CI_UnloadDlls();
  if(rv != CKR_OK) 
    {
       CI_LogEntry("C_Finalize",
		  "failed to unload Dlls",rv,0);
      return rv;
    }
#endif  

  CK_I_global_flags ^= CK_IGF_INITIALIZED;
  CI_LogEntry("C_Finalize", "...complete", rv, 1);
  return rv;
}