An Active-X control that wraps the Windows Crypto API is sometimes returning an error of "The keyset is not defined". I have discussed this problem with the vendor of the Active-X control and they are as puzzled as well. They are using NULL as the provider which allows the Crypto API to make its own choice.
This Microsoft article, CryptAcquireContext() use and troubleshooting as well as some other bits and pieces of information indicates registration issues or Windows Registry issues.
My question is what are some of the reasons why this sometimes happen when most of the time we do not see this problem?
What kinds of procedures could we use to collect data leading to a root cause?
An actual suggested solution would be nice however some additional data collection for root cause analysis would be helpful.
The actual deployment environment is a set of tablet PCs which are using a cellular network for LAN access in a mobile environment. There are a set of these tablets which are set up and provisioned when being deployed for a trip. On end of trip, the tablets are put back into storage.
We have been unable to replicate this problem in the lab. Lab testing seems to work fine even when the environment is replicated to using the cellular LAN that is used in the field.
Edit 01.
One thing we have seen in the field is that once the problem is hit, it consistently happens during a short span of time as in over the course of half a minute. We know this because we have logs which show the Decrypt being done for a series of records which are being processed and on each error we skip to the next record which again gives us a Decrypt error. If there are say 30 records to be processed, we will see 30 logs, one for each record, with the same error.
We are looking at the following and once I have additional information I will update this question:
stopping processing at the first failure in order to allow for a reboot and retry
auditing tablet tracking to determine if it is only particular tablets
I am currently working my way through the various links of Window C/C++ Crypto API Examples and tips and one thing that may be helpful in gathering data is to enumerate through the list of providers when the application starts up to generate a list of those.
Edit 02
The vendor has provided the usage of the CryptAcquireContext()
function being used. It is being compiled with UNICODE turned off so the LPCTSTR is standard char
string and not wchar_t
string.
if(!::CryptAcquireContext(&m_hCryptProv,NULL,MS_ENHANCED_PROV,PROV_RSA_FULL,CRYPT_VERIFYCONTEXT))
{
m_strLastError = LookupSystemError(::GetLastError() );
DestroySession();
return false;
}