Files
ssw-mvp/scard/code
admin 866cbc1c56 feat(sswflow+scard): connector 模式端到端跑通 (AUC=0.7794 + 数据不出域)
- Go 1.22 docker 重 build scard connector-linux-amd64 (md5 5c41d7240c523128c50570558f9059fc)
  解决 Go 1.26 ELF ↔ OrbStack VM 内核 7.0.11-orbstack ABI 错配 (SEGV)
  build 命令: docker run --rm -e GOPROXY=https://goproxy.cn,direct -v ... golang:1.22-alpine
- scard connector main.go: secret 来源从 loadOrCreateSessionSecret (每次启动随机) 改为
  os.Getenv(SSW_CONNECTOR_SESSION_SECRET) || c.deviceID, 与 Java 端 connector_code 对齐
- application.yml: sa-token exclude-url 加 /api/ssw/tds/Connector/*/PullSession (V1.5+)
- K8sSandboxClient.PartySession 加 expiry 字段, yaml 加 SSW_CONNECTOR_EXPIRY + SSW_CONNECTOR_TASK_ID env
- nax_2p.py: _handshake_if_connector 用 env 的 expiry+taskId (不再自算避免不匹配),
  删 [A] epX dec-u/enc-d [B] epX dec-d 三行调试 print
- K8sExec.findLastJsonLine: kubectl logs --tail=-1 实际返回全部, 用可 parseJson 行作 resultJson
- 两 VM systemd unit: Environment=SSW_CONNECTOR_SESSION_SECRET=J7NODE-A/B + --session-listen :9443

验证: curl POST Nax2PJob {connectorMode: connector, partyAConnectorId: J7NODE-A, partyBConnectorId: J7NODE-B}
  → code=200, status=SUCCESS, AUC=0.7794 KS=0.5128, [CONNECTOR] handshake admitted role=A connector=J7NODE-A
  [PSI] A 侧交集样本数=300 (原始 uid/特征未跨 VM), [VLR] A 侧训练完成 AUC=0.7794 KS=0.5128
2026-08-14 11:27:28 +08:00
..
2026-08-05 18:29:12 +08:00
2026-08-05 18:29:12 +08:00
2026-08-05 18:29:12 +08:00
2026-08-05 18:29:12 +08:00
2026-08-05 18:29:12 +08:00
2026-08-05 18:29:12 +08:00
2026-08-05 18:29:12 +08:00
2026-08-05 18:29:12 +08:00
2026-08-05 18:29:12 +08:00
2026-08-05 18:29:12 +08:00

security-connector

Secure Connector Backend System

A security-focused backend system for managing connector devices with TPM-based hardware security, ECDH key exchange, and policy-based access control.

Architecture

code/
├── server/          # Server-side components (x86 Linux)
│   ├── main.go      # Server entry point
│   ├── api/         # REST API handlers
│   ├── crypto/      # Server-side cryptographic operations
│   ├── auth/        # Device authentication
│   ├── keyring/     # KEK/DEK management
│   ├── policy/      # RBAC/ABAC policy engine
│   ├── audit/       # Audit logging
│   └── easytier/    # EasyTier tunnel coordination
│
├── connector/       # Connector-side components (Host x86)
│   ├── main.go      # Connector entry point
│   ├── tpm/         # TPM interface (mock for Phase 1)
│   ├── keys/        # Local key management
│   ├── k3s/         # k3s API gateway
│   └── register/    # Device registration flow
│
├── common/          # Shared modules
│   ├── proto/       # Protocol message definitions
│   ├── crypto/      # Shared cryptographic primitives
│   └── types/       # Shared type definitions
│
├── scripts/
│   └── cloudinit/  # Cloud-init configuration generator
│
└── tests/           # Tests

Key Protocols

1. Device Registration (AUTH_REGISTER)

  • Connector sends CSR with TPM public key
  • Server validates and derives KEK via ECDH
  • Server returns encrypted KEK and session certificate

2. Challenge-Response (Runtime Auth)

  • Server sends Nonce + Challenge
  • Connector signs with TPM private key
  • Server verifies signature and derives session key

3. Key Incremental Update

  • Partial key updates via offset/length
  • Server FPGA signature required
  • Version checking prevents rollback

Key Hierarchy

Layer 0: TPM SRK (device hardware root trust)
Layer 1: KEK (Key Encryption Key) - derived via ECDH
Layer 2: DEK (Data Encryption Key) - encrypted by KEK
Layer 3: Session Keys (mTLS) - short-lived
Layer 4: Server Root Key (HSM-level)

API Endpoints

Method Path Description
POST /api/v1/device/register Device registration
POST /api/v1/device/challenge Get challenge for auth
POST /api/v1/device/auth Submit challenge response
GET /api/v1/device/{id}/status Get device status
POST /api/v1/key/incremental-update Incremental key update
POST /api/v1/easytier/join Join EasyTier network
POST /api/v1/k3s/join Join k3s cluster

Building

# Server
cd server && go build -o security-server .

# Connector
cd connector && go build -o connector .

# Cloud-init generator
cd scripts/cloudinit && chmod +x generate.sh

Running

# Server
./security-server --listen :8443 --data-dir /var/lib/security-connector

# Connector
./connector --server https://localhost:8443 --device-id DEV_001 --register

Cloud-init Configuration

# Generate cloud-init for a new device
./scripts/cloudinit/generate.sh \
    --device-id DEV_host1_001 \
    --server-url https://connector-server:8443 \
    --network-id secure-net \
    --output cloud-init.yaml

Development

Phase 1 (Current)

  • Protocol message definitions (proto/)
  • Server API handlers (server/api/)
  • Server-side crypto (server/crypto/)
  • Device authentication (server/auth/)
  • Key management (server/keyring/)
  • Policy engine (server/policy/)
  • Audit logging (server/audit/)
  • EasyTier coordinator (server/easytier/)
  • Mock TPM (connector/tpm/)
  • Connector key manager (connector/keys/)
  • Registration flow (connector/register/)
  • Cloud-init generator (scripts/cloudinit/)

Phase 2 (Planned)

  • Real TPM interface implementation
  • k3s integration
  • PostgreSQL storage backend
  • Device revocation handling

Phase 3 (Future)

  • PQC algorithm support (ML-KEM/ML-DSA)
  • FPGA/SED integration
  • Production hardening

Security Notes

  • All cryptographic operations use ECDH P-256 and AES-256-GCM
  • KEK is derived per-device using ECDH
  • Session keys are short-lived and rotated
  • TPM Quote provides remote attestation
  • Incremental updates prevent rollback attacks