1

在一些运行 Windows 7 的系统上,我们在名称密钥容器中生成了一个密钥,如果我们更改用户的密码,当我们调用 CryptAcquireCertificatePrivateKey() 时,我们会收到错误 CRYPT_E_NO_KEY_PROPERTY (0x8009200B)。

这不会发生在所有盒子上。我们最初认为这是与不在网络上的域机器一起使用的东西,并且它无法刷新它的域内容,但我们让它在一些独立的机器上重现。

我读取密钥的代码

if((StoreHandle = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER, QWARQ_CERT_STORE_NAME)) != NULL)
     {
        /* Look for certificate with matching user guid.            */
        if((CertContext = CertFindCertificateInStore(StoreHandle,PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, 0, CERT_FIND_SUBJECT_STR,DataBuffer, NULL)) != NULL)
        {
           if(CryptAcquireCertificatePrivateKey(CertContext, 0,NULL, &CryptProvHandle, &KeySpec, &FreeHandle))
           {
           }
           else
           {
                   DWORD dwError=GetLastError();   //CRYPT_E_NO_KEY_PROPERTY
           }
        }
     }

这是生成密钥/密钥容器的代码

if(CryptAcquireContext(&hCryptProv,KEY_CONTAINER_NAME, NULL,PROV_RSA_FULL, 0) == FALSE) //CRYPT_NEWKEYSET
{
    DWORD result = GetLastError();
    if (NTE_BAD_KEY_STATE  == result)
    {
        DebugLogging::DbgPrintF(TEXT("[CertInitialization] NTE_BAD_KEY_STATE - user has changed his password \n"), result);
        return false;
    }
    else if (NTE_BAD_KEYSET != result)
    {
        DebugLogging::DbgPrintF(TEXT("[CertInitialization] could not acquire CSP[0x%x]\n"), result);
        return false;
    }

    if(CryptAcquireContext(&hCryptProv, KEY_CONTAINER_NAME, NULL,PROV_RSA_FULL, CRYPT_NEWKEYSET) == FALSE) //CRYPT_NEWKEYSET
    {
        DWORD result = GetLastError();
        DebugLogging::DbgPrintF(TEXT("[CertInitialization] could not acquire CSP from new keyset[0x%x]\n"), result);
        return false;
    }
}
if(CryptGenKey(hCryptProv, AT_KEYEXCHANGE, RSA2048BIT_KEY |CRYPT_EXPORTABLE, &hKey)== FALSE)
{
    DebugLogging::DbgPrintF(TEXT("CertGeneration() could not generate key[%d]\n"),GetLastError());
    return false;
} 
4

1 回答 1

1

在了解更多关于 DPAPI 之后

密码更改

在这种方法中,在密码更改期间可以连续访问用户的主密钥。Winlogon 组件在 Active Directory 域中的密码更改操作期间调用 DPAPI:

* DPAPI receives notification from Winlogon during a password change operation.
* DPAPI decrypts all master keys that were encrypted with the user's old passwords.
* DPAPI re-encrypts all master keys with the user's new password.

密码重置(设置)

这种方法是管理员强制重置用户密码。密码重置比密码更改更复杂。因为管理员没有以用户身份登录并且无权访问用户的旧密码,所以该旧密码不能用于解密旧主密钥并使用新密码重新加密它。

于 2010-02-16T23:48:46.043 回答