-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #423 from buchdag/default-cert-key
Automatic creation of default cert and private key
- Loading branch information
Showing
9 changed files
with
256 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Started letsencrypt container for test default_cert | ||
Connection to le1.wtf using https was successful. | ||
Connection to le2.wtf using https was successful. | ||
Connection to le3.wtf using https was successful. | ||
Connection to le1.wtf using https was successful. | ||
Connection to le2.wtf using https was successful. | ||
Connection to le3.wtf using https was successful. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/bin/bash | ||
|
||
## Test for single domain certificates. | ||
|
||
if [[ -z $TRAVIS_CI ]]; then | ||
le_container_name="$(basename ${0%/*})_$(date "+%Y-%m-%d_%H.%M.%S")" | ||
else | ||
le_container_name="$(basename ${0%/*})" | ||
fi | ||
run_le_container ${1:?} "$le_container_name" | ||
|
||
# Create the $domains array from comma separated domains in TEST_DOMAINS. | ||
IFS=',' read -r -a domains <<< "$TEST_DOMAINS" | ||
|
||
# Cleanup function with EXIT trap | ||
function cleanup { | ||
# Cleanup the files created by this run of the test to avoid foiling following test(s). | ||
docker exec "$le_container_name" sh -c 'rm -rf /etc/nginx/certs/default.*' | ||
docker stop "$le_container_name" > /dev/null | ||
} | ||
trap cleanup EXIT | ||
|
||
function default_cert_fingerprint { | ||
docker exec "$le_container_name" openssl x509 -in "/etc/nginx/certs/default.crt" -fingerprint -noout | ||
} | ||
|
||
function default_cert_subject { | ||
docker exec "$le_container_name" openssl x509 -in "/etc/nginx/certs/default.crt" -subject -noout | ||
} | ||
|
||
user_cn="user-provided" | ||
|
||
i=0 | ||
until docker exec "$le_container_name" [[ -f /etc/nginx/certs/default.crt ]]; do | ||
if [ $i -gt 60 ]; then | ||
echo "Default cert wasn't created under one minute at container first launch." | ||
fi | ||
i=$((i + 2)) | ||
sleep 2 | ||
done | ||
|
||
# Connection test to unconfigured domains | ||
for domain in "${domains[@]}"; do | ||
wait_for_conn --domain "$domain" --default-cert | ||
done | ||
|
||
# Test if the default certificate get re-created when | ||
# the certificate or private key file are deleted | ||
for file in 'default.key' 'default.crt'; do | ||
old_default_cert_fingerprint="$(default_cert_fingerprint)" | ||
docker exec "$le_container_name" rm -f /etc/nginx/certs/$file | ||
docker restart "$le_container_name" > /dev/null && sleep 5 | ||
i=0 | ||
while [[ "$(default_cert_fingerprint)" == "$old_default_cert_fingerprint" ]]; do | ||
if [ $i -gt 55 ]; then | ||
echo "Default cert wasn't re-created under one minute after $file deletion." | ||
break | ||
fi | ||
i=$((i + 2)) | ||
sleep 2 | ||
done | ||
done | ||
|
||
# Test if the default certificate get re-created when | ||
# the certificate expire in less than three months | ||
docker exec "$le_container_name" sh -c 'rm -rf /etc/nginx/certs/default.*' | ||
docker exec "$le_container_name" openssl req -x509 \ | ||
-newkey rsa:4096 -sha256 -nodes -days 60 \ | ||
-subj "/CN=letsencrypt-nginx-proxy-companion" \ | ||
-keyout /etc/nginx/certs/default.key \ | ||
-out /etc/nginx/certs/default.crt > /dev/null 2>&1 | ||
old_default_cert_fingerprint="$(default_cert_fingerprint)" | ||
docker restart "$le_container_name" > /dev/null && sleep 5 | ||
i=0 | ||
while [[ "$(default_cert_fingerprint)" == "$old_default_cert_fingerprint" ]]; do | ||
if [ $i -gt 55 ]; then | ||
echo "Default cert wasn't re-created under one minute when the certificate expire in less than three months." | ||
break | ||
fi | ||
i=$((i + 2)) | ||
sleep 2 | ||
done | ||
|
||
# Test that a user provided default certificate isn't overwrited | ||
docker exec "$le_container_name" sh -c 'rm -rf /etc/nginx/certs/default.*' | ||
docker exec "$le_container_name" openssl req -x509 \ | ||
-newkey rsa:4096 -sha256 -nodes -days 60 \ | ||
-subj "/CN=$user_cn" \ | ||
-keyout /etc/nginx/certs/default.key \ | ||
-out /etc/nginx/certs/default.crt > /dev/null 2>&1 | ||
docker restart "$le_container_name" > /dev/null | ||
|
||
# Connection test to unconfigured domains | ||
for domain in "${domains[@]}"; do | ||
wait_for_conn --domain "$domain" --subject-match "$user_cn" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters