wez*_*ten 8 c c++ schannel wdk kmdf
我叫AcquireCredentialsHandle在内核驱动程序,传递SCHANNEL_CRED与dwCredFormat设置为SCH_CRED_FORMAT_CERT_HASH.它失败了SEC_E_NO_CREDENTIALS.这是我的代码:
BYTE certHashBytes[20] = { 0x6d,0x64,0xed,0x56,0xd2,0x94,0x15,0xf4,0x49,0x08,0xaf,0x18,0xf1,0xca,0xf5,0xa2,0xc8,0x01,0x20,0x96 };
CredHandle credHandle;
RtlZeroMemory(&credHandle, sizeof(CredHandle));
SCHANNEL_CRED schannelCred;
RtlZeroMemory(&schannelCred, sizeof(SCHANNEL_CRED));
schannelCred.dwVersion = 4;
schannelCred.cCreds = 1;
schannelCred.paCred = certHashBytes;
schannelCred.dwCredFormat = 1;
UNICODE_STRING unispName;
RtlUnicodeStringInit(&unispName, L"Microsoft Unified Security Protocol Provider");
TimeStamp ts;
SECURITY_STATUS res = AcquireCredentialsHandle(NULL, &unispName, SECPKG_CRED_INBOUND, NULL, &schannelCred, NULL, NULL, &credHandle, &ts);
DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_INFO_LEVEL, "AcquireCredentialsHandle %x\n", res);
Run Code Online (Sandbox Code Playgroud)
我的证书哈希肯定是正确的,并且在MY商店中正确安装,用于用户帐户和本地计算机.我知道这是因为它在用户模式下工作正常,如下所示:
HCERTSTORE certStore = CertOpenSystemStore(NULL, L"MY");
BYTE certHashBytes[20] = { 0x6d,0x64,0xed,0x56,0xd2,0x94,0x15,0xf4,0x49,0x08,0xaf,0x18,0xf1,0xca,0xf5,0xa2,0xc8,0x01,0x20,0x96 };
CERT_NAME_BLOB certHash { 20, certHashBytes };
PCCERT_CONTEXT cert = CertFindCertificateInStore(certStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_SHA1_HASH, &certHash, NULL);
CredHandle credHandle;
ZeroMemory(&credHandle, sizeof(CredHandle));
SCHANNEL_CRED cred;
ZeroMemory(&cred, sizeof(SCHANNEL_CRED));
cred.dwVersion = SCHANNEL_CRED_VERSION;
cred.cCreds = 1;
cred.paCred = &cert;
SECURITY_STATUS res = AcquireCredentialsHandle(NULL, const_cast<LPWSTR>(UNISP_NAME), SECPKG_CRED_INBOUND, NULL, &cred, NULL, NULL, &credHandle, NULL);
Run Code Online (Sandbox Code Playgroud)
我相信我按照MSDN说明如何正确使用SCH_CRED_FORMAT_CERT_HASH- 出了什么问题?
小智 0
如果不进行调试,很难确定,但是我看到一些可能存在问题的点: - 如果无法验证证书链;或者是自签名的;或者在您执行代码检查 CRL 时机器无法访问互联网,您的调用将会失败。如果是这种情况,请使用CRYPT_E_NO_REVOCATION_CHECK
- 如果您的证书的目的对于向远程服务器证明身份是正确的?
Windows 最近进行了一些安全强化,在证书方面非常挑剔。有时,自签名证书比签名证书更容易测试。我发现越来越多的应用程序因证书未得到 100% 验证而停止工作。除此之外,我不明白问题是什么。