56 lines
1.5 KiB
JavaScript

import { unknownLocalAuthority } from "../fixtures/tls.js";
import { TrustRunner } from "../src/index.js";
const villagePlugin = {
manifest: {
manifestVersion: 1,
trustApiVersion: "0.1",
id: "community.village.trust",
name: "Village community trust",
version: "0.0.0",
supportedModes: ["decision-authority"],
capabilities: {},
},
hooks: {
collectEvidence({ facts }) {
if (facts.hostname !== "library.village") return;
return {
entries: [
{
kind: "evidence",
code: "known-community-key",
message: "The community has previously observed this certificate.",
},
],
};
},
async onTlsFailure({ facts, journal }) {
const known = journal.entries.some(
(entry) => entry.code === "known-community-key",
);
if (!known) return;
return {
trusted: true,
scope: {
kind: "certificate-for-host",
hostname: facts.hostname,
port: facts.port,
certificateSha256: facts.presentedChain[0].sha256,
},
lifetime: { kind: "connection" },
reasonEntryIds: journal.entries
.filter((entry) => entry.code === "known-community-key")
.map((entry) => entry.id),
};
},
},
};
const result = await new TrustRunner({
plugins: [{ plugin: villagePlugin, mode: "decision-authority" }],
}).evaluate(
unknownLocalAuthority,
);
console.log(JSON.stringify(result, null, 2));