@moqtap/codec 0.10.0 → 0.12.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/CHANGELOG.md +175 -0
- package/README.md +3 -2
- package/dist/auth-redaction-B9JJOlIY.d.cts +100 -0
- package/dist/auth-redaction-B9JJOlIY.d.ts +100 -0
- package/dist/{chunk-RYKQXBG6.cjs → chunk-27K5BUAG.cjs} +481 -517
- package/dist/{chunk-WCPENYNE.js → chunk-3RNQMGKA.js} +359 -390
- package/dist/{chunk-TSUZ6GJV.js → chunk-5AWIXOLB.js} +438 -469
- package/dist/{chunk-4XLYCT5Q.cjs → chunk-5IMHJIAZ.cjs} +52 -2
- package/dist/{chunk-KTNERCTZ.cjs → chunk-5JGZCKJO.cjs} +488 -518
- package/dist/{chunk-WCTMPDUX.cjs → chunk-73K4OSAN.cjs} +401 -432
- package/dist/{chunk-N2V7Z37J.js → chunk-7VQKRGRD.js} +19 -3
- package/dist/{chunk-BIBMDTU5.cjs → chunk-A3UCQOIB.cjs} +486 -517
- package/dist/{chunk-K2B3OVFK.js → chunk-A7PDMVXM.js} +24 -3
- package/dist/{chunk-VZHL2U2N.cjs → chunk-A7VQO6YC.cjs} +54 -38
- package/dist/{chunk-AQ445VV7.cjs → chunk-ACQHZLRZ.cjs} +66 -46
- package/dist/{chunk-L5DRACXS.js → chunk-BBICOMW6.js} +25 -3
- package/dist/{chunk-T4VWPKDG.cjs → chunk-BNIUVOCJ.cjs} +529 -599
- package/dist/{chunk-UKKDOOUO.cjs → chunk-CNC6ANS4.cjs} +58 -37
- package/dist/{chunk-OZRK73NQ.js → chunk-FDLQSWHK.js} +433 -469
- package/dist/{chunk-IJAF6PAY.js → chunk-FFNOE4UR.js} +19 -3
- package/dist/{chunk-CZNW3R5E.cjs → chunk-GMENT63T.cjs} +54 -38
- package/dist/{chunk-XCRCAUGI.cjs → chunk-HM7BLRVP.cjs} +291 -297
- package/dist/{chunk-XHAP2YST.js → chunk-HZONHFNO.js} +19 -3
- package/dist/{chunk-SDJTSMOW.cjs → chunk-ILYABWDK.cjs} +60 -38
- package/dist/{chunk-IDV2JYJ6.cjs → chunk-KRSFTZVO.cjs} +56 -40
- package/dist/{chunk-RIIA4ALQ.cjs → chunk-KSPH6KMH.cjs} +54 -38
- package/dist/{chunk-OUNN4IQB.cjs → chunk-KTY4LAUV.cjs} +482 -497
- package/dist/chunk-OBATJBNL.cjs +868 -0
- package/dist/{chunk-RZTLQAKF.js → chunk-OJNLJT5D.js} +0 -1
- package/dist/{chunk-FT3HDNIB.js → chunk-PJK2ZS3I.js} +467 -537
- package/dist/{chunk-G53WYUXL.js → chunk-PSMZKHOC.js} +441 -456
- package/dist/{chunk-7RE6KSIY.cjs → chunk-Q5JQGHWY.cjs} +0 -1
- package/dist/{chunk-BX2N7TZM.js → chunk-SQTUQY5E.js} +31 -11
- package/dist/chunk-T2TCLZZV.js +2304 -0
- package/dist/chunk-WB65UG7G.cjs +2304 -0
- package/dist/{chunk-CF5DDD3Q.js → chunk-WCRLAKDW.js} +239 -245
- package/dist/{chunk-KYVTM5VI.js → chunk-WL2YUEXH.js} +19 -3
- package/dist/chunk-XPCBPACE.js +868 -0
- package/dist/{chunk-KGDVC4O6.js → chunk-YCNIVZS7.js} +439 -469
- package/dist/{chunk-KLPWJU6W.js → chunk-YRZQVNZO.js} +50 -0
- package/dist/{codec-DOmAmFkI.d.ts → codec-B-oUU-cp.d.ts} +21 -2
- package/dist/{codec-DNmiG2e0.d.cts → codec-B3RpCI9k.d.cts} +21 -2
- package/dist/codec-B5pcOS3m.d.cts +38 -0
- package/dist/{codec-BNy5syCU.d.ts → codec-BLjxwK2f.d.ts} +21 -2
- package/dist/{codec-alVA27Uc.d.ts → codec-BV3CL_3m.d.ts} +21 -2
- package/dist/{codec-Czejcmxr.d.cts → codec-BYCDWgED.d.ts} +22 -3
- package/dist/{codec-DaXjRrOV.d.ts → codec-Bwqq7ZQT.d.ts} +22 -3
- package/dist/{codec-CFWu5KVT.d.cts → codec-BzWxOFby.d.cts} +22 -3
- package/dist/codec-C-nJhNNl.d.ts +38 -0
- package/dist/{codec-EvybrBuY.d.cts → codec-C11VEPbQ.d.cts} +21 -2
- package/dist/codec-C9U0Vzy9.d.cts +68 -0
- package/dist/{codec-Cm3D261p.d.ts → codec-CCx22jnd.d.ts} +21 -2
- package/dist/{codec-CwZ6OCPP.d.ts → codec-CP3zkfTv.d.ts} +22 -3
- package/dist/{codec-BxQTybUX.d.cts → codec-CRmOLDpt.d.ts} +22 -3
- package/dist/{codec-DzkdW4kO.d.cts → codec-CUu56DDU.d.cts} +21 -2
- package/dist/codec-Cb8mUre3.d.ts +68 -0
- package/dist/{codec-f7vxeVIS.d.cts → codec-CemqAQdR.d.cts} +22 -3
- package/dist/{codec-gl4_QEva.d.ts → codec-CxMvsVMS.d.ts} +21 -2
- package/dist/{codec-Bd60SGKH.d.cts → codec-DIgMVTi4.d.cts} +21 -2
- package/dist/{codec--CVeqGQv.d.ts → codec-DYzozF68.d.ts} +21 -2
- package/dist/{codec-CWnf8mn_.d.cts → codec-D_O9zxax.d.ts} +22 -3
- package/dist/{codec-08ZOr5wI.d.ts → codec-Ddc-QxV6.d.cts} +22 -3
- package/dist/{codec-CBdOIfMY.d.ts → codec-DoojMl2z.d.cts} +22 -3
- package/dist/{codec-BrTi4K7r.d.cts → codec-DqdjiOQF.d.ts} +22 -3
- package/dist/{codec-CXCjya_G.d.cts → codec-Dstemwrq.d.cts} +21 -2
- package/dist/{codec-Dl_QIXMz.d.ts → codec-Dt6nuejp.d.ts} +21 -2
- package/dist/{codec-Bux_Q40X.d.ts → codec-DuYhd8fP.d.cts} +22 -3
- package/dist/{codec-Cfo_z5ET.d.cts → codec-DwNOFgPU.d.cts} +21 -2
- package/dist/{codec-guzqtfMk.d.cts → codec-l01BpNhF.d.cts} +21 -2
- package/dist/{codec-C3mdsGx3.d.ts → codec-psN2vB6I.d.cts} +22 -3
- package/dist/draft07-session.d.cts +3 -3
- package/dist/draft07-session.d.ts +3 -3
- package/dist/draft07.cjs +48 -4
- package/dist/draft07.d.cts +44 -4
- package/dist/draft07.d.ts +44 -4
- package/dist/draft07.js +49 -5
- package/dist/draft08-session.d.cts +3 -3
- package/dist/draft08-session.d.ts +3 -3
- package/dist/draft08.cjs +76 -3
- package/dist/draft08.d.cts +73 -5
- package/dist/draft08.d.ts +73 -5
- package/dist/draft08.js +77 -4
- package/dist/draft09-session.d.cts +3 -3
- package/dist/draft09-session.d.ts +3 -3
- package/dist/draft09.cjs +76 -3
- package/dist/draft09.d.cts +73 -5
- package/dist/draft09.d.ts +73 -5
- package/dist/draft09.js +77 -4
- package/dist/draft10-session.d.cts +3 -3
- package/dist/draft10-session.d.ts +3 -3
- package/dist/draft10.cjs +76 -3
- package/dist/draft10.d.cts +73 -5
- package/dist/draft10.d.ts +73 -5
- package/dist/draft10.js +77 -4
- package/dist/draft11-session.d.cts +3 -3
- package/dist/draft11-session.d.ts +3 -3
- package/dist/draft11.cjs +104 -3
- package/dist/draft11.d.cts +101 -5
- package/dist/draft11.d.ts +101 -5
- package/dist/draft11.js +105 -4
- package/dist/draft12-session.d.cts +3 -3
- package/dist/draft12-session.d.ts +3 -3
- package/dist/draft12.cjs +113 -3
- package/dist/draft12.d.cts +110 -5
- package/dist/draft12.d.ts +110 -5
- package/dist/draft12.js +114 -4
- package/dist/draft13-session.d.cts +3 -3
- package/dist/draft13-session.d.ts +3 -3
- package/dist/draft13.cjs +105 -3
- package/dist/draft13.d.cts +102 -5
- package/dist/draft13.d.ts +102 -5
- package/dist/draft13.js +106 -4
- package/dist/draft14-session.d.cts +3 -3
- package/dist/draft14-session.d.ts +3 -3
- package/dist/draft14.cjs +107 -3
- package/dist/draft14.d.cts +104 -31
- package/dist/draft14.d.ts +104 -31
- package/dist/draft14.js +108 -4
- package/dist/draft15-session.d.cts +4 -4
- package/dist/draft15-session.d.ts +4 -4
- package/dist/draft15.cjs +69 -3
- package/dist/draft15.d.cts +68 -25
- package/dist/draft15.d.ts +68 -25
- package/dist/draft15.js +70 -4
- package/dist/draft16-session.cjs +2 -2
- package/dist/draft16-session.d.cts +4 -4
- package/dist/draft16-session.d.ts +4 -4
- package/dist/draft16-session.js +1 -1
- package/dist/draft16.cjs +76 -8
- package/dist/draft16.d.cts +70 -16
- package/dist/draft16.d.ts +70 -16
- package/dist/draft16.js +73 -5
- package/dist/draft17-session.d.cts +4 -4
- package/dist/draft17-session.d.ts +4 -4
- package/dist/draft17.cjs +77 -3
- package/dist/draft17.d.cts +75 -6
- package/dist/draft17.d.ts +75 -6
- package/dist/draft17.js +78 -4
- package/dist/draft18-session.d.cts +4 -4
- package/dist/draft18-session.d.ts +4 -4
- package/dist/draft18.cjs +8 -3
- package/dist/draft18.d.cts +6 -5
- package/dist/draft18.d.ts +6 -5
- package/dist/draft18.js +9 -4
- package/dist/draft19-session.d.cts +4 -4
- package/dist/draft19-session.d.ts +4 -4
- package/dist/draft19.cjs +11 -4
- package/dist/draft19.d.cts +6 -5
- package/dist/draft19.d.ts +6 -5
- package/dist/draft19.js +12 -5
- package/dist/draft20-session.d.cts +4 -4
- package/dist/draft20-session.d.ts +4 -4
- package/dist/draft20.cjs +8 -3
- package/dist/draft20.d.cts +6 -5
- package/dist/draft20.d.ts +6 -5
- package/dist/draft20.js +9 -4
- package/dist/draft21-session.cjs +8 -0
- package/dist/draft21-session.d.cts +195 -0
- package/dist/draft21-session.d.ts +195 -0
- package/dist/draft21-session.js +8 -0
- package/dist/draft21.cjs +222 -0
- package/dist/draft21.d.cts +176 -0
- package/dist/draft21.d.ts +176 -0
- package/dist/draft21.js +222 -0
- package/dist/index.cjs +37 -31
- package/dist/index.d.cts +29 -23
- package/dist/index.d.ts +29 -23
- package/dist/index.js +22 -16
- package/dist/{session-types-Dn7b3RZM.d.ts → session-types-Cxx7W8zZ.d.ts} +1 -1
- package/dist/{session-types-B9idsih-.d.cts → session-types-DZkI_qFG.d.cts} +1 -1
- package/dist/session.cjs +7 -3
- package/dist/session.d.cts +11 -9
- package/dist/session.d.ts +11 -9
- package/dist/session.js +6 -2
- package/dist/{types-DG5_iKuv.d.cts → types-2NisMA8_.d.cts} +1 -1
- package/dist/{types-DG5_iKuv.d.ts → types-2NisMA8_.d.ts} +1 -1
- package/dist/{types-C1rxh-id.d.cts → types-Btp416jt.d.cts} +8 -0
- package/dist/{types-C1rxh-id.d.ts → types-Btp416jt.d.ts} +8 -0
- package/dist/{types-CZTzbIzQ.d.cts → types-BxTL1NXw.d.cts} +7 -0
- package/dist/{types-CZTzbIzQ.d.ts → types-BxTL1NXw.d.ts} +7 -0
- package/dist/{types-pShrs3fN.d.cts → types-CuibHYcf.d.cts} +7 -0
- package/dist/{types-pShrs3fN.d.ts → types-CuibHYcf.d.ts} +7 -0
- package/dist/{types-CY-QWxd-.d.cts → types-CwN7AEoL.d.cts} +13 -1
- package/dist/{types-CY-QWxd-.d.ts → types-CwN7AEoL.d.ts} +13 -1
- package/dist/{types-D4bmW8rY.d.cts → types-DAnalt5K.d.cts} +7 -0
- package/dist/{types-D4bmW8rY.d.ts → types-DAnalt5K.d.ts} +7 -0
- package/dist/types-DDwidj2d.d.cts +371 -0
- package/dist/types-DDwidj2d.d.ts +371 -0
- package/dist/{types-Bg86GGVZ.d.cts → types-DxXNP32l.d.cts} +8 -0
- package/dist/{types-Bg86GGVZ.d.ts → types-DxXNP32l.d.ts} +8 -0
- package/package.json +15 -3
- package/src/core/auth-redaction.ts +190 -0
- package/src/core/types.ts +1 -0
- package/src/drafts/draft07/codec.ts +40 -0
- package/src/drafts/draft07/error-codes.ts +44 -0
- package/src/drafts/draft07/index.ts +15 -0
- package/src/drafts/draft08/codec.ts +40 -0
- package/src/drafts/draft08/error-codes.ts +76 -0
- package/src/drafts/draft08/index.ts +21 -0
- package/src/drafts/draft09/codec.ts +40 -0
- package/src/drafts/draft09/error-codes.ts +76 -0
- package/src/drafts/draft09/index.ts +21 -0
- package/src/drafts/draft10/codec.ts +40 -0
- package/src/drafts/draft10/error-codes.ts +76 -0
- package/src/drafts/draft10/index.ts +21 -0
- package/src/drafts/draft11/codec.ts +60 -0
- package/src/drafts/draft11/error-codes.ts +106 -0
- package/src/drafts/draft11/index.ts +23 -0
- package/src/drafts/draft12/codec.ts +61 -0
- package/src/drafts/draft12/error-codes.ts +116 -0
- package/src/drafts/draft12/index.ts +25 -0
- package/src/drafts/draft13/codec.ts +69 -11
- package/src/drafts/draft13/error-codes.ts +107 -0
- package/src/drafts/draft13/index.ts +23 -0
- package/src/drafts/draft13/types.ts +1 -1
- package/src/drafts/draft14/codec.ts +65 -4
- package/src/drafts/draft14/data-streams.ts +331 -259
- package/src/drafts/draft14/error-codes.ts +109 -0
- package/src/drafts/draft14/index.ts +23 -0
- package/src/drafts/draft15/codec.ts +65 -8
- package/src/drafts/draft15/data-streams.ts +489 -444
- package/src/drafts/draft15/error-codes.ts +66 -0
- package/src/drafts/draft15/index.ts +15 -0
- package/src/drafts/draft15/types.ts +7 -0
- package/src/drafts/draft16/codec.ts +146 -52
- package/src/drafts/draft16/data-streams.ts +513 -442
- package/src/drafts/draft16/error-codes.ts +68 -0
- package/src/drafts/draft16/index.ts +15 -0
- package/src/drafts/draft16/messages.ts +4 -4
- package/src/drafts/draft16/session-fsm.ts +0 -1
- package/src/drafts/draft16/types.ts +22 -8
- package/src/drafts/draft17/codec.ts +73 -12
- package/src/drafts/draft17/data-streams.ts +567 -488
- package/src/drafts/draft17/index.ts +15 -0
- package/src/drafts/draft17/types.ts +7 -0
- package/src/drafts/draft18/codec.ts +66 -9
- package/src/drafts/draft18/data-streams.ts +570 -482
- package/src/drafts/draft18/index.ts +3 -0
- package/src/drafts/draft18/types.ts +16 -8
- package/src/drafts/draft19/codec.ts +70 -10
- package/src/drafts/draft19/data-streams.ts +570 -482
- package/src/drafts/draft19/error-codes.ts +3 -1
- package/src/drafts/draft19/index.ts +3 -0
- package/src/drafts/draft19/messages.ts +3 -1
- package/src/drafts/draft19/types.ts +22 -11
- package/src/drafts/draft20/codec.ts +90 -23
- package/src/drafts/draft20/data-streams.ts +610 -563
- package/src/drafts/draft20/index.ts +3 -0
- package/src/drafts/draft20/types.ts +14 -2
- package/src/drafts/draft21/codec.ts +1816 -0
- package/src/drafts/draft21/data-streams.ts +1338 -0
- package/src/drafts/draft21/error-codes.ts +135 -0
- package/src/drafts/draft21/index.ts +168 -0
- package/src/drafts/draft21/messages.ts +68 -0
- package/src/drafts/draft21/rules.ts +107 -0
- package/src/drafts/draft21/session-fsm.ts +1063 -0
- package/src/drafts/draft21/session.ts +21 -0
- package/src/drafts/draft21/types.ts +473 -0
- package/src/index.ts +9 -1
- package/src/session.ts +4 -0
- package/dist/codec-BJ7BHuiZ.d.ts +0 -18
- package/dist/codec-C6Mx4bwz.d.cts +0 -18
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AuthRedaction, recordAuthValueSpan, redactWith } from '../../core/auth-redaction.js'
|
|
1
2
|
import { BufferReader } from '../../core/buffer-reader.js'
|
|
2
3
|
import { BufferWriter } from '../../core/buffer-writer.js'
|
|
3
4
|
import { bytesToHex, hexToBytes } from '../../core/hex.js'
|
|
@@ -227,6 +228,7 @@ function decodeParams(r: BufferReader): Draft11Params {
|
|
|
227
228
|
const token_type = r.readVarInt()
|
|
228
229
|
const tokenBytesLen = length - (r.offset - startOff)
|
|
229
230
|
const tokenBytes = r.readBytes(tokenBytesLen)
|
|
231
|
+
noteAuthTokenValue(startOff, length, tokenBytes)
|
|
230
232
|
result.authorization_token = [
|
|
231
233
|
...(result.authorization_token ?? []),
|
|
232
234
|
{
|
|
@@ -1054,3 +1056,61 @@ export function createDraft11Codec(): Draft11Codec {
|
|
|
1054
1056
|
createStreamDecoder,
|
|
1055
1057
|
}
|
|
1056
1058
|
}
|
|
1059
|
+
|
|
1060
|
+
/**
|
|
1061
|
+
* Record where a Token Value sits, so it can be overwritten before the frame
|
|
1062
|
+
* reaches anything that keeps it.
|
|
1063
|
+
*
|
|
1064
|
+
* The span falls out of the decode with no second walk. The Token Value is the
|
|
1065
|
+
* last field of the Token structure, so its start is the parameter value's end
|
|
1066
|
+
* minus the value's own length. The fields before it are left alone
|
|
1067
|
+
* deliberately: Alias Type, Token Alias and Token Type are structure rather
|
|
1068
|
+
* than secret, and they are what distinguishes a session that failed to
|
|
1069
|
+
* authenticate from one that never tried.
|
|
1070
|
+
*
|
|
1071
|
+
* A token carrying no value at all -- DELETE and USE_ALIAS -- records nothing,
|
|
1072
|
+
* and its frame passes through untouched.
|
|
1073
|
+
*/
|
|
1074
|
+
function noteAuthTokenValue(
|
|
1075
|
+
valueStart: number,
|
|
1076
|
+
valueLength: number,
|
|
1077
|
+
value: Uint8Array | undefined,
|
|
1078
|
+
): void {
|
|
1079
|
+
if (value === undefined || value.byteLength === 0) return
|
|
1080
|
+
recordAuthValueSpan(valueStart + valueLength - value.byteLength, value.byteLength)
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* Overwrite every Authorization Token value in a draft-11 control frame.
|
|
1085
|
+
*
|
|
1086
|
+
* One decode, whose *output is discarded*: the point is not to read the
|
|
1087
|
+
* message, it is to learn where the credentials were so the caller never has to
|
|
1088
|
+
* hold a frame that contains one. A caller that also wants the message should
|
|
1089
|
+
* decode the **redacted** frame with {@link decodeMessage}, which then cannot
|
|
1090
|
+
* produce a value because there is no longer one in the bytes.
|
|
1091
|
+
*
|
|
1092
|
+
* A frame that fails to decode is still redacted as far as the decode got. That
|
|
1093
|
+
* is the useful direction to fail in: a value that was read is a value that was
|
|
1094
|
+
* exposed, whatever went wrong after it.
|
|
1095
|
+
*
|
|
1096
|
+
* See {@link AuthRedaction.incomplete} for the one result a caller must not
|
|
1097
|
+
* treat as clean, and {@link AuthRedaction.decoded} for the residual it cannot
|
|
1098
|
+
* close.
|
|
1099
|
+
*/
|
|
1100
|
+
export function redactAuthTokens(bytes: Uint8Array): AuthRedaction {
|
|
1101
|
+
let payloadStart: number
|
|
1102
|
+
try {
|
|
1103
|
+
const probe = new BufferReader(bytes)
|
|
1104
|
+
probe.readVarInt()
|
|
1105
|
+
probe.readUint8()
|
|
1106
|
+
probe.readUint8()
|
|
1107
|
+
payloadStart = probe.offset
|
|
1108
|
+
} catch {
|
|
1109
|
+
// Too short to carry a message header, and so too short for the parameters
|
|
1110
|
+
// that carry a credential. Reported as not decoded rather than as clean: a
|
|
1111
|
+
// framer only ever emits complete frames, so a caller that gets here is
|
|
1112
|
+
// holding something this function did not check.
|
|
1113
|
+
return { bytes, redacted: 0, incomplete: false, decoded: false }
|
|
1114
|
+
}
|
|
1115
|
+
return redactWith(bytes, payloadStart, () => decodeMessage(bytes).ok)
|
|
1116
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Draft-11 error, status and termination code registries.
|
|
2
|
+
|
|
3
|
+
export const SessionErrorCode = {
|
|
4
|
+
NoError: 0x0n,
|
|
5
|
+
InternalError: 0x1n,
|
|
6
|
+
Unauthorized: 0x2n,
|
|
7
|
+
ProtocolViolation: 0x3n,
|
|
8
|
+
InvalidRequestId: 0x4n,
|
|
9
|
+
DuplicateTrackAlias: 0x5n,
|
|
10
|
+
KeyValueFormattingError: 0x6n,
|
|
11
|
+
TooManyRequests: 0x7n,
|
|
12
|
+
InvalidPath: 0x8n,
|
|
13
|
+
MalformedPath: 0x9n,
|
|
14
|
+
GoawayTimeout: 0x10n,
|
|
15
|
+
ControlMessageTimeout: 0x11n,
|
|
16
|
+
DataStreamTimeout: 0x12n,
|
|
17
|
+
AuthTokenCacheOverflow: 0x13n,
|
|
18
|
+
DuplicateAuthTokenAlias: 0x14n,
|
|
19
|
+
VersionNegotiationFailed: 0x15n,
|
|
20
|
+
} as const
|
|
21
|
+
export type SessionErrorCodeValue = (typeof SessionErrorCode)[keyof typeof SessionErrorCode]
|
|
22
|
+
|
|
23
|
+
export const SubscribeErrorCode = {
|
|
24
|
+
InternalError: 0x0n,
|
|
25
|
+
Unauthorized: 0x1n,
|
|
26
|
+
Timeout: 0x2n,
|
|
27
|
+
NotSupported: 0x3n,
|
|
28
|
+
TrackDoesNotExist: 0x4n,
|
|
29
|
+
InvalidRange: 0x5n,
|
|
30
|
+
RetryTrackAlias: 0x6n,
|
|
31
|
+
MalformedAuthToken: 0x10n,
|
|
32
|
+
UnknownAuthTokenAlias: 0x11n,
|
|
33
|
+
ExpiredAuthToken: 0x12n,
|
|
34
|
+
} as const
|
|
35
|
+
export type SubscribeErrorCodeValue = (typeof SubscribeErrorCode)[keyof typeof SubscribeErrorCode]
|
|
36
|
+
|
|
37
|
+
export const SubscribeDoneStatusCode = {
|
|
38
|
+
InternalError: 0x0n,
|
|
39
|
+
Unauthorized: 0x1n,
|
|
40
|
+
TrackEnded: 0x2n,
|
|
41
|
+
SubscriptionEnded: 0x3n,
|
|
42
|
+
GoingAway: 0x4n,
|
|
43
|
+
Expired: 0x5n,
|
|
44
|
+
TooFarBehind: 0x6n,
|
|
45
|
+
} as const
|
|
46
|
+
export type SubscribeDoneStatusCodeValue =
|
|
47
|
+
(typeof SubscribeDoneStatusCode)[keyof typeof SubscribeDoneStatusCode]
|
|
48
|
+
|
|
49
|
+
export const FetchErrorCode = {
|
|
50
|
+
InternalError: 0x0n,
|
|
51
|
+
Unauthorized: 0x1n,
|
|
52
|
+
Timeout: 0x2n,
|
|
53
|
+
NotSupported: 0x3n,
|
|
54
|
+
TrackDoesNotExist: 0x4n,
|
|
55
|
+
InvalidRange: 0x5n,
|
|
56
|
+
NoObjects: 0x6n,
|
|
57
|
+
InvalidJoiningSubscribeId: 0x7n,
|
|
58
|
+
MalformedAuthToken: 0x10n,
|
|
59
|
+
UnknownAuthTokenAlias: 0x11n,
|
|
60
|
+
ExpiredAuthToken: 0x12n,
|
|
61
|
+
} as const
|
|
62
|
+
export type FetchErrorCodeValue = (typeof FetchErrorCode)[keyof typeof FetchErrorCode]
|
|
63
|
+
|
|
64
|
+
export const AnnounceErrorCode = {
|
|
65
|
+
InternalError: 0x0n,
|
|
66
|
+
Unauthorized: 0x1n,
|
|
67
|
+
Timeout: 0x2n,
|
|
68
|
+
NotSupported: 0x3n,
|
|
69
|
+
Uninterested: 0x4n,
|
|
70
|
+
MalformedAuthToken: 0x10n,
|
|
71
|
+
UnknownAuthTokenAlias: 0x11n,
|
|
72
|
+
ExpiredAuthToken: 0x12n,
|
|
73
|
+
} as const
|
|
74
|
+
export type AnnounceErrorCodeValue = (typeof AnnounceErrorCode)[keyof typeof AnnounceErrorCode]
|
|
75
|
+
|
|
76
|
+
export const SubscribeAnnouncesErrorCode = {
|
|
77
|
+
InternalError: 0x0n,
|
|
78
|
+
Unauthorized: 0x1n,
|
|
79
|
+
Timeout: 0x2n,
|
|
80
|
+
NotSupported: 0x3n,
|
|
81
|
+
NamespacePrefixUnknown: 0x4n,
|
|
82
|
+
NamespacePrefixOverlap: 0x5n,
|
|
83
|
+
MalformedAuthToken: 0x10n,
|
|
84
|
+
UnknownAuthTokenAlias: 0x11n,
|
|
85
|
+
ExpiredAuthToken: 0x12n,
|
|
86
|
+
} as const
|
|
87
|
+
export type SubscribeAnnouncesErrorCodeValue =
|
|
88
|
+
(typeof SubscribeAnnouncesErrorCode)[keyof typeof SubscribeAnnouncesErrorCode]
|
|
89
|
+
|
|
90
|
+
export const TrackStatusCode = {
|
|
91
|
+
InProgress: 0x00n,
|
|
92
|
+
TrackDoesNotExist: 0x01n,
|
|
93
|
+
NotYetBegun: 0x02n,
|
|
94
|
+
Finished: 0x03n,
|
|
95
|
+
RelayStatusUnavailable: 0x04n,
|
|
96
|
+
} as const
|
|
97
|
+
export type TrackStatusCodeValue = (typeof TrackStatusCode)[keyof typeof TrackStatusCode]
|
|
98
|
+
|
|
99
|
+
export const StreamResetErrorCode = {
|
|
100
|
+
InternalError: 0x0n,
|
|
101
|
+
Cancelled: 0x1n,
|
|
102
|
+
DeliveryTimeout: 0x2n,
|
|
103
|
+
SessionClosed: 0x3n,
|
|
104
|
+
} as const
|
|
105
|
+
export type StreamResetErrorCodeValue =
|
|
106
|
+
(typeof StreamResetErrorCode)[keyof typeof StreamResetErrorCode]
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export const DRAFT_VERSION = 0xff00000bn
|
|
2
2
|
|
|
3
|
+
export type { AuthRedaction } from '../../core/auth-redaction.js'
|
|
4
|
+
export { REDACTION_FILL } from '../../core/auth-redaction.js'
|
|
3
5
|
export type { Draft11Codec } from './codec.js'
|
|
4
6
|
export {
|
|
5
7
|
createDraft11Codec,
|
|
@@ -13,7 +15,28 @@ export {
|
|
|
13
15
|
encodeFetchStream,
|
|
14
16
|
encodeMessage,
|
|
15
17
|
encodeSubgroupStream,
|
|
18
|
+
redactAuthTokens,
|
|
16
19
|
} from './codec.js'
|
|
20
|
+
export type {
|
|
21
|
+
AnnounceErrorCodeValue,
|
|
22
|
+
FetchErrorCodeValue,
|
|
23
|
+
SessionErrorCodeValue,
|
|
24
|
+
StreamResetErrorCodeValue,
|
|
25
|
+
SubscribeAnnouncesErrorCodeValue,
|
|
26
|
+
SubscribeDoneStatusCodeValue,
|
|
27
|
+
SubscribeErrorCodeValue,
|
|
28
|
+
TrackStatusCodeValue,
|
|
29
|
+
} from './error-codes.js'
|
|
30
|
+
export {
|
|
31
|
+
AnnounceErrorCode,
|
|
32
|
+
FetchErrorCode,
|
|
33
|
+
SessionErrorCode,
|
|
34
|
+
StreamResetErrorCode,
|
|
35
|
+
SubscribeAnnouncesErrorCode,
|
|
36
|
+
SubscribeDoneStatusCode,
|
|
37
|
+
SubscribeErrorCode,
|
|
38
|
+
TrackStatusCode,
|
|
39
|
+
} from './error-codes.js'
|
|
17
40
|
export {
|
|
18
41
|
MESSAGE_ID_MAP,
|
|
19
42
|
MESSAGE_TYPE_MAP,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AuthRedaction, recordAuthValueSpan, redactWith } from '../../core/auth-redaction.js'
|
|
1
2
|
import { BufferReader } from '../../core/buffer-reader.js'
|
|
2
3
|
import { BufferWriter } from '../../core/buffer-writer.js'
|
|
3
4
|
import { bytesToHex, hexToBytes } from '../../core/hex.js'
|
|
@@ -148,6 +149,7 @@ function decodeSetupParams(r: BufferReader): Draft12SetupParams {
|
|
|
148
149
|
const token_type = r.readVarInt()
|
|
149
150
|
const tokenBytesLen = length - (r.offset - startOff)
|
|
150
151
|
const tokenBytes = r.readBytes(tokenBytesLen)
|
|
152
|
+
noteAuthTokenValue(startOff, length, tokenBytes)
|
|
151
153
|
result.authorization_token = [
|
|
152
154
|
...(result.authorization_token ?? []),
|
|
153
155
|
{
|
|
@@ -257,6 +259,7 @@ function decodeParams(r: BufferReader): Draft12Params {
|
|
|
257
259
|
const token_type = r.readVarInt()
|
|
258
260
|
const tokenBytesLen = length - (r.offset - startOff)
|
|
259
261
|
const tokenBytes = r.readBytes(tokenBytesLen)
|
|
262
|
+
noteAuthTokenValue(startOff, length, tokenBytes)
|
|
260
263
|
result.authorization_token = [
|
|
261
264
|
...(result.authorization_token ?? []),
|
|
262
265
|
{
|
|
@@ -1205,3 +1208,61 @@ export function createDraft12Codec(): Draft12Codec {
|
|
|
1205
1208
|
createStreamDecoder,
|
|
1206
1209
|
}
|
|
1207
1210
|
}
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* Record where a Token Value sits, so it can be overwritten before the frame
|
|
1214
|
+
* reaches anything that keeps it.
|
|
1215
|
+
*
|
|
1216
|
+
* The span falls out of the decode with no second walk. The Token Value is the
|
|
1217
|
+
* last field of the Token structure, so its start is the parameter value's end
|
|
1218
|
+
* minus the value's own length. The fields before it are left alone
|
|
1219
|
+
* deliberately: Alias Type, Token Alias and Token Type are structure rather
|
|
1220
|
+
* than secret, and they are what distinguishes a session that failed to
|
|
1221
|
+
* authenticate from one that never tried.
|
|
1222
|
+
*
|
|
1223
|
+
* A token carrying no value at all -- DELETE and USE_ALIAS -- records nothing,
|
|
1224
|
+
* and its frame passes through untouched.
|
|
1225
|
+
*/
|
|
1226
|
+
function noteAuthTokenValue(
|
|
1227
|
+
valueStart: number,
|
|
1228
|
+
valueLength: number,
|
|
1229
|
+
value: Uint8Array | undefined,
|
|
1230
|
+
): void {
|
|
1231
|
+
if (value === undefined || value.byteLength === 0) return
|
|
1232
|
+
recordAuthValueSpan(valueStart + valueLength - value.byteLength, value.byteLength)
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
/**
|
|
1236
|
+
* Overwrite every Authorization Token value in a draft-12 control frame.
|
|
1237
|
+
*
|
|
1238
|
+
* One decode, whose *output is discarded*: the point is not to read the
|
|
1239
|
+
* message, it is to learn where the credentials were so the caller never has to
|
|
1240
|
+
* hold a frame that contains one. A caller that also wants the message should
|
|
1241
|
+
* decode the **redacted** frame with {@link decodeMessage}, which then cannot
|
|
1242
|
+
* produce a value because there is no longer one in the bytes.
|
|
1243
|
+
*
|
|
1244
|
+
* A frame that fails to decode is still redacted as far as the decode got. That
|
|
1245
|
+
* is the useful direction to fail in: a value that was read is a value that was
|
|
1246
|
+
* exposed, whatever went wrong after it.
|
|
1247
|
+
*
|
|
1248
|
+
* See {@link AuthRedaction.incomplete} for the one result a caller must not
|
|
1249
|
+
* treat as clean, and {@link AuthRedaction.decoded} for the residual it cannot
|
|
1250
|
+
* close.
|
|
1251
|
+
*/
|
|
1252
|
+
export function redactAuthTokens(bytes: Uint8Array): AuthRedaction {
|
|
1253
|
+
let payloadStart: number
|
|
1254
|
+
try {
|
|
1255
|
+
const probe = new BufferReader(bytes)
|
|
1256
|
+
probe.readVarInt()
|
|
1257
|
+
probe.readUint8()
|
|
1258
|
+
probe.readUint8()
|
|
1259
|
+
payloadStart = probe.offset
|
|
1260
|
+
} catch {
|
|
1261
|
+
// Too short to carry a message header, and so too short for the parameters
|
|
1262
|
+
// that carry a credential. Reported as not decoded rather than as clean: a
|
|
1263
|
+
// framer only ever emits complete frames, so a caller that gets here is
|
|
1264
|
+
// holding something this function did not check.
|
|
1265
|
+
return { bytes, redacted: 0, incomplete: false, decoded: false }
|
|
1266
|
+
}
|
|
1267
|
+
return redactWith(bytes, payloadStart, () => decodeMessage(bytes).ok)
|
|
1268
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Draft-12 error, status and termination code registries.
|
|
2
|
+
|
|
3
|
+
export const SessionErrorCode = {
|
|
4
|
+
NoError: 0x0n,
|
|
5
|
+
InternalError: 0x1n,
|
|
6
|
+
Unauthorized: 0x2n,
|
|
7
|
+
ProtocolViolation: 0x3n,
|
|
8
|
+
InvalidRequestId: 0x4n,
|
|
9
|
+
DuplicateTrackAlias: 0x5n,
|
|
10
|
+
KeyValueFormattingError: 0x6n,
|
|
11
|
+
TooManyRequests: 0x7n,
|
|
12
|
+
InvalidPath: 0x8n,
|
|
13
|
+
MalformedPath: 0x9n,
|
|
14
|
+
GoawayTimeout: 0x10n,
|
|
15
|
+
ControlMessageTimeout: 0x11n,
|
|
16
|
+
DataStreamTimeout: 0x12n,
|
|
17
|
+
AuthTokenCacheOverflow: 0x13n,
|
|
18
|
+
DuplicateAuthTokenAlias: 0x14n,
|
|
19
|
+
VersionNegotiationFailed: 0x15n,
|
|
20
|
+
MalformedAuthToken: 0x16n,
|
|
21
|
+
UnknownAuthTokenAlias: 0x17n,
|
|
22
|
+
ExpiredAuthToken: 0x18n,
|
|
23
|
+
} as const
|
|
24
|
+
export type SessionErrorCodeValue = (typeof SessionErrorCode)[keyof typeof SessionErrorCode]
|
|
25
|
+
|
|
26
|
+
export const SubscribeErrorCode = {
|
|
27
|
+
InternalError: 0x0n,
|
|
28
|
+
Unauthorized: 0x1n,
|
|
29
|
+
Timeout: 0x2n,
|
|
30
|
+
NotSupported: 0x3n,
|
|
31
|
+
TrackDoesNotExist: 0x4n,
|
|
32
|
+
InvalidRange: 0x5n,
|
|
33
|
+
MalformedAuthToken: 0x10n,
|
|
34
|
+
ExpiredAuthToken: 0x12n,
|
|
35
|
+
} as const
|
|
36
|
+
export type SubscribeErrorCodeValue = (typeof SubscribeErrorCode)[keyof typeof SubscribeErrorCode]
|
|
37
|
+
|
|
38
|
+
export const SubscribeDoneStatusCode = {
|
|
39
|
+
InternalError: 0x0n,
|
|
40
|
+
Unauthorized: 0x1n,
|
|
41
|
+
TrackEnded: 0x2n,
|
|
42
|
+
SubscriptionEnded: 0x3n,
|
|
43
|
+
GoingAway: 0x4n,
|
|
44
|
+
Expired: 0x5n,
|
|
45
|
+
TooFarBehind: 0x6n,
|
|
46
|
+
MalformedTrack: 0x7n,
|
|
47
|
+
} as const
|
|
48
|
+
export type SubscribeDoneStatusCodeValue =
|
|
49
|
+
(typeof SubscribeDoneStatusCode)[keyof typeof SubscribeDoneStatusCode]
|
|
50
|
+
|
|
51
|
+
export const PublishErrorCode = {
|
|
52
|
+
InternalError: 0x0n,
|
|
53
|
+
Unauthorized: 0x1n,
|
|
54
|
+
Timeout: 0x2n,
|
|
55
|
+
NotSupported: 0x3n,
|
|
56
|
+
Uninterested: 0x4n,
|
|
57
|
+
} as const
|
|
58
|
+
export type PublishErrorCodeValue = (typeof PublishErrorCode)[keyof typeof PublishErrorCode]
|
|
59
|
+
|
|
60
|
+
export const FetchErrorCode = {
|
|
61
|
+
InternalError: 0x0n,
|
|
62
|
+
Unauthorized: 0x1n,
|
|
63
|
+
Timeout: 0x2n,
|
|
64
|
+
NotSupported: 0x3n,
|
|
65
|
+
TrackDoesNotExist: 0x4n,
|
|
66
|
+
InvalidRange: 0x5n,
|
|
67
|
+
NoObjects: 0x6n,
|
|
68
|
+
InvalidJoiningRequestId: 0x7n,
|
|
69
|
+
UnknownStatusInRange: 0x8n,
|
|
70
|
+
MalformedTrack: 0x9n,
|
|
71
|
+
MalformedAuthToken: 0x10n,
|
|
72
|
+
ExpiredAuthToken: 0x12n,
|
|
73
|
+
} as const
|
|
74
|
+
export type FetchErrorCodeValue = (typeof FetchErrorCode)[keyof typeof FetchErrorCode]
|
|
75
|
+
|
|
76
|
+
export const AnnounceErrorCode = {
|
|
77
|
+
InternalError: 0x0n,
|
|
78
|
+
Unauthorized: 0x1n,
|
|
79
|
+
Timeout: 0x2n,
|
|
80
|
+
NotSupported: 0x3n,
|
|
81
|
+
Uninterested: 0x4n,
|
|
82
|
+
MalformedAuthToken: 0x10n,
|
|
83
|
+
ExpiredAuthToken: 0x12n,
|
|
84
|
+
} as const
|
|
85
|
+
export type AnnounceErrorCodeValue = (typeof AnnounceErrorCode)[keyof typeof AnnounceErrorCode]
|
|
86
|
+
|
|
87
|
+
export const SubscribeAnnouncesErrorCode = {
|
|
88
|
+
InternalError: 0x0n,
|
|
89
|
+
Unauthorized: 0x1n,
|
|
90
|
+
Timeout: 0x2n,
|
|
91
|
+
NotSupported: 0x3n,
|
|
92
|
+
NamespacePrefixUnknown: 0x4n,
|
|
93
|
+
NamespacePrefixOverlap: 0x5n,
|
|
94
|
+
MalformedAuthToken: 0x10n,
|
|
95
|
+
ExpiredAuthToken: 0x12n,
|
|
96
|
+
} as const
|
|
97
|
+
export type SubscribeAnnouncesErrorCodeValue =
|
|
98
|
+
(typeof SubscribeAnnouncesErrorCode)[keyof typeof SubscribeAnnouncesErrorCode]
|
|
99
|
+
|
|
100
|
+
export const StreamResetErrorCode = {
|
|
101
|
+
InternalError: 0x0n,
|
|
102
|
+
Cancelled: 0x1n,
|
|
103
|
+
DeliveryTimeout: 0x2n,
|
|
104
|
+
SessionClosed: 0x3n,
|
|
105
|
+
} as const
|
|
106
|
+
export type StreamResetErrorCodeValue =
|
|
107
|
+
(typeof StreamResetErrorCode)[keyof typeof StreamResetErrorCode]
|
|
108
|
+
|
|
109
|
+
export const TrackStatusCode = {
|
|
110
|
+
InProgress: 0x00n,
|
|
111
|
+
TrackDoesNotExist: 0x01n,
|
|
112
|
+
NotYetBegun: 0x02n,
|
|
113
|
+
Finished: 0x03n,
|
|
114
|
+
RelayStatusUnavailable: 0x04n,
|
|
115
|
+
} as const
|
|
116
|
+
export type TrackStatusCodeValue = (typeof TrackStatusCode)[keyof typeof TrackStatusCode]
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export const DRAFT_VERSION = 0xff00000cn
|
|
2
2
|
|
|
3
|
+
export type { AuthRedaction } from '../../core/auth-redaction.js'
|
|
4
|
+
export { REDACTION_FILL } from '../../core/auth-redaction.js'
|
|
3
5
|
export type { Draft12Codec } from './codec.js'
|
|
4
6
|
export {
|
|
5
7
|
createDraft12Codec,
|
|
@@ -13,7 +15,30 @@ export {
|
|
|
13
15
|
encodeFetchStream,
|
|
14
16
|
encodeMessage,
|
|
15
17
|
encodeSubgroupStream,
|
|
18
|
+
redactAuthTokens,
|
|
16
19
|
} from './codec.js'
|
|
20
|
+
export type {
|
|
21
|
+
AnnounceErrorCodeValue,
|
|
22
|
+
FetchErrorCodeValue,
|
|
23
|
+
PublishErrorCodeValue,
|
|
24
|
+
SessionErrorCodeValue,
|
|
25
|
+
StreamResetErrorCodeValue,
|
|
26
|
+
SubscribeAnnouncesErrorCodeValue,
|
|
27
|
+
SubscribeDoneStatusCodeValue,
|
|
28
|
+
SubscribeErrorCodeValue,
|
|
29
|
+
TrackStatusCodeValue,
|
|
30
|
+
} from './error-codes.js'
|
|
31
|
+
export {
|
|
32
|
+
AnnounceErrorCode,
|
|
33
|
+
FetchErrorCode,
|
|
34
|
+
PublishErrorCode,
|
|
35
|
+
SessionErrorCode,
|
|
36
|
+
StreamResetErrorCode,
|
|
37
|
+
SubscribeAnnouncesErrorCode,
|
|
38
|
+
SubscribeDoneStatusCode,
|
|
39
|
+
SubscribeErrorCode,
|
|
40
|
+
TrackStatusCode,
|
|
41
|
+
} from './error-codes.js'
|
|
17
42
|
export {
|
|
18
43
|
MESSAGE_ID_MAP,
|
|
19
44
|
MESSAGE_TYPE_MAP,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AuthRedaction, recordAuthValueSpan, redactWith } from '../../core/auth-redaction.js'
|
|
1
2
|
import { BufferReader } from '../../core/buffer-reader.js'
|
|
2
3
|
import { BufferWriter } from '../../core/buffer-writer.js'
|
|
3
4
|
import { bytesToHex, hexToBytes } from '../../core/hex.js'
|
|
@@ -185,10 +186,10 @@ function decodeSetupParams(r: BufferReader): Draft13SetupParams {
|
|
|
185
186
|
const bytes = r.readBytes(length)
|
|
186
187
|
result.path = textDecoder.decode(bytes)
|
|
187
188
|
} else if (paramType === SETUP_PARAM_AUTHORIZATION_TOKEN) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
]
|
|
189
|
+
const valueStart = r.offset
|
|
190
|
+
const token = decodeAuthorizationToken(r, length)
|
|
191
|
+
noteAuthTokenValue(valueStart, length, token.token_value)
|
|
192
|
+
result.authorization_token = [...(result.authorization_token ?? []), token]
|
|
192
193
|
} else {
|
|
193
194
|
const bytes = r.readBytes(length)
|
|
194
195
|
unknown.push({
|
|
@@ -278,10 +279,10 @@ function decodeParams(r: BufferReader): Draft13Params {
|
|
|
278
279
|
const length = Number(r.readVarInt())
|
|
279
280
|
|
|
280
281
|
if (paramType === PARAM_AUTHORIZATION_TOKEN) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
]
|
|
282
|
+
const valueStart = r.offset
|
|
283
|
+
const token = decodeAuthorizationToken(r, length)
|
|
284
|
+
noteAuthTokenValue(valueStart, length, token.token_value)
|
|
285
|
+
result.authorization_token = [...(result.authorization_token ?? []), token]
|
|
285
286
|
} else {
|
|
286
287
|
const bytes = r.readBytes(length)
|
|
287
288
|
unknown.push({
|
|
@@ -431,7 +432,7 @@ function encodeAnnounceCancelPayload(
|
|
|
431
432
|
w.writeString(msg.reason_phrase)
|
|
432
433
|
}
|
|
433
434
|
|
|
434
|
-
// Draft-13
|
|
435
|
+
// Draft-13 subscribe_namespace (0x11) — byte-identical to the payload draft-12 spells subscribe_announces.
|
|
435
436
|
function encodeSubscribeNamespacePayload(
|
|
436
437
|
msg: Draft13Message & { type: 'subscribe_namespace' },
|
|
437
438
|
w: BufferWriter,
|
|
@@ -553,7 +554,7 @@ function encodeFetchCancelPayload(
|
|
|
553
554
|
w.writeVarInt(msg.request_id)
|
|
554
555
|
}
|
|
555
556
|
|
|
556
|
-
// Draft-13:
|
|
557
|
+
// Draft-13 Section 8.20: the TRACK_STATUS message format is identical to SUBSCRIBE.
|
|
557
558
|
function encodeTrackStatusPayload(
|
|
558
559
|
msg: Draft13Message & { type: 'track_status' },
|
|
559
560
|
w: BufferWriter,
|
|
@@ -783,7 +784,6 @@ function decodeAnnounceCancelPayload(r: BufferReader): Draft13Message {
|
|
|
783
784
|
return { type: 'announce_cancel', track_namespace, error_code, reason_phrase }
|
|
784
785
|
}
|
|
785
786
|
|
|
786
|
-
// Draft-13: subscribe_namespace (renamed from subscribe_announces)
|
|
787
787
|
function decodeSubscribeNamespacePayload(r: BufferReader): Draft13Message {
|
|
788
788
|
const request_id = r.readVarInt()
|
|
789
789
|
const track_namespace_prefix = r.readTuple()
|
|
@@ -1299,3 +1299,61 @@ export function createDraft13Codec(): Draft13Codec {
|
|
|
1299
1299
|
createStreamDecoder,
|
|
1300
1300
|
}
|
|
1301
1301
|
}
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* Record where a Token Value sits, so it can be overwritten before the frame
|
|
1305
|
+
* reaches anything that keeps it.
|
|
1306
|
+
*
|
|
1307
|
+
* The span falls out of the decode with no second walk. The Token Value is the
|
|
1308
|
+
* last field of the Token structure, so its start is the parameter value's end
|
|
1309
|
+
* minus the value's own length. The fields before it are left alone
|
|
1310
|
+
* deliberately: Alias Type, Token Alias and Token Type are structure rather
|
|
1311
|
+
* than secret, and they are what distinguishes a session that failed to
|
|
1312
|
+
* authenticate from one that never tried.
|
|
1313
|
+
*
|
|
1314
|
+
* A token carrying no value at all -- DELETE and USE_ALIAS -- records nothing,
|
|
1315
|
+
* and its frame passes through untouched.
|
|
1316
|
+
*/
|
|
1317
|
+
function noteAuthTokenValue(
|
|
1318
|
+
valueStart: number,
|
|
1319
|
+
valueLength: number,
|
|
1320
|
+
value: Uint8Array | undefined,
|
|
1321
|
+
): void {
|
|
1322
|
+
if (value === undefined || value.byteLength === 0) return
|
|
1323
|
+
recordAuthValueSpan(valueStart + valueLength - value.byteLength, value.byteLength)
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
/**
|
|
1327
|
+
* Overwrite every Authorization Token value in a draft-13 control frame.
|
|
1328
|
+
*
|
|
1329
|
+
* One decode, whose *output is discarded*: the point is not to read the
|
|
1330
|
+
* message, it is to learn where the credentials were so the caller never has to
|
|
1331
|
+
* hold a frame that contains one. A caller that also wants the message should
|
|
1332
|
+
* decode the **redacted** frame with {@link decodeMessage}, which then cannot
|
|
1333
|
+
* produce a value because there is no longer one in the bytes.
|
|
1334
|
+
*
|
|
1335
|
+
* A frame that fails to decode is still redacted as far as the decode got. That
|
|
1336
|
+
* is the useful direction to fail in: a value that was read is a value that was
|
|
1337
|
+
* exposed, whatever went wrong after it.
|
|
1338
|
+
*
|
|
1339
|
+
* See {@link AuthRedaction.incomplete} for the one result a caller must not
|
|
1340
|
+
* treat as clean, and {@link AuthRedaction.decoded} for the residual it cannot
|
|
1341
|
+
* close.
|
|
1342
|
+
*/
|
|
1343
|
+
export function redactAuthTokens(bytes: Uint8Array): AuthRedaction {
|
|
1344
|
+
let payloadStart: number
|
|
1345
|
+
try {
|
|
1346
|
+
const probe = new BufferReader(bytes)
|
|
1347
|
+
probe.readVarInt()
|
|
1348
|
+
probe.readUint8()
|
|
1349
|
+
probe.readUint8()
|
|
1350
|
+
payloadStart = probe.offset
|
|
1351
|
+
} catch {
|
|
1352
|
+
// Too short to carry a message header, and so too short for the parameters
|
|
1353
|
+
// that carry a credential. Reported as not decoded rather than as clean: a
|
|
1354
|
+
// framer only ever emits complete frames, so a caller that gets here is
|
|
1355
|
+
// holding something this function did not check.
|
|
1356
|
+
return { bytes, redacted: 0, incomplete: false, decoded: false }
|
|
1357
|
+
}
|
|
1358
|
+
return redactWith(bytes, payloadStart, () => decodeMessage(bytes).ok)
|
|
1359
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Draft-13 error, status and termination code registries.
|
|
2
|
+
|
|
3
|
+
export const SessionErrorCode = {
|
|
4
|
+
NoError: 0x0n,
|
|
5
|
+
InternalError: 0x1n,
|
|
6
|
+
Unauthorized: 0x2n,
|
|
7
|
+
ProtocolViolation: 0x3n,
|
|
8
|
+
InvalidRequestId: 0x4n,
|
|
9
|
+
DuplicateTrackAlias: 0x5n,
|
|
10
|
+
KeyValueFormattingError: 0x6n,
|
|
11
|
+
TooManyRequests: 0x7n,
|
|
12
|
+
InvalidPath: 0x8n,
|
|
13
|
+
MalformedPath: 0x9n,
|
|
14
|
+
GoawayTimeout: 0x10n,
|
|
15
|
+
ControlMessageTimeout: 0x11n,
|
|
16
|
+
DataStreamTimeout: 0x12n,
|
|
17
|
+
AuthTokenCacheOverflow: 0x13n,
|
|
18
|
+
DuplicateAuthTokenAlias: 0x14n,
|
|
19
|
+
VersionNegotiationFailed: 0x15n,
|
|
20
|
+
MalformedAuthToken: 0x16n,
|
|
21
|
+
UnknownAuthTokenAlias: 0x17n,
|
|
22
|
+
ExpiredAuthToken: 0x18n,
|
|
23
|
+
} as const
|
|
24
|
+
export type SessionErrorCodeValue = (typeof SessionErrorCode)[keyof typeof SessionErrorCode]
|
|
25
|
+
|
|
26
|
+
export const SubscribeErrorCode = {
|
|
27
|
+
InternalError: 0x0n,
|
|
28
|
+
Unauthorized: 0x1n,
|
|
29
|
+
Timeout: 0x2n,
|
|
30
|
+
NotSupported: 0x3n,
|
|
31
|
+
TrackDoesNotExist: 0x4n,
|
|
32
|
+
InvalidRange: 0x5n,
|
|
33
|
+
MalformedAuthToken: 0x10n,
|
|
34
|
+
ExpiredAuthToken: 0x12n,
|
|
35
|
+
} as const
|
|
36
|
+
export type SubscribeErrorCodeValue = (typeof SubscribeErrorCode)[keyof typeof SubscribeErrorCode]
|
|
37
|
+
|
|
38
|
+
export const SubscribeDoneStatusCode = {
|
|
39
|
+
InternalError: 0x0n,
|
|
40
|
+
Unauthorized: 0x1n,
|
|
41
|
+
TrackEnded: 0x2n,
|
|
42
|
+
SubscriptionEnded: 0x3n,
|
|
43
|
+
GoingAway: 0x4n,
|
|
44
|
+
Expired: 0x5n,
|
|
45
|
+
TooFarBehind: 0x6n,
|
|
46
|
+
MalformedTrack: 0x7n,
|
|
47
|
+
} as const
|
|
48
|
+
export type SubscribeDoneStatusCodeValue =
|
|
49
|
+
(typeof SubscribeDoneStatusCode)[keyof typeof SubscribeDoneStatusCode]
|
|
50
|
+
|
|
51
|
+
export const PublishErrorCode = {
|
|
52
|
+
InternalError: 0x0n,
|
|
53
|
+
Unauthorized: 0x1n,
|
|
54
|
+
Timeout: 0x2n,
|
|
55
|
+
NotSupported: 0x3n,
|
|
56
|
+
Uninterested: 0x4n,
|
|
57
|
+
} as const
|
|
58
|
+
export type PublishErrorCodeValue = (typeof PublishErrorCode)[keyof typeof PublishErrorCode]
|
|
59
|
+
|
|
60
|
+
export const FetchErrorCode = {
|
|
61
|
+
InternalError: 0x0n,
|
|
62
|
+
Unauthorized: 0x1n,
|
|
63
|
+
Timeout: 0x2n,
|
|
64
|
+
NotSupported: 0x3n,
|
|
65
|
+
TrackDoesNotExist: 0x4n,
|
|
66
|
+
InvalidRange: 0x5n,
|
|
67
|
+
NoObjects: 0x6n,
|
|
68
|
+
InvalidJoiningRequestId: 0x7n,
|
|
69
|
+
UnknownStatusInRange: 0x8n,
|
|
70
|
+
MalformedTrack: 0x9n,
|
|
71
|
+
MalformedAuthToken: 0x10n,
|
|
72
|
+
ExpiredAuthToken: 0x12n,
|
|
73
|
+
} as const
|
|
74
|
+
export type FetchErrorCodeValue = (typeof FetchErrorCode)[keyof typeof FetchErrorCode]
|
|
75
|
+
|
|
76
|
+
export const AnnounceErrorCode = {
|
|
77
|
+
InternalError: 0x0n,
|
|
78
|
+
Unauthorized: 0x1n,
|
|
79
|
+
Timeout: 0x2n,
|
|
80
|
+
NotSupported: 0x3n,
|
|
81
|
+
Uninterested: 0x4n,
|
|
82
|
+
MalformedAuthToken: 0x10n,
|
|
83
|
+
ExpiredAuthToken: 0x12n,
|
|
84
|
+
} as const
|
|
85
|
+
export type AnnounceErrorCodeValue = (typeof AnnounceErrorCode)[keyof typeof AnnounceErrorCode]
|
|
86
|
+
|
|
87
|
+
export const SubscribeNamespaceErrorCode = {
|
|
88
|
+
InternalError: 0x0n,
|
|
89
|
+
Unauthorized: 0x1n,
|
|
90
|
+
Timeout: 0x2n,
|
|
91
|
+
NotSupported: 0x3n,
|
|
92
|
+
NamespacePrefixUnknown: 0x4n,
|
|
93
|
+
NamespacePrefixOverlap: 0x5n,
|
|
94
|
+
MalformedAuthToken: 0x10n,
|
|
95
|
+
ExpiredAuthToken: 0x12n,
|
|
96
|
+
} as const
|
|
97
|
+
export type SubscribeNamespaceErrorCodeValue =
|
|
98
|
+
(typeof SubscribeNamespaceErrorCode)[keyof typeof SubscribeNamespaceErrorCode]
|
|
99
|
+
|
|
100
|
+
export const StreamResetErrorCode = {
|
|
101
|
+
InternalError: 0x0n,
|
|
102
|
+
Cancelled: 0x1n,
|
|
103
|
+
DeliveryTimeout: 0x2n,
|
|
104
|
+
SessionClosed: 0x3n,
|
|
105
|
+
} as const
|
|
106
|
+
export type StreamResetErrorCodeValue =
|
|
107
|
+
(typeof StreamResetErrorCode)[keyof typeof StreamResetErrorCode]
|