From 5491266a850beb5687cf4dbc8a76c369f5990d0c Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Sun, 10 Dec 2023 18:35:59 -0500 Subject: [PATCH] sao: fix https --- titles/sao/config.py | 6 ++++++ titles/sao/index.py | 20 +++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/titles/sao/config.py b/titles/sao/config.py index 33d319b..dfae3c0 100644 --- a/titles/sao/config.py +++ b/titles/sao/config.py @@ -29,6 +29,12 @@ class SaoServerConfig: self.__config, "sao", "server", "auto_register", default=True ) + @property + def use_https(self) -> bool: + return CoreConfig.get_config_field( + self.__config, "sao", "server", "use_https", default=False + ) + class SaoCryptConfig: def __init__(self, parent_config: "SaoConfig"): self.__config = parent_config diff --git a/titles/sao/index.py b/titles/sao/index.py index 1607aa1..78d641e 100644 --- a/titles/sao/index.py +++ b/titles/sao/index.py @@ -76,13 +76,17 @@ class SaoServlet(BaseServlet): return True def get_allnet_info(self, game_code: str, game_ver: int, keychip: str) -> Tuple[str, str]: - if not self.core_cfg.server.is_using_proxy and Utils.get_title_port_ssl(self.core_cfg) != 443: - return ( - f"https://{self.core_cfg.title.hostname}:{Utils.get_title_port_ssl(self.core_cfg)}/", - f"{self.core_cfg.title.hostname}/", - ) + port_ssl = Utils.get_title_port_ssl(self.core_cfg) + port_normal = Utils.get_title_port(self.core_cfg) - return (f"http://{self.core_cfg.title.hostname}:{Utils.get_title_port(self.core_cfg)}/", "") + proto = "http" + port = f":{port_normal}" if not self.core_cfg.server.is_using_proxy and port_normal != 80 else "" + + if self.game_cfg.server.use_https: + proto = "https" + port = f":{port_ssl}" if not self.core_cfg.server.is_using_proxy and port_ssl != 443 else "" + + return (f"{proto}://{self.core_cfg.title.hostname}{port}/", "") def get_mucha_info(self, core_cfg: CoreConfig, cfg_dir: str) -> Tuple[bool, str]: if not self.game_cfg.server.enable: @@ -96,7 +100,9 @@ class SaoServlet(BaseServlet): iv = b"" req_raw = request.content.read() - sao_request = req_raw.hex() + if len(req_raw) < 40: + self.logger.warn(f"Malformed request to {endpoint} - {req_raw.hex()}") + return b"" req_header = SaoRequestHeader(req_raw) cmd_str = f"{req_header.cmd:04x}"