-
Notifications
You must be signed in to change notification settings - Fork 1
/
tls-csr.js
59 lines (53 loc) · 1.63 KB
/
tls-csr.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
#!/usr/bin/env node
/*
* Copyright (c) 2015 by Jonas Friedmann. Please see the
* LICENSE file for more information. All Rights Reserved.
*/
var cmdr = require('commander'),
helpers = require('./lib/helper'),
openssl = require('openssl-cert-tools');
/* Logic */
// Setup sub command options
cmdr
.option('-f, --filename <file>', 'search CRT or CSR in file')
.option('-c, --clipboard', 'search CSR in clipboard')
.parse(process.argv);
// Declare variables
var haystack;
// If "--filename" is set
if (cmdr.filename) {
var fileName = cmdr.filename;
helpers.checkIfFileExists(fileName, function(exists){
if (exists){
haystack = helpers.getFileContent(fileName);
helpers.searchForCertificateRequest(haystack, function(searchResult){
if (searchResult !== false) {
// Call displayCrtInformation()
helpers.displayCsrInformation(searchResult, function(data){
helpers.quit(0);
});
} else {
helpers.die('Couldn\'t certificate request in file "' + fileName + '"');
}
});
} else {
helpers.die('Couldn\'t access file "' + fileName + '"');
}
});
// otherwise check clipboard...
} else if (cmdr.clipboard) {
haystack = helpers.getClipboard();
helpers.searchForCertificateRequest(haystack, function(searchResult){
if (searchResult !== false) {
// Call displayCrtInformation()
helpers.displayCsrInformation(searchResult, function(data){
helpers.quit(0);
});
} else {
helpers.die('Couldn\'t find certificate request in clipboard');
}
});
} else {
helpers.error('No option passed');
cmdr.help();
}