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

Turned credentials into namespaced methods.

This commit is contained in:
Markus Birth 2018-02-05 16:38:15 +01:00
parent 7332846805
commit 648e89f9be
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
4 changed files with 22 additions and 25 deletions

View File

@ -9,7 +9,7 @@ import enum
import requests import requests
from . import (credentials, devlist, dumpmgr, servervote, tclcheck, from . import (dumpmgr, servervote, tclcheck,
tclchecksum, tclencheader, tclrequest, xmltools) tclchecksum, tclencheader, tclrequest, xmltools)
@ -24,7 +24,6 @@ class FotaCheck(
tclchecksum.TclChecksumMixin, tclchecksum.TclChecksumMixin,
tclencheader.TclEncHeaderMixin, tclencheader.TclEncHeaderMixin,
servervote.ServerVoteMixin, servervote.ServerVoteMixin,
credentials.CredentialsMixin,
dumpmgr.DumpMgrMixin dumpmgr.DumpMgrMixin
): ):
"""Main API handler class.""" """Main API handler class."""

View File

@ -8,24 +8,20 @@
import base64 import base64
class CredentialsMixin: def get_creds():
"""A mixin component to provide authentication.""" """Return main authentication."""
@staticmethod creds = {
def get_creds(): b"YWNjb3VudA==": b"emhlbmdodWEuZ2Fv",
"""Return main authentication.""" b"cGFzc3dvcmQ=": b"cWFydUQ0b2s=",
creds = { }
b"YWNjb3VudA==": b"emhlbmdodWEuZ2Fv", params = {base64.b64decode(key): base64.b64decode(val) for key, val in creds.items()}
b"cGFzc3dvcmQ=": b"cWFydUQ0b2s=", return params
}
params = {base64.b64decode(key): base64.b64decode(val) for key, val in creds.items()}
return params
@staticmethod def get_creds2():
def get_creds2(): """Return alternate authentication."""
"""Return alternate authentication.""" creds = {
creds = { b"YWNjb3VudA==": b"VGVsZUV4dFRlc3Q=",
b"YWNjb3VudA==": b"VGVsZUV4dFRlc3Q=", b"cGFzc3dvcmQ=": b"dDA1MjM=",
b"cGFzc3dvcmQ=": b"dDA1MjM=", }
} params = {base64.b64decode(key): base64.b64decode(val) for key, val in creds.items()}
params = {base64.b64decode(key): base64.b64decode(val) for key, val in creds.items()} return params
return params

View File

@ -8,14 +8,14 @@
import json import json
from defusedxml import ElementTree from defusedxml import ElementTree
from . import credentials
class TclChecksumMixin: class TclChecksumMixin:
"""A mixin component for TCL's checksum API.""" """A mixin component for TCL's checksum API."""
def do_checksum(self, encslave, address, uri): def do_checksum(self, encslave, address, uri):
"""Perform checksum request with given parameters.""" """Perform checksum request with given parameters."""
url = "http://" + encslave + "/checksum.php" url = "http://" + encslave + "/checksum.php"
params = self.get_creds2() params = credentials.get_creds2()
payload = {address: uri} payload = {address: uri}
payload_json = json.dumps(payload) payload_json = json.dumps(payload)

View File

@ -5,12 +5,14 @@
"""Tools to interface with TCL's encrypted header API.""" """Tools to interface with TCL's encrypted header API."""
from . import credentials
class TclEncHeaderMixin: class TclEncHeaderMixin:
"""A mixin component for TCL's encrypted header API..""" """A mixin component for TCL's encrypted header API.."""
def do_encrypt_header(self, encslave, address): def do_encrypt_header(self, encslave, address):
"""Perform encrypted header request with given parameters.""" """Perform encrypted header request with given parameters."""
params = self.get_creds2() params = credentials.get_creds2()
params[b"address"] = bytes(address, "utf-8") params[b"address"] = bytes(address, "utf-8")
url = "http://" + encslave + "/encrypt_header.php" url = "http://" + encslave + "/encrypt_header.php"
req = self.sess.post(url, data=params, verify=False) req = self.sess.post(url, data=params, verify=False)