2018-02-03 20:40:17 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-02-03 00:36:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-02-03 20:40:17 +00:00
|
|
|
# pylint: disable=C0111,C0326,C0103
|
|
|
|
|
2018-02-03 21:25:26 +00:00
|
|
|
"""Tools to interface with TCL's encrypted header API."""
|
|
|
|
|
2018-02-05 15:38:15 +00:00
|
|
|
from . import credentials
|
|
|
|
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2018-02-03 12:46:17 +00:00
|
|
|
class TclEncHeaderMixin:
|
2018-02-03 21:25:26 +00:00
|
|
|
"""A mixin component for TCL's encrypted header API.."""
|
2018-02-06 18:27:36 +00:00
|
|
|
|
2018-02-03 00:36:08 +00:00
|
|
|
def do_encrypt_header(self, encslave, address):
|
2018-02-03 21:25:26 +00:00
|
|
|
"""Perform encrypted header request with given parameters."""
|
2018-02-05 15:38:15 +00:00
|
|
|
params = credentials.get_creds2()
|
2018-02-03 00:36:08 +00:00
|
|
|
params[b"address"] = bytes(address, "utf-8")
|
|
|
|
url = "http://" + encslave + "/encrypt_header.php"
|
|
|
|
req = self.sess.post(url, data=params, verify=False)
|
|
|
|
# Expect "HTTP 206 Partial Content" response
|
|
|
|
if req.status_code == 206:
|
|
|
|
return req.content
|
|
|
|
else:
|
|
|
|
print("ENCRYPT: " + repr(req))
|
|
|
|
print(repr(req.headers))
|
|
|
|
print(repr(req.text))
|
|
|
|
raise SystemExit
|