30
30
import re
31
31
import struct
32
32
import sys
33
+ import textwrap
33
34
from io import open
34
35
35
36
try :
@@ -217,6 +218,15 @@ def main():
217
218
help = "Path to CSV-file where the second columns contains the name of the certificates \
218
219
that should be included from cacrt_all.pem" ,
219
220
)
221
+ parser .add_argument (
222
+ "--asm" ,
223
+ "-S" ,
224
+ action = "store_true" ,
225
+ default = False ,
226
+ help = "Output an asm file for use with gas, rather than a binary file" ,
227
+ )
228
+ parser .add_argument ("--symbol" , help = "The symbol to define" , default = "x509_crt_bundle" )
229
+ parser .add_argument ("--output" , "-o" , help = "The output file" , default = None )
220
230
221
231
args = parser .parse_args ()
222
232
@@ -239,8 +249,45 @@ def main():
239
249
240
250
crt_bundle = bundle .create_bundle ()
241
251
242
- with open (ca_bundle_bin_file , "wb" ) as f :
243
- f .write (crt_bundle )
252
+ if args .asm :
253
+ symbol = args .symbol
254
+ filename = args .output or (ca_bundle_bin_file + ".S" )
255
+ with open (filename , "w" ) as f :
256
+ print (
257
+ textwrap .dedent (
258
+ f"""\
259
+ // Generated from { " " .join (args .input )} with { len (bundle .certificates )} certificates
260
+ .data
261
+ .section .rodata.embedded
262
+
263
+ .global { symbol }
264
+ .global _binary_{ symbol } _start
265
+ .global _binary_{ symbol } _end
266
+ { symbol } :
267
+ _binary_{ symbol } _start:
268
+ """
269
+ ),
270
+ file = f ,
271
+ )
272
+ for i in range (0 , len (crt_bundle ), 16 ):
273
+ chunk = crt_bundle [i : i + 16 ]
274
+ formatted = ", " .join (f"0x{ byte :02x} " for byte in chunk )
275
+ print (f".byte { formatted } " , file = f )
276
+ print (
277
+ textwrap .dedent (
278
+ f"""\
279
+ _binary_{ symbol } _end:
280
+
281
+ { symbol } _length:
282
+ .word { len (crt_bundle )}
283
+ """
284
+ ),
285
+ file = f ,
286
+ )
287
+ else :
288
+ filename = args .output or ca_bundle_bin_file
289
+ with open (filename , "wb" ) as f :
290
+ f .write (crt_bundle )
244
291
245
292
246
293
if __name__ == "__main__" :
0 commit comments