omnicell-router 0.8.4 → 0.10.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 +26 -7
- package/README.zh-CN.md +18 -5
- package/backend/dist/capture/recorder.d.ts +4 -10
- package/backend/dist/capture/recorder.js +6 -58
- package/backend/dist/cli/clients/base.d.ts +36 -11
- package/backend/dist/cli/clients/base.js +31 -15
- package/backend/dist/cli/clients/claude.d.ts +9 -0
- package/backend/dist/cli/clients/claude.js +6 -0
- package/backend/dist/cli/clients/codex.d.ts +8 -0
- package/backend/dist/cli/clients/codex.js +5 -0
- package/backend/dist/cli/clients/core-adapters.d.ts +1 -1
- package/backend/dist/cli/clients/core-adapters.js +1 -1
- package/backend/dist/cli/clients/dsh.d.ts +8 -0
- package/backend/dist/cli/clients/dsh.js +5 -0
- package/backend/dist/cli/clients/grok.d.ts +15 -1
- package/backend/dist/cli/clients/grok.js +16 -2
- package/backend/dist/cli/clients/index.d.ts +13 -1
- package/backend/dist/cli/clients/index.js +97 -19
- package/backend/dist/cli/clients/kimi.d.ts +6 -0
- package/backend/dist/cli/clients/kimi.js +3 -0
- package/backend/dist/cli/clients/launcher.d.ts +1 -1
- package/backend/dist/cli/clients/model-meta.js +6 -3
- package/backend/dist/cli/clients/omp.d.ts +6 -0
- package/backend/dist/cli/clients/omp.js +3 -0
- package/backend/dist/cli/clients/openclaw.d.ts +6 -0
- package/backend/dist/cli/clients/openclaw.js +3 -0
- package/backend/dist/cli/clients/opencode.d.ts +8 -0
- package/backend/dist/cli/clients/opencode.js +5 -0
- package/backend/dist/cli/clients/pi.d.ts +6 -0
- package/backend/dist/cli/clients/pi.js +3 -0
- package/backend/dist/cli/clients/update-check.d.ts +37 -0
- package/backend/dist/cli/clients/update-check.js +309 -0
- package/backend/dist/cli/clients/workbuddy.d.ts +19 -0
- package/backend/dist/cli/clients/workbuddy.js +66 -0
- package/backend/dist/cli/index.js +5 -4
- package/backend/dist/cli/paths.js +8 -0
- package/backend/dist/cli/types.d.ts +92 -16
- package/backend/dist/config/comments-en.js +31 -26
- package/backend/dist/config/comments-zh.js +29 -24
- package/backend/dist/config/defaults.d.ts +194 -33
- package/backend/dist/config/defaults.js +193 -32
- package/backend/dist/config/env.d.ts +10 -0
- package/backend/dist/config/env.js +3 -2
- package/backend/dist/config/index.d.ts +7 -0
- package/backend/dist/config/index.js +184 -43
- package/backend/dist/config/migrations/v0-to-v1.d.ts +2 -2
- package/backend/dist/config/migrations/v10-to-v11.d.ts +38 -0
- package/backend/dist/config/migrations/v10-to-v11.js +43 -0
- package/backend/dist/config/migrations/v6-to-v7.d.ts +45 -0
- package/backend/dist/config/migrations/v6-to-v7.js +97 -0
- package/backend/dist/config/migrations/v7-to-v8.d.ts +36 -0
- package/backend/dist/config/migrations/v7-to-v8.js +43 -0
- package/backend/dist/config/migrations/v8-to-v9.d.ts +38 -0
- package/backend/dist/config/migrations/v8-to-v9.js +43 -0
- package/backend/dist/config/migrations/v9-to-v10.d.ts +51 -0
- package/backend/dist/config/migrations/v9-to-v10.js +71 -0
- package/backend/dist/config/runtime.js +1 -1
- package/backend/dist/config/schema.d.ts +3 -3
- package/backend/dist/config/schema.js +14 -4
- package/backend/dist/config/types.d.ts +167 -38
- package/backend/dist/egress-proxy/asset-download.d.ts +54 -0
- package/backend/dist/egress-proxy/asset-download.js +420 -0
- package/backend/dist/egress-proxy/manual-node-spec.d.ts +92 -0
- package/backend/dist/egress-proxy/manual-node-spec.js +408 -0
- package/backend/dist/egress-proxy/mihomo-binary.d.ts +54 -0
- package/backend/dist/egress-proxy/mihomo-binary.js +278 -0
- package/backend/dist/egress-proxy/mihomo-client.d.ts +94 -0
- package/backend/dist/egress-proxy/mihomo-client.js +308 -0
- package/backend/dist/egress-proxy/mihomo-config.d.ts +40 -0
- package/backend/dist/egress-proxy/mihomo-config.js +161 -0
- package/backend/dist/egress-proxy/mihomo-geo.d.ts +87 -0
- package/backend/dist/egress-proxy/mihomo-geo.js +213 -0
- package/backend/dist/egress-proxy/mihomo-logs.d.ts +43 -0
- package/backend/dist/egress-proxy/mihomo-logs.js +84 -0
- package/backend/dist/egress-proxy/mihomo-pac.d.ts +37 -0
- package/backend/dist/egress-proxy/mihomo-pac.js +75 -0
- package/backend/dist/egress-proxy/mihomo-rules-import.d.ts +43 -0
- package/backend/dist/egress-proxy/mihomo-rules-import.js +193 -0
- package/backend/dist/egress-proxy/mihomo-sidecar.d.ts +81 -0
- package/backend/dist/egress-proxy/mihomo-sidecar.js +637 -0
- package/backend/dist/forward-proxy/egress.d.ts +50 -11
- package/backend/dist/forward-proxy/egress.js +50 -17
- package/backend/dist/forward-proxy/h2-forward.js +36 -10
- package/backend/dist/forward-proxy/index.d.ts +11 -8
- package/backend/dist/forward-proxy/index.js +22 -60
- package/backend/dist/forward-proxy/interceptor.d.ts +3 -2
- package/backend/dist/forward-proxy/interceptor.js +4 -4
- package/backend/dist/forward-proxy/relay.js +3 -3
- package/backend/dist/forward-proxy/rules.d.ts +4 -4
- package/backend/dist/forward-proxy/rules.js +25 -4
- package/backend/dist/forward-proxy/server.d.ts +0 -16
- package/backend/dist/forward-proxy/server.js +124 -156
- package/backend/dist/harness/host/hosts.js +3 -2
- package/backend/dist/index.js +53 -18
- package/backend/dist/ingress-proxy/access-log.d.ts +176 -0
- package/backend/dist/ingress-proxy/access-log.js +774 -0
- package/backend/dist/ingress-proxy/ca-inventory.d.ts +106 -0
- package/backend/dist/ingress-proxy/ca-inventory.js +525 -0
- package/backend/dist/ingress-proxy/ca-trust.d.ts +96 -0
- package/backend/dist/ingress-proxy/ca-trust.js +315 -0
- package/backend/dist/ingress-proxy/ca.d.ts +104 -0
- package/backend/dist/ingress-proxy/ca.js +273 -0
- package/backend/dist/ingress-proxy/data-dir.d.ts +28 -0
- package/backend/dist/ingress-proxy/data-dir.js +45 -0
- package/backend/dist/ingress-proxy/egress.d.ts +151 -0
- package/backend/dist/ingress-proxy/egress.js +364 -0
- package/backend/dist/ingress-proxy/h2-forward.d.ts +66 -0
- package/backend/dist/ingress-proxy/h2-forward.js +561 -0
- package/backend/dist/ingress-proxy/index.d.ts +24 -0
- package/backend/dist/ingress-proxy/index.js +144 -0
- package/backend/dist/ingress-proxy/interceptor.d.ts +25 -0
- package/backend/dist/ingress-proxy/interceptor.js +52 -0
- package/backend/dist/ingress-proxy/ordered-relay.d.ts +29 -0
- package/backend/dist/ingress-proxy/ordered-relay.js +46 -0
- package/backend/dist/ingress-proxy/relay.d.ts +54 -0
- package/backend/dist/ingress-proxy/relay.js +188 -0
- package/backend/dist/ingress-proxy/rules.d.ts +195 -0
- package/backend/dist/ingress-proxy/rules.js +348 -0
- package/backend/dist/ingress-proxy/server.d.ts +153 -0
- package/backend/dist/ingress-proxy/server.js +2065 -0
- package/backend/dist/ingress-proxy/sni.d.ts +35 -0
- package/backend/dist/ingress-proxy/sni.js +124 -0
- package/backend/dist/ingress-proxy/status.d.ts +32 -0
- package/backend/dist/ingress-proxy/status.js +15 -0
- package/backend/dist/ingress-proxy/system-proxy.d.ts +112 -0
- package/backend/dist/ingress-proxy/system-proxy.js +481 -0
- package/backend/dist/ingress-proxy/traffic-delete.d.ts +21 -0
- package/backend/dist/ingress-proxy/traffic-delete.js +64 -0
- package/backend/dist/ingress-proxy/traffic-delete.worker.d.ts +44 -0
- package/backend/dist/ingress-proxy/traffic-delete.worker.js +228 -0
- package/backend/dist/ingress-proxy/traffic-files.d.ts +10 -0
- package/backend/dist/ingress-proxy/traffic-files.js +10 -0
- package/backend/dist/ingress-proxy/upstream-tls.d.ts +46 -0
- package/backend/dist/ingress-proxy/upstream-tls.js +105 -0
- package/backend/dist/ingress-proxy/ws-frames.d.ts +45 -0
- package/backend/dist/ingress-proxy/ws-frames.js +153 -0
- package/backend/dist/ir/adapters/anthropic-messages-stream.js +6 -1
- package/backend/dist/ir/adapters/anthropic-messages.js +12 -5
- package/backend/dist/ir/adapters/google-gemini-stream.js +7 -2
- package/backend/dist/ir/adapters/google-gemini.js +5 -2
- package/backend/dist/ir/adapters/openai-chat-stream.js +5 -1
- package/backend/dist/ir/adapters/openai-chat.d.ts +25 -0
- package/backend/dist/ir/adapters/openai-chat.js +45 -3
- package/backend/dist/ir/adapters/openai-responses-output.d.ts +1 -0
- package/backend/dist/ir/adapters/openai-responses-output.js +67 -21
- package/backend/dist/ir/adapters/openai-responses-stream.d.ts +13 -0
- package/backend/dist/ir/adapters/openai-responses-stream.js +34 -1
- package/backend/dist/ir/adapters/openai-responses.d.ts +82 -24
- package/backend/dist/ir/adapters/openai-responses.js +146 -37
- package/backend/dist/ir/media.d.ts +20 -0
- package/backend/dist/ir/media.js +41 -0
- package/backend/dist/ir/tool-identity.d.ts +35 -0
- package/backend/dist/ir/tool-identity.js +40 -0
- package/backend/dist/ir/types.d.ts +9 -1
- package/backend/dist/local/build-jobs.d.ts +66 -0
- package/backend/dist/local/build-jobs.js +243 -0
- package/backend/dist/local/detect.d.ts +32 -0
- package/backend/dist/local/detect.js +145 -0
- package/backend/dist/local/draft-match.d.ts +58 -0
- package/backend/dist/local/draft-match.js +124 -0
- package/backend/dist/local/engine-runtime.d.ts +522 -0
- package/backend/dist/local/engine-runtime.js +1 -0
- package/backend/dist/local/engines.d.ts +241 -0
- package/backend/dist/local/engines.js +651 -0
- package/backend/dist/local/gguf.d.ts +35 -0
- package/backend/dist/local/gguf.js +314 -0
- package/backend/dist/local/hf.d.ts +120 -0
- package/backend/dist/local/hf.js +304 -0
- package/backend/dist/local/install.d.ts +90 -0
- package/backend/dist/local/install.js +421 -0
- package/backend/dist/local/llamacpp.d.ts +55 -0
- package/backend/dist/local/llamacpp.js +177 -0
- package/backend/dist/local/local-provider.d.ts +81 -0
- package/backend/dist/local/local-provider.js +301 -0
- package/backend/dist/local/machine-stats.d.ts +87 -0
- package/backend/dist/local/machine-stats.js +332 -0
- package/backend/dist/local/model-store.d.ts +347 -0
- package/backend/dist/local/model-store.js +1215 -0
- package/backend/dist/local/part-sweep.d.ts +32 -0
- package/backend/dist/local/part-sweep.js +156 -0
- package/backend/dist/local/plan.d.ts +65 -0
- package/backend/dist/local/plan.js +146 -0
- package/backend/dist/local/resources.d.ts +49 -0
- package/backend/dist/local/resources.js +64 -0
- package/backend/dist/local/run-stats.d.ts +95 -0
- package/backend/dist/local/run-stats.js +195 -0
- package/backend/dist/local/runner.d.ts +235 -0
- package/backend/dist/local/runner.js +1392 -0
- package/backend/dist/local/settings.d.ts +79 -0
- package/backend/dist/local/settings.js +180 -0
- package/backend/dist/local/strata-catalog.d.ts +30 -0
- package/backend/dist/local/strata-catalog.js +511 -0
- package/backend/dist/local/strata-drafting.d.ts +46 -0
- package/backend/dist/local/strata-drafting.js +265 -0
- package/backend/dist/local/strata.d.ts +278 -0
- package/backend/dist/local/strata.js +1392 -0
- package/backend/dist/local/tar.d.ts +20 -0
- package/backend/dist/local/tar.js +367 -0
- package/backend/dist/local/transport.d.ts +35 -0
- package/backend/dist/local/transport.js +89 -0
- package/backend/dist/local/tune.d.ts +58 -0
- package/backend/dist/local/tune.js +324 -0
- package/backend/dist/observability/http-exchange.d.ts +2 -2
- package/backend/dist/opencode/catalog/auto-pull.d.ts +14 -3
- package/backend/dist/opencode/catalog/auto-pull.js +276 -70
- package/backend/dist/opencode/catalog/ocr-store.js +3 -1
- package/backend/dist/opencode/catalog/overrides-store.d.ts +10 -1
- package/backend/dist/opencode/catalog/overrides-store.js +6 -0
- package/backend/dist/opencode/catalog/reasoning-declaration.d.ts +35 -0
- package/backend/dist/opencode/catalog/reasoning-declaration.js +66 -0
- package/backend/dist/opencode/catalog/repository.js +25 -2
- package/backend/dist/opencode/catalog/sources/models-dev.js +13 -3
- package/backend/dist/opencode/catalog/types.d.ts +35 -3
- package/backend/dist/opencode/catalog/types.js +38 -1
- package/backend/dist/opencode/credentials/ocr-store.js +11 -2
- package/backend/dist/opencode/credentials/sync.js +12 -3
- package/backend/dist/opencode/credentials/types.d.ts +31 -4
- package/backend/dist/opencode/credentials/types.js +25 -0
- package/backend/dist/opencode/probe.d.ts +21 -4
- package/backend/dist/opencode/probe.js +34 -10
- package/backend/dist/pipeline/directives.d.ts +9 -4
- package/backend/dist/pipeline/directives.js +14 -10
- package/backend/dist/pipeline/orchestrator.d.ts +42 -13
- package/backend/dist/pipeline/orchestrator.js +497 -165
- package/backend/dist/plugins/environment-ack.d.ts +51 -0
- package/backend/dist/plugins/environment-ack.js +81 -0
- package/backend/dist/plugins/gateways.d.ts +6 -6
- package/backend/dist/plugins/gateways.js +2 -2
- package/backend/dist/plugins/host.d.ts +98 -14
- package/backend/dist/plugins/host.js +622 -87
- package/backend/dist/plugins/install-run.d.ts +27 -0
- package/backend/dist/plugins/install-run.js +99 -0
- package/backend/dist/plugins/manifest.d.ts +84 -32
- package/backend/dist/plugins/manifest.js +149 -45
- package/backend/dist/plugins/market-install.d.ts +18 -0
- package/backend/dist/plugins/market-install.js +111 -0
- package/backend/dist/plugins/market-source.d.ts +100 -0
- package/backend/dist/plugins/market-source.js +449 -0
- package/backend/dist/plugins/market-updates.d.ts +70 -0
- package/backend/dist/plugins/market-updates.js +97 -0
- package/backend/dist/plugins/market.d.ts +677 -0
- package/backend/dist/plugins/market.js +2113 -0
- package/backend/dist/plugins/source-index.d.ts +155 -0
- package/backend/dist/plugins/source-index.js +217 -0
- package/backend/dist/plugins/types.d.ts +402 -37
- package/backend/dist/projects/worktrees.d.ts +88 -0
- package/backend/dist/projects/worktrees.js +220 -0
- package/backend/dist/providers/boot-direct.d.ts +41 -7
- package/backend/dist/providers/boot-direct.js +252 -36
- package/backend/dist/providers/compat/tool-markup-recovery.js +31 -6
- package/backend/dist/providers/executors/dispatch.d.ts +17 -7
- package/backend/dist/providers/executors/dispatch.js +28 -9
- package/backend/dist/providers/executors/openai-chat.js +14 -2
- package/backend/dist/providers/executors/plugin-adapter.d.ts +23 -1
- package/backend/dist/providers/executors/plugin-adapter.js +59 -3
- package/backend/dist/providers/member-match.d.ts +32 -9
- package/backend/dist/providers/member-match.js +65 -21
- package/backend/dist/providers/model-resolution.d.ts +62 -0
- package/backend/dist/providers/model-resolution.js +62 -0
- package/backend/dist/providers/price-order.d.ts +51 -0
- package/backend/dist/providers/price-order.js +54 -0
- package/backend/dist/providers/provider-takedown.d.ts +5 -2
- package/backend/dist/providers/registry.d.ts +84 -25
- package/backend/dist/providers/registry.js +209 -114
- package/backend/dist/providers/selection.d.ts +91 -0
- package/backend/dist/providers/selection.js +158 -0
- package/backend/dist/providers/virtual-meta.d.ts +33 -2
- package/backend/dist/providers/virtual-meta.js +74 -18
- package/backend/dist/quota/cli-login.d.ts +25 -4
- package/backend/dist/quota/cli-login.js +35 -5
- package/backend/dist/quota/coverage-generation.d.ts +24 -0
- package/backend/dist/quota/coverage-generation.js +29 -0
- package/backend/dist/quota/declarations.js +8 -4
- package/backend/dist/quota/engine.js +2 -2
- package/backend/dist/quota/prober.d.ts +43 -2
- package/backend/dist/quota/prober.js +97 -22
- package/backend/dist/ratelimit/rate-limiter.d.ts +1 -1
- package/backend/dist/resilience/error-classifier.js +29 -0
- package/backend/dist/router/index.d.ts +1 -1
- package/backend/dist/router/index.js +17 -1
- package/backend/dist/router/layer2-decision.d.ts +1 -1
- package/backend/dist/router/layer2-decision.js +2 -2
- package/backend/dist/routes/console.js +928 -310
- package/backend/dist/routes/environments.js +1 -1
- package/backend/dist/routes/local-models.d.ts +2 -0
- package/backend/dist/routes/local-models.js +1414 -0
- package/backend/dist/routes/mihomo.d.ts +2 -2
- package/backend/dist/routes/mihomo.js +20 -11
- package/backend/dist/routes/projects.js +121 -0
- package/backend/dist/server.js +318 -13
- package/backend/dist/session/session-manager.d.ts +42 -5
- package/backend/dist/session/session-manager.js +64 -11
- package/backend/dist/session/session-row.d.ts +29 -8
- package/backend/dist/session/session-row.js +18 -13
- package/backend/dist/snapshot/bundle.d.ts +40 -0
- package/backend/dist/snapshot/bundle.js +177 -0
- package/backend/dist/snapshot/handoff/compress.d.ts +46 -0
- package/backend/dist/snapshot/handoff/compress.js +77 -0
- package/backend/dist/snapshot/handoff/index.d.ts +119 -0
- package/backend/dist/snapshot/handoff/index.js +160 -0
- package/backend/dist/snapshot/handoff/jsonl-writer.d.ts +78 -0
- package/backend/dist/snapshot/handoff/jsonl-writer.js +175 -0
- package/backend/dist/snapshot/handoff/opencode-writer.d.ts +51 -0
- package/backend/dist/snapshot/handoff/opencode-writer.js +214 -0
- package/backend/dist/snapshot/handoff/summarize.d.ts +39 -0
- package/backend/dist/snapshot/handoff/summarize.js +118 -0
- package/backend/dist/snapshot/handoff/transcript.d.ts +71 -0
- package/backend/dist/snapshot/handoff/transcript.js +167 -0
- package/backend/dist/snapshot/media-fs.d.ts +10 -0
- package/backend/dist/snapshot/media-fs.js +50 -0
- package/backend/dist/snapshot/media.d.ts +32 -0
- package/backend/dist/snapshot/media.js +87 -0
- package/backend/dist/snapshot/store.d.ts +226 -0
- package/backend/dist/snapshot/store.js +887 -0
- package/backend/dist/snapshot/tree.d.ts +112 -0
- package/backend/dist/snapshot/tree.js +207 -0
- package/backend/dist/snapshot/types.d.ts +212 -0
- package/backend/dist/snapshot/types.js +14 -0
- package/backend/dist/snapshot/view.d.ts +19 -0
- package/backend/dist/snapshot/view.js +57 -0
- package/backend/dist/snapshot/write-worker.d.ts +67 -0
- package/backend/dist/snapshot/write-worker.js +129 -0
- package/backend/dist/surfaces/body-admission.d.ts +67 -2
- package/backend/dist/surfaces/body-admission.js +218 -13
- package/backend/dist/surfaces/chat-pipeline.js +8 -0
- package/backend/dist/surfaces/decision-pipeline.js +10 -7
- package/backend/dist/surfaces/gateway-catalog.d.ts +26 -0
- package/backend/dist/surfaces/gateway-catalog.js +202 -0
- package/backend/dist/surfaces/gateway-chat.d.ts +7 -11
- package/backend/dist/surfaces/gateway-chat.js +50 -12
- package/backend/dist/surfaces/ocr-headers.d.ts +6 -4
- package/backend/dist/surfaces/ocr-headers.js +11 -7
- package/backend/dist/surfaces/systemone.js +1 -1
- package/backend/dist/surfaces/transport-fastify.js +32 -5
- package/backend/dist/surfaces/transport-node-http.d.ts +9 -3
- package/backend/dist/surfaces/transport-node-http.js +6 -19
- package/backend/dist/surfaces/types.d.ts +11 -3
- package/backend/dist/trace/persist.js +21 -1
- package/backend/dist/trace/tracker.d.ts +35 -3
- package/backend/dist/trace/tracker.js +23 -0
- package/backend/dist/types/openai.d.ts +8 -0
- package/backend/dist/types/router.d.ts +17 -6
- package/backend/dist/types/router.js +14 -2
- package/backend/dist/utils/client-families.d.ts +66 -0
- package/backend/dist/utils/client-families.js +127 -0
- package/backend/dist/utils/event-ring.d.ts +1 -1
- package/backend/dist/utils/event-ring.js +1 -1
- package/backend/dist/utils/proxy-node.js +1 -1
- package/backend/dist/utils/proxy.d.ts +135 -11
- package/backend/dist/utils/proxy.js +144 -29
- package/backend/dist/utils/run-command.d.ts +21 -1
- package/backend/dist/utils/run-command.js +64 -4
- package/backend/dist/utils/server-liveness.d.ts +3 -2
- package/backend/dist/utils/server-liveness.js +3 -2
- package/backend/dist/utils/session-file.d.ts +28 -0
- package/backend/dist/utils/session-file.js +34 -0
- package/frontend/dist/assets/antigravity.color-DXFfVr6X.svg +39 -0
- package/frontend/dist/assets/gemini-cli.color-BfquLd1p.svg +1 -0
- package/frontend/dist/assets/index-CTZNvn1d.js +1707 -0
- package/frontend/dist/assets/{index-KI1OW5x6.css → index-CqDSOPQ0.css} +1 -1
- package/frontend/dist/index.html +2 -2
- package/package.json +3 -1
- package/frontend/dist/assets/index-Dk76uc7e.js +0 -1522
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import forge from 'node-forge';
|
|
5
|
+
import { getOcrHomeDir, getSharedDataRootDir } from '../cli/paths.js';
|
|
6
|
+
/**
|
|
7
|
+
* MITM CA + per-host certificate minting for the inbound ingress proxy.
|
|
8
|
+
*
|
|
9
|
+
* Generation uses `node:crypto` for the RSA keypairs (native, fast) and
|
|
10
|
+
* node-forge purely for X.509 assembly/signing (Bun has no cert-signing API).
|
|
11
|
+
* On disk under `<caDir>/`: ca.pem + ca-key.pem + leaf-key.pem (all 0600).
|
|
12
|
+
*
|
|
13
|
+
* One shared leaf keypair is reused across every minted cert — the certs are
|
|
14
|
+
* all ours; only the subject/SAN varies per host. Minted certs are cached in
|
|
15
|
+
* memory (persist nothing per-host).
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The Common Name of a NEWLY minted CA.
|
|
19
|
+
*
|
|
20
|
+
* Renaming this is SAFE, and that is verified rather than assumed:
|
|
21
|
+
* - it is used only on first generation (`ensureCa` reads an existing bundle
|
|
22
|
+
* verbatim and never re-signs), so an operator who already imported a CA
|
|
23
|
+
* keeps working with the CN that CA carries;
|
|
24
|
+
* - every trust probe matches the certificate by FINGERPRINT, never by CN
|
|
25
|
+
* (`ca-trust.ts`), because two roots can share a CN.
|
|
26
|
+
*
|
|
27
|
+
* No direction word: this CA belongs to the inbound listener's MITM, and the
|
|
28
|
+
* previous "Forward Proxy" spelling was the retired vocabulary.
|
|
29
|
+
*
|
|
30
|
+
* The one place that DOES depend on the CN is the macOS removal command the
|
|
31
|
+
* console shows — it must name the certificate actually on disk, so the page
|
|
32
|
+
* substitutes `CaMeta.subject` instead of assuming this constant.
|
|
33
|
+
*/
|
|
34
|
+
export const CA_CN = 'OmniCellRouter Proxy CA';
|
|
35
|
+
/** PEM file name inside the resolved CA dir — one spelling for every consumer. */
|
|
36
|
+
export const CA_CERT_FILENAME = 'ca.pem';
|
|
37
|
+
const CA_DAYS = 3650;
|
|
38
|
+
const LEAF_DAYS = 30;
|
|
39
|
+
function generateRsaKeyPem() {
|
|
40
|
+
const { privateKey } = crypto.generateKeyPairSync('rsa', {
|
|
41
|
+
modulusLength: 2048,
|
|
42
|
+
privateKeyEncoding: { type: 'pkcs1', format: 'pem' },
|
|
43
|
+
publicKeyEncoding: { type: 'spki', format: 'pem' },
|
|
44
|
+
});
|
|
45
|
+
return privateKey;
|
|
46
|
+
}
|
|
47
|
+
function createCaCertPem(caKey, commonName) {
|
|
48
|
+
const cert = forge.pki.createCertificate();
|
|
49
|
+
cert.publicKey = forge.pki.setRsaPublicKey(caKey.n, caKey.e);
|
|
50
|
+
cert.serialNumber = '01';
|
|
51
|
+
cert.validity.notBefore = new Date(Date.now() - 24 * 3600 * 1000);
|
|
52
|
+
cert.validity.notAfter = new Date(Date.now() + CA_DAYS * 24 * 3600 * 1000);
|
|
53
|
+
// A unique OU per CA key. Without it every OCR CA shares one subject DN, and
|
|
54
|
+
// a verifier holding several same-subject roots (the operator's installed
|
|
55
|
+
// CA plus a test/rotated one) can select the wrong certificate and report
|
|
56
|
+
// CERT_SIGNATURE_FAILURE. The CN stays stable for CA detection/CLI display.
|
|
57
|
+
const keyId = crypto
|
|
58
|
+
.createHash('sha256')
|
|
59
|
+
.update(`${caKey.n.toString(16)}:${caKey.e.toString(16)}`)
|
|
60
|
+
.digest('hex')
|
|
61
|
+
.slice(0, 8);
|
|
62
|
+
const attrs = [
|
|
63
|
+
{ name: 'commonName', value: commonName },
|
|
64
|
+
{ name: 'organizationalUnitName', value: `CA ${keyId}` },
|
|
65
|
+
];
|
|
66
|
+
cert.setSubject(attrs);
|
|
67
|
+
cert.setIssuer(attrs);
|
|
68
|
+
cert.setExtensions([
|
|
69
|
+
{ name: 'basicConstraints', cA: true },
|
|
70
|
+
{ name: 'keyUsage', keyCertSign: true, cRLSign: true },
|
|
71
|
+
]);
|
|
72
|
+
cert.sign(caKey, forge.md.sha256.create());
|
|
73
|
+
return forge.pki.certificateToPem(cert);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Load the CA bundle from disk, generating (and persisting) it on first use.
|
|
77
|
+
*
|
|
78
|
+
* `commonName` is overridable for TESTS only. A test CA that reuses `CA_CN` is
|
|
79
|
+
* shadowed by an OCR CA installed in the OS trust store: the TLS verifier can
|
|
80
|
+
* resolve the stored same-subject certificate first and fail the signature
|
|
81
|
+
* check (CERT_SIGNATURE_FAILURE) even though the minted CA is valid.
|
|
82
|
+
*
|
|
83
|
+
* A persisted bundle whose CN differs from an EXPLICITLY requested one is an
|
|
84
|
+
* ERROR, never a silent return: `ensureCa(dir, testCn)` on a dir that already
|
|
85
|
+
* holds the operator CA would hand back the production CA and reintroduce
|
|
86
|
+
* exactly that shadowing with no trace of what happened. The DEFAULT CN stays
|
|
87
|
+
* permissive on purpose — the proxy, the PEM download and the CA card all call
|
|
88
|
+
* `ensureCa(dir)` and must keep working over whatever bundle the dir holds
|
|
89
|
+
* (test sandboxes seed one).
|
|
90
|
+
*/
|
|
91
|
+
export function ensureCa(caDir, commonName = CA_CN) {
|
|
92
|
+
fs.mkdirSync(caDir, { recursive: true });
|
|
93
|
+
const caCertFile = path.join(caDir, CA_CERT_FILENAME);
|
|
94
|
+
const caKeyPath = path.join(caDir, 'ca-key.pem');
|
|
95
|
+
const leafKeyPath = path.join(caDir, 'leaf-key.pem');
|
|
96
|
+
let caCertPem;
|
|
97
|
+
let caKeyPem;
|
|
98
|
+
let leafKeyPem;
|
|
99
|
+
if (fs.existsSync(caCertFile) && fs.existsSync(caKeyPath) && fs.existsSync(leafKeyPath)) {
|
|
100
|
+
caCertPem = fs.readFileSync(caCertFile, 'utf8');
|
|
101
|
+
caKeyPem = fs.readFileSync(caKeyPath, 'utf8');
|
|
102
|
+
leafKeyPem = fs.readFileSync(leafKeyPath, 'utf8');
|
|
103
|
+
const persistedCn = forge.pki.certificateFromPem(caCertPem).subject.getField('CN').value;
|
|
104
|
+
if (commonName !== CA_CN && persistedCn !== commonName) {
|
|
105
|
+
throw new Error(`CA at ${caDir} has CN "${persistedCn}", but "${commonName}" was requested — refusing to return a CA under the wrong identity.`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
caKeyPem = generateRsaKeyPem();
|
|
110
|
+
leafKeyPem = generateRsaKeyPem();
|
|
111
|
+
const caKey = forge.pki.privateKeyFromPem(caKeyPem);
|
|
112
|
+
caCertPem = createCaCertPem(caKey, commonName);
|
|
113
|
+
fs.writeFileSync(caCertFile, caCertPem, { mode: 0o600 });
|
|
114
|
+
fs.writeFileSync(caKeyPath, caKeyPem, { mode: 0o600 });
|
|
115
|
+
fs.writeFileSync(leafKeyPath, leafKeyPem, { mode: 0o600 });
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
caCertPem,
|
|
119
|
+
caCert: forge.pki.certificateFromPem(caCertPem),
|
|
120
|
+
caKey: forge.pki.privateKeyFromPem(caKeyPem),
|
|
121
|
+
leafKeyPem,
|
|
122
|
+
leafKey: forge.pki.privateKeyFromPem(leafKeyPem),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The machine-wide CA directory every OCR book-set shares: the per-user data
|
|
127
|
+
* root (the desktop shell's default OCR_HOME) + `ingress-proxy`. A trust anchor
|
|
128
|
+
* is MACHINE state — a second install must adopt the root the operator already
|
|
129
|
+
* imported instead of minting a same-CN twin that clients can pick by mistake
|
|
130
|
+
* (`CERT_SIGNATURE_FAILURE`). `ingressProxy.caDir` is the operator override;
|
|
131
|
+
* `OCR_CA_DIR` pins the default for sandboxed test runs.
|
|
132
|
+
*/
|
|
133
|
+
export function defaultCaDir() {
|
|
134
|
+
return path.join(getSharedDataRootDir(), 'ingress-proxy');
|
|
135
|
+
}
|
|
136
|
+
const CA_FILES = ['ca.pem', 'ca-key.pem', 'leaf-key.pem'];
|
|
137
|
+
/**
|
|
138
|
+
* Adopt a CA from a directory an older release used, into the CURRENT dir.
|
|
139
|
+
*
|
|
140
|
+
* Two sources, in order:
|
|
141
|
+
* 1. `<sharedRoot>/forward-proxy` — the pre-rename spelling of THIS directory;
|
|
142
|
+
* 2. `<ocrHome>/forward-proxy` — the even older per-home default.
|
|
143
|
+
*
|
|
144
|
+
* Upgrades MUST keep the same identity: regenerating would invalidate the root
|
|
145
|
+
* the operator already imported into the OS trust store, because a trust store
|
|
146
|
+
* pins the certificate's FINGERPRINT, not its path. So the files are COPIED
|
|
147
|
+
* byte-for-byte, never re-minted. Runs only while the target holds no CA; each
|
|
148
|
+
* file lands through temp+rename so a concurrent boot never reads a half-written
|
|
149
|
+
* key. Best-effort: a failed adoption falls through to minting a fresh CA.
|
|
150
|
+
*/
|
|
151
|
+
function adoptLegacyCa(targetDir) {
|
|
152
|
+
const candidates = [
|
|
153
|
+
path.join(getSharedDataRootDir(), 'forward-proxy'),
|
|
154
|
+
path.join(getOcrHomeDir(), 'forward-proxy'),
|
|
155
|
+
];
|
|
156
|
+
if (CA_FILES.some((name) => fs.existsSync(path.join(targetDir, name))))
|
|
157
|
+
return;
|
|
158
|
+
const legacyDir = candidates.find((dir) => path.resolve(dir) !== path.resolve(targetDir) &&
|
|
159
|
+
CA_FILES.every((name) => fs.existsSync(path.join(dir, name))));
|
|
160
|
+
if (!legacyDir)
|
|
161
|
+
return;
|
|
162
|
+
try {
|
|
163
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
164
|
+
for (const name of CA_FILES) {
|
|
165
|
+
const dest = path.join(targetDir, name);
|
|
166
|
+
if (fs.existsSync(dest))
|
|
167
|
+
continue;
|
|
168
|
+
const tmp = `${dest}.${process.pid}.tmp`;
|
|
169
|
+
try {
|
|
170
|
+
fs.copyFileSync(path.join(legacyDir, name), tmp);
|
|
171
|
+
fs.renameSync(tmp, dest);
|
|
172
|
+
fs.chmodSync(dest, 0o600);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
fs.rmSync(tmp, { force: true });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
// Unreadable legacy dir or a read-only data root: fall through to a fresh CA.
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Resolve the MITM CA directory: the operator's `ingressProxy.caDir` override,
|
|
185
|
+
* else the `OCR_CA_DIR` sandbox pin, else the machine-wide default (adopting a
|
|
186
|
+
* legacy per-home CA first). ONE spelling for the proxy, the console CA
|
|
187
|
+
* download and the system-proxy trust hint — a drift twin here points users at
|
|
188
|
+
* a certificate the proxy does not use.
|
|
189
|
+
*/
|
|
190
|
+
export function resolveCaDir(caDir) {
|
|
191
|
+
const explicit = caDir?.trim() || process.env.OCR_CA_DIR?.trim();
|
|
192
|
+
if (explicit)
|
|
193
|
+
return explicit;
|
|
194
|
+
const dir = defaultCaDir();
|
|
195
|
+
adoptLegacyCa(dir);
|
|
196
|
+
return dir;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Absolute path of the PEM clients must trust. The proxy, the console CA card,
|
|
200
|
+
* the trust probe and the system-proxy hint all come through here — a second
|
|
201
|
+
* `path.join(..., 'ca.pem')` is the drift twin that points users at a
|
|
202
|
+
* certificate the proxy does not sign with.
|
|
203
|
+
*/
|
|
204
|
+
export function caCertPath(caDir) {
|
|
205
|
+
return path.join(resolveCaDir(caDir), CA_CERT_FILENAME);
|
|
206
|
+
}
|
|
207
|
+
/** Read/generate the CA and describe it without exposing key material. */
|
|
208
|
+
export function describeCa(caDir) {
|
|
209
|
+
const dir = resolveCaDir(caDir);
|
|
210
|
+
const x509 = new crypto.X509Certificate(ensureCa(dir).caCertPem);
|
|
211
|
+
return {
|
|
212
|
+
path: path.join(dir, CA_CERT_FILENAME),
|
|
213
|
+
fingerprintSha256: x509.fingerprint256,
|
|
214
|
+
subject: x509.subject.split('\n').join(', '),
|
|
215
|
+
notBefore: new Date(x509.validFrom).toISOString(),
|
|
216
|
+
notAfter: new Date(x509.validTo).toISOString(),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Cap on cached leaf certs. Full-capture MITM mints one per host and the proxy
|
|
221
|
+
* sees every host a client visits, so an unbounded map is a slow leak; evicting
|
|
222
|
+
* a cert is free (the next CONNECT re-mints it from the same CA).
|
|
223
|
+
*/
|
|
224
|
+
const MAX_CACHED_CERTS = 512;
|
|
225
|
+
export class CertMinter {
|
|
226
|
+
ca;
|
|
227
|
+
cache = new Map();
|
|
228
|
+
constructor(ca) {
|
|
229
|
+
this.ca = ca;
|
|
230
|
+
}
|
|
231
|
+
/** Cached per-host leaf cert for the per-host `tls.createServer` (server.ts). */
|
|
232
|
+
get(host) {
|
|
233
|
+
const hit = this.cache.get(host);
|
|
234
|
+
if (hit) {
|
|
235
|
+
// Re-insert to mark most-recently-used (a Map keeps insertion order).
|
|
236
|
+
this.cache.delete(host);
|
|
237
|
+
this.cache.set(host, hit);
|
|
238
|
+
return hit;
|
|
239
|
+
}
|
|
240
|
+
const certPem = this.mintLeaf(host);
|
|
241
|
+
const out = {
|
|
242
|
+
key: this.ca.leafKeyPem,
|
|
243
|
+
cert: certPem,
|
|
244
|
+
};
|
|
245
|
+
this.cache.set(host, out);
|
|
246
|
+
while (this.cache.size > MAX_CACHED_CERTS) {
|
|
247
|
+
const oldest = this.cache.keys().next();
|
|
248
|
+
if (oldest.done)
|
|
249
|
+
break;
|
|
250
|
+
this.cache.delete(oldest.value);
|
|
251
|
+
}
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
mintLeaf(host) {
|
|
255
|
+
const cert = forge.pki.createCertificate();
|
|
256
|
+
cert.publicKey = forge.pki.setRsaPublicKey(this.ca.leafKey.n, this.ca.leafKey.e);
|
|
257
|
+
cert.serialNumber = '02' + crypto.randomBytes(9).toString('hex');
|
|
258
|
+
cert.validity.notBefore = new Date(Date.now() - 24 * 3600 * 1000);
|
|
259
|
+
cert.validity.notAfter = new Date(Date.now() + LEAF_DAYS * 24 * 3600 * 1000);
|
|
260
|
+
cert.setSubject([{ name: 'commonName', value: host }]);
|
|
261
|
+
cert.setIssuer(this.ca.caCert.subject.attributes);
|
|
262
|
+
const isIp = /^\d{1,3}(\.\d{1,3}){3}$/.test(host);
|
|
263
|
+
const altNames = (isIp ? [{ type: 7, ip: host }] : [{ type: 2, value: host }]);
|
|
264
|
+
cert.setExtensions([
|
|
265
|
+
{ name: 'basicConstraints', cA: false },
|
|
266
|
+
{ name: 'keyUsage', digitalSignature: true, keyEncipherment: true },
|
|
267
|
+
{ name: 'extKeyUsage', serverAuth: true },
|
|
268
|
+
{ name: 'subjectAltName', altNames },
|
|
269
|
+
]);
|
|
270
|
+
cert.sign(this.ca.caKey, forge.md.sha256.create());
|
|
271
|
+
return forge.pki.certificateToPem(cert);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The inbound listener's own state directory under `<ocrHome>`:
|
|
3
|
+
* `access-log/` (the traffic archive) and `system-proxy.json` (the OS-proxy
|
|
4
|
+
* snapshot) live here.
|
|
5
|
+
*
|
|
6
|
+
* A LEAF module on purpose — `index.ts`, `access-log.ts` and `system-proxy.ts`
|
|
7
|
+
* all need the name, and routing it through `index.ts` would make two of them
|
|
8
|
+
* import their own parent. One spelling, one file.
|
|
9
|
+
*/
|
|
10
|
+
export declare const INGRESS_PROXY_DATA_DIR = "ingress-proxy";
|
|
11
|
+
/** The pre-rename spelling. Read-only from here on: it is migration INPUT. */
|
|
12
|
+
export declare const LEGACY_PROXY_DATA_DIR = "forward-proxy";
|
|
13
|
+
export declare function ingressProxyDataPath(...segments: string[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* Rename `<ocrHome>/forward-proxy` to `<ocrHome>/ingress-proxy`, once.
|
|
16
|
+
*
|
|
17
|
+
* Fail-safe in both directions:
|
|
18
|
+
* - the new directory already exists → nothing moves (a rename over it would
|
|
19
|
+
* orphan whatever new code already wrote);
|
|
20
|
+
* - the rename fails (cross-device, permissions, an open file) → the OLD path
|
|
21
|
+
* keeps serving, because losing the archive is worse than an old name.
|
|
22
|
+
*
|
|
23
|
+
* A `renameSync` on one filesystem, never a copy: the archive grows to many MB.
|
|
24
|
+
*/
|
|
25
|
+
export declare function migrateIngressProxyDataDir(): {
|
|
26
|
+
migrated: boolean;
|
|
27
|
+
dir: string;
|
|
28
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { getOcrHomeDir } from '../cli/paths.js';
|
|
4
|
+
/**
|
|
5
|
+
* The inbound listener's own state directory under `<ocrHome>`:
|
|
6
|
+
* `access-log/` (the traffic archive) and `system-proxy.json` (the OS-proxy
|
|
7
|
+
* snapshot) live here.
|
|
8
|
+
*
|
|
9
|
+
* A LEAF module on purpose — `index.ts`, `access-log.ts` and `system-proxy.ts`
|
|
10
|
+
* all need the name, and routing it through `index.ts` would make two of them
|
|
11
|
+
* import their own parent. One spelling, one file.
|
|
12
|
+
*/
|
|
13
|
+
export const INGRESS_PROXY_DATA_DIR = 'ingress-proxy';
|
|
14
|
+
/** The pre-rename spelling. Read-only from here on: it is migration INPUT. */
|
|
15
|
+
export const LEGACY_PROXY_DATA_DIR = 'forward-proxy';
|
|
16
|
+
export function ingressProxyDataPath(...segments) {
|
|
17
|
+
return path.join(getOcrHomeDir(), INGRESS_PROXY_DATA_DIR, ...segments);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Rename `<ocrHome>/forward-proxy` to `<ocrHome>/ingress-proxy`, once.
|
|
21
|
+
*
|
|
22
|
+
* Fail-safe in both directions:
|
|
23
|
+
* - the new directory already exists → nothing moves (a rename over it would
|
|
24
|
+
* orphan whatever new code already wrote);
|
|
25
|
+
* - the rename fails (cross-device, permissions, an open file) → the OLD path
|
|
26
|
+
* keeps serving, because losing the archive is worse than an old name.
|
|
27
|
+
*
|
|
28
|
+
* A `renameSync` on one filesystem, never a copy: the archive grows to many MB.
|
|
29
|
+
*/
|
|
30
|
+
export function migrateIngressProxyDataDir() {
|
|
31
|
+
const home = getOcrHomeDir();
|
|
32
|
+
const next = path.join(home, INGRESS_PROXY_DATA_DIR);
|
|
33
|
+
const legacy = path.join(home, LEGACY_PROXY_DATA_DIR);
|
|
34
|
+
if (fs.existsSync(next) || !fs.existsSync(legacy))
|
|
35
|
+
return { migrated: false, dir: next };
|
|
36
|
+
try {
|
|
37
|
+
fs.renameSync(legacy, next);
|
|
38
|
+
console.log(`[IngressProxy] moved ${LEGACY_PROXY_DATA_DIR}/ -> ${INGRESS_PROXY_DATA_DIR}/ (traffic archive + OS-proxy snapshot)`);
|
|
39
|
+
return { migrated: true, dir: next };
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
console.warn(`[IngressProxy] could not move ${LEGACY_PROXY_DATA_DIR}/ -> ${INGRESS_PROXY_DATA_DIR}/ (${err?.message ?? err}); continuing on the old directory`);
|
|
43
|
+
return { migrated: false, dir: legacy };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import https from 'node:https';
|
|
3
|
+
import net from 'node:net';
|
|
4
|
+
import type { InterceptPosture, IngressProxyConfig, IngressProxyRule } from '../config/types.js';
|
|
5
|
+
import { type RuleDecision } from './rules.js';
|
|
6
|
+
export declare function setLiveIngressProxy(reader: (() => IngressProxyConfig | undefined) | undefined): void;
|
|
7
|
+
/** Boot snapshot of the rule table + posture — only one ingress proxy exists per process. */
|
|
8
|
+
export declare function setBootRules(rules: IngressProxyRule[] | undefined, intercept?: InterceptPosture): void;
|
|
9
|
+
/** The rule table in force for this request (live config first, boot snapshot second). */
|
|
10
|
+
export declare function currentRules(): IngressProxyRule[] | undefined;
|
|
11
|
+
/** The interception posture in force for this request (live config first, boot snapshot second). */
|
|
12
|
+
export declare function currentInterceptPosture(): InterceptPosture;
|
|
13
|
+
/**
|
|
14
|
+
* The full decision for one host. Every leg and the console preview call this
|
|
15
|
+
* (directly or through the thin helpers below), so they cannot disagree.
|
|
16
|
+
*
|
|
17
|
+
* Claims are read from the LIVE plugin registry on every call (the host swaps it
|
|
18
|
+
* atomically on install/uninstall/disable, ADR-0017), and the posture comes from
|
|
19
|
+
* the live config ref — so neither a plugin install nor a console save needs a
|
|
20
|
+
* restart. The egress callback is live for the same reason: the tier that owns a
|
|
21
|
+
* claimed host's leg may be the plugin's own code answering for THIS request.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ruleDecision(host: string): RuleDecision;
|
|
24
|
+
/**
|
|
25
|
+
* Admission gate: true when a rule rejects this host. Every proxy leg consults
|
|
26
|
+
* this BEFORE opening a tunnel or minting a certificate.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isRuleRejected(host: string): boolean;
|
|
29
|
+
/** True when the host must NOT be intercepted (blind tunnel). */
|
|
30
|
+
export declare function ruleTunnels(host: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Does a rule or a claim WANT this host on the outbound proxy?
|
|
33
|
+
*
|
|
34
|
+
* The INTENT half, and only that: it reads the rule table plus the live claim
|
|
35
|
+
* ladder and says which leg they name. It deliberately does not look at
|
|
36
|
+
* `proxy.enabled` — "the operator declared this host must be proxied" and "this
|
|
37
|
+
* machine has a proxy to send it through" are two facts, and answering them in
|
|
38
|
+
* one place used to let the second silently overwrite the first. That comparison
|
|
39
|
+
* lives in {@link resolveDialEgress}, which is what a dial actually calls.
|
|
40
|
+
*
|
|
41
|
+
* The empty-table escape survives for the same reason it always had: no table
|
|
42
|
+
* installed means the historical DIRECT, but a claim's leg is not a table row,
|
|
43
|
+
* so the escape must not swallow it — relaying direct while every preview of the
|
|
44
|
+
* same host reads `proxy` is the preview/reality split this module exists to
|
|
45
|
+
* prevent.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isProxyRouted(host: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* What a DIAL must do for one host, decided in ONE place.
|
|
50
|
+
*
|
|
51
|
+
* This is the only code that compares "the route says proxy" against "there is
|
|
52
|
+
* an outbound proxy to dial through". Before it existed, every leg asked the
|
|
53
|
+
* two questions separately and quietly answered DIRECT when the second came
|
|
54
|
+
* back empty — a host the operator had declared must be proxied went out over
|
|
55
|
+
* this machine's own address with no log, no ledger row and no console warning
|
|
56
|
+
* (`proxy-rule-without-proxy` covers table rows only, and a plugin claim is not
|
|
57
|
+
* a row).
|
|
58
|
+
*
|
|
59
|
+
* A tagged union, not a bag of optional fields: every outcome has a name, so a
|
|
60
|
+
* call site never reaches "direct" by a value being absent (the trap ADR-0009
|
|
61
|
+
* bans for the plugin seam, applied here for the same reason). `blocked` is a
|
|
62
|
+
* REFUSAL, not a fallback — the operator's intent and the machine's
|
|
63
|
+
* configuration disagree, so the leg is answered with
|
|
64
|
+
* {@link EGRESS_UNAVAILABLE_MESSAGE} instead of a silent direct dial.
|
|
65
|
+
*/
|
|
66
|
+
export type DialEgress = {
|
|
67
|
+
via: 'proxy';
|
|
68
|
+
url: string;
|
|
69
|
+
} | {
|
|
70
|
+
via: 'direct';
|
|
71
|
+
} | {
|
|
72
|
+
via: 'blocked';
|
|
73
|
+
reason: 'no-endpoint';
|
|
74
|
+
};
|
|
75
|
+
export declare function resolveDialEgress(host: string): DialEgress;
|
|
76
|
+
/** True when the operator's egress proxy is switched on at all. */
|
|
77
|
+
export declare function isEgressProxyEnabled(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* The refusal every leg answers for `{ via: 'blocked' }`. Spelled once: the
|
|
80
|
+
* client sees the same sentence on h1, h2, blind tunnels and the client-gateway
|
|
81
|
+
* relay, and it names the FIX rather than the symptom.
|
|
82
|
+
*/
|
|
83
|
+
export declare const EGRESS_UNAVAILABLE_MESSAGE: string;
|
|
84
|
+
export declare function filterHeaders(headers: http.IncomingHttpHeaders): Record<string, string | string[]>;
|
|
85
|
+
export declare function parseProxy(proxyUrl: string): {
|
|
86
|
+
host: string;
|
|
87
|
+
port: number;
|
|
88
|
+
auth?: string;
|
|
89
|
+
} | null;
|
|
90
|
+
/**
|
|
91
|
+
* Open a raw byte pipe to `host:port` through an HTTP CONNECT proxy.
|
|
92
|
+
* Resolves with the tunneled socket (paused — consumers must splice/pipe,
|
|
93
|
+
* which resumes it; Bun drops listener-less early data, hence the pause).
|
|
94
|
+
*/
|
|
95
|
+
export declare function openViaProxy(proxyUrl: string, host: string, port: number): Promise<net.Socket>;
|
|
96
|
+
/** Node http/https request verb for a target scheme. */
|
|
97
|
+
export declare function transportFor(secure: boolean): typeof http | typeof https;
|
|
98
|
+
/**
|
|
99
|
+
* `servername` for an upstream TLS client we originate on a proxied client's
|
|
100
|
+
* behalf — empty for an IP literal.
|
|
101
|
+
*
|
|
102
|
+
* RFC 6066 forbids an IP address in SNI, and Node/Bun do not degrade quietly:
|
|
103
|
+
* `tls.connect({ servername: '127.0.0.1' })` THROWS synchronously (verified on
|
|
104
|
+
* Bun 1.3.14: "Setting the TLS ServerName to an IP address is not permitted").
|
|
105
|
+
* Thrown from a socket 'data' listener that is an uncaught exception, so an
|
|
106
|
+
* IP-addressed origin (an IP literal in the request line, a passthrough-rule
|
|
107
|
+
* host, an
|
|
108
|
+
* internal service) used to kill the connection silently. An IP origin needs
|
|
109
|
+
* no SNI: the certificate is validated against its IP SAN instead.
|
|
110
|
+
*/
|
|
111
|
+
export declare function upstreamServernameOption(host: string): {
|
|
112
|
+
servername?: string;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* ONE honest sentence for a failed origin leg, shared by every forwarder (h1
|
|
116
|
+
* direct, h1 through the outbound proxy, the h2 relay and the Upgrade relay).
|
|
117
|
+
*
|
|
118
|
+
* Every failure used to collapse into "upstream connection failed", throwing
|
|
119
|
+
* away the only information that identifies the cause: a TLS TRUST failure (a
|
|
120
|
+
* private CA the operator has to trust — ADR-0019), a DNS failure, a refused
|
|
121
|
+
* port. The error code now rides in the message the client sees AND in the
|
|
122
|
+
* ledger note, so "why did this host stop working" is answerable from the
|
|
123
|
+
* console instead of from a packet capture.
|
|
124
|
+
*/
|
|
125
|
+
export interface UpstreamFailure {
|
|
126
|
+
status: number;
|
|
127
|
+
message: string;
|
|
128
|
+
/** Ledger note (a stable prefix + the code), never user-facing prose. */
|
|
129
|
+
note: string;
|
|
130
|
+
}
|
|
131
|
+
/** Our own hang guard's code (never a socket error). */
|
|
132
|
+
export declare const UPSTREAM_TIMEOUT_CODE = "OCR_UPSTREAM_TIMEOUT";
|
|
133
|
+
/** Human label for a failed origin leg: the socket code when it has one. */
|
|
134
|
+
export declare function failureLabel(err: unknown): string;
|
|
135
|
+
export declare function shouldRetryOriginLeg(err: unknown, state: {
|
|
136
|
+
headersSent: boolean;
|
|
137
|
+
sentBytes: number;
|
|
138
|
+
attempts: number;
|
|
139
|
+
}): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Classify an origin-leg error.
|
|
142
|
+
*
|
|
143
|
+
* `timedOut` is passed by the callers that arm their own hang guard (the guard
|
|
144
|
+
* destroys the request with a synthetic `upstream timeout` error, so the code
|
|
145
|
+
* is ours, not the socket's).
|
|
146
|
+
*/
|
|
147
|
+
export declare function describeUpstreamFailure(err: unknown, opts?: {
|
|
148
|
+
proxied?: boolean;
|
|
149
|
+
timedOut?: boolean;
|
|
150
|
+
prefix?: string;
|
|
151
|
+
}): UpstreamFailure;
|