Score:3

Import-PfxCertificate not importing to correct certificate store

us flag

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?

br flag
What happens if you `cd` into the store first, then run it without the `-CertStoreLocation` argument? (I'm clutching at straws here, by the way!)
us flag
Sadly it does the same thing
us flag
The cert does not seem to have the Basic Constraints extension, so no I don't think so
us flag
Any way we can do a cert exchange to compare? I wonder if our AD CA is doing something unusual in the Web Server template that means my cert is interpreted differently to yours when imported. My team doesn't control the CA or templates, so if there is an issue there I'd need to identify it before I approach the team to adjust it
us flag
Got it thanks! I'll have a play and see what happens when using yours. Interestingly, if I run my same PS command on my Win 10 workstation, it imports correctly to personal, so I am wondering if this is a Server 2016 issue specifically
us flag
Ok, don't know why, but if I add this to my command, it works flawlessly; `-certpbe PBE-SHA1-3DES -keypbe PBE-SHA1-3DES -nomac`
br flag
That is very odd. My PFX was created with OpenSSL version 1.1.1n on Linux. That may have a bearing. Anyway, glad you got somewhere.
us flag
Yeah I'm using 3.0 on Windows. I've seen other questions around the password issue during import which I also had, but didn't realise this would also play into the import/store issue. References here: https://stackoverflow.com/questions/69343254/the-password-you-entered-is-incorrect-when-importing-pfx-files-to-windows-cer
Score:1
us flag

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

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.