v1.2.13: update docs

This commit is contained in:
AJ ONeal 2019-10-19 23:52:59 -06:00
parent 092008f766
commit 1321e5170b
12 changed files with 829 additions and 410 deletions

8
.prettierrc Normal file
View File

@ -0,0 +1,8 @@
{
"bracketSpacing": true,
"printWidth": 80,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "none",
"useTabs": true
}

396
LICENSE
View File

@ -1,41 +1,375 @@
Copyright 2017 AJ ONeal Copyright 2015-2019 AJ ONeal
This is open source software; you can redistribute it and/or modify it under the Mozilla Public License Version 2.0
terms of either: ==================================
a) the "MIT License" 1. Definitions
b) the "Apache-2.0 License" --------------
MIT License 1.1. "Contributor"
means each individual or legal entity that creates, contributes to
the creation of, or owns Covered Software.
Permission is hereby granted, free of charge, to any person obtaining a copy 1.2. "Contributor Version"
of this software and associated documentation files (the "Software"), to deal means the combination of the Contributions of others (if any) used
in the Software without restriction, including without limitation the rights by a Contributor and that particular Contributor's Contribution.
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all 1.3. "Contribution"
copies or substantial portions of the Software. means Covered Software of a particular Contributor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1.4. "Covered Software"
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, means Source Code Form to which the initial Contributor has attached
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE the notice in Exhibit A, the Executable Form of such Source Code
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER Form, and Modifications of such Source Code Form, in each case
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, including portions thereof.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Apache-2.0 License Summary 1.5. "Incompatible With Secondary Licenses"
means
Licensed under the Apache License, Version 2.0 (the "License"); (a) that the initial Contributor has attached the notice described
you may not use this file except in compliance with the License. in Exhibit B to the Covered Software; or
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 (b) that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the
terms of a Secondary License.
Unless required by applicable law or agreed to in writing, software 1.6. "Executable Form"
distributed under the License is distributed on an "AS IS" BASIS, means any form of the work other than Source Code Form.
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and 1.7. "Larger Work"
limitations under the License. means a work that combines Covered Software with other material, in
a separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible,
whether at the time of the initial grant or subsequently, any and
all of the rights conveyed by this License.
1.10. "Modifications"
means any of the following:
(a) any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered
Software; or
(b) any new file in Source Code Form that contains any Covered
Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the
License, by the making, using, selling, offering for sale, having
made, import, or transfer of either its Contributions or its
Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU
Lesser General Public License, Version 2.1, the GNU Affero General
Public License, Version 3.0, or any later versions of those
licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that
controls, is controlled by, or is under common control with You. For
purposes of this definition, "control" means (a) the power, direct
or indirect, to cause the direction or management of such entity,
whether by contract or otherwise, or (b) ownership of more than
fifty percent (50%) of the outstanding shares or beneficial
ownership of such entity.
2. License Grants and Conditions
--------------------------------
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
(a) under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
(b) under Patent Claims of such Contributor to make, use, sell, offer
for sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
(a) for any code that a Contributor has removed from Covered Software;
or
(b) for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
(c) under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights
to grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
in Section 2.1.
3. Responsibilities
-------------------
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
(a) such Covered Software must also be made available in Source Code
Form, as described in Section 3.1, and You must inform recipients of
the Executable Form how they can obtain a copy of such Source Code
Form by reasonable means in a timely manner, at a charge no more
than the cost of distribution to the recipient; and
(b) You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter
the recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty,
or limitations of liability) contained within the Source Code Form of
the Covered Software, except that You may alter any license notices to
the extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
---------------------------------------------------
If it is impossible for You to comply with any of the terms of this
License with respect to some or all of the Covered Software due to
statute, judicial order, or regulation then You must: (a) comply with
the terms of this License to the maximum extent possible; and (b)
describe the limitations and the code they affect. Such description must
be placed in a text file included with all distributions of the Covered
Software under this License. Except to the extent prohibited by statute
or regulation, such description must be sufficiently detailed for a
recipient of ordinary skill to be able to understand it.
5. Termination
--------------
5.1. The rights granted under this License will terminate automatically
if You fail to comply with any of its terms. However, if You become
compliant, then the rights granted under this License from a particular
Contributor are reinstated (a) provisionally, unless and until such
Contributor explicitly and finally terminates Your grants, and (b) on an
ongoing basis, if such Contributor fails to notify You of the
non-compliance by some reasonable means prior to 60 days after You have
come back into compliance. Moreover, Your grants from a particular
Contributor are reinstated on an ongoing basis if such Contributor
notifies You of the non-compliance by some reasonable means, this is the
first time You have received notice of non-compliance with this License
from such Contributor, and You become compliant prior to 30 days after
Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
end user license agreements (excluding distributors and resellers) which
have been validly granted by You or Your distributors under this License
prior to termination shall survive termination.
************************************************************************
* *
* 6. Disclaimer of Warranty *
* ------------------------- *
* *
* Covered Software is provided under this License on an "as is" *
* basis, without warranty of any kind, either expressed, implied, or *
* statutory, including, without limitation, warranties that the *
* Covered Software is free of defects, merchantable, fit for a *
* particular purpose or non-infringing. The entire risk as to the *
* quality and performance of the Covered Software is with You. *
* Should any Covered Software prove defective in any respect, You *
* (not any Contributor) assume the cost of any necessary servicing, *
* repair, or correction. This disclaimer of warranty constitutes an *
* essential part of this License. No use of any Covered Software is *
* authorized under this License except under this disclaimer. *
* *
************************************************************************
************************************************************************
* *
* 7. Limitation of Liability *
* -------------------------- *
* *
* Under no circumstances and under no legal theory, whether tort *
* (including negligence), contract, or otherwise, shall any *
* Contributor, or anyone who distributes Covered Software as *
* permitted above, be liable to You for any direct, indirect, *
* special, incidental, or consequential damages of any character *
* including, without limitation, damages for lost profits, loss of *
* goodwill, work stoppage, computer failure or malfunction, or any *
* and all other commercial damages or losses, even if such party *
* shall have been informed of the possibility of such damages. This *
* limitation of liability shall not apply to liability for death or *
* personal injury resulting from such party's negligence to the *
* extent applicable law prohibits such limitation. Some *
* jurisdictions do not allow the exclusion or limitation of *
* incidental or consequential damages, so this exclusion and *
* limitation may not apply to You. *
* *
************************************************************************
8. Litigation
-------------
Any litigation relating to this License may be brought only in the
courts of a jurisdiction where the defendant maintains its principal
place of business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions.
Nothing in this Section shall prevent a party's ability to bring
cross-claims or counter-claims.
9. Miscellaneous
----------------
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides
that the language of a contract shall be construed against the drafter
shall not be used to construe this License against a Contributor.
10. Versions of the License
---------------------------
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
-------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular
file, then You may include the notice in a location (such as a LICENSE
file in a relevant directory) where a recipient would be likely to look
for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
---------------------------------------------------------
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.

