forked from zigbee-alliance/distributed-compliance-ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pki-combine-certs.sh
executable file
·423 lines (334 loc) · 18.6 KB
/
pki-combine-certs.sh
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
#!/bin/bash
# Copyright 2020 DSR Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
source integration_tests/cli/common.sh
# DA
da_root_path="integration_tests/constants/root_cert"
da_root_subject="MDQxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApzb21lLXN0YXRlMRAwDgYDVQQKDAdyb290LWNh"
da_root_subject_key_id="5A:88:0E:6C:36:53:D0:7F:B0:89:71:A3:F4:73:79:09:30:E6:2B:DB"
da_intermediate_path="integration_tests/constants/intermediate_cert"
da_intermediate_subject="MDwxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApzb21lLXN0YXRlMRgwFgYDVQQKDA9pbnRlcm1lZGlhdGUtY2E="
da_intermediate_subject_key_id="4E:3B:73:F4:70:4D:C2:98:0D:DB:C8:5A:5F:02:3B:BF:86:25:56:2B"
da_leaf_path="integration_tests/constants/leaf_cert"
da_leaf_subject="MDExCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApzb21lLXN0YXRlMQ0wCwYDVQQKDARsZWFm"
da_leaf_subject_key_id="30:F4:65:75:14:20:B2:AF:3D:14:71:17:AC:49:90:93:3E:24:A0:1F"
# NOC
noc_root_path="integration_tests/constants/noc_root_cert_1"
noc_root_subject="MHoxCzAJBgNVBAYTAlVaMRMwEQYDVQQIDApTb21lIFN0YXRlMREwDwYDVQQHDAhUYXNoa2VudDEYMBYGA1UECgwPRXhhbXBsZSBDb21wYW55MRkwFwYDVQQLDBBUZXN0aW5nIERpdmlzaW9uMQ4wDAYDVQQDDAVOT0MtMQ=="
noc_root_subject_key_id="44:EB:4C:62:6B:25:48:CD:A2:B3:1C:87:41:5A:08:E7:2B:B9:83:26"
noc_intermediate_path="integration_tests/constants/noc_cert_1"
noc_intermediate_subject="MIGCMQswCQYDVQQGEwJVWjETMBEGA1UECAwKU29tZSBTdGF0ZTETMBEGA1UEBwwKU29tZSBTdGF0ZTEYMBYGA1UECgwPRXhhbXBsZSBDb21wYW55MRkwFwYDVQQLDBBUZXN0aW5nIERpdmlzaW9uMRQwEgYDVQQDDAtOT0MtY2hpbGQtMQ=="
noc_intermediate_subject_key_id="02:72:6E:BC:BB:EF:D6:BD:8D:9B:42:AE:D4:3C:C0:55:5F:66:3A:B3"
noc_leaf_path="integration_tests/constants/noc_leaf_cert_1"
noc_leaf_subject="MIGBMQswCQYDVQQGEwJVWjETMBEGA1UECAwKU29tZSBTdGF0ZTETMBEGA1UEBwwKU29tZSBTdGF0ZTEYMBYGA1UECgwPRXhhbXBsZSBDb21wYW55MRkwFwYDVQQLDBBUZXN0aW5nIERpdmlzaW9uMRMwEQYDVQQDDApOT0MtbGVhZi0x"
noc_leaf_subject_key_id="77:1F:DB:C4:4C:B1:29:7E:3C:EB:3E:D8:2A:38:0B:63:06:07:00:01"
# Accounts
trustee_account="jack"
second_trustee_account="alice"
vid_in_hex_format=0x6006
vid=24582
vendor_account=vendor_account_$vid_in_hex_format
echo "Create Vendor account - $vendor_account"
create_new_vendor_account $vendor_account $vid_in_hex_format
vid_2_in_hex_format=0x125D
vid_2=4701
test_divider
# Body
echo "1. QUERY Certificates (EMPTY)"
test_divider
echo "Request all approved DA certificates must be empty"
result=$(dcld query pki all-x509-certs)
echo $result | jq
check_response "$result" "\[\]"
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
echo "Request all NOC certificates must be empty"
result=$(dcld query pki all-noc-x509-certs)
echo $result | jq
check_response "$result" "\[\]"
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
test_divider
echo "Request approved DA certificate must be empty"
result=$(dcld query pki x509-cert --subject="$da_root_subject" --subject-key-id="$da_root_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
echo "Request NOC Root certificate must be empty"
result=$(dcld query pki noc-x509-cert --subject="$noc_root_subject" --subject-key-id="$noc_root_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
test_divider
echo "Request proposed DA Root certificate must be empty"
result=$(dcld query pki proposed-x509-root-cert --subject="$da_root_subject" --subject-key-id="$da_root_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
echo "Request all proposed DA Root certificates must be empty"
result=$(dcld query pki all-proposed-x509-root-certs)
check_response "$result" "\[\]"
echo $result | jq
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
test_divider
echo "Request all revoked DA certificates must be empty"
result=$(dcld query pki all-revoked-x509-certs)
echo $result | jq
check_response "$result" "\[\]"
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
echo "Request all revoked NOC Root certificates must be empty"
result=$(dcld query pki all-revoked-noc-x509-root-certs)
echo $result | jq
check_response "$result" "\[\]"
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
echo "Request all revoked NOC ICA certificates must be empty"
result=$(dcld query pki all-revoked-noc-x509-ica-certs)
echo $result | jq
check_response "$result" "\[\]"
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_intermediate_subject_key_id\""
echo "Request revoked DA certificate must be empty"
result=$(dcld query pki revoked-x509-cert --subject="$da_root_subject" --subject-key-id="$da_root_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
echo "Request revoked NOC Root certificate must be empty"
result=$(dcld query pki revoked-noc-x509-root-cert --subject="$noc_root_subject" --subject-key-id="$noc_root_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
echo "Request revoked NOC ICA certificate must be empty"
result=$(dcld query pki revoked-noc-x509-ica-cert --subject="$noc_intermediate_subject" --subject-key-id="$noc_intermediate_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_intermediate_subject_key_id\""
test_divider
echo "Request all DA certificates by subject must be empty"
result=$(dcld query pki all-subject-x509-certs --subject="$da_root_subject")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"$da_root_subject\""
echo "Request all NOC certificates by subject must be empty"
result=$(dcld query pki all-noc-subject-x509-certs --subject="$noc_root_subject")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"$noc_root_subject\""
test_divider
echo "Request all child certificates for DA root must be empty"
result=$(dcld query pki all-child-x509-certs --subject="$da_root_subject" --subject-key-id="$da_root_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"$da_root_subject_key_id\""
echo "Request all child certificates for NOC root must be empty"
result=$(dcld query pki all-child-x509-certs --subject="$noc_root_subject" --subject-key-id="$noc_root_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"$noc_root_subject_key_id\""
test_divider
echo "2. ADD Certificates"
test_divider
echo "$trustee_account (Trustee) propose DA Root certificate"
cert_schema_version_0=0
result=$(echo "$passphrase" | dcld tx pki propose-add-x509-root-cert --certificate="$da_root_path" --schemaVersion=$cert_schema_version_0 --from $trustee_account --vid $vid --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
echo "$second_trustee_account (Second Trustee) approves DA Root certificate"
result=$(echo "$passphrase" | dcld tx pki approve-add-x509-root-cert --subject="$da_root_subject" --subject-key-id="$da_root_subject_key_id" --from $second_trustee_account --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
echo "$vendor_account adds DA Intermediate certificate"
result=$(echo "$passphrase" | dcld tx pki add-x509-cert --certificate="$da_intermediate_path" --schemaVersion=$cert_schema_version_0 --from $vendor_account --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
echo "$vendor_account add DA Leaf certificate"
result=$(echo "$passphrase" | dcld tx pki add-x509-cert --certificate="$da_leaf_path" --from $vendor_account --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
echo "$vendor_account add NOC Root certificate"
cert_schema_version_0=0
result=$(echo "$passphrase" | dcld tx pki add-noc-x509-root-cert --certificate="$noc_root_path" --schemaVersion=$cert_schema_version_0 --from $vendor_account --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
echo "$vendor_account adds NOC Intermediate certificate"
result=$(echo "$passphrase" | dcld tx pki add-noc-x509-ica-cert --certificate="$noc_intermediate_path" --from $vendor_account --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
echo "$vendor_account adds NOC Leaf certificate"
result=$(echo "$passphrase" | dcld tx pki add-noc-x509-ica-cert --certificate="$noc_leaf_path" --from $vendor_account --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
echo "3. QUERY Certificates (PRESENT)"
test_divider
echo "Request all certificates"
result=$(dcld query pki all-certs)
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
check_response "$result" "\"subjectKeyId\": \"$da_intermediate_subject_key_id\""
check_response "$result" "\"subjectKeyId\": \"$da_leaf_subject_key_id\""
check_response "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
check_response "$result" "\"subjectKeyId\": \"$noc_intermediate_subject_key_id\""
check_response "$result" "\"subjectKeyId\": \"$noc_leaf_subject_key_id\""
echo "Request all approved DA certificates"
result=$(dcld query pki all-x509-certs)
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
check_response "$result" "\"subjectKeyId\": \"$da_intermediate_subject_key_id\""
check_response "$result" "\"subjectKeyId\": \"$da_leaf_subject_key_id\""
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_intermediate_subject_key_id\""
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_leaf_subject_key_id\""
echo "Request all NOC certificates"
result=$(dcld query pki all-noc-x509-certs)
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
check_response "$result" "\"subjectKeyId\": \"$noc_intermediate_subject_key_id\""
check_response "$result" "\"subjectKeyId\": \"$noc_leaf_subject_key_id\""
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_intermediate_subject_key_id\""
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_leaf_subject_key_id\""
test_divider
echo "Request DA certificate using global command"
result=$(dcld query pki cert --subject="$da_root_subject" --subject-key-id="$da_root_subject_key_id")
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
echo "Request NOC certificate using global command"
result=$(dcld query pki cert --subject="$noc_root_subject" --subject-key-id="$noc_root_subject_key_id")
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
echo "Request DA certificate"
result=$(dcld query pki x509-cert --subject="$da_root_subject" --subject-key-id="$da_root_subject_key_id")
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
echo "Request NOC certificate using DA command (must be empty)"
result=$(dcld query pki x509-cert --subject="$noc_root_subject" --subject-key-id="$noc_root_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
echo "Request NOC Root certificate"
result=$(dcld query pki noc-x509-cert --subject="$noc_root_subject" --subject-key-id="$noc_root_subject_key_id")
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
echo "Request DA certificate using NOC command (must be empty)"
result=$(dcld query pki noc-x509-cert --subject="$da_root_subject" --subject-key-id="$da_root_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
test_divider
echo "Request certificates by subject key id"
echo "Request DA certificate using global command"
result=$(dcld query pki cert --subject-key-id="$da_root_subject_key_id")
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
echo "Request NOC certificate using global command"
result=$(dcld query pki cert --subject-key-id="$noc_root_subject_key_id")
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
echo "Request DA certificate"
result=$(dcld query pki x509-cert --subject-key-id="$da_root_subject_key_id")
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
echo "Request NOC certificate using DA command (must be empty)"
result=$(dcld query pki x509-cert --subject="$noc_root_subject" --subject-key-id="$noc_root_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
echo "Request NOC Root certificate"
result=$(dcld query pki noc-x509-cert --subject="$noc_root_subject" --subject-key-id="$noc_root_subject_key_id")
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$noc_root_subject_key_id\""
echo "Request DA certificate using NOC command (must be empty)"
result=$(dcld query pki noc-x509-cert --subject="$da_root_subject" --subject-key-id="$da_root_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_root_subject_key_id\""
test_divider
echo "Request DA certificates by subject using global command"
result=$(dcld query pki all-subject-certs --subject=$da_root_subject)
echo $result | jq
check_response "$result" "\"$da_root_subject\""
check_response "$result" "\"$da_root_subject_key_id\""
echo "Request NOC certificates by subject using global command"
result=$(dcld query pki all-subject-certs --subject=$noc_root_subject)
echo $result | jq
check_response "$result" "\"$noc_root_subject\""
check_response "$result" "\"$noc_root_subject_key_id\""
echo "Request all DA certificates by subject must be empty"
result=$(dcld query pki all-subject-x509-certs --subject="$da_root_subject")
echo $result | jq
check_response "$result" "\"$da_root_subject\""
echo "Request all NOC certificates by subject using DA command (must be empty)"
result=$(dcld query pki all-subject-x509-certs --subject="$noc_root_subject")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"$noc_root_subject\""
echo "Request all NOC certificates by subject"
result=$(dcld query pki all-noc-subject-x509-certs --subject="$noc_root_subject")
echo $result | jq
check_response "$result" "\"$noc_root_subject\""
echo "Request all DA certificates by subject using NOC command (must be empty)"
result=$(dcld query pki all-noc-subject-x509-certs --subject="$da_root_subject")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"$da_root_subject\""
test_divider
echo "Request all child certificates for DA root"
result=$(dcld query pki all-child-x509-certs --subject="$da_root_subject" --subject-key-id="$da_root_subject_key_id")
echo $result | jq
check_response "$result" "\"$da_root_subject\""
check_response "$result" "\"$da_root_subject_key_id\""
echo "Request all child certificates for NOC root"
result=$(dcld query pki all-child-x509-certs --subject="$noc_root_subject" --subject-key-id="$noc_root_subject_key_id")
echo $result | jq
check_response "$result" "\"$noc_root_subject\""
check_response "$result" "\"$noc_root_subject_key_id\""
test_divider
echo "4. Revoke Certificates"
test_divider
echo "$vendor_account revoke an intermediate DA certificate"
result=$(echo "$passphrase" | dcld tx pki revoke-x509-cert --subject="$da_intermediate_subject" --subject-key-id="$da_intermediate_subject_key_id" --from=$vendor_account --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
echo "$vendor_account revoke an intermediate NOC certificate"
result=$(echo "$passphrase" | dcld tx pki revoke-noc-x509-ica-cert --subject="$noc_intermediate_subject" --subject-key-id="$noc_intermediate_subject_key_id" --from=$vendor_account --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
test_divider
echo "Request all revoked DA certificates"
result=$(dcld query pki all-revoked-x509-certs)
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$da_intermediate_subject_key_id\""
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_intermediate_subject_key_id\""
echo "Request all revoked NOC ICA certificates must be empty"
result=$(dcld query pki all-revoked-noc-x509-ica-certs)
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$noc_intermediate_subject_key_id\""
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_intermediate_subject_key_id\""
echo "Request revoked DA certificate "
result=$(dcld query pki revoked-x509-cert --subject="$da_intermediate_subject" --subject-key-id="$da_intermediate_subject_key_id")
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$da_intermediate_subject_key_id\""
echo "Request revoked NOC certificate using DA command (must be empty)"
result=$(dcld query pki revoked-x509-cert --subject="$noc_intermediate_subject" --subject-key-id="$noc_intermediate_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"subjectKeyId\": \"$noc_intermediate_subject_key_id\""
echo "Request revoked NOC ICA certificate"
result=$(dcld query pki revoked-noc-x509-ica-cert --subject="$noc_intermediate_subject" --subject-key-id="$noc_intermediate_subject_key_id")
echo $result | jq
check_response "$result" "\"subjectKeyId\": \"$noc_intermediate_subject_key_id\""
echo "Request revoked DA certificate using NOC command (must be empty)"
result=$(dcld query pki revoked-noc-x509-ica-cert --subject="$da_intermediate_subject" --subject-key-id="$da_intermediate_subject_key_id")
echo $result | jq
check_response "$result" "Not Found"
response_does_not_contain "$result" "\"subjectKeyId\": \"$da_intermediate_subject_key_id\""
test_divider
echo "PASS"