@ai-ecoverse/slicc-kernel 1.155.0 → 1.157.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/README.md CHANGED
@@ -413,6 +413,7 @@ The module's default export (or its `main` export) is called with a context and
413
413
  - **The parent's copy:** the program keeps `f` and closes it itself when it no longer needs it, so the child sees end of file once it's the only one left.
414
414
  - **Why a `Record`:** it can't name a child fd twice, and it reads like Node's `stdio` index, so it's this rather than a list of `{ fd, from }`.
415
415
  - `asyncContext` (the Node entry only; absent in a browser, so a runtime feature-detects it; #1350, slicc-jsh#375) is `{ run(store, fn, ...args), getStore(), enterWith(store) }`, backed by one host `AsyncLocalStorage` the process worker makes for each program, since a program can't import `node:async_hooks` and the realm has no promise hooks of its own. A store follows the program's native `await` continuations and promise jobs, as an `AsyncLocalStorage` does in Node, so Next.js, OpenTelemetry and request-context loggers keep their context. Each process and each thread has its own. Only these three frozen functions on a frozen null-prototype object reach the program: they hold the host storage in a closure, `run` calls the program's function with its own arguments, and nothing they return or expose is a host object.
416
+ - `sync.runScript(source, { filename })` (#1541, slicc-jsh#977) runs `source` as a classic script in the program's own global scope, synchronously, as Node's `vm.runInThisContext` does: `let`, `const` and `class` land in the global lexical scope, `var` (in strict code too) on the global object, and stack frames are named `filename` (default `[eval]`). On the Node entry it returns `{ value, completion: true }` with the completion value, and an error the script throws is thrown as it is. In a browser, where process workers are module workers with no synchronous classic-script path, it returns `undefined`, so a runtime feature-detects it with `ctx.sync.runScript('1') !== undefined`. A non-string `source` or `filename` is a `TypeError` everywhere. The script sees exactly the globals the program sees, `import()` inside it is refused, and a `var`, function or `let` declaration can't replace a global the program can't assign: a non-configurable one stays as it is, and the only configurable, non-assignable ones (`crypto`, `navigator`) are ones the program can already redefine with `Object.defineProperty`.
416
417
  - `memory()`, synchronous and without a kernel call, measures the calling isolate: each `thread` answers for its own (#1240, slicc-jsh#397). It returns a fresh plain object of numbers in bytes, each field only where it's measured: `heapUsed`, `heapTotal`, `heapLimit` (V8's heap size limit), `external` and `arrayBuffers`. On the Node entry they come from V8's heap statistics and Node's memory usage, through functions the worker captured before its lockdown, so nothing reachable from the program leads back to `process` or `v8`; there is no `rss`, which is the whole host's. In a browser `memory()` answers `{}` for now.
417
418
  - **`thread`, kernel threads of the same process** ([#1094](https://github.com/ai-ecoverse/slicc-kernel/issues/1094)), the base for Node's `worker_threads` (tinypool, piscina, vitest's and jest's thread pools, eslint's concurrency). `thread.spawn({ data, transfer })` resolves with `{ tid, port, exited, terminate() }`.
418
419
  - **What a thread is:** a new process worker in the **same process**. It has the same pid, descriptor table, cwd, umask, credentials and lockdown, and a sync lane of its own, so `sync` calls in one thread don't hold another.
@@ -501,6 +502,7 @@ The module's default export (or its `main` export) is called with a context and
501
502
  - Before dialling, `cert` without `key` (or the reverse) is `EINVAL`. A key that doesn't match the leaf is `ERR_OSSL_X509_KEY_VALUES_MISMATCH`, a wrong passphrase `ERR_OSSL_BAD_DECRYPT`, a missing one `ERR_OSSL_CRYPTO_INTERRUPTED_OR_CANCELLED`, and a key the engine can't read `ERR_OSSL_UNSUPPORTED`.
502
503
  - `pfx` is `ENOTSUP`: pass `cert` and `key`.
503
504
  - A server that requires a certificate and gets none refuses with an alert. On TLS 1.2 that fails the connect (`ERR_SSL_HANDSHAKE_FAILURE`). On TLS 1.3 the client's side of the handshake is already done, so the next read or write fails with `ERR_SSL_FATAL_ALERT`, as Node's fails after `secureConnect`.
505
+ - **A reply that isn't TLS** ([#1548](https://github.com/ai-ecoverse/slicc-kernel/issues/1548)) is told apart by its first record's header, in OpenSSL's order, so a program gets Node's code: an SSLv2 version is `ERR_SSL_WRONG_VERSION_NUMBER`; a length over 16704 bytes `ERR_SSL_PACKET_LENGTH_TOO_LONG` (most plain-text replies, `HTTP/1.1 …` among them); a major version other than 3 `ERR_SSL_HTTP_REQUEST` for `GET ` or `PUT ` and `ERR_SSL_WRONG_VERSION_NUMBER` otherwise (`220 …`, `SSH-2.0…`, `+OK …`); a record over 16384 bytes `ERR_SSL_DATA_LENGTH_TOO_LONG`; and a handshake record that isn't a ServerHello `ERR_SSL_UNEXPECTED_MESSAGE`. Anything else stays `ERR_SSL_HANDSHAKE_FAILURE`, or `ECONNRESET` for a server that closes.
504
506
  - **A fatal alert from the server**, at the handshake or after it, is in the error: its `detail` ends in ` (alert <n>)`, and a JS program's error has `alert: n`, the alert's description number (116 certificate_required, 40 handshake_failure).
505
507
  - **`keylog: true`** ([#1504](https://github.com/ai-ecoverse/slicc-kernel/issues/1504), tls-engine 4.2.0-10) gives the session's NSS key log lines as `conn.tls.keylog`, a frozen list of strings: `CLIENT_RANDOM …` on TLS 1.2, the four `…_TRAFFIC_SECRET…` lines on TLS 1.3, the lines Node's `keylog` event and `SSLKEYLOGFILE` carry. **They are the session's secrets: anyone holding them and a capture of the traffic can read it.** So a keylogged session is never sealed (`substitutes: false`; a placeholder goes out as written), and `keylog` on the transport path (A1, where the page makes the TLS) is `ENOTSUP`. Without `keylog` the engine collects nothing. The kernel wipes its copies once the lines are in the reply (the engine zeroes its buffer as it hands them out); the lines reach the program as JS strings, which can't be wiped, so they live as long as the program keeps them, as with its own `key`. A TLS server takes `keylog` too (`listen({ tls })`, `secure(conn, { server: true })`), for every connection it serves.
506
508
  - **`sni: false`** sends no server name. The leaf is still checked against `servername` exactly as with SNI.
@@ -8112,7 +8112,7 @@ function satisfies(version, range2) {
8112
8112
  }
8113
8113
 
8114
8114
  // src/version.ts
8115
- var KERNEL_VERSION = true ? "1.155.0" : "0.0.0-dev";
8115
+ var KERNEL_VERSION = true ? "1.157.0" : "0.0.0-dev";
8116
8116
  var OS_RELEASE = "6.0.0-slicc";
8117
8117
  function procVersion() {
8118
8118
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -19467,6 +19467,7 @@ function openSession(o) {
19467
19467
  var Ciphertext = class {
19468
19468
  queue = [];
19469
19469
  ended = false;
19470
+ opening = new Uint8Array(0);
19470
19471
  conn;
19471
19472
  session;
19472
19473
  constructor(conn, session) {
@@ -19475,11 +19476,19 @@ var Ciphertext = class {
19475
19476
  }
19476
19477
  hand(bytes) {
19477
19478
  if (bytes.length > 0) this.queue.push(bytes);
19479
+ this.note(bytes);
19480
+ }
19481
+ note(bytes) {
19482
+ if (this.opening.length >= OPENING) return;
19483
+ const next3 = new Uint8Array(Math.min(OPENING, this.opening.length + bytes.length));
19484
+ next3.set(this.opening);
19485
+ next3.set(bytes.subarray(0, next3.length - this.opening.length), this.opening.length);
19486
+ this.opening = next3;
19478
19487
  }
19479
19488
  async more() {
19480
19489
  if (this.queue.length === 0 && !this.ended) {
19481
19490
  const bytes = await this.conn.read();
19482
- if (bytes) this.queue.push(bytes);
19491
+ if (bytes) this.hand(bytes);
19483
19492
  else this.ended = true;
19484
19493
  }
19485
19494
  if (this.queue.length === 0) {
@@ -19509,11 +19518,38 @@ async function send(conn, session) {
19509
19518
  }
19510
19519
  }
19511
19520
  }
19512
- function refused2(engine, session, err) {
19521
+ var OPENING = 6;
19522
+ var PLAIN_MAX = 16384;
19523
+ var ENCRYPTED_MAX = PLAIN_MAX + 320;
19524
+ var HTTP_METHODS = ["GET ", "POST ", "HEAD ", "PUT ", "PATCH", "OPTIO", "DELET", "TRACE"];
19525
+ function headerClass(head) {
19526
+ const [type, major, minor, hi, lo] = head;
19527
+ if (major === 0 && minor === 2) return ["ERR_SSL_WRONG_VERSION_NUMBER", "wrong version number"];
19528
+ const length2 = hi << 8 | lo;
19529
+ if (length2 > ENCRYPTED_MAX) return ["ERR_SSL_PACKET_LENGTH_TOO_LONG", "packet length too long"];
19530
+ if (major !== 3) {
19531
+ const text = new TextDecoder("latin1").decode(head.subarray(0, 5));
19532
+ if (HTTP_METHODS.some((m) => text.startsWith(m)))
19533
+ return ["ERR_SSL_HTTP_REQUEST", "http request"];
19534
+ return ["ERR_SSL_WRONG_VERSION_NUMBER", "wrong version number"];
19535
+ }
19536
+ if (length2 > PLAIN_MAX) return ["ERR_SSL_DATA_LENGTH_TOO_LONG", "data length too long"];
19537
+ if (type === 22 && head.length > 5 && head[5] !== 2)
19538
+ return ["ERR_SSL_UNEXPECTED_MESSAGE", "unexpected message"];
19539
+ return void 0;
19540
+ }
19541
+ function recordRefusal(opening2) {
19542
+ if (opening2.length < 5) return void 0;
19543
+ const found = headerClass(opening2);
19544
+ return found && new KernelError("EPROTO", `${found[0]}: ${found[1]}`);
19545
+ }
19546
+ function refused2(engine, session, err, opening2) {
19513
19547
  const flags2 = session.verifyResult;
19514
19548
  const code = verifyCode(flags2);
19515
19549
  if (code && flags2 !== -1)
19516
19550
  return new KernelError("EPROTO", `${code}: ${engine.verifyInfo(flags2).trim()}`);
19551
+ const record2 = recordRefusal(opening2);
19552
+ if (record2) return record2;
19517
19553
  const text = err instanceof TlsError ? err.message : String(err);
19518
19554
  return new KernelError("EPROTO", `ERR_SSL_HANDSHAKE_FAILURE: ${text}${alertOf(session)}`);
19519
19555
  }
@@ -19528,15 +19564,12 @@ async function handshake(conn, o, session, inbox) {
19528
19564
  done5 = session.handshake();
19529
19565
  } catch (err) {
19530
19566
  await send(conn, session).catch(() => void 0);
19531
- throw refused2(o.engine, session, err);
19567
+ throw refused2(o.engine, session, err, inbox.opening);
19532
19568
  }
19533
19569
  await send(conn, session);
19534
19570
  if (done5) return;
19535
19571
  if (!await inbox.more()) {
19536
- throw new KernelError(
19537
- "ECONNRESET",
19538
- "the server closed the connection during the TLS handshake"
19539
- );
19572
+ throw recordRefusal(inbox.opening) ?? new KernelError("ECONNRESET", "the server closed the connection during the TLS handshake");
19540
19573
  }
19541
19574
  }
19542
19575
  }