Feature: Embed the master's TLS certificate in generated clients
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
This commit is contained in:
1 parent
c4021e1fc9
commit
951b4072e5
31 files changed
+1911
-122
No files matched your search
@@ -304,6 +304,31 @@ public:
|
||||
void SetLoginAcked(bool v) { m_loginAcked.store(v, std::memory_order_release); }
|
||||
bool IsLoginAcked() const { return m_loginAcked.load(std::memory_order_acquire); }
|
||||
|
||||
// 本连接是否真的走 TLS(ConnectServer 握手成功时锁定,见 m_useTls)。登录上报用它,
|
||||
// 而不是再去看全局的 TlsEnabled()——UDP/KCP 客户端各自 override ConnectServer、完全
|
||||
// 不含 TLS,PROTO_WS 是显式明文形态,只有这里才给得出如实答案。
|
||||
#if defined(YAMA_TLS_CHANNEL)
|
||||
bool IsTlsActive() const { return m_useTls.load(std::memory_order_acquire); }
|
||||
// 本连接校验服务端证书时用的是不是「生成时内嵌的锚」。登录上报
|
||||
// CLIENT_CAP_EMBEDDED_ANCHOR 用它:分享/并行实例连的是别的主控,本连接并不会用
|
||||
// 内嵌锚,不能因为它进程里有锚块就声称「关服务端 TLS 会失联」。
|
||||
bool IsTlsAnchorEmbedded() const
|
||||
{
|
||||
return m_useTls.load(std::memory_order_acquire) && m_tls.AnchorEmbedded();
|
||||
}
|
||||
// 按**本连接的目标**重算一次传输方式(信任锚热重载后由 KernelManager 调用)。
|
||||
// 不能用进程级 TlsEnabled() 比较前后:分享/并行实例连的不是生成时那台主控,它实际
|
||||
// 在走明文,而进程级开关(「允许内嵌锚」那套状态)仍报 true,会漏掉明文 → TLS 的切换。
|
||||
bool TlsEnabledForCurrentTarget() const
|
||||
{
|
||||
return TlsEnabledFor(m_sCurIP, m_Domain.GetAddress());
|
||||
}
|
||||
#else
|
||||
bool IsTlsActive() const { return false; }
|
||||
bool IsTlsAnchorEmbedded() const { return false; }
|
||||
bool TlsEnabledForCurrentTarget() const { return false; }
|
||||
#endif
|
||||
|
||||
// 主动断开当前连接,关闭 socket。提到 public 让外层(如 Linux/macOS main 的心跳
|
||||
// 循环检测到服务端身份校验超时)能在重连前显式关闭旧 fd,避免泄漏。
|
||||
virtual VOID Disconnect(); // 函数支持 TCP/UDP
|
||||
|
||||
Reference in new issue
Block a user