Skip to content

Commit 0c9805d

Browse files
committed
Configurable location of SSL certificate and private key files in container.
1 parent f983f58 commit 0c9805d

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Use volume mounting to substitute the certificate and private key with your own.
8686
- /etc/ssl/certs/ssl-cert-snakeoil.pem:/app/fullchain.pem
8787
- /etc/ssl/private/ssl-cert-snakeoil.key:/app/privkey.pem
8888

89+
`/app/fullchain.pem` and `/app/privkey.pem` paths can be changed - use `HTTPS_CERT_FILE` and `HTTPS_KEY_FILE` environment variables to define location of existing certificate and private key inside container.
8990

9091

9192
## Decode JWT header

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ app.all('*', (req, res) => {
121121
});
122122

123123
let sslOpts = {
124-
key: require('fs').readFileSync('privkey.pem'),
125-
cert: require('fs').readFileSync('fullchain.pem')
124+
key: require('fs').readFileSync(process.env.HTTPS_KEY_FILE || 'privkey.pem'),
125+
cert: require('fs').readFileSync(process.env.HTTPS_CERT_FILE || 'fullchain.pem')
126126
};
127127

128128
//Whether to enable the client certificate feature

tests.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,39 @@ fi
364364
message " Stop containers "
365365
docker stop http-echo-tests
366366

367+
message " Check that SSL certificate and private key are loaded from custom location"
368+
cert_common_name="server.example.net"
369+
https_cert_file="$(pwd)/server_fullchain.pem"
370+
https_key_file="$(pwd)/server_privkey.pem"
371+
# Generate a new self signed cert locally
372+
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout "${https_key_file}" -out "${https_cert_file}" \
373+
-subj "/CN=${cert_common_name}" \
374+
-addext "subjectAltName=DNS:${cert_common_name}"
375+
chmod a+r "${https_cert_file}"
376+
chmod a+r "${https_key_file}"
377+
container_https_cert_file="/test/tls.crt"
378+
container_https_key_file="/test/tls.key"
379+
docker run -d --rm \
380+
-v "${https_cert_file}:${container_https_cert_file}:ro,z" \
381+
-e HTTPS_CERT_FILE="${container_https_cert_file}" \
382+
-v "${https_key_file}:${container_https_key_file}:ro,z" \
383+
-e HTTPS_KEY_FILE="${container_https_key_file}" \
384+
--name http-echo-tests -p 8443:8443 -t mendhak/http-https-echo
385+
sleep 5
386+
387+
REQUEST_WITH_STATUS_CODE="$(curl -s --cacert "$(pwd)/server_fullchain.pem" -o /dev/null -w "%{http_code}" \
388+
--resolve "${cert_common_name}:8443:127.0.0.1" "https://${cert_common_name}:8443/hello-world")"
389+
if [ "${REQUEST_WITH_STATUS_CODE}" = 200 ]
390+
then
391+
passed "Server certificate and private key are loaded from configured custom location"
392+
else
393+
failed "HTTPS request failed"
394+
exit 1
395+
fi
396+
397+
message " Stop containers "
398+
docker stop http-echo-tests
399+
367400
message " Check that environment variables returned in response if enabled"
368401
docker run -d --rm -e ECHO_INCLUDE_ENV_VARS=1 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
369402
sleep 5

0 commit comments

Comments
 (0)