-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
check_releases.py
executable file
·190 lines (152 loc) · 5.56 KB
/
check_releases.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python3
import os
import json
import struct
def check_bridge():
patterns = [
"index.html",
"trezor-bridge-%(version)s-1.i386.rpm",
"trezor-bridge-%(version)s-1.x86_64.rpm",
"trezor-bridge_%(version)s_amd64.deb",
"trezor-bridge_%(version)s_i386.deb",
"trezor-bridge-%(version)s-win32-install.exe",
"trezor-bridge-%(version)s-win32-install.exe.asc",
"trezor-bridge-%(version)s.pkg",
"trezor-bridge-%(version)s.pkg.asc",
]
print("Checking Bridge data:")
v = open("bridge/latest.txt", "r").read().strip()
print("* expected latest version: %s" % v)
if not os.path.isdir(os.path.join("bridge", v)):
return False
ok = True
print("* checking files for version: %s" % v)
for p in patterns:
expected = p % {"version": v}
fname = os.path.join("bridge", v, expected)
print(" * %s ... " % fname, end="")
if os.path.isfile(fname):
print("OK")
else:
ok = False
print("MISSING")
print()
return ok
def check_firmware(model, bitcoin_only=False):
if model not in ["1", "2", "t1b1", "t2t1", "t2b1"]:
raise ValueError("Unknown model: %s" % model)
print("Checking Firmware (model %s) data:" % model)
ok = True
releases = json.load(open("firmware/%s/releases.json" % model, "r"))
# Find out the latest firmware release
latest = [0, 0, 0]
for r in releases:
latest = max(latest, r["version"])
print("* expected latest version: %s" % ".".join(str(x) for x in latest))
for r in releases:
# Check only latest firmware, others may not be available
if r["version"] != latest:
continue
firmware = r["url_bitcoinonly"] if bitcoin_only else r["url"]
version = ".".join([str(x) for x in r["version"]])
if bitcoin_only:
if not "changelog_bitcoinonly" in r:
print("Missing changelog_bitcoinonly")
ok = False
continue
else:
if not "changelog" in r:
print("Missing changelog")
ok = False
continue
if version not in firmware:
print("Missing '%s' in '%s'" % (version, firmware))
ok = False
continue
print(" * %s ... " % firmware, end="")
if not os.path.exists(firmware[len("data/") :]):
print("MISSING")
ok = False
continue
else:
data = open(firmware[len("data/") :], "rb").read()
if model == "1" or model == "t1b1":
legacy_header = r["version"] < [1, 12, 0]
start = b"TRZR" if legacy_header else b"TRZF"
elif model == "2" or model == "t2t1" or model == "t2b1":
start = b"TRZV"
if not data.startswith(start):
print("WRONG HEADER")
ok = False
continue
if model == "1" or model == "t1b1":
if legacy_header:
hdrlen = 256
codelen = struct.unpack("<I", data[4:8])
codelen = codelen[0]
else:
hdrlen = 1024
codelen = struct.unpack("<I", data[12:16])
codelen = codelen[0]
if hdrlen + codelen != len(data):
print(
"INVALID SIZE (is %d bytes, should be %d bytes)"
% (hdrlen + codelen, len(data))
)
ok = False
continue
elif len(data) > 1024 * 1024 - 32 * 1024: # Firmware - header - signatures
print("TOO BIG")
ok = False
continue
else:
print("OK")
if model == "2" or model == "t2t1":
vendorlen = struct.unpack("<I", data[4:8])[0]
headerlen = struct.unpack("<I", data[4 + vendorlen : 8 + vendorlen])[0]
codelen = struct.unpack("<I", data[12 + vendorlen : 16 + vendorlen])[0]
expected_len = codelen + vendorlen + headerlen
if expected_len != len(data):
print(
"INVALID SIZE (is %d bytes, should be %d bytes)"
% (expected_len, len(data))
)
ok = False
continue
else:
print("OK")
if model == "t2b1":
vendorlen = struct.unpack("<I", data[4:8])[0]
headerlen = struct.unpack("<I", data[4 + vendorlen : 8 + vendorlen])[0]
codelen = struct.unpack("<I", data[12 + vendorlen : 16 + vendorlen])[0]
expected_len = codelen + vendorlen + headerlen
if expected_len != len(data):
print(
"INVALID SIZE (is %d bytes, should be %d bytes)"
% (expected_len, len(data))
)
ok = False
continue
else:
print("OK")
print()
return ok
if __name__ == "__main__":
ok = True
ok &= check_bridge()
ok &= check_firmware("1")
ok &= check_firmware("t1b1")
ok &= check_firmware("1", bitcoin_only=True)
ok &= check_firmware("t1b1", bitcoin_only=True)
ok &= check_firmware("2")
ok &= check_firmware("t2t1")
ok &= check_firmware("2", bitcoin_only=True)
ok &= check_firmware("t2t1", bitcoin_only=True)
ok &= check_firmware("t2b1")
ok &= check_firmware("t2b1", bitcoin_only=True)
if ok:
print("EVERYTHING OK")
exit(0)
else:
print("PROBLEMS FOUND")
exit(1)