Skip to content

Instantly share code, notes, and snippets.

@plinionaves
Forked from pgilad/Instructions.md
Created June 23, 2020 18:11
Show Gist options
  • Save plinionaves/785657f93180a5c818ffaa6a42099335 to your computer and use it in GitHub Desktop.
Save plinionaves/785657f93180a5c818ffaa6a42099335 to your computer and use it in GitHub Desktop.
Generate SSL Certificate for use with Webpack Dev Server (OSX)
#!/usr/bin/env bash
# openssl req \
# -newkey rsa:4096 \
# -x509 \
# -nodes \
# -keyout private.pem \
# -new \
# -out private.crt \
# -subj /CN=localhost \
# -reqexts SAN \
# -extensions SAN \
# -config <(cat /System/Library/OpenSSL/openssl.cnf \
# <(printf '[SAN]\nsubjectAltName=DNS:localhost')) \
# -sha512 \
# -days 365
openssl req -config ssl.conf -new -sha256 -newkey rsa:2048 -nodes -keyout private.key -x509 -days 3650 -out private.crt
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain private.crt

Generate private key

$ openssl genrsa -out private.key 4096

Generate a Certificate Signing Request

openssl req -new -sha256 \
    -out private.csr \
    -key private.key \
    -config ssl.conf 

Generate the certificate

openssl x509 -req \
    -days 3650 \
    -in private.csr \
    -signkey private.key \
    -out private.crt \
    -extensions req_ext \
    -extfile ssl.conf

Add the certificate to keychain and trust it:

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain private.crt

Create a pem file from crt

openssl x509 -in private.crt -out private.pem -outform PEM

Run webpack dev server

npm run webpack-dev-server -- --open --https --cert private.pem --key private.key

PROFIT $$

[ req ]
default_bits = 4096
distinguished_name = req_distinguished_name
req_extensions = req_ext
[ req_distinguished_name ]
countryName = IL
countryName_default = GB
stateOrProvinceName = Center
stateOrProvinceName_default = England
localityName = Tel Aviv
localityName_default = Brighton
organizationName = CA
organizationName_default = Hallmarkdesign
organizationalUnitName = BlazeMeter
commonName = localhost
commonName_max = 64
commonName_default = localhost
[ req_ext ]
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