Script for export crt and key to apache

Hi everyone,
I use apache so I made a script to automatically deploy the private key and the certificate:

$dir = “C:\ProgramData\Certify\certes\assets\pfx”
$latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1
openssl pkcs12 -in C:\ProgramData\Certify\certes\assets\pfx\$latest -passin pass: -out C:\path\to\apache\ssl.key\public.key -nocerts -nodes
openssl pkcs12 -in C:\ProgramData\Certify\certes\assets\pfx\$latest -out C:\path\to\apache\ssl.crt\public.crt -nokeys -passin pass:
Restart-Service -Name Apache2.4

Edit accordingly to your scenario, set certify to run post-request script and that’s it.

P.S. You need to set the path enviroment variable for openssl in windows or run it from the openssl directory

1 Like