1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-11-09 22:06:47 +00:00

Added new style EncryptHeaderRequest. tclcheck.py completely working

again.
This commit is contained in:
Markus Birth 2018-02-10 03:30:10 +01:00
parent f470221989
commit 77e947f77b
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
4 changed files with 57 additions and 12 deletions

View File

@ -9,10 +9,11 @@ import os
import random import random
import sys import sys
import tcllib from tcllib import argparser
import tcllib.argparser
from tcllib.devices import Device from tcllib.devices import Device
from tcllib.requests import RequestRunner, CheckRequest, DownloadRequest, ChecksumRequest, ServerSelector, write_info_if_dumps_found from tcllib.requests import RequestRunner, CheckRequest, DownloadRequest, \
ChecksumRequest, EncryptHeaderRequest, ServerSelector, \
write_info_if_dumps_found
from tcllib.xmltools import pretty_xml from tcllib.xmltools import pretty_xml
@ -20,7 +21,7 @@ dpdesc = """
Checks for the latest FULL updates for the specified PRD number or for an OTA from the Checks for the latest FULL updates for the specified PRD number or for an OTA from the
version specified as fvver. version specified as fvver.
""" """
dp = tcllib.argparser.DefaultParser(__file__, dpdesc) dp = argparser.DefaultParser(__file__, dpdesc)
dp.add_argument("prd", nargs=1, help="CU Reference #, e.g. PRD-63117-011") dp.add_argument("prd", nargs=1, help="CU Reference #, e.g. PRD-63117-011")
dp.add_argument("fvver", nargs="?", help="Firmware version to check for OTA updates, e.g. AAM481 (omit to run FULL check)", default="AAA000") dp.add_argument("fvver", nargs="?", help="Firmware version to check for OTA updates, e.g. AAM481 (omit to run FULL check)", default="AAA000")
dp.add_argument("-i", "--imei", help="use specified IMEI instead of default", type=str) dp.add_argument("-i", "--imei", help="use specified IMEI instead of default", type=str)
@ -88,9 +89,9 @@ dlrres = dlr.get_result()
print(dlrres.pretty_xml()) print(dlrres.pretty_xml())
if dlrres.encslaves: if dlrres.encslaves:
cksrunner = RequestRunner(ServerSelector(dlrres.encslaves), https=False) encrunner = RequestRunner(ServerSelector(dlrres.encslaves), https=False)
cks = ChecksumRequest(dlrres.fileurl, dlrres.fileurl) cks = ChecksumRequest(dlrres.fileurl, dlrres.fileurl)
cksrunner.run(cks) encrunner.run(cks)
if not cks.success: if not cks.success:
print("{}".format(cks.error)) print("{}".format(cks.error))
sys.exit(4) sys.exit(4)
@ -104,17 +105,22 @@ for s in dlrres.s3_slaves:
print("http://{}{}".format(s, dlrres.s3_fileurl)) print("http://{}{}".format(s, dlrres.s3_fileurl))
if dev.mode == dev.MODE_STATES["FULL"]: if dev.mode == dev.MODE_STATES["FULL"]:
header = fc.do_encrypt_header(random.choice(encslaves), fileurl) hdr = EncryptHeaderRequest(dlrres.fileurl)
headname = "header_{}.bin".format(tv) encrunner.run(hdr)
if not hdr.success:
print("{}".format(hdr.error))
sys.exit(5)
hdrres = hdr.get_result()
headname = "header_{}.bin".format(chkres.tvver)
headdir = "headers" headdir = "headers"
if not os.path.exists(headdir): if not os.path.exists(headdir):
os.makedirs(headdir) os.makedirs(headdir)
if len(header) == 4194320: if len(hdrres.rawdata) == 4194320:
# TODO: Check sha1sum # TODO: Check sha1sum
print("Header length check passed. Writing to {}.".format(headname)) print("Header length check passed. Writing to {}.".format(headname))
with open(os.path.join(headdir, headname), "wb") as f: with open(os.path.join(headdir, headname), "wb") as f:
f.write(header) f.write(hdrres.rawdata)
else: else:
print("Header length invalid ({}).".format(len(header))) print("Header length invalid ({}).".format(len(hdrres.rawdata)))
tcllib.FotaCheck.write_info_if_dumps_found() write_info_if_dumps_found()

View File

@ -3,6 +3,7 @@
from .checkrequest import CheckRequest from .checkrequest import CheckRequest
from .downloadrequest import DownloadRequest from .downloadrequest import DownloadRequest
from .checksumrequest import ChecksumRequest from .checksumrequest import ChecksumRequest
from .encryptheaderrequest import EncryptHeaderRequest
from .runner import * from .runner import *
from .serverselector import * from .serverselector import *
from .dumpmgr import write_info_if_dumps_found from .dumpmgr import write_info_if_dumps_found

View File

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
from collections import OrderedDict
from .. import credentials, devices
from .tclrequest import TclRequest
from .tclresult import EncryptHeaderResult
class EncryptHeaderRequest(TclRequest):
def __init__(self, file_uri):
super().__init__()
# NOTE: THIS HAS TO BE RUN ON AN ENCSLAVE
self.uri = "/encrypt_header.php"
self.rawmode = True
self.method = "POST"
self.file_uri = file_uri
def get_headers(self):
return {"User-Agent": "tcl"}
def get_params(self):
params = OrderedDict()
params.update(credentials.get_creds2())
params["address"] = bytes(self.file_uri, "utf-8")
return params
def is_done(self, http_status: int, contents: str) -> bool:
# Expect "HTTP 206 Partial Content" response
if http_status == 206:
self.result = EncryptHeaderResult(contents)
self.success = True
return True
self.error = "HTTP {}".format(http_status)
self.success = False
return True

View File

@ -62,3 +62,7 @@ class ChecksumResult(TclResult):
self.sha1_enc_footer = file.find("ENCRYPT_FOOTER").text self.sha1_enc_footer = file.find("ENCRYPT_FOOTER").text
self.sha1_footer = file.find("FOOTER").text self.sha1_footer = file.find("FOOTER").text
self.sha1_body = file.find("BODY").text self.sha1_body = file.find("BODY").text
class EncryptHeaderResult(TclResult):
def __init__(self, contents: str):
self.rawdata = contents