1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-11-10 06:16:46 +00:00
tcl_ota_check/tcllib/requests/encryptheaderrequest.py

46 lines
1.3 KiB
Python
Raw Normal View History

2018-02-11 01:38:38 +00:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2018-02-11 01:38:38 +00:00
"""Generic encrypted header download request."""
from collections import OrderedDict
2018-02-11 01:38:38 +00:00
from .. import credentials
from .tclrequest import TclRequest
from .tclresult import EncryptHeaderResult
2018-02-11 01:38:38 +00:00
class EncryptHeaderRequest(TclRequest):
2018-02-11 01:38:38 +00:00
"""Generic encrypted header download request."""
def __init__(self, file_uri):
2018-02-11 01:38:38 +00:00
"""Populate variables."""
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):
2018-02-11 01:38:38 +00:00
"""Return request headers."""
return {"User-Agent": "tcl"}
def get_params(self):
2018-02-11 01:38:38 +00:00
"""Return request parameters."""
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:
2018-02-11 01:38:38 +00:00
"""Handle request result."""
# 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