Skip to content

Instantly share code, notes, and snippets.

@ankitrgadiya
Last active June 9, 2018 09:27
Show Gist options
  • Save ankitrgadiya/11116852e37da8289756514279394ad4 to your computer and use it in GitHub Desktop.
Save ankitrgadiya/11116852e37da8289756514279394ad4 to your computer and use it in GitHub Desktop.
Setup self signed Certification Authority using openssl

Setup Certification Authority

First generate Certification Authority key. Entering pasword is recommended.

$ openssl genrsa -des3 -out myCA.key 4096

Change permissions of the key.

$ chmod 400 myCA.key

Generate Root certificate for the Certification Authority.

$ openssl req -x509 -new -nodes -key myCA.key -sha256 -days 3650 -out myCA-certificate.pem

Install Certificates

Open Chrome/Chromium Settings > Advanced > Manage Certificates > Authorities Click on Import and select myCA-certificate.pem file.

On ios devices, send email with myCA-certificate.pem attached, and tap the file, install it.

Once, root certificate is installed, all the certificates signed using it will work on the devices.

Generate Server Certificates

First generate key.

$ openssl genrsa -out host.key 4096

Now, generate Certificate Signing Request (CSR) using the key.

openssl req -new -key host.key -out host.csr

Create a new file with following contents and save it as host.ext

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

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

Finally create certificate with following command.

openssl x509 \
  -req \
  -in host.csr \
  -CA myCA-certificate.pem -CAkey myCA.key -CAcreateserial \
  -out host.crt \
  -days 365 -sha256 \
  -extfile host.ext

Generate Client Certificates

First generate key.

$ openssl genrsa -out client.key 4096

Now, generate Certificate Signing Request (CSR) using the key.

openssl req -new -key client.key -out client.csr

Finally create certificate with following command.

openssl x509 \
  -req \
  -in client.csr \
  -CA myCA-certificate.pem -CAkey myCA.key -CAcreateserial \
  -out client.crt \
  -days 365 -sha256

Now generate PKCS #12

openssl pkcs12 -export -out client.pfx -inkey client.key -in client.crt -certfile myCA-certificate.crt

Credits

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