When the server has TLS enabled, the builder can now bake its certificate into the client it produces, so a distributed client speaks TLS on its very first connection instead of waiting for the anchor to be pushed after a plaintext login. The dialog gets a checkbox (IDC_CHECK_TLS_ANCHOR) that is only enabled for payloads and protocols where an embedded anchor makes sense; the choice is remembered even when the control flips to disabled and back, so switching protocols cannot silently undo a deliberate opt-out. Every label variant stays short enough to fit the 196 DLU field, including the German ones. A template that predates the anchor block no longer aborts generation: it warns, clears the checkbox and produces a plain client, so a master upgraded without rebuilding the ghost/ServerDll resources does not block every build. The certificate lands in a fixed 4 KiB block (magic, version, length, FNV-1a hash, master address, PEM) carved out of the payload at build time. The client reads its trust anchor from four sources in order: the tls_disabled marker, the certificate the server pushed into the registry, a PEM file next to the executable, and finally the embedded block. The embedded block only applies to a connection whose target matches the master recorded at generation time, compared as an address set: an exact string match when only one address is configured, or an intersection of resolved IPv4 addresses otherwise. A transferred, shared or parallel instance falls back to the old plaintext first-connect path instead of pinning itself to a certificate it can never verify. That decision is made per connection, not per process: shared and parallel instances are threads inside a single client process, so a process-wide flag let whichever instance connected first decide for all of them, and the first load of the TLS state cached that answer for good. The TLS layer now keeps two cached states (embedded anchor allowed, and not allowed), picks one per handshake, and reports the anchor source of that handshake for the login capability bit. Matching by resolved address also keeps parallel mode working, where the connection goes to the single IP the domain pool selected while the configured master is a domain or a list. Server side, generated and updated payloads get the block written in place; the client reports the capability bit on login so the console can tell which hosts are already TLS-only on first connect. Loading the anchor decodes every PEM block in the chain rather than just the leaf, and an anchor that exists but fails to load keeps the old fail-closed behaviour. A pushed anchor only reconnects when the transport of the live connection actually changes, judged against that connection's own target rather than the process-wide switch. This was verified end to end against a freshly generated client with an empty registry: the first connection was a TLS 1.2 ClientHello 0.2 s after start, and a four-certificate fullchain loaded all four blocks. Re-verified after the per-connection rework with the anchor block patched into a debug client: with a matching master the first bytes are a ClientHello, with a foreign master the client logs the skip and sends plaintext, and a domain master resolves to the IP it connects to and still matches. A master domain that no longer resolves falls back to plaintext within a second and is not looked up again for a minute, instead of stalling every reconnect on a DNS timeout while holding the lock the certificate verification needs. Co-Authored-By: deepseek-flash
126 lines
5.6 KiB
C++
126 lines
5.6 KiB
C++
#pragma once
|
|
|
|
#include "common/header.h"
|
|
#include "common/commands.h"
|
|
#include <atlstr.h>
|
|
|
|
enum {
|
|
ONLINELIST_IP = 0, // IP的列顺序
|
|
ONLINELIST_ADDR, // 地址
|
|
ONLINELIST_LOCATION, // 地理位置
|
|
ONLINELIST_COMPUTER_NAME, // 计算机名/备注
|
|
ONLINELIST_OS, // 操作系统
|
|
ONLINELIST_CPU, // CPU
|
|
ONLINELIST_VIDEO, // 摄像头(有无)
|
|
ONLINELIST_PING, // PING(对方的网速)
|
|
ONLINELIST_VERSION, // 版本信息
|
|
ONLINELIST_INSTALLTIME, // 安装时间
|
|
ONLINELIST_LOGINTIME, // 活动窗口
|
|
ONLINELIST_CLIENTTYPE, // 客户端类型
|
|
ONLINELIST_PATH, // 文件路径
|
|
ONLINELIST_PUBIP,
|
|
ONLINELIST_STARTTIME,
|
|
ONLINELIST_CAPABILITIES, // 客户端能力位
|
|
ONLINELIST_PRIVILEGE, // 权限级别 (SYSTEM/Admin/User)
|
|
ONLINELIST_TLS, // TLS 传输启用标志 (0/1)
|
|
ONLINELIST_MAX,
|
|
};
|
|
|
|
class context
|
|
{
|
|
public:
|
|
// 纯虚函数
|
|
virtual VOID InitMember(SOCKET s, VOID* svr) = 0;
|
|
virtual BOOL Send2Client(PBYTE szBuffer, ULONG ulOriginalLength) = 0;
|
|
virtual CString GetClientData(int index)const = 0;
|
|
virtual void GetAdditionalData(CString(&s)[RES_MAX]) const = 0;
|
|
virtual CString GetAdditionalData(int index) const = 0;
|
|
virtual uint64_t GetClientID() const = 0;
|
|
virtual std::string GetPeerName() const = 0;
|
|
virtual int GetPort() const = 0;
|
|
virtual std::string GetProtocol() const = 0;
|
|
virtual int GetServerPort() const = 0;
|
|
virtual FlagType GetFlagType() const = 0;
|
|
virtual std::string GetGroupName() const = 0;
|
|
virtual uint64_t GetAliveTime()const = 0;
|
|
virtual void SetLastHeartbeat(uint64_t time) = 0;
|
|
virtual uint64_t GetLastHeartbeat() = 0;
|
|
virtual void CancelIO() = 0;
|
|
virtual std::string GetMasterID() const = 0;
|
|
public:
|
|
virtual ~context() {}
|
|
virtual void Destroy() {}
|
|
virtual BOOL IsLogin() const
|
|
{
|
|
return TRUE;
|
|
}
|
|
virtual void SetGroupName(const std::string& group) {}
|
|
|
|
// 等待本连接待发送缓冲排空(用于「发写命令 → 补发刷新命令」的背靠背发送:
|
|
// 两次 Send2Client 会对同一发送缓冲并发 WSASend,造成竞态/丢包)。非 IOCP
|
|
// 服务端无异步发送缓冲,默认立即返回 true;CONTEXT_OBJECT 覆写为轮询发送缓冲
|
|
// 归零直到排空或超时。
|
|
virtual bool WaitSendIdle(int timeoutMs)
|
|
{
|
|
(void)timeoutMs;
|
|
return true;
|
|
}
|
|
|
|
// 检查客户端是否支持 V2 文件传输
|
|
bool SupportsFileV2() const {
|
|
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
|
|
if (caps.IsEmpty()) return false;
|
|
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_V2) != 0;
|
|
}
|
|
|
|
// 检查客户端是否使用 UTF-8 协议字符串编码。
|
|
// 无此能力位的老客户端:服务端按 CP_ACP(CP936,覆盖 95% 的简中/英语 ASCII 老客户端)解读。
|
|
bool SupportsUtf8() const {
|
|
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
|
|
if (caps.IsEmpty()) return false;
|
|
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_UTF8) != 0;
|
|
}
|
|
|
|
// 检查客户端是否支持按服务端给出的路径清单向另一客户端发送文件(COMMAND_C2C_SEND_FILES)。
|
|
// 只有 Windows 客户端实现该命令,老客户端无此能力位 → 服务端据此在 MCP 侧提前拒绝。
|
|
bool SupportsC2CPaths() const {
|
|
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
|
|
if (caps.IsEmpty()) return false;
|
|
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_C2C_PATHS) != 0;
|
|
}
|
|
|
|
// 检查客户端作为 C2C 目标端时是否回落盘回执(TOKEN_C2C_RECV_RESULT)。
|
|
// 目前只有 Linux 客户端声明;没有此能力位的老客户端/Windows 端不回执,
|
|
// 服务端据此决定要不要等回执,避免给它们白等。
|
|
bool SupportsC2CRecvAck() const {
|
|
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
|
|
if (caps.IsEmpty()) return false;
|
|
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_C2C_RECV_ACK) != 0;
|
|
}
|
|
|
|
// 检查客户端是否支持屏幕预览(双击主机时拉缩略图)。
|
|
bool SupportsScreenPreview() const {
|
|
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
|
|
if (caps.IsEmpty()) return false;
|
|
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_SCREEN_PREVIEW) != 0;
|
|
}
|
|
|
|
// 检查客户端是否支持远程协议切换(COMMAND_SET_PROTO)。老客户端没有这个命令,
|
|
// 收到也会走 default 丢弃,服务端据此把「协议切换」菜单置灰。
|
|
bool SupportsProtoSwitch() const {
|
|
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
|
|
if (caps.IsEmpty()) return false;
|
|
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_PROTO_SWITCH) != 0;
|
|
}
|
|
|
|
// 本机当前是不是靠「生成时内嵌的 TLS 信任锚」在加密(CLIENT_CAP_EMBEDDED_ANCHOR)。
|
|
// 这不是能力声明而是运行时状态:只有这种主机在服务端关掉 TLS 后无法自愈——在线时
|
|
// 还能收到「取消 TLS」,离线时发 ClientHello 会被 fail-closed 挡掉,再也进不来。
|
|
// 服务端据此在「取消 TLS」确认框里提示数量(设计文档 §3.5、§4.9)。
|
|
bool UsesEmbeddedAnchor() const {
|
|
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
|
|
if (caps.IsEmpty()) return false;
|
|
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_EMBEDDED_ANCHOR) != 0;
|
|
}
|
|
};
|