From b47db645bbd432d6b9bcea74fbc15f0124aa35a8 Mon Sep 17 00:00:00 2001 From: Tracy Adams Date: Fri, 3 Jan 2020 14:56:02 -0700 Subject: [PATCH 1/5] Add Linux/Ubuntu instructions for ssl-check Add a separate function for ssl-check specifically for Linux. --- .../Create-a-self-signed-SSL-certificate.md | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md b/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md index e22251fd9..b7b7ad273 100644 --- a/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md +++ b/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md @@ -1,3 +1,4 @@ + --- id: version-1.0.0-beta.14-create-a-self-signed-ssl-certificate title: Create a self-signed SSL certificate @@ -14,6 +15,7 @@ brew install mkcert 2. Copy and paste the bash function into your terminal (or into your `.bashrc` file if you want to have it available in the future): +### Mac ```bash function ssl-check() { f=~/.localhost_ssl; @@ -62,6 +64,54 @@ function ssl-check() { } ``` +### Linux/Ubuntu +``` +function ssl-check() { + f=~/.localhost_ssl; + ssl_crt=$f/server.crt + ssl_key=$f/server.key + b=$(tput bold) + c=$(tput sgr0) + + local_ip=$(hostname -I | cut -d' ' -f1) + # local_ip=999.999.999 # (uncomment for testing) + + domains=( + "localhost" + "$local_ip" + ) + + if [[ ! -f $ssl_crt ]]; then + echo -e "\nšŸ›‘ ${b}Couldn't find a Slate SSL certificate:${c}" + make_key=true + elif [[ ! $(openssl x509 -noout -text -in $ssl_crt | grep $local_ip) ]]; then + echo -e "\nšŸ›‘ ${b}Your IP Address has changed:${c}" + make_key=true + else + echo -e "\nāœ… ${b}Your IP address is still the same.${c}" + fi + + if [[ $make_key == true ]]; then + echo -e "Generating a new Slate SSL certificate...\n" + count=$(( ${#domains[@]} - 1)) + mkcert ${domains[@]} + + # Create Slate's default certificate directory, if it doesn't exist + test ! -d $f && mkdir $f + + # It appears mkcert bases its filenames off the number of domains passed after the first one. + # This script predicts that filename, so it can copy it to Slate's default location. + if [[ $count = 0 ]]; then + mv ./localhost.pem $ssl_crt + mv ./localhost-key.pem $ssl_key + else + mv ./localhost+$count.pem $ssl_crt + mv ./localhost+$count-key.pem $ssl_key + fi + fi + } +``` + 3. Run the function you just declared in step 2: ```bash From d932f1df7df0a6647af9f9e5d40e30f445dc5558 Mon Sep 17 00:00:00 2001 From: Tracy Adams Date: Fri, 3 Jan 2020 14:58:03 -0700 Subject: [PATCH 2/5] Fix start of file Remove empty space left by my formatter --- .../Create-a-self-signed-SSL-certificate.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md b/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md index b7b7ad273..c81b945bc 100644 --- a/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md +++ b/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md @@ -1,4 +1,3 @@ - --- id: version-1.0.0-beta.14-create-a-self-signed-ssl-certificate title: Create a self-signed SSL certificate From 11cbaf1649293847cefee49b6d29029e8a0904dc Mon Sep 17 00:00:00 2001 From: Tracy Adams Date: Fri, 3 Jan 2020 15:00:59 -0700 Subject: [PATCH 3/5] Add bash for syntax highlights --- .../Create-a-self-signed-SSL-certificate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md b/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md index c81b945bc..a190b6b47 100644 --- a/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md +++ b/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md @@ -64,7 +64,7 @@ function ssl-check() { ``` ### Linux/Ubuntu -``` +```bash function ssl-check() { f=~/.localhost_ssl; ssl_crt=$f/server.crt From 1f518abfbd22bd95bce10d97f17edea773be35b0 Mon Sep 17 00:00:00 2001 From: Tracy Adams Date: Fri, 3 Jan 2020 15:12:30 -0700 Subject: [PATCH 4/5] Add comment Added a comment for the local_ip variable and the hostname usage --- .../Create-a-self-signed-SSL-certificate.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md b/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md index a190b6b47..8da7aeb2f 100644 --- a/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md +++ b/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md @@ -71,7 +71,8 @@ function ssl-check() { ssl_key=$f/server.key b=$(tput bold) c=$(tput sgr0) - + + # gets the first IP returned fro the hostname function local_ip=$(hostname -I | cut -d' ' -f1) # local_ip=999.999.999 # (uncomment for testing) From b6cb66d0a851cfcf9c388b6d7ff8fdf6a486c8a6 Mon Sep 17 00:00:00 2001 From: Tracy Adams Date: Tue, 21 Jan 2020 19:18:48 -0700 Subject: [PATCH 5/5] Update Create-a-self-signed-SSL-certificate.md Update shell script to create SSL certificate for all IPs found by `hostname`. This improves accuracy when running ssl-check. For instance, if you have a docker network interface, then sometimes the first IP will actually be the docker IP. The ssl-check function would originally fail because of that. This change resolves that failure. --- .../Create-a-self-signed-SSL-certificate.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md b/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md index 8da7aeb2f..c491699a4 100644 --- a/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md +++ b/docs/v1/versioned_docs/version-1.0.0-beta.14/Create-a-self-signed-SSL-certificate.md @@ -72,13 +72,14 @@ function ssl-check() { b=$(tput bold) c=$(tput sgr0) - # gets the first IP returned fro the hostname function - local_ip=$(hostname -I | cut -d' ' -f1) + # gets all IPs returned by the hostname function + ips=$(hostname -I) + local_ips=($(echo $ips | tr " " "\n")) # local_ip=999.999.999 # (uncomment for testing) domains=( "localhost" - "$local_ip" + "${local_ips[@]}" ) if [[ ! -f $ssl_crt ]]; then