-
Notifications
You must be signed in to change notification settings - Fork 139
443 lines (369 loc) · 15 KB
/
kra-migration-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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
name: KRA migration
on: workflow_call
env:
DS_IMAGE: ${{ vars.DS_IMAGE || 'quay.io/389ds/dirsrv' }}
jobs:
test:
name: Test
runs-on: ubuntu-latest
env:
SHARED: /tmp/workdir/pki
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Retrieve PKI images
uses: actions/cache@v4
with:
key: pki-images-${{ github.sha }}
path: pki-images.tar
- name: Load PKI images
run: docker load --input pki-images.tar
- name: Create network
run: docker network create example
- name: Set up first DS container
run: |
tests/bin/ds-create.sh \
--image=${{ env.DS_IMAGE }} \
--hostname=ds1.example.com \
--password=Secret.123 \
--base-dn="dc=pki1,dc=example,dc=com" \
ds1
- name: Connect first DS container to network
run: docker network connect example ds1 --alias ds1.example.com
- name: Set up first PKI container
run: |
tests/bin/runner-init.sh pki1
env:
HOSTNAME: pki1.example.com
- name: Connect first PKI container to network
run: docker network connect example pki1 --alias pki1.example.com
- name: Install first CA
run: |
docker exec pki1 pkispawn \
-f /usr/share/pki/server/examples/installation/ca.cfg \
-s CA \
-D pki_ds_url=ldap://ds1.example.com:3389 \
-D pki_ds_base_dn=dc=ca,dc=pki1,dc=example,dc=com \
-v
- name: Check first CA admin
run: |
docker exec pki1 pki \
-d /var/lib/pki/pki-tomcat/conf/alias \
-f /var/lib/pki/pki-tomcat/conf/password.conf \
nss-cert-export \
--output-file cert_chain.pem \
--with-chain \
ca_signing
docker exec pki1 pki nss-cert-import \
--cert cert_chain.pem \
--trust CT,C,C
docker exec pki1 pki pkcs12-import \
--pkcs12 /root/.dogtag/pki-tomcat/ca_admin_cert.p12 \
--pkcs12-password Secret.123
docker exec pki1 pki -n caadmin ca-user-show caadmin
- name: Install first KRA
run: |
docker exec pki1 pkispawn \
-f /usr/share/pki/server/examples/installation/kra.cfg \
-s KRA \
-D pki_ds_url=ldap://ds1.example.com:3389 \
-D pki_ds_base_dn=dc=kra,dc=pki1,dc=example,dc=com \
-v
- name: Check first KRA admin
run: |
docker exec pki1 pki -n caadmin kra-user-show kraadmin
- name: Check cert enrollment with key archival
run: |
# generate key and submit cert request
# https://github.com/dogtagpki/pki/wiki/Submitting-Certificate-Request-with-Key-Archival
docker exec pki1 pki \
-U http://pki1.example.com:8080 \
client-cert-request \
--profile caUserCert \
--type crmf \
--algorithm rsa \
--permanent \
UID=testuser | tee output
REQUEST_ID=$(sed -n "s/^\s*Request ID:\s*\(\S*\)\s*$/\1/p" output)
echo "Request ID: $REQUEST_ID"
# issue cert
docker exec pki1 pki \
-u caadmin \
-w Secret.123 \
ca-cert-request-approve \
--force \
$REQUEST_ID | tee output
CERT_ID=$(sed -n "s/^\s*Certificate ID:\s*\(\S*\)\s*$/\1/p" output)
echo "Cert ID: $CERT_ID"
# import cert into NSS database
docker exec pki1 pki ca-cert-export --output-file $SHARED/testuser.crt $CERT_ID
docker exec pki1 pki nss-cert-import --cert $SHARED/testuser.crt testuser
# the cert should match the key (trust flags must be u,u,u)
echo "u,u,u" > expected
docker exec pki1 pki nss-cert-show testuser | tee output
sed -n "s/^\s*Trust Flags:\s*\(\S*\)\s*$/\1/p" output > actual
diff expected actual
- name: Check archived key in first KRA
run: |
# find archived key by owner
docker exec pki1 pki \
-u kraadmin \
-w Secret.123 \
kra-key-find \
--owner UID=testuser | tee output
KEY_ID=$(sed -n "s/^\s*Key ID:\s*\(\S*\)$/\1/p" output)
echo "Key ID: $KEY_ID"
echo $KEY_ID > key.id
DEC_KEY_ID=$(python -c "print(int('$KEY_ID', 16))")
echo "Dec Key ID: $DEC_KEY_ID"
# get key record
docker exec ds1 ldapsearch \
-H ldap://ds1.example.com:3389 \
-x \
-D "cn=Directory Manager" \
-w Secret.123 \
-b "cn=$DEC_KEY_ID,ou=keyRepository,ou=kra,dc=kra,dc=pki1,dc=example,dc=com" \
-o ldif_wrap=no \
-LLL | tee kra1.ldif
# encryption mode should be "false" by default
echo "false" > expected
sed -n 's/^metaInfo: payloadEncrypted:\(.*\)$/\1/p' kra1.ldif > actual
diff expected actual
# key wrap algorithm should be "AES KeyWrap/Padding" by default
echo "AES KeyWrap/Padding" > expected
sed -n 's/^metaInfo: payloadWrapAlgorithm:\(.*\)$/\1/p' kra1.ldif > actual
diff expected actual
- name: Check key retrieval from first KRA
run: |
KEY_ID=$(cat key.id)
echo "Key ID: $KEY_ID"
BASE64_CERT=$(docker exec pki1 pki nss-cert-export --format DER testuser | base64 --wrap=0)
echo "Cert: $BASE64_CERT"
cat > request.json <<EOF
{
"ClassName" : "com.netscape.certsrv.key.KeyRecoveryRequest",
"Attributes" : {
"Attribute" : [ {
"name" : "keyId",
"value" : "$KEY_ID"
}, {
"name" : "certificate",
"value" : "$BASE64_CERT"
}, {
"name" : "passphrase",
"value" : "Secret.123"
} ]
}
}
EOF
# retrieve archived cert and key into PKCS #12 file
# https://github.com/dogtagpki/pki/wiki/Retrieving-Archived-Key
docker exec pki1 pki \
-n caadmin \
kra-key-retrieve \
--input $SHARED/request.json \
--output-data archived.p12
# import PKCS #12 file into NSS database
docker exec pki1 pki \
-d nssdb \
pkcs12-import \
--pkcs12 archived.p12 \
--password Secret.123
# remove archived cert from NSS database
docker exec pki1 pki -d nssdb nss-cert-del UID=testuser
# import original cert into NSS database
docker exec pki1 pki -d nssdb nss-cert-import --cert $SHARED/testuser.crt testuser
# the original cert should match the archived key (trust flags must be u,u,u)
echo "u,u,u" > expected
docker exec pki1 pki -d nssdb nss-cert-show testuser | tee output
sed -n "s/^\s*Trust Flags:\s*\(\S*\)$/\1/p" output > actual
diff expected actual
- name: Set up second DS container
run: |
tests/bin/ds-create.sh \
--image=${{ env.DS_IMAGE }} \
--hostname=ds2.example.com \
--password=Secret.123 \
--base-dn="dc=pki2,dc=example,dc=com" \
ds2
- name: Connect second DS container to network
run: docker network connect example ds2 --alias ds2.example.com
- name: Set up second PKI container
run: |
tests/bin/runner-init.sh pki2
env:
HOSTNAME: pki2.example.com
- name: Connect second PKI container to network
run: docker network connect example pki2 --alias pki2.example.com
- name: Install second CA
run: |
docker exec pki2 pkispawn \
-f /usr/share/pki/server/examples/installation/ca.cfg \
-s CA \
-D pki_ds_url=ldap://ds2.example.com:3389 \
-D pki_ds_base_dn=dc=ca,dc=pki2,dc=example,dc=com \
-v
- name: Check second CA admin
run: |
docker exec pki2 pki \
-d /var/lib/pki/pki-tomcat/conf/alias \
-f /var/lib/pki/pki-tomcat/conf/password.conf \
nss-cert-export \
--output-file cert_chain.pem \
--with-chain \
ca_signing
docker exec pki2 pki nss-cert-import \
--cert cert_chain.pem \
--trust CT,C,C
docker exec pki2 pki pkcs12-import \
--pkcs12 /root/.dogtag/pki-tomcat/ca_admin_cert.p12 \
--pkcs12-password Secret.123
docker exec pki2 pki -n caadmin ca-user-show caadmin
- name: Install second KRA
run: |
docker exec pki2 pkispawn \
-f /usr/share/pki/server/examples/installation/kra.cfg \
-s KRA \
-D pki_ds_url=ldap://ds2.example.com:3389 \
-D pki_ds_base_dn=dc=kra,dc=pki2,dc=example,dc=com \
-v
- name: Check second KRA admin
run: |
docker exec pki2 pki -n caadmin kra-user-show kraadmin
- name: Rewrap archived keys
run: |
echo "Secret.123" > password.txt
# export second KRA storage cert
docker exec pki2 pki-server cert-export kra_storage \
--cert-file $SHARED/kra2_storage.crt
# rewrap archived keys using second KRA storage cert
docker exec pki1 KRATool \
-kratool_config_file /usr/share/pki/tools/KRATool.cfg \
-source_kra_naming_context dc=kra,dc=pki1,dc=example,dc=com \
-source_pki_security_database_path /var/lib/pki/pki-tomcat/conf/alias \
-source_pki_security_database_pwdfile $SHARED/password.txt \
-source_storage_token_name "Internal Key Storage Token" \
-source_storage_certificate_nickname kra_storage \
-source_ldif_file $SHARED/kra1.ldif \
-process_requests_and_key_records_only \
-unwrap_algorithm AES \
-target_ldif_file $SHARED/keys.ldif \
-target_kra_naming_context dc=kra,dc=pki2,dc=example,dc=com \
-target_storage_certificate_file $SHARED/kra2_storage.crt \
-log_file $SHARED/kratool.log
cat kratool.log
cat keys.ldif
- name: Import keys into second KRA
run: |
docker exec ds2 ldapadd \
-H ldap://ds2.example.com:3389 \
-x \
-D "cn=Directory Manager" \
-w Secret.123 \
-f $SHARED/keys.ldif
- name: Check archived key in second KRA
run: |
KEY_ID=$(cat key.id)
echo "Key ID: $KEY_ID"
DEC_KEY_ID=$(python -c "print(int('$KEY_ID', 16))")
echo "Dec Key ID: $DEC_KEY_ID"
# get key record
docker exec ds2 ldapsearch \
-H ldap://ds2.example.com:3389 \
-x \
-D "cn=Directory Manager" \
-w Secret.123 \
-b "cn=$DEC_KEY_ID,ou=keyRepository,ou=kra,dc=kra,dc=pki2,dc=example,dc=com" \
-o ldif_wrap=no \
-LLL | tee kra2.ldif
# encryption mode should be "false" by default
echo "false" > expected
sed -n 's/^metaInfo: payloadEncrypted:\(.*\)$/\1/p' kra2.ldif > actual
diff expected actual
# key wrap algorithm should be "AES KeyWrap/Padding" by default
echo "AES KeyWrap/Padding" > expected
sed -n 's/^metaInfo: payloadWrapAlgorithm:\(.*\)$/\1/p' kra2.ldif > actual
diff expected actual
- name: Check key retrieval from second KRA
run: |
KEY_ID=$(cat key.id)
echo "Key ID: $KEY_ID"
BASE64_CERT=$(docker exec pki1 pki nss-cert-export --format DER testuser | base64 --wrap=0)
echo "Cert: $BASE64_CERT"
cat > request.json <<EOF
{
"ClassName" : "com.netscape.certsrv.key.KeyRecoveryRequest",
"Attributes" : {
"Attribute" : [ {
"name" : "keyId",
"value" : "$KEY_ID"
}, {
"name" : "certificate",
"value" : "$BASE64_CERT"
}, {
"name" : "passphrase",
"value" : "Secret.123"
} ]
}
}
EOF
# retrieve archived cert and key into PKCS #12 file
# https://github.com/dogtagpki/pki/wiki/Retrieving-Archived-Key
docker exec pki2 pki \
-n caadmin \
kra-key-retrieve \
--input $SHARED/request.json \
--output-data archived.p12
# import PKCS #12 file into NSS database
docker exec pki2 pki \
-d nssdb \
pkcs12-import \
--pkcs12 archived.p12 \
--password Secret.123
# remove archived cert from NSS database
docker exec pki2 pki -d nssdb nss-cert-del UID=testuser
# import original cert into NSS database
docker exec pki2 pki -d nssdb nss-cert-import --cert $SHARED/testuser.crt testuser
# the original cert should match the archived key (trust flags must be u,u,u)
echo "u,u,u" > expected
docker exec pki2 pki -d nssdb nss-cert-show testuser | tee output
sed -n "s/^\s*Trust Flags:\s*\(\S*\)$/\1/p" output > actual
diff expected actual
- name: Remove first KRA
run: docker exec pki1 pkidestroy -s KRA -v
- name: Remove first CA
run: docker exec pki1 pkidestroy -s CA -v
- name: Remove second KRA
run: docker exec pki2 pkidestroy -s KRA -v
- name: Remove second CA
run: docker exec pki2 pkidestroy -s CA -v
- name: Check first CA debug log
if: always()
run: |
docker exec pki1 find /var/lib/pki/pki-tomcat/logs/ca -name "debug.*" -exec cat {} \;
- name: Check first KRA debug log
if: always()
run: |
docker exec pki1 find /var/lib/pki/pki-tomcat/logs/kra -name "debug.*" -exec cat {} \;
- name: Check second CA debug log
if: always()
run: |
docker exec pki2 find /var/lib/pki/pki-tomcat/logs/ca -name "debug.*" -exec cat {} \;
- name: Check second KRA debug log
if: always()
run: |
docker exec pki2 find /var/lib/pki/pki-tomcat/logs/kra -name "debug.*" -exec cat {} \;
- name: Gather artifacts
if: always()
run: |
tests/bin/ds-artifacts-save.sh ds1
tests/bin/ds-artifacts-save.sh ds2
tests/bin/pki-artifacts-save.sh pki1
tests/bin/pki-artifacts-save.sh pki2
continue-on-error: true
- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: kra-migration-test
path: /tmp/artifacts