From 32bc4e6feaad5a9b5b097deb639c67a4eebd5ace Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 23 Oct 2017 20:39:32 -0600 Subject: [PATCH 01/10] fix bad test AAAA value --- BUGS.txt | 5 +++++ samples/db.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/BUGS.txt b/BUGS.txt index 574106a..3c9aee3 100644 --- a/BUGS.txt +++ b/BUGS.txt @@ -1 +1,6 @@ dig @localhost -p 65053 ANY aaaa.example.com + +# Using the wrong type (A instead of AAAA) results in an erroneous packet + +{ "zone": "example.com", "name": "aaaa.example.com", "tld": "com", "sld": "example", "sub": "aaaa" +, "type": "A", "address": "::1" } diff --git a/samples/db.js b/samples/db.js index e7a82d6..f2f86e9 100644 --- a/samples/db.js +++ b/samples/db.js @@ -29,7 +29,7 @@ module.exports = { , { "zone": "example.com", "name": "a.example.com", "tld": "com", "sld": "example", "sub": "a" , "type": "A", "address": "4.3.2.1" } , { "zone": "example.com", "name": "aaaa.example.com", "tld": "com", "sld": "example", "sub": "aaaa" - , "type": "A", "address": "::1" } + , "type": "AAAA", "address": "::1" } , { "zone": "example.com", "name": "aname.example.com", "tld": "com", "sld": "example", "sub": "aname" , "type": "A", "aname": "amazon.com" } , { "zone": "example.com", "name": "devname.example.com", "tld": "com", "sld": "example", "sub": "devname" From d4e036fa97a42f8fa058e58bee9f9550bdfc2976 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 23 Oct 2017 20:40:40 -0600 Subject: [PATCH 02/10] v1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ed9b019..10ef710 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "digd.js", - "version": "1.0.0", + "version": "1.0.1", "description": "A lightweight DNS / mDNS daemon (server) for creating and capturing DNS and mDNS query and response packets to disk as binary and/or JSON. Options are similar to the Unix dig command.", "main": "bin/digd.js", "bin": { From a8efa1f68de139e5dd69d6ccd5704a1e9d2f7278 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 23 Oct 2017 20:41:14 -0600 Subject: [PATCH 03/10] v1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 10ef710..40ddbe8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "digd.js", - "version": "1.0.1", + "version": "1.1.0", "description": "A lightweight DNS / mDNS daemon (server) for creating and capturing DNS and mDNS query and response packets to disk as binary and/or JSON. Options are similar to the Unix dig command.", "main": "bin/digd.js", "bin": { From 251afcf4393a3f662b493efcc47e3ea2fef201de Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 23 Oct 2017 20:41:23 -0600 Subject: [PATCH 04/10] v1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 40ddbe8..0b02ae5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "digd.js", - "version": "1.1.0", + "version": "1.1.1", "description": "A lightweight DNS / mDNS daemon (server) for creating and capturing DNS and mDNS query and response packets to disk as binary and/or JSON. Options are similar to the Unix dig command.", "main": "bin/digd.js", "bin": { From acfb2e7a01be07d34d5adf782516866ba34d464c Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 23 Oct 2017 20:54:49 -0600 Subject: [PATCH 05/10] update git deps --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0b02ae5..9d29770 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "author": "AJ ONeal (https://coolaj86.com)", "license": "MIT OR Apache-2.0", "dependencies": { - "dig.js": "^1.2.1", - "hexdump.js": "^1.0.4" + "dig.js": "git+https://git.daplie.com/Daplie/dig.js#v1.3", + "hexdump.js": "git+https://git.daplie.com/Daplie/hexdump.js#v1.0.4" } } From 031aa24c1b24b21dfd6e6859cc450aad85425b3e Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 23 Oct 2017 20:55:00 -0600 Subject: [PATCH 06/10] v1.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9d29770..81edf01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "digd.js", - "version": "1.1.1", + "version": "1.1.2", "description": "A lightweight DNS / mDNS daemon (server) for creating and capturing DNS and mDNS query and response packets to disk as binary and/or JSON. Options are similar to the Unix dig command.", "main": "bin/digd.js", "bin": { From 4e65f6be3f4ae9ca93f86cee6d0ff28cd10b4e41 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 23 Oct 2017 20:56:43 -0600 Subject: [PATCH 07/10] v1.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 81edf01..cdc15ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "digd.js", - "version": "1.1.2", + "version": "1.1.3", "description": "A lightweight DNS / mDNS daemon (server) for creating and capturing DNS and mDNS query and response packets to disk as binary and/or JSON. Options are similar to the Unix dig command.", "main": "bin/digd.js", "bin": { From bcb9f3cf86e6aeffd6f6567f08786563cb98fa8c Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 23 Oct 2017 21:14:52 -0600 Subject: [PATCH 08/10] add wildcard test --- samples/db.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/samples/db.js b/samples/db.js index f2f86e9..f07173a 100644 --- a/samples/db.js +++ b/samples/db.js @@ -57,6 +57,14 @@ module.exports = { , { "zone": "example.com", "name": "email.example.com", "tld": "com", "sld": "example", "sub": "email" , "type": "CNAME", "data": "mailgun.org" } + // a wildcard domain + // wild.example.com does NOT match + // exists.wild.example.com DOES match, statically + // doesntexist.wild.example.com DOES match, wildly + , { "zone": "example.com", "name": "*.wild.example.com", "tld": "com", "sld": "example", "sub": "*.wild" + , "type": "A", "address": "12.34.56.78" } + , { "zone": "example.com", "name": "exists.wild.example.com", "tld": "com", "sld": "example", "sub": "exists.wild" + , "type": "A", "address": "123.0.0.45" } // Out-delegated Domains , { "zone": "example.com", "type": "NS", "name": "out-delegated.example.com" From 62733099ec0376eec4efa2f9dc34cbedd708d9b5 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 23 Oct 2017 22:02:03 -0600 Subject: [PATCH 09/10] pass wildcard tests --- TESTS.md | 9 +++++++++ lib/dns-store.js | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/TESTS.md b/TESTS.md index 6637e6c..e10f693 100644 --- a/TESTS.md +++ b/TESTS.md @@ -126,4 +126,13 @@ $digcmd @$ns -p $port A doesntexist.a.example.com # should return NS records in ANSWER section, nothing else $digcmd @$ns -p $port NS a.example.com +# Test: +# wildcard record should match after static records +$digcmd @$ns -p $port ANY wild.example.com # no record +$digcmd @$ns -p $port ANY exists.wild.example.com # static record, before wildcard +$digcmd @$ns -p $port ANY foo.exists.wild.example.com # no record +$digcmd @$ns -p $port ANY doesntexist.wild.example.com # single-level wildcard +$digcmd @$ns -p $port ANY alsedoesntexist.wild.example.com # single-level wildcard +$digcmd @$ns -p $port ANY foo.doesntexist.wild.example.com # no second-level wildcard + ``` diff --git a/lib/dns-store.js b/lib/dns-store.js index 952ebf1..ef89016 100644 --- a/lib/dns-store.js +++ b/lib/dns-store.js @@ -29,13 +29,47 @@ function getRecords(db, qname, cb) { }); function checkCount() { + var ready; + count -= 1; - if (count <= 0) { - myRecords = myRecords.filter(function (r) { - return !delMe[r.id]; - }); - cb(null, myRecords); + ready = count <= 0; + + if (!ready) { + return; } + + myRecords = myRecords.filter(function (r) { + return !delMe[r.id]; + }); + + // There are a number of ways to interpret the wildcard rules + var hasWild = false; + var hasMatch = false; + myRecords.some(function (r) { + if (qname === r.name) { + hasMatch = true; + return true; + } + if ('*' === r.name[0]) { + hasWild = true; + } + }); + + if (hasMatch) { + myRecords = myRecords.filter(function (r) { + if ('*' !== r.name[0]) { return true; } + }); + } + /* + // no need to filter out records if wildcard is used + else { + records = records.filter(function (r) { + if ('*' === r.name[0]) { return true; } + }); + } + */ + + cb(null, myRecords); } function getRecord(r) { From cf8cab5596ce10c665bce02ba3804106537f8b11 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 23 Oct 2017 22:02:12 -0600 Subject: [PATCH 10/10] v1.1.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cdc15ff..dc5afce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "digd.js", - "version": "1.1.3", + "version": "1.1.4", "description": "A lightweight DNS / mDNS daemon (server) for creating and capturing DNS and mDNS query and response packets to disk as binary and/or JSON. Options are similar to the Unix dig command.", "main": "bin/digd.js", "bin": {