【问题标题】:Import-PfxCertificate not saving certificate in designated System Store LocationImport-PfxCertificate 未将证书保存在指定的系统存储位置
【发布时间】:2020-01-01 18:07:39
【问题描述】:

我正在尝试通过 powershell 安装 mitmproxy.org 提供的证书,但 windows 没有将证书保存在正确的位置。

我尝试运行的命令:

Get-ChildItem -Path c:\mitmproxy-ca-cert.p12 | Import-PfxCertificate -CertStoreLocation cert:\LocalMachine\Root 不是将证书插入受信任的根证书颁发机构,而是将其放入中间证书颁发机构。

Get-ChildItem -Path c:\mitmproxy-ca-cert.p12 | Import-PfxCertificate -CertStoreLocation cert:\CurrentUser\Root 和第一个命令一样。

即使将工作位置设置为PS Cert:\localmachine\Root> 也无法导入到根位置。 Get-ChildItem -Path c:\mitmproxy-ca-cert.p12 | Import-PfxCertificate -CertStoreLocation .

没有错误,所有命令都运行正常。我以管理员权限运行它们。

手动左键单击 mitmproxy-ca-cert.p12 会启动导入 GUI,将其成功导入到 Root 位置。为什么 powershell 不起作用?

按照 mitmproxy.org 自己的命令行安装指南是没有用的,因为它根本不起作用:

如何在 Windows 上安装(自动)

certutil.exe -importpfx Root mitmproxy-ca-cert.p12

C:\>certutil -importpfx Root mitmproxy-ca-cert.p12
Enter PFX password:
CertUtil: -importPFX command FAILED: 0x80092007 (-2146885625 CRYPT_E_SELF_SIGNED)
CertUtil: The specified certificate is self signed.

谁能解释一下这里发生了什么?谢谢。

【问题讨论】:

  • 您在“Pfx”中有多个证书?我认为现在不可能。我在这里也有同样的问题:https://superuser.com/questions/1471833/how-i-make-the-publisher-certificate-to-be-installed-into-trusted-publishers-b.
  • 要仔细检查存储是否正确,打开 GUI 并找到仅在 Trusted Root 文件夹中的证书。复制指纹(不带空格)并运行命令:dir -Path cert:\ -Recurse |其中 {$_.Thumbprint -eq "thumbprintwithoutspaces"}
  • 您需要另一种方法。我知道 Pfx 文件不保存证书路径。检查答案。

标签: powershell certificate


【解决方案1】:

我给你写了一个脚本,如果你不明白,请告诉我。

$in_cert = "C:\Users\Marian\Desktop\Pfx Certificate.pfx";
$password = Read-Host -AsSecureString;

# Read the pfx certificate data:
$pfx = (Get-PfxData -FilePath $in_cert -Password $password -ErrorAction Stop);

# Get the root and publisher certificate:
$root = $pfx.OtherCertificates[0];
$publisher = $pfx.EndEntityCertificates[0];

# Add the root:
$rootStore = Get-Item "Cert:\CurrentUser\Root";
$rootStore.Open('ReadWrite');
$rootStore.add($root);
$rootStore.close();

# Add the publisher:
$rootStore = Get-Item "Cert:\CurrentUser\TrustedPublisher";
$rootStore.Open('ReadWrite');
$rootStore.add($publisher);
$rootStore.close();

Pause;

我也发过帖子:My Post

【讨论】:

  • 非常感谢,成功了。如果您愿意在此处发布公共电子邮件地址,我是否也可以通过电子邮件向您发送有关此主题的后续信息?
猜你喜欢
  • 2016-09-04
  • 2011-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多