尝试撤销本地生成的证书:无本地 CA 错误

尝试撤销本地生成的证书:无本地 CA 错误

对于我的项目的一些自动化测试,我需要撤销由制作证书工具

首先,我使用以下命令生成签名者证书和相关的 CRL,然后使用certutil将它们安装到我的机器上

# Generate Signer Cert
makecert.exe -pe -n CN=SignerCert -r -sr LocalMachine -ss Root -a sha256 `
    SignerCert.cer -cy authority
certutil -installcert SignerCert.cer

# Set up a certificate revocation list for the CA cert above
makecert.exe -crl -n CN=SignerCert -r -sr LocalMachine SignerCert.crl
certutil -addstore Root SignerCert.crl

然后,我生成另一个用于身份验证的证书,我最终想撤销该证书

makecert.exe -pe -n CN=AuthCert `
    -ir LocalMachine -is Root -ic SignerCert.cer `
    -sr LocalMachine -ss My -a sha256 AuthCert.cer

并按如下方式安装(通过某些 powershell)

    $x509cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
    $certPath = Join-Path $pwd AuthCert.cer
    $x509cert.Import("$($certPath)")
    Set-Location "Cert:\LocalMachine\My"
    $cert = Get-ChildItem | Where-Object { $_.Thumbprint -eq $x509cert.Thumbprint}
    $cert = $cert[0]
    $cert.FriendlyName = $FriendlyName

到目前为止一切顺利。如果我打开certlm我的机器,我可以在“个人 > 证书”下看到 SignerCert 和 AuthCert,在“受信任的根证书颁发机构 > 证书”下看到 SignerCert,在“受信任的根证书颁发机构 > 证书吊销列表”下看到 SignerCert。

现在来看看有问题的操作。我想撤销 AuthCert:certutil有一个-revoke我可以使用的操作,所以假设我检索了 AuthCert 的序列号并运行以下命令

> certutil -revoke 12345678
Revoking 12345678 -- Reason: Unspecified
ICertAdmin::RevokeCertificate: The RPC server is unavailable. 0x800706ba (WIN32: 1722 RPC_S_SERVER_UNAVAILABLE)
CertUtil: -revoke command FAILED: 0x800706ba (WIN32: 1722 RPC_S_SERVER_UNAVAILABLE)
CertUtil: The RPC server is unavailable.

由于没有本地 CA,RPC 可能不可用

> certutil -cainfo
CertUtil: No local Certification Authority; use -config option
CertUtil: No more data is available.

有人可以向我简要介绍一下这里发生的事情以及如何成功撤销证书吗?

答案1

该命令旨在与 AD 证书服务一起使用,否则它将无法工作,因为如果没有 AD 证书服务,就没有数据库来记录哪些证书被撤销(或颁发)。您的所有命令都只是在运行中创建内容,而不会保留任何“CA”的状态。

(通常,CA 需要记住撤销,直到证书过期,因为它必须继续包含它每次它会发布新的 CRL – 如果下一版 CRL 没有该条目,则证书实际上不再被撤销。 CA 还会在其颁发的每个证书中包含撤销列表的 URL,以便客户端可以在需要时自动下载最新的 CRL。)

因此,由于您只是“即时”生成和签署证书,因此您可以通过以下方式撤销证书告诉 makecert将其序列号包含在新生成的 CRL 中(然后再次导入该 CRL)。或者至少在理论上。

不幸的是,尽管 makecert 有一个 -crl 选项,但它似乎没有指定实际撤销的证书的选项。它所做的只是创建没有任何撤销内容的空 CRL。

您可以使用其他工具(例如opensslCLI)来生成撤销列表。

相关内容