Beispiel #1
0
int EDT_CSP_EnumProviders()
{
	DWORD       dwIndex = 0;
	DWORD		dwProvType;
	DWORD       dwProvName;
	wchar_t     *pwcProvName = NULL; 

	LOG(L"CSP Providers found:\n");

	while(CryptEnumProviders(dwIndex, NULL, 0, &dwProvType, NULL, &dwProvName) == TRUE)
	{
		//dwProvName returns the length of pwcProvName
		pwcProvName = (wchar_t*)malloc(dwProvName);
		if(pwcProvName == NULL)
		{
			LOG_ERROR(L"EDT_CSP_EnumProviders : malloc failed\n");
			return EDT_ERR_INTERNAL;
		}
		if (CryptEnumProviders(dwIndex, NULL, 0, &dwProvType, pwcProvName, &dwProvName) == TRUE)
		{
			LOG(L"%d) name:%s type:%d\n",dwIndex,pwcProvName,dwProvType);
		}
		else
		{
			LOG_ERROR(L"CryptEnumProviders failed\n");
			return EDT_ERR_INTERNAL;
		}
		free(pwcProvName);
		dwIndex++;
	}
	return EDT_OK;
}
Beispiel #2
0
NTSTATUS kuhl_m_crypto_l_providers(int argc, wchar_t * argv[])
{
	DWORD provType,tailleRequise, index = 0;
	wchar_t * monProvider;
	PCRYPT_PROVIDERS pBuffer = NULL;

	kprintf(L"\nCryptoAPI providers :\n");
	while(CryptEnumProviders(index, NULL, 0, &provType, NULL, &tailleRequise))
	{
		if(monProvider = (wchar_t *) LocalAlloc(LPTR, tailleRequise))
		{
			if(CryptEnumProviders(index, NULL, 0, &provType, monProvider, &tailleRequise))
				kprintf(L"%2u. %s\n", index, monProvider);
			LocalFree(monProvider);
		}
		index++;
	}
	if(GetLastError() != ERROR_NO_MORE_ITEMS)
		PRINT_ERROR_AUTO(L"CryptEnumProviders");

	if(kuhl_m_crypto_hNCrypt)
	{
		kprintf(L"\nCNG providers :\n");
		if(NT_SUCCESS(K_BCryptEnumRegisteredProviders(&tailleRequise, &pBuffer)))
		{
			for(index = 0; index < pBuffer->cProviders; index++)
				kprintf(L"%2u. %s\n", index, pBuffer->rgpszProviders[index]);
			K_BCryptFreeBuffer(pBuffer);
		}
		else PRINT_ERROR_AUTO(L"BCryptEnumRegisteredProviders");
	}
	return STATUS_SUCCESS;
}
Beispiel #3
0
static int capi_get_provname(CAPI_CTX *ctx, LPSTR *pname, DWORD *ptype, DWORD idx)
	{
	LPSTR name;
	DWORD len, err;
	CAPI_trace(ctx, "capi_get_provname, index=%d\n", idx);
	if (!CryptEnumProviders(idx, NULL, 0, ptype, NULL, &len))
		{
		err = GetLastError();
		if (err == ERROR_NO_MORE_ITEMS)
			return 2;
		CAPIerr(CAPI_F_CAPI_GET_PROVNAME, CAPI_R_CRYPTENUMPROVIDERS_ERROR);
		capi_adderror(err);
		return 0;
		}
	name = OPENSSL_malloc(len);
		if (!CryptEnumProviders(idx, NULL, 0, ptype, name, &len))
		{
		err = GetLastError();
		if (err == ERROR_NO_MORE_ITEMS)
			return 2;
		CAPIerr(CAPI_F_CAPI_GET_PROVNAME, CAPI_R_CRYPTENUMPROVIDERS_ERROR);
		capi_adderror(err);
		return 0;
		}
	*pname = name;
	CAPI_trace(ctx, "capi_get_provname, returned name=%s, type=%d\n", name, *ptype);

	return 1;
	}
Beispiel #4
0
OP_STATUS MSCAPI_Manager::Init(uni_char **arguments, int max_args)
{
	if(!crypto_api_dll->IsLoaded())
		return OpStatus::ERR_NULL_POINTER;

	capi_CertOpenSystemStore = (pfCertOpenSystemStore) crypto_api_dll->GetSymbolAddress(CRYPT32_FUNCTION_NAME("CertOpenSystemStore"));
	capi_CertCloseStore = (pfCertCloseStore) crypto_api_dll->GetSymbolAddress("CertCloseStore");
	capi_CertNameToStr = (pfCertNameToStr) crypto_api_dll->GetSymbolAddress(CRYPT32_FUNCTION_NAME("CertNameToStr"));
	capi_CertFindCertificateInStore = (pfCertFindCertificateInStore) crypto_api_dll->GetSymbolAddress("CertFindCertificateInStore");
	capi_CryptExportPublicKeyInfo = (pfCryptExportPublicKeyInfo) crypto_api_dll->GetSymbolAddress("CryptExportPublicKeyInfo");


	if(capi_CertOpenSystemStore == NULL ||
		capi_CertCloseStore == NULL ||
		capi_CertNameToStr == NULL ||
		capi_CertFindCertificateInStore == NULL ||
		capi_CryptExportPublicKeyInfo == NULL)
		return OpStatus::ERR_NULL_POINTER;

	DWORD provider_type;
	DWORD name_length;
	uni_char *name = (uni_char *) g_memory_manager->GetTempBuf2k();
	DWORD i;

	for(i = 0;;i++)
	{
		*name = '\0';
		name_length = g_memory_manager->GetTempBuf2kLen();
		provider_type = NULL;
		if(!CryptEnumProviders(i, NULL, 0, &provider_type, name, &name_length))
		{
			int error = GetLastError();
			if(error == ERROR_MORE_DATA)
				continue; //Ignore items with too long name
			if(error != ERROR_NO_MORE_ITEMS)
				return TranslateToOP_STATUS(error);

			break;
		}

		if(provider_type != PROV_RSA_FULL &&
			provider_type != PROV_RSA_SIG)
			continue;

		OpAutoPtr<MSCAPI_Provider> provider(OP_NEW(MSCAPI_Provider, (this)));

		if(provider.get())
		{
			RETURN_IF_ERROR(provider->Construct(name, provider_type));

			provider->Into(&provider_list);
			provider.release();
		}

	}

	hMYSystemStore = CertOpenSystemStore(NULL, UNI_L("MY"));
			
	if(!hMYSystemStore)
	{
		return TranslateToOP_STATUS(GetLastError());
	}
			
	hUserDSSystemStore = CertOpenSystemStore(NULL, UNI_L("UserDS"));
			
	hCASystemStore = CertOpenSystemStore(NULL, UNI_L("CA"));
			
	hRootSystemStore = CertOpenSystemStore(NULL, UNI_L("ROOT"));

	return OpStatus::OK;
}