6bfa4294cc
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>
59 lines
1.9 KiB
CMake
59 lines
1.9 KiB
CMake
# 编译方法:cmake . && make
|
||
# 设置 CMake 最低版本要求
|
||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||
set(CMAKE_CXX_STANDARD 11)
|
||
set(CMAKE_CXX_STANDARD_REQUIRED 11)
|
||
|
||
cmake_minimum_required(VERSION 3.22)
|
||
|
||
# 定义项目名称和版本
|
||
project(SimpleRemoter VERSION 1.0)
|
||
|
||
# 对于C++项目,确保标准库也静态链接
|
||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
|
||
endif()
|
||
|
||
# X11 通过 dlopen 运行时加载,编译时无需 X11 开发库
|
||
|
||
include_directories(${CMAKE_SOURCE_DIR}/mterm)
|
||
|
||
# 额外的包含目录
|
||
include_directories(../)
|
||
include_directories(../client)
|
||
include_directories(../compress)
|
||
|
||
# 添加可执行文件
|
||
set(SOURCES
|
||
main.cpp
|
||
../client/Buffer.cpp
|
||
../client/IOCPClient.cpp
|
||
../client/TlsChannelLinux.cpp # Linux 客户端单向 TLS(OpenSSL),见 client/TlsChannel.h
|
||
../client/sign_shim_unix.cpp
|
||
)
|
||
add_executable(ghost ${SOURCES})
|
||
|
||
|
||
# 设置为可以调试
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
|
||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
|
||
|
||
# 链接 ZSTD 库
|
||
message(STATUS "链接库文件: ${CMAKE_SOURCE_DIR}/lib/libzstd.a")
|
||
target_link_libraries(ghost PRIVATE "${CMAKE_SOURCE_DIR}/lib/libzstd.a")
|
||
|
||
# 链接私有签名库(提供 signMessage / verifyMessage,源码不开源)
|
||
# 该库由 SimplePlugins 仓库本地构建后放置于 lib/,构建机需先准备好
|
||
target_link_libraries(ghost PRIVATE "${CMAKE_SOURCE_DIR}/lib/libsign.a")
|
||
|
||
# libsign.a 内部使用 OpenSSL HMAC,需要在最终可执行链接 libcrypto;
|
||
# 客户端传输层 TLS(client/TlsChannelLinux.cpp)另需 libssl。
|
||
find_package(OpenSSL REQUIRED)
|
||
target_link_libraries(ghost PRIVATE OpenSSL::Crypto OpenSSL::SSL)
|
||
|
||
# 链接 dl 库(dlopen/dlsym 用于运行时加载 X11)
|
||
target_link_libraries(ghost PRIVATE dl)
|
||
|
||
# 链接 pthread 库(std::thread 需要)
|
||
target_link_libraries(ghost PRIVATE pthread)
|