-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_secrets.py
33 lines (26 loc) · 983 Bytes
/
gen_secrets.py
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
import sys
import time
SECRET_CERTIFICATE_MAX_LEN = 512
cert_path, = sys.argv[1:]
with open(cert_path, 'rb') as f:
data = f.read()
time_str = time.strftime('%c')
print('// Auto-generated by %s at %s' % (sys.argv[0], time_str))
print('''
#include <stddef.h>
#include <stdint.h>
#ifdef __APPLE__
# define SECRET_GLOBAL __attribute__((section("__DATA,__secret")))
# define SECRET_GLOBAL_RO __attribute__((section("__TEXT,__secret")))
#else
# define SECRET_GLOBAL __attribute__((section(".data.secret")))
# define SECRET_GLOBAL_RO __attribute__((section(".rodata.secret")))
#endif
''')
print('const uint8_t secret_certificate[%d] SECRET_GLOBAL_RO = {' % SECRET_CERTIFICATE_MAX_LEN)
N = 16
for i in range(0, SECRET_CERTIFICATE_MAX_LEN, N):
line = [data[j] if j < len(data) else 0 for j in range(i, i + N)]
print(' %s,' % ', '.join('0x%02x' % b for b in line))
print('};')
print('const size_t secret_certificate_len SECRET_GLOBAL_RO = %d;' % len(data))