Skip to content

Commit

Permalink
release 1.1.1 (#31)
Browse files Browse the repository at this point in the history
* dnskey: expand algorithms per RFC 8624
* test(dnskey): update fail test
* feat(HINFO): added to/from tinydns
  • Loading branch information
msimerson authored Apr 29, 2022
1 parent d9cb905 commit 2a5fd2d
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
#### 1.N.N - YYYY-MM-DD


#### 1.1.1 - 2022-04-28

- feat(DNSKEY): expanded algo from 1-5 to 1-16 (RFC 8624)
- warn if outside that range, not error


#### 1.1.0 - 2022-04-22

- feat(tinydns): add ipv4toOctal, octalToIPv4, base64toOctal, octalToBase64
Expand Down
5 changes: 2 additions & 3 deletions DEVELOP.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@


# Release process

in your feature branch:
in your feature branch: (git checkout -b release-N.N.N)

- make your changes
- git add .
- .release/do.sh {major|minor|patch}
- fill in the blanks in CHANGES.md
- fill in the blanks in CHANGELOG.md
- .release/push.sh

Upon merge to `master`:
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ PRs are welcome, especially PRs with tests.
| **DNAME** |:white_check_mark:|:white_check_mark:|:white_check_mark:|:white_check_mark:|
| **DNSKEY** |:white_check_mark:|:white_check_mark:|:white_check_mark:|:white_check_mark:|
| **DS** |:white_check_mark:|:white_check_mark:|:white_check_mark:|:white_check_mark:|
| **HINFO** |:white_check_mark:| |:white_check_mark:| |
| **HINFO** |:white_check_mark:|:white_check_mark:|:white_check_mark:|:white_check_mark:|
|**IPSECKEY**|:white_check_mark:|:white_check_mark:|:white_check_mark:|:white_check_mark:|
| **KEY** | | | | |
| **LOC** |:white_check_mark:|:white_check_mark:|:white_check_mark:|:white_check_mark:|
Expand Down Expand Up @@ -262,7 +262,6 @@ PRs are welcome, especially PRs with tests.
## DEVELOP

- this package has no dependencies. That's no accident.
- this will be used by a node.js app & a browser based app
- [x] ES6 modules
- this will be used by a node.js app & a browser based app, so ES modules
- platform independence is a goal
- [x] CI tests are on linux, windows, and macos
22 changes: 22 additions & 0 deletions lib/tinydns.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ export function octalToUInt32 (str) {
return b.readUInt32BE()
}

export function packString (str) {
return str.match(/(.{1,255})/g).map(s => {
const len = Buffer.alloc(1)
len.writeUInt8(s.length)
return `${UInt8toOctal(len.readUInt8(0))}${s}`
}).join('')
}

export function unpackString (str) {
const asBuf = Buffer.from(octalToChar(str.toString()))
const res = []
let pos = 0
let len
while ((len = asBuf.readUInt8(pos))) { // encoded length byte
pos++
res.push(asBuf.slice(pos, pos + len).toString())
pos = +(pos + len)
if (pos >= asBuf.length) break
}
return res
}

export function packDomainName (fqdn) {
const labelRegEx = new RegExp(/[^A-Za-z0-9-.]/, 'g')

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dns-resource-record",
"version": "1.1.0",
"version": "1.1.1",
"description": "DNS Resource Records",
"main": "index.js",
"type": "module",
Expand Down
15 changes: 11 additions & 4 deletions rr/dnskey.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ export default class DNSKEY extends RR {
/****** Resource record specific setters *******/
setFlags (val) {
// a 2 octet Flags Field
// the possible values are: 0, 256, and 257 RFC 4034
this.is16bitInt('DNSKEY', 'flags', val)

// the possible values are: 0, 256, and 257; RFC 4034
if (![ 0, 256, 257 ].includes(val)) throw new Error(`DNSKEY: flags invalid, ${this.citeRFC()}`)

this.set('flags', val)
}

setProtocol (val) {
// 1 octet
this.is8bitInt('DNSKEY', 'protocol', val)

// The Protocol Field MUST be represented as an unsigned decimal integer with a value of 3.
if (![ 3 ].includes(val)) throw new Error(`DNSKEY: protocol invalid, ${this.citeRFC()}`)

Expand All @@ -27,9 +31,12 @@ export default class DNSKEY extends RR {

setAlgorithm (val) {
// 1 octet
this.is8bitInt('DNSKEY', 'algorithm', val)

// https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml
// 1=RSA/MD5, 2=DH, 3=DSA/SHA-1, 4=EC, 5=RSA/SHA-1
if (![ 1,2,3,4,5,253,254 ].includes(val))
throw new Error(`DNSKEY: algorithm invalid, ${this.citeRFC()}`)
if (![ ...Array(16).keys(),253,254 ].includes(val))
console.error(`DNSKEY: algorithm (${val}) not recognized, ${this.citeRFC()}`)

this.set('algorithm', val)
}
Expand All @@ -49,7 +56,7 @@ export default class DNSKEY extends RR {
}

getRFCs () {
return [ 4034 ]
return [ 4034, 6014, 8624 ]
}

getTypeId () {
Expand Down
30 changes: 26 additions & 4 deletions rr/hinfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import RR from '../rr.js'

import * as TINYDNS from '../lib/tinydns.js'

export default class HINFO extends RR {
constructor (opts) {
super(opts)
Expand All @@ -26,7 +28,7 @@ export default class HINFO extends RR {
}

getRFCs () {
return [ 8482 ]
return [ 1034, 1035, 8482 ]
}

getTypeId () {
Expand Down Expand Up @@ -54,9 +56,29 @@ export default class HINFO extends RR {
})
}

// fromTinydns (opts) {
// // HINFO via generic, :fqdn:n:rdata:ttl:timestamp:lo
// }
fromTinydns (opts) {
// HINFO via generic, :fqdn:n:rdata:ttl:timestamp:lo
const [ fqdn, , rdata, ttl, ts, loc ] = opts.tinyline.substring(1).split(':')
const [ cpu, os ] = [ ...TINYDNS.unpackString(rdata) ]

return new this.constructor({
owner : this.fullyQualify(fqdn),
ttl : parseInt(ttl, 10),
type : 'HINFO',
cpu,
os,
timestamp: ts,
location : loc !== '' && loc !== '\n' ? loc : '',
})
}

/****** EXPORTERS *******/
toTinydns () {
return this.getTinydnsGeneric(
[
TINYDNS.packString(this.get('cpu')),
TINYDNS.packString(this.get('os')),
].join('')
)
}
}
4 changes: 2 additions & 2 deletions test/dnskey.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const invalidRecords = [
{
...defaults,
owner : 'test.example.com.',
algorithm: 6, // invalid
msg : /flags invalid/,
algorithm: 257, // invalid
msg : /flags must be a 16-bit integer/,
},
]

Expand Down
10 changes: 5 additions & 5 deletions test/hinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const validRecords = [
cpu : 'PDP-11/73',
os : 'UNIX',
testB: 'server-under-my-desk.example.com.\t86400\tIN\tHINFO\t"PDP-11/73"\t"UNIX"\n',
// testT : ':server-under-my-desk:13: :86400::\n',
testT: ':server-under-my-desk.example.com:13:\\011PDP-11/73\\004UNIX:86400::\n',
},
{
...defaults,
owner: 'sri-nic.arpa.',
cpu : 'DEC-2060',
os : 'TOPS20',
testB: 'sri-nic.arpa.\t86400\tIN\tHINFO\t"DEC-2060"\t"TOPS20"\n',
// testT : ':server-under-my-desk:13: :86400::\n',
testT: ':sri-nic.arpa:13:\\010DEC-2060\\006TOPS20:86400::\n',
},
]

Expand All @@ -45,10 +45,10 @@ describe('HINFO record', function () {
base.getTypeId(HINFO, 13)

base.toBind(HINFO, validRecords)
// base.toTinydns(HINFO, validRecords)
base.toTinydns(HINFO, validRecords)

// base.fromBind(HINFO, validRecords)
// base.fromTinydns(HINFO, validRecords)
base.fromBind(HINFO, validRecords)
base.fromTinydns(HINFO, validRecords)

for (const val of validRecords) {
it.skip(`imports tinydns HINFO (generic) record (${val.owner})`, async function () {
Expand Down
13 changes: 12 additions & 1 deletion test/tinydns.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ describe('TINYDNS', function () {
})
})


describe('UInt32toOctal', function () {
it('converts a 32-bit number to escaped octal', function (done) {
assert.strictEqual(TINYDNS.UInt32toOctal(2319310648), '\\212\\075\\337\\070')
Expand Down Expand Up @@ -126,4 +125,16 @@ describe('TINYDNS', function () {
})
}
})

describe('packString', function () {
it(`packs a string to wire format`, async () => {
assert.strictEqual(TINYDNS.packString('matt wuz here'), '\\015matt wuz here')
})
})

describe('uppackString', function () {
it(`uppacks a string from wire format`, async () => {
assert.deepStrictEqual(TINYDNS.unpackString('\\015matt wuz here'), [ 'matt wuz here' ])
})
})
})

0 comments on commit 2a5fd2d

Please sign in to comment.