Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save onnimonni/7112e911de7913d62012 to your computer and use it in GitHub Desktop.
Save onnimonni/7112e911de7913d62012 to your computer and use it in GitHub Desktop.
How to make self-signed certificates and how to add them trusted in your own machine. This is part of our automated dev environment: http://github.com/devgeniem/gdev

Self-trusted self-signed certificates for local development

You can repeat step 2 as many times and as many domains you like.

You need to have openssl installed.

-sha256 flag is needed to make chrome trust your new certificates as well.

STEP 1: Create CA certificate

# Create new root certificate so you can be your own CA
$ sudo openssl genrsa -out ca.key 4096

# It is valid for 20 years (should be enough for your development machine)
$ sudo openssl req -new -x509 -days 7300 -key ca.key -out ca.crt -subj "/O=gdev/OU=Local development Root Certificate/CN=gdev-local"

# Trust CA in your system keychain ( only OS-X )
$ sudo security add-trusted-cert -d -r trustRoot -k '/Library/Keychains/System.keychain' ca.crt"

# Trust CA in your system certificates ( only Linux,Ubuntu )
$ sudo cp ca.crt /usr/local/share/ca-certificates/ && sudo update-ca-certificates

# If you know how to do this in windows it would be perfect to share here :)

STEP 2: Create certificates by signing with your own root certificate

# Set domain name for all later files and rules
$ export DOMAIN=wordpress.test

# Create new csr
$ openssl req -new -sha256 -nodes -newkey rsa:2048 -keyout $DOMAIN.key -out $DOMAIN.csr -subj "/O=Gdev/OU=Local development/CN=$DOMAIN"

# Sign csr with your own ca.key
$ openssl x509 -sha256 -req -days 7300 -in $DOMAIN.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out $DOMAIN.crt

# Add correct 'trust chain' in the crt for better browser compatibility
$ cat ca.crt >> $DOMAIN.crt
@onnimonni
Copy link
Author

If this was way too over your head:
Using this script you can turn these bad boys:
non-trusted-https

Into these good guys:
trusted-https

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