| Total Complexity | 5 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | #!/usr/bin/env python3 |
||
| 2 | # -*- coding: utf-8 -*- |
||
| 3 | |||
| 4 | """Generic encrypted header download request.""" |
||
| 5 | |||
| 6 | from collections import OrderedDict |
||
| 7 | |||
| 8 | from .. import credentials |
||
| 9 | from .tclrequest import TclRequest |
||
| 10 | from .tclresult import EncryptHeaderResult |
||
| 11 | |||
| 12 | |||
| 13 | class EncryptHeaderRequest(TclRequest): |
||
|
|
|||
| 14 | """Generic encrypted header download request.""" |
||
| 15 | |||
| 16 | def __init__(self, file_uri): |
||
| 17 | """Populate variables.""" |
||
| 18 | super().__init__() |
||
| 19 | # NOTE: THIS HAS TO BE RUN ON AN ENCSLAVE |
||
| 20 | self.uri = "/encrypt_header.php" |
||
| 21 | self.rawmode = True |
||
| 22 | self.method = "POST" |
||
| 23 | self.file_uri = file_uri |
||
| 24 | |||
| 25 | def get_headers(self): |
||
| 26 | """Return request headers.""" |
||
| 27 | return {"User-Agent": "tcl"} |
||
| 28 | |||
| 29 | def get_params(self): |
||
| 30 | """Return request parameters.""" |
||
| 31 | params = OrderedDict() |
||
| 32 | params.update(credentials.get_creds2()) |
||
| 33 | params["address"] = bytes(self.file_uri, "utf-8") |
||
| 34 | return params |
||
| 35 | |||
| 36 | def is_done(self, http_status: int, contents: str) -> bool: |
||
| 37 | """Handle request result.""" |
||
| 38 | # Expect "HTTP 206 Partial Content" response |
||
| 39 | if http_status == 206: |
||
| 40 | self.result = EncryptHeaderResult(contents) |
||
| 41 | self.success = True |
||
| 42 | return True |
||
| 43 | self.error = "HTTP {}".format(http_status) |
||
| 44 | self.success = False |
||
| 45 | return True |
||
| 46 |