win-cliauth 1.0.0 → 1.0.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.
- package/README.md +11 -0
- package/dist/main.js +14 -4
- package/dist/src/auth.js +50 -10
- package/dist/src/pshell.js +1 -1
- package/package.json +17 -4
package/README.md
CHANGED
|
@@ -33,6 +33,17 @@ win-cliauth --help
|
|
|
33
33
|
- The secret keys are stored in an encrypted file in the user's data directory, protected by the user's operating system.
|
|
34
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
35
|
|
|
36
|
+
## Credits
|
|
37
|
+
|
|
38
|
+
This project uses the following open-source libraries:
|
|
39
|
+
|
|
40
|
+
- [otpauth](https://github.com/hectorm/otpauth) - One Time Password (HOTP/TOTP) library for Node.js, Deno, Bun and browsers.
|
|
41
|
+
- [steam-totp](https://github.com/DoctorMcKay/node-steam-totp) - A Node.js library for generating Steam-compatible 2FA tokens.
|
|
42
|
+
- [yargs](https://github.com/yargs/yargs) - A command-line argument parsing library for Node.js.
|
|
43
|
+
|
|
44
|
+
Please refer to the respective library documentation for detailed information on their usage, licensing, and contributions.
|
|
45
|
+
|
|
46
|
+
|
|
36
47
|
## Contributing
|
|
37
48
|
|
|
38
49
|
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).
|
package/dist/main.js
CHANGED
|
@@ -11,7 +11,17 @@ var _a, _b;
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const commands_1 = require("./src/commands");
|
|
13
13
|
const pshell_1 = require("./src/pshell");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const childProcess = (0, pshell_1.decrypt)();
|
|
15
|
+
let rawData = '';
|
|
16
|
+
(_a = childProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (chunk) => {
|
|
17
|
+
rawData += chunk;
|
|
18
|
+
});
|
|
19
|
+
(_b = childProcess.stdout) === null || _b === void 0 ? void 0 : _b.on('end', () => {
|
|
20
|
+
try {
|
|
21
|
+
const svcs = JSON.parse(rawData);
|
|
22
|
+
(0, commands_1.handleCommands)(svcs);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error('Error parsing JSON:', error);
|
|
26
|
+
}
|
|
27
|
+
});
|
package/dist/src/auth.js
CHANGED
|
@@ -6,24 +6,64 @@ All rights reserved.
|
|
|
6
6
|
This source code is licensed under the BSD-style license found in the
|
|
7
7
|
LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
10
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
13
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
14
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
15
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
16
|
+
});
|
|
17
|
+
};
|
|
9
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
19
|
exports.listAuth = exports.removeAuth = exports.addAuth = exports.getAuth = void 0;
|
|
11
20
|
const child_process_1 = require("child_process");
|
|
12
|
-
const
|
|
21
|
+
const otpauth_1 = require("otpauth");
|
|
13
22
|
const steam_totp_1 = require("steam-totp");
|
|
14
23
|
const pshell_1 = require("./pshell");
|
|
24
|
+
function synchronizeTime() {
|
|
25
|
+
var _a;
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
(_a = AbortSignal.timeout) !== null && _a !== void 0 ? _a : (AbortSignal.timeout = function timeout(ms) {
|
|
28
|
+
const ctrl = new AbortController();
|
|
29
|
+
setTimeout(() => ctrl.abort(), ms);
|
|
30
|
+
return ctrl.signal;
|
|
31
|
+
});
|
|
32
|
+
try {
|
|
33
|
+
const response = yield fetch('http://www.google.com', { signal: AbortSignal.timeout(5000) });
|
|
34
|
+
const responseHeaders = response.headers;
|
|
35
|
+
const headerDate = responseHeaders.get('date');
|
|
36
|
+
const serverTime = headerDate ? Date.parse(headerDate) : Date.now();
|
|
37
|
+
const localTime = Date.now();
|
|
38
|
+
const timeDifference = serverTime - localTime;
|
|
39
|
+
return Date.now() + timeDifference;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
return Date.now();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function getTOTP(key) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const auth = new otpauth_1.TOTP({ secret: key, digits: 6, period: 30 });
|
|
49
|
+
const timestamp = yield synchronizeTime();
|
|
50
|
+
return auth.generate({ timestamp });
|
|
51
|
+
});
|
|
52
|
+
}
|
|
15
53
|
function getToken({ key, steam }) {
|
|
16
|
-
return steam ? (0, steam_totp_1.generateAuthCode)(key) :
|
|
54
|
+
return steam ? (0, steam_totp_1.generateAuthCode)(key) : getTOTP(key).then((code) => code);
|
|
17
55
|
}
|
|
18
56
|
function getAuth({ objAuth, svc, clipboard, steam }) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const skey = objAuth[`${svc}`];
|
|
59
|
+
if (skey) {
|
|
60
|
+
const token = yield getToken({ key: skey, steam: steam });
|
|
61
|
+
if (clipboard)
|
|
62
|
+
(0, child_process_1.spawn)('clip').stdin.end(token);
|
|
63
|
+
return console.info(token);
|
|
64
|
+
}
|
|
65
|
+
return console.info(`${svc} not found.`);
|
|
66
|
+
});
|
|
27
67
|
}
|
|
28
68
|
exports.getAuth = getAuth;
|
|
29
69
|
function addAuth({ objAuth, svc, sk, replace }) {
|
package/dist/src/pshell.js
CHANGED
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.decrypt = exports.encrypt = void 0;
|
|
11
11
|
const child_process_1 = require("child_process");
|
|
12
12
|
function pshell({ cmd }) {
|
|
13
|
-
return (0, child_process_1.
|
|
13
|
+
return (0, child_process_1.spawn)('powershell.exe', ['/c', cmd], { stdio: 'pipe' });
|
|
14
14
|
}
|
|
15
15
|
function encrypt({ str }) {
|
|
16
16
|
return pshell({
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "win-cliauth",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "win-cliauth is a CLI-based OTP (One-Time Password) authenticator management tool for Windows.",
|
|
5
5
|
"author": "Pedro Lucas Magalhães <pedrolucasmag@gmail.com>",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
+
"release": "standard-version",
|
|
9
10
|
"prepack": "tsc"
|
|
10
11
|
},
|
|
11
12
|
"bin": {
|
|
@@ -18,19 +19,31 @@
|
|
|
18
19
|
"!dist/keys"
|
|
19
20
|
],
|
|
20
21
|
"devDependencies": {
|
|
22
|
+
"@commitlint/cli": "^17.7.1",
|
|
23
|
+
"@commitlint/config-conventional": "^17.7.0",
|
|
21
24
|
"@types/node": "^18.11.10",
|
|
22
25
|
"@types/steam-totp": "^2.1.0",
|
|
23
26
|
"@types/yargs": "^17.0.10",
|
|
24
27
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
25
28
|
"@typescript-eslint/parser": "^5.33.1",
|
|
26
|
-
"eslint": "^8.22.0"
|
|
29
|
+
"eslint": "^8.22.0",
|
|
30
|
+
"husky": "^8.0.3"
|
|
27
31
|
},
|
|
28
32
|
"os": [
|
|
29
33
|
"win32"
|
|
30
34
|
],
|
|
35
|
+
"keywords": [
|
|
36
|
+
"otp",
|
|
37
|
+
"authenticator",
|
|
38
|
+
"cli",
|
|
39
|
+
"windows",
|
|
40
|
+
"steamguard",
|
|
41
|
+
"2fa",
|
|
42
|
+
"totp"
|
|
43
|
+
],
|
|
31
44
|
"dependencies": {
|
|
32
|
-
"
|
|
45
|
+
"otpauth": "^9.1.4",
|
|
33
46
|
"steam-totp": "^2.1.2",
|
|
34
47
|
"yargs": "^17.5.1"
|
|
35
48
|
}
|
|
36
|
-
}
|
|
49
|
+
}
|