openzoo 0.34.3 → 0.34.5
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/bin/cursor-backend.js +7 -5
- package/lib/cursorbackend.js +23 -5
- package/lib/hosts.js +28 -4
- package/package.json +1 -1
package/bin/cursor-backend.js
CHANGED
|
@@ -19,11 +19,13 @@ const port = Number(process.argv[2] || 443);
|
|
|
19
19
|
const modelsPath = process.argv[3];
|
|
20
20
|
const logPath = process.argv[4];
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
// WRITE EACH LINE ONCE. The launcher now redirects this process's stdout+stderr
|
|
23
|
+
// with `>>` to the SAME logPath (so a startup crash leaves evidence), so doing
|
|
24
|
+
// both an explicit appendFileSync AND a stdout write duplicated every single
|
|
25
|
+
// line in the file. stdout alone is the right channel: it reaches the log via
|
|
26
|
+
// the redirect, and it still shows up when the backend is run by hand on a
|
|
27
|
+
// terminal for debugging.
|
|
28
|
+
const log = (s) => { process.stdout.write(`${s}\n`); };
|
|
27
29
|
|
|
28
30
|
let models = [];
|
|
29
31
|
try { models = JSON.parse(fs.readFileSync(modelsPath, 'utf8')); }
|
package/lib/cursorbackend.js
CHANGED
|
@@ -35,21 +35,39 @@ import { encodeAvailableModels, encodeForMethod } from './cursorapi.js';
|
|
|
35
35
|
|
|
36
36
|
const TLS_DIR = path.join(os.homedir(), '.openzoo', 'cursor-tls');
|
|
37
37
|
const CURSOR_HOSTS = ['api2.cursor.sh', 'api3.cursor.sh', 'api4.cursor.sh', 'repo42.cursor.sh'];
|
|
38
|
+
// THE CERT MUST COVER ANTHROPIC TOO. This server impersonates api.anthropic.com
|
|
39
|
+
// for `claude --desktop`, but the SAN only ever listed the cursor hosts, so the
|
|
40
|
+
// client got a cert valid for a name it never asked for and killed the
|
|
41
|
+
// handshake before ALPN — logged as `HANDSHAKE FAILED ECONNRESET alpn=?`, with
|
|
42
|
+
// no request ever reaching us. Same cert, one more pair of names.
|
|
43
|
+
const ANTHROPIC_TLS_HOSTS = ['api.anthropic.com', 'api-staging.anthropic.com'];
|
|
44
|
+
const TLS_HOSTS = [...CURSOR_HOSTS, ...ANTHROPIC_TLS_HOSTS];
|
|
38
45
|
|
|
39
|
-
/** Generate (once) a self-signed cert covering
|
|
40
|
-
* on every mac/linux; this is the only external tool and it is not a trust op. */
|
|
46
|
+
/** Generate (once) a self-signed cert covering every host we impersonate. openssl
|
|
47
|
+
* is on every mac/linux; this is the only external tool and it is not a trust op. */
|
|
41
48
|
export function ensureCert(log = () => {}) {
|
|
42
49
|
const cert = path.join(TLS_DIR, 'cert.pem');
|
|
43
50
|
const key = path.join(TLS_DIR, 'key.pem');
|
|
44
|
-
|
|
51
|
+
// STALE-CERT INVALIDATION. A plain existence check meant anyone who had ever
|
|
52
|
+
// run an older build kept their cursor-only cert forever and never got the
|
|
53
|
+
// anthropic names — the fix would ship and appear to do nothing. Record the
|
|
54
|
+
// SAN set the cert was minted for and re-mint whenever that set changes.
|
|
55
|
+
const stamp = path.join(TLS_DIR, 'san.txt');
|
|
56
|
+
const want = TLS_HOSTS.join(',');
|
|
57
|
+
try {
|
|
58
|
+
fs.accessSync(cert); fs.accessSync(key);
|
|
59
|
+
if (fs.readFileSync(stamp, 'utf8').trim() === want) return { cert, key };
|
|
60
|
+
log('cursor-tls: cert predates the current host list — re-minting');
|
|
61
|
+
} catch { /* make it */ }
|
|
45
62
|
fs.mkdirSync(TLS_DIR, { recursive: true });
|
|
46
|
-
const san = `subjectAltName=${
|
|
63
|
+
const san = `subjectAltName=${TLS_HOSTS.map((h) => `DNS:${h}`).join(',')}`;
|
|
47
64
|
execFileSync('openssl', [
|
|
48
65
|
'req', '-x509', '-newkey', 'rsa:2048', '-nodes',
|
|
49
66
|
'-keyout', key, '-out', cert, '-days', '3650',
|
|
50
67
|
'-subj', '/CN=api2.cursor.sh', '-addext', san,
|
|
51
68
|
], { stdio: 'ignore' });
|
|
52
|
-
|
|
69
|
+
fs.writeFileSync(stamp, want);
|
|
70
|
+
log(`cursor-tls: self-signed cert minted at ${TLS_DIR} covering ${TLS_HOSTS.length} hosts (no CA, no trust prompt)`);
|
|
53
71
|
return { cert, key };
|
|
54
72
|
}
|
|
55
73
|
|
package/lib/hosts.js
CHANGED
|
@@ -269,9 +269,31 @@ export function bindBackend443(modelsPath, logPath, log = console.log) {
|
|
|
269
269
|
);
|
|
270
270
|
// Report whether it ACTUALLY came up rather than whether sudo exited 0 —
|
|
271
271
|
// `nohup ... &` always succeeds, so `ok` alone said nothing about the bind.
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
272
|
+
//
|
|
273
|
+
// PROBE BY CONNECTING, NOT BY lsof. The backend we just started is ROOT-owned;
|
|
274
|
+
// unprivileged `lsof -iTCP:443` cannot see another user's descriptors and exits
|
|
275
|
+
// 1 even while `netstat -an` shows `*.443 LISTEN`. That false negative made the
|
|
276
|
+
// caller tear down a WORKING setup and print "FAILED to bind" directly under
|
|
277
|
+
// the backend's own "listening on [::]+127.0.0.1:443" log line. A TCP connect
|
|
278
|
+
// is ownership-blind, and it proves the far more useful property anyway: that
|
|
279
|
+
// the socket actually accepts. Try both families — hosts.js pins both.
|
|
280
|
+
const listening = spawnSync(node, ['-e', `
|
|
281
|
+
const net = require('net');
|
|
282
|
+
const hit = (host) => new Promise((r) => {
|
|
283
|
+
const s = net.connect({ host, port: 443 });
|
|
284
|
+
s.setTimeout(1000);
|
|
285
|
+
s.on('connect', () => { s.destroy(); r(true); });
|
|
286
|
+
s.on('error', () => r(false));
|
|
287
|
+
s.on('timeout', () => { s.destroy(); r(false); });
|
|
288
|
+
});
|
|
289
|
+
(async () => {
|
|
290
|
+
for (let i = 0; i < 10; i++) {
|
|
291
|
+
if (await hit('127.0.0.1') || await hit('::1')) process.exit(0);
|
|
292
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
293
|
+
}
|
|
294
|
+
process.exit(1);
|
|
295
|
+
})();
|
|
296
|
+
`], { timeout: 20000 }).status === 0;
|
|
275
297
|
if (!listening) {
|
|
276
298
|
log(` backend did NOT bind :443 — see ${logPath}`);
|
|
277
299
|
try {
|
|
@@ -288,6 +310,8 @@ export function unbindBackend443() {
|
|
|
288
310
|
return { ok: privileged(
|
|
289
311
|
flushPf
|
|
290
312
|
+ "pkill -9 -f 'cursor-backend.js' 2>/dev/null; "
|
|
291
|
-
|
|
313
|
+
// 443 as well as 8443: the backend binds :443 directly now, and this runs
|
|
314
|
+
// under sudo so lsof CAN see the root-owned socket here.
|
|
315
|
+
+ 'for p in $(lsof -nP -iTCP:443 -sTCP:LISTEN -t 2>/dev/null) $(lsof -nP -iTCP:8443 -sTCP:LISTEN -t 2>/dev/null); do kill -9 "$p" 2>/dev/null; done; true',
|
|
292
316
|
) };
|
|
293
317
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openzoo",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.5",
|
|
4
4
|
"description": "Local x402-paying proxy + MCP server for openzoo.fun — point any OpenAI-compatible harness (Cursor, Claude Code, aider, SDKs) at localhost and it pays per call from a local burner wallet. Solana and Base rails live; Robinhood experimental.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|