32
32
if not os .path .exists (chip_cert_exe ):
33
33
print ("Error: chip-cert executable not found.Please build chip-cert in connectedhomeip by ninja -C out/host" )
34
34
35
+
35
36
def gen_test_certs (vendor_id : int ,
36
37
product_id : int ,
37
38
output : str ):
38
- """
39
- Generate Matter certificates according to given Vendor ID and Product ID using the chip-cert executable.
40
- To use own Product Attestation Authority certificate provide paa_cert_path and paa_key_path arguments.
41
- Without providing these arguments a PAA certificate will be get from /credentials/test/attestation directory
42
- in the Matter repository.
43
-
44
- Args:
45
- chip_cert_exe (str): path to chip-cert executable
46
- output (str): output path to store a newly generated certificates (CD, DAC, PAI)
47
- vendor_id (int): an identification number specific to Vendor
48
- product_id (int): an identification number specific to Product
49
- device_name (str): human-readable device name
50
- generate_cd (bool, optional): Generate Certificate Declaration and store it in thee output directory. Defaults to False.
51
- paa_cert_path (str, optional): provide PAA certification path. Defaults to None - a path will be set to
52
- /credentials/test/attestation directory.
53
- paa_key_path (str, optional): provide PAA key path. Defaults to None - a path will be set to
54
- /credentials/test/attestation directory.
55
- generate_all_certs: Generate the new DAC and PAI certificates
56
-
57
- Returns:
58
- dictionary: ["PAI_CERT": (str)<path to PAI cert .der file>,
59
- "DAC_CERT": (str)<path to DAC cert .der file>,
60
- "DAC_KEY": (str)<path to DAC key .der file>]
61
- """
62
39
63
40
CD_PATH = CHIP_ROOT + "/credentials/test/certification-declaration/Chip-Test-CD-Signing-Cert.pem"
64
41
CD_KEY_PATH = CHIP_ROOT + "/credentials/test/certification-declaration/Chip-Test-CD-Signing-Key.pem"
@@ -71,70 +48,72 @@ def gen_test_certs(vendor_id: int,
71
48
72
49
# generate Certification Declaration
73
50
cmd = [chip_cert_exe , "gen-cd" ,
74
- "--key" , CD_KEY_PATH ,
75
- "--cert" , CD_PATH ,
76
- "--out" , output + "_" + str (vendor_id ) + "_" + str (product_id ) + "/CD.der" ,
77
- "--format-version" , "1" ,
78
- "--vendor-id" , hex (vendor_id ),
79
- "--product-id" , hex (product_id ),
80
- "--device-type-id" , "0" ,
81
- "--certificate-id" , "FFFFFFFFFFFFFFFFFFF" ,
82
- "--security-level" , "0" ,
83
- "--security-info" , "0" ,
84
- "--certification-type" , "0" ,
85
- "--version-number" , "0xFFFF" ,
86
- ]
51
+ "--key" , CD_KEY_PATH ,
52
+ "--cert" , CD_PATH ,
53
+ "--out" , output + "_" + str (vendor_id ) + "_" + str (product_id ) + "/CD.der" ,
54
+ "--format-version" , "1" ,
55
+ "--vendor-id" , hex (vendor_id ),
56
+ "--product-id" , hex (product_id ),
57
+ "--device-type-id" , "0" ,
58
+ "--certificate-id" , "FFFFFFFFFFFFFFFFFFF" ,
59
+ "--security-level" , "0" ,
60
+ "--security-info" , "0" ,
61
+ "--certification-type" , "0" ,
62
+ "--version-number" , "0xFFFF" ,
63
+ ]
87
64
subprocess .run (cmd )
88
65
89
- new_certificates = {"PAI_CERT" : output + "_" + str (vendor_id ) + "_" + str (product_id ) + "/PAI_cert" ,
90
- "PAI_KEY" : output + "_" + str (vendor_id ) + "_" + str (product_id )+ "/PAI_key" ,
91
- "DAC_CERT" : output + "_" + str (vendor_id ) + "_" + str (product_id ) + "/DAC_cert" ,
92
- "DAC_KEY" : output + "_" + str (vendor_id )+ "_" + str (product_id ) + "/DAC_key"
66
+ new_certificates = {"PAI_CERT" : output + "_" + str (vendor_id ) + "_" + str (product_id ) + "/PAI_cert" ,
67
+ "PAI_KEY" : output + "_" + str (vendor_id ) + "_" + str (product_id )+ "/PAI_key" ,
68
+ "DAC_CERT" : output + "_" + str (vendor_id ) + "_" + str (product_id ) + "/DAC_cert" ,
69
+ "DAC_KEY" : output + "_" + str (vendor_id ) + "_" + str (product_id ) + "/DAC_key"
93
70
}
94
71
95
72
log .info ("Generating new PAI and DAC certificates using chip-cert..." )
96
73
97
74
# generate PAI
98
75
cmd = [chip_cert_exe , "gen-att-cert" ,
99
- "-t" , "i" ,
100
- "-c" , "device" ,
101
- "-V" , hex (vendor_id ),
102
- "-C" , PAA_PATH ,
103
- "-K" , PAA_KEY_PATH ,
104
- "-o" , new_certificates ["PAI_CERT" ] + ".pem" ,
105
- "-O" , new_certificates ["PAI_KEY" ] + ".pem" ,
106
- "-l" , str (10000 ),
107
- ]
76
+ "-t" , "i" ,
77
+ "-c" , "device" ,
78
+ "-V" , hex (vendor_id ),
79
+ "-C" , PAA_PATH ,
80
+ "-K" , PAA_KEY_PATH ,
81
+ "-o" , new_certificates ["PAI_CERT" ] + ".pem" ,
82
+ "-O" , new_certificates ["PAI_KEY" ] + ".pem" ,
83
+ "-l" , str (10000 ),
84
+ ]
108
85
subprocess .run (cmd )
109
86
110
87
# generate DAC
111
88
cmd = [chip_cert_exe , "gen-att-cert" ,
112
- "-t" , "d" ,
113
- "-c" , "device" ,
114
- "-V" , hex (vendor_id ),
115
- "-P" , hex (product_id ),
116
- "-C" , new_certificates ["PAI_CERT" ] + ".pem" ,
117
- "-K" , new_certificates ["PAI_KEY" ] + ".pem" ,
118
- "-o" , new_certificates ["DAC_CERT" ] + ".pem" ,
119
- "-O" , new_certificates ["DAC_KEY" ] + ".pem" ,
120
- "-l" , str (10000 ),
121
- ]
89
+ "-t" , "d" ,
90
+ "-c" , "device" ,
91
+ "-V" , hex (vendor_id ),
92
+ "-P" , hex (product_id ),
93
+ "-C" , new_certificates ["PAI_CERT" ] + ".pem" ,
94
+ "-K" , new_certificates ["PAI_KEY" ] + ".pem" ,
95
+ "-o" , new_certificates ["DAC_CERT" ] + ".pem" ,
96
+ "-O" , new_certificates ["DAC_KEY" ] + ".pem" ,
97
+ "-l" , str (10000 ),
98
+ ]
122
99
subprocess .run (cmd )
123
100
124
101
# convert to .der files
125
102
for cert_k , cert_v in new_certificates .items ():
126
103
action_type = "convert-cert" if cert_k .find ("CERT" ) != - 1 else "convert-key"
127
104
log .info (cert_v + ".der" )
128
105
cmd = [chip_cert_exe , action_type ,
129
- cert_v + ".pem" ,
130
- cert_v + ".der" ,
131
- "--x509-der" ,
132
- ]
106
+ cert_v + ".pem" ,
107
+ cert_v + ".der" ,
108
+ "--x509-der" ,
109
+ ]
133
110
subprocess .run (cmd )
134
111
135
112
return attestation_certs (new_certificates ["DAC_CERT" ] + ".der" ,
136
- new_certificates ["DAC_KEY" ] + ".der" ,
137
- new_certificates ["PAI_CERT" ] + ".der" )
113
+ new_certificates ["DAC_KEY" ] + ".der" ,
114
+ new_certificates ["PAI_CERT" ] + ".der" )
115
+
116
+
138
117
def get_args ():
139
118
def any_base_int (s ): return int (s , 0 )
140
119
parser = argparse .ArgumentParser (description = "ESP32 Attestation generation tool" )
@@ -144,14 +123,16 @@ def any_base_int(s): return int(s, 0)
144
123
parser .add_argument ('--product-id' , type = any_base_int , help = "Product id" )
145
124
return parser .parse_args ()
146
125
126
+
147
127
def set_up_out_dirs (args ):
148
128
os .makedirs (args .output + "_" + str (args .vendor_id ) + "_" + str (args .product_id ), exist_ok = True )
149
129
130
+
150
131
def main ():
151
132
args = get_args ()
152
133
set_up_out_dirs (args )
153
134
certs = gen_test_certs (args .vendor_id , args .product_id , args .output )
154
135
136
+
155
137
if __name__ == "__main__" :
156
138
main ()
157
-
0 commit comments