core-3nweb-client-lib 0.53.4 → 0.53.5
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { RequestFn } from "./request-utils";
|
|
2
2
|
import { DnsResolver } from "./networks";
|
|
3
|
-
export declare function dohAt(request: RequestFn<unknown>, dohServerUrl: string): DnsResolver;
|
|
3
|
+
export declare function dohAt(request: RequestFn<unknown>, dohServerUrl: string, type: 'legacy' | 'json'): DnsResolver;
|
|
4
|
+
export declare function sendLegacyDohTxtQuestion(request: RequestFn<Uint8Array>, serverUrl: string, domain: string): Promise<string[][]>;
|
package/build/lib-client/doh.js
CHANGED
|
@@ -17,26 +17,75 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.dohAt = dohAt;
|
|
20
|
+
exports.sendLegacyDohTxtQuestion = sendLegacyDohTxtQuestion;
|
|
20
21
|
const networks_1 = require("./networks");
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const Packet = require("native-node-dns-packet");
|
|
23
|
+
const buffer_utils_1 = require("../lib-common/buffer-utils");
|
|
24
|
+
function dohAt(request, dohServerUrl, type) {
|
|
25
|
+
return {
|
|
26
|
+
resolveTxt: ((type === 'legacy') ?
|
|
27
|
+
domain => sendLegacyDohTxtQuestion(request, dohServerUrl, domain) :
|
|
28
|
+
domain => sendJsonDohTxtQuestion(request, dohServerUrl, domain))
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async function sendJsonDohTxtQuestion(request, serverUrl, domain) {
|
|
32
|
+
const opts = {
|
|
33
|
+
method: 'GET',
|
|
34
|
+
url: `${serverUrl}?name=${domain}&type=TXT`,
|
|
35
|
+
requestHeaders: {
|
|
36
|
+
accept: 'application/dns-json'
|
|
37
|
+
},
|
|
38
|
+
responseType: 'json'
|
|
39
|
+
};
|
|
40
|
+
const reply = await request(opts)
|
|
41
|
+
.catch((exc) => {
|
|
42
|
+
if (exc.type === 'connect') {
|
|
43
|
+
throw { code: networks_1.CONNREFUSED, hostname: domain, cause: exc };
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw { code: networks_1.SERVFAIL, hostname: domain, cause: exc };
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const { status, data } = reply;
|
|
50
|
+
if (status !== 200) {
|
|
51
|
+
throw {
|
|
52
|
+
code: networks_1.SERVFAIL, hostname: domain,
|
|
53
|
+
message: `status ${reply.status} from DoH server`
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (data.Status !== 0) {
|
|
57
|
+
throw { code: networks_1.NOTFOUND, hostname: domain };
|
|
58
|
+
}
|
|
59
|
+
if (data.Answer) {
|
|
24
60
|
let txt = [];
|
|
25
|
-
for (const { data: line } of
|
|
61
|
+
for (const { data: line } of data.Answer) {
|
|
26
62
|
txt.push([line]);
|
|
27
63
|
}
|
|
28
64
|
return txt;
|
|
29
65
|
}
|
|
30
|
-
|
|
66
|
+
else {
|
|
67
|
+
throw { code: networks_1.NODATA, hostname: domain };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function packB64TxtDnsQuestionPacket(domain) {
|
|
71
|
+
const questionPack = new Packet();
|
|
72
|
+
questionPack.question.push({ name: domain, type: 16, class: 1 });
|
|
73
|
+
const buf = Buffer.alloc(500);
|
|
74
|
+
const len = Packet.write(buf, questionPack);
|
|
75
|
+
return buffer_utils_1.base64urlSafe.pack(buf.subarray(0, len));
|
|
76
|
+
}
|
|
77
|
+
function unpackDnsAnswerPacket(data) {
|
|
78
|
+
return Packet.parse((0, buffer_utils_1.toBuffer)(data));
|
|
31
79
|
}
|
|
32
|
-
async function
|
|
80
|
+
async function sendLegacyDohTxtQuestion(request, serverUrl, domain) {
|
|
81
|
+
const dnsPacketInB64 = packB64TxtDnsQuestionPacket(domain);
|
|
33
82
|
const opts = {
|
|
34
83
|
method: 'GET',
|
|
35
|
-
url: `${serverUrl}?
|
|
84
|
+
url: `${serverUrl}?dns=${dnsPacketInB64}`,
|
|
36
85
|
requestHeaders: {
|
|
37
|
-
accept: 'application/dns-
|
|
86
|
+
accept: 'application/dns-message'
|
|
38
87
|
},
|
|
39
|
-
responseType: '
|
|
88
|
+
responseType: 'arraybuffer'
|
|
40
89
|
};
|
|
41
90
|
const reply = await request(opts)
|
|
42
91
|
.catch((exc) => {
|
|
@@ -54,11 +103,12 @@ async function sendDohQuestion(request, serverUrl, domain, type) {
|
|
|
54
103
|
message: `status ${reply.status} from DoH server`
|
|
55
104
|
};
|
|
56
105
|
}
|
|
57
|
-
|
|
106
|
+
const answerPacket = unpackDnsAnswerPacket(data);
|
|
107
|
+
if (answerPacket.header.rcode !== 0) {
|
|
58
108
|
throw { code: networks_1.NOTFOUND, hostname: domain };
|
|
59
109
|
}
|
|
60
|
-
if (
|
|
61
|
-
return data
|
|
110
|
+
if (answerPacket.answer.length > 0) {
|
|
111
|
+
return answerPacket.answer.map(({ data }) => data);
|
|
62
112
|
}
|
|
63
113
|
else {
|
|
64
114
|
throw { code: networks_1.NODATA, hostname: domain };
|
|
@@ -20,6 +20,9 @@ exports.makeRequestFromNode = makeRequestFromNode;
|
|
|
20
20
|
const https = require("https");
|
|
21
21
|
const http = require("http");
|
|
22
22
|
const request_utils_1 = require("../lib-client/request-utils");
|
|
23
|
+
// XXX
|
|
24
|
+
// we need a request that uses http2, connected to some host:port, relying on downstream
|
|
25
|
+
// making NetClient requester for every host:port.
|
|
23
26
|
function makeRequestFromNode(getAgent) {
|
|
24
27
|
const nodeHttpsRequest = (opts) => https.request(opts);
|
|
25
28
|
const nodeHttpRequest = (opts) => http.request(opts);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "core-3nweb-client-lib",
|
|
3
|
-
"version": "0.53.
|
|
3
|
+
"version": "0.53.5",
|
|
4
4
|
"description": "3NWeb client core library, embeddable into different environments",
|
|
5
5
|
"main": "build/lib-index.js",
|
|
6
6
|
"types": "build/lib-index.d.ts",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"license": "GPL-3.0-or-later",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"ecma-nacl-cryptors": "^1.0.1",
|
|
39
|
+
"native-node-dns-packet": "^0.1.5",
|
|
39
40
|
"protobufjs": "^7.5.5",
|
|
40
41
|
"punycode": "^2.1.1",
|
|
41
42
|
"rxjs": "^7.5.7",
|