Skip to content
This repository was archived by the owner on Nov 10, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion deploy/supernode-bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
9 changes: 3 additions & 6 deletions pc2-node/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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.


# ═══════════════════════════════════════════════════════════════════════
Expand Down
2 changes: 1 addition & 1 deletion pc2-node/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 3 additions & 1 deletion pc2-node/src/api/chipotle-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -837,7 +838,8 @@ function loadCachedProvision(): ProvisionConfig | null {

function httpsGet(url: string, timeoutMs = 5000): Promise<string> {
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();
Expand Down
2 changes: 2 additions & 0 deletions pc2-node/src/api/http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -143,6 +144,7 @@ async function resolveAndValidate(hostname: string): Promise<ResolvedTarget> {
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);
},
Expand Down
6 changes: 3 additions & 3 deletions pc2-node/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = '';
Expand Down
3 changes: 3 additions & 0 deletions pc2-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions pc2-node/src/services/boson/ConnectivityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<T>(url: string, timeoutMs = 5000): Promise<T> {
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}`));
Expand Down
4 changes: 0 additions & 4 deletions pc2-node/src/services/boson/UsernameService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions pc2-node/src/services/clusterPin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
53 changes: 53 additions & 0 deletions pc2-node/src/utils/tlsTrust.ts
Original file line number Diff line number Diff line change
@@ -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<string> = new Set([
'8d417db2dd8bf5e3084d1e3f196d583849d81bdd4c00c70b9d39369e96b8c782', // emSign ECC Root CA - G3
'c619e4780ed8e0abeda24ad732567de4383a7ea941338f6d1a7d1b49ac792fe9', // emSign Root TLS CA - G3
'bd153ed7b0434f6886b17bce8bbe84ed340c7132d702a8f4fa318f756ecbd6f3', // Comodo AAA Certificate Services
]);

export const SUPERNODE_IPS: ReadonlySet<string> = 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,
),
}));
}
44 changes: 44 additions & 0 deletions pc2-node/tests/unit/tls-trust.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
Loading