1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
|
3
|
|
|
import binascii |
4
|
|
|
import hashlib |
5
|
|
|
import random |
6
|
|
|
import time |
7
|
|
|
from math import floor |
8
|
|
|
import zlib |
9
|
|
|
from collections import OrderedDict |
10
|
|
|
from defusedxml import ElementTree |
11
|
|
|
|
12
|
|
|
''' |
13
|
|
|
private HashMap<String, String> buildDownloadUrisParams(UpdatePackageInfo updatePackageInfo) { |
|
|
|
|
14
|
|
|
FotaLog.m28v(TAG, "doAfterCheck"); |
15
|
|
|
String salt = FotaUtil.salt(); |
16
|
|
|
HashMap linkedHashMap = new LinkedHashMap(); |
17
|
|
|
linkedHashMap.put("id", this.internalBuilder.getParam("id")); |
18
|
|
|
linkedHashMap.put("salt", salt); |
19
|
|
|
linkedHashMap.put("curef", updatePackageInfo.mCuref); |
20
|
|
|
linkedHashMap.put("fv", updatePackageInfo.mFv); |
21
|
|
|
linkedHashMap.put("tv", updatePackageInfo.mTv); |
22
|
|
|
linkedHashMap.put("type", "Firmware"); |
23
|
|
|
linkedHashMap.put("fw_id", updatePackageInfo.mFirmwareId); |
24
|
|
|
linkedHashMap.put("mode", "2"); |
25
|
|
|
linkedHashMap.put("vk", generateVk2((LinkedHashMap) linkedHashMap.clone())); |
|
|
|
|
26
|
|
|
linkedHashMap.put("cltp", "10"); |
27
|
|
|
linkedHashMap.put("cktp", this.internalBuilder.getParam("cktp")); |
28
|
|
|
linkedHashMap.put("rtd", this.internalBuilder.getParam("rtd")); |
29
|
|
|
linkedHashMap.put("chnl", this.internalBuilder.getParam("chnl")); |
30
|
|
|
return linkedHashMap; |
31
|
|
|
} |
32
|
|
|
''' |
|
|
|
|
33
|
|
|
|
34
|
|
|
class TclRequestMixin: |
|
|
|
|
35
|
|
|
@staticmethod |
36
|
|
|
def get_salt(): |
|
|
|
|
37
|
|
|
millis = floor(time.time() * 1000) |
38
|
|
|
tail = "{:06d}".format(random.randint(0, 999999)) |
39
|
|
|
return "{}{}".format(str(millis), tail) |
40
|
|
|
|
41
|
|
|
def get_vk2(self, params_dict, cltp): |
|
|
|
|
42
|
|
|
params_dict["cltp"] = cltp |
43
|
|
|
query = "" |
44
|
|
|
for k, v in params_dict.items(): |
|
|
|
|
45
|
|
|
if len(query) > 0: |
|
|
|
|
46
|
|
|
query += "&" |
47
|
|
|
query += k + "=" + str(v) |
48
|
|
|
vdk = zlib.decompress(binascii.a2b_base64(self.VDKEY)) |
49
|
|
|
query += vdk.decode("utf-8") |
50
|
|
|
engine = hashlib.sha1() |
51
|
|
|
engine.update(bytes(query, "utf-8")) |
52
|
|
|
hexhash = engine.hexdigest() |
53
|
|
|
return hexhash |
54
|
|
|
|
55
|
|
|
def do_request(self, curef, fv, tv, fw_id): |
|
|
|
|
56
|
|
|
url = "https://" + self.g2master + "/download_request.php" |
57
|
|
|
params = OrderedDict() |
58
|
|
|
params["id"] = self.serid |
|
|
|
|
59
|
|
|
params["salt"] = self.get_salt() |
|
|
|
|
60
|
|
|
params["curef"] = curef |
61
|
|
|
params["fv"] = fv |
|
|
|
|
62
|
|
|
params["tv"] = tv |
|
|
|
|
63
|
|
|
params["type"] = self.ftype |
|
|
|
|
64
|
|
|
params["fw_id"] = fw_id |
65
|
|
|
params["mode"] = self.mode.value |
|
|
|
|
66
|
|
|
params["vk"] = self.get_vk2(params, self.cltp.value) |
|
|
|
|
67
|
|
|
params["cltp"] = self.cltp.value |
|
|
|
|
68
|
|
|
params["cktp"] = self.cktp.value |
|
|
|
|
69
|
|
|
params["rtd"] = self.rtd.value |
|
|
|
|
70
|
|
|
if self.mode == self.MODE.FULL: |
71
|
|
|
params["foot"] = 1 |
|
|
|
|
72
|
|
|
params["chnl"] = self.chnl.value |
|
|
|
|
73
|
|
|
|
74
|
|
|
#print(repr(dict(params))) |
75
|
|
|
req = self.sess.post(url, data=params) |
76
|
|
|
if req.status_code == 200: |
77
|
|
|
req.encoding = "utf-8" # Force encoding as server doesn't give one |
|
|
|
|
78
|
|
|
self.write_dump(req.text) |
79
|
|
|
return req.text |
80
|
|
|
else: |
81
|
|
|
print("REQUEST: " + repr(req)) |
82
|
|
|
print(repr(req.headers)) |
83
|
|
|
print(repr(req.text)) |
84
|
|
|
raise SystemExit |
85
|
|
|
|
86
|
|
|
@staticmethod |
87
|
|
|
def parse_request(xmlstr): |
|
|
|
|
88
|
|
|
root = ElementTree.fromstring(xmlstr) |
89
|
|
|
file = root.find("FILE_LIST").find("FILE") |
90
|
|
|
fileid = file.find("FILE_ID").text |
|
|
|
|
91
|
|
|
fileurl = file.find("DOWNLOAD_URL").text |
92
|
|
|
s3_fileurl_node = file.find("S3_DOWNLOAD_URL") |
93
|
|
|
s3_fileurl = "" |
94
|
|
|
if s3_fileurl_node: |
95
|
|
|
s3_fileurl = s3_fileurl_node.text |
96
|
|
|
slave_list = root.find("SLAVE_LIST").findall("SLAVE") |
97
|
|
|
enc_list = root.find("SLAVE_LIST").findall("ENCRYPT_SLAVE") |
98
|
|
|
s3_slave_list = root.find("SLAVE_LIST").findall("S3_SLAVE") |
99
|
|
|
slaves = [s.text for s in slave_list] |
100
|
|
|
encslaves = [s.text for s in enc_list] |
101
|
|
|
s3_slaves = [s.text for s in s3_slave_list] |
102
|
|
|
return fileid, fileurl, slaves, encslaves, s3_fileurl, s3_slaves |
103
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.