Adds DoH capabilities

This commit is contained in:
Pierre Lannoy 2023-12-13 19:16:22 +01:00
commit 919607ecf3
Signed by: Pierre Lannoy
GPG key ID: D27231EF87D53F31

View file

@ -48,7 +48,7 @@ export async function ensureDir(dir) {
* @param {string} value
*/
const parseTxtRecordData = (value) => {
throw new Error(value);
//throw new Error(value);
const result = {};
for (const part of value.split(';')) {
const [key, ...value] = part.split('=');
@ -66,27 +66,6 @@ const parseTxtRecordData = (value) => {
export async function findTxtRecord(host) {
const resolver = new DohResolver('https://doh.hosterra.tech/dns-query');
const resolved = await resolver.query( '_.' + host );
/*resolver.query( host)
.then(response => {
response.answers.forEach(ans => {
throw new Error(ans)
const txtData = parseTxtRecordData(ans.data);
if (txtData[recordParamDestUrl]) {
throw new Error(txtData[recordParamDestUrl])
return {
url: txtData[recordParamDestUrl],
httpStatus: txtData[recordParamHttpStatus],
};
}
});
})
.catch(throw new Error(err));*/
//console.log(resolved);
//throw new Error(JSON.stringify(resolved));
if (resolved.answers) {
for (const head of resolved.answers) {
const txtData = parseTxtRecordData(head.data);
@ -97,26 +76,6 @@ export async function findTxtRecord(host) {
};
}
}
/*resolver.query( host)
.then(response => {
response.answers.forEach(ans => console.log(ans.data));
})
.catch(err => console.error(err));
const resolve = await request(`https://dns.google/resolve?name=_.${encodeURIComponent(host)}&type=TXT`);
if (resolve.data.Answer) {
for (const head of resolve.data.Answer) {
const txtData = parseTxtRecordData(head.data);
if (!txtData[recordParamDestUrl]) continue;
return {
url: txtData[recordParamDestUrl],
httpStatus: txtData[recordParamHttpStatus],
};
}
}*/
return null;
}