Mar*_*DG1 4 permissions powershell certificate certificate-store
我收到错误
无法检索证书,因为指纹无效。验证指纹并重试。
当我尝试使用 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
Run Code Online (Sandbox Code Playgroud)
我可以获得包括指纹 ($certDetails) 在内的证书详细信息,但似乎权限不允许我(或 FID)使用证书(或者可能只是访问证书的私钥部分)。当证书安装在CurrentUser存储中时,该代码将起作用。
如何允许此类非管理员用户访问LocalMachine存储中的证书?
似乎问题与Invoke-WebRequest这段代码及其使用方式有关。
代码的第一部分能够成功访问证书:
$certStorePath = "Cert:\LocalMachine\My"
$certDetails = Get-ChildItem -Path $certStorePath | Where-Object {$_.Subject -like "*myCert*"}
Run Code Online (Sandbox Code Playgroud)
然而,尽管指纹在所有证书存储中都是唯一的(例如,该指纹仅存在于 LocalMachine 中),但Invoke-WebRequest无法访问它,因为它只会在 CurrentUser 证书存储中查找。
因此,总体而言,要使其正常工作:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6207 次 |
| 最近记录: |