【问题标题】:How to access a certifciate with error: "Unable to retrieve certificates because the thumbprint is not valid"如何访问带有错误的证书:“无法检索证书,因为指纹无效”
【发布时间】:2019-12-27 03:07:49
【问题描述】:

我收到了错误

无法检索证书,因为指纹无效。 验证指纹并重试。

当我尝试使用 LocalMachine 证书存储中的证书时。

我有一个管理员帐户在 LocalMachine 证书存储中安装了证书(包括私钥),并为某些用户提供了对私钥的访问权限(例如功能 ID)。

我希望能够运行以下代码来获取指纹,然后在Invoke-WebRequest 调用中使用:

$certStorePath  = "Cert:\LocalMachine\My"
$certDetails    = Get-ChildItem -Path $certStorePath | Where-Object {$_.Subject -like "*myCert*"}   # Returns one result
$certThumbprint = $certDetails.Thumbprint

Invoke-WebRequest -Uri $externalUrl -Proxy $proxyServer -UseBasicParsing -CertificateThumbprint $certThumbprint

我可以获得包括指纹 ($certDetails) 在内的证书详细信息,但似乎权限不允许我(或 FID)使用证书(或者可能只是访问私钥部分证书)。当证书安装在 CurrentUser 商店中时,代码可以工作。

如何为此类非管理员用户启用对 LocalMachine 存储中证书的访问权限?

【问题讨论】:

    标签: powershell permissions certificate certificate-store


    【解决方案1】:

    似乎问题与Invoke-WebRequest 以及它在这段代码中的使用方式有关。

    第一部分代码能够成功访问证书:

    $certStorePath  = "Cert:\LocalMachine\My"
    $certDetails    = Get-ChildItem -Path $certStorePath | Where-Object {$_.Subject -like "*myCert*"}
    

    然而,尽管指纹在所有证书存储中都是唯一的(例如,这个指纹仅存在于 LocalMachine 中),Invoke-WebRequest 无法访问它,因为 只会在 CurrentUser 证书存储中查找。

    所以,总的来说,要让这个工作:

    1. 安装包含私钥的证书。
    2. 向相应的用户/FID 提供对证书私钥部分的访问权限。
    3. 使用Get-ChildItem 获取证书本身,并将那个 传递给Invoke-WebRequest 而不是指纹:
    $certStorePath = "Cert:\LocalMachine\My"
    $certificate   = Get-ChildItem -Path $certStorePath | Where-Object {$_.Subject -like "*myCert*"}   # Returns one result
    
    Invoke-WebRequest -Uri $externalUrl -Proxy $proxyServer -UseBasicParsing -Certificate $certificate
    

    【讨论】:

      猜你喜欢
      • 2019-10-29
      • 2014-06-13
      • 1970-01-01
      • 2015-04-18
      • 1970-01-01
      • 1970-01-01
      • 2021-01-01
      • 1970-01-01
      相关资源
      最近更新 更多