Logo

Armand.nz

Home / About / Linkedin / Github

Create a wildcard Self-Signed SSL Certificate for development and testing

#openssl |

If you need to locally test your websites with HTTPS, purchasing an SSL certificate for this purpose might not be ideal. Instead, creating your own certificates is the way to go!

Navigating through the OpenSSL command-line interface can be daunting. With its myriad of options, it’s easy to get lost.

For a quick and easy solution, **Check out the bash scripts in the repo, dev-certificates , to create development certificates the easy way.

If you want to step through the creation of a Self-Signed Wildcard SSL Certificate for internal use, development, and testing, check out the guide below

Install OpenSSL

Where is OpenSSL?

which openssl  
/usr/bin/openssl  

If the which command does not return a path then you will need to install openssl yourself:

Step 1 : Create the CA Private Key

After installing OpenSSL, the subsequent action involves creating a private key. This key is critical in SSL certificates to sign and decrypt information.

To generate a 2048-bit RSA private key, execute the command provided below. Replace private.key with your desired file name.

export KEYSIZE=2048
# openssl genrsa -des3 -out CAPrivate.key $KEYSIZE
openssl genrsa -out CAPrivate.key $KEYSIZE

Notes:

Next, we create a self-signed (“X.509”) certificate. The certificate is generated using the private key CAPrivate.key and is not encrypted with a passphrase.

export VALIDITY=365
openssl req -x509 -new -nodes \
	-key CAPrivate.key \
	-sha256 \
	-days $VALIDITY \
	-out CAPrivate.pem

Explanation:

Step 3: Create a Private Key

export KEYSIZE=2048
openssl genrsa -out private.key $KEYSIZE

Step 4: Create a Certificate Signing Request (CSR)

Now generate a new Certificate Signing Request (CSR) using our previously created private key. The CSR will include specific extensions defined for a CA certificate (v3_ca). This CSR can then be submitted to a Certificate Authority for signing to obtain a certificate based on the public key in the CSR and the information it contains.

openssl req -new -key private.key -extensions v3_ca -out request.csr

Explanation:

Step 5: Create an extensions file to specify subjectAltName

Create an extensions file named:  openssl.ss.cnf. In this file replace *.armand.nz with your domain:

export BASICCONSTRAINTS="CA:FALSE"
export SUBJECTALTNAME="DNS:*.armand.nz"
export EXTENDEDKEYUSAGE="serverAuth"

cat >> openssl.ss.cnf << EOL
basicConstraints=$BASICCONSTRAINTS
subjectAltName=$SUBJECTALTNAME
extendedKeyUsage=$EXTENDEDKEYUSAGE
EOL

A more verbose template you can base your config on looks like:

[req]  
default_md = sha256  
prompt = no  
req_extensions = req_ext  
distinguished_name = req_distinguished_name

[req_distinguished_name]  
commonName = *.armand.nz
countryName = US  
stateOrProvinceName = No state  
localityName = City  
organizationName = LTD

[req_ext]  
keyUsage=critical,digitalSignature,keyEncipherment  
extendedKeyUsage=critical,serverAuth,clientAuth  
subjectAltName = @alt_names

[alt_names]  
DNS.1=yourdomain.com  
DNS.2=*.yourdomain.com

Step 6: Generate the Certificate using the CSR

Lastly, we will use OpenSSL to sign a CSR with a CA’s certificate and private key, generating a new SSL/TLS certificate valid for the specified number of days and using SHA-256 as the hashing algorithm.

export VALIDITY=365
openssl x509 -req -in request.csr \
	-CA CAPrivate.pem \
	-CAkey private.key \
	-CAcreateserial \
	-extfile openssl.ss.cnf \
	-days $VALIDITY \
	-sha256 \
	-out MyCert.crt 

Explanation:

Step 7: Install the Certificate and Private Key on your Server or Application

Refer to the Server or Application’s documentation to learn how to do this step

Step 8: Copy the CA Root certificate and import it into the proper Certificate Store of the OS/Application or client device

This step is optional (for in which case you will see “insecure” warnings) or, in some cases, might be required. Refer to the Server or Application’s documentation to learn how to do this step and take note of whether a specific naming convention or file type is required.

For Example:

comments powered byDisqus

Copyright © Armand