394
README.md
View File

@ -1,84 +1,96 @@
dns-suite.js # [dns-suite.js](https://git.rootprojects.org/root/dns-suite.js)
========
| Built by [Root](https://rootprojects.org) for [Telebit][https://telebit.io] and [Hub](https://rootprojects.org/hub)
| **dns-suite.js** | **dns-suite.js**
| [dig.js](https://git.coolaj86.com/coolaj86/dig.js) | [dig.js](https://git.coolaj86.com/coolaj86/dig.js)
| [mdig.js](https://git.coolaj86.com/coolaj86/mdig.js) | [mdig.js](https://git.coolaj86.com/coolaj86/mdig.js)
| [digd.js](https://git.coolaj86.com/coolaj86/digd.js) | [digd.js](https://git.coolaj86.com/coolaj86/digd.js)
| Sponsored by [ppl](https://ppl.family)[.](https://dapliefounder.com)
Fast, lightweight, and easy-to-extend **pure JavaScript** (ES5.1) implementation for DNS / mDNS. Fast, lightweight, and easy-to-extend Vanilla JS (ES5.1) implementation of DNS / mDNS for Node.js and Browsers.
Works great in **Web Browsers** and in node.js! - [x] Full DNS Support
- [x] Queries
- [x] Answers
- [x] Authority
- [x] Additional
- [x] Built for Debugging
- [x] capture
- [x] packing (JSON to DNS/mDNS)
- [x] parsing (DNS/mDNS to JSON)
- [x] linting (finding errors in packets)
Detailed error checking makes it great for Uses `DataView`, `Uint8Array`, `Uint16Array`, and `ArrayBuffer`
* capture
* packing (JSON to DNS/mDNS)
* parsing (DNS/mDNS to JSON)
* linting (finding errors in packets)
* debugging
**No external dependencies** for node.js or modern browsers. Uses `DataView`, `Uint8Array`, `Uint16Array`, and `ArrayBuffer`
Similar API to `dns.js` and `native-dns-packet`. Similar API to `dns.js` and `native-dns-packet`.
# Example Query
```js
var DNSPacket = require('dns-suite').DNSPacket;
var query = {
header: {
id: rnd,
qr: 0,
opcode: 0,
aa: 0,
rd: 1,
ra: 0,
rcode: 0
},
question: [
{
name: 'google.com',
typeName: 'A',
className: 'IN'
}
]
};
var buffer = DNSPacket.pack(query);
```
# Example Response
```js
var DNSPacket = require('dns-suite').DNSPacket;
DNSPacket.parse(buffer);
```
```json ```json
{ "header": { {
"id": 5423 "header": {
, "qr": 0 "id": 5423,
, "opcode": 0 "qr": 0,
, "aa": 0 "opcode": 0,
, "tc": 0 "aa": 0,
, "rd": 1 "tc": 0,
, "ra": 0 "rd": 1,
, "res1": 0 "ra": 0,
, "res2": 0 "res1": 0,
, "res3": 0 "res2": 0,
, "rcode": 0 "res3": 0,
} "rcode": 0
, "question": [ },
{ "name": "bowie._sftp-ssh._tcp.local" "question": [
, "type": 1 {
, "typeName": "A" "name": "bowie._sftp-ssh._tcp.local",
, "class": 1 "type": 1,
, "className": "IN" "typeName": "A",
, "byteLength": 32 "class": 1,
} "className": "IN",
] "byteLength": 32
, "answer": [] }
, "authority": [] ],
, "additional": [] "answer": [],
, "edns_options": [] "authority": [],
, "byteLength": 44 "additional": [],
"edns_options": [],
"byteLength": 44
} }
``` ```
Install with git ## Install
-------
You can use git to install v1.x like so:
```bash
# latest of v1.x
npm install 'git+https://git.coolaj86.com/coolaj86/dns-suite.js#v1'
```
If you want to be more specific to v1.0.x or exactly v1.0.2 you can do so like this:
```
# latest of v1.0.x
npm install 'git+https://git.coolaj86.com/coolaj86/dns-suite.js#v1.0'
# exactly v1.0.2
npm install 'git+https://git.coolaj86.com/coolaj86/dns-suite.js#v1.0.2'
```
Install without git
-------
Don't have git? Well you can also bow down to the gods of the centralized, monopolized, concentrated, dictatornet
(as we like to call it here at ppl Labs), if that's how you roll:
``` ```
npm install --save dns-suite npm install --save dns-suite
@ -87,16 +99,13 @@ npm install --save dns-suite
**Test**: **Test**:
```bash ```bash
pushd node_modules/dns-suite node ./node_modules/dns-suite/examples/dns-pack.js
npm test
``` ```
Usage ## Usage
-----
* CLI - CLI
* API - API
### CLI Usage ### CLI Usage
@ -119,11 +128,12 @@ node node_modules/dns-suite/bin/dns-parse.js node_modules/dns-suite/samples/a-0.
### Library API ### Library API
* `DNSPacket.parse(nodeOrArrayBuffer)` returns json (as shown above) - `DNSPacket.parse(nodeOrArrayBuffer)` returns json (as shown above)
* `DNSPacket.pack(packet)` returns ArrayBuffer (browser and node) - `DNSPacket.pack(packet)` returns ArrayBuffer (browser and node)
* `DNSPacket.write(packet)` returns NodeBuffer (node only) - `DNSPacket.write(packet)` returns NodeBuffer (node only)
node.js: node.js:
```js ```js
var nodeBuffer = fs.readFileSync('./samples/a-0.mdns.bin'); var nodeBuffer = fs.readFileSync('./samples/a-0.mdns.bin');
var arrayBuffer = nodeBuffer.buffer; var arrayBuffer = nodeBuffer.buffer;
@ -137,8 +147,11 @@ console.log(new Uint8Array(ab));
``` ```
Browser: Browser:
```js ```js
var arrayBuffer = new Uint8Array.from([ /* bytes */ ]).buffer; var arrayBuffer = new Uint8Array.from([
/* bytes */
]).buffer;
var packet = DNSPacket.parse(arrayBuffer); var packet = DNSPacket.parse(arrayBuffer);
var ab = DNSPacket.pack(packet); var ab = DNSPacket.pack(packet);
@ -147,9 +160,7 @@ console.log(packet);
console.log(new Uint8Array(ab)); console.log(new Uint8Array(ab));
``` ```
## Capturing Packets
Capturing Packets
-----
We have a command line tool for that! See [dig.js](https://git.coolaj86.com/coolaj86/dig.js). We have a command line tool for that! See [dig.js](https://git.coolaj86.com/coolaj86/dig.js).
@ -164,21 +175,19 @@ dig.js A coolaj86.com --output .
dig.js --mdns PTR _services._dns-sd._udp.local --output . dig.js --mdns PTR _services._dns-sd._udp.local --output .
``` ```
Resource Record Examples # Resource Record Examples
========================
* SOA - SOA
* NS - NS
* A - A
* AAAA - AAAA
* CNAME - CNAME
* MX - MX
* TXT - TXT
* SRV - SRV
* PTR - PTR
SOA ## SOA
---
I'm pretty sure that the SOA only goes in the `authority` section I'm pretty sure that the SOA only goes in the `authority` section
(except when SOA is queried explicitly) (except when SOA is queried explicitly)
@ -191,24 +200,23 @@ a set of `NS` records should be returned instead.
```json ```json
{ {
"name": "yahoo.com", "name": "yahoo.com",
"type": 6, "type": 6,
"typeName": "SOA", "typeName": "SOA",
"class": 1, "class": 1,
"className": "IN", "className": "IN",
"ttl": 599, "ttl": 599,
"primary": "ns1.yahoo.com", "primary": "ns1.yahoo.com",
"admin": "hostmaster.yahoo-inc.com", "admin": "hostmaster.yahoo-inc.com",
"serial": 2017092539, "serial": 2017092539,
"refresh": 3600, "refresh": 3600,
"retry": 300, "retry": 300,
"expiration": 1814400, "expiration": 1814400,
"minimum": 600 "minimum": 600
} }
``` ```
NS ## NS
---
I'm also pretty sure that the NS only goes in the `authority` section I'm also pretty sure that the NS only goes in the `authority` section
(except when NS is queried explicitly) (except when NS is queried explicitly)
@ -221,144 +229,136 @@ question have been delegated to another nameserver.
```json ```json
{ {
"name": "google.com", "name": "google.com",
"type": 2, "type": 2,
"typeName": "NS", "typeName": "NS",
"class": 1, "class": 1,
"className": "IN", "className": "IN",
"ttl": 82790, "ttl": 82790,
"data": "ns3.google.com" "data": "ns3.google.com"
} }
``` ```
A ## A
---
The most common type of record. Returns the IPv4 address for a given domain. The most common type of record. Returns the IPv4 address for a given domain.
```json ```json
{ {
"name": "www.linode.com", "name": "www.linode.com",
"type": 1, "type": 1,
"typeName": "A", "typeName": "A",
"class": 1, "class": 1,
"className": "IN", "className": "IN",
"ttl": 291, "ttl": 291,
"address": "72.14.191.202" "address": "72.14.191.202"
} }
``` ```
AAAA ## AAAA
----
Returns the IPv6 address for a given domain. Returns the IPv6 address for a given domain.
```json ```json
{ {
"name": "irc6.geo.oftc.net", "name": "irc6.geo.oftc.net",
"type": 28, "type": 28,
"typeName": "AAAA", "typeName": "AAAA",
"class": 1, "class": 1,
"className": "IN", "className": "IN",
"ttl": 59, "ttl": 59,
"address": "2607:f8f0:610:4000:211:11ff:fe1c:7bec" "address": "2607:f8f0:610:4000:211:11ff:fe1c:7bec"
} }
``` ```
CNAME ## CNAME
-----
The CNAME is used to look up the IP address for the given alias. The CNAME is used to look up the IP address for the given alias.
(the alias is often referred to incorrectly as a CNAME but it is, in fact, the alias) (the alias is often referred to incorrectly as a CNAME but it is, in fact, the alias)
```json ```json
{ {
"name": "www.nodejs.org", "name": "www.nodejs.org",
"type": 5, "type": 5,
"typeName": "CNAME", "typeName": "CNAME",
"class": 1, "class": 1,
"className": "IN", "className": "IN",
"ttl": 3600, "ttl": 3600,
"data": "nodejs.org" "data": "nodejs.org"
} }
``` ```
MX ## MX
---
Mail Exchange Records show the alias that should be looked up to know where incoming mail should Mail Exchange Records show the alias that should be looked up to know where incoming mail should
be sent. be sent.
```json ```json
{ {
"name": "microsoft.com", "name": "microsoft.com",
"type": 15, "type": 15,
"typeName": "MX", "typeName": "MX",
"class": 1, "class": 1,
"className": "IN", "className": "IN",
"ttl": 197, "ttl": 197,
"priority": 10, "priority": 10,
"exchange": "microsoft-com.mail.protection.outlook.com" "exchange": "microsoft-com.mail.protection.outlook.com"
} }
``` ```
TXT ## TXT
---
Often used for outgoing mail validations, public keys, lots of arbitrary stuff. Often used for outgoing mail validations, public keys, lots of arbitrary stuff.
```json ```json
{ {
"name": "aol.com", "name": "aol.com",
"type": 16, "type": 16,
"typeName": "TXT", "typeName": "TXT",
"class": 1, "class": 1,
"className": "IN", "className": "IN",
"ttl": 1926, "ttl": 1926,
"data": [ "v=spf1 ptr:mx.aol.com ?all" ] "data": ["v=spf1 ptr:mx.aol.com ?all"]
} }
``` ```
SRV ## SRV
---
A way to associate a service with a port and other relevant information. A way to associate a service with a port and other relevant information.
Used for federated / dencentralized protocols (like XMPP) and mDNS/DLNA/UPnP/DNS-SD type stuff. Used for federated / dencentralized protocols (like XMPP) and mDNS/DLNA/UPnP/DNS-SD type stuff.
```json ```json
{ {
"name": "_xmpp-server._tcp.gmail.com", "name": "_xmpp-server._tcp.gmail.com",
"type": 33, "type": 33,
"typeName": "SRV", "typeName": "SRV",
"class": 1, "class": 1,
"className": "IN", "className": "IN",
"ttl": 900, "ttl": 900,
"priority": 5, "priority": 5,
"weight": 0, "weight": 0,
"port": 5269, "port": 5269,
"target": "xmpp-server.l.google.com" "target": "xmpp-server.l.google.com"
} }
``` ```
PTR ## PTR
---
Used for mDNS/DNS-SD type discoveries and anti-spam reverse lookup verification for mail servers. Used for mDNS/DNS-SD type discoveries and anti-spam reverse lookup verification for mail servers.
```json ```json
{ {
"name": "_pdl-datastream._tcp.local", "name": "_pdl-datastream._tcp.local",
"type": 12, "type": 12,
"typeName": "PTR", "typeName": "PTR",
"class": 1, "class": 1,
"className": "IN", "className": "IN",
"ttl": 255, "ttl": 255,
"data": "Canon MF620C Series._pdl-datastream._tcp.local" "data": "Canon MF620C Series._pdl-datastream._tcp.local"
} }
``` ```
All Properties ## All Properties
---------
For simplicity, here's a list of all properties, just for fun: For simplicity, here's a list of all properties, just for fun:
@ -402,19 +402,17 @@ For simplicity, here's a list of all properties, just for fun:
} }
``` ```
Contributing and Development # Contributing and Development
============================
How to add a new parser ## How to add a new parser
-----------------------
Each RR (aka Resource Record or RData) parser is individual. Examples include: Each RR (aka Resource Record or RData) parser is individual. Examples include:
* A (`parser/type.a.js`) - A (`parser/type.a.js`)
* AAAA (`parser/type.aaaa.js`) - AAAA (`parser/type.aaaa.js`)
* CNAME (`parser/type.cname.js`) - CNAME (`parser/type.cname.js`)
* TXT (`parser/type.txt.js`) - TXT (`parser/type.txt.js`)
* SRV (`parser/type.srv.js`) - SRV (`parser/type.srv.js`)
Let's say that To create a parser for a type which we don't currently support, Let's say that To create a parser for a type which we don't currently support,
just add the appropriate information to `dns.types.js` and create a file for just add the appropriate information to `dns.types.js` and create a file for
@ -423,7 +421,7 @@ the name of the type in the format `parser/type.<typename>.js`.
For example, if `CNAME` wasn't already supported and I wanted to add support for For example, if `CNAME` wasn't already supported and I wanted to add support for
it I would follow these steps: it I would follow these steps:
1) Update `dns.types.js` if it's not there already. 1. Update `dns.types.js` if it's not there already.
``` ```
A: 0x01 // 1 A: 0x01 // 1
@ -432,7 +430,7 @@ it I would follow these steps:
, SOA: 0x06 // 6 , SOA: 0x06 // 6
``` ```
2) Capture a packet to `test/fixtures/<domain>.<tld>.<type>.bin` 2. Capture a packet to `test/fixtures/<domain>.<tld>.<type>.bin`
This will construct and send a DNS query and save the first result This will construct and send a DNS query and save the first result
that comes back. that comes back.
@ -450,7 +448,7 @@ npm install -g dig.js
dig.js --name www.google.com --type CNAME --output ./samples/ dig.js --name www.google.com --type CNAME --output ./samples/
``` ```
3) Create `parser/type.cname.js` 3. Create `parser/type.cname.js`
Copy `parser/type.TEMPLATE.js` to the type for which you wish to create support Copy `parser/type.TEMPLATE.js` to the type for which you wish to create support
(`parser/type.cname.js` in this example) and fill in the blanks. (`parser/type.cname.js` in this example) and fill in the blanks.
@ -468,7 +466,7 @@ exports.DNS_PARSER_TYPE_CNAME = function (ab, packet, record) {
}('undefined' !== typeof window ? window : exports)); }('undefined' !== typeof window ? window : exports));
``` ```
4) Document what you've learned in `doc/<type>.txt` 4. Document what you've learned in `doc/<type>.txt`
You may be right or you might be wrong, but you might be right. You may be right or you might be wrong, but you might be right.
@ -478,7 +476,7 @@ record type - tips, tricks, little-known facts, etc.
This may help (or wildly mislead) others if there's a bug in your parser that they need to track down. This may help (or wildly mislead) others if there's a bug in your parser that they need to track down.
At the very least someone can follow a few links you followed and your thought process. At the very least someone can follow a few links you followed and your thought process.
5) Check that my changes include these files 5. Check that my changes include these files
``` ```
├── README.md ├── README.md

