I like the idea of posting regularly the things that I’ve learned. I’ve long put off getting SSL on this site, but I think I need to get with it to secure what few logins I have (which I only use at work and home anyway…). Curiously, this week I’ve been working with SSL at work, so I learned a few things running OpenSSL. Here are the basics. (technically I relearned this since I’ve done this all years back, but had to look it all up again anyway…)
To split an exported private key/certificate from IIS (.pfx format) into a more readable format:
openssl pkcs12 -nodes -in exportedfile.pfx -out outfile.pem
If you provided a password (like a good IIS admin!) to the exported private key, you will be prompted for it. To view the private key and certificate parts, just open the resulting pem file in a text editor. Both parts are enclosed in appropriate tags.
To just view the private key and certificate from the pfx file:
openssl pkcs12 -info -nodes -in exportedfile.pfx
To make a Certificate Signing Request (CSR):
openssl req -new -newkey rsa:2048 -keyout yournewkey.pem -nodes \ -out yournewcsr.pem
Save the key because this is the private key. Provide the yournewcsr.pem contents to the preferred CA such as Verisign, Thawte, or even your local CA if you have your own PKI. Once you get the certificate back and you’re using Apache, you want to follow Apache instructions (I’ll post this another time) to place the private key file and this cert file where Apache can use them. If you’re using IIS, you probably want to convert it back into the normal pcks12/pfx format:
openssl x509 -in certnew.cer -inform DER -out yournewcert.pem \ -outform PEM
You can then import it into IIS for use with web sites. In my case at work, we just left the pieces separated for use in our new Load-Balancer/SSL Terminator. Our IPS, however, would prefer the compounded format used by IIS along with the passphrase.
What if you just want a self-signed cert? This means it is free to you, although your browser may give fairly benign complaints about the cert not being signed by someone you trust. This is ok for most sites, including mine and other internal stuff:
openssl req -x509 -days 365 -newkey rsa:2048 -keyout myselfsignedkey.pem \ -nodes -out myselfsignedcert.pem
Might want to increase the 365 days to many, many years. Ten years is pretty decent and a bit easy to calculate (3650).
All of these commands used -nodes which does not mean “nodes,” it means “No DES.” This leaves the private key unencrypted. For anyone who has studied CISSP material (or even Security+) you really don’t want to leave your private keys unencrypted. You want them encrypted:
openssl rsa -des3 -in \ yourprivatekey.pem -out yourprivatekeyencrypted.pem
This will prompt for a passphrase and output the private key in an encrypted form. If you want to decrypt this key later:
openssl rsa -in yourprivatekeyencrypted.pem -out yourprivatekey.pem
I think that about does it for now. OpenSSL has tons of little options and modes, so if you find yourself getting an itch to learn more about SSL, check it out. Oh, and it comes in Linux and third-party Windows flavors for convenience. I actually really like the Windows version as it gives some nice, powerful tools for quick use to otherwise clunky Windows GUIs and servers.