Feat(client): add TLS transport to the macOS client
macOS shares the Linux transport: TlsChannel.h now dispatches __APPLE__ to the OpenSSL implementation, so handshake, pinned trust anchor, reload and removal all come from client/TlsChannelLinux.cpp. Only the platform glue is new: ConfigDir() follows initConfigPaths (HOME, then getpwuid(), then /tmp; no XDG) so the anchor sits next to config.conf, and ExeDir() uses _NSGetExecutablePath. First connect stays plaintext. The operator turns TLS on from the online list: COMMAND_TLS_ENABLE carries the anchor PEM, COMMAND_TLS_DISABLE removes it. macos/main.mm saves the anchor, calls TlsReload() and only reconnects when the transport actually changed, so re-saving the same anchor does not drop a live session. RES_TLS is filled from TlsEnabled() and refreshed on every reconnect; fillLoginInfo clears szReserved first now, because AddReserved appends and it runs twice on a group change. CMake builds arm64 only (deployment target 11.0) and links Homebrew openssl@3 statically when libcrypto.a is present, so the binary carries no Homebrew path dependency. Not built or run on a Mac yet: the Apple branch was syntax-checked under WSL and the login refresh probe-tested; macos/README.txt has the build and verify steps. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
3d87ec6720
commit
b743de6747
12 files changed
+298
-38
No files matched your search
+14
-9
@@ -6,7 +6,8 @@
|
||||
//
|
||||
// 选型:
|
||||
// - Windows:Schannel(原生 SSPI),零第三方依赖;secur32.lib / crypt32.lib 为系统库。
|
||||
// - Linux:OpenSSL(构建链已因 libsign 链接 libcrypto,另加 libssl 即可)。
|
||||
// - Linux / macOS:OpenSSL(Linux 构建链已因 libsign 链接 libcrypto,另加 libssl 即可;
|
||||
// macOS 需 Homebrew openssl@3,见 macos/CMakeLists.txt)。
|
||||
// 两者都是单向 TLS:客户端只校验服务端证书链到固定的信任锚,不提供客户端证书,
|
||||
// 客户端身份仍由隧道内登录(V1 PwdHmac / V2 ECDSA)承担;均不校主机名(客户端按 IP
|
||||
// 连接),不做吊销检查——与 Windows 版既有语义保持一致。
|
||||
@@ -16,11 +17,12 @@
|
||||
// Send/Recv 对上下文的使用由 m_ctxMtx 互斥,避免重连线程释放上下文时与使用线程产生
|
||||
// use-after-free。本对象作为 IOCPClient 的值成员存在,析构时释放上下文。
|
||||
//
|
||||
// 平台范围:_WIN32(Schannel)、Linux 与 Android(OpenSSL)有实现;macOS 不含任何内容,
|
||||
// 客户端维持明文。这些平台都通过 YAMA_TLS_CHANNEL 宏告知调用方「本平台有 TLS 通道」。
|
||||
// 平台范围:_WIN32(Schannel)、Linux / Android / macOS(OpenSSL)有实现。这些平台都通过
|
||||
// YAMA_TLS_CHANNEL 宏告知调用方「本平台有 TLS 通道」。
|
||||
// Android 复用 Linux 的 OpenSSL 实现(TlsChannelLinux.cpp),唯一差异是信任锚目录改为
|
||||
// App 私有 filesDir(由 TlsSetAnchorDir 注入),语义(单向 TLS1.2 钉扎、fail-closed、
|
||||
// 热重载)与 Linux 完全一致。
|
||||
// 热重载)与 Linux 完全一致。macOS 同样复用这份 OpenSSL 实现且不改目录规则:
|
||||
// ~/.config/ghost/yama-ca.pem 与 macOS 客户端现有的 config.conf 目录一致。
|
||||
#pragma once
|
||||
|
||||
#if defined(_WIN32)
|
||||
@@ -135,7 +137,7 @@ private:
|
||||
std::vector<BYTE> m_pending; // 已解密、未交付给应用层的明文
|
||||
};
|
||||
|
||||
#elif defined(__linux__) // 含 Android:__ANDROID__ 同时定义 __linux__
|
||||
#elif defined(__linux__) || defined(__APPLE__) // Android 同时定义 __linux__;macOS 走同一份 OpenSSL 实现
|
||||
|
||||
#define YAMA_TLS_CHANNEL 1
|
||||
|
||||
@@ -152,15 +154,18 @@ bool TlsEnabled();
|
||||
// (fail-closed),不得静默回退明文。线程安全、幂等。
|
||||
bool TlsLoadError();
|
||||
|
||||
// Windows 版按目标地址区分「用不用内嵌锚」。Linux / Android 客户端没有内嵌锚概念(生成器
|
||||
// 只往 Windows 镜像里写锚块),信任锚一律是配置文件,故这里忽略目标地址,与进程级开关等价。
|
||||
// Windows 版按目标地址区分「用不用内嵌锚」。Linux / Android / macOS 客户端没有内嵌锚概念
|
||||
// (生成器只往 Windows 镜像里写锚块),信任锚一律是配置文件,故这里忽略目标地址,与进程级
|
||||
// 开关等价。
|
||||
inline bool TlsEnabledFor(const std::string&, const std::string&) { return TlsEnabled(); }
|
||||
inline bool TlsLoadErrorFor(const std::string&, const std::string&) { return TlsLoadError(); }
|
||||
|
||||
// 服务端下发信任锚(COMMAND_TLS_ENABLE):把 PEM 正文写入信任锚文件,原子替换、权限 0600。
|
||||
// 写入前先解析验证,不是合法证书就整包拒绝。目录按平台:
|
||||
// Linux:$XDG_CONFIG_HOME/ghost/yama-ca.pem(默认 ~/.config/ghost/yama-ca.pem,无 HOME
|
||||
// 时退回程序目录);
|
||||
// Linux:$XDG_CONFIG_HOME/ghost/yama-ca.pem(默认 ~/.config/ghost/yama-ca.pem);
|
||||
// macOS:~/.config/ghost/yama-ca.pem(与 macos/main.mm 的 config.conf 同目录,不读
|
||||
// XDG_CONFIG_HOME;HOME 兜底也逐字对齐 initConfigPaths:HOME → getpwuid → /tmp);
|
||||
// Linux 无 HOME 时退回程序目录;
|
||||
// Android:App 私有 filesDir/yama-ca.pem(目录由 TlsSetAnchorDir 注入)。
|
||||
// 落盘后用 TlsReload() 立即生效(Windows 客户端在 COMMAND_TLS_ENABLE 里调用同一个
|
||||
// TlsReload(),各平台行为一致)。
|
||||
|
||||
Reference in new issue
Block a user