secrez 1.1.1 → 1.1.3

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.
Files changed (68) hide show
  1. package/README.md +503 -444
  2. package/bin/secrez.js +50 -47
  3. package/coverage.report +91 -85
  4. package/package.json +10 -12
  5. package/src/Command.js +78 -57
  6. package/src/PreCommand.js +75 -70
  7. package/src/Welcome.js +144 -134
  8. package/src/cliConfig.js +14 -14
  9. package/src/commands/Alias.js +123 -100
  10. package/src/commands/Bash.js +10 -12
  11. package/src/commands/Cat.js +117 -107
  12. package/src/commands/Cd.js +39 -42
  13. package/src/commands/Chat.js +75 -63
  14. package/src/commands/Conf.js +123 -99
  15. package/src/commands/Contacts.js +189 -171
  16. package/src/commands/Copy.js +132 -113
  17. package/src/commands/Courier.js +123 -105
  18. package/src/commands/Ds.js +88 -76
  19. package/src/commands/Edit.js +122 -103
  20. package/src/commands/Export.js +201 -116
  21. package/src/commands/Find.js +115 -110
  22. package/src/commands/Help.js +20 -23
  23. package/src/commands/Import.js +296 -225
  24. package/src/commands/Lcat.js +36 -39
  25. package/src/commands/Lcd.js +38 -39
  26. package/src/commands/Lls.js +58 -55
  27. package/src/commands/Lpwd.js +20 -24
  28. package/src/commands/Ls.js +107 -97
  29. package/src/commands/Mkdir.js +35 -38
  30. package/src/commands/Mv.js +147 -114
  31. package/src/commands/Paste.js +68 -65
  32. package/src/commands/Pwd.js +18 -23
  33. package/src/commands/Quit.js +22 -24
  34. package/src/commands/Rm.js +78 -70
  35. package/src/commands/Shell.js +31 -32
  36. package/src/commands/Ssh.js +77 -63
  37. package/src/commands/Tag.js +133 -112
  38. package/src/commands/Totp.js +166 -136
  39. package/src/commands/Touch.js +169 -56
  40. package/src/commands/Use.js +44 -41
  41. package/src/commands/Ver.js +16 -18
  42. package/src/commands/Whoami.js +34 -37
  43. package/src/commands/chat/Contacts.js +41 -44
  44. package/src/commands/chat/Help.js +20 -23
  45. package/src/commands/chat/Join.js +59 -55
  46. package/src/commands/chat/Leave.js +16 -22
  47. package/src/commands/chat/Quit.js +19 -24
  48. package/src/commands/chat/Send.js +58 -57
  49. package/src/commands/chat/Show.js +60 -51
  50. package/src/commands/chat/Whoami.js +18 -22
  51. package/src/commands/index.js +20 -22
  52. package/src/index.js +3 -3
  53. package/src/prompts/ChatPrompt.js +87 -82
  54. package/src/prompts/ChatPromptMock.js +11 -17
  55. package/src/prompts/CommandPrompt.js +146 -138
  56. package/src/prompts/Completion.js +64 -69
  57. package/src/prompts/MainPrompt.js +84 -77
  58. package/src/prompts/MainPromptMock.js +19 -30
  59. package/src/prompts/MultiEditorPrompt.js +21 -22
  60. package/src/prompts/SigintManager.js +21 -24
  61. package/src/utils/AliasManager.js +16 -18
  62. package/src/utils/ContactManager.js +15 -17
  63. package/src/utils/Fido2Client.js +59 -49
  64. package/src/utils/HelpProto.js +130 -117
  65. package/src/utils/Logger.js +48 -50
  66. package/.eslintignore +0 -0
  67. package/.eslintrc +0 -33
  68. package/.jshintrc +0 -3
@@ -1,28 +1,29 @@
1
1
  // const Fido2Client = require('../utils/Fido2Client')
2
2
  // const _ = require('lodash')
3
3
  // const Case = require('case')
4
- const { //config,
5
- ConfigUtils} = require('@secrez/core')
4
+ const {
5
+ //config,
6
+ ConfigUtils,
7
+ } = require("@secrez/core");
6
8
  // const Crypto = require('@secrez/crypto')
7
- const chalk = require('chalk')
8
-
9
- class Conf extends require('../Command') {
9
+ const chalk = require("chalk");
10
10
 
11
+ class Conf extends require("../Command") {
11
12
  setHelpAndCompletion() {
12
13
  this.cliConfig.completion.conf = {
13
- _self: this
14
- }
15
- this.cliConfig.completion.help.conf = true
14
+ _self: this,
15
+ };
16
+ this.cliConfig.completion.help.conf = true;
16
17
  this.optionDefinitions = [
17
18
  {
18
- name: 'help',
19
- alias: 'h',
20
- type: Boolean
19
+ name: "help",
20
+ alias: "h",
21
+ type: Boolean,
21
22
  },
22
23
  {
23
- name: 'show',
24
- alias: 's',
25
- type: Boolean
24
+ name: "show",
25
+ alias: "s",
26
+ type: Boolean,
26
27
  },
27
28
  // {
28
29
  // name: 'register',
@@ -52,23 +53,25 @@ class Conf extends require('../Command') {
52
53
  // type: String
53
54
  // },
54
55
  {
55
- name: 'new-password',
56
- type: Boolean
56
+ name: "new-password",
57
+ type: Boolean,
57
58
  },
58
59
  {
59
- name: 'new-iterations-number',
60
- type: Boolean
61
- }
62
- ]
60
+ name: "new-iterations-number",
61
+ type: Boolean,
62
+ },
63
+ ];
63
64
  }
64
65
 
65
66
  help() {
66
67
  return {
67
- description: ['Shows current configuration and allow to change password and number of iterations).'],
68
+ description: [
69
+ "Shows current configuration and allow to change password and number of iterations).",
70
+ ],
68
71
  examples: [
69
- ['conf -s', 'shows the general settings'],
70
- ['conf --new-password', 'changes your password'],
71
- ['conf --new-iterations-number', 'changes the number of iterations'],
72
+ ["conf -s", "shows the general settings"],
73
+ ["conf --new-password", "changes your password"],
74
+ ["conf --new-iterations-number", "changes the number of iterations"],
72
75
  // ['conf --fido2 -r solo',
73
76
  // 'registers a new key saving it as "solo"; if there are registered keys, it will checks if the new one is one of them before adding it.'],
74
77
  // ['conf -l', 'lists second factors'],
@@ -77,9 +80,8 @@ class Conf extends require('../Command') {
77
80
  // ['conf --recovery-code -r seed --use-this "salad spring peace silk snake real they thunder please final clinic close"', 'registers an emergency recovery code called "seed" using the seed passed with the parameter "--use-this"'],
78
81
  // ['conf -u solo',
79
82
  // 'unregister the fido2 key "solo"; if that is the only key, it unregister also any emergency code and restores the normal access.']
80
-
81
- ]
82
- }
83
+ ],
84
+ };
83
85
  }
84
86
 
85
87
  // isEmergencyCodeSetUp() {
