|
|
|
@ -172,18 +172,19 @@ class BootloaderImage(BinImage):
|
|
|
|
|
class VendorHeader(object):
|
|
|
|
|
|
|
|
|
|
def __init__(self, data):
|
|
|
|
|
header = struct.unpack('<4sIIBBBB', data[:16])
|
|
|
|
|
header = struct.unpack('<4sIIBBBBB', data[:17])
|
|
|
|
|
self.magic, \
|
|
|
|
|
self.hdrlen, \
|
|
|
|
|
self.expiry, \
|
|
|
|
|
self.vmajor, \
|
|
|
|
|
self.vminor, \
|
|
|
|
|
self.vsig_m, \
|
|
|
|
|
self.vsig_n = header
|
|
|
|
|
self.vsig_n, \
|
|
|
|
|
self.vtrust = header
|
|
|
|
|
assert self.magic == b'TRZV'
|
|
|
|
|
assert self.vsig_m > 0 and self.vsig_m <= self.vsig_n
|
|
|
|
|
assert self.vsig_n > 0 and self.vsig_n <= 8
|
|
|
|
|
p = 16
|
|
|
|
|
p = 32
|
|
|
|
|
self.vpub = []
|
|
|
|
|
for _ in range(self.vsig_n):
|
|
|
|
|
self.vpub.append(data[p:p + 32])
|
|
|
|
@ -200,7 +201,7 @@ class VendorHeader(object):
|
|
|
|
|
self.sigmask = data[p]
|
|
|
|
|
p += 1
|
|
|
|
|
self.sig = data[p:p + 64]
|
|
|
|
|
assert len(data) == 4 + 4 + 4 + 1 + 1 + 1 + 1 + \
|
|
|
|
|
assert len(data) == 4 + 4 + 4 + 1 + 1 + 1 + 1 + 1 + 15 + \
|
|
|
|
|
32 * len(self.vpub) + \
|
|
|
|
|
1 + self.vstr_len + vstr_pad + \
|
|
|
|
|
self.vimg_len + \
|
|
|
|
@ -213,6 +214,7 @@ class VendorHeader(object):
|
|
|
|
|
print(' * expiry :', self.expiry)
|
|
|
|
|
print(' * version : %d.%d' % (self.vmajor, self.vminor))
|
|
|
|
|
print(' * scheme : %d out of %d' % (self.vsig_m, self.vsig_n))
|
|
|
|
|
print(' * trust :', self.vtrust)
|
|
|
|
|
for i in range(self.vsig_n):
|
|
|
|
|
print(' * vpub #%d :' % (i + 1), binascii.hexlify(self.vpub[i]).decode('ascii'))
|
|
|
|
|
print(' * vstr :', self.vstr.decode('ascii'))
|
|
|
|
@ -221,10 +223,11 @@ class VendorHeader(object):
|
|
|
|
|
print(' * sig :', binascii.hexlify(self.sig).decode('ascii'))
|
|
|
|
|
|
|
|
|
|
def serialize_header(self, sig=True):
|
|
|
|
|
header = struct.pack('<4sIIBBBB',
|
|
|
|
|
header = struct.pack('<4sIIBBBBB',
|
|
|
|
|
self.magic, self.hdrlen, self.expiry,
|
|
|
|
|
self.vmajor, self.vminor,
|
|
|
|
|
self.vsig_m, self.vsig_n)
|
|
|
|
|
self.vsig_m, self.vsig_n, self.vtrust)
|
|
|
|
|
header += 15 * b'\x00'
|
|
|
|
|
for i in range(self.vsig_n):
|
|
|
|
|
header += self.vpub[i]
|
|
|
|
|
header += struct.pack('<B', self.vstr_len) + self.vstr
|
|
|
|
|