大网数据广告活动
服务器运维问答

Import-PfxCertificate not importing to correct certificate store

· 52CE 我爱测

I am trying to import a PFX using PowerShell, that has been created by OpenSSL from a cer and key file (the key was generated by OpenSSL along with a CSR, which was submitted to internal AD CA to generate the cer) When viewing ce…

问题原文

原帖链接 · James Edmonds · CC BY-SA 4.0

I am trying to import a PFX using PowerShell, that has been created by OpenSSL from a cer and key file (the key was generated by OpenSSL along with a CSR, which was submitted to internal AD CA to generate the cer)

When viewing cert info in OpenSSL, I can see the PFX contains just a single cert and a private key, which is what I expect

If I run the below command, the cert is imported into intermediate certificate authorities, rather than the machine personal store as I have specified:

Import-PfxCertificate -FilePath $SharedPFXPath -Password (ConvertTo-SecureString -String $PFXPassword -AsPlainText -Force) -CertStoreLocation Cert:\LocalMachine\My -Exportable

What could be the reason the Import-PfxCertificate command might be ignoring my cert store location?

EDIT: Just for some additional info, I thought I'd detail the commands used to generate the source cert and key files etc:

Start by creating a key and CSR

openssl.exe genrsa -out $KeyFilePath 2048
openssl.exe req -new -key $KeyFilePath -out $CSROutputPath -config $ConfigFilePath

The CSR config file contains this (actual DN values removed):

[req]
distinguished_name = req_distinguished_name
req_extensions = req_ext
prompt = no

[req_distinguished_name]
C = COUNTRY CODE
ST = COUNTY/STATE
L = TOWN
O = ORG
OU = OU
CN = COMMON NAME

[req_ext]
subjectAltName = @alt_names

[alt_names]
DNS.1 = SAN

Then I submit the CSR to AD CA, and save the BASE64 encoded cert. I use this and the key file to create the PFX

openssl.exe pkcs12 -export -in $CertPath -inkey $KeyFilePath -out $PFXPath -passout pass:$PFXPassword -nomac

I had to add -nomac to my PFX command, as otherwise I got an incorrect password error every time I tried to manually import the PFX into the cert store. Not sure if this would contribute to my issue, or if some of my earlier commands might be causing me some problems?

已采纳解答

原帖链接 · James Edmonds · CC BY-SA 4.0

This issue is linked to similar issues mentioned here

I am using OpenSSL 3.0 on Windows to generate my certs and PFXs etc. and whilst I had the same "Incorrect Password" issue as this other question, which was resolved by adding -nomac, I had not added the other options.

After adding -certpbe PBE-SHA1-3DES -keypbe PBE-SHA1-3DES to my PFX export command, I no longer have any issues and my cert is imported into my specified store

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-02-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。