Skip to content

Instantly share code, notes, and snippets.

@dinigo
Created December 20, 2017 23:22
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 dinigo/38c424b7bbb767851cc289c31cce5e1b to your computer and use it in GitHub Desktop.
Save dinigo/38c424b7bbb767851cc289c31cce5e1b to your computer and use it in GitHub Desktop.
  1. Dependencies
  • brew: run /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • node and npm: run brew install node npm
  1. Download the script
  2. Give permissions to run chmod +x install_ssl.sh
  3. Run ./install_ssl.sh
  4. Trust the cert
  • Run open ~/.config/ssl
  • Double click the cert
  • Double click the cert inside keychain
  • Select trust allways from the dropdown menu

Now you should be able to use serve everywhere to serve local files through https and be able to use the domains testing.com and tool.testing.com. They both point to 127.0.0.1

#!/bin/bash
DOMAIN=testing.com
SUBDOMAIN=tool
NAME=domain
CERTS_PATH=~/.config/ssl
SUBJ="
C=ES
ST=Asturias
O=Divisadero
localityName=Gijón
commonName=*.$DOMAIN
organizationalUnitName=Innovation
emailAddress=dinigo@divisadero.es
"
# -subj "$(echo -n "$SUBJ" | tr "\n" "/")" \
mkdir -p ${CERTS_PATH}
cd ${CERTS_PATH}
openssl req \
-newkey rsa:2048 \
-x509 \
-nodes \
-keyout ${NAME}.key \
-new \
-out ${NAME}.crt \
-subj /CN=${DOMAIN} \
-reqexts SAN \
-extensions SAN \
-config <(cat /etc/ssl/openssl.cnf \
<(printf '[SAN]\nsubjectAltName=IP:127.0.0.1')) \
-sha256 \
-days 3650 \
npm install -g http-server
cat <<EOF >> ~/.profile
serve () {
http-server --ssl --cert ${CERTS_PATH}/${NAME}.crt --key ${CERTS_PATH}/${NAME}.key
}
EOF
source ~/.profile
cat <<EOF | sudo tee -a /etc/hosts &>/dev/null
127.0.0.1 ${DOMAIN}
127.0.0.1 ${SUBDOMAIN}.${DOMAIN}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment