程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ssl-關於windows平台下的server端AcquireCredentialsHandle調用失敗問題

ssl-關於windows平台下的server端AcquireCredentialsHandle調用失敗問題

編輯:編程綜合問答
關於windows平台下的server端AcquireCredentialsHandle調用失敗問題

securityFuns.AcquireCredentialsHandle執行後,返回1312錯誤碼。如下代碼:

#include <schannel.h>
#define SECURITY_WIN32
#include <security.h>

#pragma comment(lib,"crypt32.lib")

int _tmain(int argc, _TCHAR* argv[])
{
    HMODULE modSchannel = ::LoadLibrary("SCHANNEL.DLL");
#ifdef UNICODE
    INIT_SECURITY_INTERFACE pfInitSecurityInterface = (INIT_SECURITY_INTERFACE)GetProcAddress(modSchannel, "InitSecurityInterfaceW" );
#else
    INIT_SECURITY_INTERFACE pfInitSecurityInterface = (INIT_SECURITY_INTERFACE)GetProcAddress(modSchannel, "InitSecurityInterfaceA" );
#endif

    PSecurityFunctionTable pSecurityFuns = pfInitSecurityInterface? pfInitSecurityInterface():NULL;

    SecurityFunctionTable securityFuns;
    ::memcpy(&securityFuns, pSecurityFuns, sizeof(securityFuns)); 

    HCERTSTORE hMyCertStore = CertOpenSystemStore(0,_T("ROOT"));

    PCCERT_CONTEXT pCertContext = CertFindCertificateInStore(hMyCertStore, PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, 0, CERT_FIND_SUBJECT_STR_A, L"ssltester", NULL);

    SCHANNEL_CRED  schannelCred;

    memset(&schannelCred, 0, sizeof(schannelCred));
    schannelCred.cCreds     = 1;
    schannelCred.paCred     = &pCertContext;
//  schannelCred.hRootStore = hMyCertStore;
    schannelCred.dwFlags               = SCH_CRED_NO_SYSTEM_MAPPER|SCH_CRED_REVOCATION_CHECK_CHAIN;
    schannelCred.dwVersion             = SCHANNEL_CRED_VERSION;
    schannelCred.grbitEnabledProtocols = SP_PROT_SSL3TLS1_SERVERS;

    TimeStamp  lifetime; //證書生存時間
    CredHandle hCreds;
    SECURITY_STATUS sec_ret = securityFuns.AcquireCredentialsHandle( NULL, UNISP_NAME, SECPKG_CRED_INBOUND, NULL, &schannelCred, NULL, NULL, &hCreds, &lifetime );
    unsigned long lErrorCode;
    if( sec_ret != SEC_E_OK ) 
    {
        lErrorCode = ::GetLastError(); //返回1312錯誤碼
    }
    else
    {
        lErrorCode = 0;
    }
    return 0;
}

最佳回答:


經過檢查發現是證書存在異常。問題已經解決。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved