Feature: Tunnel the device protocol through a reverse proxy over WebSocket
This commit is contained in:
1 parent
de621aa555
commit
d4f312c9d8
20 files changed
+1994
-63
No files matched your search
@@ -45,6 +45,10 @@ IOCPClient* NewNetClient(CONNECT_ADDRESS* conn, State& bExit, const std::string&
|
||||
return new IOCPUDPClient(bExit, exit_while_disconnect);
|
||||
if (type == PROTO_HTTP || type == PROTO_HTTPS)
|
||||
return new IOCPClient(bExit, exit_while_disconnect, MaskTypeHTTP, conn, publicIP);
|
||||
// WebSocket:仍然是 IOCPClient(TCP 承载),只是 ConnectServer 里多做一次 Upgrade
|
||||
// 握手,Send/Recv 换成 WS 帧。HTTP 伪装层不用(WS 帧本身就是 HTTP 升级后的流)。
|
||||
if (type == PROTO_WS || type == PROTO_WSS)
|
||||
return new IOCPClient(bExit, exit_while_disconnect, MaskTypeNone, conn, publicIP);
|
||||
if (type == PROTO_KCP) {
|
||||
return new IOCPKCPClient(bExit, exit_while_disconnect);
|
||||
}
|
||||
@@ -800,6 +804,28 @@ void ResponseDisable(IOCPClient *client, const char* type, LPBYTE data, int size
|
||||
|
||||
extern "C" bool IsSystemInSession0();
|
||||
|
||||
// 信任锚已写入/删除:热重载 TLS 状态,只在传输方式真正变化(明文 ↔ TLS)时断开重连;
|
||||
// 仅换证书(仍是 TLS)不打断现有会话,新锚从下一条新连接开始生效。与 Linux 版的
|
||||
// linux/main.cpp::ApplyTlsAnchorChange 同一语义。
|
||||
static void ApplyTlsAnchorChange(IOCPClient* client)
|
||||
{
|
||||
const bool before = TlsEnabled();
|
||||
std::string err;
|
||||
if (!TlsReload(err)) {
|
||||
Mprintf("[TLS] reload failed: %s (keeping current transport)\n", err.c_str());
|
||||
return;
|
||||
}
|
||||
const bool after = TlsEnabled();
|
||||
if (before == after) {
|
||||
Mprintf("[TLS] trust anchor updated, transport unchanged (%s)\n",
|
||||
after ? "TLS" : "plaintext");
|
||||
return;
|
||||
}
|
||||
Mprintf("[TLS] transport switched to %s, reconnecting\n", after ? "TLS" : "plaintext");
|
||||
if (client)
|
||||
client->Disconnect(); // 断开后由重连循环用新传输方式重新登录
|
||||
}
|
||||
|
||||
VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
bool isExit = szBuffer[0] == COMMAND_BYE || szBuffer[0] == SERVER_EXIT;
|
||||
@@ -853,15 +879,20 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
|
||||
case COMMAND_TLS_ENABLE: {
|
||||
// 服务端下发信任锚证书:payload = PEM 正文(szBuffer+1 .. ulLength-1)。
|
||||
// 写入注册表 settings\tls_cert,客户端下次启动读到证书即启用 TLS(非实时)。
|
||||
// 写入注册表 settings\tls_cert 后热重载:明文 → TLS 的切换会断开本连接,重连
|
||||
// 循环随即用 TLS 重新登录(此前按明文回退的 WSS 客户端就此升级为 WSS)。
|
||||
if (ulLength > 1) {
|
||||
std::string certPem((char*)szBuffer + 1, ulLength - 1);
|
||||
m_cfg->SetStr("settings", "tls_cert", certPem);
|
||||
ApplyTlsAnchorChange(m_ClientObject);
|
||||
} else {
|
||||
// 没有证书正文就等于「启用但没有锚」——不该悄悄忽略,留一行便于排查。
|
||||
Mprintf("[TLS] COMMAND_TLS_ENABLE without a certificate payload, ignored\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case COMMAND_TLS_DISABLE: {
|
||||
// 删除注册表信任锚,客户端下次启动无证书即回明文(非实时)。
|
||||
// 删除注册表信任锚后热重载:TLS → 明文时断开重连(WSS 客户端会回到明文回退)。
|
||||
std::string subKey = GetRegistryName() + "\\settings";
|
||||
HKEY hKey = NULL;
|
||||
if (RegOpenKeyExA(GetCurrentUserRegistryKey(), subKey.c_str(), 0,
|
||||
@@ -869,6 +900,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
RegDeleteValueA(hKey, "tls_cert");
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
ApplyTlsAnchorChange(m_ClientObject);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user