@thefirstspine/certificate-authority 0.0.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/generate.command.d.ts +0 -6
- package/lib/commands/generate.command.d.ts.map +1 -1
- package/lib/commands/generate.command.js +20 -77
- package/lib/commands/generate.command.js.map +1 -1
- package/lib/commands/generate.js +8 -39
- package/lib/commands/generate.js.map +1 -1
- package/package.json +5 -17
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
export declare class GenerateCommand {
|
|
2
|
-
protected force: boolean;
|
|
3
|
-
protected mode: string;
|
|
4
|
-
private chalk;
|
|
5
|
-
private inquirer;
|
|
6
2
|
constructor();
|
|
7
3
|
start(args: IGenerateCommandArgs | (IGenerateCommandArgs & IGenerateCommandPairsArgs)): Promise<void>;
|
|
8
4
|
generatePair(args: IGenerateCommandPairsArgs): Promise<void>;
|
|
9
|
-
protected promptForValue(message: string, args: any, key: string): Promise<string>;
|
|
10
5
|
}
|
|
11
6
|
export interface IGenerateCommandArgs {
|
|
12
|
-
force: boolean | undefined;
|
|
13
7
|
mode: string | undefined;
|
|
14
8
|
}
|
|
15
9
|
export interface IGenerateCommandPairsArgs {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.command.d.ts","sourceRoot":"","sources":["../../src/commands/generate.command.ts"],"names":[],"mappings":"AAQA,qBAAa,eAAe
|
|
1
|
+
{"version":3,"file":"generate.command.d.ts","sourceRoot":"","sources":["../../src/commands/generate.command.ts"],"names":[],"mappings":"AAQA,qBAAa,eAAe;;IAOpB,KAAK,CAAC,IAAI,EAAE,oBAAoB,GAAG,CAAC,oBAAoB,GAAG,yBAAyB,CAAC;IAmBrF,YAAY,CAAC,IAAI,EAAE,yBAAyB;CAqDnD;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,GAAC,SAAS,CAAC;CACxB;AAED,MAAM,WAAW,yBAAyB;IACxC,GAAG,EAAE,MAAM,GAAC,SAAS,CAAC;IACtB,WAAW,EAAE,MAAM,GAAC,SAAS,CAAC;CAC/B"}
|
|
@@ -40,78 +40,33 @@ const crypto = __importStar(require("crypto"));
|
|
|
40
40
|
const fs = __importStar(require("fs"));
|
|
41
41
|
const validator_service_1 = __importDefault(require("./../service/validator.service"));
|
|
42
42
|
class GenerateCommand {
|
|
43
|
-
constructor() {
|
|
44
|
-
this.force = false;
|
|
45
|
-
this.mode = 'ask';
|
|
46
|
-
}
|
|
43
|
+
constructor() { }
|
|
47
44
|
start(args) {
|
|
48
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
|
|
50
|
-
this.inquirer = yield Promise.resolve().then(() => __importStar(require("inquirer")));
|
|
51
|
-
console.log(this.chalk.blue(`Certification generation toolkit`));
|
|
52
|
-
if (args.force) {
|
|
53
|
-
console.log(this.chalk.yellowBright('Using `force` mode. Hope you know what you are doing.'));
|
|
54
|
-
this.force = true;
|
|
55
|
-
}
|
|
56
|
-
this.mode = args.mode;
|
|
57
|
-
if (this.mode === 'ask') {
|
|
58
|
-
const menuResponses = yield this.inquirer.prompt([
|
|
59
|
-
{
|
|
60
|
-
type: 'list',
|
|
61
|
-
name: 'menu',
|
|
62
|
-
message: 'What do you want to do?',
|
|
63
|
-
choices: [
|
|
64
|
-
'Generate a new pair',
|
|
65
|
-
],
|
|
66
|
-
}
|
|
67
|
-
]);
|
|
68
|
-
if (menuResponses.menu === 'Generate a new pair') {
|
|
69
|
-
this.mode = 'pair';
|
|
70
|
-
}
|
|
71
|
-
else if (menuResponses.menu === 'Generate a new certificate from a private key') {
|
|
72
|
-
}
|
|
73
|
-
}
|
|
46
|
+
console.log(`Certification generation toolkit`);
|
|
74
47
|
const modesMap = {
|
|
75
48
|
'pair': this.generatePair.bind(this),
|
|
76
49
|
};
|
|
77
|
-
if (!modesMap[
|
|
78
|
-
console.log(
|
|
50
|
+
if (!modesMap[args.mode]) {
|
|
51
|
+
console.log(`Unhandled mode "${args.mode}"`);
|
|
79
52
|
process.exit(1);
|
|
80
53
|
}
|
|
81
|
-
modesMap[
|
|
54
|
+
modesMap[args.mode](args);
|
|
82
55
|
});
|
|
83
56
|
}
|
|
84
57
|
generatePair(args) {
|
|
85
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const key =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
name: 'overwrite',
|
|
92
|
-
message: `${key} already exists. Overwrite?`,
|
|
93
|
-
}
|
|
94
|
-
]);
|
|
95
|
-
if (!responses.overwrite) {
|
|
96
|
-
process.exit(1);
|
|
97
|
-
}
|
|
98
|
-
fs.unlinkSync(key);
|
|
59
|
+
const key = args.key;
|
|
60
|
+
const certificate = args.certificate;
|
|
61
|
+
if (key == undefined) {
|
|
62
|
+
console.log('"[k]ey" is required.');
|
|
63
|
+
process.exit(1);
|
|
99
64
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
{
|
|
104
|
-
type: 'confirm',
|
|
105
|
-
name: 'overwrite',
|
|
106
|
-
message: `${certificate} already exists. Overwrite?`,
|
|
107
|
-
}
|
|
108
|
-
]);
|
|
109
|
-
if (!responses.overwrite) {
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
fs.unlinkSync(certificate);
|
|
65
|
+
if (certificate == undefined) {
|
|
66
|
+
console.log('"[c]ertificate" is required.');
|
|
67
|
+
process.exit(1);
|
|
113
68
|
}
|
|
114
|
-
console.log(
|
|
69
|
+
console.log('Generating pair...');
|
|
115
70
|
const result = crypto.generateKeyPairSync('rsa', {
|
|
116
71
|
modulusLength: 2048,
|
|
117
72
|
publicKeyEncoding: {
|
|
@@ -123,34 +78,22 @@ class GenerateCommand {
|
|
|
123
78
|
format: 'pem',
|
|
124
79
|
}
|
|
125
80
|
});
|
|
126
|
-
console.log(
|
|
81
|
+
console.log('Testing pair...');
|
|
127
82
|
process.env.PRIVATE_KEY = result.privateKey;
|
|
128
83
|
const challengeResult = validator_service_1.default.challenge(result.publicKey);
|
|
129
84
|
if (!challengeResult) {
|
|
130
|
-
console.log(
|
|
85
|
+
console.log(`Challenge failed.`);
|
|
131
86
|
process.exit(1);
|
|
132
87
|
}
|
|
133
|
-
console.log(
|
|
88
|
+
console.log('Challenge succeed.');
|
|
134
89
|
fs.writeFileSync(key, result.privateKey);
|
|
135
|
-
console.log(
|
|
90
|
+
console.log(`Generated key in ${key}`);
|
|
136
91
|
fs.writeFileSync(certificate, result.publicKey);
|
|
137
|
-
console.log(
|
|
138
|
-
console.log(
|
|
92
|
+
console.log(`Generated certificate in ${certificate}`);
|
|
93
|
+
console.log(`done.`);
|
|
139
94
|
process.exit();
|
|
140
95
|
});
|
|
141
96
|
}
|
|
142
|
-
promptForValue(message, args, key) {
|
|
143
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
const response = args[key] ? { [key]: args[key] } : yield this.inquirer.prompt([
|
|
145
|
-
{
|
|
146
|
-
type: 'input',
|
|
147
|
-
name: key,
|
|
148
|
-
message,
|
|
149
|
-
}
|
|
150
|
-
]);
|
|
151
|
-
return response[key];
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
97
|
}
|
|
155
98
|
exports.GenerateCommand = GenerateCommand;
|
|
156
99
|
//# sourceMappingURL=generate.command.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.command.js","sourceRoot":"","sources":["../../src/commands/generate.command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AACjC,uCAAyB;AACzB,uFAA8D;AAM9D,MAAa,eAAe;
|
|
1
|
+
{"version":3,"file":"generate.command.js","sourceRoot":"","sources":["../../src/commands/generate.command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AACjC,uCAAyB;AACzB,uFAA8D;AAM9D,MAAa,eAAe;IAC1B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,CAAC,CAAC;YAC/B,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;YAC5C,MAAM,eAAe,GAAG,2BAAgB,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACrE,IAAI,CAAC,eAAe,EAAE;gBACpB,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;gBACjC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;YACD,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;YAGlC,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;YACzC,OAAO,CAAC,GAAG,CAAC,oBAAoB,GAAG,EAAE,CAAC,CAAC;YACvC,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;YAChD,OAAO,CAAC,GAAG,CAAC,4BAA4B,WAAW,EAAE,CAAC,CAAC;YAGvD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACrB,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC;KAAA;CACF;AA/ED,0CA+EC"}
|
package/lib/commands/generate.js
CHANGED
|
@@ -1,47 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
4
|
const generate_command_1 = require("./generate.command");
|
|
8
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
9
|
-
const clear = require('clear');
|
|
10
|
-
clear();
|
|
11
|
-
yargs_1.default
|
|
12
|
-
.command('', 'Generates files to be validated in the services.')
|
|
13
|
-
.options({
|
|
14
|
-
force: {
|
|
15
|
-
alias: 'f',
|
|
16
|
-
type: 'boolean',
|
|
17
|
-
description: 'Once provided, the confirmation prompt will be ignored.',
|
|
18
|
-
default: false,
|
|
19
|
-
},
|
|
20
|
-
mode: {
|
|
21
|
-
alias: 'm',
|
|
22
|
-
type: 'string',
|
|
23
|
-
description: 'Defines wha\'s to be generated. `"ask"` or `"pair"`. If not provided, a prompt will be displayed.',
|
|
24
|
-
default: 'ask',
|
|
25
|
-
},
|
|
26
|
-
key: {
|
|
27
|
-
alias: 'k',
|
|
28
|
-
type: 'string',
|
|
29
|
-
description: 'The private key path. If not provided, a prompt will be displayed. If the file already exists, a confirmation will be asked',
|
|
30
|
-
default: false,
|
|
31
|
-
},
|
|
32
|
-
certificate: {
|
|
33
|
-
alias: 'c',
|
|
34
|
-
type: 'string',
|
|
35
|
-
description: 'The public certificate path. If not provided, a prompt will be displayed. If the file already exists, a confirmation will be asked',
|
|
36
|
-
default: false,
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
5
|
const command = new generate_command_1.GenerateCommand();
|
|
40
|
-
|
|
6
|
+
var argv = require('minimist')(process.argv.slice(2));
|
|
7
|
+
if (argv['m'] == undefined) {
|
|
8
|
+
console.log('-[m]ode option is missing');
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
41
11
|
command.start({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
certificate: args['certificate'],
|
|
12
|
+
mode: argv['m'],
|
|
13
|
+
key: argv['k'],
|
|
14
|
+
certificate: argv['c'],
|
|
46
15
|
});
|
|
47
16
|
//# sourceMappingURL=generate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":";;;AAEA,yDAAqD;AAGrD,MAAM,OAAO,GAAoB,IAAI,kCAAe,EAAE,CAAC;AAGvD,IAAI,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACtD,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,EAAE;IAC1B,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;IACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,OAAO,CAAC,KAAK,CAAC;IACZ,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;IACf,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;IACd,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC;CACvB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,33 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thefirstspine/certificate-authority",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Self-signed certificate authority to automate & check secure layer for protected endpoints.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
|
-
"type": "module",
|
|
8
7
|
"bin": {
|
|
9
8
|
"tfs-ca-generate": "lib/commands/generate.js"
|
|
10
9
|
},
|
|
11
|
-
"peerDependencies": {},
|
|
12
10
|
"dependencies": {
|
|
13
|
-
"
|
|
14
|
-
"clear": "^0.1.0",
|
|
15
|
-
"clui": "^0.3.6",
|
|
16
|
-
"eslint": "^8.49.0",
|
|
17
|
-
"inquirer": "^9.2.11",
|
|
18
|
-
"rimraf": "^5.0.1",
|
|
19
|
-
"ts-node": "^10.9.1",
|
|
20
|
-
"typescript": "^5.2.2",
|
|
21
|
-
"yargs": "^17.7.2"
|
|
11
|
+
"minimist": "^1.2.8"
|
|
22
12
|
},
|
|
23
13
|
"devDependencies": {
|
|
24
|
-
"@types/yargs": "^17.0.24",
|
|
25
|
-
"@types/chalk": "^2.2.0",
|
|
26
|
-
"@types/inquirer": "^9.0.3",
|
|
27
14
|
"@types/node": "^20.6.0",
|
|
28
15
|
"@types/node-fetch": "^2.6.4",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
16
|
+
"eslint": "^8.49.0",
|
|
17
|
+
"rimraf": "^5.0.1",
|
|
18
|
+
"typescript": "^5.2.2"
|
|
31
19
|
},
|
|
32
20
|
"scripts": {
|
|
33
21
|
"build": "rimraf ./lib && tsc -b",
|