Monorail Project: project-zero Issues People Development process History Sign in
New issue
Advanced search Search tips

Issue 1239 attachment: extract_mclf_pubkeys.py (1.6 KB)

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys, os, struct

def main():
if len(sys.argv) != 2:
print "USAGE: %s <TRUSTLET_DIRECTORY>" % sys.argv[0]
return
trustlet_dir = sys.argv[1]

moduli = set()
moduli_map = {}
for root, dirs, files in os.walk(trustlet_dir):
for name in files:
if not (name.endswith(".tlbin") or name.endswith(".drbin") or name.endswith(".tabin")):
continue

print "----------"
print "trustlet %s" % name
print "dir %s" % root
print

#Reading the length fields from the header
trustlet = open(os.path.join(root, name), "rb").read()
text_length = struct.unpack("<I", trustlet[0x34:0x38])[0]
data_length = struct.unpack("<I", trustlet[0x3C:0x40])[0]
off = text_length + data_length

if off + 4 >= len(trustlet):
print "Invalid offset, skipping."
continue

modulus_length = struct.unpack("<I", trustlet[off:off+4])[0]
modulus = trustlet[off+4:off+4+modulus_length]
moduli.add(modulus)
print int(modulus.encode("hex"), 16)

if modulus not in moduli_map:
moduli_map[modulus] = set()
moduli_map[modulus].add(root)

print "------------------"
print "moduli:"
for N in moduli:
print N.encode("hex")

print "------------------"
for N in moduli_map:
print "modulus: %s -> %s" % (N.encode("hex"), moduli_map[N])

if __name__ == "__main__":
main()