@ai-ecoverse/slicc-kernel 1.123.1 → 1.124.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.
@@ -5199,6 +5199,7 @@ function importsContext({
5199
5199
  },
5200
5200
  tryLock(fd, exclusive) {
5201
5201
  const path = requirePath(fd);
5202
+ host.fds.promote(fd);
5202
5203
  try {
5203
5204
  call2({ op: "lock", path, exclusive, fd });
5204
5205
  } catch (err) {
@@ -5208,7 +5209,7 @@ function importsContext({
5208
5209
  return E.SUCCESS;
5209
5210
  },
5210
5211
  unlock(fd) {
5211
- call2({ op: "unlock", path: requirePath(fd) });
5212
+ call2({ op: "unlock", path: requirePath(fd), fd });
5212
5213
  }
5213
5214
  };
5214
5215
  const ctx = {
@@ -5433,7 +5434,7 @@ var KERNEL_VERSION, OS_RELEASE;
5433
5434
  var init_version = __esm({
5434
5435
  "src/version.ts"() {
5435
5436
  "use strict";
5436
- KERNEL_VERSION = true ? "1.123.1" : "0.0.0-dev";
5437
+ KERNEL_VERSION = true ? "1.124.0" : "0.0.0-dev";
5437
5438
  OS_RELEASE = "6.0.0-slicc";
5438
5439
  }
5439
5440
  });
@@ -5499,7 +5500,9 @@ var init_js_kernel = __esm({
5499
5500
  "fd-write",
5500
5501
  "fd-close",
5501
5502
  "fd-open-clipboard",
5502
- "net-ws-ready"
5503
+ "net-ws-ready",
5504
+ "sock-tls",
5505
+ "sock-tls-upgrade"
5503
5506
  ]);
5504
5507
  JsKernel = class {
5505
5508
  header;
@@ -6934,6 +6937,69 @@ var init_js_fetch = __esm({
6934
6937
  });
6935
6938
 
6936
6939
  // src/process/js/js-net.ts
6940
+ function fromBase64(text) {
6941
+ const bin = atob(text);
6942
+ const out = new Uint8Array(bin.length);
6943
+ for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
6944
+ return out;
6945
+ }
6946
+ function toBase64(bytes) {
6947
+ let bin = "";
6948
+ for (const b of bytes) bin += String.fromCharCode(b);
6949
+ return btoa(bin);
6950
+ }
6951
+ function caList(ca) {
6952
+ const items = Array.isArray(ca) ? ca : [ca];
6953
+ const out = [];
6954
+ for (const item of items) {
6955
+ if (item instanceof Uint8Array && item[0] === 48) out.push(toBase64(item));
6956
+ else {
6957
+ const text = item instanceof Uint8Array ? new TextDecoder().decode(item) : String(item);
6958
+ out.push(...[...text.matchAll(PEM)].map((m) => m[1].replace(/\s+/g, "")));
6959
+ }
6960
+ }
6961
+ return out;
6962
+ }
6963
+ function tlsRequest(tls) {
6964
+ return {
6965
+ ...tls.servername ? { servername: tls.servername } : {},
6966
+ ...tls.alpn ? { alpn: [...tls.alpn] } : {},
6967
+ ...tls.ca !== void 0 ? { ca: caList(tls.ca) } : {},
6968
+ ...tls.rejectUnauthorized === false ? { insecure: true } : {}
6969
+ };
6970
+ }
6971
+ function sessionOf(r) {
6972
+ if (r.path !== "kernel") {
6973
+ return Object.freeze({
6974
+ path: "transport",
6975
+ substitutes: true,
6976
+ protocol: "transport",
6977
+ alpnProtocol: r.alpnProtocol,
6978
+ authorized: true,
6979
+ servername: r.servername
6980
+ });
6981
+ }
6982
+ return Object.freeze({
6983
+ path: "kernel",
6984
+ substitutes: false,
6985
+ protocol: r.protocol ?? "TLSv1.2",
6986
+ alpnProtocol: r.alpnProtocol,
6987
+ authorized: r.authorized === true,
6988
+ ...r.authorizationError ? { authorizationError: r.authorizationError } : {},
6989
+ servername: r.servername,
6990
+ peerCertificates: Object.freeze((r.peerCertificates ?? []).map(fromBase64))
6991
+ });
6992
+ }
6993
+ async function secureCall(call2) {
6994
+ try {
6995
+ return await call2();
6996
+ } catch (err) {
6997
+ const e = err;
6998
+ const code2 = e.code === "EPROTO" && e.detail ? TLS_CODE.exec(e.detail)?.[1] : void 0;
6999
+ if (code2) throw new JsCallError(code2, "connect", e.detail);
7000
+ throw err;
7001
+ }
7002
+ }
6937
7003
  function errnoName(errno2) {
6938
7004
  const found = Object.entries(E).find(([, n]) => n === errno2);
6939
7005
  return found ? `E${found[0]}` : "EIO";
@@ -7023,20 +7089,22 @@ function netOps(kernel, io) {
7023
7089
  };
7024
7090
  };
7025
7091
  const tlsConnect = async (options, tls) => {
7026
- const r = await kernel.json({
7027
- op: "sock-tls",
7028
- host: options.host ?? "localhost",
7029
- port: port(options.port),
7030
- ...tls.servername ? { servername: tls.servername } : {},
7031
- ...tls.alpn ? { alpn: [...tls.alpn] } : {},
7032
- ...tls.ca !== void 0 ? { ca: true } : {}
7033
- });
7034
- const session = Object.freeze({
7035
- protocol: "transport",
7036
- alpnProtocol: r.alpnProtocol,
7037
- authorized: true,
7038
- servername: r.servername
7039
- });
7092
+ const common = tlsRequest(
7093
+ options.socket && !tls.servername && options.host ? { ...tls, servername: options.host } : tls
7094
+ );
7095
+ const r = await secureCall(
7096
+ () => kernel.json(
7097
+ options.socket ? { op: "sock-tls-upgrade", fd: options.socket.fd, ...common } : {
7098
+ op: "sock-tls",
7099
+ host: options.host ?? "localhost",
7100
+ port: port(options.port),
7101
+ ...common,
7102
+ ...tls.path ? { path: tls.path } : {}
7103
+ }
7104
+ )
7105
+ );
7106
+ const session = sessionOf(r);
7107
+ if (options.socket) return Object.assign(Object.create(options.socket), { tls: session });
7040
7108
  return Object.assign(await connection(r.fd), { tls: session });
7041
7109
  };
7042
7110
  const lookup2 = async (name3, options = {}) => {
@@ -7093,12 +7161,14 @@ function netOps(kernel, io) {
7093
7161
  }
7094
7162
  };
7095
7163
  }
7096
- var SHUT_RD, SHUT_WR, IPV4, NEVER, SOL_SOCKET2, SO_ERROR2;
7164
+ var PEM, TLS_CODE, SHUT_RD, SHUT_WR, IPV4, NEVER, SOL_SOCKET2, SO_ERROR2;
7097
7165
  var init_js_net = __esm({
7098
7166
  "src/process/js/js-net.ts"() {
7099
7167
  "use strict";
7100
7168
  init_wasi_abi();
7101
7169
  init_js_kernel();
7170
+ PEM = /-----BEGIN CERTIFICATE-----([\s\S]*?)-----END CERTIFICATE-----/g;
7171
+ TLS_CODE = /^([A-Z][A-Z0-9_]+): /;
7102
7172
  SHUT_RD = 0;
7103
7173
  SHUT_WR = 1;
7104
7174
  IPV4 = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;