narkive is for sale. Interested? (dismiss)
Discussion:
Certificate Store Provider Example
(too old to reply)
Juan Segarra
2004-06-03 16:24:20 UTC
Permalink
Hi All. I'm programming a certificate store provider function that loads
certificates (or tries to) stored in a USB stick with a custom
format. I've registered the new CertDllOpenStoreProv and seems to be ok.
I've created and registered a new Physical Store under MY but when I
open it, the CertDllOpenStoreProv of my DLL is not called.

I don't know what I'm doing wrong. Below i've pasted the code
implemented. Any comment will be very valuable. Thanks in advance.

Juan.


#define UJISTORE_OID "UJIStoreProvider"


BOOL WINAPI CertDllOpenStoreProv(
IN LPCSTR lpszStoreProvider,
IN DWORD dwEncodingType,
IN HCRYPTPROV hCryptProv,
IN DWORD dwFlags,
IN const void *pvPara,
IN HCERTSTORE hCertStore,
IN OUT PCERT_STORE_PROV_INFO pStoreProvInfo
)
{

FILE *fp;

/*
* Just for testing pourposes
*/

fp = fopen("C:\\fistroPecador", "w");
fclose(fp);

return TRUE;
}


// The DllRegisterServer Entry Point
STDAPI DllRegisterServer(void)
{
// Declare and initialize variables.

LPCWSTR pvSystemName= L"UJIStore"; // For this setting of
// dwFlags, the store name may
// be prefixed with a user name.
DWORD dwFlags= CERT_SYSTEM_STORE_CURRENT_USER;
CERT_PHYSICAL_STORE_INFO PhysicalStoreInfo;

/*
* Registramos la nueva funcionalidad
*/

if(!CryptRegisterOIDFunction(
X509_ASN_ENCODING, // Encoding type
CRYPT_OID_OPEN_STORE_PROV_FUNC, // Function name
UJISTORE_OID, // OID
L"UJIStoreProvider.dll", // Dll name
"CertDllOpenStoreProv" // Override function
)) // name
{
return E_FAIL;
}

// Initialize PhysicalStoreInfo.

memset(&PhysicalStoreInfo, 0, sizeof(CERT_PHYSICAL_STORE_INFO));

PhysicalStoreInfo.cbSize = sizeof(CERT_PHYSICAL_STORE_INFO);
PhysicalStoreInfo.pszOpenStoreProvider = (LPSTR)UJISTORE_OID;
PhysicalStoreInfo.dwFlags = CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG;
PhysicalStoreInfo.OpenParameters.pbData = NULL;
PhysicalStoreInfo.OpenParameters.cbData = 0;
PhysicalStoreInfo.dwPriority = 1;
PhysicalStoreInfo.dwOpenEncodingType = X509_ASN_ENCODING;

// Register the physical store.

if(!CertRegisterPhysicalStore(
L"MY",
dwFlags,
L"UJIStore",
&PhysicalStoreInfo,
NULL
))
{
return E_FAIL;
}


return S_OK;
}



// The DllUnregisterServer Entry Point

STDAPI DllUnregisterServer(void)
{
HRESULT hr = S_OK;

if ( !CertUnregisterPhysicalStore(L"MY",CERT_SYSTEM_STORE_CURRENT_USER,
L"UJIStore") )
{

return E_FAIL;

}


if(!CryptUnregisterOIDFunction(
X509_ASN_ENCODING, // Encoding type
CRYPT_OID_OPEN_STORE_PROV_FUNC, // Function name
UJISTORE_OID // OID
))
{
if(ERROR_FILE_NOT_FOUND != GetLastError())
hr = E_FAIL;
}

return hr;
}
Jose
2014-11-13 16:38:09 UTC
Permalink
Hola Juan,

No se si me leerás, veo que tu mensaje es de hace 10 años ;)

Estoy intentando hacer algo parecido.. ¿Conseguiste solucionar el problema? ¿Tienes o sabes donde conseguir algún ejemplo del proceso?

Gracias!

Loading...