Skip to content

Commit 21bc2c8

Browse files
committed
Add cert validation test
The PKI CA test has been updated to test server cert validation.
1 parent d674171 commit 21bc2c8

File tree

1 file changed

+158
-3
lines changed

1 file changed

+158
-3
lines changed

.github/workflows/pki-ca-test.yml

Lines changed: 158 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,27 @@ jobs:
2424
- name: Load JSS images
2525
run: docker load --input jss-images.tar
2626

27-
- name: Set up JSS container
27+
- name: Create network
28+
run: docker network create example
29+
30+
- name: Set up server container
2831
run: |
2932
tests/bin/runner-init.sh pki
3033
env:
3134
HOSTNAME: pki.example.com
3235

36+
- name: Connect server container to network
37+
run: docker network connect example pki --alias pki.example.com --alias server.example.com
38+
39+
- name: Set up client container
40+
run: |
41+
tests/bin/runner-init.sh client
42+
env:
43+
HOSTNAME: client.example.com
44+
45+
- name: Connect client container to network
46+
run: docker network connect example client --alias client.example.com
47+
3348
- name: Import LDAP SDK packages
3449
run: |
3550
docker create --name=ldapjdk-dist quay.io/$NAMESPACE/ldapjdk-dist:latest
@@ -44,10 +59,15 @@ jobs:
4459
4560
- name: Install packages
4661
run: |
62+
# install packages on server
4763
docker exec pki dnf install -y 389-ds-base
4864
docker cp /tmp/RPMS/. pki:/root/RPMS/
4965
docker exec pki bash -c "dnf localinstall -y /root/RPMS/*"
5066
67+
# install packages on client
68+
docker cp /tmp/RPMS/. client:/root/RPMS/
69+
docker exec client bash -c "dnf localinstall -y /root/RPMS/*"
70+
5171
- name: Install DS
5272
run: docker exec pki ${SHARED}/tests/bin/ds-create.sh
5373