0
bin/debug.js Normal file → Executable file
View File

0
bin/debugd.js Normal file → Executable file
View File

View File

@ -9,54 +9,60 @@ var path = require('path');
var filename = process.argv[2]; var filename = process.argv[2];
var outname = process.argv[3]; var outname = process.argv[3];
if (!filename) { if (!filename) {
console.error("Usage: node bin/dns-pack.js <path/to/sample.json> <path/to/output.bin>"); console.error(
console.error("Example: node bin/dns-pack.js ./samples/services-0.mdns.json ./services-0.mdns.bin"); 'Usage: node bin/dns-pack.js <path/to/sample.json> <path/to/output.bin>'
process.exit(1); );
return; console.error(
'Example: node bin/dns-pack.js ./samples/services-0.mdns.json ./services-0.mdns.bin'
);
process.exit(1);
return;
} }
if (!outname) { if (!outname) {
console.warn(''); console.warn('');
console.warn( console.warn(
"Usage: node bin/dns-pack.js '" + filename + "' './" + path.basename(filename).replace(path.extname(filename), '') + ".bin'" "Usage: node bin/dns-pack.js '" +
); filename +
console.warn(''); "' './" +
path.basename(filename).replace(path.extname(filename), '') +
".bin'"
);
console.warn('');
} }
var PromiseA = require('bluebird'); var PromiseA = require('bluebird');
var fs = PromiseA.promisifyAll(require('fs')); var fs = PromiseA.promisifyAll(require('fs'));
var dnsjs = require('../').DNSPacket; var dnsjs = require('../').DNSPacket;
fs.readFileAsync(filename, null).then(function (nb) { fs.readFileAsync(filename, null).then(function(nb) {
// //
// current reference impl // current reference impl
// //
//console.log(require('native-dns-packet').parse(nb)); //console.log(require('native-dns-packet').parse(nb));
//
// other reference impl
//
//console.log(require('dns-js').DNSPacket.parse(nb));
// // nb is a Uint8Array (ArrayBufferView) for nb.buffer
// other reference impl // nb.buffer is the actual ArrayBuffer
//
//console.log(require('dns-js').DNSPacket.parse(nb));
// nb is a Uint8Array (ArrayBufferView) for nb.buffer //var ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength);
// nb.buffer is the actual ArrayBuffer var packet = dnsjs.write(JSON.parse(nb.toString('ascii')));
//var ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength); //console.log('[packet]', nb.byteLength, 'bytes:');
var packet = dnsjs.write(JSON.parse(nb.toString('ascii'))); //console.log(JSON.stringify(packet, null, 2));
//console.log('[packet]', nb.byteLength, 'bytes:'); //TODO hexdump packet
//console.log(JSON.stringify(packet, null, 2)); var hexdump = require('@root/hexdump');
var str = hexdump(packet);
//TODO hexdump packet console.log(str);
var hexdump = require('hexdump.js').hexdump;
var str = hexdump(packet);
console.log(str); if (outname) {
fs.writeFileSync(outname, packet, null);
if (outname) { console.log('');
fs.writeFileSync(outname, packet, null); console.log("wrote '" + outname + "'");
console.log(''); }
console.log("wrote '" + outname + "'");
}
}); });

