This repository was archived by the owner on Dec 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdnsResponseBlock.js
More file actions
113 lines (109 loc) · 3.61 KB
/
dnsResponseBlock.js
File metadata and controls
113 lines (109 loc) · 3.61 KB
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
/*
* Copyright (c) 2021 RethinkDNS and its authors.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import DNSBlockOperation from "./dnsBlockOperation.js";
export default class DNSResponseBlock {
constructor() {
this.dnsBlockOperation = new DNSBlockOperation();
}
/**
* @param {*} param
* @param {*} param.userBlocklistInfo
* @param {*} param.blocklistFilter
* @param {DnsDecodedObject} param.responseDecodedDnsPacket
* @returns
*/
async RethinkModule(param) {
let response = {};
response.isException = false;
response.exceptionStack = "";
response.exceptionFrom = "";
response.data = {};
response.data.isBlocked = false;
response.data.blockedB64Flag = "";
try {
if (param.userBlocklistInfo.userBlocklistFlagUint !== "") {
if (
param.responseDecodedDnsPacket.answers.length > 0 &&
param.responseDecodedDnsPacket.answers[0].type == "CNAME"
) {
checkCnameBlock(param, response, this.dnsBlockOperation);
} else if (
param.responseDecodedDnsPacket.answers.length > 0 &&
(param.responseDecodedDnsPacket.answers[0].type == "HTTPS" ||
param.responseDecodedDnsPacket.answers[0].type == "SVCB")
) {
checkHttpsSvcbBlock(param, response, this.dnsBlockOperation);
}
}
} catch (e) {
response.isException = true;
response.exceptionStack = e.stack;
response.exceptionFrom = "DNSResponseBlock RethinkModule";
console.error("Error At : DNSResponseBlock -> RethinkModule");
console.error(e.stack);
}
return response;
}
}
function checkHttpsSvcbBlock(
param,
response,
dnsBlockOperation,
) {
let targetName = param.responseDecodedDnsPacket.answers[0].data.targetName.trim()
.toLowerCase();
if (targetName != ".") {
let domainNameBlocklistInfo = param.blocklistFilter.getDomainInfo(
targetName,
);
if (domainNameBlocklistInfo.searchResult) {
response.data = dnsBlockOperation.checkDomainBlocking(
param.userBlocklistInfo.userBlocklistFlagUint,
param.userBlocklistInfo.userServiceListUint,
param.userBlocklistInfo.flagVersion,
domainNameBlocklistInfo.searchResult,
param.blocklistFilter,
targetName
);
}
}
}
function checkCnameBlock(param, response, dnsBlockOperation) {
let cname = param.responseDecodedDnsPacket.answers[0].data.trim().toLowerCase();
let domainNameBlocklistInfo = param.blocklistFilter.getDomainInfo(
cname,
);
if (domainNameBlocklistInfo.searchResult) {
response.data = dnsBlockOperation.checkDomainBlocking(
param.userBlocklistInfo.userBlocklistFlagUint,
param.userBlocklistInfo.userServiceListUint,
param.userBlocklistInfo.flagVersion,
domainNameBlocklistInfo.searchResult,
param.blocklistFilter,
cname
);
}
if (!response.data.isBlocked) {
cname = param.responseDecodedDnsPacket
.answers[param.responseDecodedDnsPacket.answers.length - 1].name.trim()
.toLowerCase();
domainNameBlocklistInfo = param.blocklistFilter.getDomainInfo(
cname,
);
if (domainNameBlocklistInfo.searchResult) {
response.data = dnsBlockOperation.checkDomainBlocking(
param.userBlocklistInfo.userBlocklistFlagUint,
param.userBlocklistInfo.userServiceListUint,
param.userBlocklistInfo.flagVersion,
domainNameBlocklistInfo.searchResult,
param.blocklistFilter,
cname
);
}
}
}