Skip to content

Commit 2a350ad

Browse files
committed
Generating server certificate in the http-tests workflow
1 parent 473e16d commit 2a350ad

File tree

2 files changed

+93
-3
lines changed

2 files changed

+93
-3
lines changed

.github/workflows/http-tests.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ jobs:
2323
JENA_HOME: "${{ runner.temp }}/apache-jena-${{ env.JENA_VERSION }}"
2424
- name: Checkout code
2525
uses: actions/checkout@v3
26-
with:
27-
path: http-tests
26+
- name: Generating server certificate
27+
run: ./scripts/server-cert-gen.sh .env nginx ssl
2828
- name: Writing secrets to files
2929
run: |
3030
mkdir -p ./secrets
3131
printf "%s" "${{ secrets.HTTP_TEST_OWNER_CERT_PASSWORD }}" > ./secrets/owner_cert_password.txt
3232
printf "%s" "${{ secrets.HTTP_TEST_SECRETARY_CERT_PASSWORD }}" > ./secrets/secretary_cert_password.txt
3333
printf "%s" "${{ secrets.HTTP_TEST_SECRETARY_CERT_PASSWORD }}" > ./secrets/client_truststore_password.txt
3434
shell: bash
35-
working-directory: http-tests
3635
- name: Build Docker image & Run Docker containers
3736
run: docker compose -f docker-compose.yml -f ./http-tests/docker-compose.http-tests.yml --env-file ./http-tests/.env up --build -d
3837
- name: Wait for the server to start...

scripts/server-cert-gen.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
if [ "$#" -ne 3 ]; then
5+
echo "Usage: $0" '$env_file $proxy_host $out_folder' >&2
6+
echo "Example: $0 .env nginx ssl" >&2
7+
exit 1
8+
fi
9+
10+
env_file="$1"
11+
proxy_host="$2"
12+
out_folder="$3"
13+
server_cert="${out_folder}/server/server.crt"
14+
server_public_key="${out_folder}/server/server.key"
15+
16+
function envProp {
17+
local expectedKey=$1
18+
while IFS='=' read -r k v; do
19+
if [ -n "$k" ] && [ "$k" == "$expectedKey" ] ; then
20+
echo "$v";
21+
break;
22+
fi
23+
done < "$env_file"
24+
}
25+
26+
printf "### Output folder: %s\n" "$out_folder"
27+
28+
if [ -z "$(envProp "PROTOCOL")" ]; then
29+
echo "Configuration is incomplete: PROTOCOL is missing"
30+
exit 1
31+
fi
32+
if [ -z "$(envProp "HTTPS_PORT")" ]; then
33+
echo "Configuration is incomplete: HTTPS_PORT is missing"
34+
exit 1
35+
fi
36+
if [ -z "$(envProp "HTTP_PORT")" ]; then
37+
echo "Configuration is incomplete: HTTP_PORT is missing"
38+
exit 1
39+
fi
40+
if [ -z "$(envProp "HOST")" ]; then
41+
echo "Configuration is incomplete: HOST is missing"
42+
exit 1
43+
fi
44+
if [ -z "$(envProp "ABS_PATH")" ]; then
45+
echo "Configuration is incomplete: ABS_PATH is missing"
46+
exit 1
47+
fi
48+
49+
if [ "$(envProp "PROTOCOL")" = "https" ]; then
50+
if [ "$(envProp "HTTPS_PORT")" = 443 ]; then
51+
base_uri="$(envProp "PROTOCOL")://$(envProp "HOST")$(envProp "ABS_PATH")"
52+
else
53+
base_uri="$(envProp "PROTOCOL")://$(envProp "HOST"):$(envProp "HTTPS_PORT")$(envProp "ABS_PATH")"
54+
fi
55+
else
56+
if [ "$(envProp "HTTP_PORT")" = 80 ]; then
57+
base_uri="$(envProp "PROTOCOL")://$(envProp "HOST")$(envProp "ABS_PATH")"
58+
else
59+
base_uri="$(envProp "PROTOCOL")://$(envProp "HOST"):$(envProp "HTTP_PORT")$(envProp "ABS_PATH")"
60+
fi
61+
fi
62+
63+
printf "\n### Base URI: %s\n" "$base_uri"
64+
65+
### SERVER CERT ###
66+
67+
mkdir -p "$out_folder"/server
68+
69+
# crude check if the host is an IP address
70+
if [[ "$(envProp "HOST")" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
71+
if [ -n "$proxy_host" ]; then
72+
san="subjectAltName=IP:$(envProp "HOST"),DNS:${proxy_host}" # IP address - special case for localhost
73+
else
74+
san="subjectAltName=IP:$(envProp "HOST")" # IP address
75+
fi
76+
else
77+
if [ -n "$proxy_host" ]; then
78+
san="subjectAltName=DNS:$(envProp "HOST"),DNS:${proxy_host}" # hostname - special case for localhost
79+
else
80+
san="subjectAltName=DNS:$(envProp "HOST")" # hostname
81+
fi
82+
fi
83+
84+
# openssl <= 1.1.1
85+
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
86+
-keyout "$server_public_key" \
87+
-out "$server_cert" \
88+
-subj "/CN=$(envProp "HOST")/OU=LinkedDataHub/O=AtomGraph/L=Copenhagen/C=DK" \
89+
-extensions san \
90+
-config <(echo '[req]'; echo 'distinguished_name=req';
91+
echo '[san]'; echo "$san")

0 commit comments

Comments
 (0)