Comparing version 1.1.1 to 1.2.0
39
index.js
@@ -19,2 +19,12 @@ "use strict"; | ||
// normalize a DNS name | ||
function normalize(name) { | ||
name = (name || "").toLowerCase(); | ||
if (name.endsWith(".") && name.length > 1) { | ||
name = name.substring(0, name.length - 1); | ||
} | ||
return name; | ||
} | ||
// resolve a CAA record, possibly via recursion | ||
const resolve = async ({name, socket, server, port}) => { | ||
@@ -57,3 +67,3 @@ const query = util.promisify(socket.query.bind(socket)); | ||
module.exports = async (name, opts = {}) => { | ||
const caa = module.exports = async (name, opts = {}) => { | ||
if (typeof name !== "string") { | ||
@@ -63,3 +73,2 @@ throw new Error("Expected a string"); | ||
// obtain server from options or system | ||
let server; | ||
@@ -73,11 +82,5 @@ if (opts.server) { | ||
name = normalize(name); | ||
const socket = dnsSocket(); | ||
const port = opts.port || 53; | ||
// trim trailing dot if present | ||
if (name.endsWith(".")) { | ||
name = name.substring(0, name.length - 1); | ||
} | ||
// climb up the DNS name tree | ||
const socket = dnsSocket(); | ||
const caa = await resolve({name, socket, server, port}); | ||
@@ -87,1 +90,17 @@ socket.destroy(); | ||
}; | ||
caa.matches = async (name, ca, opts = {}) => { | ||
const caas = await caa(name, opts); | ||
if (!caas.length) { | ||
return true; | ||
} | ||
const names = caas.filter(caa => caa && caa.tag === "issue").map(name => normalize(name.value)); | ||
if (names.includes(";")) { | ||
return false; | ||
} | ||
return !names.length || names.includes(normalize(ca)); | ||
}; |
{ | ||
"name": "caa", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "rfc6844-conform CAA record lookup", | ||
@@ -24,6 +24,6 @@ "author": "silverwind <me@silverwind.io>", | ||
"dependencies": { | ||
"dns-socket": "^4.1.0" | ||
"dns-socket": "^4.1.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^5.2.0", | ||
"eslint": "^5.3.0", | ||
"eslint-config-silverwind": "^1.0.45", | ||
@@ -30,0 +30,0 @@ "updates": "^4.1.2" |
@@ -17,13 +17,8 @@ # caa | ||
const records = await caa('subdomain.example.com'); | ||
console.log(records); | ||
console.log(await caa('subdomain.example.com')); | ||
// => [{flags: 0, tag: 'issue', tag: 'issue', value: 'letsencrypt.org', issuerCritical: false}] | ||
// [ | ||
// { | ||
// flags: 0, | ||
// tag: 'issue', | ||
// value: 'letsencrypt.org', | ||
// issuerCritical: false | ||
// } | ||
// ] | ||
console.log(await caa.matches('subdomain.example.com', 'letsencrypt.org')); | ||
// => true | ||
``` | ||
@@ -33,10 +28,16 @@ | ||
### caa(name, [{server, port}]) | ||
### caa(name, {server, port}) | ||
Retrieve the CAA records which apply to the given `name`. Returns a [`CAA` object](https://github.com/mafintosh/dns-packet/#caa). Optionally, a DNS `server` and `port` can be supplied, defaulting to the system resolver and port 53. | ||
Retrieve the CAA records which apply to the given `name`. Returns a [`CAA` object](https://github.com/mafintosh/dns-packet/#caa). | ||
### caa(name, ca, {server, port}) | ||
Test if the CAA record for a given `name` matches a given `ca`. | ||
#### Options | ||
Optionally, a DNS `server` and `port` can be supplied, defaulting to the first system resolver and port 53. | ||
## License | ||
© [silverwind](https://github.com/silverwind), distributed under BSD licence | ||
Based on previous work by [Felipe Apostol](https://github.com/flipjs) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5840
85
42
Updateddns-socket@^4.1.1