diff --git a/backend/internal/protect/assets/shell32_dui.bin b/backend/internal/protect/assets/shell32_dui.bin index e8be1b9..065b194 100755 Binary files a/backend/internal/protect/assets/shell32_dui.bin and b/backend/internal/protect/assets/shell32_dui.bin differ diff --git a/backend/internal/protect/assets/shell64_dui.bin b/backend/internal/protect/assets/shell64_dui.bin index dc661f2..ba13f74 100755 Binary files a/backend/internal/protect/assets/shell64_dui.bin and b/backend/internal/protect/assets/shell64_dui.bin differ diff --git a/shell/classic/shell5.cpp b/shell/classic/shell5.cpp index ffdda78..d289a78 100644 --- a/shell/classic/shell5.cpp +++ b/shell/classic/shell5.cpp @@ -444,11 +444,13 @@ static int http_login(const char *user, const char *pass, char *msg, int cap) { snprintf(path, sizeof(path), "%s", g_api); char *p = strstr(path, "://"); if (!p) return 0; + bool https = (p > path && p[-1] == 's'); p += 3; char *slash = strchr(p, '/'); if (slash) { *slash = 0; snprintf(path, sizeof(path), "%s", slash + 1); } snprintf(host, sizeof(host), "%s", p); - unsigned short port = 80; + // 原来写死 80:https 的 api 被当成明文 HTTP 发到 443,服务端回 400,登录恒失败。 + unsigned short port = https ? 443 : 80; char *colon = strrchr(host, ':'); if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); } MultiByteToWideChar(CP_UTF8, 0, host, -1, wHost, 256); @@ -459,7 +461,8 @@ static int http_login(const char *user, const char *pass, char *msg, int cap) { HINTERNET hS = WinHttpOpen(L"vfy/5.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; if (hR) { const wchar_t *hdr = L"Content-Type: application/json\r\n"; WinHttpSendRequest(hR, hdr, (DWORD)-1L, body, (DWORD)strlen(body), (DWORD)strlen(body), 0); diff --git a/shell/classic/shell6.cpp b/shell/classic/shell6.cpp index 8d1d9d7..5f81c9b 100644 --- a/shell/classic/shell6.cpp +++ b/shell/classic/shell6.cpp @@ -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"; diff --git a/shell/duilib/shell9_v6.cpp b/shell/duilib/shell9_v6.cpp index b7e2650..4b0e00b 100644 --- a/shell/duilib/shell9_v6.cpp +++ b/shell/duilib/shell9_v6.cpp @@ -253,7 +253,7 @@ static int api_login(const char *user, const char *pass, char *msg, int cap) { HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0); if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; } HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0); - HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL; + HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, https ? WINHTTP_FLAG_SECURE : 0) : NULL; int ok = 0; if (hR) { WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1, @@ -320,7 +320,7 @@ static int api_register(const char *user, const char *email, const char *code, HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0); if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; } HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0); - HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL; + HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, https ? WINHTTP_FLAG_SECURE : 0) : NULL; int ok = 0; if (hR) { WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1, @@ -369,7 +369,7 @@ static int api_send_code(const char *email, const char *purpose, char *msg, int HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0); if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; } HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0); - HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL; + HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, https ? WINHTTP_FLAG_SECURE : 0) : NULL; int ok = 0; if (hR) { WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1, @@ -415,7 +415,7 @@ static int api_post_sibling(const char *sibling, const char *body, char *msg, in HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0); if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; } HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0); - HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL; + HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, https ? WINHTTP_FLAG_SECURE : 0) : NULL; int ok = 0; if (hR) { WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1, @@ -464,7 +464,7 @@ static int api_get_sibling(const char *sibling, char *resp, int cap) { HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0); if (!hS) return 0; HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0); - HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"GET", wPath.c_str(), NULL, NULL, NULL, 0) : NULL; + HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"GET", wPath.c_str(), NULL, NULL, NULL, https ? WINHTTP_FLAG_SECURE : 0) : NULL; int ok = 0; if (hR) { WinHttpSendRequest(hR, WINHTTP_NO_ADDITIONAL_HEADERS, 0, NULL, 0, 0, 0);