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 -in gets the certificate and key out of a .pfx file

Openssl
~/tips/tip-openssl-pkcs12-extract

openssl pkcs12 -in site.pfx -nokeys -clcerts -out cert.pem

Split a PKCS#12 bundle from Windows or a NAS export into PEM files for Linux software.

Windows, many NAS boxes and some control panels export certificates as one .pfx or .p12 file. Linux software like nginx wants separate PEM files, and openssl pkcs12 splits them.

Extract the parts one by one:

openssl pkcs12 -in site.pfx -nokeys -clcerts -out cert.pem
openssl pkcs12 -in site.pfx -nokeys -cacerts -out chain.pem
openssl pkcs12 -in site.pfx -nocerts -noenc -out site.key

-clcerts keeps only the server certificate, -cacerts only the CA and intermediate certificates, and -nocerts only the key. Each command asks for the import password of the file. -noenc writes the key without a new passphrase; in OpenSSL 1.1 that flag is still called -nodes.

For nginx you then join the server certificate and the chain: cat cert.pem chain.pem > fullchain.pem.

I like a quick look with -info -noout first, because files from older Windows systems often use RC2 or 3DES. OpenSSL 3 refuses those with an unsupported error until you add -legacy. The extracted PEM files keep bag attribute lines above each block. Most software skips them, but they are harmless to delete. Set chmod 600 on the key straight away.

Further reading: OpenSSL: openssl-pkcs12

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