@@ -56,8 +76,6 @@ jobs:
5676
docker exec pki pkispawn \
5777
-f /usr/share/pki/server/examples/installation/ca.cfg \
5878
-s CA \
59-
-D pki_cert_id_generator=random \
60-
-D pki_request_id_generator=random \
6179
-v
6280
6381
# set buffer size to 0 so that revocation takes effect immediately
@@ -109,6 +127,143 @@ jobs:
109127
docker exec pki /usr/share/pki/tests/ca/bin/test-ca-auditor-cert.sh
110128
docker exec pki /usr/share/pki/tests/ca/bin/test-ca-auditor-logs.sh
111129
130+
- name: Check client with untrusted server cert
131+
run: |
132+
# run client but don't trust the cert
133+
echo n | docker exec -i client pki -U https://pki.example.com:8443 info \
134+
> >(tee stdout) 2> >(tee stderr >&2) || true
135+
136+
# check stdout
137+
cat > expected << EOF
138+
Server URL: https://pki.example.com:8443
139+
EOF
140+
141+
diff expected stdout
142+
143+
# check stderr
144+
cat > expected << EOF
145+
WARNING: UNTRUSTED ISSUER encountered on 'CN=pki.example.com,OU=pki-tomcat,O=EXAMPLE' indicates a non-trusted CA cert 'CN=CA Signing Certificate,OU=pki-tomcat,O=EXAMPLE'
146+
Trust this certificate (y/N)? SEVERE: FATAL: SSL alert sent: BAD_CERTIFICATE
147+
IOException: Unable to write to socket: Failed to write to socket: (-5987) Invalid function argument.
148+
EOF
149+
150+
diff expected stderr
151+
152+
# the cert should not be stored
153+
docker exec client pki nss-cert-find | tee output
154+
155+
diff /dev/null output
156+
157+
- name: Check client with untrusted server cert with wrong hostname
158+
run: |
159+
# run client with wrong hostname
160+
echo n | docker exec -i client pki -U https://server.example.com:8443 info \
161+
> >(tee stdout) 2> >(tee stderr >&2) || true
162+
163+
# check stdout
164+
cat > expected << EOF
165+
Server URL: https://server.example.com:8443
166+
EOF
167+
168+
diff expected stdout
169+
170+
# check stderr
171+
cat > expected << EOF
172+
WARNING: BAD_CERT_DOMAIN encountered on 'CN=pki.example.com,OU=pki-tomcat,O=EXAMPLE' indicates a common-name mismatch
173+
WARNING: UNTRUSTED ISSUER encountered on 'CN=pki.example.com,OU=pki-tomcat,O=EXAMPLE' indicates a non-trusted CA cert 'CN=CA Signing Certificate,OU=pki-tomcat,O=EXAMPLE'
174+
Trust this certificate (y/N)? SEVERE: FATAL: SSL alert sent: BAD_CERTIFICATE
175+
IOException: Unable to write to socket: Failed to write to socket: (-12276) Unable to communicate securely with peer: requested domain name does not match the server's certificate.
176+
EOF
177+
178+
diff expected stderr
179+
180+
- name: Check client with newly trusted server cert
181+
run: |
182+
# run client and trust the cert
183+
echo y | docker exec -i client pki -U https://pki.example.com:8443 info \
184+
> >(tee stdout) 2> >(tee stderr >&2) || true
185+
186+
# check stdout
187+
cat > expected << EOF
188+
Server URL: https://pki.example.com:8443
189+
Server Name: Dogtag Certificate System
190+
Server Version: 11.6.0
191+
EOF
192+
193+
diff expected stdout
194+
195+
# check stderr
196+
cat > expected << EOF
197+
WARNING: UNTRUSTED ISSUER encountered on 'CN=pki.example.com,OU=pki-tomcat,O=EXAMPLE' indicates a non-trusted CA cert 'CN=CA Signing Certificate,OU=pki-tomcat,O=EXAMPLE'
198+
Trust this certificate (y/N)?
199+
EOF
200+
201+
# remove trailing whitespace
202+
sed -i 's/ *$//' stderr
203+
204+
# append end of line
205+
echo >> stderr
206+
207+
diff expected stderr
208+
209+
# the cert should be stored and trusted
210+
docker exec client pki nss-cert-find | tee output
211+
212+
sed -i \
213+
-e '/^ *Serial Number:/d' \
214+
-e '/^ *Not Valid Before:/d' \
215+
-e '/^ *Not Valid After:/d' \
216+
output
217+
218+
cat > expected << EOF
219+
Nickname: CN=pki.example.com,OU=pki-tomcat,O=EXAMPLE
220+
Subject DN: CN=pki.example.com,OU=pki-tomcat,O=EXAMPLE
221+
Issuer DN: CN=CA Signing Certificate,OU=pki-tomcat,O=EXAMPLE
222+
Trust Flags: P,,
223+
EOF
224+
225+
diff expected output
226+
227+
- name: Check client with trusted server cert with wrong hostname
228+
run: |
229+
# run client with wrong hostname
230+
docker exec client pki -U https://server.example.com:8443 info \
231+
> >(tee stdout) 2> >(tee stderr >&2) || true
232+
233+
# check stdout
234+
cat > expected << EOF
235+
Server URL: https://server.example.com:8443
236+
Server Name: Dogtag Certificate System
237+
Server Version: 11.6.0
238+
EOF
239+
240+
diff expected stdout
241+
242+
# check stderr
243+
cat > expected << EOF
244+
WARNING: BAD_CERT_DOMAIN encountered on 'CN=pki.example.com,OU=pki-tomcat,O=EXAMPLE' indicates a common-name mismatch
245+
EOF
246+
247+
diff expected stderr
248+
249+
- name: Check client with already trusted server cert
250+
run: |
251+
# run client with correct hostname
252+
docker exec client pki -U https://pki.example.com:8443 info \
253+
> >(tee stdout) 2> >(tee stderr >&2) || true
254+
255+
# check stdout
256+
cat > expected << EOF
257+
Server URL: https://pki.example.com:8443
258+
Server Name: Dogtag Certificate System
259+
Server Version: 11.6.0
260+
EOF
261+
262+
diff expected stdout
263+
264+
# check stderr
265+
diff /dev/null stderr
266+
112267
- name: Remove CA
113268
run: docker exec pki pkidestroy -i pki-tomcat -s CA -v
114269

0 commit comments

Comments
 (0)