Comparing version 0.0.2 to 0.0.3
@@ -98,12 +98,3 @@ /*! | ||
NOTZONE: 10, // Name not contained in zone | ||
UNKNOWN: 15, | ||
BADSIG: 16, // TSIG Signature Failure | ||
BADVERS: 16, // Bad OPT Version | ||
BADKEY: 17, // Key not recognized | ||
BADTIME: 18, // Signature out of time window | ||
BADMODE: 19, // Bad TKEY Mode | ||
BADNAME: 20, // Duplicate key name | ||
BADALG: 21, // Algorithm not supported | ||
BADTRUNC: 22, // Bad Truncation | ||
BADCOOKIE: 23 // Bad/missing Server Cookie | ||
UNKNOWN: 15 | ||
}; | ||
@@ -129,12 +120,3 @@ | ||
[codes.NOTZONE]: 'NOTZONE', | ||
[codes.UNKNOWN]: 'UNKNOWN', | ||
[codes.BADSIG]: 'BADSIG', | ||
[codes.BADVERS]: 'BADVERS', | ||
[codes.BADKEY]: 'BADKEY', | ||
[codes.BADTIME]: 'BADTIME', | ||
[codes.BADMODE]: 'BADMODE', | ||
[codes.BADNAME]: 'BADNAME', | ||
[codes.BADALG]: 'BADALG', | ||
[codes.BADTRUNC]: 'BADTRUNC', | ||
[codes.BADCOOKIE]: 'BADCOOKIE' | ||
[codes.UNKNOWN]: 'UNKNOWN' | ||
}; | ||
@@ -417,2 +399,42 @@ | ||
/** | ||
* Extended Response Codes | ||
* @enum {Number} | ||
* @default | ||
*/ | ||
const ecodes = { | ||
NOERROR: 0, // No Error | ||
SUCCESS: 0, // No Error | ||
BADSIG: 1, // TSIG Signature Failure | ||
BADVERS: 1, // Bad OPT Version | ||
BADKEY: 2, // Key not recognized | ||
BADTIME: 3, // Signature out of time window | ||
BADMODE: 4, // Bad TKEY Mode | ||
BADNAME: 5, // Duplicate key name | ||
BADALG: 6, // Algorithm not supported | ||
BADTRUNC: 7, // Bad Truncation | ||
BADCOOKIE: 8, // Bad/missing Server Cookie | ||
UNKNOWN: 255 // Unknown | ||
}; | ||
/** | ||
* Extended Response Codes By Value | ||
* @enum {String} | ||
* @default | ||
*/ | ||
const ecodesByVal = { | ||
[ecodes.NOERROR]: 'NOERROR', | ||
[ecodes.BADVERS]: 'BADVERS', | ||
[ecodes.BADKEY]: 'BADKEY', | ||
[ecodes.BADTIME]: 'BADTIME', | ||
[ecodes.BADMODE]: 'BADMODE', | ||
[ecodes.BADNAME]: 'BADNAME', | ||
[ecodes.BADALG]: 'BADALG', | ||
[ecodes.BADTRUNC]: 'BADTRUNC', | ||
[ecodes.BADCOOKIE]: 'BADCOOKIE', | ||
[ecodes.UNKNOWN]: 'UNKNOWN' | ||
}; | ||
/** | ||
* EDNS0 Option Codes | ||
@@ -490,4 +512,6 @@ * @enum {Number} | ||
exports.eflagsByVal = eflagsByVal; | ||
exports.ecodes = ecodes; | ||
exports.ecodesByVal = ecodesByVal; | ||
exports.options = options; | ||
exports.optionsByVal = optionsByVal; | ||
exports.YEAR68 = YEAR68; |
@@ -28,3 +28,2 @@ /*! | ||
Record, | ||
Option, | ||
opcodes, | ||
@@ -253,6 +252,6 @@ classes, | ||
|| res.code === codes.SERVERFAILURE) | ||
&& (!res.isEDNS0() && req.isEDNS0())) { | ||
&& (!res.isEDNS() && req.isEDNS())) { | ||
// They don't like edns. | ||
req = req.clone(); | ||
req.unsetEDNS0(); | ||
req.unsetEDNS(); | ||
item.req = req; | ||
@@ -316,3 +315,3 @@ this.retry(item, rinfo); | ||
async query(qs, port, host, rd, opt) { | ||
async query(qs, port, host, rd) { | ||
assert(qs instanceof Question); | ||
@@ -322,3 +321,2 @@ assert(typeof port === 'number'); | ||
assert(typeof rd === 'boolean'); | ||
assert(!opt || (opt instanceof Option)); | ||
@@ -330,20 +328,16 @@ const req = new Message(); | ||
if (this.edns) { | ||
req.setEDNS0(4096, this.dnssec); | ||
if (this.edns) | ||
req.setEDNS(4096, this.dnssec); | ||
if (opt) | ||
req.setOption(opt); | ||
} | ||
return this.exchange(req, port, host); | ||
} | ||
async lookup(name, type, port, host, rd, opt) { | ||
async lookup(name, type, port, host, rd) { | ||
const qs = new Question(name, type); | ||
return this.query(qs, port, host, rd, opt); | ||
return this.query(qs, port, host, rd); | ||
} | ||
async reverse(addr, port, host, rd, opt) { | ||
async reverse(addr, port, host, rd) { | ||
const name = encoding.reverse(addr); | ||
return this.lookup(name, types.PTR, port, host, rd, opt); | ||
return this.lookup(name, types.PTR, port, host, rd); | ||
} | ||
@@ -534,7 +528,3 @@ } | ||
verify(qs, auth, opt, res) { | ||
return true; | ||
} | ||
async ask(qs, auth, opt) { | ||
async ask(qs, auth) { | ||
const {zone, port, host} = auth; | ||
@@ -548,13 +538,4 @@ const cache = this.cache.hit(qs, zone); | ||
if (auth.zone === '.') { | ||
const res = await this.query(qs, port, host, false, opt); | ||
const res = await this.query(qs, port, host, false); | ||
if (!this.verify(qs, auth, opt, res)) | ||
throw new Error('Invalid response.'); | ||
return [res, false]; | ||
} | ||
const res = await this.query(qs, port, host, false, null); | ||
return [res, false]; | ||
@@ -565,3 +546,3 @@ } | ||
const qs = new Question(name, type); | ||
const child = await this.follow(qs, rc.hops, rc.opt); | ||
const child = await this.follow(qs, rc.hops); | ||
const res = child.toAnswer(); | ||
@@ -603,4 +584,4 @@ | ||
async lookupDNSKEY(qs, auth, ds, opt) { | ||
const [res, hit] = await this.ask(qs, auth, opt); | ||
async lookupDNSKEY(qs, auth, ds) { | ||
const [res, hit] = await this.ask(qs, auth); | ||
const keyMap = new Map(); | ||
@@ -652,3 +633,3 @@ | ||
async checkSignatures(msg, auth, ds, opt) { | ||
async checkSignatures(msg, auth, ds) { | ||
if (!this.dnssec) | ||
@@ -658,3 +639,3 @@ return true; | ||
const qs = new Question(auth.zone, types.DNSKEY); | ||
const keyMap = await this.lookupDNSKEY(qs, auth, ds, opt); | ||
const keyMap = await this.lookupDNSKEY(qs, auth, ds); | ||
@@ -784,3 +765,3 @@ if (keyMap.size === 0) | ||
if (!await this.checkSignatures(rc.res, rc.auth, rc.ds, rc.opt)) { | ||
if (!await this.checkSignatures(rc.res, rc.auth, rc.ds)) { | ||
this.log('Trust chain broken due to lack of child verification.'); | ||
@@ -866,3 +847,3 @@ rc.chain = false; | ||
async lookupNext(rc) { | ||
const [res, hit] = await this.ask(rc.qs, rc.auth, rc.opt); | ||
const [res, hit] = await this.ask(rc.qs, rc.auth); | ||
rc.res = res; | ||
@@ -924,6 +905,5 @@ rc.hit = hit; | ||
async follow(qs, hops, opt) { | ||
async follow(qs, hops) { | ||
assert(qs instanceof Question); | ||
assert(typeof hops === 'number'); | ||
assert(!opt || (opt instanceof Option)); | ||
@@ -936,3 +916,3 @@ if (qs.class !== classes.INET | ||
const ns = this.randomAuthority(); | ||
const rc = new ResolveContext(qs, ns, hops, opt); | ||
const rc = new ResolveContext(qs, ns, hops); | ||
rc.chain = this.dnssec; | ||
@@ -943,4 +923,4 @@ | ||
async resolve(qs, opt) { | ||
const rc = await this.follow(qs, 0, opt); | ||
async resolve(qs) { | ||
const rc = await this.follow(qs, 0); | ||
@@ -952,10 +932,10 @@ this.log('Finishing resolving %s/%d (hops=%d).', qs.name, qs.type, rc.hops); | ||
async lookup(name, type, opt) { | ||
async lookup(name, type) { | ||
const qs = new Question(name, type); | ||
return this.resolve(qs, opt); | ||
return this.resolve(qs); | ||
} | ||
async reverse(addr, opt) { | ||
async reverse(addr) { | ||
const name = encoding.reverse(addr); | ||
return this.lookup(name, types.PTR, opt); | ||
return this.lookup(name, types.PTR); | ||
} | ||
@@ -982,7 +962,6 @@ } | ||
class ResolveContext { | ||
constructor(qs, ns, hops, opt) { | ||
constructor(qs, ns, hops) { | ||
this.question = qs; | ||
this.ns = ns; | ||
this.hops = hops; | ||
this.opt = opt || null; | ||
this.qs = qs.clone(); | ||
@@ -989,0 +968,0 @@ this.auth = ns; |
@@ -114,5 +114,2 @@ /*! | ||
// if (req.aa || req.tc || req.ra || req.z || req.ad) | ||
// throw new Error('Too many flags.'); | ||
if (req.code !== codes.NOERROR) | ||
@@ -119,0 +116,0 @@ throw new Error('Bad code.'); |
@@ -535,2 +535,22 @@ /*! | ||
util.digDate = function digDate(time) { | ||
const d = time != null ? new Date(time) : new Date(); | ||
const str = d.toString(); | ||
const parts = str.split(' '); | ||
let [ | ||
day, | ||
month, | ||
date, | ||
year, | ||
ts, | ||
, | ||
tz | ||
] = parts; | ||
tz = tz.slice(1, -1); | ||
return `${day} ${month} ${date} ${ts} ${tz} ${year}`; | ||
}; | ||
util.dir = function dir(obj) { | ||
@@ -537,0 +557,0 @@ console.dir(obj, { |
{ | ||
"name": "bns", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "DNS bike-shed", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
251010
10246