-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (80 loc) · 2.66 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
#!/usr/bin/env node
var Cert = require('./lib/cert');
var fs = require('fs');
var yargs = require('yargs');
var moment = require('moment');
var debug = require('debug')('ineedatestcert.cli');
/**
* You can debug the cli by setting
* DEBUG=ineedatestcert.cli
* and if you also want to debug the internals
* DEBUG=ineedatestcert.*
*/
var config = yargs
.help('h')
.alias('h', 'help')
.epilog('Made with <3 by @bengreenier')
.describe('o', 'specify a file to output to')
.alias('o','out')
.describe('b', 'specify key size')
.describe('c', 'specify common name')
.alias('c', 'name')
.describe('p', 'password to use for pkcs')
.alias('p', 'password')
.describe('t', 'type of output - pem or pkcs')
.alias('t','type')
.describe('u', 'organization to use')
.alias('u', 'org')
.describe('a', 'specify file to output ca bundle to')
.alias('a', 'ca')
.describe('alt', 'specify alternative dns names')
.describe('na', 'not after date')
.default({
na: moment().add(1, 'year').toISOString(),
alt: [],
a: null, // filpath to write ca bundle to - if null, not written
b: 2048, // any more get's real slow
c: "<uuid>.ineedatestcert.com", // generate a unique subdomain
u: "Test Cert", // the ou/organization name (shared)
p: "", // only used with pkcs==true
t: "pkcs", // or pem
o: null // filepath to write to - if null, writes to console
}).argv;
// you need to use a legit t argument...
if (config.t !== "pkcs" && config.t !== "pem") {
debug("unknown argument t: "+config.t);
yargs.showHelp();
process.exit(-1);
}
// if <uuid> is still in c, we need to replace it with an actual uuid
// but Cert does that for us
if (config.c.indexOf("<uuid>") === 0) {
delete config.c;
delete config.name; // fix the alias too
}
// if using -p <password> and -t <pem> warn
if (config.p && config.t === "pem") {
console.warn("[WARN] using -p and -t pem together isn't possible. you probably mean -t pkcs\n");
}
debug("using configuration: "+JSON.stringify(config));
var cert = new Cert(config);
cert.crunch(function calculated(err) {
if (err) {
return console.error(err);
}
if (config.a) {
fs.writeFileSync(config.a, cert.getRawPublicOnly());
if (config.o) {
console.log("wrote "+config.a);
}
debug("wrote ca bundle to "+config.a);
}
if (config.o) {
fs.writeFileSync(config.o, cert.getRaw(), {encoding: "binary"});
console.log("wrote "+config.o);
debug("wrote raw to "+config.o);
} else {
console.log(cert.getBase64());
}
debug("complete.");
});