browsec/trustlab/examples/strict-plugin.ts

50 lines
1.4 KiB
TypeScript

import {
defineTrustPlugin,
exactCertificateScope,
} from "../sdk/plugin-api.js";
export default defineTrustPlugin({
manifest: {
manifestVersion: 1,
trustApiVersion: "0.1",
id: "community.village.strict-example",
name: "Village strict example",
version: "1.0.0",
supportedModes: ["advisor", "decision-authority"],
capabilities: { interactiveUi: true },
},
hooks: {
collectEvidence({ facts }) {
if (facts.hostname !== "library.village") return undefined;
return {
entries: [
{
kind: "evidence",
code: "known-community-certificate",
message: "The configured community recognizes this certificate.",
},
],
};
},
async onTlsFailure({ facts, journal, ui }) {
const trusted = await ui.requestDecision({
title: "Unknown village authority",
summary: "Firefox does not recognize this authority. The community recognizes the exact certificate.",
proposedScope: exactCertificateScope(facts),
evidenceEntryIds: journal.entries.map((entry) => entry.id),
});
if (trusted === undefined) return undefined;
return {
trusted,
scope: exactCertificateScope(facts),
lifetime: { kind: "session" },
reasonEntryIds: journal.entries.map((entry) => entry.id),
};
},
},
});