View File

@ -10,117 +10,144 @@ var filename = process.argv[2];
var outname = process.argv[3]; var outname = process.argv[3];
if (!filename || /(-h)|(--help)/.test(process.argv.join(' '))) { if (!filename || /(-h)|(--help)/.test(process.argv.join(' '))) {
console.error(""); console.error('');
console.error("Accepts a DNS packet (binary or json), converts it, and then converts it back to verify the function of the parser and packer"); console.error(
console.error(""); 'Accepts a DNS packet (binary or json), converts it, and then converts it back to verify the function of the parser and packer'
console.error("Usage: node bin/dns-test.js <path/to/sample.json|.bin> <path/to/sample.bin|.json>"); );
console.error("Example: node bin/dns-test.js ./samples/services-0.mdns.json ./samples/services-0.mdns.bin"); console.error('');
process.exit(1); console.error(
return; 'Usage: node bin/dns-test.js <path/to/sample.json|.bin> <path/to/sample.bin|.json>'
);
console.error(
'Example: node bin/dns-test.js ./samples/services-0.mdns.json ./samples/services-0.mdns.bin'
);
process.exit(1);
return;
} }
var PromiseA = require('bluebird'); var PromiseA = require('bluebird');
var fs = PromiseA.promisifyAll(require('fs')); var fs = PromiseA.promisifyAll(require('fs'));
var dnsjs = require('../').DNSPacket; var dnsjs = require('../').DNSPacket;
var extname = path.extname(filename).substr(1).toLowerCase(); var extname = path
.extname(filename)
.substr(1)
.toLowerCase();
if ('json' !== extname && 'bin' !== extname) { if ('json' !== extname && 'bin' !== extname) {
console.error("The file extension must end in .json or .bin (raw DNS packet)"); console.error(
process.exit(3); 'The file extension must end in .json or .bin (raw DNS packet)'
return; );
process.exit(3);
return;
} }
var hexdump = require('hexdump.js').hexdump; var hexdump = require('@root/hexdump');
function testJsonAsync(nb) { function testJsonAsync(nb) {
var packet = dnsjs.write(JSON.parse(nb.toString('ascii'))); var packet = dnsjs.write(JSON.parse(nb.toString('ascii')));
var str = hexdump(packet); var str = hexdump(packet);
console.info(str); console.info(str);
var json = dnsjs.parse(packet); var json = dnsjs.parse(packet);
if (json.error) { if (json.error) {
console.error(json); console.error(json);
process.exit(37); process.exit(37);
return; return;
} }
console.info("[OK] JSON -> binary -> JSON"); console.info('[OK] JSON -> binary -> JSON');
if (!outname) { if (!outname) {
console.warn(''); console.warn('');
console.warn( console.warn(
"Usage: node bin/dns-test.js '" + filename + "' './" + path.basename(filename).replace(path.extname(filename), '.bin') + "'" "Usage: node bin/dns-test.js '" +
); filename +
console.warn(''); "' './" +
return; path
} .basename(filename)
.replace(path.extname(filename), '.bin') +
"'"
);
console.warn('');
return;
}
fs.writeFileSync(outname, packet, null); fs.writeFileSync(outname, packet, null);
} }
function testBinAsync(nb) { function testBinAsync(nb) {
var bin = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength); var bin = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength);
var json = dnsjs.parse(bin); var json = dnsjs.parse(bin);
if (json.error) { if (json.error) {
console.error(json); console.error(json);
process.exit(38); process.exit(38);
return; return;
} }
var bin2 = dnsjs.write(json); var bin2 = dnsjs.write(json);
//var debugname = outname || path.basename(filename); //var debugname = outname || path.basename(filename);
//fs.writeFileSync(debugname.replace(path.extname(debugname), '.bin'), bin2, null); //fs.writeFileSync(debugname.replace(path.extname(debugname), '.bin'), bin2, null);
var json2 = dnsjs.parse(bin2); var json2 = dnsjs.parse(bin2);
if (json2.error) { if (json2.error) {
console.error(json2); console.error(json2);
process.exit(37); process.exit(37);
return; return;
} }
var assert = require('assert'); var assert = require('assert');
// EXPLANATION: // EXPLANATION:
// The strategy used for compression pointers has not yet been proven // The strategy used for compression pointers has not yet been proven
// as deterministic... and we don't implement them anyway, so this may not be the same // as deterministic... and we don't implement them anyway, so this may not be the same
json = JSON.parse(JSON.stringify(json) json = JSON.parse(
.replace(/,"labels":.*?\]/, '') JSON.stringify(json)
.replace(/,"cpcount":\d+/, '') .replace(/,"labels":.*?\]/, '')
); .replace(/,"cpcount":\d+/, '')
json2 = JSON.parse(JSON.stringify(json2) );
.replace(/,"labels":.*?\]/, '') json2 = JSON.parse(
.replace(/,"cpcount":\d+/, '') JSON.stringify(json2)
); .replace(/,"labels":.*?\]/, '')
//json2 = JSON.parse(JSON.stringify(json2)); .replace(/,"cpcount":\d+/, '')
try { );
assert.deepEqual(json, json2); //json2 = JSON.parse(JSON.stringify(json2));
} catch(e) { try {
console.error(''); assert.deepEqual(json, json2);
console.error('Original'); } catch (e) {
console.error(JSON.stringify(json, null, 2)); console.error('');
console.error(''); console.error('Original');
console.error('Converted'); console.error(JSON.stringify(json, null, 2));
console.error(JSON.stringify(json2, null, 2)); console.error('');
console.error(''); console.error('Converted');
process.exit(422); console.error(JSON.stringify(json2, null, 2));
return; console.error('');
} process.exit(422);
return;
}
console.info("[OK] binary -> JSON -> binary -> JSON"); console.info('[OK] binary -> JSON -> binary -> JSON');
console.warn("(compression pointer support needs to be improved in order to support direct bin -> JSON -> bin testing)"); console.warn(
'(compression pointer support needs to be improved in order to support direct bin -> JSON -> bin testing)'
);
if (!outname) { if (!outname) {
console.warn(''); console.warn('');
console.warn( console.warn(
"Usage: node bin/dns-test.js '" + filename + "' './" + path.basename(filename).replace(path.extname(filename), '.json') + "'" "Usage: node bin/dns-test.js '" +
); filename +
console.warn(''); "' './" +
return; path
} .basename(filename)
.replace(path.extname(filename), '.json') +
"'"
);
console.warn('');
return;
}
fs.writeFileSync(outname, JSON.stringify(json, null, 2), null); fs.writeFileSync(outname, JSON.stringify(json, null, 2), null);
} }
if ('json' === extname) { if ('json' === extname) {
return fs.readFileAsync(filename, null).then(testJsonAsync); return fs.readFileAsync(filename, null).then(testJsonAsync);
} }
if ('bin' === extname) { if ('bin' === extname) {
return fs.readFileAsync(filename, null).then(testBinAsync); return fs.readFileAsync(filename, null).then(testBinAsync);
} }

