fix(shell): 补齐 WinHTTP 的 WINHTTP_FLAG_SECURE,https api 的请求此前全部走明文
现象:应用配了 login_mode=card,加壳后的客户端仍然显示「账号 + 密码 + 注册」
两个 tab、没有卡密输入框、没有充值入口;应用名却显示正确。
根因:壳里所有 WinHttpOpenRequest 的 dwFlags 都传 0。对 https 的 api,
WinHTTP 会用明文 HTTP 去连 443 端口,服务端(Caddy)直接回
400 The plain HTTP request was sent to HTTPS port。
而 api_get_sibling 的成功判据是 ok = (total > 0),400 的 HTML 错误页
同样算「成功」,于是 FetchAppInfo 继续往下走,对 HTML 做 json_str 解析,
全部失败,各个配置项静默回落到默认值 —— g_loginMode 停在 account、
g_billing 读不到,界面就是默认的账号登录。因为静默,所以查不出错。
应用名显示正确是另一条路径:json_str(g_cfg, "name", ...) 从 .vfy 里的
cfg 读,跟 /info 无关,所以它好着,掩盖了 /info 整体失败。
实测对比(同一 URL,wine + WinHTTP):
dwFlags=0 → status=400 <html>400 The plain HTTP request was sent to HTTPS port
dwFlags=SECURE → status=200 {"code":200,"data":{"allowed_login_types":["card"],...}}
修复:
- shell9_v6.cpp(DuiLib 全部 7 套皮肤,64/32 位)5 处 WinHttpOpenRequest
补 https ? WINHTTP_FLAG_SECURE : 0
- classic shell5.cpp / shell6.cpp 的登录另外还有 port 写死 80 的问题,
一并按 scheme 判断改成 443,并补 SECURE 标志
- 重编 shell64_dui.bin / shell32_dui.bin 并更新 embed assets
This commit is contained in:
@@ -530,6 +530,8 @@ static int api_call(const char *suffix, const char *body, char *resp, int cap) {
|
||||
snprintf(full, sizeof(full), "%s", g_api);
|
||||
char *p = strstr(full, "://");
|
||||
if (!p) return 0;
|
||||
// 判断 scheme:p 指向 "://" 的冒号,p[-1] 就是 http/https 的最后一个字母
|
||||
bool https = (p > full && p[-1] == 's');
|
||||
p += 3;
|
||||
char *slash = strchr(p, '/');
|
||||
char dir[400] = {0};
|
||||
@@ -541,7 +543,9 @@ static int api_call(const char *suffix, const char *body, char *resp, int cap) {
|
||||
}
|
||||
char host[256];
|
||||
snprintf(host, sizeof(host), "%s", p);
|
||||
unsigned short port = 80;
|
||||
// 原来写死 80:https 的 api 会被当成明文 HTTP 发到 443,服务端直接回
|
||||
// 400 "The plain HTTP request was sent to HTTPS port",登录恒失败。
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
char path[512];
|
||||
@@ -553,7 +557,8 @@ static int api_call(const char *suffix, const char *body, char *resp, int cap) {
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/6.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) return 0;
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost, port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath, NULL, NULL, NULL, 0) : NULL;
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath, NULL, NULL, NULL,
|
||||
https ? WINHTTP_FLAG_SECURE : 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
const wchar_t *hdr = L"Content-Type: application/json\r\n";
|
||||
|
||||
Reference in New Issue
Block a user