Skip to content

Commit

Permalink
feat(TLSA): prettify TLSA
Browse files Browse the repository at this point in the history
  • Loading branch information
Falci committed Jul 24, 2024
1 parent 0be7bd9 commit 85d107f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ function prettify(msg) {
case 'DS':
rr.data.digest = rr.data.digest.toString('hex');
break;
case 'TLSA':
rr.data.certificate = rr.data.certificate.toString('hex');
break;
case 'NSEC3':
rr.data.salt = rr.data.salt.toString('hex');
rr.data.nextDomain = base32Encode(rr.data.nextDomain, 'RFC4648-HEX').replace('=', '')
Expand Down
17 changes: 16 additions & 1 deletion lib/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {makeQuery, DohResolver, sendDohMsg, MethodNotAllowedError, isMethodAllowed, dnsPacket} = require('.');
const {makeQuery, DohResolver, sendDohMsg, MethodNotAllowedError, isMethodAllowed, dnsPacket, prettify} = require('.');

test('DNS query message should be created', () => {
expect(makeQuery('example.com')).toBeTruthy();
Expand Down Expand Up @@ -65,6 +65,21 @@ test('DohResolver.query() for example.com TXT contains answers', async () => {
}
});

test('prettify can handle TLSA', async () => {
// From '_443._tcp.good.dane.huque.com', 'TLSA'
const data = Buffer.from('000081800001000100000000045f343433045f74637004676f6f640464616e6505687571756503636f6d0000340001c00c0034000100001c2000230301016e8d1119ab26b6ef204b33a4036f2835cab86b0833f36ee96642e5703b74486c', 'hex')
const msg = dnsPacket.decode(data);

try {
let response = prettify(msg);
expect(response.answers).toHaveLength(1);
expect(response.answers[0].data).toHaveProperty('certificate');
expect(typeof response.answers[0].data.certificate).toBe('string')
} catch(err) {
throw err;
}
});

test('timeout works properly (and cloudflare doesn\'t respond within 1 millisecond)', async () => {
let msg = makeQuery('example.org');
try {
Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"argparse": "^1.0.10",
"base32-encode": "^1.1.1",
"browserify": "^16.5.0",
"dns-packet": "^5.2.1",
"dns-packet": "^5.6.1",
"glob-parent": "^5.1.2",
"ws": "^7.4.6"
},
Expand Down

0 comments on commit 85d107f

Please sign in to comment.