querysub 0.433.0 → 0.436.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/.eslintrc.js +50 -50
- package/bin/deploy.js +0 -0
- package/bin/function.js +0 -0
- package/bin/server.js +0 -0
- package/costsBenefits.txt +115 -115
- package/deploy.ts +2 -2
- package/package.json +1 -1
- package/spec.txt +1192 -1192
- package/src/-a-archives/archives.ts +202 -202
- package/src/-a-archives/archivesBackBlaze.ts +1 -0
- package/src/-a-archives/archivesDisk.ts +454 -454
- package/src/-a-auth/certs.ts +540 -540
- package/src/-a-auth/node-forge-ed25519.d.ts +16 -16
- package/src/-b-authorities/dnsAuthority.ts +138 -138
- package/src/-c-identity/IdentityController.ts +258 -258
- package/src/-d-trust/NetworkTrust2.ts +180 -180
- package/src/-e-certs/EdgeCertController.ts +252 -252
- package/src/-e-certs/certAuthority.ts +201 -201
- package/src/-f-node-discovery/NodeDiscovery.ts +640 -640
- package/src/-g-core-values/NodeCapabilities.ts +200 -200
- package/src/-h-path-value-serialize/stringSerializer.ts +175 -175
- package/src/0-path-value-core/PathValueCommitter.ts +468 -468
- package/src/0-path-value-core/pathValueCore.ts +2 -2
- package/src/2-proxy/PathValueProxyWatcher.ts +2542 -2542
- package/src/2-proxy/TransactionDelayer.ts +94 -94
- package/src/2-proxy/pathDatabaseProxyBase.ts +36 -36
- package/src/2-proxy/pathValueProxy.ts +159 -159
- package/src/3-path-functions/PathFunctionRunnerMain.ts +87 -87
- package/src/3-path-functions/pathFunctionLoader.ts +516 -516
- package/src/3-path-functions/tests/rejectTest.ts +76 -76
- package/src/4-deploy/deployCheck.ts +6 -6
- package/src/4-dom/css.tsx +29 -29
- package/src/4-dom/cssTypes.d.ts +211 -211
- package/src/4-dom/qreact.tsx +2799 -2799
- package/src/4-dom/qreactTest.tsx +410 -410
- package/src/4-querysub/permissions.ts +335 -335
- package/src/4-querysub/querysubPrediction.ts +483 -483
- package/src/5-diagnostics/qreactDebug.tsx +346 -346
- package/src/TestController.ts +34 -34
- package/src/bits.ts +104 -104
- package/src/buffers.ts +69 -69
- package/src/diagnostics/ActionsHistory.ts +57 -57
- package/src/diagnostics/listenOnDebugger.ts +71 -71
- package/src/diagnostics/periodic.ts +111 -111
- package/src/diagnostics/trackResources.ts +91 -91
- package/src/diagnostics/watchdog.ts +120 -120
- package/src/errors.ts +133 -133
- package/src/forceProduction.ts +2 -2
- package/src/fs.ts +80 -80
- package/src/functional/diff.ts +857 -857
- package/src/functional/promiseCache.ts +78 -78
- package/src/functional/random.ts +8 -8
- package/src/functional/stats.ts +60 -60
- package/src/heapDumps.ts +665 -665
- package/src/https.ts +1 -1
- package/src/library-components/AspectSizedComponent.tsx +87 -87
- package/src/library-components/ButtonSelector.tsx +64 -64
- package/src/library-components/DropdownCustom.tsx +150 -150
- package/src/library-components/DropdownSelector.tsx +31 -31
- package/src/library-components/InlinePopup.tsx +66 -66
- package/src/misc/color.ts +29 -29
- package/src/misc/hash.ts +83 -83
- package/src/misc/ipPong.js +13 -13
- package/src/misc/networking.ts +1 -1
- package/src/misc/random.ts +44 -44
- package/src/misc.ts +196 -196
- package/src/path.ts +255 -255
- package/src/persistentLocalStore.ts +41 -41
- package/src/promise.ts +14 -14
- package/src/storage/fileSystemPointer.ts +71 -71
- package/src/test/heapProcess.ts +35 -35
- package/src/zip.ts +15 -15
- package/tsconfig.json +26 -26
- package/yarnSpec.txt +56 -56
|
@@ -1,181 +1,181 @@
|
|
|
1
|
-
import { measureWrap } from "socket-function/src/profiling/measure";
|
|
2
|
-
import { getIdentityCA, getMachineId, getOwnMachineId } from "../-a-auth/certs";
|
|
3
|
-
import { getArchives } from "../-a-archives/archives";
|
|
4
|
-
import { isNode, throttleFunction, timeInHour, timeInSecond } from "socket-function/src/misc";
|
|
5
|
-
import { SocketFunctionHook } from "socket-function/SocketFunctionTypes";
|
|
6
|
-
import { SocketFunction } from "socket-function/SocketFunction";
|
|
7
|
-
import { IdentityController_getMachineId } from "../-c-identity/IdentityController";
|
|
8
|
-
import { cache, lazy } from "socket-function/src/caching";
|
|
9
|
-
import { getNodeIdDomainMaybeUndefined, getNodeIdIP, getNodeIdLocation } from "socket-function/src/nodeCache";
|
|
10
|
-
import { trustCertificate } from "socket-function/src/certStore";
|
|
11
|
-
import { isClient, isServer } from "../config2";
|
|
12
|
-
import debugbreak from "debugbreak";
|
|
13
|
-
import { devDebugbreak, getDomain, isDevDebugbreak, isPublic, isRecovery } from "../config";
|
|
14
|
-
import { formatTime } from "socket-function/src/formatting/format";
|
|
15
|
-
import { runInSerial } from "socket-function/src/batching";
|
|
16
|
-
import { Querysub } from "../4-querysub/QuerysubController";
|
|
17
|
-
import { magenta } from "socket-function/src/formatting/logColors";
|
|
18
|
-
|
|
19
|
-
// Cache the untrust list, to prevent bugs from causing too many backend reads (while also allowing
|
|
20
|
-
// bad servers which make request before their trust is verified from staying broken).
|
|
21
|
-
const UNTRUST_CACHE_TIME = 30 * timeInSecond;
|
|
22
|
-
const TRUSTED_CACHE_RESET_INTERVAL = timeInHour;
|
|
23
|
-
|
|
24
|
-
const archives = lazy(() => getArchives("trust2/"));
|
|
25
|
-
|
|
26
|
-
export const requiresNetworkTrustHook: SocketFunctionHook = async config => {
|
|
27
|
-
// HACK: On the clientside we strip the domain process and machine id, so we can no longer determine
|
|
28
|
-
// who it is. So... we trust anyone. This isn't so bad, as:
|
|
29
|
-
// 1) They have to at least have an HTTPS certificate, which... most nodes should have?
|
|
30
|
-
// 2) We only really talk to nodes we discovery, and only network trusted nodes can register themselves,
|
|
31
|
-
// so... they are probably already trusted.
|
|
32
|
-
// ALSO, if in NodeJS, but acting as a client, we only connect to remote servers via
|
|
33
|
-
// HTTPS, so we know we can trust them, as their certificates are verified.
|
|
34
|
-
// - Also, if we are a client we don't really have any privileged data, except
|
|
35
|
-
// the data we send servers, which we explicitly connect to.
|
|
36
|
-
// NOTE: This also exists in isTrusted.
|
|
37
|
-
if (isClient()) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
let caller = SocketFunction.getCaller();
|
|
41
|
-
if (getNodeIdIP(caller.nodeId) === "127.0.0.1" && isRecovery()) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
let machineId = IdentityController_getMachineId(caller);
|
|
45
|
-
let trusted = await isTrusted(machineId);
|
|
46
|
-
if (!trusted) {
|
|
47
|
-
devDebugbreak();
|
|
48
|
-
let machineId = IdentityController_getMachineId(caller);
|
|
49
|
-
throw new Error(`Calling machine is not trusted. Caller ${machineId} is not trusted by ${SocketFunction.mountedNodeId} to make call ${config.call.classGuid}.${config.call.functionName}. To gain trust add backblaze permissions (see hasBackblazePermissions) or set --nonetwork.`);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
export const assertIsNetworkTrusted = requiresNetworkTrustHook;
|
|
53
|
-
|
|
54
|
-
let lastArchivesTrusted: string[] | undefined;
|
|
55
|
-
let trustedCache = new Set<string>();
|
|
56
|
-
let untrustedCache = new Map<string, number>();
|
|
57
|
-
export const isTrusted = measureWrap(async function isTrusted(machineId: string) {
|
|
58
|
-
// See the comment in requiresNetworkTrustHook for why clients have to trust all callers.
|
|
59
|
-
if (isClient()) return true;
|
|
60
|
-
|
|
61
|
-
await populateTrustedCache();
|
|
62
|
-
|
|
63
|
-
if (trustedCache.has(machineId)) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
let untrustedTime = untrustedCache.get(machineId);
|
|
67
|
-
if (untrustedTime !== undefined && untrustedTime > Date.now()) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (machineId.includes("..")) {
|
|
72
|
-
console.warn(`Invalid machineId in isTrust call: ${machineId}`);
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Checking a single entry is fast and if we don't trust them they'll be added to untrusted cache so it shouldn't slow things down by too much.
|
|
77
|
-
let trusted = await archives().get(machineId);
|
|
78
|
-
if (trusted) {
|
|
79
|
-
trustedCache.add(machineId);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!trustedCache.has(machineId)) {
|
|
83
|
-
untrustedCache.set(machineId, Date.now() + UNTRUST_CACHE_TIME);
|
|
84
|
-
return false;
|
|
85
|
-
} else {
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
let populateTrustedCache = lazy(async () => {
|
|
90
|
-
let trustedMachineIds = await archives().find("");
|
|
91
|
-
lastArchivesTrusted = trustedMachineIds.slice();
|
|
92
|
-
for (let trustedMachineId of trustedMachineIds) {
|
|
93
|
-
trustedCache.add(trustedMachineId);
|
|
94
|
-
}
|
|
95
|
-
// Always trust ourself
|
|
96
|
-
trustedCache.add(getOwnMachineId());
|
|
97
|
-
|
|
98
|
-
// NOTE: This only happens to servers that we connect to. Also we only allow the machine ID to be this special ID in the case it's on our domain. And because we use HTTPS when connecting to domains, it means that it must be implicitly trusted if it has a certificate for our domain.
|
|
99
|
-
trustedCache.add("127-0-0-1");
|
|
100
|
-
|
|
101
|
-
setTimeout(() => {
|
|
102
|
-
trustedCache.clear();
|
|
103
|
-
populateTrustedCache.reset();
|
|
104
|
-
}, TRUSTED_CACHE_RESET_INTERVAL);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
export async function isNodeTrusted(nodeId: string) {
|
|
108
|
-
let domainName = getNodeIdDomainMaybeUndefined(nodeId);
|
|
109
|
-
if (!domainName) return false;
|
|
110
|
-
let machineId = getMachineId(domainName);
|
|
111
|
-
return await isTrusted(machineId);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const loadServerCert = cache(async (machineId: string) => {
|
|
115
|
-
// This cert isn't stored in the archives, but... this is fine?
|
|
116
|
-
if (machineId === "127-0-0-1." + getDomain()) return;
|
|
117
|
-
let certFile = await archives().get(machineId);
|
|
118
|
-
if (!certFile) {
|
|
119
|
-
console.warn(`Could not find certificate in archives for ${machineId}`);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
console.log(magenta(`Loading certificate for ${machineId}`));
|
|
123
|
-
trustCertificate(certFile);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
export const ensureWeAreTrusted = lazy(measureWrap(async () => {
|
|
127
|
-
let machineKeyCert = getIdentityCA();
|
|
128
|
-
let machineId = getOwnMachineId();
|
|
129
|
-
if (!await archives().get(machineId)) {
|
|
130
|
-
await archives().set(machineId, machineKeyCert.cert);
|
|
131
|
-
}
|
|
132
|
-
}));
|
|
133
|
-
|
|
134
|
-
async function loadTrustCerts(nodeId: string) {
|
|
135
|
-
let location = getNodeIdLocation(nodeId);
|
|
136
|
-
if (location) {
|
|
137
|
-
let machineId = getMachineId(location.address);
|
|
138
|
-
let isTrustedBool = await isTrusted(machineId);
|
|
139
|
-
if (isTrustedBool) {
|
|
140
|
-
await loadServerCert(machineId);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export const isTrustedByNode = cache(async function isTrustedByNode(nodeId: string) {
|
|
146
|
-
return await TrustedController.nodes[nodeId].isTrusted();
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
class IsTrustedControllerBase {
|
|
150
|
-
public async isTrusted() {
|
|
151
|
-
return await isTrusted(IdentityController_getMachineId(SocketFunction.getCaller()));
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const TrustedController = SocketFunction.register(
|
|
156
|
-
"IsTrustedController-5d0b8a77-f5f7-4584-96f4-9cd88ce5d59a",
|
|
157
|
-
new IsTrustedControllerBase(),
|
|
158
|
-
() => ({
|
|
159
|
-
isTrusted: {},
|
|
160
|
-
})
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (isNode()) {
|
|
166
|
-
// We have to be trusted if we make calls to a trusted endpoint, OR our mounting
|
|
167
|
-
// (really only if we are mounting a trusted endpoint, but we don't actually know that)
|
|
168
|
-
// ONLY done on received calls, not on calls we made. If we make a call we assume that the server we called is known to us through a trusted route, and therefore, trusted.
|
|
169
|
-
requiresNetworkTrustHook.clientHook = async config => {
|
|
170
|
-
await ensureWeAreTrusted();
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
// Load the remote certificate, in the almost certain case it isn't a real certificate, and is just internal
|
|
174
|
-
SocketFunction.addGlobalClientHook(async config => {
|
|
175
|
-
await measureWrap(async function checkTrust() {
|
|
176
|
-
// IMPORTANT! We SHOULDN'T need to add our machineId before we connect, as we only check machineId on received calls, so we only need to set it before we make a call (so by the time anyone receives a call, they trust us!)
|
|
177
|
-
await ensureWeAreTrusted();
|
|
178
|
-
await loadTrustCerts(config.call.nodeId);
|
|
179
|
-
})();
|
|
180
|
-
});
|
|
1
|
+
import { measureWrap } from "socket-function/src/profiling/measure";
|
|
2
|
+
import { getIdentityCA, getMachineId, getOwnMachineId } from "../-a-auth/certs";
|
|
3
|
+
import { getArchives } from "../-a-archives/archives";
|
|
4
|
+
import { isNode, throttleFunction, timeInHour, timeInSecond } from "socket-function/src/misc";
|
|
5
|
+
import { SocketFunctionHook } from "socket-function/SocketFunctionTypes";
|
|
6
|
+
import { SocketFunction } from "socket-function/SocketFunction";
|
|
7
|
+
import { IdentityController_getMachineId } from "../-c-identity/IdentityController";
|
|
8
|
+
import { cache, lazy } from "socket-function/src/caching";
|
|
9
|
+
import { getNodeIdDomainMaybeUndefined, getNodeIdIP, getNodeIdLocation } from "socket-function/src/nodeCache";
|
|
10
|
+
import { trustCertificate } from "socket-function/src/certStore";
|
|
11
|
+
import { isClient, isServer } from "../config2";
|
|
12
|
+
import debugbreak from "debugbreak";
|
|
13
|
+
import { devDebugbreak, getDomain, isDevDebugbreak, isPublic, isRecovery } from "../config";
|
|
14
|
+
import { formatTime } from "socket-function/src/formatting/format";
|
|
15
|
+
import { runInSerial } from "socket-function/src/batching";
|
|
16
|
+
import { Querysub } from "../4-querysub/QuerysubController";
|
|
17
|
+
import { magenta } from "socket-function/src/formatting/logColors";
|
|
18
|
+
|
|
19
|
+
// Cache the untrust list, to prevent bugs from causing too many backend reads (while also allowing
|
|
20
|
+
// bad servers which make request before their trust is verified from staying broken).
|
|
21
|
+
const UNTRUST_CACHE_TIME = 30 * timeInSecond;
|
|
22
|
+
const TRUSTED_CACHE_RESET_INTERVAL = timeInHour;
|
|
23
|
+
|
|
24
|
+
const archives = lazy(() => getArchives("trust2/"));
|
|
25
|
+
|
|
26
|
+
export const requiresNetworkTrustHook: SocketFunctionHook = async config => {
|
|
27
|
+
// HACK: On the clientside we strip the domain process and machine id, so we can no longer determine
|
|
28
|
+
// who it is. So... we trust anyone. This isn't so bad, as:
|
|
29
|
+
// 1) They have to at least have an HTTPS certificate, which... most nodes should have?
|
|
30
|
+
// 2) We only really talk to nodes we discovery, and only network trusted nodes can register themselves,
|
|
31
|
+
// so... they are probably already trusted.
|
|
32
|
+
// ALSO, if in NodeJS, but acting as a client, we only connect to remote servers via
|
|
33
|
+
// HTTPS, so we know we can trust them, as their certificates are verified.
|
|
34
|
+
// - Also, if we are a client we don't really have any privileged data, except
|
|
35
|
+
// the data we send servers, which we explicitly connect to.
|
|
36
|
+
// NOTE: This also exists in isTrusted.
|
|
37
|
+
if (isClient()) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let caller = SocketFunction.getCaller();
|
|
41
|
+
if (getNodeIdIP(caller.nodeId) === "127.0.0.1" && isRecovery()) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let machineId = IdentityController_getMachineId(caller);
|
|
45
|
+
let trusted = await isTrusted(machineId);
|
|
46
|
+
if (!trusted) {
|
|
47
|
+
devDebugbreak();
|
|
48
|
+
let machineId = IdentityController_getMachineId(caller);
|
|
49
|
+
throw new Error(`Calling machine is not trusted. Caller ${machineId} is not trusted by ${SocketFunction.mountedNodeId} to make call ${config.call.classGuid}.${config.call.functionName}. To gain trust add backblaze permissions (see hasBackblazePermissions) or set --nonetwork.`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
export const assertIsNetworkTrusted = requiresNetworkTrustHook;
|
|
53
|
+
|
|
54
|
+
let lastArchivesTrusted: string[] | undefined;
|
|
55
|
+
let trustedCache = new Set<string>();
|
|
56
|
+
let untrustedCache = new Map<string, number>();
|
|
57
|
+
export const isTrusted = measureWrap(async function isTrusted(machineId: string) {
|
|
58
|
+
// See the comment in requiresNetworkTrustHook for why clients have to trust all callers.
|
|
59
|
+
if (isClient()) return true;
|
|
60
|
+
|
|
61
|
+
await populateTrustedCache();
|
|
62
|
+
|
|
63
|
+
if (trustedCache.has(machineId)) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
let untrustedTime = untrustedCache.get(machineId);
|
|
67
|
+
if (untrustedTime !== undefined && untrustedTime > Date.now()) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (machineId.includes("..")) {
|
|
72
|
+
console.warn(`Invalid machineId in isTrust call: ${machineId}`);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Checking a single entry is fast and if we don't trust them they'll be added to untrusted cache so it shouldn't slow things down by too much.
|
|
77
|
+
let trusted = await archives().get(machineId);
|
|
78
|
+
if (trusted) {
|
|
79
|
+
trustedCache.add(machineId);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!trustedCache.has(machineId)) {
|
|
83
|
+
untrustedCache.set(machineId, Date.now() + UNTRUST_CACHE_TIME);
|
|
84
|
+
return false;
|
|
85
|
+
} else {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
let populateTrustedCache = lazy(async () => {
|
|
90
|
+
let trustedMachineIds = await archives().find("");
|
|
91
|
+
lastArchivesTrusted = trustedMachineIds.slice();
|
|
92
|
+
for (let trustedMachineId of trustedMachineIds) {
|
|
93
|
+
trustedCache.add(trustedMachineId);
|
|
94
|
+
}
|
|
95
|
+
// Always trust ourself
|
|
96
|
+
trustedCache.add(getOwnMachineId());
|
|
97
|
+
|
|
98
|
+
// NOTE: This only happens to servers that we connect to. Also we only allow the machine ID to be this special ID in the case it's on our domain. And because we use HTTPS when connecting to domains, it means that it must be implicitly trusted if it has a certificate for our domain.
|
|
99
|
+
trustedCache.add("127-0-0-1");
|
|
100
|
+
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
trustedCache.clear();
|
|
103
|
+
populateTrustedCache.reset();
|
|
104
|
+
}, TRUSTED_CACHE_RESET_INTERVAL);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export async function isNodeTrusted(nodeId: string) {
|
|
108
|
+
let domainName = getNodeIdDomainMaybeUndefined(nodeId);
|
|
109
|
+
if (!domainName) return false;
|
|
110
|
+
let machineId = getMachineId(domainName);
|
|
111
|
+
return await isTrusted(machineId);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const loadServerCert = cache(async (machineId: string) => {
|
|
115
|
+
// This cert isn't stored in the archives, but... this is fine?
|
|
116
|
+
if (machineId === "127-0-0-1." + getDomain()) return;
|
|
117
|
+
let certFile = await archives().get(machineId);
|
|
118
|
+
if (!certFile) {
|
|
119
|
+
console.warn(`Could not find certificate in archives for ${machineId}`);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
console.log(magenta(`Loading certificate for ${machineId}`));
|
|
123
|
+
trustCertificate(certFile);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
export const ensureWeAreTrusted = lazy(measureWrap(async () => {
|
|
127
|
+
let machineKeyCert = getIdentityCA();
|
|
128
|
+
let machineId = getOwnMachineId();
|
|
129
|
+
if (!await archives().get(machineId)) {
|
|
130
|
+
await archives().set(machineId, machineKeyCert.cert);
|
|
131
|
+
}
|
|
132
|
+
}));
|
|
133
|
+
|
|
134
|
+
async function loadTrustCerts(nodeId: string) {
|
|
135
|
+
let location = getNodeIdLocation(nodeId);
|
|
136
|
+
if (location) {
|
|
137
|
+
let machineId = getMachineId(location.address);
|
|
138
|
+
let isTrustedBool = await isTrusted(machineId);
|
|
139
|
+
if (isTrustedBool) {
|
|
140
|
+
await loadServerCert(machineId);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export const isTrustedByNode = cache(async function isTrustedByNode(nodeId: string) {
|
|
146
|
+
return await TrustedController.nodes[nodeId].isTrusted();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
class IsTrustedControllerBase {
|
|
150
|
+
public async isTrusted() {
|
|
151
|
+
return await isTrusted(IdentityController_getMachineId(SocketFunction.getCaller()));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const TrustedController = SocketFunction.register(
|
|
156
|
+
"IsTrustedController-5d0b8a77-f5f7-4584-96f4-9cd88ce5d59a",
|
|
157
|
+
new IsTrustedControllerBase(),
|
|
158
|
+
() => ({
|
|
159
|
+
isTrusted: {},
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
if (isNode()) {
|
|
166
|
+
// We have to be trusted if we make calls to a trusted endpoint, OR our mounting
|
|
167
|
+
// (really only if we are mounting a trusted endpoint, but we don't actually know that)
|
|
168
|
+
// ONLY done on received calls, not on calls we made. If we make a call we assume that the server we called is known to us through a trusted route, and therefore, trusted.
|
|
169
|
+
requiresNetworkTrustHook.clientHook = async config => {
|
|
170
|
+
await ensureWeAreTrusted();
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// Load the remote certificate, in the almost certain case it isn't a real certificate, and is just internal
|
|
174
|
+
SocketFunction.addGlobalClientHook(async config => {
|
|
175
|
+
await measureWrap(async function checkTrust() {
|
|
176
|
+
// IMPORTANT! We SHOULDN'T need to add our machineId before we connect, as we only check machineId on received calls, so we only need to set it before we make a call (so by the time anyone receives a call, they trust us!)
|
|
177
|
+
await ensureWeAreTrusted();
|
|
178
|
+
await loadTrustCerts(config.call.nodeId);
|
|
179
|
+
})();
|
|
180
|
+
});
|
|
181
181
|
}
|