Feature: Switch a Linux client's transport TLS at runtime
The server's TLS menu already wrote the trust anchor into the Windows client's registry and expected a restart. The Linux client grew the same command handling (166/167) but, like Windows, only read the anchor once at startup, so enabling or disabling TLS still meant restarting it. Both handlers now take effect immediately. TlsChannelLinux.cpp no longer initialises through std::call_once. The process-level state (context, enabled, load error) lives behind a mutex and TlsReload() rebuilds it from whatever anchor file is on disk, so TlsEnabled() reflects the new transport as soon as the anchor is written or removed. In-flight sessions survive the swap because SSL_new increments the SSL_CTX reference count; the unit test pins that down by keeping an established TLS connection open across a reload that frees the old context. A reload that hits a bad anchor keeps the previous state and only logs: one bad push should not brick a working client, and the next start is still fail-closed. The pushed PEM is parsed before it is written for the same reason -- a corrupt anchor on disk would lock the client out of the server with no way to correct it remotely. Only a real transport flip (plaintext <-> TLS) asks for a reconnect. An anchor swap alone, as in a certificate rotation, leaves the current session alone and applies to the next connection. The receive thread never closes the socket itself; it sets g_needReconnect and the main heartbeat loop disconnects so the outer reconnect loop can re-handshake, matching how the heartbeat timeout path already works. IOCPClient now latches the transport per connection (m_useTls) at handshake time instead of consulting TlsEnabled() on every send and receive. Without the latch, the second or so between the reload and the reconnect would push plaintext into an established TLS session, or the reverse, producing protocol errors for no reason. RES_TLS (szReserved[19]) is refreshed right before each login, including the resend after a group change, so the TLS column on the server flips with the transport instead of showing the value from process start. The confirmation dialogs now say what each platform does, with translations in en_US, zh_TW and de_DE; the keys carry the literal \n escape the INI parser understands. Ending a sub-connection is not an error. OpenSSL 3 classifies a peer that closes without close_notify as an unexpected-EOF protocol error, so every terminal or file transfer session logged an SSL_read failure on the real servers even though Recv promises 0 for a plain close and neither side sends close_notify. SSL_OP_IGNORE_UNEXPECTED_EOF restores the intended semantics. Verified with the reload unit test (RELOAD-OK, covering the in-flight connection across a context swap, garbage payload rejection and a broken anchor keeping TLS alive), an abrupt-close test (recv now returns 0 instead of SOCKET_ERROR) and end to end against a protocol-faithful fake server that signs MasterSettings with libsign: plaintext login, 166, TLS reconnect with RES_TLS=1, 167, plaintext reconnect with RES_TLS=0. The Linux client, the Debug Windows client and the Debug MFC server all build. The cost is inherent to taking effect immediately: a remote session in progress is dropped when the transport changes, and the MFC server briefly shows the client as a duplicate login until the old connection is reaped and the standby entry is promoted. Co-Authored-By: deepseek-flash Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
committed
1 parent
c11df75225
commit
6bfa4294cc
11 files changed
+824
-48
No files matched your search
@@ -4793,8 +4793,11 @@ void CMy2015RemoteDlg::OnExperimentTlsEnable()
|
||||
_T("提示"), MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
// 二次确认:避免误点就切换被控端 TLS;客户端写注册表,下次启动生效
|
||||
if (IDYES != MessageBoxL(_T("确定对选中主机启用 TLS 传输吗?(客户端下次启动生效)"),
|
||||
// 二次确认:避免误点就切换被控端 TLS。
|
||||
// 生效时机因客户端而异:Windows 写注册表、下次启动生效;Linux 落盘后立即热切换并
|
||||
// 断开重连(见 client/TlsChannelLinux.cpp 的 TlsReload),正在进行的远程会话会中断。
|
||||
if (IDYES != MessageBoxL(_T("确定对选中主机启用 TLS 传输吗?\n"
|
||||
"(Linux 客户端立即生效并断线重连;Windows 客户端下次启动生效)"),
|
||||
_T("提示"), MB_ICONQUESTION | MB_YESNO)) return;
|
||||
|
||||
// 读取服务端证书(信任锚),随启用指令一并下发;客户端写入注册表 settings\tls_cert。
|
||||
@@ -4826,7 +4829,8 @@ void CMy2015RemoteDlg::OnExperimentTlsDisable()
|
||||
_T("提示"), MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
if (IDYES != MessageBoxL(_T("确定取消选中主机的 TLS 传输吗?(客户端下次启动生效)"),
|
||||
if (IDYES != MessageBoxL(_T("确定取消选中主机的 TLS 传输吗?\n"
|
||||
"(Linux 客户端立即生效并断线重连;Windows 客户端下次启动生效)"),
|
||||
_T("提示"), MB_ICONQUESTION | MB_YESNO)) return;
|
||||
BYTE bToken = COMMAND_TLS_DISABLE; //向被控端发送停用 TLS 传输命令
|
||||
SendSelectedCommand(&bToken, sizeof(BYTE));
|
||||
|
||||
@@ -2092,8 +2092,8 @@ TLS
|
||||
证书/私钥加载失败,加密功能未生效。请检查文件路径与格式(证书 PEM、私钥 PKCS#8)。=Zertifikat/privater Schluessel konnte nicht geladen werden; Verschluesselung ist inaktiv. Bitte Pfad und Format pruefen (PEM-Zertifikat, PKCS#8-Schluessel).
|
||||
TLS传输=TLS-Transport
|
||||
取消TLS=TLS deaktivieren
|
||||
确定对选中主机启用 TLS 传输吗?(客户端下次启动生效)=TLS-Transport fuer die ausgewaehlten Hosts aktivieren? (wirkt nach Client-Neustart)
|
||||
确定取消选中主机的 TLS 传输吗?(客户端下次启动生效)=TLS-Transport fuer die ausgewaehlten Hosts deaktivieren? (wirkt nach Client-Neustart)
|
||||
确定对选中主机启用 TLS 传输吗?\n(Linux 客户端立即生效并断线重连;Windows 客户端下次启动生效)=TLS-Transport fuer die ausgewaehlten Hosts aktivieren?\n(Linux-Clients wechseln sofort und verbinden sich neu; Windows-Clients erst nach dem Neustart)
|
||||
确定取消选中主机的 TLS 传输吗?\n(Linux 客户端立即生效并断线重连;Windows 客户端下次启动生效)=TLS-Transport fuer die ausgewaehlten Hosts deaktivieren?\n(Linux-Clients wechseln sofort und verbinden sich neu; Windows-Clients erst nach dem Neustart)
|
||||
服务端未启用 TLS 证书,无法切换客户端 TLS 传输=Server-TLS-Zertifikat ist nicht aktiviert; TLS-Transport der Clients kann nicht umgeschaltet werden
|
||||
读取服务端 TLS 证书失败,无法下发=Server-TLS-Zertifikat konnte nicht gelesen werden; Verteilung nicht moeglich
|
||||
白名单=Whitelist
|
||||
|
||||
@@ -2111,8 +2111,8 @@ TLS
|
||||
证书/私钥加载失败,加密功能未生效。请检查文件路径与格式(证书 PEM、私钥 PKCS#8)。=Failed to load certificate/private key; encryption is not active. Check the file path and format (PEM certificate, PKCS#8 private key).
|
||||
TLS传输=TLS Transport
|
||||
取消TLS=Disable TLS
|
||||
确定对选中主机启用 TLS 传输吗?(客户端下次启动生效)=Enable TLS transport for the selected host? (takes effect after the client restarts)
|
||||
确定取消选中主机的 TLS 传输吗?(客户端下次启动生效)=Disable TLS transport for the selected host? (takes effect after the client restarts)
|
||||
确定对选中主机启用 TLS 传输吗?\n(Linux 客户端立即生效并断线重连;Windows 客户端下次启动生效)=Enable TLS transport for the selected host?\n(Linux clients switch immediately and reconnect; Windows clients apply it on next start)
|
||||
确定取消选中主机的 TLS 传输吗?\n(Linux 客户端立即生效并断线重连;Windows 客户端下次启动生效)=Disable TLS transport for the selected host?\n(Linux clients switch immediately and reconnect; Windows clients apply it on next start)
|
||||
服务端未启用 TLS 证书,无法切换客户端 TLS 传输=Server TLS certificate is not enabled; cannot toggle client TLS transport
|
||||
读取服务端 TLS 证书失败,无法下发=Failed to read the server TLS certificate; cannot distribute
|
||||
白名单=Whitelist
|
||||
|
||||
@@ -2102,8 +2102,8 @@ TLS
|
||||
证书/私钥加载失败,加密功能未生效。请检查文件路径与格式(证书 PEM、私钥 PKCS#8)。=憑證/私鑰載入失敗,加密功能未生效。請檢查檔案路徑與格式(憑證 PEM、私鑰 PKCS#8)。
|
||||
TLS传输=TLS 傳輸
|
||||
取消TLS=停用 TLS
|
||||
确定对选中主机启用 TLS 传输吗?(客户端下次启动生效)=確定對選取主機啟用 TLS 傳輸嗎?(用戶端下次啟動生效)
|
||||
确定取消选中主机的 TLS 传输吗?(客户端下次启动生效)=確定取消選取主機的 TLS 傳輸嗎?(用戶端下次啟動生效)
|
||||
确定对选中主机启用 TLS 传输吗?\n(Linux 客户端立即生效并断线重连;Windows 客户端下次启动生效)=確定對選取主機啟用 TLS 傳輸嗎?\n(Linux 用戶端立即生效並斷線重連;Windows 用戶端下次啟動生效)
|
||||
确定取消选中主机的 TLS 传输吗?\n(Linux 客户端立即生效并断线重连;Windows 客户端下次启动生效)=確定取消選取主機的 TLS 傳輸嗎?\n(Linux 用戶端立即生效並斷線重連;Windows 用戶端下次啟動生效)
|
||||
服务端未启用 TLS 证书,无法切换客户端 TLS 传输=伺服器未啟用 TLS 憑證,無法切換用戶端 TLS 傳輸
|
||||
读取服务端 TLS 证书失败,无法下发=讀取伺服器 TLS 憑證失敗,無法下發
|
||||
白名单=白名單
|
||||
|
||||
Reference in new issue
Block a user