Notes on openssl
|
A signed certificate is an SSL/TLS certificate signed by a public or commercially private certificate authority using their root certificate authority (CA) and private key. The steps to getting a signed certificate are:
A self-signed certificate is an SSL/TLS certificate not signed by a public or commercially private certificate authority. Instead, it's signed by the creator's own personal or root CA certificate which is free.
$ openssl req -x509 \ output self-signed certificate instead of certificate request -sha256 \ hash strength -days 356 \ certificate's lifespan in days -nodes \ means "no DES encryption" meaning it's not encrypted—don't use this! -newkey rsa:2048 \ creates new certificate and key -subj "/CN=windofkeltia.com/L=Provo/ST=UT/C=US" \ subject name -keyout root.key \ new private key's filename -out root.crt Generating a RSA private key ..........+++++ ...................................................................+++++ writing new private key to 'root.key' ----- openssl req -x509 sha256 -days 356 -pass:changeit -newkey rsa:2048 -subj "/CN=windofkeltia.com/L=Provo/ST=UT/C=US" -keyout root.key -out root.crt [copy this command]
$ openssl genrsa -out server.key 2048 Generating RSA private key, 2048 bit long modulus (2 primes) ..........+++++ ...................+++++ e is 65537 (0x010001) openssl genrsa -out server.key 2048 [copy this command] $ openssl rsa -des3 -in server.key -out server.key.new openssl rsa -des3 -in server.key -out server.key.new [copy this command] $ rm server.key $ mv server.key.new server.key
Use an editor to create a configuration file first to make this easier. Then use this file in the command.
$ vim csr.conf $ openssl req -new -key server.key -out server.csr -config csr.conf |
csr.conf: [ req ] default_bits = 2048 prompt = no default_md = sha256 req_extensions = req_ext distinguished_name = dn [ dn ] C = US ST = UT L = Provo O = Wind of Keltia CN = windofkeltia.com [ req_ext ] subjectAltName = @alt_names [ alt_names ] DNS.1 = demo.windofkeltia.com DNS.2 = www.demo.windofkeltia.com IP.1 = 192.168.0.101 IP.2 = 192.168.0.120 |
Now create another configuration file for the certificate. Then generate the certificate with the self-signed root and other credentials we created before.
$ vim certificate.conf $ openssl x509 -req \ -sha256 \ -days 365 \ -in server.csr \ -out server.crt \ -extfile certificate.conf \ -CA root.crt \ -CAkey root.key \ -CAcreateserial |
certificate.conf: authorityKeyIdentifier = keyid,issuer basicConstraints = CA:FALSE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment subjectAltName = @alt_names [alt_names] DNS.1 = demo.windofkeltia.com |
|
openssl x509 -req -sha256 -days 365 -in server.csr -out server.crt -extfile certificate.conf -CA root.crt -CAkey root.key -CAcreateserial
Signature ok
subject=C = US, ST = UT, L = Provo, O = Wind of Keltia, CN = windofkeltia.com
Getting CA Private Key
|
$ ls -lart (show relative order of file creation) -rw------- 1 russ russ 1704 Jul 23 08:14 root.key key in root.crt -rw-rw-r-- 1 russ russ 1245 Jul 23 08:14 root.crt certificate by which server.crt is signed -rw------- 1 russ russ 1751 Jul 23 08:21 server.key key in server.crt -rw-rw-r-- 1 russ russ 345 Jul 23 08:27 csr.conf (helper) -rw-rw-r-- 1 russ russ 1115 Jul 23 08:40 server.csr certificate signing request for generating server.crt -rw-rw-r-- 1 russ russ 216 Jul 23 08:55 certificate.conf (helper) -rw-rw-r-- 1 russ russ 41 Jul 23 08:55 root.srl (beats me—it just showed up) -rw-rw-r-- 1 russ russ 1294 Jul 23 08:55 server.crt certificate to enable SSL in applications!