-
Notifications
You must be signed in to change notification settings - Fork 1
/
createDS.js
63 lines (53 loc) · 1.3 KB
/
createDS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { Zone, wire, dnssec } = require('bns');
const { SOARecord, Record, codes, types } = wire;
module.exports = { createDS, sendSoa };
function createDS (publicKey) {
publicKey = publicKey || '' +
'T9cURJ2M/Mz9q6UsZNY+Ospyvj+Uv+tgrrWkLtPQwgU/Xu5Yk0l02Sn5ua2x' +
'AQfEYIzRO6v5iA+BejMeEwNP4Q==';
const ksk = Record.fromJSON({
name: '.',
ttl: 10800,
class: 'IN',
type: 'DNSKEY',
data: {
flags: 257,
protocol: 3,
algorithm: 13,
publicKey
}
});
return dnssec.createDS(ksk, dnssec.hashes.SHA256);
}
const DEFAULT_TTL = 21600;
const serial = () => {
const date = new Date();
const y = date.getUTCFullYear() * 1e6;
const m = (date.getUTCMonth() + 1) * 1e4;
const d = date.getUTCDate() * 1e2;
const h = date.getUTCHours();
return y + m + d + h;
};
function toSOA () {
const rr = new Record();
const rd = new SOARecord();
rr.name = '.';
rr.type = types.SOA;
rr.ttl = 86400;
rr.data = rd;
rd.ns = '.';
rd.mbox = '.';
rd.serial = serial();
rd.refresh = 1800;
rd.retry = 900;
rd.expire = 604800;
rd.minttl = DEFAULT_TTL;
return rr;
}
function sendSoa () {
const res = new wire.Message();
res.aa = true;
res.authority.push(toSOA());
// this.ns.signRRSet(res.authority, wire.types.SOA) // get signing right
return res;
}