Skip to content

Instantly share code, notes, and snippets.

@msioen
Last active September 23, 2019 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msioen/1cf224a242249c223cc7eee2ded9240d to your computer and use it in GitHub Desktop.
Save msioen/1cf224a242249c223cc7eee2ded9240d to your computer and use it in GitHub Desktop.
Create self-signed root certificate authority and server certificate

Two script files to setup self-signed certificate bits. Included files have the proper settings for self-signed certificates linking to localhost. If other domains are needed several changes are necessary.

  • Execute ./create_root_cert_and_key.sh to create the root certificate authority.
  • Execute ./create_server_cert_and_key_with_ca.sh to create the server certificate
#!/usr/bin/env bash
openssl genrsa -out rootCA.key 2048
openssl req -new -days 3650 -key rootCA.key -out rootCA.pem -config ./openssl-ca.cnf
openssl x509 -req -days 3650 -in rootCA.pem -signkey rootCA.key -out rootCA.crt -extfile v3-ca.ext
#!/usr/bin/env bash
openssl req -new -sha256 -nodes -out server.csr -newkey rsa:2048 -keyout server.key -config <( cat openssl-cert.cnf )
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 3650 -sha256 -extfile v3-cert.ext
[req]
default_bits = 2048
prompt = no
default_md = sha256
x509_extensions = v3_req
distinguished_name = dn
[dn]
C = BE
ST = Brussels
L = Brussels
O = CA
OU = Localhost CA
emailAddress = webmaster@example.com
CN = localhost
[v3_req]
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.localhost
DNS.2 = localhost
[req]
default_bits = 2048
prompt = no
default_md = sha256
x509_extensions = v3_req
distinguished_name = dn
[dn]
C = BE
ST = Brussels
L = Brussels
O = IT
OU = IT Department
emailAddress = it@example.com
CN = localhost
[v3_req]
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.localhost
DNS.2 = localhost
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:TRUE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment