@zohocorporation/vault-cli 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 +16 -0
- package/out/commands/add/add.const.js +6 -0
- package/out/commands/add/add.types.js +2 -0
- package/out/commands/add/add.util.js +35 -0
- package/out/commands/download/download.const.js +6 -0
- package/out/commands/download/download.types.js +2 -0
- package/out/commands/download/download.utils.js +35 -0
- package/out/commands/generate-password/generate-password.const.js +12 -0
- package/out/commands/generate-password/generate-password.types.js +2 -0
- package/out/commands/generate-password/generate-password.utils.js +58 -0
- package/out/commands/generate-template/generate-template.const.js +7 -0
- package/out/commands/generate-template/generate-template.types.js +2 -0
- package/out/commands/generate-template/generate-template.util.js +37 -0
- package/out/commands/get/get.const.js +8 -0
- package/out/commands/get/get.types.js +2 -0
- package/out/commands/get/get.utils.js +45 -0
- package/out/commands/get-default/get-default.const.js +5 -0
- package/out/commands/get-default/get-default.types.js +2 -0
- package/out/commands/get-default/get-default.utils.js +33 -0
- package/out/commands/list/list.const.js +7 -0
- package/out/commands/list/list.types.js +2 -0
- package/out/commands/list/list.utils.js +43 -0
- package/out/commands/lock/lock.action.js +13 -0
- package/out/commands/lock/lock.js +10 -0
- package/out/commands/lock/lock.utils.js +52 -0
- package/out/commands/login/login.action.js +22 -0
- package/out/commands/login/login.const.js +10 -0
- package/out/commands/login/login.help.js +12 -0
- package/out/commands/login/login.js +17 -0
- package/out/commands/login/login.types.js +5 -0
- package/out/commands/login/login.utils.js +307 -0
- package/out/commands/reset/reset.action.js +28 -0
- package/out/commands/reset/reset.help.js +8 -0
- package/out/commands/reset/reset.js +14 -0
- package/out/commands/reset/reset.utils.js +2 -0
- package/out/commands/search/search.action.js +30 -0
- package/out/commands/search/search.constants.js +14 -0
- package/out/commands/search/search.help.js +6 -0
- package/out/commands/search/search.js +26 -0
- package/out/commands/search/search.types.js +16 -0
- package/out/commands/search/search.utils.js +61 -0
- package/out/commands/set-default/set-default.const.js +6 -0
- package/out/commands/set-default/set-default.types.js +2 -0
- package/out/commands/set-default/set-default.utils.js +39 -0
- package/out/commands/unlock/unlock.action.js +23 -0
- package/out/commands/unlock/unlock.help.js +2 -0
- package/out/commands/unlock/unlock.js +12 -0
- package/out/commands/unlock/unlock.type.js +2 -0
- package/out/commands/unlock/unlock.utils.js +133 -0
- package/out/js/I18n/index.js +80 -0
- package/out/js/I18n/resources/CLI_I18N_en.js +173 -0
- package/out/js/I18n/resources/CLI_I18N_es.js +3 -0
- package/out/js/I18n/resources/CLI_I18N_fr.js +3 -0
- package/out/js/I18n/resources/CLI_I18N_nl.js +3 -0
- package/out/js/I18n/resources/CLI_I18N_pt.js +3 -0
- package/out/js/I18n/resources/CLI_I18N_zh.js +3 -0
- package/out/js/crypto/aes.js +225 -0
- package/out/js/crypto/index.js +139 -0
- package/out/js/crypto/rsa.js +1945 -0
- package/out/js/crypto/zohovault.js +671 -0
- package/out/js/logger/index.js +10 -0
- package/out/old/Add.js +590 -0
- package/out/old/Default.js +209 -0
- package/out/old/Download.js +69 -0
- package/out/old/Generate.js +171 -0
- package/out/old/Get.js +225 -0
- package/out/old/List.js +197 -0
- package/out/old/Login.js +287 -0
- package/out/old/Logout.js +21 -0
- package/out/old/PasswordGenerator.js +718 -0
- package/out/old/PasswordPolicies.js +21 -0
- package/out/old/PasswordTypes.js +33 -0
- package/out/old/Update.js +682 -0
- package/out/old/cmd/addcmd.js +59 -0
- package/out/old/cmd/downloadcmd.js +76 -0
- package/out/old/cmd/generate-passwordcmd.js +127 -0
- package/out/old/cmd/generate-templatecmd.js +59 -0
- package/out/old/cmd/get-defaultcmd.js +48 -0
- package/out/old/cmd/getcmd.js +57 -0
- package/out/old/cmd/listcmd.js +54 -0
- package/out/old/cmd/logoutcmd.js +31 -0
- package/out/old/cmd/set-default.js +75 -0
- package/out/old/cmd/updatecmd.js +44 -0
- package/out/old/index.js +580 -0
- package/out/util/configuration.util.js +103 -0
- package/out/util/consts.util.js +97 -0
- package/out/util/dbutils/db.types.js +2 -0
- package/out/util/dbutils/db.utils.js +164 -0
- package/out/util/dbutils/dbtable.utils.js +19 -0
- package/out/util/dev.utils.js +14 -0
- package/out/util/encryptionutil/encryption.uitl.js +108 -0
- package/out/util/index.util.js +341 -0
- package/out/util/keyringutil/keyring.util.js +57 -0
- package/out/util/loader/loader.interface.js +2 -0
- package/out/util/loader/transfer.loader.js +28 -0
- package/out/util/login.util.js +352 -0
- package/out/util/passwordtypes.util.js +91 -0
- package/out/util/print.util.js +4 -0
- package/out/util/search.util.js +359 -0
- package/out/util/types.util.js +7 -0
- package/out/zv.js +41 -0
- package/package.json +96 -0
package/out/old/List.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { Utilities, _pull } from "../util/index.util.js";
|
|
2
|
+
import { PasswordTypes } from "../util/passwordtypes.util.js";
|
|
3
|
+
import { I18N } from "../js/I18n/index.js";
|
|
4
|
+
import { Login } from "../util/login.util.js";
|
|
5
|
+
import wrap from "word-wrap";
|
|
6
|
+
import * as stringSimilarity from "string-similarity";
|
|
7
|
+
import { OPTIONS, VAULT_ENDPOINTS } from "../util/consts.util.js";
|
|
8
|
+
import { header } from "../commands/login/login.utils.js";
|
|
9
|
+
import { Logger } from "../js/logger/index.js";
|
|
10
|
+
// var stringSimilarity = require("string-similarity"); //No I18N
|
|
11
|
+
let i18nText;
|
|
12
|
+
export class List extends Login {
|
|
13
|
+
constructor(typeId, show, type, verbose) {
|
|
14
|
+
super();
|
|
15
|
+
this.fields = ["secretname", "description", "tags"];
|
|
16
|
+
i18nText = new I18N();
|
|
17
|
+
this.showPassword = show;
|
|
18
|
+
this.typeId = typeId;
|
|
19
|
+
this.type = type;
|
|
20
|
+
this.verbose = verbose;
|
|
21
|
+
}
|
|
22
|
+
async listSecrets() {
|
|
23
|
+
await this.getDcAndSetHeader();
|
|
24
|
+
this.masterKey = await this.getMasterKeyAfterConfiguration();
|
|
25
|
+
if (this.type === "password") {
|
|
26
|
+
if (this.typeId === undefined) {
|
|
27
|
+
this.typeId = "";
|
|
28
|
+
}
|
|
29
|
+
const resp = await _pull(header, Utilities.getVaultUrl(this.dc) + VAULT_ENDPOINTS.URL_SECRETS, {
|
|
30
|
+
isAsc: 'true',
|
|
31
|
+
pageNum: 0,
|
|
32
|
+
rowPerPage: -1,
|
|
33
|
+
secretType: this.typeId
|
|
34
|
+
});
|
|
35
|
+
if (resp.data.operation.result.status !== "Success") {
|
|
36
|
+
console.log(i18nText.getI18nMsg("vault.list.errorListing"));
|
|
37
|
+
console.log(resp.data.operation.result.message);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
let secrets = resp.data.operation.Details;
|
|
41
|
+
if (secrets === undefined || secrets.length === 0) {
|
|
42
|
+
console.log(i18nText.getI18nMsg("vault.list.noPasswordFound"));
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
let arr = [];
|
|
46
|
+
if (this.verbose) {
|
|
47
|
+
let secretType = {};
|
|
48
|
+
let templates = await PasswordTypes.getPasswordTypes(this.dc, undefined, OPTIONS.LIST, false);
|
|
49
|
+
for (let id in templates) {
|
|
50
|
+
secretType[templates[id].secret_type_name] = [];
|
|
51
|
+
}
|
|
52
|
+
for (let i = 0; i < secrets.length; i++) {
|
|
53
|
+
try {
|
|
54
|
+
secretType[templates[secrets[i].accounttype].secret_type_name].push(secrets[i]);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
Logger.error(e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (let name in secretType) {
|
|
61
|
+
arr = [];
|
|
62
|
+
if (secretType[name].length > 0) {
|
|
63
|
+
console.log(i18nText.getI18nMsg("vault.list.listsecrets_category") + `${name}`);
|
|
64
|
+
for (let i = 0; i < secretType[name].length; i++) {
|
|
65
|
+
let secretData = templates[secretType[name][i].accounttype];
|
|
66
|
+
await this.decryptSecretObject(secretType[name][i], secretData.secret_type_fields, this.showPassword);
|
|
67
|
+
let obj = [];
|
|
68
|
+
let fileArr = this.formatFilesArr(secretType[name][i].files);
|
|
69
|
+
obj[i18nText.getI18nMsg("vault.search.formatDataForTable_head_passwordId")] = wrap(secretType[name][i].secretid);
|
|
70
|
+
obj[i18nText.getI18nMsg("vault.search.formatDataForTable_head_passwordName")] = wrap(secretType[name][i].secretname, { width: 10 });
|
|
71
|
+
obj[i18nText.getI18nMsg("vault.search.formatDataForTable_head_Description")] = wrap(secretType[name][i].description, { width: 10 });
|
|
72
|
+
secretData = secretType[name][i].secretData;
|
|
73
|
+
if (!secretData) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
for (const [key, value] of Object.entries(secretData)) {
|
|
77
|
+
let label = key;
|
|
78
|
+
let name = value;
|
|
79
|
+
if (key === "username") {
|
|
80
|
+
label = i18nText.getI18nMsg("vault.search.formatDataForTable_head_username"); //No I18N
|
|
81
|
+
}
|
|
82
|
+
else if (key === "password") {
|
|
83
|
+
label = i18nText.getI18nMsg("vault.search.formatDataForTable_head_password"); //No I18N
|
|
84
|
+
}
|
|
85
|
+
else if (key === "file") { //File Attachments
|
|
86
|
+
label = i18nText.getI18nMsg("vault.search.formatDataForTable_head_file"); //No I18N
|
|
87
|
+
}
|
|
88
|
+
else if (key === "agency") { //Health Care Agency
|
|
89
|
+
label = i18nText.getI18nMsg("vault.search.formatDataForTable_head_agency"); //No I18N
|
|
90
|
+
}
|
|
91
|
+
else if (key === "policyno") { //Health Care Agency
|
|
92
|
+
label = i18nText.getI18nMsg("vault.search.formatDataForTable_head_policyno"); //No I18N
|
|
93
|
+
}
|
|
94
|
+
else if (key === "groupno") { //Health care Agency
|
|
95
|
+
label = i18nText.getI18nMsg("vault.search.formatDataForTable_head_groupno"); //No I18N
|
|
96
|
+
}
|
|
97
|
+
else if (key === "name") { //category :- Social Security Account
|
|
98
|
+
label = i18nText.getI18nMsg("vault.search.formatDataForTable_head_name"); //No I18N
|
|
99
|
+
}
|
|
100
|
+
else if (key === "ssno") { // Social Security Account
|
|
101
|
+
label = i18nText.getI18nMsg("vault.search.formatDataForTable_head_ssno"); //No I18N
|
|
102
|
+
}
|
|
103
|
+
else if (key === "accno") { //Bank Account
|
|
104
|
+
label = i18nText.getI18nMsg("vault.search.formatDataForTable_head_accno"); //No I18N
|
|
105
|
+
}
|
|
106
|
+
else if (key === "bankid") { //Bank Account
|
|
107
|
+
label = i18nText.getI18nMsg("vault.search.formatDataForTable_head_bankid"); //No I18N
|
|
108
|
+
}
|
|
109
|
+
if (name === "file") {
|
|
110
|
+
obj[label] = wrap(fileArr[value], { width: 10 });
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
if (obj.hasOwnProperty(label)) {
|
|
114
|
+
obj[wrap(`${label}(${name})`)] = wrap(value, { width: 10 });
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
obj[label] = wrap(value, { width: 10 });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
arr.push(obj);
|
|
122
|
+
}
|
|
123
|
+
Utilities.printTable(arr);
|
|
124
|
+
console.log(`\nTotal: ${arr.length} password(s) retrieved\n`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
let arr = [];
|
|
130
|
+
for (let i = 0; i < secrets.length; i++) {
|
|
131
|
+
let obj = {};
|
|
132
|
+
obj[i18nText.getI18nMsg("vault.search.formatDataForTable_head_passwordId")] = secrets[i].secretid;
|
|
133
|
+
obj[i18nText.getI18nMsg("vault.search.formatDataForTable_head_passwordName")] = wrap(secrets[i].secretname, { width: 10 });
|
|
134
|
+
obj[i18nText.getI18nMsg("vault.search.formatDataForTable_head_Description")] = wrap(secrets[i].description, { width: 10 });
|
|
135
|
+
obj[i18nText.getI18nMsg("vault.search.formatDataForTable_head_ownerName")] = secrets[i].ownerdetails.USERNAME;
|
|
136
|
+
obj[i18nText.getI18nMsg("vault.search.formatDataForTable_head_owneremail")] = wrap(secrets[i].ownerdetails.EMAIL, { width: 15 });
|
|
137
|
+
arr.push(obj);
|
|
138
|
+
}
|
|
139
|
+
Utilities.printTable(arr);
|
|
140
|
+
console.log(`\nTotal: ${arr.length} password(s) retrieved\n`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else if (this.type === "category") {
|
|
144
|
+
const pTypes = await PasswordTypes.getPasswordTypes(this.dc, undefined, OPTIONS.LIST, true);
|
|
145
|
+
const arr = this.formatTypesForTable(pTypes);
|
|
146
|
+
}
|
|
147
|
+
else if (this.type === "folder") {
|
|
148
|
+
let folders = await _pull(header, Utilities.getVaultUrl(this.dc) + VAULT_ENDPOINTS.URL_FOLDER, {
|
|
149
|
+
pageNum: 1,
|
|
150
|
+
rowPerPage: -1
|
|
151
|
+
});
|
|
152
|
+
folders = folders.data.operation.Details;
|
|
153
|
+
let folderTable = [];
|
|
154
|
+
for (let i = 0; i < folders.length; i++) {
|
|
155
|
+
folderTable.push({
|
|
156
|
+
'ID': folders[i].chamberid,
|
|
157
|
+
'Name': folders[i].chambername,
|
|
158
|
+
'Password Count': folders[i].secretcount
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
Utilities.printTable(folderTable);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
const category = ["password", "category", "folder"]; //No I18N
|
|
165
|
+
var matches = stringSimilarity.findBestMatch(this.type, category);
|
|
166
|
+
let bestCommand = matches.bestMatch.target;
|
|
167
|
+
console.log(i18nText.getI18nMsg("vault.list.category_suggestion"), bestCommand);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
formatTypesForTable(pTypes) {
|
|
171
|
+
const arr = [];
|
|
172
|
+
let i = 0;
|
|
173
|
+
for (const pTypeId in pTypes) {
|
|
174
|
+
const pType = pTypes[pTypeId];
|
|
175
|
+
arr.push({
|
|
176
|
+
SNO: ++i,
|
|
177
|
+
"Category ID": pTypeId, //No I18N
|
|
178
|
+
"Category Name": pType.secret_type_name //No I18N
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
Utilities.printTable(arr);
|
|
182
|
+
return arr;
|
|
183
|
+
}
|
|
184
|
+
formatFilesArr(files) {
|
|
185
|
+
if (files === undefined) {
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
const filesArr = JSON.parse(files);
|
|
189
|
+
let filesObj = {};
|
|
190
|
+
for (let i = 0; i < filesArr.length; i++) {
|
|
191
|
+
const file = filesArr[i];
|
|
192
|
+
filesObj[file.column] = file.name;
|
|
193
|
+
}
|
|
194
|
+
return filesObj;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=List.js.map
|
package/out/old/Login.js
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import Vault from "../js/crypto/index.js";
|
|
2
|
+
import { Logger } from "../js/logger/index.js";
|
|
3
|
+
import inquirer from "inquirer";
|
|
4
|
+
import { getDecryptedCredentials, insertToDB } from "../util/dbutils/db.utils.js";
|
|
5
|
+
import { generateWorkspaceHash } from "../commands/login/login.utils.js";
|
|
6
|
+
import { MODE } from "../util/consts.util.js";
|
|
7
|
+
import { CREDENTIALS } from "../util/consts.util.js";
|
|
8
|
+
import { getConfig } from "../util/dev.utils.js";
|
|
9
|
+
import chalk from "chalk";
|
|
10
|
+
import { setHeaders, urlGenerateToken, urlLogin, Utilites, _pull, urlOrgKey, } from "./index.js";
|
|
11
|
+
import { Utilities } from "../util/index.util.js";
|
|
12
|
+
import { DC } from "../util/consts.util.js";
|
|
13
|
+
import { exit } from "node:process";
|
|
14
|
+
export class Login {
|
|
15
|
+
constructor(passphrase) {
|
|
16
|
+
this.passphrase = passphrase;
|
|
17
|
+
}
|
|
18
|
+
getDcAndSetHeader = async () => {
|
|
19
|
+
const data = await getDecryptedCredentials(generateWorkspaceHash());
|
|
20
|
+
if (!data) {
|
|
21
|
+
throw new Error("cannot find data"); //NO I18N
|
|
22
|
+
}
|
|
23
|
+
const { credentials, createdtime, dc } = data;
|
|
24
|
+
const { access_token, refresh_token } = credentials;
|
|
25
|
+
this.accessToken = !!access_token ? access_token : "";
|
|
26
|
+
this.refreshToken = !!refresh_token ? refresh_token : "";
|
|
27
|
+
this.createdTime = !!createdtime ? +createdtime : 0;
|
|
28
|
+
this.dc = !!dc ? dc : DC.US;
|
|
29
|
+
await this.checkAccessTokenValidity();
|
|
30
|
+
setHeaders("Authorization", `Zoho-oauthtoken ${this.accessToken}`);
|
|
31
|
+
};
|
|
32
|
+
async getAccessTokenforunlock() {
|
|
33
|
+
const data = await getDecryptedCredentials(generateWorkspaceHash());
|
|
34
|
+
if (!data) {
|
|
35
|
+
console.log(`No credentails found try ${chalk.green('zv login')}`);
|
|
36
|
+
exit(0);
|
|
37
|
+
}
|
|
38
|
+
const { credentials } = data;
|
|
39
|
+
return credentials.access_token;
|
|
40
|
+
}
|
|
41
|
+
async getKeyForToken() {
|
|
42
|
+
if (this.tokenSalt === undefined) {
|
|
43
|
+
this.tokenSalt = Utilites.generateRandomToken(40);
|
|
44
|
+
}
|
|
45
|
+
return await Vault.PBKDF2_key(this.masterKey, this.tokenSalt, this.iteration);
|
|
46
|
+
}
|
|
47
|
+
async refreshAccessToken() {
|
|
48
|
+
/*
|
|
49
|
+
generate new access token with the help of refresh token
|
|
50
|
+
*/
|
|
51
|
+
const config = getConfig();
|
|
52
|
+
let { MODE: mode, CLIENT_ID, CLIENT_SECRET } = config;
|
|
53
|
+
if (mode === MODE.PRODUCTION) {
|
|
54
|
+
CLIENT_ID = CREDENTIALS.CLIENT_ID;
|
|
55
|
+
CLIENT_SECRET = CREDENTIALS.CLIENT_SECRET;
|
|
56
|
+
}
|
|
57
|
+
let newCreatedTime = Date.now();
|
|
58
|
+
let data = {
|
|
59
|
+
refresh_token: this.refreshToken,
|
|
60
|
+
client_id: CLIENT_ID,
|
|
61
|
+
client_secret: CLIENT_SECRET,
|
|
62
|
+
grant_type: "refresh_token",
|
|
63
|
+
};
|
|
64
|
+
try {
|
|
65
|
+
let resp = await _pull(Utilites.getAccountsUrl(this.dc) + urlGenerateToken, data, "POST");
|
|
66
|
+
resp = resp.data;
|
|
67
|
+
if (resp.hasOwnProperty("access_token")) {
|
|
68
|
+
this.accessToken = resp.access_token;
|
|
69
|
+
const cred = await getDecryptedCredentials(generateWorkspaceHash());
|
|
70
|
+
if (!cred) {
|
|
71
|
+
console.log(`Credentials not found, try ${chalk.green('zv login')} again`);
|
|
72
|
+
exit(0);
|
|
73
|
+
}
|
|
74
|
+
const { credentials } = cred;
|
|
75
|
+
credentials.access_token = resp.access_token;
|
|
76
|
+
credentials.refresh_token = data.refresh_token;
|
|
77
|
+
let modifiedData = { ...cred, dc: this.dc, createdtime: newCreatedTime.toString() };
|
|
78
|
+
insertToDB(modifiedData);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
Logger.error(e);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async checkAccessTokenValidity() {
|
|
86
|
+
const localtime = Date.now();
|
|
87
|
+
let diffMs = localtime - this.createdTime; // milliseconds between now & Christmas
|
|
88
|
+
let diffMins = Math.abs(Math.round(diffMs / 1000 / 60));
|
|
89
|
+
if (diffMins > 50) {
|
|
90
|
+
await this.refreshAccessToken();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async get_salt() {
|
|
94
|
+
const resp = await _pull(Utilites.getVaultUrl(this.dc) + urlLogin, { OPERATION_NAME: "GET_LOGIN" }, "POST");
|
|
95
|
+
const { ITERATION, PASSPHRASE, LOGIN, SALT } = resp.data.operation.details;
|
|
96
|
+
this.iteration = ITERATION;
|
|
97
|
+
this.passauth = PASSPHRASE;
|
|
98
|
+
this.loginType = LOGIN;
|
|
99
|
+
this.salt = SALT;
|
|
100
|
+
}
|
|
101
|
+
async getMasterKey(passphrase) {
|
|
102
|
+
if (this.salt === undefined) {
|
|
103
|
+
await this.get_salt();
|
|
104
|
+
}
|
|
105
|
+
if (this.masterKey === undefined) {
|
|
106
|
+
let masterKey;
|
|
107
|
+
if (this.loginType === "PBKDF2_AES") {
|
|
108
|
+
masterKey = await Vault.PBKDF2_key(passphrase, this.salt, this.iteration);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
//TODO check this case
|
|
112
|
+
masterKey = Vault.hash(passphrase);
|
|
113
|
+
}
|
|
114
|
+
if (this.checkLogin(masterKey)) {
|
|
115
|
+
this.masterKey = masterKey;
|
|
116
|
+
return masterKey;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return this.masterKey;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
checkLogin(masterKey) {
|
|
127
|
+
const decryptedPassAuth = Vault.decrypt(this.passauth, masterKey);
|
|
128
|
+
try {
|
|
129
|
+
return !isNaN(Date.parse(JSON.parse(decryptedPassAuth).date));
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async getMasterKeyAfterConfiguration() {
|
|
136
|
+
const isCLITrusted = await Utilities.isTrusted();
|
|
137
|
+
if (isCLITrusted.status) {
|
|
138
|
+
return isCLITrusted.masterKey;
|
|
139
|
+
}
|
|
140
|
+
let passphraseVerified = false;
|
|
141
|
+
let passphraseMsg = "Please enter your master password: "; //No I18N
|
|
142
|
+
while (!passphraseVerified) {
|
|
143
|
+
let passphrase_inp = await inquirer.prompt([
|
|
144
|
+
{
|
|
145
|
+
type: "password",
|
|
146
|
+
name: "val",
|
|
147
|
+
mask: "*",
|
|
148
|
+
message: passphraseMsg,
|
|
149
|
+
},
|
|
150
|
+
]);
|
|
151
|
+
let passphrase = passphrase_inp.val;
|
|
152
|
+
const masterKey = await this.getMasterKey(passphrase);
|
|
153
|
+
if (masterKey === undefined) {
|
|
154
|
+
passphraseMsg = "Invalid master password. Please try again."; //No I18N
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
return masterKey;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async getOrgKey() {
|
|
162
|
+
const userConfig = await getDecryptedCredentials(generateWorkspaceHash());
|
|
163
|
+
const { credentials } = userConfig;
|
|
164
|
+
if (credentials && credentials.orgkey) {
|
|
165
|
+
return credentials.orgkey;
|
|
166
|
+
}
|
|
167
|
+
if (this.orgKey === undefined) {
|
|
168
|
+
const resp = await _pull(Utilites.getVaultUrl(this.dc) + urlOrgKey, {});
|
|
169
|
+
// const { privateKey, sharedKey } = resp.data.operation.Details;
|
|
170
|
+
// const pri = Vault.decrypt(privateKey, this.masterKey, 256);
|
|
171
|
+
// this.orgKey = Vault.RSA_decrypt(sharedKey, pri);
|
|
172
|
+
const keys = {
|
|
173
|
+
privateKey: resp.data.operation.Details.privateKey,
|
|
174
|
+
rsaKeyType: resp.data.operation.Details.rsaKeyType || "RSA_1024", //No I18N
|
|
175
|
+
sharedKey: resp.data.operation.Details.sharedKey
|
|
176
|
+
};
|
|
177
|
+
const pri = Vault.decrypt(keys.privateKey, this.masterKey, 256);
|
|
178
|
+
switch (keys.rsaKeyType) {
|
|
179
|
+
case "RSA_1024":
|
|
180
|
+
this.orgKey = await Vault.RSA_decrypt(keys.sharedKey, pri, keys.rsaKeyType);
|
|
181
|
+
break;
|
|
182
|
+
case "RSA_4096":
|
|
183
|
+
const privateKey = await Utilites.importPrivateKey(pri);
|
|
184
|
+
this.orgKey = await Vault.RSA_decrypt(keys.sharedKey, privateKey, keys.rsaKeyType);
|
|
185
|
+
break;
|
|
186
|
+
default:
|
|
187
|
+
Logger.error("Invalid RSA Key Type"); //No I18N
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
credentials.orgkey = this.orgKey ? this.orgKey : '';
|
|
192
|
+
await insertToDB(userConfig);
|
|
193
|
+
return this.orgKey;
|
|
194
|
+
}
|
|
195
|
+
async decryptSecretObj(secret, notSafe,
|
|
196
|
+
// obj
|
|
197
|
+
{ secret_type_fields: template, secret_type_name }) {
|
|
198
|
+
notSafe = !notSafe;
|
|
199
|
+
if (secret.secretData != undefined) {
|
|
200
|
+
let secretData = JSON.parse(secret.secretData);
|
|
201
|
+
let key = secret.isshared === "NO" ? this.masterKey : await this.getOrgKey();
|
|
202
|
+
for (let column in secretData) {
|
|
203
|
+
secretData[column] = Vault.decrypt(secretData[column], key);
|
|
204
|
+
}
|
|
205
|
+
for (let i = 0; i < template.length; i++) {
|
|
206
|
+
let column = template[i];
|
|
207
|
+
if (column.type === "password" &&
|
|
208
|
+
((secret.sharinglevel !== undefined &&
|
|
209
|
+
Utilites.getSharingPrivilege(secret.sharinglevel) === "AUTOLOGIN") ||
|
|
210
|
+
notSafe)) {
|
|
211
|
+
column.value = "********";
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
column.value = secretData[column.name];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (secret.notes !== "" && typeof secret.notes !== "undefined") {
|
|
218
|
+
secret.notes = Vault.decrypt(secret.notes, key);
|
|
219
|
+
}
|
|
220
|
+
if (secret.encdescription != undefined && secret.encdescription != "") // changes for new encrypted fields
|
|
221
|
+
{
|
|
222
|
+
secret.decdescription = Vault.decrypt(secret.encdescription, key);
|
|
223
|
+
}
|
|
224
|
+
if (secret.encryptedtags != undefined && secret.encryptedtags != "") {
|
|
225
|
+
secret.decryptedtags = Vault.decrypt(secret.encryptedtags, key);
|
|
226
|
+
}
|
|
227
|
+
if (secret.encsecretname != undefined && secret.encsecretname != "") {
|
|
228
|
+
secret.decsecretname = Vault.decrypt(secret.encsecretname, key);
|
|
229
|
+
}
|
|
230
|
+
if (secret.encryptedurls != undefined && secret.encryptedurls != "") {
|
|
231
|
+
if (secret.encryptedurls.length > 1) {
|
|
232
|
+
let i = 0;
|
|
233
|
+
for (let url in secret.encryptedurls) {
|
|
234
|
+
secret.decryptedurls[i] = Vault.decrypt(secret.encryptedurls[url], key);
|
|
235
|
+
i++;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
secret.decryptedurls = Vault.decrypt(secret.encryptedurls[0], key);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
secret.secretData = template;
|
|
243
|
+
secret.secretTypeName = secret_type_name;
|
|
244
|
+
if (secret.customcolumn !== undefined) {
|
|
245
|
+
let customCols;
|
|
246
|
+
try {
|
|
247
|
+
customCols = JSON.parse(Vault.Base64_decode(secret.customcolumn))
|
|
248
|
+
.customcol;
|
|
249
|
+
}
|
|
250
|
+
catch (err) {
|
|
251
|
+
customCols = {};
|
|
252
|
+
}
|
|
253
|
+
for (let i = 0; i < customCols.length; i++) {
|
|
254
|
+
let column = customCols[i];
|
|
255
|
+
if (column.type === "password" &&
|
|
256
|
+
((secret.sharinglevel !== undefined &&
|
|
257
|
+
Utilites.getSharingPrivilege(secret.sharinglevel) ===
|
|
258
|
+
"AUTOLOGIN") ||
|
|
259
|
+
notSafe)) {
|
|
260
|
+
column.value = "*******";
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
column.value = Vault.decrypt(column.value, key);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
secret.customcolumn = { customcol: customCols };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
if (secret.accesssctrlconfigured == "true") {
|
|
271
|
+
console.log("password need access control");
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
console.log("error in fetching secrets");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async fullencrypt_decrypt(new_fields, isshared) {
|
|
279
|
+
let decrypted_field;
|
|
280
|
+
let key = isshared === "NO" ? this.masterKey : await this.getOrgKey(); //No I18N
|
|
281
|
+
if (new_fields != undefined) {
|
|
282
|
+
decrypted_field = Vault.decrypt(new_fields, key);
|
|
283
|
+
}
|
|
284
|
+
return decrypted_field;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=Login.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { I18N } from "../js/I18n/index.js";
|
|
2
|
+
import { deleteCredentials, getZvDB } from "../util/dbutils/db.utils.js";
|
|
3
|
+
import { Login } from "../util/login.util.js";
|
|
4
|
+
import { deleteFromKeyring } from "../util/keyringutil/keyring.util.js";
|
|
5
|
+
import { KEYRING_SERVICE, KEYRING_ACCOUNT } from "../util/consts.util.js";
|
|
6
|
+
let i18nText = new I18N();
|
|
7
|
+
export class Logout extends Login {
|
|
8
|
+
async clearAllFiles() {
|
|
9
|
+
const db = getZvDB();
|
|
10
|
+
await deleteCredentials(db);
|
|
11
|
+
try {
|
|
12
|
+
await deleteFromKeyring(KEYRING_SERVICE, KEYRING_ACCOUNT);
|
|
13
|
+
}
|
|
14
|
+
catch (_) {
|
|
15
|
+
// Keyring entry may not exist — safe to ignore
|
|
16
|
+
}
|
|
17
|
+
delete process.env.zv_keys;
|
|
18
|
+
console.log(i18nText.getI18nMsg("vault.logout.success"));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=Logout.js.map
|