@@ -129,9 +131,12 @@ class Conf extends require('../Command') {
129
131
  // }
130
132
 
131
133
  async showConf(options) {
132
- const env = await ConfigUtils.getEnv(this.secrez.config)
133
- this.Logger.reset(chalk.grey('Container: ') + this.secrez.config.container)
134
- this.Logger.reset(chalk.grey('Number of iterations: ') + (env.iterations || chalk.yellow('-- not saved locally --')))
134
+ const env = await ConfigUtils.getEnv(this.secrez.config);
135
+ this.Logger.reset(chalk.grey("Container: ") + this.secrez.config.container);
136
+ this.Logger.reset(
137
+ chalk.grey("Number of iterations: ") +
138
+ (env.iterations || chalk.yellow("-- not saved locally --"))
139
+ );
135
140
  }
136
141
 
137
142
  // async showList(options) {
@@ -336,88 +341,109 @@ class Conf extends require('../Command') {
336
341
  // }
337
342
 
338
343
  async upgradeAccount(options) {
339
- let pw = options.newPassword
340
- let it = options.newIterationsNumber
344
+ let pw = options.newPassword;
345
+ let it = options.newIterationsNumber;
341
346
  if (pw && it) {
342
- throw new Error('Changing password and number of iterations in the same operation not allowed')
347
+ throw new Error(
348
+ "Changing password and number of iterations in the same operation not allowed"
349
+ );
343
350
  }
344
- let haveSomeFactors = false
351
+ let haveSomeFactors = false;
345
352
  if (Object.keys(await this.getAllFactors()).length) {
346
- haveSomeFactors = true
353
+ haveSomeFactors = true;
347
354
  }
348
- let message = 'Are you sure you want to upgrade your '
349
- + (pw ? 'password' : 'number of iterations') + '?'
355
+ let message =
356
+ "Are you sure you want to upgrade your " +
357
+ (pw ? "password" : "number of iterations") +
358
+ "?";
350
359
  let yes = await this.useConfirm({
351
360
  message,
352
- default: false
353
- })
361
+ default: false,
362
+ });
354
363
  if (yes) {
355
364
  if (pw) {
356
365
  let oldPassword = await this.useInput({
357
- message: 'Type your existing password',
358
- type: 'password'
359
- })
366
+ message: "Type your existing password",
367
+ type: "password",
368
+ });
360
369
  if (oldPassword) {
361
370
  if (!(await this.secrez.verifyPassword(oldPassword))) {
362
- throw new Error('Wrong password. Try again')
371
+ throw new Error("Wrong password. Try again");
363
372
  }
364
373
  let newPassword = await this.useInput({
365
- message: 'Type your new password',
366
- type: 'password'
367
- })
374
+ message: "Type your new password",
375
+ type: "password",
376
+ });
368
377
  if (newPassword) {
369
378
  let password = await this.useInput({
370
- message: 'Retype your password',
371
- type: 'password',
372
- name: 'password',
379
+ message: "Retype your password",
380
+ type: "password",
381
+ name: "password",
373
382
  validate: (value, exitCode) => {
374
383
  if (value === newPassword) {
375
- return true
384
+ return true;
376
385
  } else {
377
- return chalk.red(`The two passwords do not match. Try again or cancel typing ${chalk.bold(exitCode)}`)
386
+ return chalk.red(
387
+ `The two passwords do not match. Try again or cancel typing ${chalk.bold(
388
+ exitCode
389
+ )}`
390
+ );
378
391
  }
379
- }
380
- })
392
+ },
393
+ });
381
394
  if (password) {
382
- await this.secrez.upgradeAccount(password)
383
- await this.saveAndOverwrite('main:/.NEW_PASSWORD', 'password', password, 'the new password')
384
- this.Logger.reset('In case you have doubts about it, please, "cat" the file and take a look before exiting.')
395
+ await this.secrez.upgradeAccount(password);
396
+ await this.saveAndOverwrite(
397
+ "main:/.NEW_PASSWORD",
398
+ "password",
399
+ password,
400
+ "the new password"
401
+ );
402
+ this.Logger.reset(
403
+ 'In case you have doubts about it, please, "cat" the file and take a look before exiting.'
404
+ );
385
405
  if (haveSomeFactors) {
386
- this.Logger.yellow('All the second factors have been unregistered.')
406
+ this.Logger.yellow(
407
+ "All the second factors have been unregistered."
408
+ );
387
409
  }
388
- return
410
+ return;
389
411
  }
390
412
  }
391
413
  }
392
414
  } else if (it) {
393
415
  let iterations = await this.useInput({
394
- message: 'Type the new number of iterations',
395
- name: 'password',
416
+ message: "Type the new number of iterations",
417
+ name: "password",
396
418
  validate: (value, exitCode) => {
397
419
  if (/^\d+$/.test(value)) {
398
- return true
420
+ return true;
399
421
  } else {
400
- return chalk.red(`Type a valid integer, or cancel typing ${chalk.bold(exitCode)}`)
422
+ return chalk.red(
423
+ `Type a valid integer, or cancel typing ${chalk.bold(exitCode)}`
424
+ );
401
425
  }
402
- }
403
- })
426
+ },
427
+ });
404
428
  if (iterations) {
405
- iterations = parseInt(iterations)
429
+ iterations = parseInt(iterations);
406
430
  if (iterations === 0) {
407
- throw new Error('Invalid number')
431
+ throw new Error("Invalid number");
408
432
  }
409
- await this.secrez.upgradeAccount(undefined, iterations)
410
- const env = await ConfigUtils.getEnv(this.secrez.config)
433
+ await this.secrez.upgradeAccount(undefined, iterations);
434
+ const env = await ConfigUtils.getEnv(this.secrez.config);
411
435
  if (env.iterations) {
412
- env.iterations = iterations
413
- await ConfigUtils.putEnv(this.secrez.config, env)
436
+ env.iterations = iterations;
437
+ await ConfigUtils.putEnv(this.secrez.config, env);
414
438
  }
415
- this.Logger.reset('The number of iterations has been successfully changed.')
416
- return
439
+ this.Logger.reset(
440
+ "The number of iterations has been successfully changed."
441
+ );
442
+ return;
417
443
  }
