4
I need to be able to remotely export an installed computer certificate with the full certificate chain and private keys on a Windows server. The cert is used for IIS, and I want to use it for an apache instance running on the same server.
I know how to to do this manually with the certmgr.MSC mmc snap in tool, but how can this be done from a command line or from a remote machine on the same domain?
I also know how to view just the certificate with openssl s-client
. Can that be used to save both the certificate and private key for importing to a Java keystore file?
Certmgr via RDP is too slow for what I need. I need a scripting solution.
My environment is all Windows Server 2008 R2. PowerShell remoting is not on, but I can get it on.
I have confirmed that I cannot use the PowerShell Export-PfxCertificate
, because my servers are not new enough...
So, if I can use PowerShell to get the thumbprint of the certificate I want, I can then feed it to the "certutil -exportpfx" command. I have confirmed that will work.
How do I dir the certificate store like, "dir cert:\localmachine\my | Where-Object { $_.hasPrivateKey } | " AND then feed that to the certutil export with the thumbprint?
OR, could I do the dir first and tell it to only print out the thumbprint and not the whole thing? Then save that to a file, and read the file a make the certutil command?
That is pretty darn close, but for my specific purpose it actually doesn't work. When I first do PS Remote connection with Enter-PSSession, and then run the certutil -exportpfx THAT works. I get a pfx file that when I import it with with Java keytool to a keystore file, the application that uses it is happy.. When I use that PS code I do get a valid pfx file, but it is missing something... The file is a little smaller and when I import it to the keystore file, it mostly works, BUT the application says that the certificate is Pending Approval. – user1991791 – 2015-03-13T15:20:09.663
I think that PS command is not getting the whole cert chain? The certutil command works, but its not nearly as elegant as this PS command. The PS command will both find the cert I need and export it, while with the certutil I have to first find the cert by its crazy long guid name – user1991791 – 2015-03-13T15:24:21.173
So, I just need to figure out how to run that PS command with ChainOption -Force and Extended Properties.. https://technet.microsoft.com/en-us/library/hh848635.aspx
– user1991791 – 2015-03-13T15:29:05.240I'm not sure that
Export-PfxCertificate
will work for you, because this page says it applies to: Windows 8.1, Windows PowerShell 4.0, Windows Server 2012 R2. And you're using 2008 R2. – beatcracker – 2015-03-13T15:31:32.220Is is possible to feed the first half the cert store dir Foreach-object to the certutil command? – user1991791 – 2015-03-13T15:52:31.457
Yes, I've updated my answer, see if it works for you. – beatcracker – 2015-03-13T16:03:44.553
Oh snap, I have a good feeling about that.. How would I save the pfx to the root of d:\ ? like "d:$($_.Subject).pfx") – user1991791 – 2015-03-13T16:12:37.237
Yep,
$($_.Subject)
is certificate's subject, anything else around it in quotes is just strings to form a path. So you can do:"d:\my\favorite\folder\$($_.Subject).pfx"
. – beatcracker – 2015-03-13T16:21:15.123Ohh heck yeah. That works perfectly. The cert is now recognized as signed and fully valid when I import to the Java keystore file. THANK YOU! THANK YOU! THANK YOU! YOU ROCK! HAVE A GREAT DAY! – user1991791 – 2015-03-13T16:32:10.650