Skip to content

Commit 75d8a33

Browse files
authored
Add fallback self signed certificate. (#6)
1 parent 8b659a0 commit 75d8a33

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# API Gateway Changelog
22

3-
$ 4.0.0
3+
# 4.0.2
4+
* Add fallback self signed certficate.
5+
6+
# 4.0.1
7+
* Update entrypoint script
8+
9+
# 4.0.0
410
* Add default ssl certificate. Refactored NGINX template and docker entrypoint script.
511

612
# 3.3.0

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.1
1+
4.0.2

entrypoint.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ check_env_variables() {
3636
return 0
3737
}
3838

39+
create_self_signed_certificate() {
40+
local SSL_CERTIFICATE="$1"
41+
local SSL_CERTIFICATE_KEY="$2"
42+
43+
# Check if the SSL_CERTIFICATE and SSL_CERTIFICATE_KEY are in the same directory
44+
if [ "$(dirname "$SSL_CERTIFICATE")" != "$(dirname "$SSL_CERTIFICATE_KEY")" ]; then
45+
log_message "ERROR" "SSL_CERTIFICATE and SSL_CERTIFICATE_KEY must be in the same directory"
46+
exit 1
47+
fi
48+
49+
SSL_CERT_DIR="$(dirname "$SSL_CERTIFICATE")"
50+
log_message "INFO" "Creating self-signed certificate directory in $SSL_CERT_DIR"
51+
mkdir -p "$SSL_CERT_DIR" || { log_message "ERROR" "Could not create directory $SSL_CERT_DIR"; exit 1; }
52+
53+
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
54+
-keyout $SSL_CERTIFICATE \
55+
-out $SSL_CERTIFICATE_KEY \
56+
-subj "/CN=localhost"
57+
}
58+
3959
# Initial environment variables from .env file
4060
if [ -e $ENV_CONFIG ]; then
4161
log_message "INFO" "Setting environment variables for $ENV_CONFIG file"
@@ -62,6 +82,7 @@ if [ ! -f "$SSL_CERTIFICATE_PATH" ] || [ ! -f "$SSL_CERTIFICATE_KEY_PATH" ]; the
6282
log_message "INFO" "No CA-signed certificate or key found. Using self-signed certificate instead."
6383
SSL_CERTIFICATE_PATH="$SSL_CERTIFICATE_BASE_DIR/$DOMAIN/$SELF_SIGN_CERTIFICATE_NAME"
6484
SSL_CERTIFICATE_KEY_PATH="$SSL_CERTIFICATE_BASE_DIR/$DOMAIN/$SELF_SIGN_CERTIFICATE_KEY_NAME"
85+
create_self_signed_certificate $SSL_CERTIFICATE_PATH $SSL_CERTIFICATE_KEY_PATH
6586
fi
6687

6788
log_message "INFO" "Sourcing ssl certificate: $SSL_CERTIFICATE_PATH" $SSL_CERTIFICATE_KEY_PATH

0 commit comments

Comments
 (0)