1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-09-19 22:33:25 +01:00

Rename encrypt_header to do_encrypt_header. Changed signature. Also

write header.bin since we already received it.
This commit is contained in:
Markus Birth 2017-09-01 14:07:06 +02:00
parent 525b2b4256
commit 98daf57086
3 changed files with 13 additions and 7 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/__pycache__/
/.nvimlog
/header.bin

View File

@ -37,4 +37,10 @@ for s in slaves:
print("http://{}{}".format(s, fileurl))
if fc.mode == fc.MODE_FULL:
print(fc.encrypt_header(fileurl, random.choice(encslaves)))
header = fc.do_encrypt_header(random.choice(encslaves), fileurl)
if len(header) == 4194320:
print("Header length check passed. Writing to header.bin.")
with open("header.bin", "wb") as f:
f.write(header)
else:
print("Header length invalid ({}).".format(len(header)))

View File

@ -188,17 +188,14 @@ class FotaCheck:
encslaves = [s.text for s in enc_list]
return fileid, fileurl, slaves, encslaves
def encrypt_header(self, address, encslave):
def do_encrypt_header(self, encslave, address):
params = self.get_creds()
params[b"address"] = bytes(address, "utf-8")
url = "https://" + encslave + "/encrypt_header.php"
req = self.sess.post(url, data=params, verify=False)
# Expect "HTTP 206 Partial Content" response
if req.status_code == 206: # partial
#return req.content
contentlength = int(req.headers["Content-Length"])
sentinel = "\nHEADER FOUND" if contentlength == 4194320 else "\nNO HEADER FOUND"
return sentinel
if req.status_code == 206:
return req.content
else:
print("ENCRYPT: " + repr(req))
print(repr(req.headers))