forked from lukeburns/hipr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
101 lines (75 loc) · 1.96 KB
/
example.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const { RecursiveServer } = require('./index')
const { wire, dnssec } = require('bns-plus')
const { SOARecord, Record, codes, types, typesByVal } = wire
const server = new RecursiveServer({
tcp: true,
inet6: true,
edns: true,
dnssec: true
})
server.parseOptions({ dnssec: true })
server.resolver.setStub('149.248.21.56', 53, createDS())
server.resolver.use(':data._alias.', async (params, name, type, res) => {
const { data } = params
console.log('[alias]', name, type, data)
res.code = codes.REFUSED
return res
})
server.resolver.use(':data.:protocol(_hyper|ns.direct)(.*)', async (params, name, type, res) => {
const { protocol, data } = params
console.log(`[${protocol}]`, name, type, data)
res.code = codes.REFUSED
return res
})
server.bind(5333, '127.0.0.1')
// ---
function createDS () {
const ksk = Record.fromJSON({
name: '.',
ttl: 10800,
class: 'IN',
type: 'DNSKEY',
data: {
flags: 257,
protocol: 3,
algorithm: 13,
publicKey: ''
+ 'T9cURJ2M/Mz9q6UsZNY+Ospyvj+Uv+tgrrWkLtPQwgU/Xu5Yk0l02Sn5ua2x'
+ 'AQfEYIzRO6v5iA+BejMeEwNP4Q=='
}
})
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
}