@xenos1996/usa 2.0.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +44 -33
  2. package/USA.md +9 -9
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +194 -7
  5. package/dist/cli.js.map +1 -1
  6. package/dist/config.d.ts +1 -1
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +31 -0
  9. package/dist/config.js.map +1 -1
  10. package/dist/engine/audit.d.ts.map +1 -1
  11. package/dist/engine/audit.js +42 -4
  12. package/dist/engine/audit.js.map +1 -1
  13. package/dist/engine/automatability.d.ts +32 -0
  14. package/dist/engine/automatability.d.ts.map +1 -0
  15. package/dist/engine/automatability.js +81 -0
  16. package/dist/engine/automatability.js.map +1 -0
  17. package/dist/engine/catalogues.d.ts +43 -0
  18. package/dist/engine/catalogues.d.ts.map +1 -0
  19. package/dist/engine/catalogues.js +109 -0
  20. package/dist/engine/catalogues.js.map +1 -0
  21. package/dist/engine/diff.d.ts +14 -0
  22. package/dist/engine/diff.d.ts.map +1 -1
  23. package/dist/engine/diff.js +59 -36
  24. package/dist/engine/diff.js.map +1 -1
  25. package/dist/engine/evaluate.d.ts +2 -1
  26. package/dist/engine/evaluate.d.ts.map +1 -1
  27. package/dist/engine/evaluate.js +125 -3
  28. package/dist/engine/evaluate.js.map +1 -1
  29. package/dist/engine/gate.d.ts +33 -0
  30. package/dist/engine/gate.d.ts.map +1 -1
  31. package/dist/engine/gate.js +116 -0
  32. package/dist/engine/gate.js.map +1 -1
  33. package/dist/engine/loader.d.ts.map +1 -1
  34. package/dist/engine/loader.js +92 -4
  35. package/dist/engine/loader.js.map +1 -1
  36. package/dist/engine/review.d.ts +49 -0
  37. package/dist/engine/review.d.ts.map +1 -0
  38. package/dist/engine/review.js +128 -0
  39. package/dist/engine/review.js.map +1 -0
  40. package/dist/engine/suppression.d.ts +52 -0
  41. package/dist/engine/suppression.d.ts.map +1 -0
  42. package/dist/engine/suppression.js +91 -0
  43. package/dist/engine/suppression.js.map +1 -0
  44. package/dist/index.d.ts +6 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +6 -0
  47. package/dist/index.js.map +1 -1
  48. package/dist/report/json.d.ts +48 -0
  49. package/dist/report/json.d.ts.map +1 -0
  50. package/dist/report/json.js +60 -0
  51. package/dist/report/json.js.map +1 -0
  52. package/dist/report/markdown.d.ts.map +1 -1
  53. package/dist/report/markdown.js +110 -17
  54. package/dist/report/markdown.js.map +1 -1
  55. package/dist/report/sarif.d.ts +84 -0
  56. package/dist/report/sarif.d.ts.map +1 -0
  57. package/dist/report/sarif.js +129 -0
  58. package/dist/report/sarif.js.map +1 -0
  59. package/dist/report/signature.d.ts +76 -0
  60. package/dist/report/signature.d.ts.map +1 -0
  61. package/dist/report/signature.js +206 -0
  62. package/dist/report/signature.js.map +1 -0
  63. package/dist/types.d.ts +115 -0
  64. package/dist/types.d.ts.map +1 -1
  65. package/dist/types.js +2 -1
  66. package/dist/types.js.map +1 -1
  67. package/dist/util/project.d.ts.map +1 -1
  68. package/dist/util/project.js +23 -1
  69. package/dist/util/project.js.map +1 -1
  70. package/dist/util/site.d.ts +13 -0
  71. package/dist/util/site.d.ts.map +1 -0
  72. package/dist/util/site.js +24 -0
  73. package/dist/util/site.js.map +1 -0
  74. package/package.json +9 -1
  75. package/rules/catalogues.yaml +109 -0
  76. package/rules/core/provenance-attestation.yaml +65 -0
  77. package/rules/core/provenance-cosign.yaml +110 -0
  78. package/rules/index.yaml +2 -0
  79. package/rules/profiles/maturity.yaml +1 -1
  80. package/templates/AGENTS.audit.md +135 -0
  81. package/templates/AUDIT_REPORT.md +155 -0
