Skip to content

Instantly share code, notes, and snippets.

@jwoo92
Created December 9, 2019 15:08
Show Gist options
  • Save jwoo92/6c8ba21aac058a30be06a84065edc872 to your computer and use it in GitHub Desktop.
Save jwoo92/6c8ba21aac058a30be06a84065edc872 to your computer and use it in GitHub Desktop.
Create a trusted certificate for local development on MacOS

Create a trusted certificate for local development on MacOS

1. Copy openSSL config to local temp file

cp /System/Library/OpenSSL/openssl.cnf ~/openssl-temp.cnf

2. Add Subject Alternative Name to openssl-temp.cnf, under [v3_ca]

[ v3_ca ]
subjectAltName = DNS:localhost # or local domain

3. Create local certs directory

mkdir ~/certs

4. Create certificate

openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -config ~/openssl-temp.cnf -keyout ~/certs/domain-name.com.key -out ~/certs/domain-name.com.crt

5. Add trust to Keychain

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/certs/domain-name.com.crt

6. Delete openSSL temp file

rm -f ~/openssl-temp.cnf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment