@reclaimprotocol/attestor-core 5.0.1-beta.2 → 5.0.1-beta.22
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/browser/resources/attestor-browser.min.mjs +4512 -0
- package/lib/avs/abis/avsDirectoryABI.js +338 -341
- package/lib/avs/abis/delegationABI.js +1 -4
- package/lib/avs/abis/registryABI.js +719 -722
- package/lib/avs/client/create-claim-on-avs.js +129 -157
- package/lib/avs/config.js +18 -24
- package/lib/avs/contracts/ReclaimServiceManager.js +1 -0
- package/lib/avs/contracts/common.js +1 -0
- package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +1139 -1156
- package/lib/avs/contracts/factories/index.js +4 -4
- package/lib/avs/contracts/index.js +2 -6
- package/lib/avs/types/index.js +1 -0
- package/lib/avs/utils/contracts.js +30 -50
- package/lib/avs/utils/register.js +75 -70
- package/lib/avs/utils/tasks.js +38 -45
- package/lib/client/create-claim.js +402 -431
- package/lib/client/tunnels/make-rpc-tcp-tunnel.js +46 -48
- package/lib/client/tunnels/make-rpc-tls-tunnel.js +125 -121
- package/lib/client/utils/attestor-pool.js +23 -22
- package/lib/client/utils/client-socket.js +86 -109
- package/lib/client/utils/message-handler.js +79 -89
- package/lib/config/index.js +40 -58
- package/lib/external-rpc/benchmark.js +61 -74
- package/lib/external-rpc/event-bus.js +12 -15
- package/lib/external-rpc/handle-incoming-msg.js +216 -225
- package/lib/external-rpc/jsc-polyfills/1.js +70 -68
- package/lib/external-rpc/jsc-polyfills/2.js +17 -12
- package/lib/external-rpc/jsc-polyfills/event.js +10 -15
- package/lib/external-rpc/jsc-polyfills/index.js +2 -2
- package/lib/external-rpc/jsc-polyfills/ws.js +77 -79
- package/lib/external-rpc/setup-browser.js +28 -28
- package/lib/external-rpc/setup-jsc.js +17 -17
- package/lib/external-rpc/types.js +1 -0
- package/lib/external-rpc/utils.js +89 -89
- package/lib/external-rpc/zk.js +55 -50
- package/lib/index.js +2 -6
- package/lib/mechain/abis/governanceABI.js +457 -460
- package/lib/mechain/abis/taskABI.js +502 -505
- package/lib/mechain/client/create-claim-on-mechain.js +24 -29
- package/lib/mechain/constants/index.js +3 -8
- package/lib/mechain/types/index.js +1 -0
- package/lib/proto/api.js +4200 -4087
- package/lib/proto/tee-bundle.js +1261 -1241
- package/lib/providers/http/index.js +616 -603
- package/lib/providers/http/patch-parse5-tree.js +27 -29
- package/lib/providers/http/utils.js +289 -248
- package/lib/providers/index.js +3 -6
- package/lib/server/create-server.js +89 -91
- package/lib/server/handlers/claimTeeBundle.js +231 -211
- package/lib/server/handlers/claimTunnel.js +66 -73
- package/lib/server/handlers/completeClaimOnChain.js +20 -25
- package/lib/server/handlers/createClaimOnChain.js +21 -27
- package/lib/server/handlers/createTaskOnMechain.js +40 -50
- package/lib/server/handlers/createTunnel.js +85 -90
- package/lib/server/handlers/disconnectTunnel.js +4 -7
- package/lib/server/handlers/fetchCertificateBytes.js +37 -53
- package/lib/server/handlers/index.js +21 -24
- package/lib/server/handlers/init.js +27 -28
- package/lib/server/handlers/toprf.js +13 -16
- package/lib/server/socket.js +97 -100
- package/lib/server/tunnels/make-tcp-tunnel.js +161 -186
- package/lib/server/utils/apm.js +32 -25
- package/lib/server/utils/assert-valid-claim-request.js +305 -334
- package/lib/server/utils/config-env.js +2 -2
- package/lib/server/utils/dns.js +12 -18
- package/lib/server/utils/gcp-attestation.js +233 -181
- package/lib/server/utils/generics.d.ts +1 -1
- package/lib/server/utils/generics.js +43 -37
- package/lib/server/utils/iso.js +253 -256
- package/lib/server/utils/keep-alive.js +36 -36
- package/lib/server/utils/nitro-attestation.js +295 -220
- package/lib/server/utils/oprf-raw.js +48 -55
- package/lib/server/utils/process-handshake.js +200 -218
- package/lib/server/utils/proxy-session.js +5 -5
- package/lib/server/utils/tee-oprf-mpc-verification.js +82 -78
- package/lib/server/utils/tee-oprf-verification.js +165 -142
- package/lib/server/utils/tee-transcript-reconstruction.js +176 -129
- package/lib/server/utils/tee-verification.js +397 -334
- package/lib/server/utils/validation.js +30 -37
- package/lib/types/bgp.js +1 -0
- package/lib/types/claims.js +1 -0
- package/lib/types/client.js +1 -0
- package/lib/types/general.js +1 -0
- package/lib/types/handlers.js +1 -0
- package/lib/types/providers.d.ts +3 -2
- package/lib/types/providers.gen.js +9 -15
- package/lib/types/providers.js +1 -0
- package/lib/types/rpc.js +1 -0
- package/lib/types/signatures.d.ts +1 -2
- package/lib/types/signatures.js +1 -0
- package/lib/types/tunnel.js +1 -0
- package/lib/types/zk.js +1 -0
- package/lib/utils/auth.js +54 -66
- package/lib/utils/b64-json.js +15 -15
- package/lib/utils/bgp-listener.js +107 -111
- package/lib/utils/claims.js +89 -80
- package/lib/utils/env.js +13 -17
- package/lib/utils/error.js +43 -47
- package/lib/utils/generics.js +284 -235
- package/lib/utils/http-parser.js +232 -187
- package/lib/utils/logger.js +80 -71
- package/lib/utils/prepare-packets.js +69 -67
- package/lib/utils/redactions.js +163 -121
- package/lib/utils/retries.js +22 -24
- package/lib/utils/signatures/eth.js +29 -28
- package/lib/utils/signatures/index.js +5 -10
- package/lib/utils/socket-base.js +84 -88
- package/lib/utils/tls.js +28 -28
- package/lib/utils/ws.js +19 -19
- package/lib/utils/zk.js +542 -582
- package/package.json +12 -5
- package/lib/external-rpc/global.d.js +0 -0
- package/lib/scripts/build-browser.d.ts +0 -1
- package/lib/scripts/build-jsc.d.ts +0 -1
- package/lib/scripts/build-lib.d.ts +0 -1
- package/lib/scripts/check-avs-registration.d.ts +0 -1
- package/lib/scripts/check-avs-registration.js +0 -28
- package/lib/scripts/fallbacks/crypto.d.ts +0 -1
- package/lib/scripts/fallbacks/crypto.js +0 -4
- package/lib/scripts/fallbacks/empty.d.ts +0 -3
- package/lib/scripts/fallbacks/empty.js +0 -4
- package/lib/scripts/fallbacks/re2.d.ts +0 -1
- package/lib/scripts/fallbacks/re2.js +0 -7
- package/lib/scripts/fallbacks/snarkjs.d.ts +0 -1
- package/lib/scripts/fallbacks/snarkjs.js +0 -10
- package/lib/scripts/fallbacks/stwo.d.ts +0 -6
- package/lib/scripts/fallbacks/stwo.js +0 -159
- package/lib/scripts/generate-provider-types.d.ts +0 -5
- package/lib/scripts/generate-provider-types.js +0 -101
- package/lib/scripts/generate-receipt.d.ts +0 -9
- package/lib/scripts/generate-receipt.js +0 -101
- package/lib/scripts/generate-toprf-keys.d.ts +0 -1
- package/lib/scripts/generate-toprf-keys.js +0 -24
- package/lib/scripts/jsc-cli-rpc.d.ts +0 -1
- package/lib/scripts/jsc-cli-rpc.js +0 -35
- package/lib/scripts/register-avs-operator.d.ts +0 -1
- package/lib/scripts/register-avs-operator.js +0 -3
- package/lib/scripts/start-server.d.ts +0 -1
- package/lib/scripts/start-server.js +0 -11
- package/lib/scripts/update-avs-metadata.d.ts +0 -1
- package/lib/scripts/update-avs-metadata.js +0 -20
- package/lib/scripts/utils.d.ts +0 -1
- package/lib/scripts/utils.js +0 -10
- package/lib/scripts/whitelist-operator.d.ts +0 -1
- package/lib/scripts/whitelist-operator.js +0 -16
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
Element
|
|
3
|
-
|
|
1
|
+
// these patches are required to make "xpath" work with parse5
|
|
2
|
+
import { Element, Node } from 'domhandler';
|
|
3
|
+
Element.prototype.toString = function () {
|
|
4
|
+
throw new Error('Element.toString() is not supported');
|
|
5
|
+
// return ds(this)
|
|
4
6
|
};
|
|
5
|
-
Object.defineProperty(Node.prototype,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
Object.defineProperty(Node.prototype, 'nodeName', {
|
|
8
|
+
get: function () {
|
|
9
|
+
return this.name;
|
|
10
|
+
},
|
|
9
11
|
});
|
|
10
|
-
Object.defineProperty(Node.prototype,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
Object.defineProperty(Node.prototype, 'localName', {
|
|
13
|
+
get: function () {
|
|
14
|
+
return this.name;
|
|
15
|
+
},
|
|
14
16
|
});
|
|
15
|
-
const origAttributes = Object.getOwnPropertyDescriptor(
|
|
16
|
-
Element.prototype,
|
|
17
|
-
"attributes"
|
|
18
|
-
)?.get;
|
|
17
|
+
const origAttributes = Object.getOwnPropertyDescriptor(Element.prototype, 'attributes')?.get;
|
|
19
18
|
if (origAttributes) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
19
|
+
Object.defineProperty(Element.prototype, 'attributes', {
|
|
20
|
+
get: function (...args) {
|
|
21
|
+
const attrs = origAttributes.call(this, ...args);
|
|
22
|
+
attrs.item = (idx) => {
|
|
23
|
+
const el = attrs[idx];
|
|
24
|
+
return { ...el, nodeType: 2, localName: el.name };
|
|
25
|
+
};
|
|
26
|
+
return attrs;
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
console.warn('[WARN] Unable to patch DOM: Element.attributes property descriptor not found');
|
|
34
32
|
}
|
|
@@ -1,283 +1,324 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from "esprima-next";
|
|
11
|
-
import { JSONPath } from "jsonpath-plus";
|
|
12
|
-
import { parse } from "parse5";
|
|
13
|
-
import { adapter as htmlAdapter } from "parse5-htmlparser2-tree-adapter";
|
|
14
|
-
import RE2 from "re2";
|
|
15
|
-
import xpath from "xpath";
|
|
1
|
+
// noinspection ExceptionCaughtLocallyJS
|
|
2
|
+
import "./patch-parse5-tree.js";
|
|
3
|
+
import { concatenateUint8Arrays } from '@reclaimprotocol/tls';
|
|
4
|
+
import { ArrayExpression, ExpressionStatement, ObjectExpression, parseScript, Property, Syntax } from 'esprima-next';
|
|
5
|
+
import { JSONPath } from 'jsonpath-plus';
|
|
6
|
+
import { parse } from 'parse5';
|
|
7
|
+
import { adapter as htmlAdapter, } from 'parse5-htmlparser2-tree-adapter';
|
|
8
|
+
import RE2 from 're2';
|
|
9
|
+
import xpath from 'xpath';
|
|
16
10
|
import { getHttpRequestDataFromTranscript, isApplicationData, makeHttpResponseParser, REDACTION_CHAR_CODE } from "../../utils/index.js";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Returns only first extracted element
|
|
13
|
+
* @param html
|
|
14
|
+
* @param xpathExpression
|
|
15
|
+
* @param contentsOnly
|
|
16
|
+
*/
|
|
17
|
+
export function extractHTMLElement(html, xpathExpression, contentsOnly) {
|
|
18
|
+
const { start, end } = extractHTMLElementIndex(html, xpathExpression, contentsOnly);
|
|
19
|
+
return html.slice(start, end);
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Returns all extracted elements
|
|
23
|
+
* @param html
|
|
24
|
+
* @param xpathExpression
|
|
25
|
+
* @param contentsOnly
|
|
26
|
+
*/
|
|
27
|
+
export function extractHTMLElements(html, xpathExpression, contentsOnly) {
|
|
28
|
+
const indexes = extractHTMLElementsIndexes(html, xpathExpression, contentsOnly);
|
|
29
|
+
const res = [];
|
|
30
|
+
for (const { start, end } of indexes) {
|
|
31
|
+
res.push(html.slice(start, end));
|
|
32
|
+
}
|
|
33
|
+
return res;
|
|
28
34
|
}
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
/**
|
|
36
|
+
* returns a single index of extracted element
|
|
37
|
+
* @param html
|
|
38
|
+
* @param xpathExpression
|
|
39
|
+
* @param contentsOnly
|
|
40
|
+
*/
|
|
41
|
+
export function extractHTMLElementIndex(html, xpathExpression, contentsOnly) {
|
|
42
|
+
return extractHTMLElementsIndexes(html, xpathExpression, contentsOnly)[0];
|
|
31
43
|
}
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Returns indexes of all extracted elements
|
|
46
|
+
* @param html
|
|
47
|
+
* @param xpathExpression
|
|
48
|
+
* @param contentsOnly indices of the start and end of the element's contents only,
|
|
49
|
+
* not the whole tag
|
|
50
|
+
*/
|
|
51
|
+
export function extractHTMLElementsIndexes(html, xpathExpression, contentsOnly) {
|
|
52
|
+
return extractHTMLElementIndexesParse5(html, xpathExpression, contentsOnly);
|
|
34
53
|
}
|
|
35
54
|
function extractHTMLElementIndexesParse5(html, xpathExpression, contentsOnly) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
return nodes.map((node) => getNodeRange(node, contentsOnly));
|
|
55
|
+
const domLight = parse(html, { treeAdapter: htmlAdapter, sourceCodeLocationInfo: true });
|
|
56
|
+
// lets xpath identify this as a node
|
|
57
|
+
domLight['name'] = 'root';
|
|
58
|
+
const parsedPath = xpath.parse(xpathExpression);
|
|
59
|
+
const nodes = parsedPath.select({
|
|
60
|
+
node: domLight,
|
|
61
|
+
allowAnyNamespaceForNoPrefix: true,
|
|
62
|
+
});
|
|
63
|
+
if (!nodes.length) {
|
|
64
|
+
throw new Error(`Failed to find XPath: "${xpathExpression}"`);
|
|
65
|
+
}
|
|
66
|
+
return nodes.map(node => getNodeRange(node, contentsOnly));
|
|
50
67
|
}
|
|
51
68
|
function getNodeRange(node, contentsOnly) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
69
|
+
if (!contentsOnly) {
|
|
70
|
+
return { start: node.startIndex, end: node.endIndex };
|
|
71
|
+
}
|
|
72
|
+
if (!('firstChild' in node) || !node.firstChild) {
|
|
73
|
+
throw new Error(`Node "${node['name']}" has no children`);
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
start: node.firstChild.startIndex,
|
|
77
|
+
end: node.lastChild.endIndex
|
|
78
|
+
};
|
|
62
79
|
}
|
|
63
|
-
function extractJSONValueIndex(json, jsonPath) {
|
|
64
|
-
|
|
80
|
+
export function extractJSONValueIndex(json, jsonPath) {
|
|
81
|
+
return extractJSONValueIndexes(json, jsonPath)[0];
|
|
65
82
|
}
|
|
66
|
-
function extractJSONValueIndexes(json, jsonPath) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
const tree = parseScript("(" + json + ")", { range: true });
|
|
80
|
-
if (tree.body[0] instanceof ExpressionStatement && (tree.body[0].expression instanceof ObjectExpression || tree.body[0].expression instanceof ArrayExpression)) {
|
|
81
|
-
const traversePointers = Array.isArray(pointers) ? pointers : [pointers];
|
|
82
|
-
const res = [];
|
|
83
|
-
for (const pointer of traversePointers) {
|
|
84
|
-
const index = traverse(tree.body[0].expression, "", [pointer]);
|
|
85
|
-
if (index) {
|
|
86
|
-
res.push({
|
|
87
|
-
start: index.start - 1,
|
|
88
|
-
//account for '('
|
|
89
|
-
end: index.end - 1
|
|
90
|
-
});
|
|
91
|
-
}
|
|
83
|
+
export function extractJSONValueIndexes(json, jsonPath) {
|
|
84
|
+
const pointers = JSONPath({
|
|
85
|
+
path: jsonPath,
|
|
86
|
+
json: JSON.parse(json),
|
|
87
|
+
wrap: false,
|
|
88
|
+
resultType: 'pointer',
|
|
89
|
+
eval: 'safe',
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
ignoreEvalErrors: true
|
|
92
|
+
});
|
|
93
|
+
if (!pointers) {
|
|
94
|
+
throw new Error('jsonPath not found');
|
|
92
95
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
//wrap in parentheses for esprima to parse
|
|
97
|
+
const tree = parseScript('(' + json + ')', { range: true });
|
|
98
|
+
if (tree.body[0] instanceof ExpressionStatement
|
|
99
|
+
&& (tree.body[0].expression instanceof ObjectExpression || tree.body[0].expression instanceof ArrayExpression)) {
|
|
100
|
+
const traversePointers = Array.isArray(pointers) ? pointers : [pointers];
|
|
101
|
+
const res = [];
|
|
102
|
+
for (const pointer of traversePointers) {
|
|
103
|
+
const index = traverse(tree.body[0].expression, '', [pointer]);
|
|
104
|
+
if (index) {
|
|
105
|
+
res.push({
|
|
106
|
+
start: index.start - 1, //account for '('
|
|
107
|
+
end: index.end - 1,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return res;
|
|
112
|
+
}
|
|
113
|
+
throw new Error('jsonPath not found');
|
|
96
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* recursively go through AST tree and build a JSON path while it's not equal to the one we search for
|
|
117
|
+
* @param o - esprima expression for root object
|
|
118
|
+
* @param path - path that is being built
|
|
119
|
+
* @param pointers - JSON pointers to compare to
|
|
120
|
+
*/
|
|
97
121
|
function traverse(o, path, pointers) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
if (o instanceof ObjectExpression) {
|
|
123
|
+
for (const p of o.properties) {
|
|
124
|
+
if (!(p instanceof Property)) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const localPath = p.key.type === Syntax.Literal
|
|
128
|
+
? path + '/' + p.key.value
|
|
129
|
+
: path;
|
|
130
|
+
if (pointers.includes(localPath) && 'range' in p && Array.isArray(p.range)) {
|
|
131
|
+
return {
|
|
132
|
+
start: p.range[0],
|
|
133
|
+
end: p.range[1],
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (p.value instanceof ObjectExpression
|
|
137
|
+
|| p.value instanceof ArrayExpression) {
|
|
138
|
+
const res = traverse(p.value, localPath, pointers);
|
|
139
|
+
if (res) {
|
|
140
|
+
return res;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
114
143
|
}
|
|
115
|
-
}
|
|
116
144
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
145
|
+
if (o instanceof ArrayExpression) {
|
|
146
|
+
for (let i = 0; i < o.elements.length; i++) {
|
|
147
|
+
const element = o.elements[i];
|
|
148
|
+
if (!element) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const localPath = path + '/' + i;
|
|
152
|
+
if (pointers.includes(localPath) &&
|
|
153
|
+
'range' in element &&
|
|
154
|
+
Array.isArray(element.range)) {
|
|
155
|
+
return {
|
|
156
|
+
start: element.range[0],
|
|
157
|
+
end: element.range[1],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (element instanceof ObjectExpression) {
|
|
161
|
+
const res = traverse(element, localPath, pointers);
|
|
162
|
+
if (res) {
|
|
163
|
+
return res;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (element instanceof ArrayExpression) {
|
|
167
|
+
const res = traverse(element, localPath, pointers);
|
|
168
|
+
if (res) {
|
|
169
|
+
return res;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
141
172
|
}
|
|
142
|
-
}
|
|
143
173
|
}
|
|
144
|
-
|
|
145
|
-
return null;
|
|
174
|
+
return null;
|
|
146
175
|
}
|
|
147
|
-
function buildHeaders(input) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
176
|
+
export function buildHeaders(input) {
|
|
177
|
+
const headers = [];
|
|
178
|
+
for (const [key, value] of Object.entries(input || {})) {
|
|
179
|
+
headers.push(`${key}: ${value}`);
|
|
180
|
+
}
|
|
181
|
+
return headers;
|
|
153
182
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Converts position in HTTP response body to an absolute position in TLS transcript considering chunked encoding
|
|
185
|
+
* @param pos
|
|
186
|
+
* @param bodyStartIdx
|
|
187
|
+
* @param chunks
|
|
188
|
+
*/
|
|
189
|
+
export function convertResponsePosToAbsolutePos(pos, bodyStartIdx, chunks) {
|
|
190
|
+
if (chunks?.length) {
|
|
191
|
+
let chunkBodyStart = 0;
|
|
192
|
+
for (const chunk of chunks) {
|
|
193
|
+
const chunkSize = chunk.toIndex - chunk.fromIndex;
|
|
194
|
+
if (pos >= chunkBodyStart && pos <= (chunkBodyStart + chunkSize)) {
|
|
195
|
+
return pos - chunkBodyStart + chunk.fromIndex;
|
|
196
|
+
}
|
|
197
|
+
chunkBodyStart += chunkSize;
|
|
198
|
+
}
|
|
199
|
+
throw new Error('position out of range');
|
|
163
200
|
}
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
return bodyStartIdx + pos;
|
|
201
|
+
return bodyStartIdx + pos;
|
|
167
202
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
res.push({
|
|
177
|
-
fromIndex: chunks[i - 1].toIndex,
|
|
178
|
-
toIndex: chunk.fromIndex
|
|
179
|
-
});
|
|
203
|
+
/**
|
|
204
|
+
* If this reveal spans the boundary of two chunks, we'll
|
|
205
|
+
*
|
|
206
|
+
*/
|
|
207
|
+
export function getRedactionsForChunkHeaders(from, to, chunks) {
|
|
208
|
+
const res = [];
|
|
209
|
+
if (!chunks?.length) {
|
|
210
|
+
return res;
|
|
180
211
|
}
|
|
181
|
-
|
|
182
|
-
|
|
212
|
+
for (let i = 1; i < chunks?.length; i++) {
|
|
213
|
+
const chunk = chunks[i];
|
|
214
|
+
if (chunk.fromIndex > from && chunk.fromIndex < to) {
|
|
215
|
+
res.push({
|
|
216
|
+
fromIndex: chunks[i - 1].toIndex,
|
|
217
|
+
toIndex: chunk.fromIndex,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return res;
|
|
183
222
|
}
|
|
184
|
-
function parseHttpResponse(buff) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
223
|
+
export function parseHttpResponse(buff) {
|
|
224
|
+
const parser = makeHttpResponseParser();
|
|
225
|
+
parser.onChunk(buff);
|
|
226
|
+
parser.streamEnded();
|
|
227
|
+
return parser.res;
|
|
189
228
|
}
|
|
190
|
-
function makeRegex(str) {
|
|
191
|
-
|
|
229
|
+
export function makeRegex(str) {
|
|
230
|
+
return RE2(str, 'sgiu');
|
|
192
231
|
}
|
|
193
|
-
const TEMPLATE_START_CHARCODE =
|
|
194
|
-
const TEMPLATE_END_CHARCODE =
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
let
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
232
|
+
const TEMPLATE_START_CHARCODE = '{'.charCodeAt(0);
|
|
233
|
+
const TEMPLATE_END_CHARCODE = '}'.charCodeAt(0);
|
|
234
|
+
/**
|
|
235
|
+
* Try to match strings that contain templates like {{param}}
|
|
236
|
+
* against redacted string that has *** instead of that param
|
|
237
|
+
*/
|
|
238
|
+
export function matchRedactedStrings(templateString, redactedString) {
|
|
239
|
+
if (templateString.length === 0 && redactedString?.length === 0) {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
if (!redactedString) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
let ts = -1;
|
|
246
|
+
let rs = -1;
|
|
247
|
+
while (ts < templateString.length && rs < redactedString.length) {
|
|
248
|
+
let ct = getTChar();
|
|
249
|
+
let cr = getRChar();
|
|
250
|
+
if (ct !== cr) {
|
|
251
|
+
// only valid if param contains "{" & redacted contains "*"
|
|
252
|
+
if (ct === TEMPLATE_START_CHARCODE && cr === REDACTION_CHAR_CODE) {
|
|
253
|
+
//check that the char after first "{" is also "{"
|
|
254
|
+
if (getTChar() !== TEMPLATE_START_CHARCODE) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
//look for first closing bracket
|
|
258
|
+
while (((ct = getTChar()) !== TEMPLATE_END_CHARCODE) && ct !== -1) {
|
|
259
|
+
}
|
|
260
|
+
//look for second closing bracket
|
|
261
|
+
while (((ct = getTChar()) !== TEMPLATE_END_CHARCODE) && ct !== -1) {
|
|
262
|
+
}
|
|
263
|
+
if (ct === -1) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
//find the end of redaction
|
|
267
|
+
while (((cr = getRChar()) === REDACTION_CHAR_CODE) && cr !== -1) {
|
|
268
|
+
}
|
|
269
|
+
if (cr === -1) {
|
|
270
|
+
//if there's nothing after template too then both ended at the end of strings
|
|
271
|
+
return getTChar() === -1;
|
|
272
|
+
}
|
|
273
|
+
//rewind redacted string position back 1 char because we read one extra
|
|
274
|
+
rs--;
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
211
279
|
}
|
|
212
|
-
|
|
280
|
+
}
|
|
281
|
+
function getTChar() {
|
|
282
|
+
ts++;
|
|
283
|
+
if (ts < templateString.length) {
|
|
284
|
+
return templateString[ts];
|
|
213
285
|
}
|
|
214
|
-
|
|
286
|
+
else {
|
|
287
|
+
return -1;
|
|
215
288
|
}
|
|
216
|
-
|
|
217
|
-
|
|
289
|
+
}
|
|
290
|
+
function getRChar() {
|
|
291
|
+
if (!redactedString) {
|
|
292
|
+
return -1;
|
|
218
293
|
}
|
|
219
|
-
|
|
294
|
+
rs++;
|
|
295
|
+
if (rs < redactedString.length) {
|
|
296
|
+
return redactedString[rs];
|
|
220
297
|
}
|
|
221
|
-
|
|
222
|
-
|
|
298
|
+
else {
|
|
299
|
+
return -1;
|
|
223
300
|
}
|
|
224
|
-
rs--;
|
|
225
|
-
} else {
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
function getTChar() {
|
|
231
|
-
ts++;
|
|
232
|
-
if (ts < templateString.length) {
|
|
233
|
-
return templateString[ts];
|
|
234
|
-
} else {
|
|
235
|
-
return -1;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
function getRChar() {
|
|
239
|
-
if (!redactedString) {
|
|
240
|
-
return -1;
|
|
241
301
|
}
|
|
242
|
-
rs
|
|
243
|
-
if (rs < redactedString.length) {
|
|
244
|
-
return redactedString[rs];
|
|
245
|
-
} else {
|
|
246
|
-
return -1;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return ts === templateString.length && rs === redactedString.length;
|
|
302
|
+
return ts === templateString.length && rs === redactedString.length;
|
|
250
303
|
}
|
|
251
|
-
function generateRequstAndResponseFromTranscript(transcript, tlsVersion) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
304
|
+
export function generateRequstAndResponseFromTranscript(transcript, tlsVersion) {
|
|
305
|
+
const allPackets = transcript;
|
|
306
|
+
const packets = [];
|
|
307
|
+
for (const b of allPackets) {
|
|
308
|
+
if (b.message.type !== 'ciphertext'
|
|
309
|
+
|| !isApplicationData(b.message, tlsVersion)) {
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
const plaintext = tlsVersion === 'TLS1_3'
|
|
313
|
+
? b.message.plaintext.slice(0, -1)
|
|
314
|
+
: b.message.plaintext;
|
|
315
|
+
packets.push({
|
|
316
|
+
message: plaintext,
|
|
317
|
+
sender: b.sender
|
|
318
|
+
});
|
|
257
319
|
}
|
|
258
|
-
const
|
|
259
|
-
packets.
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
const req = getHttpRequestDataFromTranscript(packets);
|
|
265
|
-
const responsePackets = concatenateUint8Arrays(packets.filter((p) => p.sender === "server").map((p) => p.message).filter((b) => !b.every((b2) => b2 === REDACTION_CHAR_CODE)));
|
|
266
|
-
const res = parseHttpResponse(responsePackets);
|
|
267
|
-
return { req, res };
|
|
320
|
+
const req = getHttpRequestDataFromTranscript(packets);
|
|
321
|
+
const responsePackets = concatenateUint8Arrays(packets.filter(p => p.sender === 'server').map(p => p.message).filter(b => !b.every(b => b === REDACTION_CHAR_CODE)));
|
|
322
|
+
const res = parseHttpResponse(responsePackets);
|
|
323
|
+
return { req, res };
|
|
268
324
|
}
|
|
269
|
-
export {
|
|
270
|
-
buildHeaders,
|
|
271
|
-
convertResponsePosToAbsolutePos,
|
|
272
|
-
extractHTMLElement,
|
|
273
|
-
extractHTMLElementIndex,
|
|
274
|
-
extractHTMLElements,
|
|
275
|
-
extractHTMLElementsIndexes,
|
|
276
|
-
extractJSONValueIndex,
|
|
277
|
-
extractJSONValueIndexes,
|
|
278
|
-
generateRequstAndResponseFromTranscript,
|
|
279
|
-
getRedactionsForChunkHeaders,
|
|
280
|
-
makeRegex,
|
|
281
|
-
matchRedactedStrings,
|
|
282
|
-
parseHttpResponse
|
|
283
|
-
};
|
package/lib/providers/index.js
CHANGED