@@ -0,0 +1,84 @@
1
+ import type { AuditReport } from '../types.js';
2
+ /**
3
+ * SARIF 2.1.0 renderer — lets USA compose with GitHub code scanning, IDE
4
+ * SARIF viewers, and any dashboard that ingests SARIF.
5
+ *
6
+ * Only findings that represent an actionable defect become `results`; PASS and
7
+ * NOT_APPLICABLE are successes, not results. Judgement findings (status
8
+ * UNKNOWN) are emitted at `note` level with the evidence hint, because "a
9
+ * human must look at this" is the finding.
10
+ *
11
+ * Path handling: SARIF wants URI-style, repo-relative paths. Locations from
12
+ * the engine are already relative to the audit target, but we normalize
13
+ * separators and strip a leading `./` so GitHub links line up.
14
+ */
15
+ export declare const SARIF_VERSION = "2.1.0";
16
+ export declare const SARIF_SCHEMA = "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json";
17
+ /** SARIF levels, weakest to strongest. */
18
+ export type SarifLevel = 'none' | 'note' | 'warning' | 'error';
19
+ /** Normalize an engine path to a SARIF-friendly, repo-relative URI. */
20
+ export declare function sarifUri(file: string): string;
21
+ interface SarifPhysicalLocation {
22
+ physicalLocation: {
23
+ artifactLocation: {
24
+ uri: string;
25
+ };
26
+ region?: Record<string, number>;
27
+ };
28
+ }
29
+ interface SarifRule {
30
+ id: string;
31
+ name: string;
32
+ shortDescription: {
33
+ text: string;
34
+ };
35
+ fullDescription?: {
36
+ text: string;
37
+ };
38
+ help?: {
39
+ text: string;
40
+ };
41
+ helpUri?: string;
42
+ defaultConfiguration: {
43
+ level: SarifLevel;
44
+ };
45
+ properties: Record<string, unknown>;
46
+ }
47
+ interface SarifResult {
48
+ ruleId: string;
49
+ ruleIndex: number;
50
+ level: SarifLevel;
51
+ kind: 'fail' | 'informational';
52
+ message: {
53
+ text: string;
54
+ };
55
+ locations: SarifPhysicalLocation[];
56
+ suppressions?: {
57
+ kind: 'external';
58
+ justification: string;
59
+ }[];
60
+ }
61
+ export interface SarifLog {
62
+ version: typeof SARIF_VERSION;
63
+ $schema: typeof SARIF_SCHEMA;
64
+ runs: {
65
+ tool: {
66
+ driver: {
67
+ name: string;
68
+ version: string;
69
+ informationUri: string;
70
+ rules: SarifRule[];
71
+ };
72
+ };
73
+ results: SarifResult[];
74
+ invocations: {
75
+ executionSuccessful: boolean;
76
+ }[];
77
+ }[];
78
+ }
79
+ /** Builds a SARIF 2.1.0 log from an audit report. */
80
+ export declare function toSarif(report: AuditReport): SarifLog;
81
+ /** Renders an AuditReport as pretty-printed SARIF 2.1.0 (trailing newline). */
82
+ export declare function renderSarif(report: AuditReport): string;
83
+ export {};
84
+ //# sourceMappingURL=sarif.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sarif.d.ts","sourceRoot":"","sources":["../../src/report/sarif.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAuC,MAAM,aAAa,CAAC;AAEpF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,UAAU,CAAC;AACrC,eAAO,MAAM,YAAY,mGACyE,CAAC;AAEnG,0CAA0C;AAC1C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAoB/D,uEAAuE;AACvE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG7C;AAMD,UAAU,qBAAqB;IAC7B,gBAAgB,EAAE;QAChB,gBAAgB,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,CAAC;QAClC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACjC,CAAC;CACH;AAaD,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC,eAAe,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE;QAAE,KAAK,EAAE,UAAU,CAAA;KAAE,CAAC;IAC5C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AA4BD,UAAU,WAAW;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;IAC/B,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1B,SAAS,EAAE,qBAAqB,EAAE,CAAC;IACnC,YAAY,CAAC,EAAE;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC9D;AAkBD,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,OAAO,aAAa,CAAC;IAC9B,OAAO,EAAE,OAAO,YAAY,CAAC;IAC7B,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,CAAC;gBAChB,cAAc,EAAE,MAAM,CAAC;gBACvB,KAAK,EAAE,SAAS,EAAE,CAAC;aACpB,CAAC;SACH,CAAC;QACF,OAAO,EAAE,WAAW,EAAE,CAAC;QACvB,WAAW,EAAE;YAAE,mBAAmB,EAAE,OAAO,CAAA;SAAE,EAAE,CAAC;KACjD,EAAE,CAAC;CACL;AAED,qDAAqD;AACrD,wBAAgB,OAAO,CAAC,MAAM,EAAE,WAAW,GAAG,QAAQ,CAkCrD;AAED,+EAA+E;AAC/E,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAEvD"}
@@ -0,0 +1,129 @@
1
+ import path from 'node:path';
2
+ /**
3
+ * SARIF 2.1.0 renderer — lets USA compose with GitHub code scanning, IDE
4
+ * SARIF viewers, and any dashboard that ingests SARIF.
5
+ *
6
+ * Only findings that represent an actionable defect become `results`; PASS and
7
+ * NOT_APPLICABLE are successes, not results. Judgement findings (status
8
+ * UNKNOWN) are emitted at `note` level with the evidence hint, because "a
9
+ * human must look at this" is the finding.
10
+ *
11
+ * Path handling: SARIF wants URI-style, repo-relative paths. Locations from
12
+ * the engine are already relative to the audit target, but we normalize
13
+ * separators and strip a leading `./` so GitHub links line up.
14
+ */
15
+ export const SARIF_VERSION = '2.1.0';
16
+ export const SARIF_SCHEMA = 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json';
17
+ const SEVERITY_LEVEL = {
18
+ CRITICAL: 'error',
19
+ HIGH: 'error',
20
+ MEDIUM: 'warning',
21
+ LOW: 'note',
22
+ FUTURE: 'note',
23
+ };
24
+ /** A finding is reported only when it is not a success or a skip. */
25
+ const REPORTED_STATUSES = new Set([
26
+ 'FAIL',
27
+ 'WRONG',
28
+ 'MISSING',
29
+ 'DEPRECATED',
30
+ 'EXPERIMENTAL',
31
+ 'UNKNOWN',
32
+ ]);
33
+ /** Normalize an engine path to a SARIF-friendly, repo-relative URI. */
34
+ export function sarifUri(file) {
35
+ const posix = file.split(path.sep).join('/');
36
+ return posix.startsWith('./') ? posix.slice(2) : posix;
37
+ }
38
+ function region(l) {
39
+ return typeof l.line === 'number' ? { startLine: l.line } : undefined;
40
+ }
41
+ function locationsOf(f) {
42
+ return f.locations.map((l) => {
43
+ const physicalLocation = {
44
+ artifactLocation: { uri: sarifUri(l.file) },
45
+ };
46
+ const r = region(l);
47
+ if (r)
48
+ physicalLocation.region = r;
49
+ return { physicalLocation };
50
+ });
51
+ }
52
+ function toRule(f) {
53
+ const help = f.remediation
54
+ ? { text: `${f.why ? `${f.why}\n\n` : ''}${f.remediation}` }
55
+ : f.why
56
+ ? { text: f.why }
57
+ : undefined;
58
+ const firstRef = f.references?.[0];
59
+ return {
60
+ id: f.ruleId,
61
+ name: f.ruleId,
62
+ shortDescription: { text: f.title },
63
+ ...(f.why ? { fullDescription: { text: f.why } } : {}),
64
+ ...(help ? { help } : {}),
65
+ ...(firstRef ? { helpUri: firstRef } : {}),
66
+ defaultConfiguration: { level: SEVERITY_LEVEL[f.severity] },
67
+ properties: {
68
+ section: f.section,
69
+ sectionTitle: f.sectionTitle,
70
+ severity: f.severity,
71
+ baseSeverity: f.baseSeverity,
72
+ ruleClass: f.ruleClass,
73
+ ...(f.automatability ? { automatability: f.automatability } : {}),
74
+ },
75
+ };
76
+ }
77
+ function toResult(f, ruleIndex) {
78
+ const isJudgement = f.status === 'UNKNOWN';
79
+ const result = {
80
+ ruleId: f.ruleId,
81
+ ruleIndex,
82
+ level: isJudgement ? 'note' : SEVERITY_LEVEL[f.severity],
83
+ kind: isJudgement ? 'informational' : 'fail',
84
+ message: { text: f.message },
85
+ locations: locationsOf(f),
86
+ };
87
+ if (f.suppressedReason) {
88
+ result.suppressions = [{ kind: 'external', justification: f.suppressedReason }];
89
+ }
90
+ return result;
91
+ }
92
+ /** Builds a SARIF 2.1.0 log from an audit report. */
93
+ export function toSarif(report) {
94
+ const reported = report.findings.filter((f) => REPORTED_STATUSES.has(f.status));
95
+ // One SARIF rule entry per distinct rule id, in first-seen order so ruleIndex
96
+ // stays stable for a given report.
97
+ const ruleIndex = new Map();
98
+ const rules = [];
99
+ for (const f of reported) {
100
+ if (!ruleIndex.has(f.ruleId)) {
101
+ ruleIndex.set(f.ruleId, rules.length);
102
+ rules.push(toRule(f));
103
+ }
104
+ }
105
+ const results = reported.map((f) => toResult(f, ruleIndex.get(f.ruleId)));
106
+ return {
107
+ version: SARIF_VERSION,
108
+ $schema: SARIF_SCHEMA,
109
+ runs: [
110
+ {
111
+ tool: {
112
+ driver: {
113
+ name: 'USA — Universal Software Auditor',
114
+ version: report.usaVersion,
115
+ informationUri: 'https://github.com/Er-Sajan-PLG/universal-software-auditor',
116
+ rules,
117
+ },
118
+ },
119
+ results,
120
+ invocations: [{ executionSuccessful: true }],
121
+ },
122
+ ],
123
+ };
124
+ }
125
+ /** Renders an AuditReport as pretty-printed SARIF 2.1.0 (trailing newline). */
126
+ export function renderSarif(report) {
127
+ return `${JSON.stringify(toSarif(report), null, 2)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 * Verify-side support for detached report signatures (Sigstore/cosign).
4
+ *
5
+ * ADR-0011 boundary: USA ships NO signer. There is deliberately no
6
+ * `signReport()` here — minting a signature would cross the charter
7
+ * constraint ("no signer") and must re-open ADR-0011 first. This module only
8
+ * consumes evidence produced elsewhere: it builds the deterministic payload
9
+ * bytes a report signs over, parses a `.sig.json` sidecar, and shells out to
10
+ * an external `cosign` binary to verify it — the same opt-in posture as
11
+ * `command` checks (absent binary = explicit error, NEVER a fake pass).
12
+ *
13
+ * Deterministic/offline core: everything here is pure bytes except the
14
+ * explicitly-invoked local `cosign verify-blob` subprocess. No network calls.
15
+ */
16
+ export declare const SIGNATURE_SCHEMA = "usa-report-sig-v1";
17
+ export declare const SIDECAR_SUFFIX = ".sig.json";
18
+ /**
19
+ * Deterministic payload bytes of a report: the single canonical trailer
20
+ * projection from `markdown.ts`, UTF-8 encoded with a trailing newline.
21
+ * No second canonicalization is invented here — whatever `usa diff` parses
22
+ * is exactly what a signature binds to.
23
+ */
24
+ export declare function canonicalReportBytes(report: AuditReport): Buffer;
25
+ /** Lowercase hex SHA-256 of bytes (or a UTF-8 string). */
26
+ export declare function sha256Hex(data: Uint8Array | string): string;
27
+ /**
28
+ * Detached-signature sidecar (the `.sig.json` file beside a report).
29
+ * `bundle` is the base64-encoded Sigstore bundle as written by
30
+ * `cosign sign-blob --bundle` — kept base64 so the sidecar stays plain JSON.
31
+ */
32
+ export interface DetachedSignature {
33
+ schema: typeof SIGNATURE_SCHEMA;
34
+ /** Hex SHA-256 of `canonicalReportBytes(report)` at signing time. */
35
+ payloadSha256: string;
36
+ /** Base64-encoded Sigstore bundle binding the payload to a key. */
37
+ bundle: string;
38
+ keyHint?: string;
39
+ createdAt?: string;
40
+ }
41
+ /**
42
+ * Parses a `.sig.json` sidecar. Fail-closed: anything malformed throws —
43
+ * a corrupt sidecar is an operator error, never something to verify past.
44
+ */
45
+ export declare function parseDetachedSignature(raw: string): DetachedSignature;
46
+ /** Serializes a sidecar to prettier-stable JSON (trailing newline). */
47
+ export declare function formatDetachedSignature(sig: DetachedSignature): string;
48
+ /** True when the external `cosign` binary runs. Never throws. */
49
+ export declare function isCosignAvailable(cosignBinary?: string): boolean;
50
+ export interface VerifyOptions {
51
+ /** Path to the PEM-encoded public key the bundle is verified against. */
52
+ publicKeyPath: string;
53
+ /** Override the `cosign` binary (tests, custom installs). */
54
+ cosignBinary?: string;
55
+ /** Subprocess timeout in ms (default 60 s, mirroring `command` checks). */
56
+ timeoutMs?: number;
57
+ }
58
+ export interface VerifyResult {
59
+ ok: boolean;
60
+ detail: string;
61
+ }
62
+ /**
63
+ * Verifies a report's detached signature against a public key.
64
+ *
65
+ * Fail-closed contract:
66
+ * - payload hash mismatch → `{ ok: false }` (report changed after signing);
67
+ * - missing public key, cosign rejection, timeout → `{ ok: false }`;
68
+ * - malformed sidecar → throws (cannot even attempt verification);
69
+ * - absent `cosign` binary → throws an explicit error (same posture as
70
+ * `command` checks: an unverifiable report is NEVER reported as passing).
71
+ *
72
+ * The only external touch is the local `cosign verify-blob` subprocess;
73
+ * no network calls are made from this module.
74
+ */
75
+ export declare function verifyDetachedSignature(payload: AuditReport | Uint8Array, signature: DetachedSignature | string, options: VerifyOptions): VerifyResult;
76
+ //# sourceMappingURL=signature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/report/signature.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,gBAAgB,sBAAsB,CAAC;AACpD,eAAO,MAAM,cAAc,cAAc,CAAC;AAG1C;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAEhE;AAED,0DAA0D;AAC1D,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAI3D;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,OAAO,gBAAgB,CAAC;IAChC,qEAAqE;IACrE,aAAa,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAsDD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CASrE;AAED,uEAAuE;AACvE,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,iBAAiB,GAAG,MAAM,CAGtE;AAED,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,YAAY,SAAW,GAAG,OAAO,CAWlE;AAED,MAAM,WAAW,aAAa;IAC5B,yEAAyE;IACzE,aAAa,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB;AAiED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,WAAW,GAAG,UAAU,EACjC,SAAS,EAAE,iBAAiB,GAAG,MAAM,EACrC,OAAO,EAAE,aAAa,GACrB,YAAY,CAmCd"}
@@ -0,0 +1,206 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { trailer } from './markdown.js';
7
+ /**
8
+ * Verify-side support for detached report signatures (Sigstore/cosign).
9
+ *
10
+ * ADR-0011 boundary: USA ships NO signer. There is deliberately no
11
+ * `signReport()` here — minting a signature would cross the charter
12
+ * constraint ("no signer") and must re-open ADR-0011 first. This module only
13
+ * consumes evidence produced elsewhere: it builds the deterministic payload
14
+ * bytes a report signs over, parses a `.sig.json` sidecar, and shells out to
15
+ * an external `cosign` binary to verify it — the same opt-in posture as
16
+ * `command` checks (absent binary = explicit error, NEVER a fake pass).
17
+ *
18
+ * Deterministic/offline core: everything here is pure bytes except the
19
+ * explicitly-invoked local `cosign verify-blob` subprocess. No network calls.
20
+ */
21
+ export const SIGNATURE_SCHEMA = 'usa-report-sig-v1';
22
+ export const SIDECAR_SUFFIX = '.sig.json';
23
+ const DEFAULT_TIMEOUT_MS = 60_000;
24
+ /**
25
+ * Deterministic payload bytes of a report: the single canonical trailer
26
+ * projection from `markdown.ts`, UTF-8 encoded with a trailing newline.
27
+ * No second canonicalization is invented here — whatever `usa diff` parses
28
+ * is exactly what a signature binds to.
29
+ */
30
+ export function canonicalReportBytes(report) {
31
+ return Buffer.from(`${trailer(report)}\n`, 'utf8');
32
+ }
33
+ /** Lowercase hex SHA-256 of bytes (or a UTF-8 string). */
34
+ export function sha256Hex(data) {
35
+ const h = createHash('sha256');
36
+ h.update(typeof data === 'string' ? Buffer.from(data, 'utf8') : data);
37
+ return h.digest('hex');
38
+ }
39
+ const HEX64 = /^[0-9a-f]{64}$/;
40
+ const BASE64 = /^[A-Za-z0-9+/=\s]+$/;
41
+ function assertSidecarSchema(s) {
42
+ if (s['schema'] !== SIGNATURE_SCHEMA) {
43
+ throw new Error(`unsupported signature schema ${JSON.stringify(s['schema'])} — expected ${JSON.stringify(SIGNATURE_SCHEMA)}`);
44
+ }
45
+ }
46
+ function assertSidecarHash(s) {
47
+ if (typeof s['payloadSha256'] !== 'string' || !HEX64.test(s['payloadSha256'])) {
48
+ throw new Error('signature sidecar has no valid payloadSha256 (expected 64 lowercase hex chars)');
49
+ }
50
+ }
51
+ function decodedBundleLength(bundle) {
52
+ try {
53
+ return Buffer.from(bundle, 'base64').length;
54
+ }
55
+ catch {
56
+ return 0;
57
+ }
58
+ }
59
+ function assertSidecarBundle(s) {
60
+ if (typeof s['bundle'] !== 'string' || s['bundle'].length === 0 || !BASE64.test(s['bundle'])) {
61
+ throw new Error('signature sidecar has no valid bundle (expected non-empty base64)');
62
+ }
63
+ if (decodedBundleLength(s['bundle']) === 0) {
64
+ throw new Error('signature sidecar bundle decodes to zero bytes');
65
+ }
66
+ }
67
+ function assertSidecarShape(sig) {
68
+ if (typeof sig !== 'object' || sig === null || Array.isArray(sig)) {
69
+ throw new Error('signature sidecar must be a JSON object, got a non-object');
70
+ }
71
+ const s = sig;
72
+ assertSidecarSchema(s);
73
+ assertSidecarHash(s);
74
+ assertSidecarBundle(s);
75
+ if (s['keyHint'] !== undefined && typeof s['keyHint'] !== 'string') {
76
+ throw new Error('signature sidecar keyHint must be a string when present');
77
+ }
78
+ if (s['createdAt'] !== undefined && typeof s['createdAt'] !== 'string') {
79
+ throw new Error('signature sidecar createdAt must be a string when present');
80
+ }
81
+ }
82
+ /**
83
+ * Parses a `.sig.json` sidecar. Fail-closed: anything malformed throws —
84
+ * a corrupt sidecar is an operator error, never something to verify past.
85
+ */
86
+ export function parseDetachedSignature(raw) {
87
+ let parsed;
88
+ try {
89
+ parsed = JSON.parse(raw);
90
+ }
91
+ catch {
92
+ throw new Error('signature sidecar is not valid JSON');
93
+ }
94
+ assertSidecarShape(parsed);
95
+ return parsed;
96
+ }
97
+ /** Serializes a sidecar to prettier-stable JSON (trailing newline). */
98
+ export function formatDetachedSignature(sig) {
99
+ assertSidecarShape(sig);
100
+ return `${JSON.stringify(sig, null, 2)}\n`;
101
+ }
102
+ /** True when the external `cosign` binary runs. Never throws. */
103
+ export function isCosignAvailable(cosignBinary = 'cosign') {
104
+ try {
105
+ execFileSync(cosignBinary, ['version'], {
106
+ encoding: 'utf8',
107
+ timeout: 15_000,
108
+ stdio: ['ignore', 'pipe', 'pipe'],
109
+ });
110
+ return true;
111
+ }
112
+ catch {
113
+ return false;
114
+ }
115
+ }
116
+ function truncate(s, n) {
117
+ const flat = s.replace(/\s+/g, ' ').trim();
118
+ return flat.length > n ? `${flat.slice(0, n)}…` : flat;
119
+ }
120
+ /** Returns a fail-closed refusal detail, or null when the key file is usable. */
121
+ function checkPublicKey(publicKeyPath) {
122
+ if (!publicKeyPath) {
123
+ return 'no public key supplied — cannot verify a signature without one';
124
+ }
125
+ let isFile;
126
+ try {
127
+ isFile = fs.statSync(publicKeyPath).isFile();
128
+ }
129
+ catch {
130
+ return `public key not found at ${publicKeyPath} — refusing to pass an unverifiable report`;
131
+ }
132
+ return isFile
133
+ ? null
134
+ : `public key at ${publicKeyPath} is not a file — refusing to pass an unverifiable report`;
135
+ }
136
+ /**
137
+ * Runs the single allowed external touch: the local `cosign verify-blob`
138
+ * subprocess. Cosign rejections come back as `{ ok: false }`; only an
139
+ * absent binary throws (explicitly — never a fake pass).
140
+ */
141
+ function runCosignVerify(binary, publicKeyPath, bundlePath, payloadPath, timeoutMs) {
142
+ try {
143
+ const out = execFileSync(binary, ['verify-blob', '--key', publicKeyPath, '--bundle', bundlePath, payloadPath], {
144
+ encoding: 'utf8',
145
+ timeout: timeoutMs,
146
+ maxBuffer: 1 * 1024 * 1024,
147
+ stdio: ['ignore', 'pipe', 'pipe'],
148
+ });
149
+ return { ok: true, detail: truncate(out, 200) || 'signature verified' };
150
+ }
151
+ catch (err) {
152
+ const msg = err instanceof Error ? err.message : String(err);
153
+ if (/ENOENT/i.test(msg)) {
154
+ // Same posture as `command` checks: the tool is absent, so the check
155
+ // is explicitly un-runnable — throw rather than return ok:false, so
156
+ // no caller can mistake this for a completed verification.
157
+ throw new Error(`cosign binary not found (${binary}) — install cosign to verify report signatures; refusing to pass an unverified report`, { cause: err });
158
+ }
159
+ return {
160
+ ok: false,
161
+ detail: `cosign verify-blob rejected the signature: ${truncate(msg, 300)}`,
162
+ };
163
+ }
164
+ }
165
+ /**
166
+ * Verifies a report's detached signature against a public key.
167
+ *
168
+ * Fail-closed contract:
169
+ * - payload hash mismatch → `{ ok: false }` (report changed after signing);
170
+ * - missing public key, cosign rejection, timeout → `{ ok: false }`;
171
+ * - malformed sidecar → throws (cannot even attempt verification);
172
+ * - absent `cosign` binary → throws an explicit error (same posture as
173
+ * `command` checks: an unverifiable report is NEVER reported as passing).
174
+ *
175
+ * The only external touch is the local `cosign verify-blob` subprocess;
176
+ * no network calls are made from this module.
177
+ */
178
+ export function verifyDetachedSignature(payload, signature, options) {
179
+ const sig = typeof signature === 'string' ? parseDetachedSignature(signature) : signature;
180
+ assertSidecarShape(sig);
181
+ const bytes = payload instanceof Uint8Array ? payload : canonicalReportBytes(payload);
182
+ const binary = options.cosignBinary ?? 'cosign';
183
+ const actual = sha256Hex(bytes);
184
+ if (actual !== sig.payloadSha256) {
185
+ return {
186
+ ok: false,
187
+ detail: `payload hash mismatch — report changed after signing (sidecar binds ${sig.payloadSha256}, payload hashes to ${actual})`,
188
+ };
189
+ }
190
+ const keyRefusal = checkPublicKey(options.publicKeyPath);
191
+ if (keyRefusal !== null) {
192
+ return { ok: false, detail: keyRefusal };
193
+ }
194
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'usa-sig-verify-'));
195
+ try {
196
+ const payloadPath = path.join(dir, 'payload.bin');
197
+ const bundlePath = path.join(dir, 'bundle.json');
198
+ fs.writeFileSync(payloadPath, bytes);
199
+ fs.writeFileSync(bundlePath, Buffer.from(sig.bundle, 'base64'));
200
+ return runCosignVerify(binary, options.publicKeyPath, bundlePath, payloadPath, options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
201
+ }
202
+ finally {
203
+ fs.rmSync(dir, { recursive: true, force: true });
204
+ }
205
+ }
206
+ //# sourceMappingURL=signature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src/report/signature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,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