From 21d795a5f032145d99e2843eb2533e2143bedc97 Mon Sep 17 00:00:00 2001 From: Rithvik Vibhu Date: Tue, 14 May 2024 23:10:31 +0530 Subject: [PATCH] dns: add TLSA record query and parsing PR-URL: https://github.com/nodejs/node/pull/52983 Refs: https://github.com/nodejs/node/issues/39569 Reviewed-By: Paolo Insogna Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Ethan Arrowood --- doc/api/dns.md | 71 ++++++++++++++++++ lib/internal/dns/utils.js | 2 + src/cares_wrap.cc | 96 +++++++++++++++++++++++++ src/cares_wrap.h | 8 +++ src/env_properties.h | 4 ++ test/common/internet.js | 2 + test/internet/test-dns-cares-domains.js | 1 + test/internet/test-dns.js | 41 +++++++++++ test/internet/test-trace-events-dns.js | 1 + 9 files changed, 226 insertions(+) diff --git a/doc/api/dns.md b/doc/api/dns.md index af71918496a883..5dc7a5230f5fec 100644 --- a/doc/api/dns.md +++ b/doc/api/dns.md @@ -129,6 +129,7 @@ The following methods from the `node:dns` module are available: * [`resolver.resolvePtr()`][`dns.resolvePtr()`] * [`resolver.resolveSoa()`][`dns.resolveSoa()`] * [`resolver.resolveSrv()`][`dns.resolveSrv()`] +* [`resolver.resolveTlsa()`][`dns.resolveTlsa()`] * [`resolver.resolveTxt()`][`dns.resolveTxt()`] * [`resolver.reverse()`][`dns.reverse()`] * [`resolver.setServers()`][`dns.setServers()`] @@ -444,6 +445,7 @@ records. The type and structure of individual results varies based on `rrtype`: | `'PTR'` | pointer records | {string} | [`dns.resolvePtr()`][] | | `'SOA'` | start of authority records | {Object} | [`dns.resolveSoa()`][] | | `'SRV'` | service records | {Object} | [`dns.resolveSrv()`][] | +| `'TLSA'` | certificate associations | {Object} | [`dns.resolveTlsa()`][] | | `'TXT'` | text records | {string\[]} | [`dns.resolveTxt()`][] | On error, `err` is an [`Error`][] object, where `err.code` is one of the @@ -543,6 +545,7 @@ will be present on the object: | `'PTR'` | `value` | | `'SOA'` | Refer to [`dns.resolveSoa()`][] | | `'SRV'` | Refer to [`dns.resolveSrv()`][] | +| `'TLSA'` | Refer to [`dns.resolveTlsa()`][] | | `'TXT'` | This type of record contains an array property called `entries` which refers to [`dns.resolveTxt()`][], e.g. `{ entries: ['...'], type: 'TXT' }` | Here is an example of the `ret` object passed to the callback: @@ -802,6 +805,41 @@ be an array of objects with the following properties: } ``` +## `dns.resolveTlsa(hostname, callback)` + + + + + +* `hostname` {string} +* `callback` {Function} + * `err` {Error} + * `records` {Object\[]} + + + +Uses the DNS protocol to resolve certificate associations (`TLSA` records) for +the `hostname`. The `records` argument passed to the `callback` function is an +array of objects with these properties: + +* `certUsage` +* `selector` +* `match` +* `data` + + + +```js +{ + certUsage: 3, + selector: 1, + match: 1, + data: [ArrayBuffer] +} +``` + ## `dns.resolveTxt(hostname, callback)` + +* `hostname` {string} + +Uses the DNS protocol to resolve certificate associations (`TLSA` records) for +the `hostname`. On success, the `Promise` is resolved with an array of objects +with these properties: + +* `certUsage` +* `selector` +* `match` +* `data` + + + +```js +{ + certUsage: 3, + selector: 1, + match: 1, + data: [ArrayBuffer] +} +``` + ### `dnsPromises.resolveTxt(hostname)`