10

我在内核驱动程序中调用AcquireCredentialsHandle ,传入SCHANNEL_CREDdwCredFormat设置为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);

对于用户帐户和本地计算机,我的证书哈希绝对正确,并且正确安装在 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);

我相信我按照 MSDN 关于如何使用的说明进行操作SCH_CRED_FORMAT_CERT_HASH- 有什么问题?

4

1 回答 1

0

没有调试很难确定,但是我看到了一些可能是问题的地方: - 如果证书链无法验证;或者它是自签名的;或者在您执行代码检查 CRL 时机器无法访问互联网,您的调用将失败。如果是这种情况,请使用CRYPT_E_NO_REVOCATION_CHECK - 如果您的证书的目的对于向远程服务器证明身份是正确的?

Windows 中最近的一些安全强化措施在证书方面非常挑剔。自签名证书有时比签名证书更容易测试。我看到越来越多的正在运行的应用程序因为没有 100% 的证书而停止工作。缺少它,我不明白问题是什么。

于 2018-08-10T22:55:38.030 回答