27
examples/dns-pack.js Normal file
View File

@ -0,0 +1,27 @@
'use strict';
var DNSPacket = require('../').DNSPacket;
var rnd = Math.floor(Math.random() * 65536);
var query = {
header: {
id: rnd,
qr: 0,
opcode: 0,
aa: 0,
rd: 1,
ra: 0,
rcode: 0
},
question: [
{
name: 'google.com',
typeName: 'A',
className: 'IN'
}
]
};
var buffer = DNSPacket.pack(query);
console.info(Buffer.from(buffer));

13
package-lock.json generated Normal file
View File

@ -0,0 +1,13 @@
{
"name": "dns-suite",
"version": "1.2.13",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@root/hexdump": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@root/hexdump/-/hexdump-1.1.1.tgz",
"integrity": "sha512-AmrmLOutlzctR599ittO06lINOco1TIqb0c1wu83fP2Eoi5iSvx7kVWC4mDufze8rxPewC+aQOx4e6Pw7izV4A=="
}
}
}

View File

@ -1,29 +1,25 @@
{ {
"name": "dns-suite", "name": "dns-suite",
"version": "1.2.12", "version": "1.2.13",
"description": "testing dns", "description": "DNS implemented in Vanilla JS for Node.js and Browsers",
"main": "dns.js", "main": "dns.js",
"homepage": "https://git.coolaj86.com/coolaj86/dns-suite.js", "homepage": "https://git.coolaj86.com/coolaj86/dns-suite.js",
"bin": { "bin": {
"dns-pack.js": "bin/dns-pack.js", "dns-pack.js": "bin/dns-pack.js",
"dns-parse.js": "bin/dns-parse.js", "dns-parse.js": "bin/dns-parse.js",
"dns-test.js": "bin/dns-test.js", "dns-test.js": "bin/dns-test.js",
"mdns-capture.js": "bin/mdns-capture.js" "mdns-capture.js": "bin/mdns-capture.js"
}, },
"scripts": { "scripts": {
"test": "node test/parser.js && node test/packer.js" "test": "node test/parser.js && node test/packer.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://git.coolaj86.com:coolaj86/dns-suite.js.git" "url": "https://git.coolaj86.com:coolaj86/dns-suite.js.git"
}, },
"author": "", "author": "",
"license": "(MIT or Apache2)", "license": "MPL-2.0",
"devDependencies": { "dependencies": {
"bluebird": "^3.5.0" "@root/hexdump": "^1.1.1"
}, }
"dependencies": {
"bluebird": "^3.5.0",
"hexdump.js": "git+https://git.coolaj86.com/coolaj86/hexdump.js#v1.0.4"
}
} }

