Feature: Add on-demand TLS transport with hot-switch to the Android client
Reuse the Linux OpenSSL TlsChannel implementation (platform guard widened to __linux__); the trust anchor lives in the app-private filesDir, injected via TlsSetAnchorDir in nativeInit before the connection thread starts. COMMAND_TLS_ENABLE/DISABLE save/remove the anchor, hot-reload and reconnect only when the transport actually changes, so the master menu takes effect within seconds without restarting the app. Login reports RES_TLS, refreshed before each re-login. The reconnect flag is consumed before the drop check and cleared before reconnecting so a switch racing a disconnect cannot cause an extra reconnect/login cycle. Cross-compile OpenSSL 3.5.0 per ABI with build_openssl_android.sh (NDK clang + MSYS2 perl/make), integrated into build_android_libs.ps1 (-OpenSslOnly). Static libs and per-ABI headers are tracked like the existing libzstd/libsign prebuilts; --exclude-libs keeps OpenSSL symbols private to libyama.so, isolated from the Java-layer Conscrypt. Co-Authored-By: Qoder <noreply@qoder.com>
This commit is contained in:
1 parent
36618b0ad0
commit
51747dc0ea
586 files changed
+183905
-35
No files matched your search
+23
-12
@@ -16,9 +16,11 @@
|
||||
// Send/Recv 对上下文的使用由 m_ctxMtx 互斥,避免重连线程释放上下文时与使用线程产生
|
||||
// use-after-free。本对象作为 IOCPClient 的值成员存在,析构时释放上下文。
|
||||
//
|
||||
// 平台范围:_WIN32 与 Linux(非 Android)有实现;macOS / Android 不含任何内容,客户端
|
||||
// 维持明文(TLS 接入按设计文档延后)。两平台都通过 YAMA_TLS_CHANNEL 宏告知调用方
|
||||
// 「本平台有 TLS 通道」。
|
||||
// 平台范围:_WIN32(Schannel)、Linux 与 Android(OpenSSL)有实现;macOS 不含任何内容,
|
||||
// 客户端维持明文。这些平台都通过 YAMA_TLS_CHANNEL 宏告知调用方「本平台有 TLS 通道」。
|
||||
// Android 复用 Linux 的 OpenSSL 实现(TlsChannelLinux.cpp),唯一差异是信任锚目录改为
|
||||
// App 私有 filesDir(由 TlsSetAnchorDir 注入),语义(单向 TLS1.2 钉扎、fail-closed、
|
||||
// 热重载)与 Linux 完全一致。
|
||||
#pragma once
|
||||
|
||||
#if defined(_WIN32)
|
||||
@@ -133,7 +135,7 @@ private:
|
||||
std::vector<BYTE> m_pending; // 已解密、未交付给应用层的明文
|
||||
};
|
||||
|
||||
#elif defined(__linux__) && !defined(__ANDROID__)
|
||||
#elif defined(__linux__) // 含 Android:__ANDROID__ 同时定义 __linux__
|
||||
|
||||
#define YAMA_TLS_CHANNEL 1
|
||||
|
||||
@@ -150,22 +152,31 @@ bool TlsEnabled();
|
||||
// (fail-closed),不得静默回退明文。线程安全、幂等。
|
||||
bool TlsLoadError();
|
||||
|
||||
// Windows 版按目标地址区分「用不用内嵌锚」。Linux 客户端没有内嵌锚概念(生成器只往
|
||||
// Windows 镜像里写锚块),信任锚一律是配置文件,故这里忽略目标地址,与进程级开关等价。
|
||||
// Windows 版按目标地址区分「用不用内嵌锚」。Linux / Android 客户端没有内嵌锚概念(生成器
|
||||
// 只往 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 正文写入
|
||||
// $XDG_CONFIG_HOME/ghost/yama-ca.pem(默认 ~/.config/ghost/yama-ca.pem,无 HOME 时退回
|
||||
// 程序目录),原子替换、权限 0600。写入前先解析验证,不是合法证书就整包拒绝。
|
||||
// 服务端下发信任锚(COMMAND_TLS_ENABLE):把 PEM 正文写入信任锚文件,原子替换、权限 0600。
|
||||
// 写入前先解析验证,不是合法证书就整包拒绝。目录按平台:
|
||||
// Linux:$XDG_CONFIG_HOME/ghost/yama-ca.pem(默认 ~/.config/ghost/yama-ca.pem,无 HOME
|
||||
// 时退回程序目录);
|
||||
// Android:App 私有 filesDir/yama-ca.pem(目录由 TlsSetAnchorDir 注入)。
|
||||
// 落盘后用 TlsReload() 立即生效(Windows 客户端在 COMMAND_TLS_ENABLE 里调用同一个
|
||||
// TlsReload(),两平台行为一致)。
|
||||
// TlsReload(),各平台行为一致)。
|
||||
bool TlsTrustAnchorSave(const std::string& pem, std::string& err);
|
||||
|
||||
// 服务端撤销信任锚(COMMAND_TLS_DISABLE):删除上述配置文件(含程序目录同名文件)。
|
||||
// 返回是否删掉了至少一个文件;之后同样用 TlsReload() 立即生效。
|
||||
bool TlsTrustAnchorRemove(std::string& err);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
// Android:注入信任锚目录(App 私有 context.filesDir,无需存储权限、跨重启持久)。
|
||||
// 必须在首次 TlsEnabled()/握手前调用一次(nativeInit 里)。Linux 用 XDG_CONFIG_HOME/HOME
|
||||
// 定位目录,不需要此函数。设一次后不再变更,故与 TLS 状态锁无竞争。
|
||||
void TlsSetAnchorDir(const std::string& dir);
|
||||
#endif
|
||||
|
||||
// 按当前信任锚文件重建 TLS 上下文并更新开关,让随后建立的新连接立刻走新传输方式
|
||||
// (已建立的连接不受影响:SSL 对象自持 SSL_CTX 引用)。信任锚无效时不做任何改动、
|
||||
// 返回 false 并给出原因——一次坏下发不该把正在工作的客户端打死(下次启动仍 fail-closed)。
|
||||
@@ -204,7 +215,7 @@ public:
|
||||
// 握手是否已完成(Send/Recv 可用)。诊断用:区分「本连接已走 TLS」与「裸连接」。
|
||||
bool IsReady() const { return m_ready; }
|
||||
|
||||
// Linux 客户端没有内嵌锚(见上),恒为 false,与 Windows 版签名保持一致。
|
||||
// Linux / Android 客户端没有内嵌锚(见上),恒为 false,与 Windows 版签名保持一致。
|
||||
bool AnchorEmbedded() const { return false; }
|
||||
|
||||
private:
|
||||
@@ -221,4 +232,4 @@ private:
|
||||
mutable std::recursive_mutex m_ctxMtx;
|
||||
};
|
||||
|
||||
#endif // _WIN32 / __linux__ && !__ANDROID__
|
||||
#endif // _WIN32 / __linux__(含 Android)
|
||||
Reference in new issue
Block a user