Files
ARTEX-chixuweihu/traffic/ca_bundle.go
T
ji ruo d786de90af feat(traffic,sandbox): add TUN/netstack transparent gateway, egress controls, CAP_NET_RAW hardening, and i18n fixes
- Implement full-traffic transparent gateway (cmd/artex-gateway, traffic/netstack.go, traffic/transparent.go) using Linux TUN + gVisor netstack deferred TCP handshakes (eliminating nmap/nc false-positive open ports), real ICMPv4 Echo proxying, UDP/DNS interception, and per-container upstream proxy overrides.
- Add egress blacklist + asset-intercept sync, non-HTTP flow/DNS SQLite persistence and APIs, and /system/proxy & /function/traffic TCP/UDP/DNS UI panels.
- Fix sandbox Playwright MCP browser loopback --proxy-server rewrite and NODE_EXTRA_CA_CERTS override in server/mcpstdio.go.
- Strip all SUID/SGID binaries in Dockerfile.sandbox, grant minimal cap_net_raw+ep to nmap/nping/ping with ARTEX_SANDBOX_ALLOW_NET_RAW toggle, and enforce IPv4/IPv6 anti-spoofing in iptables and netstack.
- Remove hardcoded Chinese "(全局)" from GET /api/proxy/routes, localize ContainerRoutesTab / NonHTTPTrafficPanel labels, and expose reactive locale/isEn from useLiveTranslation for React Compiler compatibility.
2026-12-02 02:51:36 +08:00

69 lines
1.8 KiB
Go

package traffic
import (
"bytes"
"os"
"path/filepath"
)
var systemCABundleCandidates = []string{
"/etc/ssl/certs/ca-certificates.crt",
"/etc/pki/tls/certs/ca-bundle.crt",
"/etc/ssl/cert.pem",
}
// SystemCABundlePath returns the path to the merged CA bundle (system roots +
// ARTEX MITM CA) maintained under <trafficDir>/_ca/ca-certificates.crt.
func (t *Traffic) SystemCABundlePath() string {
if t == nil {
return ""
}
return filepath.Join(t.dir, "_ca", "ca-certificates.crt")
}
// EnsureSystemCABundle builds a merged CA bundle combining the host/container
// system root store with ARTEX's MITM CA cert so sandbox containers can mount
// it read-only at /etc/ssl/certs/ca-certificates.crt without requiring root or
// runtime update-ca-certificates (#218 Phase 3). Returns the bundle path if
// built, or empty string if no base system bundle or MITM CA is present.
func (t *Traffic) EnsureSystemCABundle() string {
if t == nil {
return ""
}
mitmPEM, err := os.ReadFile(t.CACertPath())
if err != nil || len(bytes.TrimSpace(mitmPEM)) == 0 {
return ""
}
var sysPEM []byte
for _, p := range systemCABundleCandidates {
if b, err := os.ReadFile(p); err == nil && len(bytes.TrimSpace(b)) > 0 {
sysPEM = b
break
}
}
if len(sysPEM) == 0 {
return ""
}
var merged bytes.Buffer
merged.Write(sysPEM)
if !bytes.HasSuffix(sysPEM, []byte("\n")) {
merged.WriteByte('\n')
}
merged.WriteString("# ARTEX Recording Proxy MITM CA\n")
merged.Write(mitmPEM)
if !bytes.HasSuffix(mitmPEM, []byte("\n")) {
merged.WriteByte('\n')
}
dest := t.SystemCABundlePath()
tmp := dest + ".tmp"
if err := os.WriteFile(tmp, merged.Bytes(), 0o644); err != nil {
return ""
}
if err := os.Rename(tmp, dest); err != nil {
_ = os.Remove(tmp)
return ""
}
return dest
}