Hi,
I know the problem is not directly related to OpenSSL, but i thought
someone might know it. Also if someone know some method that i can use
using OpenSSL, please let me know that, I am open to use that also.
I am trying to programatically install certificate to Windows Certificate
Store, for this i am trying to get the information from certificate to see
which store i need to open, but it seems not to work properly. Can someone
please help me in this, and see what i am missing from below code. With the
code I have certificate is getting installed, but not the store it gets
installed when i double click it. Thanks.
HCERTSTORE GetCurrentStore(PCCERT_CONTEXT pContext)
{
if(!pContext) return NULL;
HCERTSTORE hReturn = NULL;
if(IsCACert(pContext) == TRUE)
{
if(IsCASelfsigned(pContext) == TRUE)
{
hReturn = ROOT;
}
else
{
hReturn = CA;
}
}
else
{
hReturn = MY;
}
return hReturn;
}
BOOL IsCACert(PCCERT_CONTEXT pContext)
{
if(!pContext) return FALSE;
PCERT_EXTENSION pCertExt = NULL;
BOOL fCA = FALSE;
PCERT_BASIC_CONSTRAINTS2_INFO pInfo = NULL;
DWORD cbInfo = 0;
pCertExt = CertFindExtension(szOID_BASIC_CONSTRAINTS2,
pContext->pCertInfo->cExtension, pContext->pCertInfo->rgExtension);
if (pCertExt == NULL)
{
return FALSE;
}
if (!CryptDecodeObjectEx(X509_ASN_ENCODING, X509_BASIC_CONSTRAINTS2,
pCertExt->Value.pbData, pCertExt->Value.cbData, CRYPT_DECODE_ALLOC_FLAG,
(PCRYPT_DECODE_PARA)NULL, &pInfo, &cbInfo))
{
return FALSE;
}
if(pInfo)
{
fCA = pInfo->fCA;
LocalFree(pInfo);
}
return fCA;
}
BOOL IsCASelfsigned(PCCERT_CONTEXT pContext)
{
if(!pContext) return FALSE;
DWORD dwFlags = CERT_STORE_SIGNATURE_FLAG;
if (!(CertCompareCertificateName(X509_ASN_ENCODING,
&pContext->pCertInfo->Issuer, &pContext->pCertInfo->Subject)))
{
return FALSE;
}
if (!(CertVerifySubjectCertificateContext(pContext, pContext, &dwFlags)))
{
return FALSE;
}
if (dwFlags != 0)
{
return FALSE;
}
return TRUE;
}
// Harshvir