418
444
  }
419
445
  }
420
- this.Logger.grey('Operation canceled')
446
+ this.Logger.grey("Operation canceled");
421
447
  }
422
448
 
423
449
  async conf(options) {
@@ -427,53 +453,51 @@ class Conf extends require('../Command') {
427
453
  // if (options.list) {
428
454
  // await this.showList(options)
429
455
  // } else
430
- if (options.show) {
431
- await this.showConf(options)
432
- // } else if (options.recoveryCode) {
433
- // await this.setRecoveryCode(options)
434
- // } else if (options.fido2) {
435
- // let yes = await this.useConfirm({
436
- // message: 'Fido2 requires external libraries written in Python. It is an experimental feature, and it is not guaranteed to work. Are you sure you want to set it up?',
437
- // default: false
438
- // })
439
- // if (!yes) {
440
- // throw new Error('Operation canceled')
441
- // }
442
- // await this.fido2Client.checkIfReady()
443
- // await this.setFido2(options)
444
- // } else if (options.unregister) {
445
- // await this.unregister(options)
456
+ if (options.show) {
457
+ await this.showConf(options);
458
+ // } else if (options.recoveryCode) {
459
+ // await this.setRecoveryCode(options)
460
+ // } else if (options.fido2) {
461
+ // let yes = await this.useConfirm({
462
+ // message: 'Fido2 requires external libraries written in Python. It is an experimental feature, and it is not guaranteed to work. Are you sure you want to set it up?',
463
+ // default: false
464
+ // })
465
+ // if (!yes) {
466
+ // throw new Error('Operation canceled')
467
+ // }
468
+ // await this.fido2Client.checkIfReady()
469
+ // await this.setFido2(options)
470
+ // } else if (options.unregister) {
471
+ // await this.unregister(options)
446
472
  } else if (options.newPassword || options.newIterationsNumber) {
447
- await this.upgradeAccount(options)
473
+ await this.upgradeAccount(options);
448
474
  } else {
449
- throw new Error('Missing parameters. Run "conf -h" to see examples.')
475
+ throw new Error('Missing parameters. Run "conf -h" to see examples.');
450
476
  }
451
477
  }
452
478
 
453
479
  async exec(options = {}) {
454
480
  if (options.help) {
455
- return this.showHelp()
481
+ return this.showHelp();
456
482
  }
457
483
  try {
458
484
  // if (!Object.keys(options).length) {
459
485
  // options.list = true
460
486
  // }
461
- this.validate(options)
487
+ this.validate(options);
462
488
  // if (options.fido2 && options.recoveryCode) {
463
489
  // throw new Error('Conflicting params. Launch "conf -h" for examples.')
464
490
  // }
465
491
  // if (options.register && !(options.fido2 || options.recoveryCode)) {
466
492
  // throw new Error('Missing parameters. Launch "conf -h" for examples.')
467
493
  // }
468
- await this.conf(options)
494
+ await this.conf(options);
469
495
  } catch (e) {
470
496
  // console.error(e)
471
- this.Logger.red(e.message)
497
+ this.Logger.red(e.message);
472
498
  }
473
- await this.prompt.run()
499
+ await this.prompt.run();
474
500
  }
475
501
  }
476
502
 
477
- module.exports = Conf
478
-
479
-
503
+ module.exports = Conf;