@eyeoverthink/edge-tls-mcp 0.0.0-stage → 1.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ Copyright 2026 Vaughn Scott (@eyeoverthink)
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,32 @@
1
- # Temporary Holding Version
1
+ # `@eyeoverthink/edge-tls-mcp` (`v1.0.0`)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
4
+
5
+ **Zero-dependency dual-stack IPv4/IPv6 TLS handshake, certificate-expiry, DNS/CAA preflight, and Ed25519-signed incident receipt MCP server.**
6
+
7
+ ## MCP Tools (4)
8
+
9
+ | Tool | Purpose |
10
+ | :--- | :--- |
11
+ | `tls_probe_endpoint` | Probe a live host:port over both IPv4 and IPv6 for TLS protocol/cipher, handshake alerts, cert chain, days remaining, and dual-stack parity |
12
+ | `tls_audit_dns` | Resolve `A`, `AAAA`, `CAA`, `CNAME`, and `NS` records to catch ACME CAA blocks or missing IPv6 parity |
13
+ | `tls_gate_deploy` | Fail-closed `ALLOW \| WARN \| BLOCK` deploy/incident gate combining TLS + DNS checks with an Ed25519-signed `edge-tls-receipt/1` receipt |
14
+ | `tls_verify_snapshot` | Verify signed `edge-tls-receipt/1` receipts offline against snapshot digests and caller-pinned Ed25519 keys |
15
+
16
+ ## Quick Start
17
+
18
+ ```bash
19
+ # Run as stdio JSON-RPC 2.0 MCP server
20
+ node bin/edge-tls-mcp.js mcp
21
+
22
+ # CLI commands
23
+ node bin/edge-tls-mcp.js probe glama.ai
24
+ node bin/edge-tls-mcp.js dns glama.ai
25
+ node bin/edge-tls-mcp.js gate glama.ai --out evidence/glama-outage-2026-12-06.json
26
+ node bin/edge-tls-mcp.js verify evidence/glama-outage-2026-12-06.json --key <publicKeyHex>
27
+ ```
28
+
29
+ ## Live Captured Evidence
30
+
31
+ - `evidence/glama-outage-2026-12-06.json`: Real-time signed dual-stack TLS + DNS snapshot of `glama.ai` (verifying `TLSv1.3`, `Let's Encrypt YE1`, 77 days remaining, IPv4/IPv6 parity, and missing CAA warning).
32
+ - `evidence/github-healthy-2026-12-06.json`: Baseline signed snapshot of `github.com`.
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ // @eyeoverthink/edge-tls-mcp CLI & stdio MCP server.
3
+ import fs from 'node:fs';
4
+ import { probeEndpoint, auditDns, gateDeploy, batchAudit, renderMarkdownScorecard, verifySnapshotReceipt, startStdioMcpServer } from '../src/index.js';
5
+
6
+ const USAGE = `edge-tls-mcp v1.1.0 — Zero-dependency dual-stack TLS/DNS preflight & signed incident receipt MCP server
7
+
8
+ Commands:
9
+ edge-tls-mcp mcp Start stdio JSON-RPC 2.0 MCP server (4 tools)
10
+ edge-tls-mcp probe <host> [port] Probe dual-stack IPv4/IPv6 TLS handshake & cert
11
+ edge-tls-mcp dns <host> Audit A, AAAA, CAA, CNAME, NS records
12
+ edge-tls-mcp gate <host> [port] [--out file.json] Run fail-closed deploy gate & mint signed receipt
13
+ edge-tls-mcp batch <hosts.txt> [--out file.json] [--md file.md] Polite rate-limited TLS/DNS scorecard
14
+ edge-tls-mcp verify <file.json> [--key hex] Verify a signed gate snapshot offline
15
+ `;
16
+
17
+ const [cmd, ...rest] = process.argv.slice(2);
18
+
19
+ if (cmd === '-h' || cmd === '--help' || (!cmd && process.stdin.isTTY)) {
20
+ console.log(USAGE);
21
+ process.exit(0);
22
+ }
23
+
24
+ if (!cmd || cmd === 'mcp') {
25
+ startStdioMcpServer();
26
+ } else if (cmd === 'probe') {
27
+ const host = rest[0];
28
+ const port = rest[1] ? Number(rest[1]) : 443;
29
+ const res = await probeEndpoint({ host, port });
30
+ console.log(JSON.stringify(res, null, 2));
31
+ process.exit(res.ok ? 0 : 1);
32
+ } else if (cmd === 'dns') {
33
+ const res = await auditDns({ host: rest[0] });
34
+ console.log(JSON.stringify(res, null, 2));
35
+ process.exit(res.ok ? 0 : 1);
36
+ } else if (cmd === 'gate') {
37
+ const host = rest[0];
38
+ let port = 443;
39
+ let outFile = null;
40
+ for (let i = 1; i < rest.length; i++) {
41
+ if (rest[i] === '--out') outFile = rest[++i];
42
+ else if (/^\d+$/.test(rest[i])) port = Number(rest[i]);
43
+ }
44
+ const res = await gateDeploy({ host, port });
45
+ const json = JSON.stringify(res, null, 2);
46
+ if (outFile) fs.writeFileSync(outFile, json + '\n', 'utf8');
47
+ console.log(json);
48
+ process.exit(res.ok ? 0 : 1);
49
+ } else if (cmd === 'batch') {
50
+ const listFile = rest[0];
51
+ let outFile = null;
52
+ let mdFile = null;
53
+ for (let i = 1; i < rest.length; i++) {
54
+ if (rest[i] === '--out') outFile = rest[++i];
55
+ else if (rest[i] === '--md') mdFile = rest[++i];
56
+ }
57
+ const hosts = fs.readFileSync(listFile, 'utf8').split(/\r?\n/);
58
+ const res = await batchAudit({ hosts });
59
+ const md = renderMarkdownScorecard(res);
60
+ if (outFile) fs.writeFileSync(outFile, JSON.stringify(res, null, 2) + '\n', 'utf8');
61
+ if (mdFile) fs.writeFileSync(mdFile, md, 'utf8');
62
+ console.log(md);
63
+ process.exit(0);
64
+ } else if (cmd === 'verify') {
65
+ const file = rest[0];
66
+ let key = null;
67
+ let allowUnpinned = false;
68
+ for (let i = 1; i < rest.length; i++) {
69
+ if (rest[i] === '--key') key = rest[++i];
70
+ else if (rest[i] === '--allow-unpinned') allowUnpinned = true;
71
+ }
72
+ const data = JSON.parse(fs.readFileSync(file, 'utf8'));
73
+ const res = verifySnapshotReceipt(data.receipt, {
74
+ snapshot: data.snapshot,
75
+ expectedPublicKeys: key ? [key] : null,
76
+ allowUnpinned,
77
+ });
78
+ console.log(JSON.stringify(res, null, 2));
79
+ process.exit(res.ok ? 0 : 1);
80
+ } else {
81
+ console.error(`Unknown command: ${cmd}\n\n${USAGE}`);
82
+ process.exit(2);
83
+ }
@@ -0,0 +1,141 @@
1
+ {
2
+ "ok": true,
3
+ "verdict": "WARN",
4
+ "host": "github.com",
5
+ "port": 443,
6
+ "blockers": [],
7
+ "warnings": [
8
+ "No AAAA (IPv6) record published"
9
+ ],
10
+ "snapshot": {
11
+ "host": "github.com",
12
+ "port": 443,
13
+ "verdict": "WARN",
14
+ "policy": {
15
+ "minDaysRemaining": 14,
16
+ "requireIpv6Parity": false,
17
+ "requireTls13": false
18
+ },
19
+ "tlsProbe": {
20
+ "ok": true,
21
+ "verdict": "ALLOW",
22
+ "host": "github.com",
23
+ "port": 443,
24
+ "capturedAt": "2026-12-06T09:22:41.500Z",
25
+ "dns": {
26
+ "ipv4": [
27
+ "4.236.95.112"
28
+ ],
29
+ "ipv6": []
30
+ },
31
+ "parity": "ipv4_only",
32
+ "probes": [
33
+ {
34
+ "ip": "4.236.95.112",
35
+ "family": 4,
36
+ "port": 443,
37
+ "latencyMs": 89,
38
+ "ok": true,
39
+ "verdict": "ALLOW",
40
+ "protocol": "TLSv1.3",
41
+ "cipher": "TLS_AES_128_GCM_SHA256",
42
+ "alpnProtocol": null,
43
+ "authorized": true,
44
+ "authorizationError": null,
45
+ "certificate": {
46
+ "subjectCN": "github.com",
47
+ "issuerCN": "Sectigo Public Server Authentication CA DV E36",
48
+ "issuerO": "Sectigo Limited",
49
+ "validFrom": "Oct 30 00:00:00 2026 GMT",
50
+ "validTo": "Jan 27 23:59:59 2027 GMT",
51
+ "daysRemaining": 52,
52
+ "fingerprint256": "7D:C4:D8:5C:F1:E3:10:97:12:25:BC:9A:92:57:67:90:43:A2:43:D7:0A:3C:C2:A9:1C:C5:D3:89:89:2C:27:76",
53
+ "sanCount": 2
54
+ }
55
+ }
56
+ ],
57
+ "reasons": []
58
+ },
59
+ "dnsAudit": {
60
+ "ok": true,
61
+ "verdict": "WARN",
62
+ "host": "github.com",
63
+ "capturedAt": "2026-12-06T09:22:41.430Z",
64
+ "records": {
65
+ "A": [
66
+ "4.236.95.112"
67
+ ],
68
+ "AAAA": [],
69
+ "CAA": [
70
+ {
71
+ "critical": 0,
72
+ "type": "CAA",
73
+ "issue": "letsencrypt.org"
74
+ },
75
+ {
76
+ "critical": 0,
77
+ "type": "CAA",
78
+ "issue": "sectigo.com"
79
+ },
80
+ {
81
+ "critical": 0,
82
+ "type": "CAA",
83
+ "issuewild": "digicert.com"
84
+ },
85
+ {
86
+ "critical": 0,
87
+ "type": "CAA",
88
+ "issuewild": "letsencrypt.org"
89
+ },
90
+ {
91
+ "critical": 0,
92
+ "type": "CAA",
93
+ "issuewild": "sectigo.com"
94
+ },
95
+ {
96
+ "critical": 0,
97
+ "type": "CAA",
98
+ "issue": "digicert.com"
99
+ },
100
+ {
101
+ "critical": 0,
102
+ "type": "CAA",
103
+ "issue": "globalsign.com"
104
+ }
105
+ ],
106
+ "CNAME": [],
107
+ "NS": [
108
+ "dns3.p08.nsone.net",
109
+ "dns4.p08.nsone.net",
110
+ "ns-1283.awsdns-32.org",
111
+ "ns-1707.awsdns-21.co.uk",
112
+ "ns-421.awsdns-52.com",
113
+ "ns-520.awsdns-01.net",
114
+ "dns1.p08.nsone.net",
115
+ "dns2.p08.nsone.net"
116
+ ]
117
+ },
118
+ "warnings": [
119
+ "No AAAA (IPv6) record published"
120
+ ],
121
+ "blockers": []
122
+ },
123
+ "blockers": [],
124
+ "warnings": [
125
+ "No AAAA (IPv6) record published"
126
+ ]
127
+ },
128
+ "receipt": {
129
+ "statement": {
130
+ "spec": "edge-tls-receipt/1",
131
+ "issuedAt": "2026-12-06T09:22:41.502Z",
132
+ "clockStatus": "unattested",
133
+ "fxId": "fx_206c3a2fcd76",
134
+ "publicKeyHex": "32349657d2f93fb9e24c291805f47ed158696bf4e057e85b151b21958e9babe7",
135
+ "deliverableSha256": "eb1138c029a8700a95dd820ec93c7bf1be9d746a88c2c581ffe7c64d8c916864"
136
+ },
137
+ "signatureHex": "fb8bddb30237c48997c2c73f4b82e90021a3cc25613133093b1f7aa19572bf179396c93b3ef5508f5cc9f092d6f2095768de9e62fc8912bda88767d6b7d79d01"
138
+ },
139
+ "publicKeyHex": "32349657d2f93fb9e24c291805f47ed158696bf4e057e85b151b21958e9babe7",
140
+ "fxId": "fx_206c3a2fcd76"
141
+ }
@@ -0,0 +1,126 @@
1
+ {
2
+ "ok": true,
3
+ "verdict": "WARN",
4
+ "host": "glama.ai",
5
+ "port": 443,
6
+ "blockers": [],
7
+ "warnings": [
8
+ "No CAA record restricts certificate issuers (ACME unrestricted)"
9
+ ],
10
+ "snapshot": {
11
+ "host": "glama.ai",
12
+ "port": 443,
13
+ "verdict": "WARN",
14
+ "policy": {
15
+ "minDaysRemaining": 14,
16
+ "requireIpv6Parity": false,
17
+ "requireTls13": false
18
+ },
19
+ "tlsProbe": {
20
+ "ok": true,
21
+ "verdict": "ALLOW",
22
+ "host": "glama.ai",
23
+ "port": 443,
24
+ "capturedAt": "2026-12-06T09:22:41.245Z",
25
+ "dns": {
26
+ "ipv4": [
27
+ "40.160.65.14"
28
+ ],
29
+ "ipv6": [
30
+ "2604:2dc0:14c:e00::"
31
+ ]
32
+ },
33
+ "parity": "match",
34
+ "probes": [
35
+ {
36
+ "ip": "40.160.65.14",
37
+ "family": 4,
38
+ "port": 443,
39
+ "latencyMs": 203,
40
+ "ok": true,
41
+ "verdict": "ALLOW",
42
+ "protocol": "TLSv1.3",
43
+ "cipher": "TLS_AES_128_GCM_SHA256",
44
+ "alpnProtocol": null,
45
+ "authorized": true,
46
+ "authorizationError": null,
47
+ "certificate": {
48
+ "subjectCN": "glama.ai",
49
+ "issuerCN": "YE1",
50
+ "issuerO": "Let's Encrypt",
51
+ "validFrom": "Nov 24 08:22:05 2026 GMT",
52
+ "validTo": "Feb 22 08:22:04 2027 GMT",
53
+ "daysRemaining": 77,
54
+ "fingerprint256": "6B:07:D3:EF:F5:D0:C7:0F:1B:28:01:B9:45:24:E6:54:73:3C:9A:B2:98:C7:5A:92:C6:33:BB:E2:9A:85:80:3D",
55
+ "sanCount": 1
56
+ }
57
+ },
58
+ {
59
+ "ip": "2604:2dc0:14c:e00::",
60
+ "family": 6,
61
+ "port": 443,
62
+ "latencyMs": 189,
63
+ "ok": true,
64
+ "verdict": "ALLOW",
65
+ "protocol": "TLSv1.3",
66
+ "cipher": "TLS_AES_128_GCM_SHA256",
67
+ "alpnProtocol": null,
68
+ "authorized": true,
69
+ "authorizationError": null,
70
+ "certificate": {
71
+ "subjectCN": "glama.ai",
72
+ "issuerCN": "YE1",
73
+ "issuerO": "Let's Encrypt",
74
+ "validFrom": "Nov 24 08:22:05 2026 GMT",
75
+ "validTo": "Feb 22 08:22:04 2027 GMT",
76
+ "daysRemaining": 77,
77
+ "fingerprint256": "6B:07:D3:EF:F5:D0:C7:0F:1B:28:01:B9:45:24:E6:54:73:3C:9A:B2:98:C7:5A:92:C6:33:BB:E2:9A:85:80:3D",
78
+ "sanCount": 1
79
+ }
80
+ }
81
+ ],
82
+ "reasons": []
83
+ },
84
+ "dnsAudit": {
85
+ "ok": true,
86
+ "verdict": "WARN",
87
+ "host": "glama.ai",
88
+ "capturedAt": "2026-12-06T09:22:41.051Z",
89
+ "records": {
90
+ "A": [
91
+ "40.160.65.14"
92
+ ],
93
+ "AAAA": [
94
+ "2604:2dc0:14c:e00::"
95
+ ],
96
+ "CAA": [],
97
+ "CNAME": [],
98
+ "NS": [
99
+ "isaac.ns.cloudflare.com",
100
+ "davina.ns.cloudflare.com"
101
+ ]
102
+ },
103
+ "warnings": [
104
+ "No CAA record restricts certificate issuers (ACME unrestricted)"
105
+ ],
106
+ "blockers": []
107
+ },
108
+ "blockers": [],
109
+ "warnings": [
110
+ "No CAA record restricts certificate issuers (ACME unrestricted)"
111
+ ]
112
+ },
113
+ "receipt": {
114
+ "statement": {
115
+ "spec": "edge-tls-receipt/1",
116
+ "issuedAt": "2026-12-06T09:22:41.246Z",
117
+ "clockStatus": "unattested",
118
+ "fxId": "fx_b7399d312f3d",
119
+ "publicKeyHex": "f52cbb7704f565390f62b06c4514e88f78c6f3ff26513f30824ab74503f6d3e7",
120
+ "deliverableSha256": "e92a32ac6a32127f3ec0a36124fe39f19cbd1fd19c9b4eb26484041bf4aa4fbd"
121
+ },
122
+ "signatureHex": "63c485f01d0a5bbedccb2bfdc095beb38bbcd71c10ddf3a66674b837aa2c7d525914626c2a67a34cfeecd28b9b4ee39a36a8267a1ee0ddccf5e135932dda9f0d"
123
+ },
124
+ "publicKeyHex": "f52cbb7704f565390f62b06c4514e88f78c6f3ff26513f30824ab74503f6d3e7",
125
+ "fxId": "fx_b7399d312f3d"
126
+ }
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@eyeoverthink/edge-tls-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "mcpName": "io.github.eyeoverthink/edge-tls-mcp",
5
+ "type": "module",
6
+ "description": "Zero-dependency dual-stack IPv4/IPv6 TLS handshake, cert-expiry, DNS/CAA preflight, and Ed25519-signed incident receipt MCP server.",
7
+ "license": "Apache-2.0",
8
+ "main": "./src/index.js",
9
+ "bin": {
10
+ "edge-tls-mcp": "bin/edge-tls-mcp.js"
11
+ },
12
+ "files": [
13
+ "bin/",
14
+ "src/",
15
+ "evidence/",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "scripts": {
20
+ "build": "node -e \"console.log('edge-tls-mcp zero-build ESM ready')\"",
21
+ "test": "node --test \"test/*.test.js\"",
22
+ "mcp": "node ./bin/edge-tls-mcp.js mcp"
23
+ },
24
+ "keywords": [
25
+ "mcp",
26
+ "mcp-server",
27
+ "tls",
28
+ "ssl",
29
+ "dns",
30
+ "caa",
31
+ "devops",
32
+ "sre",
33
+ "ed25519",
34
+ "zero-dependency"
35
+ ],
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/eyeoverthink/edge-tls-mcp.git"
39
+ },
40
+ "homepage": "https://github.com/eyeoverthink/edge-tls-mcp",
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "engines": {
45
+ "node": ">=22.0.0"
46
+ }
47
+ }
package/src/batch.js ADDED
@@ -0,0 +1,99 @@
1
+ // Polite, rate-limited batch TLS & DNS hygiene scorecard generator with Ed25519 signed summary.
2
+ import { gateDeploy } from './probe.js';
3
+ import { mintSnapshotReceipt } from './receipt.js';
4
+
5
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
6
+
7
+ export async function batchAudit({
8
+ hosts = [],
9
+ minDaysRemaining = 14,
10
+ delayMs = 250,
11
+ timeoutMs = 8000,
12
+ seedHex = null,
13
+ } = {}) {
14
+ const cleanHosts = [...new Set(
15
+ hosts
16
+ .map((h) => String(h || '').trim())
17
+ .filter((h) => h && !h.startsWith('#'))
18
+ )];
19
+
20
+ const rows = [];
21
+ for (let i = 0; i < cleanHosts.length; i++) {
22
+ const host = cleanHosts[i];
23
+ try {
24
+ const res = await gateDeploy({ host, minDaysRemaining, timeoutMs, seedHex });
25
+ const v4 = res.snapshot.tlsProbe.probes.find((p) => p.family === 4);
26
+ const v6 = res.snapshot.tlsProbe.probes.find((p) => p.family === 6);
27
+ const primary = v4 || v6 || null;
28
+ rows.push({
29
+ host: res.host,
30
+ verdict: res.verdict,
31
+ protocol: primary?.protocol || 'FAIL',
32
+ daysRemaining: primary?.certificate?.daysRemaining ?? null,
33
+ issuer: primary?.certificate?.issuerO || primary?.certificate?.issuerCN || null,
34
+ parity: res.snapshot.tlsProbe.parity,
35
+ caaCount: res.snapshot.dnsAudit.records.CAA.length,
36
+ latencyMs: primary?.latencyMs ?? null,
37
+ blockers: res.blockers,
38
+ warnings: res.warnings,
39
+ });
40
+ } catch (err) {
41
+ rows.push({
42
+ host,
43
+ verdict: 'BLOCK',
44
+ protocol: 'ERROR',
45
+ daysRemaining: null,
46
+ issuer: null,
47
+ parity: 'unresolved',
48
+ caaCount: 0,
49
+ latencyMs: null,
50
+ blockers: [err?.message || String(err)],
51
+ warnings: [],
52
+ });
53
+ }
54
+ if (delayMs > 0 && i < cleanHosts.length - 1) await sleep(delayMs);
55
+ }
56
+
57
+ const summary = {
58
+ capturedAt: new Date().toISOString(),
59
+ totalHosts: rows.length,
60
+ allowCount: rows.filter((r) => r.verdict === 'ALLOW').length,
61
+ warnCount: rows.filter((r) => r.verdict === 'WARN').length,
62
+ blockCount: rows.filter((r) => r.verdict === 'BLOCK').length,
63
+ missingCaaCount: rows.filter((r) => r.caaCount === 0).length,
64
+ ipv4OnlyCount: rows.filter((r) => r.parity === 'ipv4_only').length,
65
+ rows,
66
+ };
67
+
68
+ const minted = mintSnapshotReceipt(summary, { seedHex });
69
+ return {
70
+ summary,
71
+ receipt: minted.receipt,
72
+ publicKeyHex: minted.publicKeyHex,
73
+ fxId: minted.fxId,
74
+ };
75
+ }
76
+
77
+ export function renderMarkdownScorecard(batchResult, title = 'AI & MCP Ecosystem TLS/DNS Hygiene Scorecard') {
78
+ const { summary, fxId, receipt } = batchResult;
79
+ const lines = [
80
+ `# ${title}`,
81
+ '',
82
+ `- **Captured At:** \`${summary.capturedAt}\``,
83
+ `- **Hosts Audited:** \`${summary.totalHosts}\` (ALLOW: **${summary.allowCount}** · WARN: **${summary.warnCount}** · BLOCK: **${summary.blockCount}**)`,
84
+ `- **Missing DNS CAA Records:** **${summary.missingCaaCount}/${summary.totalHosts}**`,
85
+ `- **IPv4-Only (No AAAA Parity):** **${summary.ipv4OnlyCount}/${summary.totalHosts}**`,
86
+ `- **Signed Receipt:** \`${fxId}\` · SHA-256 \`${receipt.statement.deliverableSha256.slice(0, 16)}...\``,
87
+ '',
88
+ '| Host | Verdict | TLS | Cert Days | Parity | CAA | Notes |',
89
+ '| :--- | :---: | :---: | :---: | :---: | :---: | :--- |',
90
+ ];
91
+
92
+ for (const r of summary.rows) {
93
+ const notes = [...r.blockers, ...r.warnings].join('; ') || 'Clean';
94
+ const days = r.daysRemaining === null ? '—' : `${r.daysRemaining}d`;
95
+ lines.push(`| \`${r.host}\` | **${r.verdict}** | \`${r.protocol}\` | ${days} | \`${r.parity}\` | ${r.caaCount} | ${notes} |`);
96
+ }
97
+ lines.push('');
98
+ return lines.join('\n');
99
+ }
package/src/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { probeEndpoint, auditDns, gateDeploy } from './probe.js';
2
+ export { batchAudit, renderMarkdownScorecard } from './batch.js';
3
+ export { mintSnapshotReceipt, verifySnapshotReceipt, canonicalJson, sha256Hex } from './receipt.js';
4
+ export { createMcpHandler, EDGE_TLS_TOOLS, SERVER_INFO, startStdioMcpServer } from './mcp-server.js';
@@ -0,0 +1,245 @@
1
+ // Zero-dependency stdio JSON-RPC 2.0 MCP Server for @eyeoverthink/edge-tls-mcp.
2
+ import fs from 'node:fs';
3
+ import readline from 'node:readline';
4
+ import { probeEndpoint, auditDns, gateDeploy } from './probe.js';
5
+ import { verifySnapshotReceipt } from './receipt.js';
6
+
7
+ const PKG_VERSION = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
8
+
9
+ export const SERVER_INFO = {
10
+ name: '@eyeoverthink/edge-tls-mcp',
11
+ version: PKG_VERSION,
12
+ };
13
+
14
+ export const EDGE_TLS_TOOLS = [
15
+ {
16
+ name: 'tls_probe_endpoint',
17
+ title: 'Probe Dual-Stack IPv4/IPv6 TLS Handshake & Certificate Health',
18
+ description:
19
+ 'Probe a live host and port over both IPv4 and IPv6 to inspect TLS protocol/cipher negotiation, fatal TLS handshake alerts, certificate chain validity, days remaining, and dual-stack parity. Call this to diagnose live TLS outages or certificate expiry on an endpoint; do not use for DNS/CAA-only checks (use tls_audit_dns) or signed pre-deploy gating (use tls_gate_deploy). Performs live network TCP/TLS probes and returns ok: false with verdict "BLOCK" and exact error codes on any handshake or certificate failure.',
20
+ annotations: {
21
+ title: 'Probe Live Dual-Stack TLS Endpoint',
22
+ readOnlyHint: true,
23
+ destructiveHint: false,
24
+ idempotentHint: true,
25
+ openWorldHint: true,
26
+ },
27
+ inputSchema: {
28
+ type: 'object',
29
+ additionalProperties: false,
30
+ required: ['host'],
31
+ properties: {
32
+ host: { type: 'string', minLength: 1, description: 'Target hostname or IP address (e.g., glama.ai or example.com).' },
33
+ port: { type: 'integer', minimum: 1, maximum: 65535, description: 'TCP port to probe (default 443).' },
34
+ timeoutMs: { type: 'integer', minimum: 500, maximum: 30000, description: 'Per-socket handshake timeout in milliseconds (default 8000).' },
35
+ },
36
+ },
37
+ outputSchema: {
38
+ type: 'object',
39
+ required: ['ok', 'verdict', 'host', 'port', 'parity', 'probes', 'reasons'],
40
+ properties: {
41
+ ok: { type: 'boolean', description: 'True only when every resolved IPv4/IPv6 target completed an authorized TLS handshake with an unexpired certificate.' },
42
+ verdict: { type: 'string', enum: ['ALLOW', 'BLOCK'], description: 'Fail-closed probe verdict.' },
43
+ host: { type: 'string', description: 'Sanitized hostname probed.' },
44
+ port: { type: 'integer', description: 'TCP port probed.' },
45
+ capturedAt: { type: 'string', description: 'ISO-8601 UTC timestamp of probe capture.' },
46
+ dns: { type: 'object', description: 'Resolved A (ipv4) and AAAA (ipv6) address arrays.' },
47
+ parity: { type: 'string', enum: ['match', 'mismatch', 'ipv4_only', 'ipv6_only', 'unresolved', 'single_stack'], description: 'Dual-stack IPv4 vs IPv6 TLS outcome parity.' },
48
+ probes: { type: 'array', items: { type: 'object', description: 'Per-IP TLS handshake and certificate telemetry.' }, description: 'Individual IPv4/IPv6 probe results.' },
49
+ reasons: { type: 'array', items: { type: 'string', description: 'Failure diagnostic.' }, description: 'List of exact handshake, cert, or parity failure reasons.' },
50
+ },
51
+ },
52
+ },
53
+ {
54
+ name: 'tls_audit_dns',
55
+ title: 'Audit DNS A/AAAA Parity & CAA Certificate-Issuer Policy',
56
+ description:
57
+ 'Resolve A, AAAA, CAA, CNAME, and NS records for a domain to detect missing IPv6 parity, ACME CAA blocks, or unresolved endpoints before certificate renewal or deployment. Call this when inspecting DNS and certificate-issuer policy independently; do not use for live TLS handshake probing (use tls_probe_endpoint) or signed deploy gating (use tls_gate_deploy). Performs read-only DNS queries and returns verdict "ALLOW", "WARN", or "BLOCK".',
58
+ annotations: {
59
+ title: 'Audit DNS & CAA Records',
60
+ readOnlyHint: true,
61
+ destructiveHint: false,
62
+ idempotentHint: true,
63
+ openWorldHint: true,
64
+ },
65
+ inputSchema: {
66
+ type: 'object',
67
+ additionalProperties: false,
68
+ required: ['host'],
69
+ properties: {
70
+ host: { type: 'string', minLength: 1, description: 'Target domain name to resolve (e.g., glama.ai).' },
71
+ },
72
+ },
73
+ outputSchema: {
74
+ type: 'object',
75
+ required: ['ok', 'verdict', 'host', 'records', 'warnings', 'blockers'],
76
+ properties: {
77
+ ok: { type: 'boolean', description: 'True when no DNS blockers were found.' },
78
+ verdict: { type: 'string', enum: ['ALLOW', 'WARN', 'BLOCK'], description: 'DNS preflight verdict.' },
79
+ host: { type: 'string', description: 'Sanitized domain name queried.' },
80
+ capturedAt: { type: 'string', description: 'ISO-8601 UTC timestamp of DNS audit.' },
81
+ records: { type: 'object', description: 'Resolved A, AAAA, CAA, CNAME, and NS record lists.' },
82
+ warnings: { type: 'array', items: { type: 'string', description: 'Non-blocking DNS warning.' }, description: 'Advisory warnings such as missing AAAA or CAA records.' },
83
+ blockers: { type: 'array', items: { type: 'string', description: 'Blocking DNS error.' }, description: 'Fatal DNS resolution failures.' },
84
+ },
85
+ },
86
+ },
87
+ {
88
+ name: 'tls_gate_deploy',
89
+ title: 'Run Fail-Closed TLS/DNS Deploy Gate & Mint Ed25519 Receipt',
90
+ description:
91
+ 'Execute a combined dual-stack TLS handshake probe and DNS/CAA audit against configurable expiry/TLS-1.3/IPv6-parity policies, returning a fail-closed ALLOW/WARN/BLOCK verdict and an Ed25519-signed cryptographic incident receipt. Call this before promoting an edge deployment or to capture tamper-evident outage evidence; do not use to verify an existing receipt (use tls_verify_snapshot). Non-idempotent because each call captures live network state and stamps a fresh timestamp and ephemeral Ed25519 key unless a 64-hex seedHex is provided.',
92
+ annotations: {
93
+ title: 'Gate Deploy & Mint Signed TLS Receipt',
94
+ readOnlyHint: true,
95
+ destructiveHint: false,
96
+ idempotentHint: false,
97
+ openWorldHint: true,
98
+ },
99
+ inputSchema: {
100
+ type: 'object',
101
+ additionalProperties: false,
102
+ required: ['host'],
103
+ properties: {
104
+ host: { type: 'string', minLength: 1, description: 'Target hostname to gate.' },
105
+ port: { type: 'integer', minimum: 1, maximum: 65535, description: 'TCP port (default 443).' },
106
+ minDaysRemaining: { type: 'integer', minimum: 1, description: 'Minimum certificate days remaining required to pass (default 14).' },
107
+ requireIpv6Parity: { type: 'boolean', description: 'Block if IPv4 and IPv6 do not both pass TLS handshakes (default false).' },
108
+ requireTls13: { type: 'boolean', description: 'Block if any probe negotiates below TLSv1.3 (default false).' },
109
+ timeoutMs: { type: 'integer', minimum: 500, maximum: 30000, description: 'Per-socket handshake timeout in ms (default 8000).' },
110
+ seedHex: { type: 'string', description: 'Optional 64-hex Ed25519 signing seed for stable signer identity; ephemeral key generated if omitted.' },
111
+ },
112
+ },
113
+ outputSchema: {
114
+ type: 'object',
115
+ required: ['ok', 'verdict', 'host', 'port', 'blockers', 'warnings', 'snapshot', 'receipt', 'publicKeyHex', 'fxId'],
116
+ properties: {
117
+ ok: { type: 'boolean', description: 'True when verdict is ALLOW or WARN; false on BLOCK.' },
118
+ verdict: { type: 'string', enum: ['ALLOW', 'WARN', 'BLOCK'], description: 'Fail-closed deploy/incident gate decision.' },
119
+ host: { type: 'string', description: 'Target hostname.' },
120
+ port: { type: 'integer', description: 'Target port.' },
121
+ blockers: { type: 'array', items: { type: 'string', description: 'Blocking failure reason.' }, description: 'All policy or handshake blockers.' },
122
+ warnings: { type: 'array', items: { type: 'string', description: 'Advisory warning.' }, description: 'All non-blocking warnings.' },
123
+ snapshot: { type: 'object', description: 'Canonical live TLS + DNS evidence payload bound into the receipt.' },
124
+ receipt: { type: 'object', description: 'Ed25519-signed edge-tls-receipt/1 cryptographic receipt.' },
125
+ publicKeyHex: { type: 'string', description: '64-hex Ed25519 public key used to sign the receipt.' },
126
+ fxId: { type: 'string', description: 'Deterministic key fingerprint.' },
127
+ },
128
+ },
129
+ },
130
+ {
131
+ name: 'tls_verify_snapshot',
132
+ title: 'Verify Ed25519-Signed TLS Incident Snapshot Receipt Offline',
133
+ description:
134
+ 'Verify an Ed25519-signed edge-tls-receipt/1 snapshot receipt offline against its payload digest and caller-pinned public keys. Call this when auditing a captured outage or pre-deploy receipt for tampering; do not use to run live network probes (use tls_probe_endpoint or tls_gate_deploy). Runs strictly offline in memory; omitting expectedPublicKeys holds intact receipts at integrity_only (ok: false) unless allowUnpinned: true is explicitly set for demos.',
135
+ annotations: {
136
+ title: 'Verify Signed TLS Snapshot Receipt Offline',
137
+ readOnlyHint: true,
138
+ destructiveHint: false,
139
+ idempotentHint: true,
140
+ openWorldHint: false,
141
+ },
142
+ inputSchema: {
143
+ type: 'object',
144
+ additionalProperties: false,
145
+ required: ['receipt'],
146
+ properties: {
147
+ receipt: { type: 'object', description: 'Signed edge-tls-receipt/1 receipt object returned by tls_gate_deploy.' },
148
+ snapshot: { description: 'Optional snapshot object or canonical JSON string to verify against deliverableSha256.' },
149
+ expectedPublicKeys: {
150
+ type: 'array',
151
+ items: { type: 'string', description: 'Trusted 64-hex Ed25519 public key.' },
152
+ description: 'Caller-pinned signer public key(s) allowed to have signed the receipt.',
153
+ },
154
+ allowUnpinned: { type: 'boolean', description: 'Accept any valid signer when expectedPublicKeys is omitted (demos only).' },
155
+ },
156
+ },
157
+ outputSchema: {
158
+ type: 'object',
159
+ required: ['ok', 'outcome'],
160
+ properties: {
161
+ ok: { type: 'boolean', description: 'True only when Ed25519 signature, optional snapshot digest, and signer trust all pass.' },
162
+ outcome: { type: 'string', enum: ['verified', 'verification_failed', 'rejected_malformed', 'integrity_only', 'untrusted_signer'], description: 'Exact deterministic verification outcome.' },
163
+ deliverable: { type: 'string', description: 'Snapshot digest check status (verified, not_checked, or verification_failed).' },
164
+ trust: { type: 'string', description: 'Signer trust classification (pinned, unpinned, or rejected).' },
165
+ fxId: { type: 'string', description: 'Verified signer fingerprint when valid.' },
166
+ reason: { type: 'string', description: 'Exact failure or integrity_only explanation.' },
167
+ },
168
+ },
169
+ },
170
+ ];
171
+
172
+ async function runTool(name, args = {}) {
173
+ switch (name) {
174
+ case 'tls_probe_endpoint':
175
+ return probeEndpoint(args);
176
+ case 'tls_audit_dns':
177
+ return auditDns(args);
178
+ case 'tls_gate_deploy':
179
+ return gateDeploy(args);
180
+ case 'tls_verify_snapshot':
181
+ return verifySnapshotReceipt(args.receipt, {
182
+ snapshot: args.snapshot ?? null,
183
+ expectedPublicKeys: args.expectedPublicKeys ?? null,
184
+ allowUnpinned: args.allowUnpinned === true,
185
+ });
186
+ default:
187
+ throw new Error(`Unknown tool: ${name}`);
188
+ }
189
+ }
190
+
191
+ export function createMcpHandler() {
192
+ return async function handleRequest(msg) {
193
+ if (!msg || typeof msg !== 'object' || msg.jsonrpc !== '2.0') {
194
+ return { jsonrpc: '2.0', id: null, error: { code: -32600, message: 'Invalid JSON-RPC 2.0 request' } };
195
+ }
196
+ const { id, method, params } = msg;
197
+ if (id === undefined) return null;
198
+
199
+ try {
200
+ if (method === 'initialize') {
201
+ const protocolVersion = typeof params?.protocolVersion === 'string' ? params.protocolVersion : '2025-11-25';
202
+ return {
203
+ jsonrpc: '2.0',
204
+ id,
205
+ result: { protocolVersion, capabilities: { tools: {} }, serverInfo: SERVER_INFO },
206
+ };
207
+ }
208
+ if (method === 'ping') return { jsonrpc: '2.0', id, result: {} };
209
+ if (method === 'tools/list') return { jsonrpc: '2.0', id, result: { tools: EDGE_TLS_TOOLS } };
210
+ if (method === 'tools/call') {
211
+ const out = await runTool(params?.name, params?.arguments || {});
212
+ return {
213
+ jsonrpc: '2.0',
214
+ id,
215
+ result: {
216
+ isError: false,
217
+ structuredContent: out,
218
+ content: [{ type: 'text', text: JSON.stringify(out, null, 2) }],
219
+ },
220
+ };
221
+ }
222
+ return { jsonrpc: '2.0', id, error: { code: -32601, message: `Method not found: ${method}` } };
223
+ } catch (err) {
224
+ return { jsonrpc: '2.0', id, error: { code: -32000, message: err?.message || String(err) } };
225
+ }
226
+ };
227
+ }
228
+
229
+ export function startStdioMcpServer() {
230
+ const handle = createMcpHandler();
231
+ const rl = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });
232
+ rl.on('line', async (line) => {
233
+ const trimmed = line.trim();
234
+ if (!trimmed) return;
235
+ let parsed;
236
+ try {
237
+ parsed = JSON.parse(trimmed);
238
+ } catch {
239
+ process.stdout.write(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } }) + '\n');
240
+ return;
241
+ }
242
+ const resp = await handle(parsed);
243
+ if (resp) process.stdout.write(JSON.stringify(resp) + '\n');
244
+ });
245
+ }
package/src/probe.js ADDED
@@ -0,0 +1,288 @@
1
+ // Zero-dependency dual-stack IPv4/IPv6 TLS handshake, cert-expiry, and DNS/CAA preflight auditor.
2
+ import tls from 'node:tls';
3
+ import dns from 'node:dns/promises';
4
+ import net from 'node:net';
5
+ import { mintSnapshotReceipt } from './receipt.js';
6
+
7
+ function sanitizeHost(raw) {
8
+ let h = String(raw ?? '').trim().toLowerCase();
9
+ if (h.startsWith('https://')) h = h.slice(8);
10
+ else if (h.startsWith('http://')) h = h.slice(7);
11
+ const slash = h.indexOf('/');
12
+ if (slash !== -1) h = h.slice(0, slash);
13
+ const colon = h.lastIndexOf(':');
14
+ if (colon !== -1 && !h.includes(']')) h = h.slice(0, colon);
15
+ if (!h || h.length > 253 || /[^a-z0-9.\-:\[\]]/.test(h)) {
16
+ throw new Error('Invalid hostname');
17
+ }
18
+ return h;
19
+ }
20
+
21
+ function parseSingleTlsProbe({ host, ip, family, port, servername, timeoutMs }) {
22
+ return new Promise((resolve) => {
23
+ const started = Date.now();
24
+ let settled = false;
25
+ const done = (result) => {
26
+ if (settled) return;
27
+ settled = true;
28
+ resolve({ ip, family, port, latencyMs: Date.now() - started, ...result });
29
+ };
30
+
31
+ const socket = tls.connect({
32
+ host: ip,
33
+ port,
34
+ servername,
35
+ rejectUnauthorized: false, // inspect cert & capture authorizationError explicitly
36
+ timeout: timeoutMs,
37
+ });
38
+
39
+ const timer = setTimeout(() => {
40
+ socket.destroy();
41
+ done({
42
+ ok: false,
43
+ verdict: 'BLOCK',
44
+ errorCode: 'ETIMEDOUT',
45
+ errorMessage: `TLS handshake timed out after ${timeoutMs}ms`,
46
+ });
47
+ }, timeoutMs);
48
+
49
+ socket.once('secureConnect', () => {
50
+ clearTimeout(timer);
51
+ const protocol = socket.getProtocol();
52
+ const cipher = socket.getCipher();
53
+ const alpnProtocol = socket.alpnProtocol || null;
54
+ const authorized = socket.authorized;
55
+ const authorizationError = socket.authorizationError || null;
56
+ const cert = socket.getPeerCertificate(false);
57
+ socket.end();
58
+
59
+ let validFrom = null;
60
+ let validTo = null;
61
+ let daysRemaining = null;
62
+ if (cert && cert.valid_to) {
63
+ validFrom = cert.valid_from || null;
64
+ validTo = cert.valid_to;
65
+ const msLeft = Date.parse(cert.valid_to) - Date.now();
66
+ daysRemaining = Number.isFinite(msLeft) ? Math.floor(msLeft / 86400000) : null;
67
+ }
68
+
69
+ const sanList = cert?.subjectaltname
70
+ ? cert.subjectaltname.split(',').map((s) => s.trim()).filter(Boolean)
71
+ : [];
72
+
73
+ const ok = Boolean(authorized && (daysRemaining === null || daysRemaining > 0));
74
+ done({
75
+ ok,
76
+ verdict: ok ? 'ALLOW' : 'BLOCK',
77
+ protocol,
78
+ cipher: cipher?.name || null,
79
+ alpnProtocol,
80
+ authorized,
81
+ authorizationError,
82
+ certificate: cert && Object.keys(cert).length > 0 ? {
83
+ subjectCN: cert.subject?.CN || null,
84
+ issuerCN: cert.issuer?.CN || null,
85
+ issuerO: cert.issuer?.O || null,
86
+ validFrom,
87
+ validTo,
88
+ daysRemaining,
89
+ fingerprint256: cert.fingerprint256 || null,
90
+ sanCount: sanList.length,
91
+ } : null,
92
+ });
93
+ });
94
+
95
+ socket.once('error', (err) => {
96
+ clearTimeout(timer);
97
+ done({
98
+ ok: false,
99
+ verdict: 'BLOCK',
100
+ errorCode: err.code || 'TLS_HANDSHAKE_ERROR',
101
+ errorMessage: err.message || String(err),
102
+ });
103
+ });
104
+ });
105
+ }
106
+
107
+ export async function probeEndpoint({ host, port = 443, timeoutMs = 8000 } = {}) {
108
+ const cleanHost = sanitizeHost(host);
109
+ const p = Number.isInteger(port) && port >= 1 && port <= 65535 ? port : 443;
110
+ const t = Number.isInteger(timeoutMs) && timeoutMs >= 500 && timeoutMs <= 30000 ? timeoutMs : 8000;
111
+
112
+ let ipv4 = [];
113
+ let ipv6 = [];
114
+ if (net.isIPv4(cleanHost)) {
115
+ ipv4 = [cleanHost];
116
+ } else if (net.isIPv6(cleanHost)) {
117
+ ipv6 = [cleanHost];
118
+ } else {
119
+ const [r4, r6] = await Promise.allSettled([dns.resolve4(cleanHost), dns.resolve6(cleanHost)]);
120
+ if (r4.status === 'fulfilled') ipv4 = r4.value;
121
+ if (r6.status === 'fulfilled') ipv6 = r6.value;
122
+ }
123
+
124
+ const targets = [];
125
+ if (ipv4[0]) targets.push({ ip: ipv4[0], family: 4 });
126
+ if (ipv6[0]) targets.push({ ip: ipv6[0], family: 6 });
127
+
128
+ if (targets.length === 0) {
129
+ return {
130
+ ok: false,
131
+ verdict: 'BLOCK',
132
+ host: cleanHost,
133
+ port: p,
134
+ capturedAt: new Date().toISOString(),
135
+ dns: { ipv4: [], ipv6: [] },
136
+ parity: 'unresolved',
137
+ probes: [],
138
+ reasons: ['DNS resolution returned no A or AAAA records'],
139
+ };
140
+ }
141
+
142
+ const probes = await Promise.all(
143
+ targets.map(({ ip, family }) =>
144
+ parseSingleTlsProbe({
145
+ host: cleanHost,
146
+ ip,
147
+ family,
148
+ port: p,
149
+ servername: net.isIP(cleanHost) ? undefined : cleanHost,
150
+ timeoutMs: t,
151
+ })
152
+ )
153
+ );
154
+
155
+ const v4 = probes.find((x) => x.family === 4) || null;
156
+ const v6 = probes.find((x) => x.family === 6) || null;
157
+
158
+ let parity = 'single_stack';
159
+ if (v4 && v6) {
160
+ parity = v4.ok === v6.ok ? 'match' : 'mismatch';
161
+ } else if (v4) {
162
+ parity = 'ipv4_only';
163
+ } else if (v6) {
164
+ parity = 'ipv6_only';
165
+ }
166
+
167
+ const reasons = [];
168
+ for (const pr of probes) {
169
+ if (!pr.ok) {
170
+ reasons.push(`IPv${pr.family} (${pr.ip}) failed: ${pr.errorCode || pr.authorizationError || 'untrusted'}`);
171
+ }
172
+ }
173
+ if (parity === 'mismatch') {
174
+ reasons.push('Dual-stack IPv4/IPv6 TLS parity mismatch');
175
+ }
176
+
177
+ const allOk = probes.every((x) => x.ok);
178
+ return {
179
+ ok: allOk,
180
+ verdict: allOk ? 'ALLOW' : 'BLOCK',
181
+ host: cleanHost,
182
+ port: p,
183
+ capturedAt: new Date().toISOString(),
184
+ dns: { ipv4, ipv6 },
185
+ parity,
186
+ probes,
187
+ reasons,
188
+ };
189
+ }
190
+
191
+ export async function auditDns({ host } = {}) {
192
+ const cleanHost = sanitizeHost(host);
193
+ const [a, aaaa, caa, cname, ns] = await Promise.allSettled([
194
+ dns.resolve4(cleanHost),
195
+ dns.resolve6(cleanHost),
196
+ dns.resolveCaa(cleanHost),
197
+ dns.resolveCname(cleanHost),
198
+ dns.resolveNs(cleanHost),
199
+ ]);
200
+
201
+ const records = {
202
+ A: a.status === 'fulfilled' ? a.value : [],
203
+ AAAA: aaaa.status === 'fulfilled' ? aaaa.value : [],
204
+ CAA: caa.status === 'fulfilled' ? caa.value : [],
205
+ CNAME: cname.status === 'fulfilled' ? cname.value : [],
206
+ NS: ns.status === 'fulfilled' ? ns.value : [],
207
+ };
208
+
209
+ const warnings = [];
210
+ const blockers = [];
211
+ if (records.A.length === 0 && records.AAAA.length === 0 && records.CNAME.length === 0) {
212
+ blockers.push('No A, AAAA, or CNAME records resolved');
213
+ }
214
+ if (records.A.length > 0 && records.AAAA.length === 0) {
215
+ warnings.push('No AAAA (IPv6) record published');
216
+ }
217
+ if (records.CAA.length === 0) {
218
+ warnings.push('No CAA record restricts certificate issuers (ACME unrestricted)');
219
+ }
220
+
221
+ const verdict = blockers.length > 0 ? 'BLOCK' : (warnings.length > 0 ? 'WARN' : 'ALLOW');
222
+ return {
223
+ ok: blockers.length === 0,
224
+ verdict,
225
+ host: cleanHost,
226
+ capturedAt: new Date().toISOString(),
227
+ records,
228
+ warnings,
229
+ blockers,
230
+ };
231
+ }
232
+
233
+ export async function gateDeploy({
234
+ host,
235
+ port = 443,
236
+ minDaysRemaining = 14,
237
+ requireIpv6Parity = false,
238
+ requireTls13 = false,
239
+ timeoutMs = 8000,
240
+ seedHex = null,
241
+ } = {}) {
242
+ const [tlsProbe, dnsAudit] = await Promise.all([
243
+ probeEndpoint({ host, port, timeoutMs }),
244
+ auditDns({ host }),
245
+ ]);
246
+
247
+ const blockers = [...tlsProbe.reasons, ...dnsAudit.blockers];
248
+ const warnings = [...dnsAudit.warnings];
249
+
250
+ for (const pr of tlsProbe.probes) {
251
+ const days = pr.certificate?.daysRemaining;
252
+ if (typeof days === 'number' && days < minDaysRemaining) {
253
+ blockers.push(`IPv${pr.family} certificate expires in ${days} day(s) (< ${minDaysRemaining}d threshold)`);
254
+ }
255
+ if (requireTls13 && pr.ok && pr.protocol !== 'TLSv1.3') {
256
+ blockers.push(`IPv${pr.family} negotiated ${pr.protocol} (TLSv1.3 required)`);
257
+ }
258
+ }
259
+ if (requireIpv6Parity && tlsProbe.parity !== 'match') {
260
+ blockers.push(`Dual-stack IPv6 parity required (observed: ${tlsProbe.parity})`);
261
+ }
262
+
263
+ const verdict = blockers.length > 0 ? 'BLOCK' : (warnings.length > 0 ? 'WARN' : 'ALLOW');
264
+ const snapshot = {
265
+ host: tlsProbe.host,
266
+ port: tlsProbe.port,
267
+ verdict,
268
+ policy: { minDaysRemaining, requireIpv6Parity, requireTls13 },
269
+ tlsProbe,
270
+ dnsAudit,
271
+ blockers,
272
+ warnings,
273
+ };
274
+
275
+ const minted = mintSnapshotReceipt(snapshot, { seedHex });
276
+ return {
277
+ ok: verdict !== 'BLOCK',
278
+ verdict,
279
+ host: tlsProbe.host,
280
+ port: tlsProbe.port,
281
+ blockers,
282
+ warnings,
283
+ snapshot,
284
+ receipt: minted.receipt,
285
+ publicKeyHex: minted.publicKeyHex,
286
+ fxId: minted.fxId,
287
+ };
288
+ }
package/src/receipt.js ADDED
@@ -0,0 +1,126 @@
1
+ // Pure Node.js Ed25519 receipt signing & verification for live TLS/DNS incident snapshots.
2
+ import crypto from 'node:crypto';
3
+
4
+ export function canonicalJson(val) {
5
+ if (val === null || typeof val !== 'object') return JSON.stringify(val);
6
+ if (Array.isArray(val)) return '[' + val.map(canonicalJson).join(',') + ']';
7
+ const keys = Object.keys(val).sort();
8
+ return '{' + keys.map((k) => JSON.stringify(k) + ':' + canonicalJson(val[k])).join(',') + '}';
9
+ }
10
+
11
+ export function sha256Hex(str) {
12
+ return crypto.createHash('sha256').update(str, 'utf8').digest('hex');
13
+ }
14
+
15
+ function keypairFromSeedHex(seedHex) {
16
+ if (typeof seedHex !== 'string' || !/^[0-9a-fA-F]{64}$/.test(seedHex)) {
17
+ throw new Error('seedHex must be 64 hex characters');
18
+ }
19
+ const seed = Buffer.from(seedHex, 'hex');
20
+ // PKCS#8 DER prefix for 32-byte Ed25519 private key
21
+ const pkcs8Prefix = Buffer.from('302e020100300506032b657004220420', 'hex');
22
+ const privateKey = crypto.createPrivateKey({
23
+ key: Buffer.concat([pkcs8Prefix, seed]),
24
+ format: 'der',
25
+ type: 'pkcs8',
26
+ });
27
+ const publicKey = crypto.createPublicKey(privateKey);
28
+ return { privateKey, publicKey };
29
+ }
30
+
31
+ function rawPublicKeyHex(publicKey) {
32
+ const spki = publicKey.export({ format: 'der', type: 'spki' });
33
+ return spki.subarray(spki.length - 32).toString('hex');
34
+ }
35
+
36
+ function publicKeyFromHex(pubHex) {
37
+ if (typeof pubHex !== 'string' || !/^[0-9a-fA-F]{64}$/.test(pubHex)) {
38
+ throw new Error('publicKeyHex must be 64 hex characters');
39
+ }
40
+ const spkiPrefix = Buffer.from('302a300506032b6570032100', 'hex');
41
+ return crypto.createPublicKey({
42
+ key: Buffer.concat([spkiPrefix, Buffer.from(pubHex, 'hex')]),
43
+ format: 'der',
44
+ type: 'spki',
45
+ });
46
+ }
47
+
48
+ export function mintSnapshotReceipt(snapshot, { seedHex = null } = {}) {
49
+ const { privateKey, publicKey } = seedHex
50
+ ? keypairFromSeedHex(seedHex)
51
+ : crypto.generateKeyPairSync('ed25519');
52
+ const publicKeyHex = rawPublicKeyHex(publicKey);
53
+ const fxId = 'fx_' + sha256Hex(publicKeyHex).slice(0, 12);
54
+ const deliverable = canonicalJson(snapshot);
55
+ const deliverableSha256 = sha256Hex(deliverable);
56
+ const statement = {
57
+ spec: 'edge-tls-receipt/1',
58
+ issuedAt: new Date().toISOString(),
59
+ clockStatus: 'unattested',
60
+ fxId,
61
+ publicKeyHex,
62
+ deliverableSha256,
63
+ };
64
+ const statementCanon = canonicalJson(statement);
65
+ const signatureHex = crypto.sign(null, Buffer.from(statementCanon, 'utf8'), privateKey).toString('hex');
66
+ return {
67
+ receipt: { statement, signatureHex },
68
+ deliverable,
69
+ publicKeyHex,
70
+ fxId,
71
+ };
72
+ }
73
+
74
+ export function verifySnapshotReceipt(receipt, { snapshot = null, expectedPublicKeys = null, allowUnpinned = false } = {}) {
75
+ if (!receipt || typeof receipt !== 'object' || !receipt.statement || typeof receipt.signatureHex !== 'string') {
76
+ return { ok: false, outcome: 'rejected_malformed', reason: 'Malformed receipt object' };
77
+ }
78
+ const { statement, signatureHex } = receipt;
79
+ if (statement.spec !== 'edge-tls-receipt/1' || typeof statement.publicKeyHex !== 'string') {
80
+ return { ok: false, outcome: 'rejected_malformed', reason: 'Unsupported receipt spec or missing publicKeyHex' };
81
+ }
82
+ let pubKey;
83
+ try {
84
+ pubKey = publicKeyFromHex(statement.publicKeyHex);
85
+ } catch (e) {
86
+ return { ok: false, outcome: 'verification_failed', reason: e.message };
87
+ }
88
+ const statementCanon = canonicalJson(statement);
89
+ let sigOk = false;
90
+ try {
91
+ sigOk = crypto.verify(null, Buffer.from(statementCanon, 'utf8'), pubKey, Buffer.from(signatureHex, 'hex'));
92
+ } catch {
93
+ sigOk = false;
94
+ }
95
+ if (!sigOk) {
96
+ return { ok: false, outcome: 'verification_failed', deliverable: 'not_checked', reason: 'Ed25519 signature invalid' };
97
+ }
98
+
99
+ let deliverableStatus = 'not_checked';
100
+ if (snapshot !== null && snapshot !== undefined) {
101
+ const canon = typeof snapshot === 'string' ? snapshot : canonicalJson(snapshot);
102
+ if (sha256Hex(canon) !== statement.deliverableSha256) {
103
+ return { ok: false, outcome: 'verification_failed', deliverable: 'verification_failed', reason: 'Snapshot digest mismatch' };
104
+ }
105
+ deliverableStatus = 'verified';
106
+ }
107
+
108
+ const pinned = Array.isArray(expectedPublicKeys) && expectedPublicKeys.length > 0;
109
+ if (pinned) {
110
+ const allowed = expectedPublicKeys.map((k) => String(k).toLowerCase());
111
+ if (!allowed.includes(statement.publicKeyHex.toLowerCase())) {
112
+ return { ok: false, outcome: 'untrusted_signer', deliverable: deliverableStatus, trust: 'rejected', reason: 'Signer not in expectedPublicKeys' };
113
+ }
114
+ return { ok: true, outcome: 'verified', deliverable: deliverableStatus, trust: 'pinned', fxId: statement.fxId };
115
+ }
116
+ if (allowUnpinned) {
117
+ return { ok: true, outcome: 'verified', deliverable: deliverableStatus, trust: 'unpinned', fxId: statement.fxId };
118
+ }
119
+ return {
120
+ ok: false,
121
+ outcome: 'integrity_only',
122
+ deliverable: deliverableStatus,
123
+ trust: 'unpinned',
124
+ reason: 'Signature valid, but expectedPublicKeys not provided (pass allowUnpinned: true for demos)',
125
+ };
126
+ }