Skip to content

Instantly share code, notes, and snippets.

@alexcreek
Last active August 19, 2022 06:46
Show Gist options
  • Save alexcreek/6247cad43d68800373707a384a71f473 to your computer and use it in GitHub Desktop.
Save alexcreek/6247cad43d68800373707a384a71f473 to your computer and use it in GitHub Desktop.
OpenSSL cheat sheet

Creating

Create a csr and key

openssl req -new -out fqdn.csr -newkey rsa:2048 -nodes -keyout fqdn.key -subj /C=US/ST=State/L=City/O=Company/CN=fqdn

Create a self signed cert and key

openssl req -x509 -days 365 -out fqdn.crt -newkey rsa:2048 -nodes -keyout fqdn.key -subj /C=US/ST=State/L=City/O=Company/CN=fqdn

Create a csr using an existing key

openssl req -new -out fqdn.csr -key fqdn.key -subj /C=US/ST=State/L=City/O=Company/CN=fqdn

Create just a key

openssl genrsa -out fqdn.key 2048

Reading

Show a cert's fingerprint

openssl x509 -in fqdn.crt -noout -fingerprint -sha256

Show a cert's expiration

openssl x509 -in fqdn.crt -noout -enddate

Show a cert's details

openssl x509 -in fqdn.crt -text -noout

Show a csr's details

openssl req -in fqdn.csr -noout -text 

Show a key's contents (not much to see)

openssl rsa -in fqdn.key

Show your openssl version

openssl version

Verifying

Verify a cert matches a key

openssl x509 -noout -modulus -in fqdn.crt | openssl sha256
openssl rsa -noout -modulus -in fqdn.key | openssl sha256

Verify a key is valid

openssl rsa -in fqdn.key -check

Verify a cert against the system trust store

openssl verify cert.crt

Verify a cert against a specific trust store

openssl verify cert.crt -CAfile /path/to/ca/file 

Converting

Convert der to pem

openssl x509 -in fqdn.der -inform der -out fqdn.crt

Networking with s_client

Show a remote cert's details

openssl s_client -connect google.com:443 2> /dev/null | sed -n '/-BEGIN/,/-END/p' | openssl x509 -noout -text

Only show certificate trust info

openssl s_client -connect google.com:443 -quiet

Show intermediate certs

openssl s_client -connect google.com:443 -showcerts

Make s_client exit immediately

echo | openssl s_client ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment