@tik-choco/mistlib-mcp 0.0.0-stage → 0.1.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/LICENSE +373 -0
- package/README.md +128 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/schema.d.ts +6 -0
- package/dist/mcp/schema.js +29 -0
- package/dist/mcp/server.d.ts +100 -0
- package/dist/mcp/server.js +303 -0
- package/dist/provider/identity.d.ts +4 -0
- package/dist/provider/identity.js +57 -0
- package/dist/provider/index.d.ts +4 -0
- package/dist/provider/index.js +3 -0
- package/dist/provider/mistseed.d.ts +16 -0
- package/dist/provider/mistseed.js +91 -0
- package/dist/provider/protocol.d.ts +49 -0
- package/dist/provider/protocol.js +139 -0
- package/dist/provider/provider.d.ts +3 -0
- package/dist/provider/provider.js +430 -0
- package/dist/provider/shared-node.d.ts +23 -0
- package/dist/provider/shared-node.js +78 -0
- package/dist/provider/types.d.ts +31 -0
- package/dist/provider/types.js +1 -0
- package/dist/wire/credentials.d.ts +47 -0
- package/dist/wire/credentials.js +79 -0
- package/dist/wire/encoding.d.ts +7 -0
- package/dist/wire/encoding.js +23 -0
- package/dist/wire/errors.d.ts +27 -0
- package/dist/wire/errors.js +19 -0
- package/dist/wire/framing.d.ts +40 -0
- package/dist/wire/framing.js +166 -0
- package/dist/wire/index.d.ts +8 -0
- package/dist/wire/index.js +8 -0
- package/dist/wire/json.d.ts +13 -0
- package/dist/wire/json.js +73 -0
- package/dist/wire/messages.d.ts +68 -0
- package/dist/wire/messages.js +89 -0
- package/dist/wire/names.d.ts +4 -0
- package/dist/wire/names.js +14 -0
- package/dist/wire/noise-session.d.ts +135 -0
- package/dist/wire/noise-session.js +432 -0
- package/noise-wasm/README.md +59 -0
- package/noise-wasm/pkg/noise_wasm.d.ts +101 -0
- package/noise-wasm/pkg/noise_wasm.js +699 -0
- package/noise-wasm/pkg/noise_wasm_bg.wasm +0 -0
- package/noise-wasm/pkg/noise_wasm_bg.wasm.d.ts +30 -0
- package/package.json +70 -4
- package/spec/provider-runtime-v1.md +100 -0
- package/spec/secure-channel-v1.md +213 -0
- package/spec/wire-v1.md +355 -0
- package/vectors/wire-v1.json +117 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_handshake_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_transport_free: (a: number, b: number) => void;
|
|
6
|
+
export const generate_keypair: (a: number) => void;
|
|
7
|
+
export const handshake_close: (a: number) => void;
|
|
8
|
+
export const handshake_handshake_hash: (a: number, b: number) => void;
|
|
9
|
+
export const handshake_initiator: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
|
|
10
|
+
export const handshake_into_transport: (a: number, b: number) => void;
|
|
11
|
+
export const handshake_is_closed: (a: number) => number;
|
|
12
|
+
export const handshake_is_finished: (a: number) => number;
|
|
13
|
+
export const handshake_is_my_turn: (a: number) => number;
|
|
14
|
+
export const handshake_read_message: (a: number, b: number, c: number, d: number) => void;
|
|
15
|
+
export const handshake_remote_static: (a: number, b: number) => void;
|
|
16
|
+
export const handshake_responder: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
|
|
17
|
+
export const handshake_write_message: (a: number, b: number, c: number, d: number) => void;
|
|
18
|
+
export const transport_close: (a: number) => void;
|
|
19
|
+
export const transport_decrypt: (a: number, b: number, c: number, d: number) => void;
|
|
20
|
+
export const transport_encrypt: (a: number, b: number, c: number, d: number) => void;
|
|
21
|
+
export const transport_is_closed: (a: number) => number;
|
|
22
|
+
export const __wbindgen_export: (a: number) => void;
|
|
23
|
+
export const __wbindgen_export2: () => number;
|
|
24
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
25
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
26
|
+
export const __wbindgen_export3: (a: number) => void;
|
|
27
|
+
export const __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
28
|
+
export const __wbindgen_export5: (a: number, b: number) => number;
|
|
29
|
+
export const __wbindgen_export6: (a: number, b: number, c: number, d: number) => number;
|
|
30
|
+
export const __wbindgen_start: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tik-choco/mistlib-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Transport-independent browser MCP provider SDK for mistl.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MPL-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/tik-choco-lab/mistlib-mcp.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/tik-choco-lab/mistlib-mcp#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/tik-choco-lab/mistlib-mcp/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"mcp",
|
|
17
|
+
"model-context-protocol",
|
|
18
|
+
"mistl",
|
|
19
|
+
"browser",
|
|
20
|
+
"typescript",
|
|
21
|
+
"noise-protocol",
|
|
22
|
+
"wasm"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20"
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./wire": {
|
|
35
|
+
"types": "./dist/wire/index.d.ts",
|
|
36
|
+
"default": "./dist/wire/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./mcp": {
|
|
39
|
+
"types": "./dist/mcp/index.d.ts",
|
|
40
|
+
"default": "./dist/mcp/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./mistseed": {
|
|
43
|
+
"types": "./dist/provider/mistseed.d.ts",
|
|
44
|
+
"default": "./dist/provider/mistseed.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist",
|
|
49
|
+
"noise-wasm/pkg",
|
|
50
|
+
"spec",
|
|
51
|
+
"vectors",
|
|
52
|
+
"README.md",
|
|
53
|
+
"LICENSE"
|
|
54
|
+
],
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsc -p tsconfig.build.json",
|
|
57
|
+
"prepare": "npm run build",
|
|
58
|
+
"test": "vitest run --pool=threads --maxWorkers=1",
|
|
59
|
+
"build:wasm": "node scripts/build-wasm.mjs",
|
|
60
|
+
"test:interop": "npm run build && cargo build --release --manifest-path noise-wasm/interop/Cargo.toml && node noise-wasm/interop/run.mjs"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"ajv": "^8.17.1"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"typescript": "~6.0.2",
|
|
67
|
+
"vitest": "^4.0.0"
|
|
68
|
+
},
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"access": "public"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Provider runtime v1 control payloads
|
|
2
|
+
|
|
3
|
+
This specifies the provider runtime's concrete carriage of the handshakes
|
|
4
|
+
in [wire v1](wire-v1.md) and [secure channel v1](secure-channel-v1.md).
|
|
5
|
+
It does not change either Noise pattern or DID binding signature format.
|
|
6
|
+
|
|
7
|
+
## Discovery and pairing
|
|
8
|
+
|
|
9
|
+
The gateway joins `mcp-pair-v1-` plus the first 32 lowercase hex
|
|
10
|
+
characters of SHA-256(UTF-8(`mist-mcp/v1/pair-room|` + normalized code)).
|
|
11
|
+
The code is single-use; the gateway enforces consumption and rate limits.
|
|
12
|
+
Send a public `mcp.hello` on peer join and periodically, both in the
|
|
13
|
+
pairing room and the gateway's permanent `mcp-v1-<32 lowercase hex>` room.
|
|
14
|
+
The provider treats hello only as an unauthenticated discovery hint.
|
|
15
|
+
|
|
16
|
+
P = provider (Noise initiator), G = gateway (Noise responder). The
|
|
17
|
+
provider generates the 128-bit `sid`; each following row uses the same
|
|
18
|
+
room, directed peer IDs and sid. Noise handshake messages have empty
|
|
19
|
+
payloads. The two binding records are exactly the first Noise transport
|
|
20
|
+
messages returned by `bindSession`, not wrapped in another encryption.
|
|
21
|
+
|
|
22
|
+
| Direction | Outer type | Decoded `data` bytes |
|
|
23
|
+
| --- | --- | --- |
|
|
24
|
+
| G → P | `mcp.hello` | Public hello (no data field) |
|
|
25
|
+
| P → G | `mcp.pair.challenge` | XXpsk3 message 1 |
|
|
26
|
+
| G → P | `mcp.pair.proof` | XXpsk3 message 2 |
|
|
27
|
+
| P → G | `mcp.pair.proof` | XXpsk3 message 3 |
|
|
28
|
+
| P → G | `mcp.pair.proof` | Sealed initiator DID binding |
|
|
29
|
+
| G → P | `mcp.pair.proof` | Sealed responder DID binding |
|
|
30
|
+
| P → G | `mcp.pair.grant` | Protected body `{"origin":"https://example.org"}` |
|
|
31
|
+
| G → P | `mcp.pair.grant` | Protected body `{"room":"mcp-v1-…","ticket":{…}}` |
|
|
32
|
+
|
|
33
|
+
The gateway verifies the initiator binding before issuing a ticket and
|
|
34
|
+
obtains the owner's approval for the claimed origin and leaf. The provider
|
|
35
|
+
verifies the responder binding against the hello DID and verifies the
|
|
36
|
+
ticket's Ed25519 signature, origin, audience, issuer, instance and
|
|
37
|
+
validity before saving the pairing. Entering the one-time code is the
|
|
38
|
+
provider-side opt-in; the status fingerprint is exposed as soon as the
|
|
39
|
+
responder binding is verified. The provider leaves the pairing room and
|
|
40
|
+
establishes a fresh KK session in the stored permanent room. No RPC is
|
|
41
|
+
sent on the pairing session.
|
|
42
|
+
|
|
43
|
+
## Reconnect and authentication
|
|
44
|
+
|
|
45
|
+
The provider accepts only hello hints whose DID and instance equal the
|
|
46
|
+
saved pairing; the subsequent KK handshake and bindings must match
|
|
47
|
+
both pinned static keys and both DIDs. No credentials are sent before
|
|
48
|
+
binding verification. The gateway may have a different transport node
|
|
49
|
+
ID after a restart, and the prologue uses the current IDs.
|
|
50
|
+
|
|
51
|
+
| Direction | Outer type | Decoded `data` bytes |
|
|
52
|
+
| --- | --- | --- |
|
|
53
|
+
| G → P | `mcp.hello` | Public hello |
|
|
54
|
+
| P → G | `mcp.auth.challenge` | KK message 1 |
|
|
55
|
+
| G → P | `mcp.auth.proof` | KK message 2 |
|
|
56
|
+
| P → G | `mcp.auth.proof` | Sealed initiator DID binding |
|
|
57
|
+
| G → P | `mcp.auth.proof` | Sealed responder DID binding |
|
|
58
|
+
| P → G | `mcp.auth.grant` | Protected body `{ticket,namespace,title,bootNonce,limits}` |
|
|
59
|
+
| G → P | `mcp.auth.accept` | Protected body `{namespace,bootNonce,limits}` |
|
|
60
|
+
| G ↔ P | `mcp.frame` | Wire v1 authenticated frame |
|
|
61
|
+
| G ↔ P | `mcp.close` | Protected body `{}` (best effort) |
|
|
62
|
+
|
|
63
|
+
The gateway checks the ticket against its current epoch and revocation
|
|
64
|
+
policy, verifies the claimed namespace and leaf and checks the current
|
|
65
|
+
boot nonce and supported limits. `limits` has the exact hello limit
|
|
66
|
+
members; `auth.accept` echoes the agreed namespace, boot nonce and limits
|
|
67
|
+
exactly. The provider supports wire v1 default maxima and uses the hello
|
|
68
|
+
limits only after this authenticated agreement. Rejection can close the
|
|
69
|
+
session without a reply. The gateway must reject a second live session
|
|
70
|
+
for the same namespace. After accept it initializes MCP 2025-11-25,
|
|
71
|
+
sends `notifications/initialized`, and requests `tools/list`. The gateway
|
|
72
|
+
must independently enforce catalog/namespace approval before forwarding
|
|
73
|
+
calls, and send MCP `ping` every 10 seconds while idle. The runtime expires
|
|
74
|
+
sessions after 45 seconds without a complete authenticated RPC or when the
|
|
75
|
+
ticket expires. The runtime does not issue namespace grants or implement
|
|
76
|
+
their renewal/revocation protocol; those approvals remain gateway policy.
|
|
77
|
+
|
|
78
|
+
## Protected controls
|
|
79
|
+
|
|
80
|
+
For credential, accept and close records, `data` is the unpadded
|
|
81
|
+
base64url encoding of a single Noise transport ciphertext:
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
seal(canonicalBytes({v:1,type:<outer type>,sid:<outer sid>,body:<object>}))
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The receiver decrypts and checks the exact key set and matches type/sid
|
|
88
|
+
against the outer envelope before using the body. All records obey the
|
|
89
|
+
wire control size limit. Binding records retain their secure-channel v1
|
|
90
|
+
format. A record with a different room, peer or sid is ignored; once an
|
|
91
|
+
ordered Noise cipher is selected, a failed decryption is fatal (including
|
|
92
|
+
an invalid close for that session). The sender never retries ciphertext
|
|
93
|
+
or an RPC with an unknown execution result. A new connection always
|
|
94
|
+
starts a fresh handshake and MCP initialization.
|
|
95
|
+
|
|
96
|
+
The local provider storage key is `mist-mcp:v1:pairing`. The runtime's
|
|
97
|
+
namespace lock includes the serialized origin and namespace; the origin
|
|
98
|
+
pairing lock serializes explicit pairing operations. On platforms without
|
|
99
|
+
Web Locks there is no cross-tab leader guarantee. The gateway remains
|
|
100
|
+
responsible for duplicate-namespace rejection in all environments.
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Secure Channel v1
|
|
2
|
+
|
|
3
|
+
Status: draft. This document specifies the end-to-end authenticated channel between a
|
|
4
|
+
**gateway** (a resident daemon) and a **provider** (a browser application) that exchange MCP
|
|
5
|
+
JSON-RPC over mistlib room messages. mistlib messages may be relayed by intermediate overlay
|
|
6
|
+
peers, so hop-by-hop DTLS is not sufficient; this channel provides confidentiality, integrity,
|
|
7
|
+
replay/reorder protection and mutual authentication end to end.
|
|
8
|
+
|
|
9
|
+
The channel is built exclusively from the [Noise Protocol Framework](https://noiseprotocol.org/noise.html)
|
|
10
|
+
(revision 34). Reference implementations: the `snow` crate natively and the same crate compiled
|
|
11
|
+
to WebAssembly in browsers. Key words MUST, SHOULD, MAY are per RFC 2119.
|
|
12
|
+
|
|
13
|
+
## 1. Overview
|
|
14
|
+
|
|
15
|
+
| Phase | Noise pattern | Authenticates via |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| Pairing (first contact) | `Noise_XXpsk3_25519_ChaChaPoly_SHA256` | one-time pairing code (PSK) |
|
|
18
|
+
| Reconnect | `Noise_KK_25519_ChaChaPoly_SHA256` | static keys pinned during pairing |
|
|
19
|
+
|
|
20
|
+
After either handshake, each side sends a **binding** (section 6) that ties its long-term Ed25519
|
|
21
|
+
DID key to the handshake hash. Application data flows only after both bindings are verified.
|
|
22
|
+
|
|
23
|
+
Each party has:
|
|
24
|
+
|
|
25
|
+
- a Noise static key pair (X25519), generated once and stored privately;
|
|
26
|
+
- an Ed25519 DID key (`did:key`, multicodec `0xed01`, base58btc multibase `z`).
|
|
27
|
+
|
|
28
|
+
Roles: the **initiator** is the party that sends the first handshake message. In v1 the provider
|
|
29
|
+
is the initiator of both patterns and the gateway is the responder. Implementations MUST NOT rely
|
|
30
|
+
on that assignment for security; the prologue binds the actual roles.
|
|
31
|
+
|
|
32
|
+
## 2. Pairing code and PSK
|
|
33
|
+
|
|
34
|
+
The gateway generates a pairing code from at least 128 bits of CSPRNG output, encoded in
|
|
35
|
+
Crockford base32 (alphabet `0123456789ABCDEFGHJKMNPQRSTVWXYZ`). Codes are single-use and short-lived
|
|
36
|
+
(RECOMMENDED: 120 s), and attempts MUST be rate-limited.
|
|
37
|
+
|
|
38
|
+
**Normalisation** (both sides, before use): remove ASCII whitespace and `-`; uppercase;
|
|
39
|
+
map `I`, `L` to `1` and `O` to `0`. The result MUST be 26..64 characters, all in the alphabet;
|
|
40
|
+
otherwise the code is rejected.
|
|
41
|
+
|
|
42
|
+
**PSK**:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
PSK = HKDF-SHA256(
|
|
46
|
+
IKM = ASCII(normalized_code),
|
|
47
|
+
salt = UTF8("mist-mcp/secure-channel/v1/pair-psk-salt"),
|
|
48
|
+
info = UTF8("mist-mcp/secure-channel/v1/pair-psk|Noise_XXpsk3_25519_ChaChaPoly_SHA256"),
|
|
49
|
+
L = 32)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The PSK is used at position 3 (`psk3`). It MUST be erased after the handshake, whether it
|
|
53
|
+
succeeds or not. The pairing code MUST be consumed after one handshake attempt that reaches the
|
|
54
|
+
responder's processing of message 3.
|
|
55
|
+
|
|
56
|
+
## 3. Prologue
|
|
57
|
+
|
|
58
|
+
Both sides MUST compute the identical prologue; a mismatch makes the handshake fail.
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
prologue = UTF8("mist-mcp/secure-channel") || 0x00 || 0x01
|
|
62
|
+
|| lp(room_id) || lp(initiator_node_id) || lp(responder_node_id)
|
|
63
|
+
lp(s) = uint16_be(len(UTF8(s))) || UTF8(s)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- `0x01` is the protocol version.
|
|
67
|
+
- `room_id` is the mistlib room in which the handshake runs.
|
|
68
|
+
- `initiator_node_id` / `responder_node_id` are the transport (overlay) node IDs of the two
|
|
69
|
+
parties, as observed by the receiver in the room callback `from` field and as used by the sender
|
|
70
|
+
as the destination.
|
|
71
|
+
- Each string MUST be non-empty, well-formed Unicode, and at most 512 bytes in UTF-8.
|
|
72
|
+
- On reconnect the prologue uses the current room and current node IDs; it is not stored.
|
|
73
|
+
|
|
74
|
+
## 4. Handshakes
|
|
75
|
+
|
|
76
|
+
### 4.1 Pairing — `Noise_XXpsk3_25519_ChaChaPoly_SHA256`
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
-> e
|
|
80
|
+
<- e, ee, s, es
|
|
81
|
+
-> s, se, psk
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Inputs: prologue, local static key, PSK. On success each side MUST verify its binding (section 6)
|
|
85
|
+
and then store the peer's Noise static public key (`rs`) together with the peer's DID. Neither
|
|
86
|
+
side stores anything before the peer's binding has been verified.
|
|
87
|
+
|
|
88
|
+
Note: the initiator finishes after writing message 3 and cannot detect a wrong PSK until the
|
|
89
|
+
responder's binding fails to decrypt or never arrives. The initiator MUST therefore treat the
|
|
90
|
+
session as unauthenticated until it has verified the responder's binding.
|
|
91
|
+
|
|
92
|
+
### 4.2 Reconnect — `Noise_KK_25519_ChaChaPoly_SHA256`
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
-> s
|
|
96
|
+
<- s
|
|
97
|
+
...
|
|
98
|
+
-> e, es, ss
|
|
99
|
+
<- e, ee, se
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Inputs: prologue, local static key, and the peer static key pinned during pairing. A side that has
|
|
103
|
+
no pinned key for the peer MUST NOT start KK. The binding (section 6) is still REQUIRED, and the
|
|
104
|
+
DID it carries MUST equal the DID stored at pairing.
|
|
105
|
+
|
|
106
|
+
### 4.3 Handshake payloads
|
|
107
|
+
|
|
108
|
+
v1 handshake payloads SHOULD be empty. A receiver MUST reject a payload longer than 512 bytes and
|
|
109
|
+
any handshake message longer than 1024 bytes. Payload contents (if any) before the final message
|
|
110
|
+
are not authenticated to a known peer and MUST NOT carry secrets.
|
|
111
|
+
|
|
112
|
+
### 4.4 Message carriage
|
|
113
|
+
|
|
114
|
+
Handshake and transport messages are opaque byte strings. How they are carried (for example as
|
|
115
|
+
base64url in a JSON envelope sent to a specific room member) is defined by the wire framing
|
|
116
|
+
specification; framing metadata outside the Noise ciphertext is **not** authenticated by this
|
|
117
|
+
channel (see section 7.3).
|
|
118
|
+
|
|
119
|
+
## 5. Transport
|
|
120
|
+
|
|
121
|
+
After the handshake, each side obtains a Noise transport with two CipherStates.
|
|
122
|
+
|
|
123
|
+
- Each application chunk is encrypted as exactly one Noise transport message with empty associated
|
|
124
|
+
data, using Noise's internal 64-bit nonce counter. Nonces are never transmitted.
|
|
125
|
+
- Maximum plaintext per transport message: **12800 bytes** (one 12288-byte chunk plus up to 512 bytes
|
|
126
|
+
of canonical frame header, see wire-v1). Sealed size is plaintext + 16.
|
|
127
|
+
A receiver MUST reject sealed messages shorter than 16 or longer than 12816 bytes.
|
|
128
|
+
- Messages MUST be delivered and decrypted in the order they were sent, without loss. Any
|
|
129
|
+
out-of-order, duplicated, dropped or modified message causes decryption failure, which is fatal
|
|
130
|
+
(section 8). Recovery is a new handshake.
|
|
131
|
+
- `Rekey` is not used in v1. A session MUST be closed before either nonce reaches 2^64 − 1
|
|
132
|
+
(implementations MAY impose a much lower limit and re-handshake).
|
|
133
|
+
|
|
134
|
+
The first transport message in each direction is the binding (section 6). Application data
|
|
135
|
+
MUST NOT be sent or accepted until the peer's binding has been verified.
|
|
136
|
+
|
|
137
|
+
## 6. Identity binding
|
|
138
|
+
|
|
139
|
+
Each side signs, with the Ed25519 private key of its DID:
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
binding_message(role) = UTF8("mist-mcp/secure-channel/v1/binding|" || role) || 0x00 || h
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
where `role` is the signer's role, `"initiator"` or `"responder"`, and `h` is the 32-byte Noise
|
|
146
|
+
handshake hash (`GetHandshakeHash()`) after the final handshake message. The role label prevents
|
|
147
|
+
reflecting a peer's binding back to it.
|
|
148
|
+
|
|
149
|
+
Binding plaintext (UTF-8 JSON, exactly these three members, at most 1024 bytes):
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{"v":1,"did":"did:key:z6Mk...","sig":"<base64url, no padding, 64-byte Ed25519 signature>"}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The receiver MUST:
|
|
156
|
+
|
|
157
|
+
1. decrypt it as the first transport message from the peer;
|
|
158
|
+
2. check `v == 1`, exact member set, canonical base64url, signature length 64;
|
|
159
|
+
3. decode `did` as an Ed25519 `did:key` (multibase `z`, multicodec prefix `0xed 0x01`, 32-byte key);
|
|
160
|
+
4. if a DID is expected for this peer (reconnect, or an out-of-band confirmed DID), require equality;
|
|
161
|
+
5. verify the Ed25519 signature over `binding_message(peer_role)`.
|
|
162
|
+
|
|
163
|
+
During pairing, the DID and static key learned here are presented to the user for confirmation
|
|
164
|
+
(for example as fingerprints) before they are stored.
|
|
165
|
+
|
|
166
|
+
## 7. Limits and security notes
|
|
167
|
+
|
|
168
|
+
### 7.1 Limits
|
|
169
|
+
|
|
170
|
+
| Item | Limit |
|
|
171
|
+
|---|---|
|
|
172
|
+
| Pairing code | 26..64 Crockford base32 chars after normalisation (>= 128 bits entropy) |
|
|
173
|
+
| Prologue field | 1..512 UTF-8 bytes each |
|
|
174
|
+
| Handshake message / payload | 1024 / 512 bytes |
|
|
175
|
+
| Transport plaintext / sealed | 12800 / 12816 bytes |
|
|
176
|
+
| Binding plaintext | 1024 bytes |
|
|
177
|
+
|
|
178
|
+
### 7.2 What this channel provides
|
|
179
|
+
|
|
180
|
+
- Confidentiality and integrity of every chunk against relaying overlay peers.
|
|
181
|
+
- Mutual authentication: by the pairing code (XXpsk3) or pinned static keys (KK), and of the
|
|
182
|
+
long-term DID via the binding.
|
|
183
|
+
- Strict ordering and replay rejection inside one session (implicit nonces).
|
|
184
|
+
- Forward secrecy for both patterns (ephemeral-ephemeral DH).
|
|
185
|
+
|
|
186
|
+
### 7.3 What the framing layer must still do
|
|
187
|
+
|
|
188
|
+
Fields outside the ciphertext (session id, message id, chunk index/count) are unauthenticated.
|
|
189
|
+
Because chunks are decrypted strictly in arrival order, the framing layer MUST reassemble chunks in
|
|
190
|
+
decryption order and MUST treat any header that disagrees with that order (unexpected chunk
|
|
191
|
+
index, interleaving, count change) as fatal for the session. Integrity-relevant metadata SHOULD be
|
|
192
|
+
carried inside the encrypted plaintext.
|
|
193
|
+
|
|
194
|
+
## 8. Error handling
|
|
195
|
+
|
|
196
|
+
Any of the following MUST close the session immediately, discard all handshake and transport
|
|
197
|
+
state (keys, hashes, partially reassembled data), and MUST NOT leave a usable cipher:
|
|
198
|
+
|
|
199
|
+
- a handshake message that fails to process, arrives out of turn, or exceeds a limit;
|
|
200
|
+
- a prologue, PSK or pinned-key mismatch (manifests as a handshake or first-decryption failure);
|
|
201
|
+
- a transport message that fails to decrypt or exceeds a limit;
|
|
202
|
+
- a missing, malformed or invalid binding, or a binding DID different from the expected DID;
|
|
203
|
+
- a timeout while waiting for the next handshake message or the peer's binding
|
|
204
|
+
(RECOMMENDED: 15 s total).
|
|
205
|
+
|
|
206
|
+
No partial state is retained: a failed pairing stores no keys and consumes the code; a failed
|
|
207
|
+
reconnect does not modify stored keys. Errors reported to the peer (if any) MUST NOT reveal which
|
|
208
|
+
check failed. A new attempt always starts a fresh handshake with fresh ephemeral keys.
|
|
209
|
+
|
|
210
|
+
## 9. Versioning
|
|
211
|
+
|
|
212
|
+
The version byte in the prologue, the `v` member of the binding and the labels above all carry
|
|
213
|
+
version 1. A future version MUST change all of them; v1 implementations reject anything else.
|