Repository navigation
Expand file tree
/
Copy pathgooddanetlsa.js
More file actions
155 lines (131 loc) · 6.38 KB
/
Copy pathgooddanetlsa.js
File metadata and controls
155 lines (131 loc) · 6.38 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Sample to demonstrate the usage of getdns nodejs API and host it
// in an express web context.
// Install from http://expressjs.com/ and follow instructions to setup in the Readme
//
//
// Replace the relative paths with your own path for the install of expressjs
var express = require('../../expressjs/express');
var app = module.exports = express();
// You need getdns and getdns node installed prior to running this sample
// You can install this sample in the root directory of the getdnsnode install directory
// getdns includes. set LD_LIBRARY_PATH to /usr/local/lib
var getdns = require('../../getdnsnode/branch15/getdns-node/getdns');
var options = {
// request timeout time in millis
timeout : 5000,
// always return dnssec status
return_dnssec_status : true,
dnssec_return_only_secure : true,
dnssec_return_validation_chain : true
};
var repl = function(key, value){
if(key == "rdata_raw") {
return undefined;
}
if(key == "signature"){
return undefined;
}
if(key == "certificate_association_data"){
return undefined;
}
return value;
};
/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/
var Base64 = {
// private property
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
// public method for encoding
encode : function (input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
if (!input) return "";
//input = Base64._utf8_encode(input);
while (i < input.length) {
chr1 = input[i++];
chr2 = input[i++];
chr3 = input[i++];
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
}
return output;
},
}
// getdns query callback
var callback = function(err, result) {
process.stdout.write("testing app err = " + JSON.stringify(err));
// if not null, err is an object w/ msg and code.
// code maps to a GETDNS_CALLBACK_TYPE
// result is a response dictionary
var res1 = "<h1>Response tree</h1>";
res1 += "<h2>Question: _443._tcp.good.dane.verisignlabs.com TLSA</h2>";
res1 += "<p>This web page is created using nodejs, the getdns API, in the expressjs framework. Source code available in github/getdnsapi/getdnsnodejsdanesample.</p>";
if (result == null ) {
res1 += "<p>No result</p>";
process.stdout.write("no result\n");
} else {
for ( var index in result.replies_tree) {
process.stdout.write("tree = " + JSON.stringify(result.replies_tree[index], 0 , 2));
res1 += "<h3>QUESTION</h3><pre> " + JSON.stringify(result.replies_tree[index].question, 0, 4) + "</pre>";
res1 += "<h3>HEADER</h3><pre> " + JSON.stringify(result.replies_tree[index].header, 0, 2) + "</pre>";
if (result.replies_tree[index].dnssec_status == getdns.DNSSEC_SECURE)
res1 += "<h3>DNSSEC_STATUS</h3><pre> " + "GETDNS_DNSSEC_SECURE" + "</pre>";
else if (result.replies_tree[index].dnssec_status == getdns.DNSSEC_INSECURE)
res1 += "<h3>DNSSEC_STATUS</h3><pre> " + "GETDNS_DNSSEC_INSECURE" + "</pre>";
res1 += "<h3>CANONICAL_NAME</h3><pre> " + JSON.stringify(result.replies_tree[index].canonical_name, 0, 2) + "</pre>";
for ( var index1 in result.replies_tree[index].answer) {
res1 += "<h3>ANSWER</h3><pre> " + JSON.stringify(result.replies_tree[index].answer[index1], repl, 2) + "</pre>";
if (result.replies_tree[index].answer[index1].rdata.certificate_association_data)
res1 += "<h3>CERTIFICATE ASSOCIATION DATA</h3><pre> " + Base64.encode(result.replies_tree[index].answer[index1].rdata.certificate_association_data) + "</pre>";
if (result.replies_tree[index].answer[index1].rdata.signature)
res1 += "<h3>TLSA </h3><pre> " + Base64.encode(result.replies_tree[index].answer[index1].rdata.signature) + "</pre>";
}
for ( var index1 in result.replies_tree[index].authority) {
res1 += "<h3>AUTHORITY</h3><pre> " + JSON.stringify(result.replies_tree[index].authority[index1], repl, 2) + "</pre>";
if (result.replies_tree[index].authority[index1].rdata.certificate_association_data)
res1 += "<h3>CERTIFICATE ASSOCIATION DATA</h3><pre> " + Base64.encode(result.replies_tree[index].authority[index1].rdata.certificate_association_data) + "</pre>";
if (result.replies_tree[index].authority[index1].rdata.signature)
res1 += "<h3>TLSA </h3><pre> " + Base64.encode(result.replies_tree[index].authority[index1].rdata.signature) + "</pre>";
for ( var index1 in result.replies_tree[index].additional) {
res1 += "<h3>AUTHORITY</h3><pre> " + JSON.stringify(result.replies_tree[index].additional[index1], repl, 2) + "</pre>";
if (result.replies_tree[index].additional[index1].rdata.certificate_association_data)
res1 += "<h3>CERTIFICATE ASSOCIATION DATA</h3><pre> " + Base64.encode(result.replies_tree[index].additional[index1].rdata.certificate_association_data) + "</pre>";
if (result.replies_tree[index].additional[index1].rdata.signature)
res1 += "<h3>TLSA </h3><pre> " + Base64.encode(result.replies_tree[index].additional[index1].rdata.signature) + "</pre>";
}
}
}
app.get('/', function(req, res){
res.send(res1);
});
// when done with a context, it must be explicitly destroyed
context.destroy();
}
}
// create the context with the above options
var context = getdns.createContext(options);
// getdns general
// last argument must be a callback
var transactionId = context.lookup("_443._tcp.good.dane.verisignlabs.com", getdns.RRTYPE_TLSA, callback);
// extensions are passed as dictionaries
// where the value for on / off are normal bools
//context.getAddress("cnn.com", { return_both_v4_and_v6 : true }, callback);
if (!module.parent) {
app.listen(50000);
console.log('Express started on port 50000');
}