-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.js
220 lines (127 loc) · 6.04 KB
/
block.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
const { password, needToSetPassword, wrongPass } = require("../password");
const {
String,
StringMatch,
} = require("../_data/primordials");
const { wrongPassEmitter } = require("../logs");
const { whiteList } = require("./addToWhiteList");
const tls = require("tls");
const net = require("net");
const http = require("http");
const http2 = require("http2");
const https = require("https");
const _tls_wrap = require("_tls_wrap");
const _http_agent = require("_http_agent");
const _http_client = require("_http_client");
const {
$tls,
$net,
$http,
$https,
$http2,
_tls,
_httpAgent,
_httpClient,
} = require("./store");
const integrateToFns = require("../integrateFunctionality/toFns");
const integrateToObject = require("../integrateFunctionality/toObject");
const integrateToProtoFn = require("../integrateFunctionality/toProtoFn");
function integrateToTls(tryPass, fullBlock) {
if(password.value === null) throw new Error(needToSetPassword);
if(tryPass != password.value) return wrongPassEmitter(wrongPass, "blockTls", { fullBlock });
if($tls.status == true) return false;
integrateToFns(whiteList, ["connect"], tls, $tls, ["https.js", "internal/http2/core.js"], fullBlock);
if( !StringMatch( String(tls.TLSSocket.prototype.connect), /\/\/NODE-RULES-SYSTEM-SIGNATURE/ ) ) {
integrateToProtoFn(whiteList, "connect", tls.TLSSocket, $tls, "socketProtoConnect", ["net.js", "_tls_wrap.js", "https.js"], fullBlock);
}
return $tls.status = true;
}
function integrateToTlsWrap(tryPass, fullBlock) {
if (password.value === null) throw new Error(needToSetPassword);
if(tryPass != password.value) return wrongPassEmitter(wrongPass, "blockTlsWrap", { fullBlock });
if (_tls.status == true) return false;
integrateToFns(whiteList, ["connect"], _tls_wrap, _tls, ["https.js", "internal/http2/core.js"], fullBlock);
if( !StringMatch( String(_tls_wrap.TLSSocket.prototype.connect), /\/\/NODE-RULES-SYSTEM-SIGNATURE/ ) ) {
integrateToProtoFn(whiteList, "connect", _tls_wrap.TLSSocket, _tls, "socketProtoConnect", ["net.js", "_tls_wrap.js", "https.js"], fullBlock);
}
return _tls.status = true;
}
function integrateToNet(tryPass, fullBlock) {
if(password.value === null) throw new Error(needToSetPassword);
if(tryPass != password.value) return wrongPassEmitter(wrongPass, "blockNet", { fullBlock });
if($net.status == true) return false;
integrateToFns(whiteList, ["connect", "createConnection", "createQuicSocket"], net, $net, ["internal/http2/core.js"], fullBlock);
integrateToProtoFn(whiteList, "connect", net.Socket, $net, "SocketPrototypeConnect", ["net.js", "_tls_wrap.js"], fullBlock);
if( !StringMatch( String(net.Stream.prototype.connect), /\/\/NODE-RULES-SYSTEM-SIGNATURE/ ) ) {
integrateToProtoFn(whiteList, "connect", net.Stream, $net, "StreamPrototypeConnect", ["net.js", "_tls_wrap.js"], fullBlock);
}
return $net.status = true;
}
function integrateToHttpAgent(tryPass, fullBlock) {
if(password.value === null) throw new Error(needToSetPassword);
if(tryPass != password.value) return wrongPassEmitter(wrongPass, "blockHttpAgent", { fullBlock });
if(_httpAgent.status == true) return false;
integrateToFns(whiteList, ["Agent"], _http_agent, _httpAgent, [], fullBlock);
if($http.status == false) {
integrateToObject(whiteList, "globalAgent", _http_agent, _httpAgent, ["_http_client.js", "_http_agent.js", "util.js", "internal/util.js"], fullBlock);
} else {
_httpAgent.globalAgent = $http.globalAgent;
}
return _httpAgent.status = true;
}
function integrateToHttpClient(tryPass, fullBlock) {
if(password.value === null) throw new Error(needToSetPassword);
if(tryPass != password.value) return wrongPassEmitter(wrongPass, "blockHttpClient", { fullBlock });
if(_httpClient.status == true) return false;
integrateToFns(whiteList, ["ClientRequest"], _http_client, _httpClient, [], fullBlock);
return _httpClient.status = true;
}
function integrateToHttp(tryPass, fullBlock) {
if(password.value === null) throw new Error(needToSetPassword);
if(tryPass != password.value) return wrongPassEmitter(wrongPass, "blockHttp", { fullBlock });
if($http.status == true) return false;
integrateToFns(whiteList, ["Agent", "ClientRequest", "get", "request", "Client", "createClient"], http, $http, [], fullBlock);
integrateToObject(whiteList, "globalAgent", http, $http, ["_http_client.js", "_http_agent.js", "util.js", "internal/util.js"], fullBlock);
return $http.status = true;
}
function integrateToHttps(tryPass, fullBlock) {
if(password.value === null) throw new Error(needToSetPassword);
if(tryPass != password.value) return wrongPassEmitter(wrongPass, "blockHttps", { fullBlock });
if($https.status == true) return false;
integrateToFns(whiteList, ["Agent", "get", "request"], https, $https, [], fullBlock);
integrateToObject(whiteList, "globalAgent", https, $https, ["_http_client.js", "_http_agent.js", "_https.js", "https.js", "util.js", "internal/util.js"], fullBlock);
return $https.status = true;
}
function integrateToHttp2(tryPass, fullBlock) {
if(password.value === null) throw new Error(needToSetPassword);
if(tryPass != password.value) return wrongPassEmitter(wrongPass, "blockHttp2", { fullBlock });
if($http2.status == true) return false;
integrateToFns(whiteList, ["connect"], http2, $http2, [], fullBlock);
return $http2.status = true;
}
function blockConnections(tryPass, fullBlock) {
if(password.value === null) throw new Error(needToSetPassword);
if(tryPass != password.value) return wrongPassEmitter(wrongPass, "blockConnections", { fullBlock });
const result = [
integrateToNet(tryPass, fullBlock),
integrateToHttp(tryPass, fullBlock),
integrateToHttps(tryPass, fullBlock),
integrateToHttp2(tryPass, fullBlock),
integrateToHttpAgent(tryPass, fullBlock),
integrateToHttpClient(tryPass, fullBlock),
integrateToTls(tryPass, fullBlock),
integrateToTlsWrap(tryPass, fullBlock),
];
return result;
}
module.exports = {
integrateToNet,
integrateToHttp,
integrateToHttps,
integrateToHttp2,
integrateToHttpAgent,
integrateToHttpClient,
integrateToTls,
integrateToTlsWrap,
blockConnections,
};