1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-10-12 02:49:02 +00:00
trezor-firmware/tools/codegen/gen_cert_bundle.py

48 lines
1.2 KiB
Python
Executable File

#!/usr/bin/python3
from pyblake2 import blake2s
import requests
CERTDATA_TXT = 'https://hg.mozilla.org/releases/mozilla-beta/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt'
def process_certdata(data):
certs = {}
lines = [x.strip() for x in data.split('\n')]
label = None
value = None
for line in lines:
if line == 'END':
if label is not None and value is not None:
certs[label] = bytes([int(x, 8) for x in value.split('\\')[1:]])
label = None
value = None
elif line.startswith('CKA_LABEL UTF8 '):
label = line.split('"')[1]
elif line == 'CKA_VALUE MULTILINE_OCTAL':
assert(label is not None)
value = ''
elif value is not None:
assert(label is not None)
value += line
return certs
def main():
r = requests.get(CERTDATA_TXT)
assert(r.status_code == 200)
certs = process_certdata(r.text)
print('cert_bundle = [')
for k, v in certs.items():
print(' # %s' % k)
print(' %s,' % blake2s(v).digest())
print(']')
if __name__ == '__main__':
main()