secrez 1.1.1 → 1.1.2
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/README.md +414 -291
- package/bin/secrez.js +50 -47
- package/coverage.report +63 -305
- package/package.json +10 -12
- package/src/Command.js +78 -57
- package/src/PreCommand.js +74 -70
- package/src/Welcome.js +144 -134
- package/src/cliConfig.js +14 -14
- package/src/commands/Alias.js +123 -100
- package/src/commands/Bash.js +10 -12
- package/src/commands/Cat.js +117 -107
- package/src/commands/Cd.js +39 -42
- package/src/commands/Chat.js +75 -63
- package/src/commands/Conf.js +123 -99
- package/src/commands/Contacts.js +189 -171
- package/src/commands/Copy.js +132 -113
- package/src/commands/Courier.js +123 -105
- package/src/commands/Ds.js +88 -76
- package/src/commands/Edit.js +122 -103
- package/src/commands/Export.js +153 -114
- package/src/commands/Find.js +115 -110
- package/src/commands/Help.js +20 -23
- package/src/commands/Import.js +296 -225
- package/src/commands/Lcat.js +36 -39
- package/src/commands/Lcd.js +38 -39
- package/src/commands/Lls.js +58 -55
- package/src/commands/Lpwd.js +20 -24
- package/src/commands/Ls.js +107 -97
- package/src/commands/Mkdir.js +35 -38
- package/src/commands/Mv.js +147 -114
- package/src/commands/Paste.js +68 -65
- package/src/commands/Pwd.js +18 -23
- package/src/commands/Quit.js +22 -24
- package/src/commands/Rm.js +78 -70
- package/src/commands/Shell.js +31 -32
- package/src/commands/Ssh.js +77 -63
- package/src/commands/Tag.js +133 -112
- package/src/commands/Totp.js +166 -136
- package/src/commands/Touch.js +169 -56
- package/src/commands/Use.js +44 -41
- package/src/commands/Ver.js +16 -18
- package/src/commands/Whoami.js +34 -37
- package/src/commands/chat/Contacts.js +41 -44
- package/src/commands/chat/Help.js +20 -23
- package/src/commands/chat/Join.js +59 -55
- package/src/commands/chat/Leave.js +16 -22
- package/src/commands/chat/Quit.js +19 -24
- package/src/commands/chat/Send.js +58 -57
- package/src/commands/chat/Show.js +60 -51
- package/src/commands/chat/Whoami.js +18 -22
- package/src/commands/index.js +20 -22
- package/src/index.js +3 -3
- package/src/prompts/ChatPrompt.js +87 -82
- package/src/prompts/ChatPromptMock.js +11 -17
- package/src/prompts/CommandPrompt.js +146 -138
- package/src/prompts/Completion.js +64 -69
- package/src/prompts/MainPrompt.js +84 -77
- package/src/prompts/MainPromptMock.js +19 -30
- package/src/prompts/MultiEditorPrompt.js +21 -22
- package/src/prompts/SigintManager.js +21 -24
- package/src/utils/AliasManager.js +16 -18
- package/src/utils/ContactManager.js +15 -17
- package/src/utils/Fido2Client.js +59 -49
- package/src/utils/HelpProto.js +130 -117
- package/src/utils/Logger.js +48 -50
- package/.eslintignore +0 -0
- package/.eslintrc +0 -33
- package/.jshintrc +0 -3
package/src/Welcome.js
CHANGED
@@ -1,151 +1,157 @@
|
|
1
|
-
const chalk = require(
|
2
|
-
const inquirer = require(
|
3
|
-
const fs = require(
|
4
|
-
const Crypto = require(
|
5
|
-
const Logger = require(
|
6
|
-
const Fido2Client = require(
|
1
|
+
const chalk = require("chalk");
|
2
|
+
const inquirer = require("inquirer");
|
3
|
+
const fs = require("fs-extra");
|
4
|
+
const Crypto = require("@secrez/crypto");
|
5
|
+
const Logger = require("./utils/Logger");
|
6
|
+
const Fido2Client = require("./utils/Fido2Client");
|
7
7
|
|
8
8
|
class Welcome {
|
9
|
-
|
10
9
|
async start(secrez, options) {
|
11
|
-
this.secrez = secrez
|
12
|
-
this.options = options
|
13
|
-
this.iterations = options.iterations || await this.getIterations()
|
10
|
+
this.secrez = secrez;
|
11
|
+
this.options = options;
|
12
|
+
this.iterations = options.iterations || (await this.getIterations());
|
14
13
|
if (await fs.pathExists(this.secrez.config.oldKeysPath)) {
|
15
|
-
const oldConf = require(this.secrez.config.oldKeysPath)
|
14
|
+
const oldConf = require(this.secrez.config.oldKeysPath);
|
16
15
|
if (!oldConf.data.why) {
|
17
|
-
Logger.red(
|
16
|
+
Logger.red(
|
17
|
+
chalk.bold(`
|
18
18
|
Your encrypted db is not compatible with this version of Secrez.
|
19
|
-
`)
|
19
|
+
`)
|
20
|
+
);
|
20
21
|
Logger.reset(`Install secrez-migrate with
|
21
22
|
|
22
|
-
${chalk.bold(
|
23
|
+
${chalk.bold("pnpm i -g @secrez/migrate")}
|
23
24
|
|
24
25
|
and run it to migrate the db. If you specify the container launching secrez, specify it also launching secrez-migrate.
|
25
26
|
If you need to access your secrets now, revert to a compatible version with
|
26
27
|
|
27
|
-
${chalk.bold(
|
28
|
+
${chalk.bold("pnpm i -g secrez@0.10.8")}
|
28
29
|
|
29
30
|
and migrate your db later.
|
30
|
-
Thanks.`)
|
31
|
+
Thanks.`);
|
31
32
|
// eslint-disable-next-line no-process-exit
|
32
|
-
process.exit(0)
|
33
|
+
process.exit(0);
|
33
34
|
}
|
34
35
|
}
|
35
36
|
|
36
37
|
if (await fs.pathExists(this.secrez.config.keysPath)) {
|
37
|
-
let errorCode = await this.login()
|
38
|
+
let errorCode = await this.login();
|
38
39
|
if (errorCode === 1) {
|
39
|
-
await this.sharedLogin()
|
40
|
+
await this.sharedLogin();
|
40
41
|
}
|
41
42
|
} else {
|
42
|
-
Logger.grey(
|
43
|
-
await this.signup()
|
43
|
+
Logger.grey("Please signup to create your local account");
|
44
|
+
await this.signup();
|
44
45
|
}
|
45
46
|
}
|
46
47
|
|
47
48
|
async getIterations() {
|
48
49
|
if (await fs.pathExists(this.secrez.config.envPath)) {
|
49
|
-
let env = require(this.secrez.config.envPath)
|
50
|
+
let env = require(this.secrez.config.envPath);
|
50
51
|
if (env.iterations) {
|
51
|
-
return env.iterations
|
52
|
+
return env.iterations;
|
52
53
|
}
|
53
54
|
}
|
54
|
-
let {iterations} = await inquirer.prompt([
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
55
|
+
let { iterations } = await inquirer.prompt([
|
56
|
+
{
|
57
|
+
name: "iterations",
|
58
|
+
type: "input",
|
59
|
+
message: "Type the number of iterations for password derivation:",
|
60
|
+
validate: (value) => {
|
61
|
+
if (value.length && parseInt(value) > 0) {
|
62
|
+
return true;
|
63
|
+
} else {
|
64
|
+
return "Please enter a valid number of iterations.";
|
65
|
+
}
|
66
|
+
},
|
67
|
+
},
|
68
|
+
]);
|
69
|
+
return parseInt(iterations);
|
67
70
|
}
|
68
71
|
|
69
|
-
// chimney piano fabric forest curious black hip axis story stool spoil fold
|
72
|
+
// chimney piano fabric forest curious black hip axis story stool spoil fold
|
70
73
|
async saveIterations() {
|
71
74
|
if (this.options.saveIterations) {
|
72
|
-
await this.secrez.saveIterations(this.iterations)
|
75
|
+
await this.secrez.saveIterations(this.iterations);
|
73
76
|
}
|
74
77
|
}
|
75
78
|
|
76
79
|
async login() {
|
77
|
-
for (
|
80
|
+
for (;;) {
|
78
81
|
try {
|
79
|
-
let {password} = await inquirer.prompt([
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
82
|
+
let { password } = await inquirer.prompt([
|
83
|
+
{
|
84
|
+
name: "password",
|
85
|
+
type: "password",
|
86
|
+
message: "Enter your master password:",
|
87
|
+
validate: (value) => {
|
88
|
+
if (value.length) {
|
89
|
+
return true;
|
90
|
+
} else {
|
91
|
+
return "Please enter your master password.";
|
92
|
+
}
|
93
|
+
},
|
94
|
+
},
|
95
|
+
]);
|
91
96
|
try {
|
92
|
-
await this.secrez.signin(password, this.iterations)
|
97
|
+
await this.secrez.signin(password, this.iterations);
|
93
98
|
if (this.secrez.masterKeyHash) {
|
94
|
-
await this.saveIterations()
|
99
|
+
await this.saveIterations();
|
95
100
|
}
|
96
|
-
return 0
|
101
|
+
return 0;
|
97
102
|
} catch (e) {
|
98
|
-
if (e.message ===
|
99
|
-
return 1
|
103
|
+
if (e.message === "A second factor is required") {
|
104
|
+
return 1;
|
100
105
|
}
|
101
|
-
Logger.red(`${e.message}.Try again or Ctrl - C to exit.`)
|
106
|
+
Logger.red(`${e.message}.Try again or Ctrl - C to exit.`);
|
102
107
|
}
|
103
108
|
} catch (e) {
|
104
|
-
Logger.red(
|
109
|
+
Logger.red("Unrecognized error. Try again or Ctrl-c to exit.");
|
105
110
|
}
|
106
111
|
}
|
107
112
|
}
|
108
113
|
|
109
114
|
async sharedLogin() {
|
110
|
-
let fido2Client = new Fido2Client(this.secrez)
|
111
|
-
let authenticator
|
112
|
-
let list = await fido2Client.getKeys()
|
113
|
-
const conf = await this.secrez.readConf()
|
114
|
-
let choices = []
|
115
|
+
let fido2Client = new Fido2Client(this.secrez);
|
116
|
+
let authenticator;
|
117
|
+
let list = await fido2Client.getKeys();
|
118
|
+
const conf = await this.secrez.readConf();
|
119
|
+
let choices = [];
|
115
120
|
for (let authenticator in conf.data.keys) {
|
116
|
-
choices.push(authenticator)
|
121
|
+
choices.push(authenticator);
|
117
122
|
}
|
118
|
-
for (
|
123
|
+
for (;;) {
|
119
124
|
if (list.length === 1) {
|
120
|
-
authenticator = list[0]
|
125
|
+
authenticator = list[0];
|
121
126
|
} else {
|
122
127
|
let p = await inquirer.prompt([
|
123
128
|
{
|
124
|
-
type:
|
125
|
-
name:
|
126
|
-
message:
|
127
|
-
choices
|
128
|
-
}
|
129
|
-
])
|
130
|
-
authenticator = p.authenticator
|
129
|
+
type: "list",
|
130
|
+
name: "authenticator",
|
131
|
+
message: "Which second factor would you like to use?",
|
132
|
+
choices,
|
133
|
+
},
|
134
|
+
]);
|
135
|
+
authenticator = p.authenticator;
|
131
136
|
}
|
132
|
-
let secret
|
137
|
+
let secret;
|
133
138
|
try {
|
134
139
|
try {
|
135
140
|
if (fido2Client.keys[authenticator]) {
|
136
|
-
Logger.grey(
|
137
|
-
secret = await fido2Client.verifySecret(authenticator)
|
141
|
+
Logger.grey("Touch your fido2 authenticator device now...");
|
142
|
+
secret = await fido2Client.verifySecret(authenticator);
|
138
143
|
} else {
|
139
|
-
let exitCode = Crypto.getRandomBase58String(2)
|
140
|
-
let p = await inquirer.prompt([
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
144
|
+
let exitCode = Crypto.getRandomBase58String(2);
|
145
|
+
let p = await inquirer.prompt([
|
146
|
+
{
|
147
|
+
name: "recoveryCode",
|
148
|
+
type: "input",
|
149
|
+
message: "Type or paste your recovery code:",
|
150
|
+
validate: (value) => {
|
151
|
+
if (value.length) {
|
152
|
+
return true;
|
153
|
+
} else {
|
154
|
+
return `
|
149
155
|
Please
|
150
156
|
paste
|
151
157
|
a
|
@@ -157,84 +163,88 @@ Thanks.`)
|
|
157
163
|
to
|
158
164
|
choose
|
159
165
|
another
|
160
|
-
factor
|
161
|
-
|
162
|
-
|
163
|
-
|
166
|
+
factor.`;
|
167
|
+
}
|
168
|
+
},
|
169
|
+
},
|
170
|
+
]);
|
164
171
|
if (p.recoveryCode === exitCode) {
|
165
|
-
continue
|
172
|
+
continue;
|
166
173
|
}
|
167
|
-
secret = p.recoveryCode
|
174
|
+
secret = p.recoveryCode;
|
168
175
|
}
|
169
|
-
let resCode = await this.secrez.sharedSignin(authenticator, secret)
|
176
|
+
let resCode = await this.secrez.sharedSignin(authenticator, secret);
|
170
177
|
if (this.secrez.masterKeyHash) {
|
171
|
-
await this.saveIterations()
|
178
|
+
await this.saveIterations();
|
172
179
|
}
|
173
180
|
if (resCode === 1) {
|
174
|
-
Logger.bold(chalk.red(
|
175
|
-
Logger.red(
|
176
|
-
|
181
|
+
Logger.bold(chalk.red("Your data has been upgraded."));
|
182
|
+
Logger.red(
|
183
|
+
"To avoid conflicts, any registered second factor has been removed."
|
184
|
+
);
|
185
|
+
Logger.grey("Please, register them again, thanks.");
|
177
186
|
}
|
178
|
-
return
|
187
|
+
return;
|
179
188
|
} catch (e) {
|
180
189
|
Logger.red(`${e.message}.Try
|
181
190
|
again
|
182
191
|
or
|
183
192
|
Ctrl - C
|
184
193
|
to
|
185
|
-
exit.`)
|
194
|
+
exit.`);
|
186
195
|
}
|
187
196
|
} catch (e) {
|
188
|
-
Logger.red(
|
197
|
+
Logger.red("Unrecognized error. Try again or Ctrl-C to exit.");
|
189
198
|
}
|
190
199
|
}
|
191
200
|
}
|
192
201
|
|
193
202
|
async signup() {
|
194
|
-
for (
|
203
|
+
for (;;) {
|
195
204
|
try {
|
196
|
-
let p = await inquirer.prompt([
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
205
|
+
let p = await inquirer.prompt([
|
206
|
+
{
|
207
|
+
name: "password",
|
208
|
+
type: "password",
|
209
|
+
message: "Enter your password:",
|
210
|
+
validate: (value) => {
|
211
|
+
if (value.length) {
|
212
|
+
return true;
|
213
|
+
} else {
|
214
|
+
return "Please enter your password";
|
215
|
+
}
|
216
|
+
},
|
217
|
+
},
|
218
|
+
{
|
219
|
+
name: "retype",
|
220
|
+
type: "password",
|
221
|
+
message: "Retype your password:",
|
222
|
+
validate: (value) => {
|
223
|
+
if (value.length) {
|
224
|
+
return true;
|
225
|
+
} else {
|
226
|
+
return "Please enter your password";
|
227
|
+
}
|
228
|
+
},
|
229
|
+
},
|
230
|
+
]);
|
219
231
|
if (p.password === p.retype) {
|
220
232
|
try {
|
221
|
-
await this.secrez.signup(p.password, this.iterations)
|
222
|
-
await this.saveIterations()
|
223
|
-
return
|
233
|
+
await this.secrez.signup(p.password, this.iterations);
|
234
|
+
await this.saveIterations();
|
235
|
+
return;
|
224
236
|
} catch (e) {
|
225
|
-
Logger.red(e.message)
|
226
|
-
break
|
237
|
+
Logger.red(e.message);
|
238
|
+
break;
|
227
239
|
}
|
228
240
|
} else {
|
229
|
-
Logger.red(
|
241
|
+
Logger.red("The two passwords do not match. Try again");
|
230
242
|
}
|
231
243
|
} catch (e) {
|
232
|
-
Logger.red(
|
244
|
+
Logger.red("Unrecognized error. Try again or Ctrl-c to exit.");
|
233
245
|
}
|
234
246
|
}
|
235
|
-
|
236
247
|
}
|
237
|
-
|
238
248
|
}
|
239
249
|
|
240
|
-
module.exports = new Welcome
|
250
|
+
module.exports = new Welcome();
|
package/src/cliConfig.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
const TRUE = 1
|
2
|
-
const STRING = 2
|
3
|
-
const ARRAY = 3
|
4
|
-
const NUMBER = 4
|
5
|
-
const BOOL = 5
|
6
|
-
const OBJECT = 6
|
1
|
+
const TRUE = 1;
|
2
|
+
const STRING = 2;
|
3
|
+
const ARRAY = 3;
|
4
|
+
const NUMBER = 4;
|
5
|
+
const BOOL = 5;
|
6
|
+
const OBJECT = 6;
|
7
7
|
|
8
8
|
const completionTypes = {
|
9
9
|
TRUE,
|
@@ -11,17 +11,17 @@ const completionTypes = {
|
|
11
11
|
ARRAY,
|
12
12
|
NUMBER,
|
13
13
|
BOOL,
|
14
|
-
OBJECT
|
15
|
-
}
|
14
|
+
OBJECT,
|
15
|
+
};
|
16
16
|
|
17
|
-
const cliConfig = Object.assign(require(
|
17
|
+
const cliConfig = Object.assign(require("@secrez/core").config, {
|
18
18
|
completion: {
|
19
|
-
help: {}
|
19
|
+
help: {},
|
20
20
|
},
|
21
21
|
chatCompletion: {
|
22
|
-
help: {}
|
22
|
+
help: {},
|
23
23
|
},
|
24
|
-
completionTypes
|
25
|
-
})
|
24
|
+
completionTypes,
|
25
|
+
});
|
26
26
|
|
27
|
-
module.exports = cliConfig
|
27
|
+
module.exports = cliConfig;
|