Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
chakram.resolve = function (name, type) {
var deferred = Q.defer();
var buf = packet.encode({
type: 'query',
id: nextId,
questions: [{
type: type,
class: 'IN',
name: name
}]
});
// FIXME contacting nslord for DNS responses. This can changed to nsmaster as soon as changes to the DNS are applied
// immediately, i.e. before pdns HTTP responses return to the API.
socket.send(buf, 0, buf.length, 53, process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.129');
inflight[nextId] = deferred;
nextId = (nextId + 1) % 65536; // We don't care if id's are predictable in our test setting
return deferred.promise;
questions: requestPacket.questions,
answers: [{
type: question.type,
class: 'IN',
name: question.name,
data: question.type === 'A' ? '127.0.0.1' : '::1',
ttl: 600
}]
}
} else {
// Update the request packet to do a different host
log('Proxying requested DNS name to: ', conf.proxyDnsTo)
const origName = question.name
requestPacket.questions.forEach(q => q.name = conf.proxyDnsTo)
// Send it off
const proxiedResponse = await deferToDnsFallback(request, dnsPacket.encode(requestPacket).buffer)
// Change any response names back
responsePacket = dnsPacket.decode(Buffer.from(new Uint8Array(await proxiedResponse.arrayBuffer())))
responsePacket.questions.forEach(q => {
if (q.name === conf.proxyDnsTo) q.name = origName
})
responsePacket.answers.forEach(a => {
if (a.name === conf.proxyDnsTo) a.name = origName
})
}
// Send the response back
const responseBody = dnsPacket.encode(responsePacket).buffer
if (conf.log) logDnsPacket('Response DNS (custom): ', dnsPacket.decode(Buffer.from(new Uint8Array(responseBody))))
return new Response(dnsPacket.encode(responsePacket).buffer, {
status: 200,
headers: { 'Content-Type': 'application/dns-message' }
function dohBinary (key, callback) {
const cid = new Cid(key.slice(ipns.namespaceLength))
const buf = dnsPacket.encode({
type: 'query',
id: getRandomInt(1, 65534),
flags: dnsPacket.RECURSION_DESIRED,
questions: [{
type: 'TXT',
name: `${cid.toV1().toString()}.dns.ipns.dev`
}]
})
// https://dns.google.com/experimental
// https://cloudflare-dns.com/dns-query
// https://mozilla.cloudflare-dns.com/dns-query
ky
.get('https://cloudflare-dns.com/dns-query', {
searchParams: {
dns: buf.toString('base64')
},
function spoof () {
const query = dnsPacket.encode({
type: 'query',
questions: [{
type: 'A',
name: domain
}]
})
const stream = sendQuery(query)
stream.on('error', (error) => {
console.error(`Worker ${threadId}: spoofed query failed - ${error.message}`)
stream.close()
})
stream.resume()
}
const random = Math.random()
async function dohBinary (url, domain, key) {
const start = Date.now()
const keyStr = keyToBase32(key)
const buf = dnsPacket.encode({
type: 'query',
questions: [{
type: 'TXT',
name: `${keyStr}.${domain}`
}]
})
const result = await ky
.get(url, {
searchParams: {
dns: buf.toString('base64')
},
headers: {
accept: 'application/dns-message'
}
})
cb(new Error('Socket destroyed'))
return 0
}
this.inflight++
query.type = 'query'
query.flags = typeof query.flags === 'number' ? query.flags : DNS.RECURSION_DESIRED
const id = this._getNextEmptyId()
if (id === -1) {
cb(new Error('Query array is full!'))
return 0
}
query.id = id + 1
const buffer = packet.encode(query)
this._queries[id] = {
callback: cb || noop,
redirects: 0,
firstTry: Date.now(),
query: query,
tries: 0,
buffer: buffer,
port: port,
host: host
}
this.socket.send(buffer, 0, buffer.length, port, Array.isArray(host) ? host[Math.floor(host.length * Math.random())] : host || '127.0.0.1')
return id
}
function onbind (err) {
if (destroyed) return cb()
if (err) return cb(err)
var message = packet.encode(value)
socket.send(message, 0, message.length, rinfo.port, rinfo.address || rinfo.host, cb)
}
}
cb(new Error('Socket destroyed'))
return 0
}
this.inflight++
query.type = 'query'
query.flags = typeof query.flags === 'number' ? query.flags : DNS.RECURSION_DESIRED
const id = this._getNextEmptyId()
if (id === -1) {
cb(new Error('Query array is full!'))
return 0
}
query.id = id + 1
const buffer = packet.encode(query)
this._queries[id] = {
callback: cb || noop,
redirects: 0,
firstTry: Date.now(),
query: query,
tries: 0,
buffer: buffer,
port: port,
host: host
}
this.socket.send(buffer, 0, buffer.length, port, Array.isArray(host) ? host[Math.floor(host.length * Math.random())] : host || '127.0.0.1')
return id
}