win-cliauth 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/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) <2022>, <Pedro Lucas Magalhães de Oliveira>
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the copyright holder nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # win-cliauth
2
+
3
+ win-cliauth is a CLI-based OTP (One-Time Password) authenticator management tool for Windows.
4
+
5
+ ## Installation
6
+
7
+ You can install win-cliauth globally using npm:
8
+
9
+ npm install -g win-cliauth
10
+
11
+ ## Usage
12
+
13
+ win-cliauth provides a command-line interface for managing OTP (One-Time Password) authenticators. It supports the following commands:
14
+
15
+ - `add <name> <secret-key>`: Adds an authenticator with the given name and secret key.
16
+ - `add <name> <secret-key> --replace`: Adds an authenticator, replacing an existing one with the same name.
17
+ - `remove <name>`: Removes the authenticator with the specified name.
18
+ - `get <name>`: Retrieves the token from the authenticator with the specified name.
19
+ - `get <name> --steam`: Retrieves the token from the Steam authenticator with the specified name.
20
+ - `get <name> --clipboard`: Retrieves the token and adds it to the clipboard.
21
+ - `list`: Lists all registered authenticators.
22
+ - `list --showsecret`: Lists all registered authenticators, including the secret keys.
23
+
24
+ To use win-cliauth, open a terminal or command prompt and run one of the commands listed above.
25
+
26
+ For detailed information on the available commands and options, you can run:
27
+
28
+ win-cliauth --help
29
+
30
+ ## Security
31
+
32
+ - win-cliauth encrypts the secret keys using the `ConvertTo-SecureString` command in PowerShell before storing them on disk.
33
+ - The secret keys are stored in an encrypted file in the user's data directory, protected by the user's operating system.
34
+ - Please note that the encrypted file can only be read on the same Windows user account where it was created. It may not be readable on other user accounts or operating systems.
35
+
36
+ ## Contributing
37
+
38
+ Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on [GitHub](https://github.com/pedrolucasmag/win-cliauth).
39
+
40
+ ## License
41
+
42
+ This project is licensed under the BSD-3-Clause License. See the LICENSE file for details.
package/dist/main.js ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /*
4
+ Copyright (c) <2022>, <Pedro Lucas Magalhães de Oliveira>
5
+ All rights reserved.
6
+
7
+ This source code is licensed under the BSD-style license found in the
8
+ LICENSE file in the root directory of this source tree.
9
+ */
10
+ var _a, _b;
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const commands_1 = require("./src/commands");
13
+ const pshell_1 = require("./src/pshell");
14
+ (_b = (_a = (0, pshell_1.decrypt)().stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
15
+ const svcs = JSON.parse(data);
16
+ (0, commands_1.handleCommands)(svcs);
17
+ })) !== null && _b !== void 0 ? _b : false;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) <2022>, <Pedro Lucas Magalhães de Oliveira>
4
+ All rights reserved.
5
+
6
+ This source code is licensed under the BSD-style license found in the
7
+ LICENSE file in the root directory of this source tree.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.listAuth = exports.removeAuth = exports.addAuth = exports.getAuth = void 0;
11
+ const child_process_1 = require("child_process");
12
+ const otplib_1 = require("otplib");
13
+ const steam_totp_1 = require("steam-totp");
14
+ const pshell_1 = require("./pshell");
15
+ function getToken({ key, steam }) {
16
+ return steam ? (0, steam_totp_1.generateAuthCode)(key) : otplib_1.authenticator.generate(key);
17
+ }
18
+ function getAuth({ objAuth, svc, clipboard, steam }) {
19
+ const skey = objAuth[`${svc}`];
20
+ if (skey) {
21
+ const token = getToken({ key: skey, steam: steam });
22
+ if (clipboard)
23
+ (0, child_process_1.spawn)('clip').stdin.end(token);
24
+ return console.info(token);
25
+ }
26
+ return console.info(`${svc} not found.`);
27
+ }
28
+ exports.getAuth = getAuth;
29
+ function addAuth({ objAuth, svc, sk, replace }) {
30
+ if (objAuth[`${svc}`] && !replace)
31
+ return console.info(`${svc} already exists, adds --replace to overwrite it.`);
32
+ objAuth[`${svc}`] = String(sk);
33
+ (0, pshell_1.encrypt)({ str: JSON.stringify(objAuth) });
34
+ return console.info(`${svc} added!`);
35
+ }
36
+ exports.addAuth = addAuth;
37
+ function removeAuth({ objAuth, svc }) {
38
+ if (!objAuth[`${svc}`])
39
+ return console.info(`${svc} not found.`);
40
+ delete objAuth[`${svc}`];
41
+ (0, pshell_1.encrypt)({ str: JSON.stringify(objAuth) });
42
+ return console.info(`${svc} removed!`);
43
+ }
44
+ exports.removeAuth = removeAuth;
45
+ function listAuth({ objAuth, showsecret }) {
46
+ return showsecret ? console.table(objAuth) : console.table(Object.keys(objAuth));
47
+ }
48
+ exports.listAuth = listAuth;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) <2022>, <Pedro Lucas Magalhães de Oliveira>
4
+ All rights reserved.
5
+
6
+ This source code is licensed under the BSD-style license found in the
7
+ LICENSE file in the root directory of this source tree.
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.handleCommands = void 0;
14
+ const yargs_1 = __importDefault(require("yargs"));
15
+ const helpers_1 = require("yargs/helpers");
16
+ const auth_1 = require("./auth");
17
+ function handleCommands(objAuth) {
18
+ return (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
19
+ .scriptName("win-cliauth")
20
+ .command('add <name> <secret-key>', 'adds authenticator with given secret key.', (y) => y.options({
21
+ 'replace': {
22
+ description: "forces replacement of existing service.",
23
+ require: false
24
+ },
25
+ }), (argv) => (0, auth_1.addAuth)({ objAuth, svc: argv.name, sk: argv.secretKey, replace: argv.replace }))
26
+ .command('remove <name>', 'removes the given <name> authenticator.', {}, (argv) => (0, auth_1.removeAuth)({ objAuth, svc: argv.name }))
27
+ .command('get <name>', 'gets the token from service <name> (for steam guard, add --steam)', (y) => y.options({
28
+ 'steam': {
29
+ description: "gets token from steam authenticator.",
30
+ required: false
31
+ },
32
+ 'clipboard': {
33
+ description: 'adds authenticator code to clipboard',
34
+ required: false
35
+ }
36
+ }), (argv) => {
37
+ (0, auth_1.getAuth)({ objAuth, svc: argv.name, clipboard: argv.clipboard, steam: argv.steam });
38
+ })
39
+ .command('list', 'Prints out the list of authenticators.', (y) => y.options({
40
+ 'showsecret': {
41
+ description: "Prints out the list with secret keys",
42
+ require: false
43
+ },
44
+ }), (argv) => (0, auth_1.listAuth)({ objAuth, showsecret: argv.showsecret }))
45
+ .wrap(null)
46
+ .showHelpOnFail(true)
47
+ .demandCommand()
48
+ .recommendCommands()
49
+ .strict()
50
+ .parse();
51
+ }
52
+ exports.handleCommands = handleCommands;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) <2022>, <Pedro Lucas Magalhães de Oliveira>
4
+ All rights reserved.
5
+
6
+ This source code is licensed under the BSD-style license found in the
7
+ LICENSE file in the root directory of this source tree.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.decrypt = exports.encrypt = void 0;
11
+ const child_process_1 = require("child_process");
12
+ function pshell({ cmd }) {
13
+ return (0, child_process_1.exec)(cmd, { shell: 'powershell.exe' });
14
+ }
15
+ function encrypt({ str }) {
16
+ return pshell({
17
+ cmd: `
18
+ $keyPath = "$($env:AppData)/win-cliauth/keys"
19
+ if (!(Test-Path "$keyPath")) { New-Item -Path $keyPath -Force }
20
+ $secureString = ConvertTo-SecureString '${str}' -AsPlainText -Force
21
+ $encrypted = ConvertFrom-SecureString -SecureString $secureString
22
+ $encrypted > $keyPath
23
+ `
24
+ });
25
+ }
26
+ exports.encrypt = encrypt;
27
+ function decrypt() {
28
+ return pshell({
29
+ cmd: `
30
+ $keyPath = "$($env:AppData)/win-cliauth/keys"
31
+ if (!(Test-Path "$keyPath")) { '{}' }
32
+ else {
33
+ $secureString = Get-Content $keyPath | ConvertTo-SecureString
34
+ $decrypted = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($secureString))
35
+ $decrypted
36
+ }`
37
+ });
38
+ }
39
+ exports.decrypt = decrypt;
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "win-cliauth",
3
+ "version": "1.0.0",
4
+ "description": "win-cliauth is a CLI-based OTP (One-Time Password) authenticator management tool for Windows.",
5
+ "author": "Pedro Lucas Magalhães <pedrolucasmag@gmail.com>",
6
+ "license": "BSD-3-Clause",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "prepack": "tsc"
10
+ },
11
+ "bin": {
12
+ "win-cliauth": "./dist/main.js"
13
+ },
14
+ "repository": "github:pedrolucasmag/win-cliauth",
15
+ "files": [
16
+ "dist",
17
+ "LICENSE",
18
+ "!dist/keys"
19
+ ],
20
+ "devDependencies": {
21
+ "@types/node": "^18.11.10",
22
+ "@types/steam-totp": "^2.1.0",
23
+ "@types/yargs": "^17.0.10",
24
+ "@typescript-eslint/eslint-plugin": "^5.33.1",
25
+ "@typescript-eslint/parser": "^5.33.1",
26
+ "eslint": "^8.22.0"
27
+ },
28
+ "os": [
29
+ "win32"
30
+ ],
31
+ "dependencies": {
32
+ "otplib": "^12.0.1",
33
+ "steam-totp": "^2.1.2",
34
+ "yargs": "^17.5.1"
35
+ }
36
+ }