-
Notifications
You must be signed in to change notification settings - Fork 139
176 lines (149 loc) · 6.5 KB
/
pki-pkcs12-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: PKI PKCS12 CLI
on: workflow_call
env:
DB_IMAGE: ${{ vars.DB_IMAGE || 'quay.io/389ds/dirsrv' }}
jobs:
# https://github.com/dogtagpki/pki/wiki/PKI-PKCS12-CLI
test:
name: Test
runs-on: ubuntu-latest
env:
SHARED: /tmp/workdir/pki
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Retrieve PKI images
uses: actions/cache@v3
with:
key: pki-images-${{ github.sha }}
path: pki-images.tar
- name: Load PKI images
run: docker load --input pki-images.tar
- name: Set up runner container
run: |
tests/bin/runner-init.sh pki
env:
HOSTNAME: pki.example.com
- name: Generate CA signing cert request in NSS database
run: |
docker exec pki pki nss-cert-request \
--subject "CN=Certificate Authority" \
--ext /usr/share/pki/server/certs/ca_signing.conf \
--csr ca_signing.csr
- name: Issue self-signed CA signing cert
run: |
docker exec pki pki nss-cert-issue \
--csr ca_signing.csr \
--ext /usr/share/pki/server/certs/ca_signing.conf \
--cert ca_signing.crt
docker exec pki cat ca_signing.crt
- name: Import CA signing cert into NSS database
run: |
docker exec pki pki nss-cert-import \
--cert ca_signing.crt \
--trust CT,C,C \
ca_signing
- name: Generate SSL server cert request in NSS database
run: |
docker exec pki pki nss-cert-request \
--subject "CN=localhost.localdomain" \
--ext /usr/share/pki/server/certs/sslserver.conf \
--csr sslserver.csr
- name: Issue SSL server cert signed by CA signing cert
run: |
docker exec pki pki nss-cert-issue \
--issuer ca_signing \
--csr sslserver.csr \
--ext /usr/share/pki/server/certs/ca_signing.conf \
--cert sslserver.crt
docker exec pki cat sslserver.crt
- name: Import SSL server cert into NSS database
run: docker exec pki pki nss-cert-import --cert sslserver.crt sslserver
- name: "Export all certs and keys from NSS database into PKCS #12 file"
run: |
docker exec pki pki pkcs12-export \
--pkcs12-file test.p12 \
--pkcs12-password Secret.123
- name: "List certs in PKCS #12 file"
run: |
docker exec pki pki pkcs12-cert-find \
--pkcs12-file test.p12 \
--pkcs12-password Secret.123 | tee output
# compare certs in PKCS #12 file and in NSS database
sed -n 's/^\s*Friendly Name:\s*\(.\+\)\s*$/\1/p' output | sort > actual
docker exec pki certutil -L -d /root/.dogtag/nssdb | tee output
tail -n +5 output | awk '{print $1;}' | sort > expected
diff actual expected
- name: "List keys in PKCS #12 file"
run: |
docker exec pki pki pkcs12-key-find \
--pkcs12-file test.p12 \
--pkcs12-password Secret.123 | tee output
# compare keys in PKCS #12 file and in NSS database
sed -n 's/^\s*Key ID:\s*0x\(.\+\)\s*$/\1/p' output | sort > actual
docker exec pki certutil -K -d /root/.dogtag/nssdb | tee output
sed -n 's/^<.*>\s\+\S\+\s\+\(\S\+\).*/\1/p' output | sort > expected
diff actual expected
- name: "Export SSL server cert from PKCS #12 file"
run: |
docker exec pki pki pkcs12-cert-export \
--pkcs12-file test.p12 \
--pkcs12-password Secret.123 \
--cert-file sslserver2.crt \
sslserver
# verify exported cert
docker exec pki diff sslserver.crt sslserver2.crt
- name: "Remove SSL server cert from PKCS #12 file"
run: |
docker exec pki pki pkcs12-cert-del \
--pkcs12-file test.p12 \
--pkcs12-password Secret.123 \
sslserver
# verify cert removal
docker exec pki pki pkcs12-cert-find \
--pkcs12-file test.p12 \
--pkcs12-password Secret.123 | tee output
sed -n 's/^\s*Friendly Name:\s*\(.\+\)\s*$/\1/p' output | sort > actual
echo ca_signing > expected
diff actual expected
- name: "Re-import SSL server cert from NSS database into PKCS #12 file"
run: |
docker exec pki pki pkcs12-cert-import \
--pkcs12-file test.p12 \
--pkcs12-password Secret.123 \
--append \
--no-chain \
sslserver
# compare certs in PKCS #12 file and in NSS database
docker exec pki pki pkcs12-cert-find \
--pkcs12-file test.p12 \
--pkcs12-password Secret.123 | tee output
sed -n 's/^\s*Friendly Name:\s*\(.\+\)\s*$/\1/p' output | sort > actual
docker exec pki certutil -L -d /root/.dogtag/nssdb | tee output
tail -n +5 output | awk '{print $1;}' | sort > expected
diff actual expected
# compare keys in PKCS #12 file and in NSS database
docker exec pki pki pkcs12-key-find \
--pkcs12-file test.p12 \
--pkcs12-password Secret.123 | tee output
sed -n 's/^\s*Key ID:\s*0x\(.\+\)\s*$/\1/p' output | sort > actual
docker exec pki certutil -K -d /root/.dogtag/nssdb | tee output
sed -n 's/^<.*>\s\+\S\+\s\+\(\S\+\).*/\1/p' output| sort > expected
diff actual expected
- name: "Import all certs and keys from PKCS #12 file into a new NSS database"
run: |
docker exec pki pki -d nssdb pkcs12-import \
--pkcs12-file test.p12 \
--pkcs12-password Secret.123
# compare certs in new and old NSS databases
docker exec pki certutil -L -d nssdb | tee output
tail -n +5 output | awk '{print $1;}' | sort > actual
docker exec pki certutil -L -d /root/.dogtag/nssdb | tee output
tail -n +5 output | awk '{print $1;}' | sort > expected
diff actual expected
# compare keys in new and old NSS databases
docker exec pki certutil -K -d nssdb | tee output
sed -n 's/^<.*>\s\+\S\+\s\+\(\S\+\).*/\1/p' output | sort > actual
docker exec pki certutil -K -d /root/.dogtag/nssdb | tee output
sed -n 's/^<.*>\s\+\S\+\s\+\(\S\+\).*/\1/p' output | sort > expected
diff actual expected