web-agent-bridge 3.3.0 → 3.4.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 +12 -0
- package/README.ar.md +18 -0
- package/README.md +198 -1664
- package/bin/wab-init.js +223 -0
- package/examples/azure-dns-wab.js +83 -0
- package/examples/cloudflare-wab-dns.js +121 -0
- package/examples/cpanel-wab-dns.js +114 -0
- package/examples/dns-discovery-agent.js +166 -0
- package/examples/gcp-dns-wab.js +76 -0
- package/examples/governance-agent.js +169 -0
- package/examples/plesk-wab-dns.js +103 -0
- package/examples/route53-wab-dns.js +144 -0
- package/examples/safe-mode-agent.js +96 -0
- package/examples/wab-sign.js +74 -0
- package/examples/wab-verify.js +60 -0
- package/package.json +5 -5
- package/public/.well-known/wab.json +28 -0
- package/public/activate.html +368 -0
- package/public/adoption-metrics.html +188 -0
- package/public/api.html +1 -1
- package/public/azure-dns-integration.html +289 -0
- package/public/cloudflare-integration.html +380 -0
- package/public/cpanel-integration.html +398 -0
- package/public/css/styles.css +28 -0
- package/public/dashboard.html +1 -0
- package/public/dns.html +101 -172
- package/public/docs.html +1 -0
- package/public/gcp-dns-integration.html +318 -0
- package/public/growth.html +4 -2
- package/public/index.html +227 -31
- package/public/integrations.html +1 -1
- package/public/js/activate.js +145 -0
- package/public/js/auth-nav.js +34 -0
- package/public/js/dns.js +438 -0
- package/public/openapi.json +89 -0
- package/public/plesk-integration.html +375 -0
- package/public/premium.html +1 -1
- package/public/provider-onboarding.html +172 -0
- package/public/provider-sandbox.html +134 -0
- package/public/providers.html +359 -0
- package/public/registrar-integrations.html +141 -0
- package/public/robots.txt +12 -0
- package/public/route53-integration.html +531 -0
- package/public/shieldqr.html +231 -0
- package/public/sitemap.xml +6 -0
- package/public/wab-trust.html +200 -0
- package/public/wab-vs-protocols.html +210 -0
- package/public/whitepaper.html +449 -0
- package/sdk/auto-discovery.js +288 -0
- package/sdk/governance.js +262 -0
- package/sdk/index.js +13 -0
- package/sdk/package.json +2 -2
- package/sdk/safe-mode.js +221 -0
- package/server/index.js +144 -5
- package/server/migrations/007_governance.sql +106 -0
- package/server/migrations/008_plans.sql +144 -0
- package/server/migrations/009_shieldqr.sql +30 -0
- package/server/migrations/010_extended_trust.sql +33 -0
- package/server/models/adapters/mysql.js +1 -1
- package/server/models/adapters/postgresql.js +1 -1
- package/server/models/db.js +60 -1
- package/server/routes/admin-plans.js +76 -0
- package/server/routes/admin-premium.js +4 -2
- package/server/routes/admin-shieldqr.js +90 -0
- package/server/routes/admin-trust-monitor.js +83 -0
- package/server/routes/admin.js +289 -1
- package/server/routes/billing.js +16 -4
- package/server/routes/discovery.js +1933 -2
- package/server/routes/governance.js +208 -0
- package/server/routes/plans.js +33 -0
- package/server/routes/providers.js +650 -0
- package/server/routes/shieldqr.js +88 -0
- package/server/services/email.js +29 -0
- package/server/services/governance.js +466 -0
- package/server/services/plans.js +214 -0
- package/server/services/premium.js +1 -1
- package/server/services/provider-clients.js +740 -0
- package/server/services/shieldqr.js +322 -0
- package/server/services/ssl-inspector.js +42 -0
- package/server/services/ssl-monitor.js +167 -0
- package/server/services/stripe.js +18 -5
- package/server/services/vision.js +1 -1
- package/server/services/wab-crypto.js +178 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WAB Crypto v1.3 — Ed25519 signing + canonical JSON.
|
|
3
|
+
*
|
|
4
|
+
* Trust model:
|
|
5
|
+
* 1. Domain owner generates Ed25519 keypair (offline).
|
|
6
|
+
* 2. Public key published as `pk=ed25519:BASE64KEY` in `_wab` TXT record.
|
|
7
|
+
* DNSSEC protects the key from tampering at the resolver level.
|
|
8
|
+
* 3. The discovery manifest (wab.json) is signed with the private key.
|
|
9
|
+
* Agents fetch the manifest, fetch the pubkey from DNS, and verify.
|
|
10
|
+
* 4. No CA required. Trust root = DNS + DNSSEC + TLS — already universal.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const crypto = require('crypto');
|
|
16
|
+
|
|
17
|
+
/** Generate a fresh Ed25519 keypair encoded as base64 (raw 32-byte form). */
|
|
18
|
+
function generateKeyPair() {
|
|
19
|
+
const { publicKey, privateKey } = crypto.generateKeyPairSync('ed25519');
|
|
20
|
+
// Export raw public key (last 32 bytes of DER)
|
|
21
|
+
const pubDer = publicKey.export({ type: 'spki', format: 'der' });
|
|
22
|
+
const rawPub = pubDer.slice(pubDer.length - 32);
|
|
23
|
+
// Export raw private key (last 32 bytes of DER PKCS#8)
|
|
24
|
+
const privDer = privateKey.export({ type: 'pkcs8', format: 'der' });
|
|
25
|
+
const rawPriv = privDer.slice(privDer.length - 32);
|
|
26
|
+
return {
|
|
27
|
+
public_key: rawPub.toString('base64'),
|
|
28
|
+
private_key: rawPriv.toString('base64'),
|
|
29
|
+
algorithm: 'ed25519',
|
|
30
|
+
fingerprint: fingerprint(rawPub.toString('base64')),
|
|
31
|
+
created_at: new Date().toISOString(),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** SHA-256(public_key) base64, first 16 chars — short, stable identifier. */
|
|
36
|
+
function fingerprint(publicKeyB64) {
|
|
37
|
+
const raw = Buffer.from(publicKeyB64, 'base64');
|
|
38
|
+
return crypto.createHash('sha256').update(raw).digest('base64').slice(0, 16);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Wrap a 32-byte raw Ed25519 key in DER for Node's crypto API. */
|
|
42
|
+
function rawToPublicKey(rawB64) {
|
|
43
|
+
const raw = Buffer.from(rawB64, 'base64');
|
|
44
|
+
if (raw.length !== 32) throw new Error('public key must be 32 raw bytes (base64)');
|
|
45
|
+
// SPKI prefix for Ed25519
|
|
46
|
+
const prefix = Buffer.from('302a300506032b6570032100', 'hex');
|
|
47
|
+
const der = Buffer.concat([prefix, raw]);
|
|
48
|
+
return crypto.createPublicKey({ key: der, format: 'der', type: 'spki' });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function rawToPrivateKey(rawB64) {
|
|
52
|
+
const raw = Buffer.from(rawB64, 'base64');
|
|
53
|
+
if (raw.length !== 32) throw new Error('private key must be 32 raw bytes (base64)');
|
|
54
|
+
// PKCS#8 prefix for Ed25519
|
|
55
|
+
const prefix = Buffer.from('302e020100300506032b657004220420', 'hex');
|
|
56
|
+
const der = Buffer.concat([prefix, raw]);
|
|
57
|
+
return crypto.createPrivateKey({ key: der, format: 'der', type: 'pkcs8' });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* RFC 8785-style JSON canonicalization (subset sufficient for WAB):
|
|
62
|
+
* - object keys sorted lexicographically (UTF-16 code units)
|
|
63
|
+
* - no insignificant whitespace
|
|
64
|
+
* - numbers serialized as JS Number → JSON.stringify default
|
|
65
|
+
* - the `signature` field at the top level is excluded from canonical form
|
|
66
|
+
*/
|
|
67
|
+
function canonicalize(value, excludeKeys = ['signature']) {
|
|
68
|
+
const seen = new WeakSet();
|
|
69
|
+
function walk(v, depth) {
|
|
70
|
+
if (v === null || typeof v !== 'object') return JSON.stringify(v);
|
|
71
|
+
if (seen.has(v)) throw new Error('canonicalize: cycle detected');
|
|
72
|
+
seen.add(v);
|
|
73
|
+
if (Array.isArray(v)) return '[' + v.map(x => walk(x, depth + 1)).join(',') + ']';
|
|
74
|
+
const keys = Object.keys(v).filter(k => v[k] !== undefined);
|
|
75
|
+
// Only the top-level signature field is excluded.
|
|
76
|
+
const filtered = depth === 0 ? keys.filter(k => !excludeKeys.includes(k)) : keys;
|
|
77
|
+
filtered.sort();
|
|
78
|
+
return '{' + filtered.map(k => JSON.stringify(k) + ':' + walk(v[k], depth + 1)).join(',') + '}';
|
|
79
|
+
}
|
|
80
|
+
return walk(value, 0);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Sign a manifest. Mutates a shallow copy by adding a `signature` block:
|
|
85
|
+
* { algorithm: 'ed25519', value: '<b64>', key_id: '<fp>', signed_at: 'ISO' }
|
|
86
|
+
*/
|
|
87
|
+
function signManifest(manifest, privateKeyB64, opts = {}) {
|
|
88
|
+
if (!manifest || typeof manifest !== 'object') throw new Error('manifest must be an object');
|
|
89
|
+
const priv = rawToPrivateKey(privateKeyB64);
|
|
90
|
+
|
|
91
|
+
// Derive public key from private to compute key_id deterministically.
|
|
92
|
+
const pubObj = crypto.createPublicKey(priv);
|
|
93
|
+
const pubDer = pubObj.export({ type: 'spki', format: 'der' });
|
|
94
|
+
const pubB64 = pubDer.slice(pubDer.length - 32).toString('base64');
|
|
95
|
+
|
|
96
|
+
const toSign = { ...manifest };
|
|
97
|
+
delete toSign.signature;
|
|
98
|
+
const canonical = canonicalize(toSign);
|
|
99
|
+
const sig = crypto.sign(null, Buffer.from(canonical, 'utf8'), priv);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
...toSign,
|
|
103
|
+
signature: {
|
|
104
|
+
algorithm: 'ed25519',
|
|
105
|
+
value: sig.toString('base64'),
|
|
106
|
+
key_id: opts.key_id || fingerprint(pubB64),
|
|
107
|
+
public_key: opts.embed_public_key ? pubB64 : undefined,
|
|
108
|
+
signed_at: new Date().toISOString(),
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Verify a signed manifest. Returns { ok, reason?, key_id?, signed_at?, age_seconds? }.
|
|
115
|
+
*/
|
|
116
|
+
function verifyManifest(manifest, publicKeyB64, opts = {}) {
|
|
117
|
+
if (!manifest || typeof manifest !== 'object') return { ok: false, reason: 'manifest must be an object' };
|
|
118
|
+
const sig = manifest.signature;
|
|
119
|
+
if (!sig) return { ok: false, reason: 'no signature field' };
|
|
120
|
+
if (sig.algorithm !== 'ed25519') return { ok: false, reason: `unsupported algorithm: ${sig.algorithm}` };
|
|
121
|
+
if (!sig.value) return { ok: false, reason: 'signature.value missing' };
|
|
122
|
+
|
|
123
|
+
// Use embedded key only if caller didn't pin one.
|
|
124
|
+
const keyB64 = publicKeyB64 || sig.public_key;
|
|
125
|
+
if (!keyB64) return { ok: false, reason: 'no public key supplied (DNS pk= or embedded)' };
|
|
126
|
+
|
|
127
|
+
let pub;
|
|
128
|
+
try { pub = rawToPublicKey(keyB64); }
|
|
129
|
+
catch (err) { return { ok: false, reason: 'invalid public key: ' + err.message }; }
|
|
130
|
+
|
|
131
|
+
const expectedFp = fingerprint(keyB64);
|
|
132
|
+
if (sig.key_id && sig.key_id !== expectedFp) {
|
|
133
|
+
return { ok: false, reason: `key_id mismatch: signature claims ${sig.key_id}, key fingerprint is ${expectedFp}` };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const canonical = canonicalize(manifest);
|
|
137
|
+
let okSig = false;
|
|
138
|
+
try {
|
|
139
|
+
okSig = crypto.verify(null, Buffer.from(canonical, 'utf8'), pub, Buffer.from(sig.value, 'base64'));
|
|
140
|
+
} catch (err) {
|
|
141
|
+
return { ok: false, reason: 'verify error: ' + err.message };
|
|
142
|
+
}
|
|
143
|
+
if (!okSig) return { ok: false, reason: 'signature does not match' };
|
|
144
|
+
|
|
145
|
+
// Freshness check (optional)
|
|
146
|
+
let age_seconds = null;
|
|
147
|
+
if (sig.signed_at) {
|
|
148
|
+
const t = Date.parse(sig.signed_at);
|
|
149
|
+
if (!isNaN(t)) age_seconds = Math.max(0, Math.floor((Date.now() - t) / 1000));
|
|
150
|
+
}
|
|
151
|
+
if (opts.max_age_seconds && age_seconds !== null && age_seconds > opts.max_age_seconds) {
|
|
152
|
+
return { ok: false, reason: `signature too old (${age_seconds}s > ${opts.max_age_seconds}s)`, age_seconds };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return { ok: true, key_id: expectedFp, signed_at: sig.signed_at, age_seconds };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Parse the `pk=ed25519:BASE64KEY` field from a parsed _wab record.
|
|
160
|
+
* Returns { algorithm, public_key } or null.
|
|
161
|
+
*/
|
|
162
|
+
function parsePkField(pkValue) {
|
|
163
|
+
if (!pkValue || typeof pkValue !== 'string') return null;
|
|
164
|
+
const m = /^([a-z0-9]+):([A-Za-z0-9+/=_-]+)$/.exec(pkValue.trim());
|
|
165
|
+
if (!m) return null;
|
|
166
|
+
return { algorithm: m[1], public_key: m[2].replace(/-/g, '+').replace(/_/g, '/') };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
module.exports = {
|
|
170
|
+
generateKeyPair,
|
|
171
|
+
fingerprint,
|
|
172
|
+
canonicalize,
|
|
173
|
+
signManifest,
|
|
174
|
+
verifyManifest,
|
|
175
|
+
parsePkField,
|
|
176
|
+
rawToPublicKey,
|
|
177
|
+
rawToPrivateKey,
|
|
178
|
+
};
|