37
37
PRODUCTION_NODE_URL_REST = "https://on.dcl.csa-iot.org"
38
38
TEST_NODE_URL_REST = "https://on.test-net.dcl.csa-iot.org"
39
39
40
+ # TODO: really? We can't just get this by name from the DCL?
41
+ MATTER_CERT_CA_SUBJECT = "MFIxDDAKBgNVBAoMA0NTQTEsMCoGA1UEAwwjTWF0dGVyIENlcnRpZmljYXRpb24gYW5kIFRlc3RpbmcgQ0ExFDASBgorBgEEAYKifAIBDARDNUEw"
42
+ MATTER_CERT_CA_SUBJECT_KEY_ID = "97:E4:69:D0:C5:04:14:C2:6F:C7:01:F7:7E:94:77:39:09:8D:F6:A5"
43
+
40
44
41
45
def parse_paa_root_certs (cmdpipe , paa_list ):
42
46
"""
@@ -80,7 +84,7 @@ def parse_paa_root_certs(cmdpipe, paa_list):
80
84
paa_list .append (copy .deepcopy (result ))
81
85
82
86
83
- def write_paa_root_cert (certificate , subject ):
87
+ def write_cert (certificate , subject ):
84
88
filename = 'dcld_mirror_' + \
85
89
re .sub ('[^a-zA-Z0-9_-]' , '' , re .sub ('[=, ]' , '_' , subject ))
86
90
with open (filename + '.pem' , 'w+' ) as outfile :
@@ -135,10 +139,37 @@ def use_dcld(dcld, production, cmdlist):
135
139
@optgroup .option ('--paa-trust-store-path' , default = 'paa-root-certs' , type = str , metavar = 'PATH' , help = "PAA trust store path (default: paa-root-certs)" )
136
140
def main (use_main_net_dcld , use_test_net_dcld , use_main_net_http , use_test_net_http , paa_trust_store_path ):
137
141
"""DCL PAA mirroring tools"""
138
- fetch_certs (use_main_net_dcld , use_test_net_dcld , use_main_net_http , use_test_net_http , paa_trust_store_path )
142
+ fetch_paa_certs (use_main_net_dcld , use_test_net_dcld , use_main_net_http , use_test_net_http , paa_trust_store_path )
143
+
144
+
145
+ def get_cert_from_rest (rest_node_url , subject , subject_key_id ):
146
+ response = requests .get (
147
+ f"{ rest_node_url } /dcl/pki/certificates/{ subject } /{ subject_key_id } " ).json ()["approvedCertificates" ]["certs" ][0 ]
148
+ certificate = response ["pemCert" ].rstrip ("\n " )
149
+ subject = response ["subjectAsText" ]
150
+ return certificate , subject
151
+
152
+
153
+ def fetch_cd_signing_certs (store_path ):
154
+ ''' Only supports using main net http currently.'''
155
+ rest_node_url = PRODUCTION_NODE_URL_REST
156
+ os .makedirs (store_path , exist_ok = True )
157
+ original_dir = os .getcwd ()
158
+ os .chdir (store_path )
159
+
160
+ cd_signer_ids = requests .get (f"{ rest_node_url } /dcl/pki/child-certificates/{ MATTER_CERT_CA_SUBJECT } /{ MATTER_CERT_CA_SUBJECT_KEY_ID } " ).json ()['childCertificates' ]['certIds' ]
161
+ for signer in cd_signer_ids :
162
+ subject = signer ['subject' ]
163
+ subject_key_id = signer ['subjectKeyId' ]
164
+ certificate , subject = get_cert_from_rest (rest_node_url , subject , subject_key_id )
165
+
166
+ print (f"Downloaded CD signing cert with subject: { subject } " )
167
+ write_cert (certificate , subject )
168
+
169
+ os .chdir (original_dir )
139
170
140
171
141
- def fetch_certs (use_main_net_dcld , use_test_net_dcld , use_main_net_http , use_test_net_http , paa_trust_store_path ):
172
+ def fetch_paa_certs (use_main_net_dcld , use_test_net_dcld , use_main_net_http , use_test_net_http , paa_trust_store_path ):
142
173
production = False
143
174
dcld = use_test_net_dcld
144
175
@@ -171,10 +202,7 @@ def fetch_certs(use_main_net_dcld, use_test_net_dcld, use_main_net_http, use_tes
171
202
172
203
for paa in paa_list :
173
204
if use_rest :
174
- response = requests .get (
175
- f"{ rest_node_url } /dcl/pki/certificates/{ paa ['subject' ]} /{ paa ['subjectKeyId' ]} " ).json ()["approvedCertificates" ]["certs" ][0 ]
176
- certificate = response ["pemCert" ]
177
- subject = response ["subjectAsText" ]
205
+ certificate , subject = get_cert_from_rest (rest_node_url , paa ['subject' ], paa ['subjectKeyId' ])
178
206
else :
179
207
cmdlist = ['query' , 'pki' , 'x509-cert' , '-u' ,
180
208
paa ['subject' ], '-k' , paa ['subjectKeyId' ]]
@@ -186,8 +214,8 @@ def fetch_certs(use_main_net_dcld, use_test_net_dcld, use_main_net_http, use_tes
186
214
187
215
certificate = certificate .rstrip ('\n ' )
188
216
189
- print (f"Downloaded certificate with subject: { subject } " )
190
- write_paa_root_cert (certificate , subject )
217
+ print (f"Downloaded PAA certificate with subject: { subject } " )
218
+ write_cert (certificate , subject )
191
219
192
220
os .chdir (original_dir )
193
221
0 commit comments