@jingyi0605/codingns 0.4.0 → 0.5.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/bin/codingns.mjs +425 -1
- package/dist/public/assets/AdaptiveButlerPage-B153lk5H.css +1 -0
- package/dist/public/assets/AdaptiveButlerPage-R-XZw7pd.js +3 -0
- package/dist/public/assets/App-DUAg5urj.css +1 -0
- package/dist/public/assets/App-DkvE5EyM.js +30 -0
- package/dist/public/assets/BootstrapPage-Vu5oEJ8z.js +1 -0
- package/dist/public/assets/ConversationPage-Cjpg6g0J.js +2 -0
- package/dist/public/assets/DesktopDetachPreviewPage-BgeEqbc5.js +1 -0
- package/dist/public/assets/DesktopWindowPage-1WelvxdH.js +2 -0
- package/dist/public/assets/FileContextPanel-D_ghXJuW.js +1 -0
- package/dist/public/assets/GitSidebar-D9f9Jxwr.js +6 -0
- package/dist/public/assets/MobileCreateSessionSheet-DLq5qPkx.js +1 -0
- package/dist/public/assets/MobileSheet-DLg-gX1t.js +1 -0
- package/dist/public/assets/MobileTopHeaderFrame-DArgZI7L.js +1 -0
- package/dist/public/assets/MobileWorkspaceSwitcherHeader-0ywJKfBQ.js +1 -0
- package/dist/public/assets/ServerSettingsModal-izoYMx9U.js +1 -0
- package/dist/public/assets/SessionIndexPage-C5aG8FIv.js +1 -0
- package/dist/public/assets/SettingsPage-HJIC-P-4.js +1 -0
- package/dist/public/assets/TerminalManagerPanel-DpyUTo9k.js +1 -0
- package/dist/public/assets/{TerminalPage-6jHZV9Mh.js → TerminalPage-CtKXIU0h.js} +19 -19
- package/dist/public/assets/TerminalRuntimeFallbackModal-CRhOQOsT.js +1 -0
- package/dist/public/assets/ToolFilesPage-DcYPsS-e.js +1 -0
- package/dist/public/assets/ToolGitPage-CsPl89ty.js +1 -0
- package/dist/public/assets/ToolProcessesPage-D0dvR8xK.js +1 -0
- package/dist/public/assets/ToolsHomePage-4fP-KRiv.js +1 -0
- package/dist/public/assets/WorkbenchLandingPage-kvlfyxRo.js +1 -0
- package/dist/public/assets/WorkbenchLayout-ByFw4eeu.js +3 -0
- package/dist/public/assets/WorkbenchModal-Ctob14VR.js +1 -0
- package/dist/public/assets/WorkbenchShellRoute-BUITtdAg.css +1 -0
- package/dist/public/assets/WorkbenchShellRoute-Kw7JEZI3.js +1 -0
- package/dist/public/assets/WorkspaceDebugDetailPage-Com5kEXJ.js +1 -0
- package/dist/public/assets/WorkspaceDetailPage-D0Lrx4Uz.js +1 -0
- package/dist/public/assets/WorkspaceHomePage-wR8d3aP9.js +1 -0
- package/dist/public/assets/butler-records-events-DgWCG364.js +1 -0
- package/dist/public/assets/default-session-permission-mode-CcGwR4Kk.js +1 -0
- package/dist/public/assets/event-DvH9tcej.js +1 -0
- package/dist/public/assets/file-tree-icon-UFVoVzhM.js +31 -0
- package/dist/public/assets/index-Byp9hJ0c.js +42 -0
- package/dist/public/assets/index-_52jxu4a.css +1 -0
- package/dist/public/assets/preferences-service-KIYeE2gk.js +1 -0
- package/dist/public/assets/session-runtime-machine-0KNSSPp5.js +17 -0
- package/dist/public/assets/styles-BWPBZvze.css +1 -0
- package/dist/public/assets/styles-CSUx5LGe.js +1 -0
- package/dist/public/assets/terminal-runtime-meta-AWXJpN4r.js +1 -0
- package/dist/public/assets/useRegisteredDebugTemplates-DBDRdptr.js +1 -0
- package/dist/public/assets/window-BWqRixxq.js +1 -0
- package/dist/public/index.html +2 -2
- package/dist/server/middlewares/auth-guard.d.ts +4 -0
- package/dist/server/middlewares/auth-guard.js +42 -4
- package/dist/server/middlewares/auth-guard.js.map +1 -1
- package/dist/server/modules/assistant-capability/assistant-capability-controller.d.ts +62 -1
- package/dist/server/modules/assistant-capability/assistant-capability-controller.js +58 -0
- package/dist/server/modules/assistant-capability/assistant-capability-controller.js.map +1 -1
- package/dist/server/modules/assistant-capability/assistant-capability-service.d.ts +66 -3
- package/dist/server/modules/assistant-capability/assistant-capability-service.js +173 -1
- package/dist/server/modules/assistant-capability/assistant-capability-service.js.map +1 -1
- package/dist/server/modules/auth/auth-controller.d.ts +11 -1
- package/dist/server/modules/auth/auth-controller.js +61 -2
- package/dist/server/modules/auth/auth-controller.js.map +1 -1
- package/dist/server/modules/auth/auth-device-display-name.d.ts +10 -0
- package/dist/server/modules/auth/auth-device-display-name.js +190 -0
- package/dist/server/modules/auth/auth-device-display-name.js.map +1 -0
- package/dist/server/modules/auth/auth-service.d.ts +80 -5
- package/dist/server/modules/auth/auth-service.js +333 -23
- package/dist/server/modules/auth/auth-service.js.map +1 -1
- package/dist/server/modules/butler/assistant-automation-service.d.ts +2 -0
- package/dist/server/modules/butler/assistant-automation-service.js +46 -0
- package/dist/server/modules/butler/assistant-automation-service.js.map +1 -1
- package/dist/server/modules/butler/assistant-sandbox-cleanup-scheduler.d.ts +32 -0
- package/dist/server/modules/butler/assistant-sandbox-cleanup-scheduler.js +93 -0
- package/dist/server/modules/butler/assistant-sandbox-cleanup-scheduler.js.map +1 -0
- package/dist/server/modules/butler/assistant-sandbox-service.d.ts +16 -2
- package/dist/server/modules/butler/assistant-sandbox-service.js +137 -4
- package/dist/server/modules/butler/assistant-sandbox-service.js.map +1 -1
- package/dist/server/modules/butler/butler-auth-service.js +7 -2
- package/dist/server/modules/butler/butler-auth-service.js.map +1 -1
- package/dist/server/modules/butler/butler-control-session-service.d.ts +4 -1
- package/dist/server/modules/butler/butler-control-session-service.js +20 -1
- package/dist/server/modules/butler/butler-control-session-service.js.map +1 -1
- package/dist/server/modules/butler/butler-follow-up-evaluation-instruction-adapter.d.ts +2 -1
- package/dist/server/modules/butler/butler-follow-up-evaluation-instruction-adapter.js +27 -25
- package/dist/server/modules/butler/butler-follow-up-evaluation-instruction-adapter.js.map +1 -1
- package/dist/server/modules/butler/butler-follow-up-service.d.ts +32 -4
- package/dist/server/modules/butler/butler-follow-up-service.js +436 -331
- package/dist/server/modules/butler/butler-follow-up-service.js.map +1 -1
- package/dist/server/modules/butler/butler-inbox-analysis-service.d.ts +1 -1
- package/dist/server/modules/butler/butler-inbox-analysis-service.js.map +1 -1
- package/dist/server/modules/butler/butler-inbox-service.js +1 -0
- package/dist/server/modules/butler/butler-inbox-service.js.map +1 -1
- package/dist/server/modules/butler/butler-session-service.d.ts +3 -1
- package/dist/server/modules/butler/butler-session-service.js +15 -1
- package/dist/server/modules/butler/butler-session-service.js.map +1 -1
- package/dist/server/modules/butler/butler-workspace-context.d.ts +1 -1
- package/dist/server/modules/butler/butler-workspace-context.js +54 -28
- package/dist/server/modules/butler/butler-workspace-context.js.map +1 -1
- package/dist/server/modules/provider/provider-controller.d.ts +1 -1
- package/dist/server/modules/provider/provider-controller.js.map +1 -1
- package/dist/server/modules/relay-tunnel/crypto/relay-tunnel-identity-service.d.ts +10 -0
- package/dist/server/modules/relay-tunnel/crypto/relay-tunnel-identity-service.js +48 -0
- package/dist/server/modules/relay-tunnel/crypto/relay-tunnel-identity-service.js.map +1 -0
- package/dist/server/modules/relay-tunnel/crypto/relay-tunnel-packets.d.ts +48 -0
- package/dist/server/modules/relay-tunnel/crypto/relay-tunnel-packets.js +11 -0
- package/dist/server/modules/relay-tunnel/crypto/relay-tunnel-packets.js.map +1 -0
- package/dist/server/modules/relay-tunnel/crypto/relay-tunnel-protocol.d.ts +74 -0
- package/dist/server/modules/relay-tunnel/crypto/relay-tunnel-protocol.js +302 -0
- package/dist/server/modules/relay-tunnel/crypto/relay-tunnel-protocol.js.map +1 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-controller.d.ts +33 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-controller.js +57 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-controller.js.map +1 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-edge-proof.d.ts +9 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-edge-proof.js +25 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-edge-proof.js.map +1 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-gateway-service.d.ts +18 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-gateway-service.js +230 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-gateway-service.js.map +1 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-runtime-adapter.d.ts +41 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-runtime-adapter.js +443 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-runtime-adapter.js.map +1 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-service.d.ts +111 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-service.js +771 -0
- package/dist/server/modules/relay-tunnel/relay-tunnel-service.js.map +1 -0
- package/dist/server/modules/sessions/codex-app-server-helper-client.d.ts +2 -1
- package/dist/server/modules/sessions/codex-app-server-helper-client.js +78 -0
- package/dist/server/modules/sessions/codex-app-server-helper-client.js.map +1 -1
- package/dist/server/modules/sessions/codex-app-server-helper-process.js +84 -2
- package/dist/server/modules/sessions/codex-app-server-helper-process.js.map +1 -1
- package/dist/server/modules/sessions/provider-session-delete-cli.d.ts +15 -0
- package/dist/server/modules/sessions/provider-session-delete-cli.js +148 -0
- package/dist/server/modules/sessions/provider-session-delete-cli.js.map +1 -0
- package/dist/server/modules/sessions/session-controller.d.ts +4 -1
- package/dist/server/modules/sessions/session-controller.js +4 -0
- package/dist/server/modules/sessions/session-controller.js.map +1 -1
- package/dist/server/modules/sessions/session-history-service.d.ts +17 -0
- package/dist/server/modules/sessions/session-history-service.js +150 -1
- package/dist/server/modules/sessions/session-history-service.js.map +1 -1
- package/dist/server/modules/sessions/session-live-runtime-router-service.d.ts +25 -0
- package/dist/server/modules/sessions/session-live-runtime-router-service.js +42 -0
- package/dist/server/modules/sessions/session-live-runtime-router-service.js.map +1 -0
- package/dist/server/modules/sessions/session-live-runtime-service.js +34 -18
- package/dist/server/modules/sessions/session-live-runtime-service.js.map +1 -1
- package/dist/server/modules/sessions/session-message-attachment-service.d.ts +1 -0
- package/dist/server/modules/sessions/session-message-attachment-service.js +22 -0
- package/dist/server/modules/sessions/session-message-attachment-service.js.map +1 -1
- package/dist/server/modules/sessions/session-permission-request-service.d.ts +1 -0
- package/dist/server/modules/sessions/session-permission-request-service.js +200 -5
- package/dist/server/modules/sessions/session-permission-request-service.js.map +1 -1
- package/dist/server/modules/sessions/session-provider-error-mapper.js +32 -0
- package/dist/server/modules/sessions/session-provider-error-mapper.js.map +1 -1
- package/dist/server/modules/sessions/session-provider-usage-guard-service.d.ts +37 -0
- package/dist/server/modules/sessions/session-provider-usage-guard-service.js +179 -0
- package/dist/server/modules/sessions/session-provider-usage-guard-service.js.map +1 -0
- package/dist/server/modules/sessions/session-provider-usage-limit.d.ts +17 -0
- package/dist/server/modules/sessions/session-provider-usage-limit.js +465 -0
- package/dist/server/modules/sessions/session-provider-usage-limit.js.map +1 -0
- package/dist/server/modules/skills/assistant-runtime-skill-catalog.d.ts +8 -0
- package/dist/server/modules/skills/assistant-runtime-skill-catalog.js +26 -0
- package/dist/server/modules/skills/assistant-runtime-skill-catalog.js.map +1 -0
- package/dist/server/modules/skills/assistant-runtime-skill-cleanup.d.ts +9 -0
- package/dist/server/modules/skills/assistant-runtime-skill-cleanup.js +55 -0
- package/dist/server/modules/skills/assistant-runtime-skill-cleanup.js.map +1 -0
- package/dist/server/modules/skills/builtin-skill-service.js +1 -6
- package/dist/server/modules/skills/builtin-skill-service.js.map +1 -1
- package/dist/server/modules/skills/skill-controller.d.ts +2 -2
- package/dist/server/modules/skills/skill-controller.js +9 -1
- package/dist/server/modules/skills/skill-controller.js.map +1 -1
- package/dist/server/modules/skills/skill-manager-service.d.ts +26 -1
- package/dist/server/modules/skills/skill-manager-service.js +346 -90
- package/dist/server/modules/skills/skill-manager-service.js.map +1 -1
- package/dist/server/modules/skills/skill-name-policy.d.ts +2 -0
- package/dist/server/modules/skills/skill-name-policy.js +10 -0
- package/dist/server/modules/skills/skill-name-policy.js.map +1 -0
- package/dist/server/modules/tailscale/tailscale-service.d.ts +2 -0
- package/dist/server/modules/tailscale/tailscale-service.js +21 -8
- package/dist/server/modules/tailscale/tailscale-service.js.map +1 -1
- package/dist/server/modules/tasks/task-types.d.ts +3 -0
- package/dist/server/modules/tasks/task-types.js +3 -0
- package/dist/server/modules/tasks/task-types.js.map +1 -1
- package/dist/server/modules/terminal/template-reverse-proxy-service.js +71 -3
- package/dist/server/modules/terminal/template-reverse-proxy-service.js.map +1 -1
- package/dist/server/routes/assistant.js +30 -0
- package/dist/server/routes/assistant.js.map +1 -1
- package/dist/server/routes/auth.js +4 -0
- package/dist/server/routes/auth.js.map +1 -1
- package/dist/server/routes/sessions.js +1 -0
- package/dist/server/routes/sessions.js.map +1 -1
- package/dist/server/routes/system.d.ts +2 -1
- package/dist/server/routes/system.js +13 -1
- package/dist/server/routes/system.js.map +1 -1
- package/dist/server/server/create-server.d.ts +10 -0
- package/dist/server/server/create-server.js +82 -12
- package/dist/server/server/create-server.js.map +1 -1
- package/dist/server/shared/utils/tokens.d.ts +3 -1
- package/dist/server/shared/utils/tokens.js +9 -2
- package/dist/server/shared/utils/tokens.js.map +1 -1
- package/dist/server/storage/repositories/assistant-automation-task-repository.d.ts +2 -0
- package/dist/server/storage/repositories/assistant-automation-task-repository.js +8 -2
- package/dist/server/storage/repositories/assistant-automation-task-repository.js.map +1 -1
- package/dist/server/storage/repositories/assistant-sandbox-workspace-repository.d.ts +1 -0
- package/dist/server/storage/repositories/assistant-sandbox-workspace-repository.js +27 -0
- package/dist/server/storage/repositories/assistant-sandbox-workspace-repository.js.map +1 -1
- package/dist/server/storage/repositories/auth-device-repository.d.ts +22 -0
- package/dist/server/storage/repositories/auth-device-repository.js +97 -0
- package/dist/server/storage/repositories/auth-device-repository.js.map +1 -0
- package/dist/server/storage/repositories/auth-device-session-repository.d.ts +17 -0
- package/dist/server/storage/repositories/auth-device-session-repository.js +82 -0
- package/dist/server/storage/repositories/auth-device-session-repository.js.map +1 -0
- package/dist/server/storage/repositories/auth-login-event-repository.d.ts +9 -0
- package/dist/server/storage/repositories/auth-login-event-repository.js +53 -0
- package/dist/server/storage/repositories/auth-login-event-repository.js.map +1 -0
- package/dist/server/storage/repositories/auth-token-repository.d.ts +4 -0
- package/dist/server/storage/repositories/auth-token-repository.js +58 -5
- package/dist/server/storage/repositories/auth-token-repository.js.map +1 -1
- package/dist/server/storage/repositories/butler-follow-up-task-repository.js +21 -3
- package/dist/server/storage/repositories/butler-follow-up-task-repository.js.map +1 -1
- package/dist/server/storage/repositories/instance-relay-tunnel-identity-repository.d.ts +8 -0
- package/dist/server/storage/repositories/instance-relay-tunnel-identity-repository.js +52 -0
- package/dist/server/storage/repositories/instance-relay-tunnel-identity-repository.js.map +1 -0
- package/dist/server/storage/repositories/instance-relay-tunnel-repository.d.ts +10 -0
- package/dist/server/storage/repositories/instance-relay-tunnel-repository.js +153 -0
- package/dist/server/storage/repositories/instance-relay-tunnel-repository.js.map +1 -0
- package/dist/server/storage/repositories/instance-tailscale-repository.js +6 -3
- package/dist/server/storage/repositories/instance-tailscale-repository.js.map +1 -1
- package/dist/server/storage/repositories/managed-skill-repository.d.ts +2 -1
- package/dist/server/storage/repositories/managed-skill-repository.js +14 -4
- package/dist/server/storage/repositories/managed-skill-repository.js.map +1 -1
- package/dist/server/storage/repositories/session-message-attachment-repository.d.ts +2 -0
- package/dist/server/storage/repositories/session-message-attachment-repository.js +24 -0
- package/dist/server/storage/repositories/session-message-attachment-repository.js.map +1 -1
- package/dist/server/storage/sqlite/client.js +297 -2
- package/dist/server/storage/sqlite/client.js.map +1 -1
- package/dist/server/storage/sqlite/schema.sql +122 -4
- package/dist/server/types/domain.d.ts +82 -1
- package/dist/server/ws/workbench-ws-hub.js +99 -75
- package/dist/server/ws/workbench-ws-hub.js.map +1 -1
- package/dist/server/ws/ws-auth-guard.js +1 -4
- package/dist/server/ws/ws-auth-guard.js.map +1 -1
- package/dist/server/ws/ws-server.d.ts +1 -1
- package/dist/server/ws/ws-server.js.map +1 -1
- package/node_modules/@codingns/session-sync-core/dist/codex-resume-history.d.ts +1 -0
- package/node_modules/@codingns/session-sync-core/dist/codex-resume-history.js +80 -0
- package/node_modules/@codingns/session-sync-core/dist/codex-resume-history.js.map +1 -0
- package/node_modules/@codingns/session-sync-core/dist/providers/claude-code.d.ts +1 -0
- package/node_modules/@codingns/session-sync-core/dist/providers/claude-code.js +11 -1
- package/node_modules/@codingns/session-sync-core/dist/providers/claude-code.js.map +1 -1
- package/node_modules/@codingns/session-sync-core/dist/providers/codex.d.ts +11 -0
- package/node_modules/@codingns/session-sync-core/dist/providers/codex.js +132 -21
- package/node_modules/@codingns/session-sync-core/dist/providers/codex.js.map +1 -1
- package/node_modules/@codingns/session-sync-core/dist/providers/gemini.d.ts +2 -0
- package/node_modules/@codingns/session-sync-core/dist/providers/gemini.js +53 -1
- package/node_modules/@codingns/session-sync-core/dist/providers/gemini.js.map +1 -1
- package/node_modules/@codingns/session-sync-core/dist/providers/kimi.d.ts +1 -0
- package/node_modules/@codingns/session-sync-core/dist/providers/kimi.js +10 -1
- package/node_modules/@codingns/session-sync-core/dist/providers/kimi.js.map +1 -1
- package/node_modules/@codingns/session-sync-core/dist/providers/opencode.d.ts +1 -0
- package/node_modules/@codingns/session-sync-core/dist/providers/opencode.js +30 -0
- package/node_modules/@codingns/session-sync-core/dist/providers/opencode.js.map +1 -1
- package/node_modules/@codingns/session-sync-core/dist/runtime/codex-runtime.d.ts +5 -1
- package/node_modules/@codingns/session-sync-core/dist/runtime/codex-runtime.js +145 -58
- package/node_modules/@codingns/session-sync-core/dist/runtime/codex-runtime.js.map +1 -1
- package/node_modules/@codingns/session-sync-core/dist/services.d.ts +1 -0
- package/node_modules/@codingns/session-sync-core/dist/services.js +7 -0
- package/node_modules/@codingns/session-sync-core/dist/services.js.map +1 -1
- package/node_modules/@codingns/session-sync-core/dist/types.d.ts +2 -0
- package/package.json +1 -1
- package/scripts/postinstall.mjs +0 -33
- package/dist/public/assets/index-CSVhg7I8.js +0 -123
- package/dist/public/assets/index-Ce1VX19m.css +0 -1
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHash, createHmac, createPrivateKey, createPublicKey, diffieHellman, generateKeyPairSync, hkdfSync, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { buildRelayTunnelPublicKeyFingerprint } from "./relay-tunnel-identity-service.js";
|
|
3
|
+
export const RELAY_TUNNEL_PROTOCOL_VERSION = 1;
|
|
4
|
+
export const RELAY_TUNNEL_CIPHER_SUITE = "x25519-hkdf-sha256-aes-256-gcm";
|
|
5
|
+
const RELAY_TUNNEL_KEY_ALGORITHM = "x25519";
|
|
6
|
+
const RELAY_TUNNEL_FRAME_ALGORITHM = "aes-256-gcm";
|
|
7
|
+
const RELAY_TUNNEL_FRAME_IV_LENGTH = 12;
|
|
8
|
+
const RELAY_TUNNEL_FRAME_KEY_LENGTH = 32;
|
|
9
|
+
export class RelayTunnelProtocolError extends Error {
|
|
10
|
+
code;
|
|
11
|
+
constructor(code, message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.name = "RelayTunnelProtocolError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function createRelayTunnelClientHandshake(input) {
|
|
18
|
+
const expectedHostFingerprint = normalizeRequiredText(input.expectedHostFingerprint, "expectedHostFingerprint");
|
|
19
|
+
const expectedHostPublicKey = normalizeRequiredText(input.expectedHostPublicKey, "expectedHostPublicKey");
|
|
20
|
+
const actualFingerprint = buildRelayTunnelPublicKeyFingerprint(expectedHostPublicKey);
|
|
21
|
+
if (actualFingerprint !== expectedHostFingerprint) {
|
|
22
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_HOST_FINGERPRINT_MISMATCH", "客户端持有的 Host 公钥和指纹不一致");
|
|
23
|
+
}
|
|
24
|
+
const { privateKey, publicKey } = generateKeyPairSync(RELAY_TUNNEL_KEY_ALGORITHM);
|
|
25
|
+
const clientHello = {
|
|
26
|
+
version: RELAY_TUNNEL_PROTOCOL_VERSION,
|
|
27
|
+
cipherSuite: RELAY_TUNNEL_CIPHER_SUITE,
|
|
28
|
+
clientEphemeralPublicKey: exportPublicKeyAsSpkiBase64Url(publicKey),
|
|
29
|
+
clientNonce: randomBytes(16).toString("base64url"),
|
|
30
|
+
expectedHostFingerprint
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
pendingHandshake: {
|
|
34
|
+
expectedHostPublicKey,
|
|
35
|
+
expectedHostFingerprint,
|
|
36
|
+
clientEphemeralPrivateKey: privateKey,
|
|
37
|
+
clientHello
|
|
38
|
+
},
|
|
39
|
+
clientHello
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function acceptRelayTunnelClientHandshake(input) {
|
|
43
|
+
validateHandshakeEnvelope(input.clientHello);
|
|
44
|
+
if (input.clientHello.expectedHostFingerprint !== input.hostIdentity.keyFingerprint) {
|
|
45
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_HOST_FINGERPRINT_MISMATCH", "客户端请求的 Host 指纹和当前 Host 身份不匹配");
|
|
46
|
+
}
|
|
47
|
+
const clientEphemeralPublicKey = importPublicKeyFromSpkiBase64Url(input.clientHello.clientEphemeralPublicKey);
|
|
48
|
+
const hostStaticPrivateKey = createPrivateKey(input.hostIdentity.privateKeyPem);
|
|
49
|
+
const { privateKey: serverEphemeralPrivateKey, publicKey: serverEphemeralPublicKey } = generateKeyPairSync(RELAY_TUNNEL_KEY_ALGORITHM);
|
|
50
|
+
const serverHello = {
|
|
51
|
+
version: RELAY_TUNNEL_PROTOCOL_VERSION,
|
|
52
|
+
cipherSuite: RELAY_TUNNEL_CIPHER_SUITE,
|
|
53
|
+
sessionId: randomUUID(),
|
|
54
|
+
hostPublicKey: input.hostIdentity.publicKeyPem,
|
|
55
|
+
hostKeyFingerprint: input.hostIdentity.keyFingerprint,
|
|
56
|
+
serverEphemeralPublicKey: exportPublicKeyAsSpkiBase64Url(serverEphemeralPublicKey),
|
|
57
|
+
serverNonce: randomBytes(16).toString("base64url"),
|
|
58
|
+
proof: ""
|
|
59
|
+
};
|
|
60
|
+
const transcriptHash = buildHandshakeTranscriptHash(input.clientHello, serverHello);
|
|
61
|
+
const ikm = deriveHandshakeInputKeyMaterial({
|
|
62
|
+
clientEphemeralPublicKey,
|
|
63
|
+
clientEphemeralPrivateKey: null,
|
|
64
|
+
hostStaticPrivateKey,
|
|
65
|
+
hostStaticPublicKey: null,
|
|
66
|
+
serverEphemeralPrivateKey,
|
|
67
|
+
serverEphemeralPublicKey: null
|
|
68
|
+
});
|
|
69
|
+
serverHello.proof = createHandshakeProof(ikm, transcriptHash);
|
|
70
|
+
return {
|
|
71
|
+
serverHello,
|
|
72
|
+
session: createRelayTunnelSession({
|
|
73
|
+
sessionId: serverHello.sessionId,
|
|
74
|
+
role: "host",
|
|
75
|
+
peerHostFingerprint: input.hostIdentity.keyFingerprint,
|
|
76
|
+
ikm,
|
|
77
|
+
transcriptHash
|
|
78
|
+
})
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function finalizeRelayTunnelClientHandshake(input) {
|
|
82
|
+
validateHandshakeEnvelope(input.pendingHandshake.clientHello);
|
|
83
|
+
validateServerHelloEnvelope(input.serverHello);
|
|
84
|
+
if (input.serverHello.hostKeyFingerprint !== input.pendingHandshake.expectedHostFingerprint) {
|
|
85
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_HOST_FINGERPRINT_MISMATCH", "服务端返回的 Host 指纹和客户端预期不一致");
|
|
86
|
+
}
|
|
87
|
+
const actualFingerprint = buildRelayTunnelPublicKeyFingerprint(input.serverHello.hostPublicKey);
|
|
88
|
+
if (actualFingerprint !== input.pendingHandshake.expectedHostFingerprint) {
|
|
89
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_HOST_FINGERPRINT_MISMATCH", "服务端返回的 Host 公钥与指纹不一致");
|
|
90
|
+
}
|
|
91
|
+
if (normalizePem(input.serverHello.hostPublicKey) !== normalizePem(input.pendingHandshake.expectedHostPublicKey)) {
|
|
92
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_HOST_PUBLIC_KEY_MISMATCH", "服务端返回的 Host 公钥和客户端持有的公钥不一致");
|
|
93
|
+
}
|
|
94
|
+
const transcriptHash = buildHandshakeTranscriptHash(input.pendingHandshake.clientHello, input.serverHello);
|
|
95
|
+
const ikm = deriveHandshakeInputKeyMaterial({
|
|
96
|
+
clientEphemeralPublicKey: null,
|
|
97
|
+
clientEphemeralPrivateKey: input.pendingHandshake.clientEphemeralPrivateKey,
|
|
98
|
+
hostStaticPrivateKey: null,
|
|
99
|
+
hostStaticPublicKey: createPublicKey(input.pendingHandshake.expectedHostPublicKey),
|
|
100
|
+
serverEphemeralPrivateKey: null,
|
|
101
|
+
serverEphemeralPublicKey: importPublicKeyFromSpkiBase64Url(input.serverHello.serverEphemeralPublicKey)
|
|
102
|
+
});
|
|
103
|
+
const expectedProof = createHandshakeProof(ikm, transcriptHash);
|
|
104
|
+
const expectedProofBuffer = Buffer.from(expectedProof, "utf8");
|
|
105
|
+
const actualProofBuffer = Buffer.from(input.serverHello.proof, "utf8");
|
|
106
|
+
if (expectedProofBuffer.length !== actualProofBuffer.length
|
|
107
|
+
|| !timingSafeEqual(expectedProofBuffer, actualProofBuffer)) {
|
|
108
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_HANDSHAKE_PROOF_INVALID", "服务端握手证明无效");
|
|
109
|
+
}
|
|
110
|
+
return createRelayTunnelSession({
|
|
111
|
+
sessionId: input.serverHello.sessionId,
|
|
112
|
+
role: "client",
|
|
113
|
+
peerHostFingerprint: input.serverHello.hostKeyFingerprint,
|
|
114
|
+
ikm,
|
|
115
|
+
transcriptHash
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
export function encryptRelayTunnelFrame(session, payload) {
|
|
119
|
+
const nextSequence = session.sendSequence + 1;
|
|
120
|
+
const direction = resolveSendDirection(session.role);
|
|
121
|
+
const iv = randomBytes(RELAY_TUNNEL_FRAME_IV_LENGTH);
|
|
122
|
+
const cipher = createCipheriv(RELAY_TUNNEL_FRAME_ALGORITHM, session.sendKey, iv);
|
|
123
|
+
const plaintext = normalizePayload(payload);
|
|
124
|
+
const aad = buildFrameAad({
|
|
125
|
+
sessionId: session.sessionId,
|
|
126
|
+
direction,
|
|
127
|
+
sequence: nextSequence
|
|
128
|
+
});
|
|
129
|
+
cipher.setAAD(aad);
|
|
130
|
+
const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
131
|
+
const authTag = cipher.getAuthTag();
|
|
132
|
+
session.sendSequence = nextSequence;
|
|
133
|
+
return {
|
|
134
|
+
version: RELAY_TUNNEL_PROTOCOL_VERSION,
|
|
135
|
+
cipherSuite: RELAY_TUNNEL_CIPHER_SUITE,
|
|
136
|
+
sessionId: session.sessionId,
|
|
137
|
+
direction,
|
|
138
|
+
sequence: nextSequence,
|
|
139
|
+
iv: iv.toString("base64url"),
|
|
140
|
+
authTag: authTag.toString("base64url"),
|
|
141
|
+
ciphertext: ciphertext.toString("base64url")
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export function decryptRelayTunnelFrame(session, frame) {
|
|
145
|
+
validateFrameEnvelope(frame);
|
|
146
|
+
if (frame.sessionId !== session.sessionId) {
|
|
147
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_FRAME_SESSION_MISMATCH", "加密帧的会话标识和当前会话不匹配");
|
|
148
|
+
}
|
|
149
|
+
const expectedDirection = resolveReceiveDirection(session.role);
|
|
150
|
+
if (frame.direction !== expectedDirection) {
|
|
151
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_FRAME_DIRECTION_MISMATCH", "加密帧方向和当前接收方向不匹配");
|
|
152
|
+
}
|
|
153
|
+
const expectedSequence = session.receiveSequence + 1;
|
|
154
|
+
if (frame.sequence !== expectedSequence) {
|
|
155
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_FRAME_SEQUENCE_MISMATCH", `加密帧序号错误,期望 ${expectedSequence},实际 ${frame.sequence}`);
|
|
156
|
+
}
|
|
157
|
+
const decipher = createDecipheriv(RELAY_TUNNEL_FRAME_ALGORITHM, session.receiveKey, Buffer.from(frame.iv, "base64url"));
|
|
158
|
+
const aad = buildFrameAad({
|
|
159
|
+
sessionId: frame.sessionId,
|
|
160
|
+
direction: frame.direction,
|
|
161
|
+
sequence: frame.sequence
|
|
162
|
+
});
|
|
163
|
+
decipher.setAAD(aad);
|
|
164
|
+
decipher.setAuthTag(Buffer.from(frame.authTag, "base64url"));
|
|
165
|
+
try {
|
|
166
|
+
const plaintext = Buffer.concat([
|
|
167
|
+
decipher.update(Buffer.from(frame.ciphertext, "base64url")),
|
|
168
|
+
decipher.final()
|
|
169
|
+
]);
|
|
170
|
+
session.receiveSequence = frame.sequence;
|
|
171
|
+
return plaintext;
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_FRAME_AUTH_INVALID", "加密帧完整性校验失败");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function createRelayTunnelSession(input) {
|
|
178
|
+
const clientToHostKey = deriveSessionKey(input.ikm, input.transcriptHash, "codingns-relay-client-to-host");
|
|
179
|
+
const hostToClientKey = deriveSessionKey(input.ikm, input.transcriptHash, "codingns-relay-host-to-client");
|
|
180
|
+
return {
|
|
181
|
+
sessionId: input.sessionId,
|
|
182
|
+
role: input.role,
|
|
183
|
+
cipherSuite: RELAY_TUNNEL_CIPHER_SUITE,
|
|
184
|
+
peerHostFingerprint: input.peerHostFingerprint,
|
|
185
|
+
sendSequence: 0,
|
|
186
|
+
receiveSequence: 0,
|
|
187
|
+
sendKey: input.role === "client" ? clientToHostKey : hostToClientKey,
|
|
188
|
+
receiveKey: input.role === "client" ? hostToClientKey : clientToHostKey
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function validateHandshakeEnvelope(hello) {
|
|
192
|
+
if (hello.version !== RELAY_TUNNEL_PROTOCOL_VERSION
|
|
193
|
+
|| hello.cipherSuite !== RELAY_TUNNEL_CIPHER_SUITE) {
|
|
194
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_PROTOCOL_UNSUPPORTED", "客户端握手协议版本或套件不受支持");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function validateServerHelloEnvelope(hello) {
|
|
198
|
+
if (hello.version !== RELAY_TUNNEL_PROTOCOL_VERSION
|
|
199
|
+
|| hello.cipherSuite !== RELAY_TUNNEL_CIPHER_SUITE) {
|
|
200
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_PROTOCOL_UNSUPPORTED", "服务端握手协议版本或套件不受支持");
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function validateFrameEnvelope(frame) {
|
|
204
|
+
if (frame.version !== RELAY_TUNNEL_PROTOCOL_VERSION
|
|
205
|
+
|| frame.cipherSuite !== RELAY_TUNNEL_CIPHER_SUITE) {
|
|
206
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_PROTOCOL_UNSUPPORTED", "加密帧协议版本或套件不受支持");
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function deriveHandshakeInputKeyMaterial(input) {
|
|
210
|
+
const staticShared = input.hostStaticPrivateKey
|
|
211
|
+
? diffieHellman({
|
|
212
|
+
privateKey: input.hostStaticPrivateKey,
|
|
213
|
+
publicKey: input.clientEphemeralPublicKey
|
|
214
|
+
})
|
|
215
|
+
: diffieHellman({
|
|
216
|
+
privateKey: input.clientEphemeralPrivateKey,
|
|
217
|
+
publicKey: input.hostStaticPublicKey
|
|
218
|
+
});
|
|
219
|
+
const ephemeralShared = input.serverEphemeralPrivateKey
|
|
220
|
+
? diffieHellman({
|
|
221
|
+
privateKey: input.serverEphemeralPrivateKey,
|
|
222
|
+
publicKey: input.clientEphemeralPublicKey
|
|
223
|
+
})
|
|
224
|
+
: diffieHellman({
|
|
225
|
+
privateKey: input.clientEphemeralPrivateKey,
|
|
226
|
+
publicKey: input.serverEphemeralPublicKey
|
|
227
|
+
});
|
|
228
|
+
return Buffer.concat([staticShared, ephemeralShared]);
|
|
229
|
+
}
|
|
230
|
+
function buildHandshakeTranscriptHash(clientHello, serverHello) {
|
|
231
|
+
return createHash("sha256")
|
|
232
|
+
.update(JSON.stringify({
|
|
233
|
+
version: RELAY_TUNNEL_PROTOCOL_VERSION,
|
|
234
|
+
cipherSuite: RELAY_TUNNEL_CIPHER_SUITE,
|
|
235
|
+
clientEphemeralPublicKey: clientHello.clientEphemeralPublicKey,
|
|
236
|
+
clientNonce: clientHello.clientNonce,
|
|
237
|
+
expectedHostFingerprint: clientHello.expectedHostFingerprint,
|
|
238
|
+
hostPublicKey: normalizePem(serverHello.hostPublicKey),
|
|
239
|
+
hostKeyFingerprint: serverHello.hostKeyFingerprint,
|
|
240
|
+
serverEphemeralPublicKey: serverHello.serverEphemeralPublicKey,
|
|
241
|
+
serverNonce: serverHello.serverNonce,
|
|
242
|
+
sessionId: serverHello.sessionId
|
|
243
|
+
}))
|
|
244
|
+
.digest();
|
|
245
|
+
}
|
|
246
|
+
function createHandshakeProof(ikm, transcriptHash) {
|
|
247
|
+
const proofKey = hkdfBuffer(ikm, transcriptHash, "codingns-relay-handshake-proof");
|
|
248
|
+
return createHmac("sha256", proofKey)
|
|
249
|
+
.update(transcriptHash)
|
|
250
|
+
.digest("base64url");
|
|
251
|
+
}
|
|
252
|
+
function deriveSessionKey(ikm, transcriptHash, info) {
|
|
253
|
+
return hkdfBuffer(ikm, transcriptHash, info);
|
|
254
|
+
}
|
|
255
|
+
function hkdfBuffer(ikm, salt, info) {
|
|
256
|
+
return Buffer.from(hkdfSync("sha256", ikm, salt, Buffer.from(info, "utf8"), RELAY_TUNNEL_FRAME_KEY_LENGTH));
|
|
257
|
+
}
|
|
258
|
+
function buildFrameAad(input) {
|
|
259
|
+
return Buffer.from(JSON.stringify({
|
|
260
|
+
version: RELAY_TUNNEL_PROTOCOL_VERSION,
|
|
261
|
+
cipherSuite: RELAY_TUNNEL_CIPHER_SUITE,
|
|
262
|
+
sessionId: input.sessionId,
|
|
263
|
+
direction: input.direction,
|
|
264
|
+
sequence: input.sequence
|
|
265
|
+
}), "utf8");
|
|
266
|
+
}
|
|
267
|
+
function exportPublicKeyAsSpkiBase64Url(key) {
|
|
268
|
+
return key.export({
|
|
269
|
+
type: "spki",
|
|
270
|
+
format: "der"
|
|
271
|
+
}).toString("base64url");
|
|
272
|
+
}
|
|
273
|
+
function importPublicKeyFromSpkiBase64Url(value) {
|
|
274
|
+
return createPublicKey({
|
|
275
|
+
key: Buffer.from(value, "base64url"),
|
|
276
|
+
type: "spki",
|
|
277
|
+
format: "der"
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
function normalizePayload(payload) {
|
|
281
|
+
if (typeof payload === "string") {
|
|
282
|
+
return Buffer.from(payload, "utf8");
|
|
283
|
+
}
|
|
284
|
+
return Buffer.from(payload);
|
|
285
|
+
}
|
|
286
|
+
function resolveSendDirection(role) {
|
|
287
|
+
return role === "client" ? "client_to_host" : "host_to_client";
|
|
288
|
+
}
|
|
289
|
+
function resolveReceiveDirection(role) {
|
|
290
|
+
return role === "client" ? "host_to_client" : "client_to_host";
|
|
291
|
+
}
|
|
292
|
+
function normalizeRequiredText(value, field) {
|
|
293
|
+
const normalized = value.trim();
|
|
294
|
+
if (!normalized) {
|
|
295
|
+
throw new RelayTunnelProtocolError("RELAY_TUNNEL_PROTOCOL_UNSUPPORTED", `${field} 不能为空`);
|
|
296
|
+
}
|
|
297
|
+
return normalized;
|
|
298
|
+
}
|
|
299
|
+
function normalizePem(value) {
|
|
300
|
+
return value.trim().replace(/\r\n/g, "\n");
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=relay-tunnel-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-tunnel-protocol.js","sourceRoot":"","sources":["../../../../../src/modules/relay-tunnel/crypto/relay-tunnel-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAC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;AAC7C,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import type { RelayTunnelControlLoginInput, RelayTunnelBindInput, RelayTunnelConfigUpdateInput } from "./relay-tunnel-service.js";
|
|
3
|
+
import { RelayTunnelService } from "./relay-tunnel-service.js";
|
|
4
|
+
export declare class RelayTunnelController {
|
|
5
|
+
private readonly relayTunnelService;
|
|
6
|
+
constructor(relayTunnelService: RelayTunnelService);
|
|
7
|
+
readonly getStatus: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
8
|
+
readonly ensureIdentity: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
9
|
+
readonly updateConfig: (request: FastifyRequest<{
|
|
10
|
+
Body: RelayTunnelConfigUpdateInput;
|
|
11
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
12
|
+
readonly loginControl: (request: FastifyRequest<{
|
|
13
|
+
Body: RelayTunnelControlLoginInput;
|
|
14
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
15
|
+
readonly logoutControl: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
16
|
+
readonly checkHostLabelAvailability: (request: FastifyRequest<{
|
|
17
|
+
Querystring: {
|
|
18
|
+
hostLabel?: string;
|
|
19
|
+
};
|
|
20
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
21
|
+
readonly bindControlHost: (request: FastifyRequest<{
|
|
22
|
+
Body: {
|
|
23
|
+
hostLabel?: string;
|
|
24
|
+
};
|
|
25
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
26
|
+
readonly getTrafficWallet: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
27
|
+
readonly bind: (request: FastifyRequest<{
|
|
28
|
+
Body: RelayTunnelBindInput;
|
|
29
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
30
|
+
readonly unbind: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
31
|
+
readonly enable: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
32
|
+
readonly disable: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { requireUserId } from "../preferences/common.js";
|
|
2
|
+
export class RelayTunnelController {
|
|
3
|
+
relayTunnelService;
|
|
4
|
+
constructor(relayTunnelService) {
|
|
5
|
+
this.relayTunnelService = relayTunnelService;
|
|
6
|
+
}
|
|
7
|
+
getStatus = async (request, reply) => {
|
|
8
|
+
requireUserId(request);
|
|
9
|
+
reply.send(await this.relayTunnelService.getStatus());
|
|
10
|
+
};
|
|
11
|
+
ensureIdentity = async (request, reply) => {
|
|
12
|
+
requireUserId(request);
|
|
13
|
+
reply.send(await this.relayTunnelService.ensureIdentity());
|
|
14
|
+
};
|
|
15
|
+
updateConfig = async (request, reply) => {
|
|
16
|
+
requireUserId(request);
|
|
17
|
+
reply.send(await this.relayTunnelService.updateConfig(request.body ?? {}));
|
|
18
|
+
};
|
|
19
|
+
loginControl = async (request, reply) => {
|
|
20
|
+
requireUserId(request);
|
|
21
|
+
reply.send(await this.relayTunnelService.loginControl(request.body ?? {}));
|
|
22
|
+
};
|
|
23
|
+
logoutControl = async (request, reply) => {
|
|
24
|
+
requireUserId(request);
|
|
25
|
+
reply.send(await this.relayTunnelService.logoutControl());
|
|
26
|
+
};
|
|
27
|
+
checkHostLabelAvailability = async (request, reply) => {
|
|
28
|
+
requireUserId(request);
|
|
29
|
+
reply.send(await this.relayTunnelService.checkHostLabelAvailability(request.query.hostLabel ?? ""));
|
|
30
|
+
};
|
|
31
|
+
bindControlHost = async (request, reply) => {
|
|
32
|
+
requireUserId(request);
|
|
33
|
+
reply.send(await this.relayTunnelService.bindControlHost(request.body?.hostLabel ?? ""));
|
|
34
|
+
};
|
|
35
|
+
getTrafficWallet = async (request, reply) => {
|
|
36
|
+
requireUserId(request);
|
|
37
|
+
const wallet = await this.relayTunnelService.getTrafficWallet();
|
|
38
|
+
reply.send({ wallet });
|
|
39
|
+
};
|
|
40
|
+
bind = async (request, reply) => {
|
|
41
|
+
requireUserId(request);
|
|
42
|
+
reply.send(await this.relayTunnelService.bind(request.body ?? {}));
|
|
43
|
+
};
|
|
44
|
+
unbind = async (request, reply) => {
|
|
45
|
+
requireUserId(request);
|
|
46
|
+
reply.send(await this.relayTunnelService.unbind());
|
|
47
|
+
};
|
|
48
|
+
enable = async (request, reply) => {
|
|
49
|
+
requireUserId(request);
|
|
50
|
+
reply.send(await this.relayTunnelService.enable());
|
|
51
|
+
};
|
|
52
|
+
disable = async (request, reply) => {
|
|
53
|
+
requireUserId(request);
|
|
54
|
+
reply.send(await this.relayTunnelService.disable());
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=relay-tunnel-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-tunnel-controller.js","sourceRoot":"","sources":["../../../../src/modules/relay-tunnel/relay-tunnel-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAQzD,MAAM,OAAO,qBAAqB;IACH;IAA7B,YAA6B,kBAAsC;QAAtC,uBAAkB,GAAlB,kBAAkB,CAAoB;IAAG,CAAC;IAE9D,SAAS,GAAG,KAAK,EAAE,OAAuB,EAAE,KAAmB,EAAiB,EAAE;QACzF,aAAa,CAAC,OAAO,CAAC,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,CAAC,CAAC;IACxD,CAAC,CAAC;IAEO,cAAc,GAAG,KAAK,EAC7B,OAAuB,EACvB,KAAmB,EACJ,EAAE;QACjB,aAAa,CAAC,OAAO,CAAC,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,kBAAkB,CAAC,cAAc,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAC;IAEO,YAAY,GA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,KAAmB,EAAiB,EAAE;QAChG,aAAa,CAAC,OAAO,CAAC,CAAC;QACvB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,EAAE,CAAC;QAChE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACzB,CAAC,CAAC;IAEO,IAAI,GAAG,KAAK,EACnB,OAAuD,EACvD,KAAmB,EACJ,EAAE;QACjB,aAAa,CAAC,OAAO,CAAC,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;IACrE,CAAC,CAAC;IAEO,MAAM,GAAG,KAAK,EAAE,OAAuB,EAAE,KAAmB,EAAiB,EAAE;QACtF,aAAa,CAAC,OAAO,CAAC,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC;IACrD,CAAC,CAAC;IAEO,MAAM,GAAG,KAAK,EAAE,OAAuB,EAAE,KAAmB,EAAiB,EAAE;QACtF,aAAa,CAAC,OAAO,CAAC,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC;IACrD,CAAC,CAAC;IAEO,OAAO,GAAG,KAAK,EAAE,OAAuB,EAAE,KAAmB,EAAiB,EAAE;QACvF,aAAa,CAAC,OAAO,CAAC,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC;CACH"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createHash, createHmac, createPrivateKey, createPublicKey, diffieHellman, hkdfSync } from "node:crypto";
|
|
2
|
+
export function createRelayTunnelHostClaimProof(input) {
|
|
3
|
+
const transcript = Buffer.from(JSON.stringify({
|
|
4
|
+
challengeId: input.challengeId.trim(),
|
|
5
|
+
bindingId: input.bindingId.trim(),
|
|
6
|
+
tunnelDomain: input.tunnelDomain.trim().toLowerCase(),
|
|
7
|
+
hostFingerprint: input.hostFingerprint.trim(),
|
|
8
|
+
relayPublicKey: input.relayPublicKey.trim(),
|
|
9
|
+
relayNonce: input.relayNonce.trim()
|
|
10
|
+
}), "utf8");
|
|
11
|
+
const transcriptHash = createHash("sha256").update(transcript).digest();
|
|
12
|
+
const sharedSecret = diffieHellman({
|
|
13
|
+
privateKey: createPrivateKey(input.hostPrivateKeyPem),
|
|
14
|
+
publicKey: createPublicKey({
|
|
15
|
+
key: Buffer.from(input.relayPublicKey, "base64url"),
|
|
16
|
+
type: "spki",
|
|
17
|
+
format: "der"
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
const proofKey = Buffer.from(hkdfSync("sha256", sharedSecret, transcriptHash, Buffer.from("codingns-relay-host-claim-proof", "utf8"), 32));
|
|
21
|
+
return createHmac("sha256", proofKey)
|
|
22
|
+
.update(transcriptHash)
|
|
23
|
+
.digest("base64url");
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=relay-tunnel-edge-proof.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-tunnel-edge-proof.js","sourceRoot":"","sources":["../../../../src/modules/relay-tunnel/relay-tunnel-edge-proof.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,QAAQ,EACT,MAAM,aAAa,CAAC;AAErB,MAAM,UAAU,+BAA+B,CAAC,KAQ/C;IACC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAC5B,IAAI,CAAC,SAAS,CAAC;QACb,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE;QACrC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE;QACjC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE;QACrD,eAAe,EAAE,KAAK,CAAC,eAAe,CAAC,IAAI,EAAE;QAC7C,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE;QAC3C,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE;KACpC,CAAC,EACF,MAAM,CACP,CAAC;IACF,MAAM,cAAc,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,CAAC;IACxE,MAAM,YAAY,GAAG,aAAa,CAAC;QACjC,UAAU,EAAE,gBAAgB,CAAC,KAAK,CAAC,iBAAiB,CAAC;QACrD,SAAS,EAAE,eAAe,CAAC;YACzB,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,WAAW,CAAC;YACnD,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,KAAK;SACd,CAAC;KACH,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAC1B,QAAQ,CACN,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,MAAM,CAAC,IAAI,CAAC,iCAAiC,EAAE,MAAM,CAAC,EACtD,EAAE,CACH,CACF,CAAC;IAEF,OAAO,UAAU,CAAC,QAAQ,EAAE,QAAQ,CAAC;SAClC,MAAM,CAAC,cAAc,CAAC;SACtB,MAAM,CAAC,WAAW,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RelayTunnelGatewayPacket } from "./crypto/relay-tunnel-packets.js";
|
|
2
|
+
export declare class RelayTunnelGatewayService {
|
|
3
|
+
private readonly localHttpBaseUrl;
|
|
4
|
+
private readonly localWsBaseUrl;
|
|
5
|
+
private readonly wsSockets;
|
|
6
|
+
constructor(options: {
|
|
7
|
+
localTargetBaseUrl: string;
|
|
8
|
+
onPacket: (packet: RelayTunnelGatewayPacket) => void | Promise<void>;
|
|
9
|
+
});
|
|
10
|
+
private readonly onPacket;
|
|
11
|
+
handlePacket(packet: RelayTunnelGatewayPacket): Promise<void>;
|
|
12
|
+
close(): void;
|
|
13
|
+
private handleHttpRequest;
|
|
14
|
+
private handleWsOpen;
|
|
15
|
+
private handleWsMessage;
|
|
16
|
+
private handleWsClosed;
|
|
17
|
+
private emitError;
|
|
18
|
+
}
|