openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
42 lines (41 loc) • 1.69 kB
JavaScript
import { t as CONFIG_DIR } from "./utils-BclMknzT.mjs";
import { p as resolveUserPath } from "./path-guards-quCEQx1i.mjs";
import { T as readFileDescriptorBounded } from "./redact-BRF0hr6G.mjs";
import "./exec-CUD-gZWW.mjs";
import { n as ok, t as err } from "./result-CV1-31DB.mjs";
import "./fs-safe-CQCGsM4r.mjs";
import { r as normalizeTlsFingerprint } from "./client-address-utils-Dc3O8nVZ.mjs";
import "./resolve-system-bin-C-lukYOk.mjs";
import path from "node:path";
import { X509Certificate } from "node:crypto";
import fsPromises from "node:fs/promises";
import "@openclaw/fs-safe/durability";
//#region src/infra/tls/gateway.ts
const MAX_TLS_LEAF_FILE_BYTES = 65536;
async function readTlsLeafFile(e) {
const t = await fsPromises.open(e, "r");
try {
return (await readFileDescriptorBounded(t.fd, MAX_TLS_LEAF_FILE_BYTES)).toString("utf8");
} finally {
await t.close();
}
}
function resolveGatewayTlsCertPath(e) {
return resolveUserPath(typeof e === "string" && e.trim() ? e : path.join(CONFIG_DIR, "gateway", "tls", "gateway-cert.pem"));
}
/** Read only public certificate bytes. Inspection never provisions or requires server secrets. */
async function inspectGatewayTlsCertificate(e) {
if (e?.enabled !== true) return err("gateway tls is disabled");
try {
const t = await readTlsLeafFile(resolveGatewayTlsCertPath(e.certPath));
const n = normalizeTlsFingerprint(new X509Certificate(t).fingerprint256);
return n ? ok({
cert: t,
fingerprintSha256: n
}) : err("gateway tls: unable to compute certificate fingerprint");
} catch (e) {
return err(`gateway tls: failed to load cert (${String(e)})`);
}
}
//#endregion
export { inspectGatewayTlsCertificate };