diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index 198c6c5ff5..bc0ec0d2e0 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -362,6 +362,14 @@ jobs: (cd pc2-node && npm run test:unit) echo "::endgroup::" + - name: No TLS verification bypass in pc2-node + run: | + set -euo pipefail + if grep -rnE "rejectUnauthorized:[[:space:]]*false|NODE_TLS_REJECT_UNAUTHORIZED[[:space:]]*=" pc2-node/src; then + echo "::error::TLS verification bypass found in pc2-node/src" + exit 1 + fi + # A-4: Boot smoke — actually start the pc2-node binary in the background # and assert /api/health responds with status:ok before tearing it down. # diff --git a/CHANGELOG.md b/CHANGELOG.md index 2548d9d651..52b4001fe6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ --- +## [v1.4.3] - 2026-10-21 - Outbound HTTPS certificates are verified + +pc2-node no longer accepts any certificate on outbound HTTPS. Until now it switched verification off for the whole process at startup, so AI keys, RPC calls, gateway tokens and pins could be intercepted on an untrusted network. + +- Certificate verification is on for every outbound request. Self-signed, expired and wrong-host certificates are refused. +- The Elacity supernodes are still reached by IP, but are checked against their Let's Encrypt `*.ela.city` certificate. No supernode or DNS change is needed. +- The roots distrusted after the eMudhra intermediate compromise (20 Oct 2026) are removed from the trust store pc2-node uses. Node's bundled store still includes emSign ECC Root CA - G3. +- The supernode bootstrap no longer writes `NODE_TLS_REJECT_UNAUTHORIZED=0` into the gateway's systemd unit. + +--- + ## [v1.4.2] - 2026-10-16 - Setup page and recovery phrase require the owner An already-configured node can no longer be reset through the public setup page, and the recovery phrase can no longer be locked or read without the owner's session and a real wallet signature. diff --git a/deploy/supernode-bootstrap.sh b/deploy/supernode-bootstrap.sh index b0bcb037d7..e9fa3820de 100755 --- a/deploy/supernode-bootstrap.sh +++ b/deploy/supernode-bootstrap.sh @@ -735,7 +735,6 @@ ExecStart=/usr/bin/node index.js Restart=always RestartSec=3 Environment=NODE_ENV=production -Environment=NODE_TLS_REJECT_UNAUTHORIZED=0 [Install] WantedBy=multi-user.target diff --git a/package-lock.json b/package-lock.json index 454cf12a35..b213148b6e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "elastos-desktop", - "version": "1.4.2", + "version": "1.4.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "elastos-desktop", - "version": "1.4.2", + "version": "1.4.3", "license": "AGPL-3.0-only", "workspaces": [ "src/*", diff --git a/package.json b/package.json index b405cd7a68..4676d7bdf3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "elastos-desktop", - "version": "1.4.2", + "version": "1.4.3", "author": "Elacity LLC", "license": "AGPL-3.0-only", "description": "PC2 - your sovereign Web3 cloud desktop that runs on your own hardware.", diff --git a/pc2-node/.env.example b/pc2-node/.env.example index 9d4472458f..ff509632de 100644 --- a/pc2-node/.env.example +++ b/pc2-node/.env.example @@ -52,12 +52,9 @@ # SUPERNODE_CLUSTER_PIN_REPLICATION_MIN=2 # SUPERNODE_CLUSTER_PIN_REPLICATION_MAX=2 -# TLS handling — pc2-node already disables cert verification globally -# at boot via UsernameService.ts (scoped to the pc2 process). The default -# cluster URL uses an IP literal with self-signed cert which works -# transparently. Will be cleaned up in v1.2.8 (per-request override -# instead of process-wide) once cluster.ela.city DNS + valid cert ship. -# NODE_TLS_REJECT_UNAUTHORIZED=0 +# TLS handling — certificates are always verified. Supernode IPs are +# checked against their `*.ela.city` certificate (utils/tlsTrust.ts). +# Do not set NODE_TLS_REJECT_UNAUTHORIZED=0. # ═══════════════════════════════════════════════════════════════════════ diff --git a/pc2-node/package.json b/pc2-node/package.json index 65bd46ee33..1c84df0983 100644 --- a/pc2-node/package.json +++ b/pc2-node/package.json @@ -1,6 +1,6 @@ { "name": "@elastos/pc2-node", - "version": "1.4.2", + "version": "1.4.3", "description": "PC2 Production Node - Self-hosted personal cloud with ElastOS frontend built-in", "main": "dist/index.js", "type": "module", diff --git a/pc2-node/src/api/chipotle-client.ts b/pc2-node/src/api/chipotle-client.ts index 4a646305c5..1a788ca58c 100644 --- a/pc2-node/src/api/chipotle-client.ts +++ b/pc2-node/src/api/chipotle-client.ts @@ -23,6 +23,7 @@ import type { StoredSession } from '../services/session/BackendSessionService.js import { createLogger } from '../utils/logger.js'; import { getBaseRpcUrl, getPublicProxyUrl, getHealthyBaseRpcUrls } from '../utils/rpc.js'; import { recordMetricCounter, recordMetricHistogram } from '../utils/metrics.js'; +import { supernodeServername } from '../utils/tlsTrust.js'; const logger = createLogger('chipotle'); @@ -837,7 +838,8 @@ function loadCachedProvision(): ProvisionConfig | null { function httpsGet(url: string, timeoutMs = 5000): Promise { return new Promise((resolve, reject) => { - const req = https.get(url, { rejectUnauthorized: false, timeout: timeoutMs }, (res) => { + const servername = supernodeServername(new URL(url).hostname); + const req = https.get(url, { servername, timeout: timeoutMs }, (res) => { if (!res.statusCode || res.statusCode >= 400) { reject(new Error(`HTTP ${res.statusCode}`)); res.resume(); diff --git a/pc2-node/src/api/http-client.ts b/pc2-node/src/api/http-client.ts index 650621d2ef..8c58d7b8ed 100644 --- a/pc2-node/src/api/http-client.ts +++ b/pc2-node/src/api/http-client.ts @@ -9,6 +9,7 @@ import { logger } from '../utils/logger.js'; import { lookup as dnsLookup } from 'dns/promises'; import { isIP } from 'net'; import { Agent } from 'undici'; +import { TRUSTED_ROOT_CERTIFICATES } from '../utils/tlsTrust.js'; const router = Router(); @@ -143,6 +144,7 @@ async function resolveAndValidate(hostname: string): Promise { function makePinnedDispatcher(target: ResolvedTarget): Agent { return new Agent({ connect: { + ca: TRUSTED_ROOT_CERTIFICATES, lookup: (_host: string, _opts: unknown, cb: (err: NodeJS.ErrnoException | null, address: string, family: number) => void) => { cb(null, target.ip, target.family); }, diff --git a/pc2-node/src/api/index.ts b/pc2-node/src/api/index.ts index 492914fdc5..b54e788c81 100644 --- a/pc2-node/src/api/index.ts +++ b/pc2-node/src/api/index.ts @@ -9,6 +9,7 @@ import fs from 'fs'; import type { DatabaseManager, FilesystemManager } from '../storage/index.js'; import { Config } from '../config/loader.js'; import { baseRpcCall } from '../utils/rpc.js'; +import { SUPERNODE_TLS_SERVERNAME } from '../utils/tlsTrust.js'; import { Server as SocketIOServer } from 'socket.io'; import { authenticate, requireOwner, corsMiddleware, errorHandler, AuthenticatedRequest } from './middleware.js'; import { logger, createLogger } from '../utils/logger.js'; @@ -1395,17 +1396,16 @@ export function setupAPI(app: Express): void { } }); - // ESC RPC Proxy — forwards JSON-RPC calls to Contabo ESC archive node (self-signed cert) - const escRpcAgent = new https.Agent({ rejectUnauthorized: false }); + // ESC RPC Proxy — forwards JSON-RPC calls to Contabo ESC archive node app.post('/api/esc-rpc', (req: Request, res: Response) => { const postData = JSON.stringify(req.body); const proxyReq = https.request({ hostname: '38.242.211.112', + servername: SUPERNODE_TLS_SERVERNAME, port: 443, path: '/rpc/esc', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) }, - agent: escRpcAgent, timeout: 15000, }, (proxyRes) => { let body = ''; diff --git a/pc2-node/src/index.ts b/pc2-node/src/index.ts index 6398754fde..e2f5283653 100644 --- a/pc2-node/src/index.ts +++ b/pc2-node/src/index.ts @@ -93,10 +93,13 @@ import { getUpdateService } from './services/UpdateService.js'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; import { readFileSync as fsReadFileSync, existsSync as fsExistsSync } from 'fs'; +import { installOutboundTlsPolicy } from './utils/tlsTrust.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); +installOutboundTlsPolicy(); + // Load configuration let config: Config; try { diff --git a/pc2-node/src/services/boson/ConnectivityService.ts b/pc2-node/src/services/boson/ConnectivityService.ts index 075d0059cd..84b8836581 100644 --- a/pc2-node/src/services/boson/ConnectivityService.ts +++ b/pc2-node/src/services/boson/ConnectivityService.ts @@ -16,6 +16,7 @@ import { WireGuardService } from '../wireguard/WireGuardService.js'; import { AmneziaWGService } from '../wireguard/AmneziaWGService.js'; import { VLESSRealityService } from '../vless/VLESSRealityService.js'; import { fromBase58 } from './IdentityService.js'; +import { supernodeServername } from '../../utils/tlsTrust.js'; import { execSync } from 'child_process'; import net, { type Server, type Socket } from 'net'; import https from 'https'; @@ -85,12 +86,12 @@ let cacheTimestamp: number = 0; const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes /** - * Fetch JSON from an HTTPS URL, tolerating self-signed certs - * (supernodes serve HTTPS on raw IPs with self-signed certificates). + * Fetch JSON from an HTTPS URL. Supernode IPs verify against their ela.city certificate. */ function httpsGetJson(url: string, timeoutMs = 5000): Promise { return new Promise((resolve, reject) => { - const req = https.get(url, { rejectUnauthorized: false, timeout: timeoutMs }, (res) => { + const servername = supernodeServername(new URL(url).hostname); + const req = https.get(url, { servername, timeout: timeoutMs }, (res) => { if (!res.statusCode || res.statusCode >= 400) { res.resume(); reject(new Error(`HTTP ${res.statusCode}`)); diff --git a/pc2-node/src/services/boson/UsernameService.ts b/pc2-node/src/services/boson/UsernameService.ts index 8d8c2e744e..c58971ef17 100644 --- a/pc2-node/src/services/boson/UsernameService.ts +++ b/pc2-node/src/services/boson/UsernameService.ts @@ -12,10 +12,6 @@ import { join } from 'path'; import { logger } from '../../utils/logger.js'; import type { GatewayTokenStore } from '../gateway/GatewayTokenStore.js'; -// Allow self-signed certificates when calling gateway by IP -// This is safe because we're only calling our own trusted gateway -process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; - export interface UsernameConfig { dataDir: string; // Directory to store username config gatewayUrl: string; // Web Gateway URL (e.g., https://demo.ela.city) diff --git a/pc2-node/src/services/clusterPin.ts b/pc2-node/src/services/clusterPin.ts index 6ff699c870..020663f0de 100644 --- a/pc2-node/src/services/clusterPin.ts +++ b/pc2-node/src/services/clusterPin.ts @@ -82,10 +82,8 @@ let retrySchedulerStarted = false; // tokens with rotatable scopes are slated for v1.2.8 — see SUPERNODE-RPC-PROXY // task for the same migration pattern. // -// IP-based HTTPS URL is intentional: the cert is self-signed (no DNS for -// `cluster.ela.city` pointing here yet — gated on Thailand DNS round-trip). -// pc2-node already runs with NODE_TLS_REJECT_UNAUTHORIZED=0 globally -// (UsernameService.ts:17), so the IP-literal cert is accepted. +// IP-based HTTPS URL: the supernode serves the Let's Encrypt `*.ela.city` +// certificate, and utils/tlsTrust.ts verifies supernode IPs against it. // // Override: set SUPERNODE_CLUSTER_PIN_URL and/or _TOKEN in shell env or // pc2-node/.env to use a different cluster (e.g. self-hosted). diff --git a/pc2-node/src/utils/tlsTrust.ts b/pc2-node/src/utils/tlsTrust.ts new file mode 100644 index 0000000000..f73358eb81 --- /dev/null +++ b/pc2-node/src/utils/tlsTrust.ts @@ -0,0 +1,53 @@ +/** + * Outbound TLS trust for pc2-node. + * + * Node bundles its own root store and has not yet dropped the roots + * distrusted after the eMudhra intermediate compromise (2026-10-20), so we + * filter them out ourselves by SPKI hash. + * + * Elacity supernodes are addressed by IP but serve the Let's Encrypt + * `*.ela.city` certificate; connections to them verify against an ela.city + * name instead of the IP. The Host header is unchanged, so nginx routing is + * the same as before. + */ + +import https from 'https'; +import { createHash, X509Certificate } from 'crypto'; +import { rootCertificates } from 'tls'; +import { Agent, buildConnector, setGlobalDispatcher } from 'undici'; + +const DISTRUSTED_ROOT_SPKI_SHA256: ReadonlySet = new Set([ + '8d417db2dd8bf5e3084d1e3f196d583849d81bdd4c00c70b9d39369e96b8c782', // emSign ECC Root CA - G3 + 'c619e4780ed8e0abeda24ad732567de4383a7ea941338f6d1a7d1b49ac792fe9', // emSign Root TLS CA - G3 + 'bd153ed7b0434f6886b17bce8bbe84ed340c7132d702a8f4fa318f756ecbd6f3', // Comodo AAA Certificate Services +]); + +export const SUPERNODE_IPS: ReadonlySet = new Set(['69.164.241.210', '38.242.211.112']); +export const SUPERNODE_TLS_SERVERNAME = 'supernode.ela.city'; + +/** SHA-256 (hex) of a PEM certificate's SubjectPublicKeyInfo. */ +export function spkiSha256(pem: string): string { + const spki = new X509Certificate(pem).publicKey.export({ type: 'spki', format: 'der' }); + return createHash('sha256').update(spki).digest('hex'); +} + +export const TRUSTED_ROOT_CERTIFICATES: string[] = rootCertificates.filter( + (pem) => !DISTRUSTED_ROOT_SPKI_SHA256.has(spkiSha256(pem)), +); + +/** TLS name to verify for a host: the ela.city name for supernode IPs, otherwise undefined (use the host). */ +export function supernodeServername(host: string): string | undefined { + return SUPERNODE_IPS.has(host) ? SUPERNODE_TLS_SERVERNAME : undefined; +} + +/** Apply the trust policy to every global `fetch` and default-agent `https` request. Call once at boot. */ +export function installOutboundTlsPolicy(): void { + https.globalAgent.options.ca = TRUSTED_ROOT_CERTIFICATES; + const connect = buildConnector({ ca: TRUSTED_ROOT_CERTIFICATES }); + setGlobalDispatcher(new Agent({ + connect: (opts, callback) => connect( + { ...opts, servername: supernodeServername(opts.hostname) ?? opts.servername }, + callback, + ), + })); +} diff --git a/pc2-node/tests/unit/tls-trust.test.js b/pc2-node/tests/unit/tls-trust.test.js new file mode 100644 index 0000000000..5a887ec4bd --- /dev/null +++ b/pc2-node/tests/unit/tls-trust.test.js @@ -0,0 +1,44 @@ +/** + * Outbound TLS trust: distrusted-root filter and supernode name mapping. + * + * Imports the built module so `node --test` (CI, Node 20) can run it. + * `npm run build:backend` must have produced dist/ first. + */ + +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import https from 'node:https'; +import { rootCertificates } from 'node:tls'; + +const { + TRUSTED_ROOT_CERTIFICATES, + SUPERNODE_TLS_SERVERNAME, + spkiSha256, + supernodeServername, + installOutboundTlsPolicy, +} = await import('../../dist/utils/tlsTrust.js'); + +const EMSIGN_ECC_G3 = '8d417db2dd8bf5e3084d1e3f196d583849d81bdd4c00c70b9d39369e96b8c782'; + +test('emSign ECC Root CA - G3 is removed from the trusted roots', () => { + assert.ok(rootCertificates.some((pem) => spkiSha256(pem) === EMSIGN_ECC_G3), 'fixture: Node still bundles it'); + assert.ok(!TRUSTED_ROOT_CERTIFICATES.some((pem) => spkiSha256(pem) === EMSIGN_ECC_G3)); +}); + +test('only distrusted roots are removed', () => { + const removed = rootCertificates.length - TRUSTED_ROOT_CERTIFICATES.length; + assert.ok(removed >= 1 && removed <= 3, `removed ${removed}`); +}); + +test('supernode IPs verify against the ela.city name; other hosts are unchanged', () => { + assert.equal(supernodeServername('69.164.241.210'), SUPERNODE_TLS_SERVERNAME); + assert.equal(supernodeServername('38.242.211.112'), SUPERNODE_TLS_SERVERNAME); + assert.equal(supernodeServername('1.2.3.4'), undefined); + assert.equal(supernodeServername('api.openai.com'), undefined); + assert.match(SUPERNODE_TLS_SERVERNAME, /\.ela\.city$/); +}); + +test('installOutboundTlsPolicy sets the default https trust store', () => { + installOutboundTlsPolicy(); + assert.equal(https.globalAgent.options.ca, TRUSTED_ROOT_CERTIFICATES); +});