gpt4 book ai didi

c++ - SCHANNEL TLS 服务器端无法 CertFindCertificateInStore

转载 作者:太空宇宙 更新时间:2023-11-04 13:46:31 28 4
gpt4 key购买 nike

我正在将 TLS 加密添加到服务器端应用程序。我正在使用 Schannel API 添加 TLS。我在使用 CertFindCertificateInStore 时遇到问题。它永远找不到我正在搜索的证书。作为搜索标准,我使用证书的名称。我现在已经在这上面花了很多时间,但不明白为什么它不起作用。任何帮助将不胜感激。我在其中使用的功能如下所示。谢谢,

int ServerCreateCredentials() {

//- get the certificate store
HCERTSTORE myCertStore = NULL;
myCertStore = CertOpenStore(
CERT_STORE_PROV_SYSTEM,
X509_ASN_ENCODING,
NULL,
CERT_SYSTEM_STORE_LOCAL_MACHINE,
L"My");

// check for the failure to find the appropriate store
if (myCertStore == NULL) {
return 1;
}

// find the certificate in the store
m_CertificateContext = CertFindCertificateInStore(
myCertStore,
X509_ASN_ENCODING,
0,
CERT_FIND_SUBJECT_STR_A,
(LPVOID) CertificateName,
NULL);

if (m_CertificateContext == NULL) {
// try unicode
m_CertificateContext = CertFindCertificateInStore(
myCertStore,
X509_ASN_ENCODING,
0,
CERT_FIND_SUBJECT_STR_W,
CertificateName,
NULL);

if (m_CertificateContext == NULL ) {
// free the store
CertCloseStore(myCertStore, CERT_CLOSE_STORE_CHECK_FLAG);
return 2;
}
}

TimeStamp life;
// get the credentials
SCHANNEL_CRED SchannelCredentials;
ZeroMemory(&SchannelCredentials, sizeof(SchannelCredentials));

SchannelCredentials.dwVersion = SCHANNEL_CRED_VERSION;

SchannelCredentials.cCreds = 1; // number of credentials
SchannelCredentials.paCred = &m_CertificateContext; // credentials
SchannelCredentials.hRootStore = myCertStore; // certificate store location
SchannelCredentials.dwMinimumCipherStrength = 80; // minimum encryption allowed
SchannelCredentials.grbitEnabledProtocols = 0; // let the dll decide
SchannelCredentials.dwFlags = SCH_CRED_AUTO_CRED_VALIDATION
| SCH_CRED_NO_SERVERNAME_CHECK
| SCH_CRED_REVOCATION_CHECK_CHAIN;
DWORD Status = SEC_E_OK;
Status = m_securityFunctionTable.AcquireCredentialsHandle(
NULL,
UNISP_NAME,
SECPKG_CRED_INBOUND,
NULL,
&SchannelCredentials,
NULL,
NULL,
&m_credentials,
&life);

// at this point we should be good
// free the store
CertCloseStore(myCertStore, CERT_CLOSE_STORE_CHECK_FLAG);
if (Status != SEC_E_OK) {
return 3;
}

return 0;

最佳答案

我发现我没有搜索正确的参数。您需要根据主题名称进行搜索,然后它才会起作用。

关于c++ - SCHANNEL TLS 服务器端无法 CertFindCertificateInStore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25647995/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com