Skip to content

Instantly share code, notes, and snippets.

@dinigo
Created Dec 20, 2017
Embed
What would you like to do?
  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