credential-owner-probe.mjs 962 B

123456789101112131415161718192021
  1. import { appendFile, mkdir } from "node:fs/promises";
  2. import { dirname } from "node:path";
  3. import { AsyncEntry } from "@napi-rs/keyring";
  4. const path = process.env.ZCODE_E2E_CREDENTIAL_OWNER_LOG;
  5. if (!path) throw new Error("Credential owner probe requires its isolated output path");
  6. const role = process.type ?? "node";
  7. await mkdir(dirname(path), { recursive: true });
  8. const record = (event) =>
  9. appendFile(path, `${JSON.stringify({ event, role, pid: process.pid })}\n`);
  10. await record("loaded");
  11. // 不接触真实系统钥匙串;Host/CLI 一旦直接读取就失败,不能被合成密钥掩盖。
  12. AsyncEntry.prototype.getPassword = async function () {
  13. await record("get");
  14. if (role !== "browser") throw new Error("Only Desktop Main may access the key store");
  15. return Buffer.alloc(32, 9).toString("base64url");
  16. };
  17. AsyncEntry.prototype.setPassword = async function () {
  18. await record("set");
  19. throw new Error("The synthetic key already exists");
  20. };