-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
131 lines (106 loc) · 4.01 KB
/
index.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
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
var mod = require('./em-x509');
function cppVectorToArray(vector) {
var out = [];
for(var i = 0;i < vector.size();++i)
out.push(vector.get(i));
vector.delete();
return out;
}
function cppMapToObject(map) {
var keys = cppVectorToArray(map.keys());
var out = {};
keys.forEach(function(key) {
out[key] = map.get(key);
});
map.delete();
return out;
}
function parseCert(str) {
if(str.length > 65536) {
throw new Error("Certificate data larger than 65536");
}
try {
var out = mod.parseCert(new Buffer(str, 'utf8').toString('binary'));
} catch(err) {
console.log("DUPA!");
process.exit(1);
}
out.altNames = cppVectorToArray(out.altNames);
out.ocspList = cppVectorToArray(out.ocspList);
out.subject = cppMapToObject(out.subject);
out.issuer = cppMapToObject(out.issuer);
if(out.error) {
throw new Error(out.error);
} else {
delete out.error;
}
return out;
}
function parseKey(str) {
if(str.length > 65536) {
throw new Error("Key data larger than 65536");
}
try {
var out = mod.parseKey(new Buffer(str, 'utf8').toString('binary'));
} catch(err) {
console.log("DUPA2!");
process.exit(1);
}
if(out.error) {
throw new Error(out.error);
} else {
delete out.error;
}
return out;
}
module.exports = {
parseCert: parseCert,
parseKey: parseKey,
info: mod.info
};
// try {
// var certificate =
// '-----BEGIN CERTIFICATE-----\n' +
// 'MIIFRTCCBC2gAwIBAgIHJ6yuMLnzIzANBgkqhkiG9w0BAQUFADCByjELMAkGA1UE\n' +
// 'BhMCVVMxEDAOBgNVBAgTB0FyaXpv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wOTA3BggrBgEFBQcCARYraHR0cDovL2NlcnRpZmljYXRl\n' +
// 'cy5nb2RhZGR5LmNvbS9yZXBvc2l0b3J5LzCBgAYIKwYBBQUHAQEEdDByMCQGCCsG\n' +
// 'AQUFBzABhhhodHRwOi8vb2NzcC5nb2RhZGR5LmNvbS8wSgYIKwYBBQUHMAKGPmh0\n' +
// 'dHA6Ly9jZXJ0aWZpY2F0ZXMuZ29kYWRkeS5jb20vcmVwb3NpdG9yeS9nZF9pbnRl\n' +
// 'cm1lZGlhdGUuY3J0MB8GA1UdIwQYMBaAFP2sYTKTbEXW4u6FX5q653aZaMznMCcG\n' +
// 'A1UdEQQgMB6CD3d3dy5hY2FsaW5lLmNvbYILYWNhbGluZS5jb20wHQYDVR0OBBYE\n' +
// 'FOZhFE5aS1EMTmxePHlhZdS9ZJS+MA0GCSqGSIb3DQEBBQUAA4IBAQBWtSoAXqwS\n' +
// 'lGHM199r4mZ8aPBgPEm8IJipk/qR4sbcSu2GdCChxpyu459tIUhOh+/noHc1Ubfx\n' +
// '+e7W96kX1HMQETYSC8FWn6LVTURRWwA/NIqM4AEGO+d3qwwchmw6pZX7R3+4DZ8f\n' +
// '3IjOuovhqGt0EJEPRKqzbFzrjFCoRYpgn52aijBdZGLJaPvZOKT5fJ6ntsbgO0xK\n' +
// 'dd9L2ODL/CJzS/RRRhO0k76vCq88kX1pham8yXH6mYLcCrUcWY1HcgC/y/5EESWH\n' +
// 'Y5+UfLaeUH5QU3Wtg2qwo5fUDG8ox8PlNXKEs6u38/x84GKJdOmpzAP8/a/HPECM\n' +
// 'S0cBxC+UItcO\n' +
// '-----END CERTIFICATE-----\n';
// // setInterval(function() {
// var beginDate = new Date();
// for(var i = 0;i < 10000;++i) {
// var out = parseCert(certificate);
// }
// var endDate = new Date();
// //console.log(out);
// console.log(endDate.getTime() - beginDate.getTime());
// //}, 1000);
// } catch(ex) {
// console.log(ex, "aa");
// }
// console.log("CC");