openssl: self-signed certificates in a very simple way
Translation of the original in Catalan. Read it in: CatalàCastellano
Until this morning every time I needed to create self-signed certificates for myself I used extremely long lists of options with openssl, but today I've discovered (call me slow) that if you download the OpenSSL package and unpack it inside the source code there's a directory called: easy-rsa.
As you can see the name already gives a lot of clues, well then, inside this one we find yet another directory called 2.0. In here, there are a load of scripts that will simplify our lives enormously when creating certificates, as always I make a summary in the form of a cookbook.
-
Edit the vars file. You have to change the value of the variables:
export KEY_COUNTRY="yourContry"
export KEY_PROVINCE="yourProvince"
export KEY_CITY="yourCity"
export KEY_ORG="myOwnOrg"
export KEY_EMAIL="user@domain.tld"
-
Then we clean the keys directory so there are no leftovers from examples:
./clean-all
-
We load the environment variables from the vars file:
source ./vars
-
We create a CA (Certificate Authority):
./pkitool --initca
-
Create the certificate for a server:
# ./pkitool --server
# penseu que a vegades el common_name ha de ser el url_host del servidor, per exemple, en servidors https
./pkitool --server nom_servidor
-
Certificates for a client:
# ./pkitool
./pkitool nom_client
-
Certificate for a client packaged with PKCS12:
# ./pkitool --pkcs12
./pkitool --pkcs12 nom_client
-
Generate a DH file (Diffie-Hellman)
./pkitool --build-dh
NOTE: in case you want to protect the private keys with a symmetric key to prevent them from being used by third parties you can do so by adding the '--pass' parameter to the previous commands.
You can find the generated keys in the 'easy-rsa/2.0/keys' directory.
For those of you who aren't too familiar with the subject of certificates I'll add four notes about the files created:
-
*.csr: Certificate Signing Request, certificate request that is sent to a CA so that it returns it signed to us.
-
*.crt: Certificate signed by a CA
-
*.key: Private key of the certificate, often it's usual to protect it with a symmetric key
-
ca.crt: Certificate of the CA
-
ca.key: private key of the CA certificate.
Simple, isn't it? I'd say you no longer have an excuse to manage the SSL keys yourselves. If you need other functions in the mentioned directory there are many other scripts and 'pkitool' itself has quite a few other very interesting and equally simple to use options.
3 comments
Comments from the old blog, as they were written. Comments are closed.
Ernest
on dius 'soure ./vars' vols dir 'soure ./vars' no?
Ernest
maleit copy paste:
'source ./vars'
Oriol Rius
corregit! moltes gràcies per l'apreciació nano!