@nictool/dns-resource-record 1.1.7 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -43
- package/README.md +48 -48
- package/index.js +83 -29
- package/lib/tinydns.js +68 -61
- package/package.json +1 -2
- package/rr/a.js +32 -23
- package/rr/aaaa.js +49 -35
- package/rr/caa.js +56 -44
- package/rr/cert.js +21 -19
- package/rr/cname.js +22 -23
- package/rr/dname.js +23 -23
- package/rr/dnskey.js +45 -43
- package/rr/ds.js +40 -40
- package/rr/hinfo.js +29 -28
- package/rr/https.js +62 -0
- package/rr/ipseckey.js +69 -50
- package/rr/key.js +23 -23
- package/rr/loc.js +71 -58
- package/rr/mx.js +41 -27
- package/rr/naptr.js +52 -53
- package/rr/ns.js +26 -23
- package/rr/nsec.js +24 -20
- package/rr/nsec3.js +59 -46
- package/rr/nsec3param.js +24 -26
- package/rr/nxt.js +65 -0
- package/rr/openpgpkey.js +18 -15
- package/rr/ptr.js +20 -21
- package/rr/rrsig.js +28 -23
- package/rr/sig.js +25 -20
- package/rr/smimea.js +36 -31
- package/rr/soa.js +56 -42
- package/rr/spf.js +21 -18
- package/rr/srv.js +45 -45
- package/rr/sshfp.js +30 -31
- package/rr/svcb.js +64 -0
- package/rr/tlsa.js +50 -45
- package/rr/tsig.js +56 -0
- package/rr/txt.js +42 -35
- package/rr/uri.js +33 -33
- package/rr/wks.js +45 -0
- package/rr.js +133 -87
- package/.codeclimate.yml +0 -25
- package/DEVELOP.md +0 -23
- package/test/a.js +0 -76
- package/test/aaaa.js +0 -79
- package/test/base.js +0 -138
- package/test/caa.js +0 -104
- package/test/cert.js +0 -48
- package/test/cname.js +0 -41
- package/test/dname.js +0 -53
- package/test/dnskey.js +0 -44
- package/test/ds.js +0 -44
- package/test/fake.js +0 -26
- package/test/hinfo.js +0 -75
- package/test/ipseckey.js +0 -115
- package/test/key.js +0 -37
- package/test/loc.js +0 -71
- package/test/mx.js +0 -75
- package/test/naptr.js +0 -40
- package/test/ns.js +0 -53
- package/test/nsec.js +0 -38
- package/test/nsec3.js +0 -40
- package/test/nsec3param.js +0 -26
- package/test/openpgpkey.js +0 -35
- package/test/ptr.js +0 -54
- package/test/rr.js +0 -196
- package/test/smimea.js +0 -45
- package/test/soa.js +0 -77
- package/test/spf.js +0 -48
- package/test/srv.js +0 -81
- package/test/sshfp.js +0 -62
- package/test/tinydns.js +0 -140
- package/test/tlsa.js +0 -54
- package/test/txt.js +0 -70
- package/test/uri.js +0 -61
package/rr/ds.js
CHANGED
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
|
|
2
1
|
import RR from '../rr.js'
|
|
3
2
|
|
|
4
3
|
import * as TINYDNS from '../lib/tinydns.js'
|
|
5
4
|
|
|
6
5
|
export default class DS extends RR {
|
|
7
|
-
constructor
|
|
6
|
+
constructor(opts) {
|
|
8
7
|
super(opts)
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
/****** Resource record specific setters *******/
|
|
12
|
-
setKeyTag
|
|
11
|
+
setKeyTag(val) {
|
|
13
12
|
// a 2 octet Key Tag field...in network byte order
|
|
14
|
-
if (!val)
|
|
15
|
-
if (val.length > 2)
|
|
13
|
+
if (!val) this.throwHelp(`DS: key tag is required`)
|
|
14
|
+
if (val.length > 2) this.throwHelp(`DS: key tag is too long`)
|
|
16
15
|
|
|
17
16
|
this.set('key tag', val)
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
setAlgorithm
|
|
19
|
+
setAlgorithm(val) {
|
|
21
20
|
// 1=RSA/MD5, 2=DH, 3=DSA/SHA-1, 4=EC, 5=RSA/SHA-1
|
|
22
|
-
if (![
|
|
23
|
-
|
|
21
|
+
if (![1, 2, 3, 4, 5, 253, 254].includes(val))
|
|
22
|
+
this.throwHelp(`DS: algorithm invalid`)
|
|
24
23
|
|
|
25
24
|
this.set('algorithm', val)
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
setDigestType
|
|
29
|
-
if (![
|
|
27
|
+
setDigestType(val) {
|
|
28
|
+
if (![1, 2].includes(val)) this.throwHelp(`DS: digest type invalid`)
|
|
30
29
|
|
|
31
30
|
this.set('digest type', val)
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
setDigest
|
|
35
|
-
if (!val)
|
|
33
|
+
setDigest(val) {
|
|
34
|
+
if (!val) this.throwHelp(`DS: digest is required`)
|
|
36
35
|
|
|
37
36
|
this.set('digest', val)
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
getDescription
|
|
39
|
+
getDescription() {
|
|
41
40
|
return 'Delegation Signer'
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
getRdataFields
|
|
45
|
-
return [
|
|
43
|
+
getRdataFields(arg) {
|
|
44
|
+
return ['key tag', 'algorithm', 'digest type', 'digest']
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
getRFCs
|
|
49
|
-
return [
|
|
47
|
+
getRFCs() {
|
|
48
|
+
return [4034, 4509]
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
getTypeId
|
|
51
|
+
getTypeId() {
|
|
53
52
|
return 43
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
/****** IMPORTERS *******/
|
|
57
56
|
|
|
58
|
-
fromBind
|
|
57
|
+
fromBind(opts) {
|
|
59
58
|
// test.example.com 3600 IN DS Key Tag Algorithm, Digest Type, Digest
|
|
60
|
-
const [
|
|
59
|
+
const [owner, ttl, c, type, keytag, algorithm, digesttype] =
|
|
60
|
+
opts.bindline.split(/\s+/)
|
|
61
61
|
return new DS({
|
|
62
62
|
owner,
|
|
63
|
-
ttl
|
|
64
|
-
class
|
|
63
|
+
ttl: parseInt(ttl, 10),
|
|
64
|
+
class: c,
|
|
65
65
|
type,
|
|
66
|
-
'key tag'
|
|
67
|
-
algorithm
|
|
66
|
+
'key tag': parseInt(keytag, 10),
|
|
67
|
+
algorithm: parseInt(algorithm, 10),
|
|
68
68
|
'digest type': parseInt(digesttype, 10),
|
|
69
|
-
digest
|
|
69
|
+
digest: opts.bindline.split(/\s+/).slice(7).join(' ').trim(),
|
|
70
70
|
})
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
fromTinydns
|
|
74
|
-
const [
|
|
75
|
-
if (n != 43)
|
|
73
|
+
fromTinydns(opts) {
|
|
74
|
+
const [fqdn, n, rdata, ttl, ts, loc] = opts.tinyline.substring(1).split(':')
|
|
75
|
+
if (n != 43) this.throwHelp('DS fromTinydns, invalid n')
|
|
76
76
|
|
|
77
77
|
const binRdata = Buffer.from(TINYDNS.octalToChar(rdata), 'binary')
|
|
78
78
|
|
|
79
79
|
return new DS({
|
|
80
|
-
owner
|
|
81
|
-
ttl
|
|
82
|
-
type
|
|
83
|
-
'key tag'
|
|
84
|
-
algorithm
|
|
80
|
+
owner: this.fullyQualify(fqdn),
|
|
81
|
+
ttl: parseInt(ttl, 10),
|
|
82
|
+
type: 'DS',
|
|
83
|
+
'key tag': binRdata.readUInt16BE(0),
|
|
84
|
+
algorithm: binRdata.readUInt8(2),
|
|
85
85
|
'digest type': binRdata.readUInt8(3),
|
|
86
|
-
digest
|
|
87
|
-
timestamp
|
|
88
|
-
location
|
|
86
|
+
digest: binRdata.slice(4).toString(),
|
|
87
|
+
timestamp: ts,
|
|
88
|
+
location: loc !== '' && loc !== '\n' ? loc : '',
|
|
89
89
|
})
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/****** EXPORTERS *******/
|
|
93
93
|
|
|
94
|
-
toTinydns
|
|
94
|
+
toTinydns() {
|
|
95
95
|
const rdataRe = new RegExp(/[\r\n\t:\\/]/, 'g')
|
|
96
96
|
|
|
97
97
|
return this.getTinydnsGeneric(
|
|
98
98
|
TINYDNS.UInt16toOctal(this.get('key tag')) +
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
TINYDNS.UInt8toOctal(this.get('algorithm')) +
|
|
100
|
+
TINYDNS.UInt8toOctal(this.get('digest type')) +
|
|
101
|
+
TINYDNS.escapeOctal(rdataRe, this.get('digest')),
|
|
102
102
|
)
|
|
103
103
|
}
|
|
104
104
|
}
|
package/rr/hinfo.js
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
|
-
|
|
2
1
|
import RR from '../rr.js'
|
|
3
2
|
|
|
4
3
|
import * as TINYDNS from '../lib/tinydns.js'
|
|
5
4
|
|
|
6
5
|
export default class HINFO extends RR {
|
|
7
|
-
constructor
|
|
6
|
+
constructor(opts) {
|
|
8
7
|
super(opts)
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
/****** Resource record specific setters *******/
|
|
12
|
-
setCpu
|
|
13
|
-
if (val.length > 255)
|
|
11
|
+
setCpu(val) {
|
|
12
|
+
if (val.length > 255) this.throwHelp('HINFO cpu cannot exceed 255 chars')
|
|
14
13
|
this.set('cpu', val.replace(/^["']|["']$/g, ''))
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
setOs
|
|
18
|
-
if (val.length > 255)
|
|
16
|
+
setOs(val) {
|
|
17
|
+
if (val.length > 255) this.throwHelp('HINFO os cannot exceed 255 chars')
|
|
19
18
|
this.set('os', val.replace(/^["']|["']$/g, ''))
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
getDescription
|
|
21
|
+
getDescription() {
|
|
23
22
|
return 'Host Info'
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
getRdataFields
|
|
27
|
-
return [
|
|
25
|
+
getRdataFields(arg) {
|
|
26
|
+
return ['cpu', 'os']
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
getRFCs
|
|
31
|
-
return [
|
|
29
|
+
getRFCs() {
|
|
30
|
+
return [1034, 1035, 8482]
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
getTypeId
|
|
33
|
+
getTypeId() {
|
|
35
34
|
return 13
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
getQuotedFields
|
|
39
|
-
return [
|
|
37
|
+
getQuotedFields() {
|
|
38
|
+
return ['cpu', 'os']
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
/****** IMPORTERS *******/
|
|
43
|
-
fromBind
|
|
42
|
+
fromBind(opts) {
|
|
44
43
|
// test.example.com 3600 IN HINFO DEC-2060 TOPS20
|
|
45
|
-
const match = opts.bindline.match(
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const match = opts.bindline.match(
|
|
45
|
+
/([^\s]+)\s+([0-9]+)\s+(IN)\s+(HINFO)\s+("[^"]+"|[^\s]+)\s+("[^"]+"|[^\s]+)/i,
|
|
46
|
+
)
|
|
47
|
+
if (!match) this.throwHelp(`unable to parse HINFO: ${opts.bindline}`)
|
|
48
|
+
const [owner, ttl, c, type, cpu, os] = match.slice(1)
|
|
48
49
|
|
|
49
50
|
return new HINFO({
|
|
50
51
|
owner,
|
|
51
|
-
ttl
|
|
52
|
+
ttl: parseInt(ttl, 10),
|
|
52
53
|
class: c,
|
|
53
54
|
type,
|
|
54
55
|
cpu,
|
|
@@ -56,29 +57,29 @@ export default class HINFO extends RR {
|
|
|
56
57
|
})
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
fromTinydns
|
|
60
|
+
fromTinydns(opts) {
|
|
60
61
|
// HINFO via generic, :fqdn:n:rdata:ttl:timestamp:lo
|
|
61
|
-
const [
|
|
62
|
-
const [
|
|
62
|
+
const [fqdn, , rdata, ttl, ts, loc] = opts.tinyline.substring(1).split(':')
|
|
63
|
+
const [cpu, os] = [...TINYDNS.unpackString(rdata)]
|
|
63
64
|
|
|
64
65
|
return new this.constructor({
|
|
65
|
-
owner
|
|
66
|
-
ttl
|
|
67
|
-
type
|
|
66
|
+
owner: this.fullyQualify(fqdn),
|
|
67
|
+
ttl: parseInt(ttl, 10),
|
|
68
|
+
type: 'HINFO',
|
|
68
69
|
cpu,
|
|
69
70
|
os,
|
|
70
71
|
timestamp: ts,
|
|
71
|
-
location
|
|
72
|
+
location: loc !== '' && loc !== '\n' ? loc : '',
|
|
72
73
|
})
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
/****** EXPORTERS *******/
|
|
76
|
-
toTinydns
|
|
77
|
+
toTinydns() {
|
|
77
78
|
return this.getTinydnsGeneric(
|
|
78
79
|
[
|
|
79
80
|
TINYDNS.packString(this.get('cpu')),
|
|
80
81
|
TINYDNS.packString(this.get('os')),
|
|
81
|
-
].join('')
|
|
82
|
+
].join(''),
|
|
82
83
|
)
|
|
83
84
|
}
|
|
84
85
|
}
|
package/rr/https.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import RR from '../rr.js'
|
|
2
|
+
|
|
3
|
+
export default class HTTPS extends RR {
|
|
4
|
+
constructor(opts) {
|
|
5
|
+
super(opts)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/****** Resource record specific setters *******/
|
|
9
|
+
setPriority(val) {
|
|
10
|
+
this.is16bitInt('HTTPS', 'priority', val)
|
|
11
|
+
|
|
12
|
+
this.set('priority', val)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
setTargetName(val) {
|
|
16
|
+
// this.isFullyQualified('HTTPS', 'target name', val)
|
|
17
|
+
// this.isValidHostname('HTTPS', 'target name', val)
|
|
18
|
+
|
|
19
|
+
// RFC 4034: letters in the DNS names are lower cased
|
|
20
|
+
this.set('target name', val.toLowerCase())
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setParams(val) {
|
|
24
|
+
// if (!val) this.throwHelp(`HTTPS: params is required`)
|
|
25
|
+
|
|
26
|
+
this.set('params', val)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getDescription() {
|
|
30
|
+
return 'HTTP Semantics'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getRdataFields(arg) {
|
|
34
|
+
return ['priority', 'target name', 'params']
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getRFCs() {
|
|
38
|
+
return [9460]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getTypeId() {
|
|
42
|
+
return 65
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/****** IMPORTERS *******/
|
|
46
|
+
|
|
47
|
+
fromBind(opts) {
|
|
48
|
+
// test.example.com 3600 IN HTTPS Priority TargetName Params
|
|
49
|
+
const [owner, ttl, c, type, pri, fqdn] = opts.bindline.split(/\s+/)
|
|
50
|
+
return new HTTPS({
|
|
51
|
+
owner,
|
|
52
|
+
ttl: parseInt(ttl, 10),
|
|
53
|
+
class: c,
|
|
54
|
+
type,
|
|
55
|
+
priority: parseInt(pri, 10),
|
|
56
|
+
'target name': fqdn,
|
|
57
|
+
params: opts.bindline.split(/\s+/).slice(6).join(' ').trim(),
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/****** EXPORTERS *******/
|
|
62
|
+
}
|
package/rr/ipseckey.js
CHANGED
|
@@ -1,135 +1,154 @@
|
|
|
1
|
-
|
|
2
|
-
import net from 'net'
|
|
1
|
+
import net from 'node:net'
|
|
3
2
|
|
|
4
3
|
import RR from '../rr.js'
|
|
5
4
|
|
|
6
5
|
import * as TINYDNS from '../lib/tinydns.js'
|
|
7
6
|
|
|
8
7
|
export default class IPSECKEY extends RR {
|
|
9
|
-
constructor
|
|
8
|
+
constructor(opts) {
|
|
10
9
|
super(opts)
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
/****** Resource record specific setters *******/
|
|
14
|
-
setPrecedence
|
|
13
|
+
setPrecedence(val) {
|
|
15
14
|
// an 8-bit precedence for this record.
|
|
16
15
|
this.is8bitInt('IPSECKEY', 'precedence', val)
|
|
17
16
|
|
|
18
17
|
this.set('precedence', val)
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
setGatewayType
|
|
20
|
+
setGatewayType(val) {
|
|
22
21
|
// 0 (none), 1 (4-byte IPv4), 2 (16-byte IPv6), 3 (wire encoded domain name)
|
|
23
|
-
if (![
|
|
24
|
-
|
|
22
|
+
if (![0, 1, 2, 3].includes(val))
|
|
23
|
+
this.throwHelp(`IPSECKEY: Gateway Type is invalid`)
|
|
25
24
|
|
|
26
25
|
this.set('gateway type', val)
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
setAlgorithm
|
|
28
|
+
setAlgorithm(val) {
|
|
30
29
|
// unsigned int, 1 octet, values: 1=DSA, 2=RSA
|
|
31
|
-
if (![
|
|
32
|
-
throw new Error(`IPSECKEY: Algorithm invalid, ${this.citeRFC()}`)
|
|
30
|
+
if (![1, 2].includes(val)) this.throwHelp(`IPSECKEY: Algorithm invalid`)
|
|
33
31
|
|
|
34
32
|
this.set('algorithm', val)
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
setGateway
|
|
38
|
-
const gwErr = new Error(`IPSECKEY: gateway invalid (${val})
|
|
35
|
+
setGateway(val) {
|
|
36
|
+
const gwErr = new Error(`IPSECKEY: gateway invalid (${val})`)
|
|
39
37
|
switch (this.get('gateway type')) {
|
|
40
|
-
case 0:
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
case 0:
|
|
39
|
+
if (val !== '.') throw gwErr
|
|
40
|
+
break
|
|
41
|
+
case 1:
|
|
42
|
+
if (!net.isIPv4(val)) throw gwErr
|
|
43
|
+
break
|
|
44
|
+
case 2:
|
|
45
|
+
if (!net.isIPv6(val)) throw gwErr
|
|
46
|
+
break
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
this.set('gateway', val)
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
setPublickey
|
|
49
|
-
// if (val)
|
|
52
|
+
setPublickey(val) {
|
|
53
|
+
// if (val) this.throwHelp(`IPSECKEY: publickey is optional`)
|
|
50
54
|
|
|
51
55
|
this.set('publickey', val)
|
|
52
56
|
}
|
|
53
57
|
|
|
54
|
-
getDescription
|
|
58
|
+
getDescription() {
|
|
55
59
|
return 'IPsec Keying'
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
getRdataFields
|
|
59
|
-
return [
|
|
62
|
+
getRdataFields(arg) {
|
|
63
|
+
return ['precedence', 'gateway type', 'algorithm', 'gateway', 'publickey']
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
getRFCs
|
|
63
|
-
return [
|
|
66
|
+
getRFCs() {
|
|
67
|
+
return [4025]
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
getTypeId
|
|
70
|
+
getTypeId() {
|
|
67
71
|
return 45
|
|
68
72
|
}
|
|
69
73
|
|
|
74
|
+
getCanonical() {
|
|
75
|
+
return {
|
|
76
|
+
owner: '38.2.0.192.in-addr.arpa.',
|
|
77
|
+
ttl: 7200,
|
|
78
|
+
class: 'IN',
|
|
79
|
+
type: 'IPSECKEY',
|
|
80
|
+
precedence: 10,
|
|
81
|
+
'gateway type': 1,
|
|
82
|
+
algorithm: 2,
|
|
83
|
+
gateway: '192.0.2.38',
|
|
84
|
+
publickey: 'AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==',
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
70
88
|
/****** IMPORTERS *******/
|
|
71
|
-
fromBind
|
|
89
|
+
fromBind(opts) {
|
|
72
90
|
// FQDN TTL CLASS IPSECKEY Precedence GatewayType Algorithm Gateway PublicKey
|
|
73
|
-
const [
|
|
91
|
+
const [owner, ttl, c, type, prec, gwt, algo, gateway, publickey] =
|
|
92
|
+
opts.bindline.split(/\s+/)
|
|
74
93
|
return new IPSECKEY({
|
|
75
94
|
owner,
|
|
76
|
-
ttl
|
|
77
|
-
class
|
|
95
|
+
ttl: parseInt(ttl, 10),
|
|
96
|
+
class: c,
|
|
78
97
|
type,
|
|
79
|
-
precedence
|
|
80
|
-
'gateway type': parseInt(gwt,
|
|
81
|
-
algorithm
|
|
98
|
+
precedence: parseInt(prec, 10),
|
|
99
|
+
'gateway type': parseInt(gwt, 10),
|
|
100
|
+
algorithm: parseInt(algo, 10),
|
|
82
101
|
gateway,
|
|
83
102
|
publickey,
|
|
84
103
|
})
|
|
85
104
|
}
|
|
86
105
|
|
|
87
|
-
fromTinydns
|
|
88
|
-
const [
|
|
89
|
-
if (n != 45)
|
|
106
|
+
fromTinydns(opts) {
|
|
107
|
+
const [fqdn, n, rdata, ttl, ts, loc] = opts.tinyline.substring(1).split(':')
|
|
108
|
+
if (n != 45) this.throwHelp('IPSECKEY fromTinydns, invalid n')
|
|
90
109
|
|
|
91
110
|
const precedence = TINYDNS.octalToUInt8(rdata.substring(0, 4))
|
|
92
|
-
const gwType
|
|
93
|
-
const algorithm
|
|
111
|
+
const gwType = TINYDNS.octalToUInt8(rdata.substring(4, 8))
|
|
112
|
+
const algorithm = TINYDNS.octalToUInt8(rdata.substring(8, 12))
|
|
94
113
|
|
|
95
114
|
let len, gateway, octalKey
|
|
96
115
|
|
|
97
116
|
switch (gwType) {
|
|
98
|
-
case 0:
|
|
99
|
-
gateway
|
|
117
|
+
case 0: // no gateway
|
|
118
|
+
gateway = rdata.substring(12, 13) // should always be: '.'
|
|
100
119
|
octalKey = rdata.substring(13)
|
|
101
120
|
break
|
|
102
|
-
case 1:
|
|
103
|
-
gateway
|
|
121
|
+
case 1: // 4-byte IPv4 address
|
|
122
|
+
gateway = TINYDNS.octalToIPv4(rdata.substring(12, 28))
|
|
104
123
|
octalKey = rdata.substring(28)
|
|
105
124
|
break
|
|
106
|
-
case 2:
|
|
107
|
-
gateway
|
|
125
|
+
case 2: // 16-byte IPv6
|
|
126
|
+
gateway = TINYDNS.octalToHex(rdata.substring(12, 76))
|
|
108
127
|
octalKey = rdata.substring(76)
|
|
109
128
|
break
|
|
110
|
-
case 3:
|
|
111
|
-
[
|
|
129
|
+
case 3: // wire encoded domain name
|
|
130
|
+
;[gateway, len] = TINYDNS.unpackDomainName(rdata.substring(12))
|
|
112
131
|
octalKey = rdata.substring(12 + len)
|
|
113
132
|
break
|
|
114
133
|
}
|
|
115
134
|
|
|
116
135
|
return new IPSECKEY({
|
|
117
|
-
owner
|
|
118
|
-
ttl
|
|
119
|
-
type
|
|
136
|
+
owner: this.fullyQualify(fqdn),
|
|
137
|
+
ttl: parseInt(ttl, 10),
|
|
138
|
+
type: 'IPSECKEY',
|
|
120
139
|
precedence,
|
|
121
140
|
'gateway type': gwType,
|
|
122
141
|
algorithm,
|
|
123
142
|
gateway,
|
|
124
|
-
publickey
|
|
125
|
-
timestamp
|
|
126
|
-
location
|
|
143
|
+
publickey: TINYDNS.octalToBase64(octalKey),
|
|
144
|
+
timestamp: ts,
|
|
145
|
+
location: loc !== '' && loc !== '\n' ? loc : '',
|
|
127
146
|
})
|
|
128
147
|
}
|
|
129
148
|
|
|
130
149
|
/****** EXPORTERS *******/
|
|
131
150
|
|
|
132
|
-
toTinydns
|
|
151
|
+
toTinydns() {
|
|
133
152
|
const rdataRe = new RegExp(/[\r\n\t:\\/]/, 'g')
|
|
134
153
|
|
|
135
154
|
let rdata = ''
|
package/rr/key.js
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
|
|
2
1
|
import RR from '../rr.js'
|
|
3
2
|
|
|
4
3
|
export default class KEY extends RR {
|
|
5
|
-
constructor
|
|
4
|
+
constructor(opts) {
|
|
6
5
|
super(opts)
|
|
7
6
|
}
|
|
8
7
|
|
|
9
8
|
/****** Resource record specific setters *******/
|
|
10
|
-
setFlags
|
|
9
|
+
setFlags(val) {
|
|
11
10
|
// a 2 octet Flags Field
|
|
12
11
|
this.is16bitInt('KEY', 'flags', val)
|
|
13
12
|
|
|
14
13
|
this.set('flags', val)
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
setProtocol
|
|
16
|
+
setProtocol(val) {
|
|
18
17
|
// 1 octet
|
|
19
18
|
this.is8bitInt('KEY', 'protocol', val)
|
|
20
19
|
|
|
21
20
|
this.set('protocol', val)
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
setAlgorithm
|
|
23
|
+
setAlgorithm(val) {
|
|
25
24
|
// 1 octet
|
|
26
25
|
// 1=RSA/MD5, 2=DH, 3=DSA/SHA-1, 4=EC, 5=RSA/SHA-1
|
|
27
|
-
if (![
|
|
28
|
-
|
|
26
|
+
if (![1, 2, 3, 4, 5, 253, 254].includes(val))
|
|
27
|
+
this.throwHelp(`KEY: algorithm invalid`)
|
|
29
28
|
|
|
30
29
|
this.set('algorithm', val)
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
setPublickey
|
|
34
|
-
if (!val)
|
|
32
|
+
setPublickey(val) {
|
|
33
|
+
if (!val) this.throwHelp(`KEY: publickey is required`)
|
|
35
34
|
|
|
36
35
|
this.set('publickey', val)
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
getDescription
|
|
38
|
+
getDescription() {
|
|
40
39
|
return 'DNS Public Key'
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
getRdataFields
|
|
44
|
-
return [
|
|
42
|
+
getRdataFields(arg) {
|
|
43
|
+
return ['flags', 'protocol', 'algorithm', 'publickey']
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
getRFCs
|
|
48
|
-
return [
|
|
46
|
+
getRFCs() {
|
|
47
|
+
return [2535, 3445]
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
getTypeId
|
|
50
|
+
getTypeId() {
|
|
52
51
|
return 25
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
/****** IMPORTERS *******/
|
|
56
55
|
|
|
57
|
-
fromBind
|
|
56
|
+
fromBind(opts) {
|
|
58
57
|
// test.example.com 3600 IN KEY Flags Protocol Algorithm PublicKey
|
|
59
|
-
const [
|
|
58
|
+
const [owner, ttl, c, type, flags, protocol, algorithm] =
|
|
59
|
+
opts.bindline.split(/\s+/)
|
|
60
60
|
return new KEY({
|
|
61
61
|
owner,
|
|
62
|
-
ttl
|
|
63
|
-
class
|
|
64
|
-
type
|
|
65
|
-
flags
|
|
66
|
-
protocol
|
|
67
|
-
algorithm: parseInt(algorithm,
|
|
62
|
+
ttl: parseInt(ttl, 10),
|
|
63
|
+
class: c,
|
|
64
|
+
type: type,
|
|
65
|
+
flags: parseInt(flags, 10),
|
|
66
|
+
protocol: parseInt(protocol, 10),
|
|
67
|
+
algorithm: parseInt(algorithm, 10),
|
|
68
68
|
publickey: opts.bindline.split(/\s+/).slice(7).join(' ').trim(),
|
|
69
69
|
})
|
|
70
70
|
}
|