-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnssec.js
97 lines (80 loc) · 2.54 KB
/
dnssec.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
/*!
* key.js - dnssec key for hsd
* Copyright (c) 2017-2018, Christopher Jeffrey (MIT License).
* https://github.com/handshake-org/hsd
*/
'use strict';
const { dnssec, wire } = require('bns');
const { Record, types } = wire;
// pub: 034fd714449d8cfcccfdaba52c64d63e3aca72be3f94bfeb60aeb5a42ed3d0c205
exports.kskPriv = Buffer.from(
'1c74c825c5b0f08cf6be846bfc93c423f03e3e1f6202fb2d96474b1520bbafad',
'hex');
// pub: 032399cfb3a72515ad609f09fd22954319d24b7c438dce00f535c7ee13010856e2
exports.zskPriv = Buffer.from(
'54276ff8604a3494c5c76d6651f14b289c7253ba636be4bfd7969308f48da47d',
'hex');
exports.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=='
}
});
exports.zsk = Record.fromJSON({
name: '.',
ttl: 10800,
class: 'IN',
type: 'DNSKEY',
data: {
flags: 256,
protocol: 3,
algorithm: 13,
publicKey: '' +
'I5nPs6clFa1gnwn9IpVDGdJLfEONzgD1NcfuEwEIVuIoHdZGgvVblsLNbRO+' +
'spW3nQYHg92svhy1HOjTiFBIsQ=='
}
});
// . DS 35215 13 2
// 7C50EA94A63AEECB65B510D1EAC1846C973A89D4AB292287D5A4D715136B57A3
exports.ds = dnssec.createDS(exports.ksk, dnssec.hashes.SHA256);
exports.signKSK = function signKSK (section, type) {
return dnssec.signType(section, type, exports.ksk, exports.kskPriv);
};
exports.signZSK = function signZSK (section, type) {
return dnssec.signType(section, type, exports.zsk, exports.zskPriv);
};
exports.signResponse = function signResponse (res, key = zsk, priv = zskPriv, iter = x => x) {
const answerTypes = new Set();
const authorityTypes = new Set();
const additionalTypes = new Set();
res.answer = res.answer.filter(rec => rec.type !== types.RRSIG).map(rec => {
answerTypes.add(rec.type);
return iter(rec, 'answer') || rec;
});
res.authority = res.authority.filter(rec => rec.type !== types.RRSIG).map(rec => {
authorityTypes.add(rec.type);
return iter(rec, 'authority') || rec;
});
res.additional = res.additional.filter(rec => rec.type !== types.RRSIG).map(rec => {
additionalTypes.add(rec.type);
return iter(rec, 'additional') || rec;
});
answerTypes.forEach(type => {
dnssec.signType(res.answer, type, key, priv, null);
});
authorityTypes.forEach(type => {
dnssec.signType(res.authority, type, key, priv);
});
additionalTypes.forEach(type => {
dnssec.signType(res.additional, type, key, priv, null);
});
return res;
};