brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: openssl pkcs12 -export packs a key and certificate into one .pfx file

Openssl
~/tips/tip-openssl-pkcs12-export-pfx

openssl pkcs12 -export -inkey site.key -in site.pem \

Combines a private key, certificate and chain into one password-protected .pfx file.

Linux tools are happy with a private key and a certificate as two PEM files. Windows and plenty of other software want them in one password-protected file instead, a PKCS#12 file that usually ends in .pfx or .p12. OpenSSL makes one in a single command, and I find it the least painful way to move a certificate between those two worlds.

Give it the key, the certificate and the intermediates, and it asks for an export password:

openssl pkcs12 -export -inkey site.key -in site.pem \
  -certfile chain.pem -name "nas" -out site.pfx

-certfile adds the extra certificates, so the intermediates travel along and the receiving side can build the chain. -name sets the friendly name that import dialogs show in their lists, which helps when a machine has a few certificates with almost the same subject. To look inside the result without writing anything out:

openssl pkcs12 -in site.pfx -info -noout

That shows which encryption was used and how many certificate bags are in the file, so you can see that the chain made it in.

The caveat is the encryption. Since OpenSSL 3, the default for both the key and the certificates is AES-256-CBC with PBKDF2, which is good. Some older software only understands the legacy algorithms and refuses the file or complains about the password. If that happens, export again with -legacy, which switches to the old RC2 or 3DES defaults. Use it only for the system that needs it, because those algorithms are weak. And treat the .pfx like the private key itself: the password protects it, but anyone with the file and a weak password has your key.

Further reading: openssl-pkcs12 (OpenSSL documentation)

Going deeper: Run degoog on Unraid as your own search page, compared with SearXNG and 4get

More Openssl tips openssl s_client -connect 203.0.113.10:443 -servername example.com </dev/null | openssl x509 -noout -subject openssl x509 -in cert.pem -days 365 -signkey key.pem -out cert-new.pem printf %s hello | openssl dgst -sha256 -hmac secret openssl pkcs12 -legacy -in old.pfx -nokeys echo 'aGVsbG8gd29ybGQ=' | openssl base64 -d All Openssl tips (34) All topics

Link