feat(chain): TLCP 进程通道环回实证落地,主门禁扩到 18 条

- mpc-chain 新增 TlcpEndpoint/TlcpTunnel:Rust 侧 spawn gmssl tlcp_client
  经 TLCP 收发真实 JSON-RPC(响应走 stdout),就绪状态 NeedsFfi → LoopbackReachable
- mpc chain tlcp send 端到端收发;realChainVerified 恒 false、channelLayerReachable
  仅当配置就绪才 true,诚实边界未破(环回 echo 不等于 bcos-rpc 真机通道)
- 主门禁第 18 条 = selftest-tlcp-tunnel.py(15 条真环回判据 + 零依赖 --self-test)
- 修 selftest-chain-gm.py / selftest-chain-opa.py 两处写死旧门禁计数的断言
- CLAUDE.md / INTEGRATION_ANALYSIS.md / ci.sh 同步门禁计数与状态
This commit is contained in:
admin committed 2026-11-07 19:23:40 +08:00
1 parent 8d7c9aace2
commit d6330862d9
10 files changed
+887 -89

No files matched your search

+97 -9
View File
@@ -31,7 +31,7 @@ use mpc_chain::sm2::{
SM2_DISTID,
};
use mpc_chain::tlcp::{
probe_tlcp_environment, TlcpBackend, TlcpConfig, TlcpReadiness,
probe_tlcp_environment, TlcpBackend, TlcpConfig, TlcpEndpoint, TlcpReadiness, TlcpTunnel,
};
use mpc_chain::{from_hex, to_hex, ChainConfig, TransportMode, PLAINTEXT_STUB_WARNING};
use std::collections::HashMap;
@@ -392,7 +392,14 @@ fn cmd_align(args: &[String]) -> Result<(), String> {
}
fn cmd_tlcp(args: &[String]) -> Result<(), String> {
let o = opts(args, &["--file"])?;
match args.first().map(String::as_str) {
Some("send") => cmd_tlcp_send(&args[1..]),
_ => cmd_tlcp_status(args),
}
}
fn cmd_tlcp_status(_args: &[String]) -> Result<(), String> {
let o = opts(_args, &["--file"])?;
let p = probe_tlcp_environment();
let (config_ok, detail) = match o.get("--file") {
Some(path) => match TlcpConfig::from_json(&read(path)?) {
@@ -407,11 +414,13 @@ fn cmd_tlcp(args: &[String]) -> Result<(), String> {
let readiness = if p.backend == TlcpBackend::None {
TlcpReadiness::MissingEnvironment
} else {
// ★ 环境齐备(含 GmSSL 本机握手已跑通)也只到 NeedsFfi:
// Rust 侧把 JSON-RPC 经 TLCP 发到 bcos-rpc 的通道还没接。
TlcpReadiness::NeedsFfi
// ★ 环境齐备 + Rust 侧 TLCP 进程通道(TlcpTunnel)已接入 ⇒ 通道层环回可达。
// 但服务端是 gmssl 环回 echo,不是 bcos-rpc 真机;realChainVerified 恒 false。
TlcpReadiness::LoopbackReachable
};
let ready = readiness == TlcpReadiness::Ready && config_ok;
let channel_layer_reachable = readiness == TlcpReadiness::LoopbackReachable && config_ok;
let real_chain_verified = false;
let reason = match p.backend {
TlcpBackend::None => format!(
"本机既无 OpenSSL/Tongsuo TLCP 套件({}),也无可用 GmSSL;\
@@ -419,17 +428,19 @@ fn cmd_tlcp(args: &[String]) -> Result<(), String> {
p.openssl_version
),
TlcpBackend::GmSSL => String::from(
"GmSSL TLCP 本机握手已可用,但 Rust 侧把 JSON-RPC 经 TLCP 发到 bcos-rpc 的\
进程通道 / FFI 未落地,且未验证 bcos-rpc 是否启用 TLCP;拒绝宣称能发真交易",
"GmSSL TLCP 本机握手与进程通道已可用(环回 echo 实证),但服务端不是 bcos-rpc 真机,\
未验证 bcos-rpc 启用 TLCP,也无硬件国密模组;发真交易仍被拒",
),
TlcpBackend::Tongsuo => String::from(
"Tongsuo TLCP 环境齐备但 Rust 侧 FFI 握手未落地,拒绝宣称能发真交易",
"Tongsuo TLCP 环境齐备(通道代码已接入),但发真交易仍须 bcos-rpc 真机验证",
),
};
println!(
"{{\"ready\":{},\"readiness\":\"{:?}\",\"configOk\":{},\"backend\":\"{:?}\",\"opensslVersion\":\"{}\",\"tlcpCipherAvailable\":{},\"tongsuoLib\":{},\"gmsslAvailable\":{},\"gmsslVersion\":{},\"gmsslTlcpCommands\":{},\"detail\":\"{}\",\"reason\":\"{}\"}}",
"{{\"ready\":{},\"readiness\":\"{:?}\",\"channelLayerReachable\":{},\"realChainVerified\":{},\"configOk\":{},\"backend\":\"{:?}\",\"opensslVersion\":\"{}\",\"tlcpCipherAvailable\":{},\"tongsuoLib\":{},\"gmsslAvailable\":{},\"gmsslVersion\":{},\"gmsslTlcpCommands\":{},\"detail\":\"{}\",\"reason\":\"{}\"}}",
ready,
readiness,
channel_layer_reachable,
real_chain_verified,
config_ok,
p.backend,
esc(&p.openssl_version),
@@ -450,6 +461,83 @@ fn cmd_tlcp(args: &[String]) -> Result<(), String> {
Ok(())
}
/// 经 TLCP 进程通道把一个请求体发给某 endpoint 并读回响应。
///
/// ★ 诚实边界:这只是「通道层环回实证」,把 JSON-RPC 经 TLCP 发到 endpoint
/// 并读回响应;不保证 endpoint 是 bcos-rpc。输出里 `realChainVerified`
/// 恒 false,明确标注「不等于通道已通」。
fn cmd_tlcp_send(args: &[String]) -> Result<(), String> {
let o = opts(
args,
&[
"--host",
"--port",
"--ca",
"--payload",
"--cipher-suite",
"--server-name",
"--cert",
"--key",
"--pass",
"--timeout",
],
)?;
let host = o.get("--host").cloned().ok_or_else(|| String::from("缺 --host"))?;
let port = o
.get("--port")
.cloned()
.ok_or_else(|| String::from("缺 --port"))?
.parse::<u16>()
.map_err(|e| format!("--port 不是合法端口: {e}"))?;
let ca_path = o
.get("--ca")
.cloned()
.ok_or_else(|| String::from("缺 --ca(CA 证书文件路径)"))?;
let payload_path = o
.get("--payload")
.cloned()
.ok_or_else(|| String::from("缺 --payload(请求体文件路径)"))?;
let cipher = o
.get("--cipher-suite")
.cloned()
.unwrap_or_else(|| String::from("TLS_ECC_SM4_CBC_SM3"));
let timeout = o
.get("--timeout")
.cloned()
.and_then(|s| s.parse::<u64>().ok())
.unwrap_or(0);
let ca_pem = read(&ca_path)?;
let payload = read(&payload_path)?;
let server_name = o.get("--server-name").cloned();
let client_sign_cert_pem = o.get("--cert").map(|p| read(p)).transpose()?;
let client_sign_key_pem = o.get("--key").map(|p| read(p)).transpose()?;
let client_key_pass = o.get("--pass").cloned();
let endpoint = TlcpEndpoint {
host,
port,
ca_pem: ca_pem.into_bytes(),
cipher_suite: cipher,
server_name,
client_sign_cert_pem: client_sign_cert_pem.map(|v| v.into_bytes()),
client_sign_key_pem: client_sign_key_pem.map(|v| v.into_bytes()),
client_key_pass,
};
let tun = TlcpTunnel::open(endpoint).map_err(|e| format!("开 TLCP 通道失败: {e}"))?;
let resp = tun
.send(payload.as_bytes(), timeout)
.map_err(|e| format!("经 TLCP 发送失败: {e}"))?;
let resp_text = String::from_utf8_lossy(&resp);
let resp_hex: String = resp.iter().map(|b| format!("{b:02x}")).collect();
println!(
"{{\"sentBytes\":{},\"receivedBytes\":{},\"channelLayerReachable\":true,\"realChainVerified\":false,\"responseText\":\"{}\",\"responseHexPrefix\":\"{}\",\"note\":\"环回 echo 服务端不是 bcos-rpc,本结果不等于 bcos-rpc 通道已通\"}}",
payload.len(),
resp.len(),
esc(&resp_text.chars().take(200).collect::<String>()),
resp_hex.chars().take(32).collect::<String>(),
);
Ok(())
}
fn cmd_governance(args: &[String]) -> Result<(), String> {
let o = opts(args, &["--config", "--kind", "--file"])?;
let cfg = config(req(&o, "--config")?)?;