@ai-ecoverse/slicc-kernel 1.20.0 → 1.20.1

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/dist/node.js CHANGED
@@ -4664,12 +4664,27 @@ function kernelCa(store) {
4664
4664
  function kernelTlsEngine(load) {
4665
4665
  return () => loadTlsEngine(load);
4666
4666
  }
4667
- async function writeCaFile(fs, ca) {
4668
- const { pem: pem2 } = await ca();
4669
- const current = await fs.exists(CA_PATH) ? await fs.readFile(CA_PATH) : void 0;
4670
- if (current === pem2) return;
4667
+ var CERTIFICATE = /-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g;
4668
+ var CA_BUNDLE_MAX = 16;
4669
+ var CA_FILE_LOCK = "slicc-kernel-ca-file";
4670
+ var CA_FILE_TRIES = 3;
4671
+ async function addToBundle(fs, own) {
4672
+ const current = await fs.exists(CA_PATH) ? await fs.readFile(CA_PATH) : "";
4673
+ const all = current.match(CERTIFICATE) ?? [];
4674
+ const others = all.filter((cert) => cert !== own);
4675
+ if (others.length < all.length) return true;
4676
+ const bundle = [...others, own].slice(-CA_BUNDLE_MAX);
4671
4677
  await fs.mkdir(CA_PATH.slice(0, CA_PATH.lastIndexOf("/")), { recursive: true });
4672
- await fs.writeFile(CA_PATH, pem2);
4678
+ await fs.writeFile(CA_PATH, `${bundle.join("\n")}
4679
+ `);
4680
+ return false;
4681
+ }
4682
+ async function writeCaFile(fs, ca, locks = globalThis.navigator?.locks) {
4683
+ const own = (await ca()).pem.trim();
4684
+ const update = async () => {
4685
+ for (let i = 0; i < CA_FILE_TRIES && !await addToBundle(fs, own); i++) ;
4686
+ };
4687
+ await (locks ? locks.request(CA_FILE_LOCK, update) : update());
4673
4688
  }
4674
4689
  function enableNetwork(net, options) {
4675
4690
  let proxy;