AcquireCredentialsHandle returns SEC_E_INTERNAL_ERROR
-
I am programming Socket with SSL on server side. The following code depicts how I m reteriving certificate from a store and obtaining credentials for schannel.I am getting problem in obtaning credential handle ie AcquireCredentialshandle returns SEC_E_INTERNAL_ERROR #define ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING) TimeStamp tsExpiry; SECURITY_STATUS Status; CERT_RDN cert_rdn;// structure to obtain certificate using RDN attributes //containing structure CERT_RDN_ATTR CERT_RDN_ATTR cert_rdn_attr;// structure for one attribute of RDN ie //Common Name //only one attribute of RDN is used to find certificate cert_rdn.cRDNAttr = 1;//only one CERT_RDN_ATTR cert_rdn.rgRDNAttr =&cert_rdn_attr;//pointer to CERT_RDN_ATTR the //structure contains 1 attribute const TCHAR * pszUserName=_T("SNS");//Common Name is SNS cert_rdn_attr.pszObjId = szOID_COMMON_NAME;//go for Common Name //attribte in RDN cert_rdn_attr.dwValueType = CERT_RDN_ANY_TYPE; cert_rdn_attr.Value.cbData = _tcslen(pszUserName);//length of //Common Name #ifdef _UNICODE char *pszUn = new char[wcslen(pszUserName)+1]; WideCharToMultiByte(CP_ACP,0,pszUserName,-1,pszUn,wcslen(pszUserName)+1,NULL,NULL); cert_rdn_attr.Value.pbData = (BYTE *)pszUn; #else cert_rdn_attr.Value.pbData = (BYTE *)pszUserName; #endif //search for the certificate in the certificate store PCCERT_CONTEXT m_pCertContext; m_pCertContext = CertFindCertificateInStore(m_hMyCertStore, ENCODING_TYPE, 0,//use default values CERT_FIND_SUBJECT_ATTR, &cert_rdn, NULL); #ifdef _UNICODE delete [] pszUn; #endif //If the function fails and a certificate that matches the search criteria is not //found,the return value is NULL if(m_pCertContext == NULL &&::GetLastError()==CRYPT_E_NOT_FOUND) { ::OutputDebugString(_T("error:")); } ::OutputDebugString(_T("pointer to the certificate context is available")); SCHANNEL_CRED m_SchannelCred; SecurityFunctionTable m_SecurityFunc; CredHandle m_hCreds; PCredHandle phCreds=&m_hCreds//pointer to the credential handle ZeroMemory(&m_SchannelCred, sizeof(m_SchannelCred)); //Credentials are required by the Schannel authentication m_SchannelCred.dwVersion = SCHANNEL_CRED_VERSION; m_SchannelCred.cCreds = 1;//only one certificate store m_SchannelCred.paCred = &m_pCertContext;//pointer to the pointer of //CERT_CONTEXT structure this how the certificate