started fixing format to match native dns. Spotted bug in unpacking labels. Not fixed yet
This commit is contained in:
parent
59d27abafa
commit
087dc9555d
|
@ -0,0 +1,11 @@
|
||||||
|
/* style page for DNS demo*/
|
||||||
|
|
||||||
|
|
||||||
|
input {
|
||||||
|
|
||||||
|
|
||||||
|
width: 50%;
|
||||||
|
height: 150px;
|
||||||
|
padding: 12px 20px;
|
||||||
|
|
||||||
|
}
|
28
demo.html
28
demo.html
|
@ -1,5 +1,9 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>DNS Parser Demo</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="demo.css">
|
||||||
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
|
@ -11,6 +15,25 @@
|
||||||
<!-- run `serve-https` to test at https://localhost.daplie.me:8443/demo.html -->
|
<!-- run `serve-https` to test at https://localhost.daplie.me:8443/demo.html -->
|
||||||
|
|
||||||
<!-- put form here -->
|
<!-- put form here -->
|
||||||
|
<form action="inputdata">
|
||||||
|
|
||||||
|
base64:<br>
|
||||||
|
<input type="textarea" name="base64" value="">
|
||||||
|
<br>
|
||||||
|
|
||||||
|
urlsafe base64:<br>
|
||||||
|
<input type="textarea" name="urlsafe base64" value="">
|
||||||
|
<br>
|
||||||
|
|
||||||
|
hex:<br>
|
||||||
|
<input type="textarea" name="hex" value="">
|
||||||
|
<br>
|
||||||
|
<!--
|
||||||
|
JSON (Uint8Array):<br>
|
||||||
|
<output type="text" name="hex" value="">
|
||||||
|
<br>-->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- I added some of the library files for you -->
|
<!-- I added some of the library files for you -->
|
||||||
<script src="./dns.types.js"></script>
|
<script src="./dns.types.js"></script>
|
||||||
|
@ -21,10 +44,13 @@
|
||||||
<script src="./dns.parser.js"></script>
|
<script src="./dns.parser.js"></script>
|
||||||
<script src="./dns.packer.js"></script>
|
<script src="./dns.packer.js"></script>
|
||||||
<script src="./dns.js"></script>
|
<script src="./dns.js"></script>
|
||||||
|
<script src="./browser.js"></script>
|
||||||
|
|
||||||
<!-- put jquery here -->
|
<!-- put jquery here -->
|
||||||
|
|
||||||
<!-- application code in here -->
|
<!-- application code in here -->
|
||||||
<script src="./browser.js"></script>
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
10
dns.js
10
dns.js
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
var Parser = (exports.DNS_PARSER || require('./dns.parser.js').DNS_PARSER);
|
var Parser = (exports.DNS_PARSER || require('./dns.parser.js').DNS_PARSER);
|
||||||
var Packer = (exports.DNS_PACKER || require('./dns.packer.js').DNS_PACKER);
|
var Packer = (exports.DNS_PACKER || require('./dns.packer.js').DNS_PACKER);
|
||||||
|
var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES;
|
||||||
|
var types = exports.DNS_TYPES || require('./dns.types.js').DNS_TYPES;
|
||||||
exports.DNSPacket = {
|
exports.DNSPacket = {
|
||||||
parse: function (nb) {
|
parse: function (nb) {
|
||||||
// backwards compat with node buffer
|
// backwards compat with node buffer
|
||||||
|
@ -14,11 +15,10 @@ exports.DNSPacket = {
|
||||||
var packet = Parser.unpack(ab);
|
var packet = Parser.unpack(ab);
|
||||||
|
|
||||||
function tryParseRdata(record) {
|
function tryParseRdata(record) {
|
||||||
record.data = null;
|
|
||||||
record.error = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
record.data = Parser.unpackRdata(ab, packet, record);
|
|
||||||
|
record = Parser.unpackRdata(ab, packet, record);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[Error] unpackRdata: ' + e.message);
|
console.error('[Error] unpackRdata: ' + e.message);
|
||||||
record.error = e;
|
record.error = e;
|
||||||
|
|
|
@ -106,8 +106,8 @@ pdns.unpack = function (ab) {
|
||||||
q.className = classes[q.class];
|
q.className = classes[q.class];
|
||||||
q.typeName = types[q.type];
|
q.typeName = types[q.type];
|
||||||
|
|
||||||
console.log('*********************');
|
// console.log('*********************');
|
||||||
console.log(q.typeName);
|
// console.log(q.typeName);
|
||||||
|
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
@ -157,8 +157,8 @@ pdns.unpack = function (ab) {
|
||||||
|
|
||||||
// TODO actually parse RDATA
|
// TODO actually parse RDATA
|
||||||
q.rdstart = total;
|
q.rdstart = total;
|
||||||
console.log('q.rdata', q.rdlength, 'bytes:');
|
// console.log('q.rdata', q.rdlength, 'bytes:');
|
||||||
console.log(new Uint8Array(ab).slice(total, total + q.rdlength));
|
// console.log(new Uint8Array(ab).slice(total, total + q.rdlength));
|
||||||
//q.rdata = Array.prototype.slice.apply(q.rdata);
|
//q.rdata = Array.prototype.slice.apply(q.rdata);
|
||||||
|
|
||||||
//q.rdend = q.rdstart + q.rdlength;
|
//q.rdend = q.rdstart + q.rdlength;
|
||||||
|
|
|
@ -37,6 +37,9 @@ exports.DNS_RDATA_PARSE = function (ab, packet, record) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: record will be modified
|
||||||
|
// Things that get added include:
|
||||||
|
// address, data, priority exchange, weight,
|
||||||
return parser(ab, packet, record);
|
return parser(ab, packet, record);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
exports.DNS_TYPE_A = function (ab, packet, record) {
|
exports.DNS_TYPE_A = function (ab, packet, record) {
|
||||||
var ui8 = new Uint8Array(ab.slice(record.rdstart, record.rdstart + record.rdlength));
|
var ui8 = new Uint8Array(ab.slice(record.rdstart, record.rdstart + record.rdlength));
|
||||||
// i.e. 127.0.0.1
|
// i.e. 127.0.0.1
|
||||||
|
record.address = ui8[0] + '.' + ui8[1] + '.' + ui8[2] + '.' + ui8[3];
|
||||||
|
|
||||||
return ui8[0] + '.' + ui8[1] + '.' + ui8[2] + '.' + ui8[3];
|
return record;
|
||||||
};
|
};
|
||||||
|
|
||||||
}('undefined' !== typeof window ? window : exports));
|
}('undefined' !== typeof window ? window : exports));
|
||||||
|
|
|
@ -27,7 +27,8 @@ exports.DNS_TYPE_AAAA = function (ab, packet, record) {
|
||||||
s += dv.getUint16(i, false).toString(16);
|
s += dv.getUint16(i, false).toString(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
record.address = s;
|
||||||
|
return record;
|
||||||
};
|
};
|
||||||
|
|
||||||
}('undefined' !== typeof window ? window : exports));
|
}('undefined' !== typeof window ? window : exports));
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS;
|
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS;
|
||||||
exports.DNS_TYPE_CNAME = function (ab, packet, record) {
|
exports.DNS_TYPE_CNAME = function (ab, packet, record) {
|
||||||
return unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
record.data = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
||||||
|
return record;
|
||||||
};
|
};
|
||||||
|
|
||||||
}('undefined' !== typeof window ? window : exports));
|
}('undefined' !== typeof window ? window : exports));
|
||||||
|
|
|
@ -15,10 +15,10 @@ exports.DNS_TYPE_MX = function (ab, packet, record) {
|
||||||
var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength);
|
var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength);
|
||||||
var dv = new DataView(rdataAb);
|
var dv = new DataView(rdataAb);
|
||||||
|
|
||||||
return {
|
record.priority = dv.getUint16(0, false);
|
||||||
priority: dv.getUint16(0, false)
|
record.exchange = unpackLabels(new Uint8Array(ab), record.rdstart+2, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
||||||
, exchange: unpackLabels(new Uint8Array(ab), record.rdstart+2, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name
|
|
||||||
};
|
return record;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@ var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js'
|
||||||
|
|
||||||
|
|
||||||
exports.DNS_TYPE_NS = function (ab , packet, record) {
|
exports.DNS_TYPE_NS = function (ab , packet, record) {
|
||||||
|
record.data = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
||||||
return unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
return record;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS;
|
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS;
|
||||||
exports.DNS_TYPE_PTR = function (ab, pack, record) {
|
exports.DNS_TYPE_PTR = function (ab, pack, record) {
|
||||||
|
record.data = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
||||||
return unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
return record;
|
||||||
};
|
};
|
||||||
}('undefined' !== typeof window ? window : exports));
|
}('undefined' !== typeof window ? window : exports));
|
||||||
|
|
|
@ -11,31 +11,13 @@ exports.DNS_TYPE_SRV = function (ab, packet, record) {
|
||||||
|
|
||||||
var rdataAb = ab.slice(record.rdstart,record.rdstart + record.rdlength)
|
var rdataAb = ab.slice(record.rdstart,record.rdstart + record.rdlength)
|
||||||
var dv = new DataView(rdataAb);
|
var dv = new DataView(rdataAb);
|
||||||
// var string = '';
|
|
||||||
// var data = '';
|
|
||||||
// for (var i = 0; i < dv.byteLength; i+=1){
|
|
||||||
// data = dv.getUint8(i, false);
|
|
||||||
|
|
||||||
// string = String.fromCharCode(data);
|
record.priority = dv.getUint16(0, false);
|
||||||
// console.log("data at index " + i + " is " + string);
|
record.weight = dv.getUint16(2, false);
|
||||||
// }
|
record.port = dv.getUint16(4, false);
|
||||||
|
record.target = unpackLabels(new Uint8Array(ab), record.rdstart+6, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
||||||
console.log("***************************");
|
|
||||||
console.log("printing dataView!!!");
|
return record;
|
||||||
for (var i = 0; i < dv.byteLength; i+=1) {
|
|
||||||
|
|
||||||
console.log(dv.getUint8(i, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
var s = {
|
|
||||||
priority: dv.getUint16(0, false)
|
|
||||||
, weight: dv.getUint16(2, false)
|
|
||||||
, port: dv.getUint16(4, false)
|
|
||||||
, target: unpackLabels(new Uint8Array(ab), record.rdstart+6, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return s;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}('undefined' !== typeof window ? window : exports));
|
}('undefined' !== typeof window ? window : exports));
|
||||||
|
|
|
@ -5,11 +5,30 @@
|
||||||
// with a host or other name, such as a human readable information about a server
|
// with a host or other name, such as a human readable information about a server
|
||||||
// network, data center, and other accounting information.
|
// network, data center, and other accounting information.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS;
|
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS;
|
||||||
|
|
||||||
exports.DNS_TYPE_TXT = function (ab, pack, record) {
|
exports.DNS_TYPE_TXT = function (ab, packet, record) {
|
||||||
return unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
|
||||||
|
|
||||||
|
var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength);
|
||||||
|
console.log(rdataAb);
|
||||||
|
var dv = new DataView(rdataAb);
|
||||||
|
// var d = '';
|
||||||
|
// var string = '';
|
||||||
|
// for (var i = 0; i < dv.byteLength; i+= 1){
|
||||||
|
|
||||||
|
// d = dv.getUint8(i, false);
|
||||||
|
// string = String.fromCharCode(d);
|
||||||
|
// console.log("data at: " + i + " is: " + string);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
record.data = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
||||||
|
|
||||||
|
var l = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' });
|
||||||
|
|
||||||
|
console.log("labels: " + JSON.stringify(l));
|
||||||
|
return record;
|
||||||
};
|
};
|
||||||
}('undefined' !== typeof window ? window : exports));
|
}('undefined' !== typeof window ? window : exports));
|
||||||
|
|
|
@ -18,8 +18,13 @@ exports.DNS_UNPACK_LABELS = function (ui8, ptr, q) {
|
||||||
var label = [];
|
var label = [];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
console.log("total: " + total);
|
||||||
label.length = 0;
|
label.length = 0;
|
||||||
len = ui8[total];
|
len = ui8[total];
|
||||||
|
console.log("len: " + len);
|
||||||
|
if (len === undefined){
|
||||||
|
console.log("error!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
}
|
||||||
if (0xc0 === len) {
|
if (0xc0 === len) {
|
||||||
var cpptr = ui8[total + 1];
|
var cpptr = ui8[total + 1];
|
||||||
|
|
||||||
|
@ -27,6 +32,8 @@ exports.DNS_UNPACK_LABELS = function (ui8, ptr, q) {
|
||||||
ptr = cpptr;
|
ptr = cpptr;
|
||||||
q.cpcount += 1;
|
q.cpcount += 1;
|
||||||
q.byteLength += 2; // cp and len
|
q.byteLength += 2; // cp and len
|
||||||
|
|
||||||
|
// recursion
|
||||||
return exports.DNS_UNPACK_LABELS(ui8, ptr, q);
|
return exports.DNS_UNPACK_LABELS(ui8, ptr, q);
|
||||||
}
|
}
|
||||||
//str.length = 0; // fast empty array
|
//str.length = 0; // fast empty array
|
||||||
|
@ -40,12 +47,17 @@ exports.DNS_UNPACK_LABELS = function (ui8, ptr, q) {
|
||||||
total += 1;
|
total += 1;
|
||||||
// TODO check url-allowable characters
|
// TODO check url-allowable characters
|
||||||
label.push(String.fromCharCode(ui8[total]));
|
label.push(String.fromCharCode(ui8[total]));
|
||||||
|
console.log("pushed (ui8) " + ui8[total] + " to labels at i = " + i);
|
||||||
|
console.log("in char: " + String.fromCharCode(ui8[total]));
|
||||||
}
|
}
|
||||||
if (label.length) {
|
if (label.length) {
|
||||||
|
|
||||||
|
console.log("pushed a label " + q.labels + " at index " + i);
|
||||||
|
|
||||||
q.labels.push(label.join(''));
|
q.labels.push(label.join(''));
|
||||||
}
|
}
|
||||||
total += 1;
|
total += 1;
|
||||||
//console.log('total', total, ui8[total], String.fromCharCode(ui8[total]));
|
// console.log('total', total, ui8[total], String.fromCharCode(ui8[total]));
|
||||||
} while (len);
|
} while (len);
|
||||||
|
|
||||||
//str.pop(); // remove trailing '.'
|
//str.pop(); // remove trailing '.'
|
||||||
|
@ -54,7 +66,7 @@ exports.DNS_UNPACK_LABELS = function (ui8, ptr, q) {
|
||||||
if (0 === q.cpcount) {
|
if (0 === q.cpcount) {
|
||||||
q.byteLength = total - ptr;
|
q.byteLength = total - ptr;
|
||||||
}
|
}
|
||||||
|
console.log("returning q! " + JSON.stringify(q));
|
||||||
return q;
|
return q;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue