-
Notifications
You must be signed in to change notification settings - Fork 84
/
index.js
52 lines (43 loc) · 1.17 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
var x509 = require('./build/Release/x509');
var fs = require('fs');
exports.version = x509.version;
exports.getAltNames = x509.getAltNames;
exports.getSubject = x509.getSubject;
exports.getIssuer = x509.getIssuer;
exports.verify = function(certPath, CABundlePath, cb) {
if (!certPath) {
throw new TypeError('Certificate path is required');
}
if (!CABundlePath) {
throw new TypeError('CA Bundle path is required');
}
fs.stat(certPath, function(certPathErr) {
if (certPathErr) {
return cb(certPathErr);
}
fs.stat(CABundlePath, function(bundlePathErr) {
if (bundlePathErr) {
return cb(bundlePathErr);
}
try {
x509.verify(certPath, CABundlePath);
cb(null);
}
catch (verificationError) {
cb(verificationError);
}
});
});
};
exports.parseCert = function(path) {
var ret = x509.parseCert(path);
var exts = {};
for (var key in ret.extensions) {
var newkey = key.replace('X509v3', '').replace(/ /g, '');
newkey = newkey.slice(0, 1).toLowerCase() + newkey.slice(1);
exts[newkey] = ret.extensions[key];
}
delete ret.extensions;
ret.extensions = exts;
return ret;
};