View File

@ -1,33 +0,0 @@
{ header:
{ id: 46894,
qr: 1,
opcode: 0,
aa: 0,
tc: 0,
rd: 1,
ra: 1,
res1: 0,
res2: 0,
res3: 0,
rcode: 0 },
question: [ { name: 'www.linode.com', type: 1, class: 1 } ],
answer:
[ { name: 'www.linode.com',
type: 1,
class: 1,
ttl: 291,
address: '72.14.191.202' },
{ name: 'www.linode.com',
type: 1,
class: 1,
ttl: 291,
address: '69.164.200.202' },
{ name: 'www.linode.com',
type: 1,
class: 1,
ttl: 291,
address: '72.14.180.202' } ],
authority: [],
additional: [],
edns_options: [],
payload: undefined }

43
test/fixtures/www.linode.com.a.json vendored Normal file
View File

@ -0,0 +1,43 @@
{
"header": {
"id": 46894,
"qr": 1,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 1,
"res1": 0,
"res2": 0,
"res3": 0,
"rcode": 0
},
"question": [{ "name": "www.linode.com", "type": 1, "class": 1 }],
"answer": [
{
"name": "www.linode.com",
"type": 1,
"class": 1,
"ttl": 291,
"address": "72.14.191.202"
},
{
"name": "www.linode.com",
"type": 1,
"class": 1,
"ttl": 291,
"address": "69.164.200.202"
},
{
"name": "www.linode.com",
"type": 1,
"class": 1,
"ttl": 291,
"address": "72.14.180.202"
}
],
"authority": [],
"additional": [],
"edns_options": [],
"payload": undefined
}