@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
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { Logger } from "../js/logger/index.js";
|
|
2
|
+
import { CREDENTIALS, VAULT_ENDPOINTS, ACCOUNT_ENDPOINTS, OPERATION, SHARING } from "./consts.util.js";
|
|
3
|
+
import { _pull } from "./index.util.js";
|
|
4
|
+
import { Utilities } from "./index.util.js";
|
|
5
|
+
import { DC } from "./consts.util.js";
|
|
6
|
+
import Vault from "../js/crypto/index.js";
|
|
7
|
+
import { generateWorkspaceHash, header } from "../commands/login/login.utils.js";
|
|
8
|
+
import { setHeaders } from "../commands/login/login.utils.js";
|
|
9
|
+
import { getPassPhrase } from "../commands/unlock/unlock.utils.js";
|
|
10
|
+
import { getDecryptedCredentials, insertToDB } from "./dbutils/db.utils.js";
|
|
11
|
+
import { getConfig } from "./dev.utils.js";
|
|
12
|
+
import { MODE } from "./consts.util.js";
|
|
13
|
+
import { RSA_KEY_TYPE } from "./types.util.js";
|
|
14
|
+
import { Utilites } from "../old/index.js";
|
|
15
|
+
export class Login {
|
|
16
|
+
passphrase;
|
|
17
|
+
credentialsPath;
|
|
18
|
+
accessToken;
|
|
19
|
+
refreshToken;
|
|
20
|
+
createdTime;
|
|
21
|
+
dc;
|
|
22
|
+
tokenSalt;
|
|
23
|
+
masterKey;
|
|
24
|
+
iteration;
|
|
25
|
+
passauth;
|
|
26
|
+
salt;
|
|
27
|
+
loginType;
|
|
28
|
+
orgKey;
|
|
29
|
+
zuid;
|
|
30
|
+
constructor(passphrase, dc) {
|
|
31
|
+
this.passphrase = passphrase;
|
|
32
|
+
this.credentialsPath = "";
|
|
33
|
+
this.accessToken = "";
|
|
34
|
+
this.refreshToken = "";
|
|
35
|
+
this.createdTime = 0;
|
|
36
|
+
this.dc = !!dc ? dc : DC.US;
|
|
37
|
+
this.zuid = '';
|
|
38
|
+
}
|
|
39
|
+
getDC() {
|
|
40
|
+
return this.dc;
|
|
41
|
+
}
|
|
42
|
+
setDC(dc) {
|
|
43
|
+
this.dc = dc;
|
|
44
|
+
}
|
|
45
|
+
getPassPhrase() {
|
|
46
|
+
return this.passphrase;
|
|
47
|
+
}
|
|
48
|
+
setPassPhrase(passphrase) {
|
|
49
|
+
this.passauth = passphrase;
|
|
50
|
+
}
|
|
51
|
+
setMasterKey(masterKey) {
|
|
52
|
+
this.masterKey = masterKey;
|
|
53
|
+
}
|
|
54
|
+
getDcAndSetHeader = async () => {
|
|
55
|
+
const data = await getDecryptedCredentials(generateWorkspaceHash());
|
|
56
|
+
if (!data) {
|
|
57
|
+
throw new Error("cannot find data");
|
|
58
|
+
}
|
|
59
|
+
const { credentials, createdtime, dc } = data;
|
|
60
|
+
const { access_token, refresh_token } = credentials;
|
|
61
|
+
this.accessToken = !!access_token ? access_token : "";
|
|
62
|
+
this.refreshToken = !!refresh_token ? refresh_token : "";
|
|
63
|
+
this.createdTime = !!createdtime ? +createdtime : 0;
|
|
64
|
+
this.dc = !!dc ? dc : DC.US;
|
|
65
|
+
await this.checkAccessTokenValidity();
|
|
66
|
+
setHeaders("Authorization", `Zoho-oauthtoken ${this.accessToken}`);
|
|
67
|
+
};
|
|
68
|
+
async getAccessTokenforunlock() {
|
|
69
|
+
return new Promise(async (resolve, reject) => {
|
|
70
|
+
try {
|
|
71
|
+
const data = await getDecryptedCredentials(generateWorkspaceHash());
|
|
72
|
+
if (!data) {
|
|
73
|
+
reject("User configuration is null");
|
|
74
|
+
}
|
|
75
|
+
const { credentials } = data;
|
|
76
|
+
resolve(credentials.access_token);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
Logger.error(err);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
getKeyForToken() {
|
|
84
|
+
if (this.tokenSalt === undefined) {
|
|
85
|
+
this.tokenSalt = Utilities.generateRandomToken(40);
|
|
86
|
+
}
|
|
87
|
+
return Vault.PBKDF2_key(this.masterKey, this.tokenSalt, this.iteration);
|
|
88
|
+
}
|
|
89
|
+
async refreshAccessToken() {
|
|
90
|
+
/*
|
|
91
|
+
generate new access token with the help of refresh token
|
|
92
|
+
*/
|
|
93
|
+
const config = getConfig();
|
|
94
|
+
let { MODE: mode, CLIENT_ID, CLIENT_SECRET } = config;
|
|
95
|
+
if (mode === MODE.PRODUCTION) {
|
|
96
|
+
CLIENT_ID = CREDENTIALS.CLIENT_ID;
|
|
97
|
+
CLIENT_SECRET = CREDENTIALS.CLIENT_SECRET;
|
|
98
|
+
}
|
|
99
|
+
let newCreatedTime = Date.now();
|
|
100
|
+
let data = {
|
|
101
|
+
refresh_token: this.refreshToken,
|
|
102
|
+
client_id: CLIENT_ID,
|
|
103
|
+
client_secret: CLIENT_SECRET,
|
|
104
|
+
grant_type: "refresh_token",
|
|
105
|
+
};
|
|
106
|
+
try {
|
|
107
|
+
let response = await _pull(header, Utilities.getAccountsUrl(this.dc) + ACCOUNT_ENDPOINTS.URL_GENERATE_TOKEN, data, "POST");
|
|
108
|
+
const resp = response.data;
|
|
109
|
+
if (resp.hasOwnProperty("access_token")) {
|
|
110
|
+
this.accessToken = resp.access_token;
|
|
111
|
+
Utilities.writeToFile(JSON.stringify({
|
|
112
|
+
refreshToken: data.refresh_token,
|
|
113
|
+
accessToken: resp.access_token,
|
|
114
|
+
createdTime: newCreatedTime,
|
|
115
|
+
dc: this.dc,
|
|
116
|
+
}), this.credentialsPath);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
Logger.error(e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async checkAccessTokenValidity() {
|
|
124
|
+
const localtime = Date.now();
|
|
125
|
+
let diffMs = localtime - (!!this.createdTime ? this.createdTime : 0); // milliseconds between now & Christmas
|
|
126
|
+
let diffMins = Math.abs(Math.round(diffMs / 1000 / 60));
|
|
127
|
+
if (diffMins > 50) {
|
|
128
|
+
await this.refreshAccessToken();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async setUserConfig() {
|
|
132
|
+
const resp = await _pull(header, Utilities.getVaultUrl(this.dc) + VAULT_ENDPOINTS.URL_LOGIN, { OPERATION_NAME: OPERATION.GET_LOGIN }, "POST");
|
|
133
|
+
const { ITERATION, PASSPHRASE, LOGIN, SALT, USER } = resp.data.operation.details;
|
|
134
|
+
this.iteration = ITERATION;
|
|
135
|
+
this.passauth = PASSPHRASE;
|
|
136
|
+
this.loginType = LOGIN;
|
|
137
|
+
this.salt = SALT;
|
|
138
|
+
this.zuid = USER.ZUID ? USER.ZUID : '';
|
|
139
|
+
}
|
|
140
|
+
async getMasterKey(passphrase) {
|
|
141
|
+
if (this.salt === undefined) {
|
|
142
|
+
await this.setUserConfig();
|
|
143
|
+
}
|
|
144
|
+
if (this.masterKey === undefined) {
|
|
145
|
+
let masterKey;
|
|
146
|
+
if (this.loginType === "PBKDF2_AES") {
|
|
147
|
+
masterKey = await Vault.PBKDF2_key(passphrase, this.salt, this.iteration);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
//TODO check this case
|
|
151
|
+
masterKey = Vault.hash(passphrase);
|
|
152
|
+
}
|
|
153
|
+
if (this.checkLogin(masterKey)) {
|
|
154
|
+
this.masterKey = masterKey;
|
|
155
|
+
return masterKey;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return this.masterKey;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async getZUID() {
|
|
166
|
+
if (!this.zuid) {
|
|
167
|
+
await this.setUserConfig();
|
|
168
|
+
}
|
|
169
|
+
return this.zuid;
|
|
170
|
+
}
|
|
171
|
+
checkLogin(masterKey) {
|
|
172
|
+
const decryptedPassAuth = Vault.decrypt(this.passauth, masterKey);
|
|
173
|
+
try {
|
|
174
|
+
return !isNaN(Date.parse(JSON.parse(decryptedPassAuth).date));
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async getMasterKeyAfterConfiguration() {
|
|
181
|
+
const isCLITrusted = await Utilities.isTrusted();
|
|
182
|
+
if (isCLITrusted.status) {
|
|
183
|
+
return isCLITrusted.masterKey;
|
|
184
|
+
}
|
|
185
|
+
const passPhrase = await getPassPhrase(undefined);
|
|
186
|
+
const masterKey = await this.getMasterKey(passPhrase);
|
|
187
|
+
if (masterKey === undefined) {
|
|
188
|
+
console.log("Invalid master password please try again");
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
return masterKey;
|
|
192
|
+
}
|
|
193
|
+
async getOrgKey() {
|
|
194
|
+
return new Promise(async (resolve, reject) => {
|
|
195
|
+
try {
|
|
196
|
+
const userConfig = await getDecryptedCredentials(generateWorkspaceHash());
|
|
197
|
+
const { credentials } = userConfig;
|
|
198
|
+
if (credentials && credentials.orgkey) {
|
|
199
|
+
resolve(credentials.orgkey);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (this.orgKey === undefined) {
|
|
203
|
+
const resp = await _pull(header, Utilities.getVaultUrl(this.dc) + VAULT_ENDPOINTS.URL_ORG_KEY, {}, undefined);
|
|
204
|
+
const { privateKey: encPrivateKey, sharedKey, rsaKeyType } = resp.data.operation.Details;
|
|
205
|
+
let privateKey = Vault.decrypt(encPrivateKey, this.masterKey);
|
|
206
|
+
let keyType = '';
|
|
207
|
+
switch (rsaKeyType) {
|
|
208
|
+
case RSA_KEY_TYPE.RSA_1024:
|
|
209
|
+
Utilites;
|
|
210
|
+
keyType = RSA_KEY_TYPE.RSA_1024;
|
|
211
|
+
break;
|
|
212
|
+
case RSA_KEY_TYPE.RSA_4096:
|
|
213
|
+
keyType = RSA_KEY_TYPE.RSA_4096;
|
|
214
|
+
privateKey = await Utilites.importPrivateKey(privateKey);
|
|
215
|
+
break;
|
|
216
|
+
default:
|
|
217
|
+
Logger.error("Invalid RSA Key Type"); //No I18N
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
this.orgKey = await Vault.RSA_decrypt(sharedKey, privateKey, keyType);
|
|
221
|
+
}
|
|
222
|
+
credentials.orgkey = this.orgKey ? this.orgKey : '';
|
|
223
|
+
await insertToDB(userConfig);
|
|
224
|
+
resolve(this.orgKey);
|
|
225
|
+
}
|
|
226
|
+
catch (err) {
|
|
227
|
+
Logger.error(err);
|
|
228
|
+
reject(new Error("Error getting Orgkey"));
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
convertStringToJSON(str) {
|
|
233
|
+
return new Promise((resolve, reject) => {
|
|
234
|
+
try {
|
|
235
|
+
if (str == undefined) {
|
|
236
|
+
reject(new Error("cannot convert undefined to JSON"));
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
resolve(JSON.parse(str));
|
|
240
|
+
}
|
|
241
|
+
catch (err) {
|
|
242
|
+
Logger.error(err);
|
|
243
|
+
reject(new Error("Problem while converting string to JSON"));
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
async decryptSecretData(secretData, decryptionKey, secretFieldData, notSafe, sharinglevel) {
|
|
248
|
+
return new Promise(async (resolve, reject) => {
|
|
249
|
+
try {
|
|
250
|
+
const secretDataJSON = await this.convertStringToJSON(secretData);
|
|
251
|
+
for (const key in secretDataJSON) {
|
|
252
|
+
const fieldInfo = secretFieldData.find((field) => field.name === key);
|
|
253
|
+
const chiperText = secretDataJSON[key];
|
|
254
|
+
if (chiperText !== undefined) {
|
|
255
|
+
delete secretDataJSON[key];
|
|
256
|
+
const jsonKey = fieldInfo?.label;
|
|
257
|
+
secretDataJSON[jsonKey] = await this.getDecryptedSecretData(chiperText, decryptionKey, notSafe, sharinglevel, fieldInfo?.type);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
resolve(secretDataJSON);
|
|
261
|
+
}
|
|
262
|
+
catch (err) {
|
|
263
|
+
Logger.error(err);
|
|
264
|
+
reject(new Error("Problem while decrypting secretData"));
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
async getDecryptedSecretData(chiperText, decryptionKey, notSafe, sharinglevel, type) {
|
|
269
|
+
return new Promise((resolve, reject) => {
|
|
270
|
+
if (type === "password") {
|
|
271
|
+
if ((sharinglevel !== undefined && Utilities.getSharingPrivilege(sharinglevel) === SHARING.AUTOLOGIN) || !notSafe) {
|
|
272
|
+
resolve("*********");
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const decryptedData = Vault.decrypt(chiperText, decryptionKey);
|
|
277
|
+
resolve(decryptedData);
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
async maskDecryptedSecretData(decryptedSecData, secretFieldData, notSafe, sharinglevel) {
|
|
281
|
+
return new Promise((resolve, reject) => {
|
|
282
|
+
try {
|
|
283
|
+
const containsPassowdField = secretFieldData.some((elem) => elem.type === 'password');
|
|
284
|
+
if (containsPassowdField && ((sharinglevel !== undefined && Utilities.getSharingPrivilege(sharinglevel) === SHARING.AUTOLOGIN) || !notSafe)) {
|
|
285
|
+
decryptedSecData['password'] = '*********';
|
|
286
|
+
}
|
|
287
|
+
resolve(true);
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
Logger.error(err);
|
|
291
|
+
reject(false);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
async getDecryptedCustomColumn(customcolStr, decryptionKey, notSafe, sharinglevel) {
|
|
296
|
+
return new Promise(async (resolve, reject) => {
|
|
297
|
+
try {
|
|
298
|
+
const customCol = JSON.parse(Vault.Base64_decode(customcolStr));
|
|
299
|
+
await this.maskDecryptedCustomCol(customCol.customcol, notSafe, sharinglevel, decryptionKey);
|
|
300
|
+
resolve(customCol.customcol);
|
|
301
|
+
}
|
|
302
|
+
catch (err) {
|
|
303
|
+
Logger.error(err);
|
|
304
|
+
reject(new Error("Error getting decrypted custom column"));
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
async maskDecryptedCustomCol(res, notSafe, sharinglevel, decryptionKey) {
|
|
309
|
+
if (res == undefined) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
res.forEach((col) => {
|
|
313
|
+
if (col.type === "password" && ((sharinglevel !== undefined && Utilities.getSharingPrivilege(sharinglevel) === SHARING.AUTOLOGIN) || !notSafe)) {
|
|
314
|
+
col.value = "*********";
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
col.value = Vault.decrypt(col.value, decryptionKey);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
async decryptSecretObject(secretObj, secretFieldData, notSafe) {
|
|
321
|
+
const { secretData, isshared, sharinglevel } = secretObj;
|
|
322
|
+
if (!secretData) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const decryptionKey = isshared == "NO" ? this.masterKey : await this.getOrgKey();
|
|
326
|
+
if (!decryptionKey) {
|
|
327
|
+
throw new Error("Decryption missing try lock and unlock once");
|
|
328
|
+
}
|
|
329
|
+
const decryptedSecData = await this.decryptSecretData(secretData, decryptionKey, secretFieldData, notSafe, sharinglevel);
|
|
330
|
+
// await this.maskDecryptedSecretData(decryptedSecData, secretFieldData, notSafe, sharinglevel);
|
|
331
|
+
secretObj.secretData = decryptedSecData;
|
|
332
|
+
if (secretObj.notes !== "" && !!secretObj.notes) {
|
|
333
|
+
secretObj.notes = await this.getDecryptedSecretData(secretObj.notes, decryptionKey, notSafe, sharinglevel, "notes");
|
|
334
|
+
}
|
|
335
|
+
if (secretObj.customcolumn !== "" && !!secretObj.customcolumn) {
|
|
336
|
+
const res = await this.getDecryptedCustomColumn(secretObj.customcolumn, decryptionKey, notSafe, sharinglevel);
|
|
337
|
+
secretObj.customcolumn = { customcol: res };
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
async decrypt(chipertext, isShared) {
|
|
341
|
+
try {
|
|
342
|
+
if (isShared === "NO") {
|
|
343
|
+
return Vault.decrypt(chipertext, this.masterKey);
|
|
344
|
+
}
|
|
345
|
+
return Vault.decrypt(chipertext, await this.getOrgKey());
|
|
346
|
+
}
|
|
347
|
+
catch (err) {
|
|
348
|
+
Logger.error(err);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
//# sourceMappingURL=login.util.js.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Utilities, _pull } from "./index.util.js";
|
|
2
|
+
import { OPTIONS, VAULT_ENDPOINTS } from "./consts.util.js";
|
|
3
|
+
import { generateWorkspaceHash, header } from "../commands/login/login.utils.js";
|
|
4
|
+
import { getDecryptedCredentials } from "./dbutils/db.utils.js";
|
|
5
|
+
import { Logger } from "../js/logger/index.js";
|
|
6
|
+
export class PasswordTypes {
|
|
7
|
+
dc;
|
|
8
|
+
constructor(dc) {
|
|
9
|
+
this.dc = dc;
|
|
10
|
+
}
|
|
11
|
+
static getUserConfig = async (dc) => {
|
|
12
|
+
try {
|
|
13
|
+
const res = await _pull(header, Utilities.getVaultUrl(dc) + VAULT_ENDPOINTS.USER_CONFIG, undefined, undefined);
|
|
14
|
+
const { data: { operation: { Details } } } = res;
|
|
15
|
+
return Details;
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
Logger.error(err);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
static resolveWithNoPolicyId = (dc, isAddOrCategory) => {
|
|
22
|
+
return new Promise(async (resolve, reject) => {
|
|
23
|
+
try {
|
|
24
|
+
const decryptedCredentials = await getDecryptedCredentials(generateWorkspaceHash());
|
|
25
|
+
const zuid = decryptedCredentials.zuid;
|
|
26
|
+
const resp = await _pull(header, Utilities.getVaultUrl(dc) + VAULT_ENDPOINTS.URL_SECRET_TYPES, { allTypes: true, getDefaults: true }, undefined);
|
|
27
|
+
const { data: { operation: { Details: { secret_types } } } } = resp;
|
|
28
|
+
const userConfig = await this.getUserConfig(dc);
|
|
29
|
+
let secretTypes = secret_types;
|
|
30
|
+
if (isAddOrCategory) {
|
|
31
|
+
secretTypes = secretTypes.filter(function (type) {
|
|
32
|
+
if (userConfig.SHOW_USER_DEFINED_SECRETTYPE != undefined && userConfig.SHOW_USER_DEFINED_SECRETTYPE == "Enabled") {
|
|
33
|
+
return ((type.added_by == undefined || (type.added_by != undefined && type.added_by.zuid == zuid)) &&
|
|
34
|
+
(type.status && ((userConfig.FILE_ATTACHMENT != undefined &&
|
|
35
|
+
userConfig.FILE_ATTACHMENT == "Disabled") ? ((type.is_system_defined && type.secret_type_name == "File Store") ? false : true) : true))) && type.secret_type_name !== "Passkey"; //No I18N
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return type.status && ((userConfig.FILE_ATTACHMENT != undefined
|
|
39
|
+
&& userConfig.FILE_ATTACHMENT == "Disabled") ? ((type.is_system_defined && type.secret_type_name == "File Store") ? false : true) : true) && type.secret_type_name !== "Passkey"; // No I18N
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
resolve(secretTypes);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
reject(new Error("Error while resolving with no policy id"));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
static resolveWithPolicyId = (policyId, dc) => {
|
|
51
|
+
return new Promise(async (resolve, reject) => {
|
|
52
|
+
try {
|
|
53
|
+
const resp = await _pull(header, `${Utilities.getVaultUrl(dc)}${VAULT_ENDPOINTS.URL_SECRET_TYPES}/${policyId}`, undefined, undefined);
|
|
54
|
+
const { data: { operation: { Details } } } = resp;
|
|
55
|
+
resolve([Details]);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
reject(new Error("Error getting password types with policy id"));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
static constructFormattedSecretTypes = (sceretTypeArr, policyId, operation) => {
|
|
63
|
+
const formattedScerets = {};
|
|
64
|
+
sceretTypeArr.forEach((secretType) => {
|
|
65
|
+
if (secretType.status || operation == OPTIONS.LIST || operation === OPTIONS.SEARCH) {
|
|
66
|
+
formattedScerets[secretType.secret_type_id] = secretType;
|
|
67
|
+
}
|
|
68
|
+
else if (!secretType.status && policyId != undefined) {
|
|
69
|
+
formattedScerets[secretType.secret_type_id] = secretType;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return formattedScerets;
|
|
73
|
+
};
|
|
74
|
+
static getPasswordTypes = (dc, policyId, operation, isAddOrCategory) => {
|
|
75
|
+
return new Promise(async (resolve, reject) => {
|
|
76
|
+
try {
|
|
77
|
+
if (!policyId) {
|
|
78
|
+
const secTypeArr = await this.resolveWithNoPolicyId(dc, isAddOrCategory);
|
|
79
|
+
resolve(this.constructFormattedSecretTypes(secTypeArr, policyId, operation));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const secTypeArr = await this.resolveWithPolicyId(policyId, dc);
|
|
83
|
+
resolve(this.constructFormattedSecretTypes(secTypeArr, policyId, operation));
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
reject(new Error("Cannot get passowrd types"));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=passwordtypes.util.js.map
|