Feature: Terminate TLS for the MCP endpoint inside YAMA
MCP was served by a plain httplib::Server, so remote clients could only use cleartext HTTP. YAMA now terminates TLS itself: a small front-end owns the MCP port, sniffs the first byte and either runs a Schannel handshake and forwards the decrypted bytes or passes plaintext through, with httplib moving to a loopback-only internal port. No OpenSSL, no frp change, existing local HTTP clients keep working, and an unusable certificate fails closed instead of falling back to cleartext. The identity loader grew the two things a public certificate needs. ECDSA (P-256/P-384/P-521) keys are persisted by importing PKCS#8 with an NCRYPTBUFFER_PKCS_KEY_NAME parameter, the only route MS Software KSP supports for Schannel; RSA keeps its old export-and-repersist path. Fullchains are accepted, and the intermediates are added to the current user's CA store so Schannel, which builds chains only from system stores, actually sends them. The shared handshake also now buffers a full TLS record before the first AcceptSecurityContext, which a partial ClientHello would otherwise poison (SEC_E_UNKNOWN_CREDENTIALS). Session resumption exposed a second trap: when a client resumes a session, ChangeCipherSpec, Finished and the first application record arrive in one segment and AcceptSecurityContext leaves the application record pending in the session. Nothing drained it, because both callers only decrypt when new ciphertext arrives, so the request waited until the peer gave up (the MCP front-end saw no request at all and the client reported "fetch failed (other side closed)"; the device port had the same hole behind its occasional login timeouts). Decrypt now drains pending data on len == 0, and both the front-end and the device port's handshake thread use it before entering their receive loops. Configuration is McpHttps, McpCertPath, McpKeyPath and McpInternalPort, the first three editable in the MCP settings dialog (the certificate rows stay greyed out until HTTPS is enabled and saving rejects missing files). Verified with a real Let's Encrypt ECDSA fullchain (53 tools over TLS, 401 with no or bad token), a local three-level chain whose intermediate was absent from the store, Node 24's fetch on a resumed session (initialize, notifications/initialized and tools/list all complete), and the device port's RSA handshake as a regression check. Details in docs/Mcp_Design.md section 13. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
b4cb34fea9
commit
a7dd86ff0f
15 files changed
+1218
-96
No files matched your search
@@ -2434,6 +2434,19 @@ BOOL CMy2015RemoteDlg::OnInitDialog()
|
||||
McpServer().SetKeylogEnabled(THIS_CFG.GetInt("settings", "McpKeylog", 0) != 0);
|
||||
// 工具默认等待超时(ini-only 键,无设置界面):默认 20000ms,clamp 在 SetToolTimeoutMs 内。
|
||||
McpServer().SetToolTimeoutMs(THIS_CFG.GetInt("settings", "McpToolTimeoutMs", 20000));
|
||||
// HTTPS(native TLS):McpHttps=1 时对外端口说 TLS,httplib 退到回环内部端口。
|
||||
// 证书/私钥为空时回落到 [tls] 那一对(对话框里同样按此规则预填)。
|
||||
if (THIS_CFG.GetInt("settings", "McpHttps", 0)) {
|
||||
std::string certPath = THIS_CFG.GetStr("settings", "McpCertPath", "");
|
||||
std::string keyPath = THIS_CFG.GetStr("settings", "McpKeyPath", "");
|
||||
if (certPath.empty()) certPath = THIS_CFG.GetStr("tls", "CertPath", "");
|
||||
if (keyPath.empty()) keyPath = THIS_CFG.GetStr("tls", "KeyPath", "");
|
||||
int internalPort = THIS_CFG.GetInt("settings", "McpInternalPort", 0);
|
||||
if (internalPort <= 0) internalPort = mcpPort + 1;
|
||||
McpServer().SetHttps(true, certPath, keyPath, internalPort);
|
||||
Mprintf("[MCP] HTTPS enabled: %s:%d -> 127.0.0.1:%d (cert=%s)\n",
|
||||
mcpBind.c_str(), mcpPort, internalPort, certPath.c_str());
|
||||
}
|
||||
if (!McpServer().Start(mcpBind, mcpPort)) {
|
||||
Mprintf("McpServer start failed on %s:%d\n", mcpBind.c_str(), mcpPort);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user