-
Notifications
You must be signed in to change notification settings - Fork 17
/
certdb.js
71 lines (53 loc) · 1.81 KB
/
certdb.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
/*
* Poor man's in-memory DB for quick certificate queries
*/
var log = require('fancy-log');
var crl = require('./crl.js');
certificates = new Array();
// Sample: V 270129084423Z 270129084423Z 100E unknown /C=DE/ST=Germany/O=ADITO Software GmbH/OU=IT/CN=ADITO General Intermediate CA/emailAddress=it@adito.de
var regex = /([R,E,V])(\t)(.*)(\t)(.*)(\t)([\dA-F]*)(\t)(unknown)(\t)(.*)/;
/*
* Re-indexes OpenSSL index.txt file and stores datasets in array 'certificates'
*/
var reindex = function() {
return new Promise(function(resolve, reject) {
log.info("Reindexing CertDB ...");
// Index-Datei öffnen
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream(global.paths.pkipath + 'intermediate/index.txt')
});
certificates = [];
lineReader.on('line', function (line) {
// Regex auf diese Zeile anwenden, um einzelne Spalten zu gewinnen.
var columns = regex.exec(line);
if(columns !== null){
var certificate = {
state: columns[1],
expirationtime: columns[3],
revocationtime: columns[5],
serial: columns[7],
subject: columns[11]
};
certificates.push(certificate);
} else {
log.error("Error while parsing index.txt line :(");
}
});
lineReader.on('close', function() {
log.info("Reindexing finished");
// Re-Create CRL
crl.createCRL();
resolve();
});
});
}
/*
* Return all certificates
*/
var getIndex = function() {
return certificates;
}
module.exports = {
reindex: reindex,
getIndex: getIndex
}