@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.
Files changed (102) hide show
  1. package/README.md +16 -0
  2. package/out/commands/add/add.const.js +6 -0
  3. package/out/commands/add/add.types.js +2 -0
  4. package/out/commands/add/add.util.js +35 -0
  5. package/out/commands/download/download.const.js +6 -0
  6. package/out/commands/download/download.types.js +2 -0
  7. package/out/commands/download/download.utils.js +35 -0
  8. package/out/commands/generate-password/generate-password.const.js +12 -0
  9. package/out/commands/generate-password/generate-password.types.js +2 -0
  10. package/out/commands/generate-password/generate-password.utils.js +58 -0
  11. package/out/commands/generate-template/generate-template.const.js +7 -0
  12. package/out/commands/generate-template/generate-template.types.js +2 -0
  13. package/out/commands/generate-template/generate-template.util.js +37 -0
  14. package/out/commands/get/get.const.js +8 -0
  15. package/out/commands/get/get.types.js +2 -0
  16. package/out/commands/get/get.utils.js +45 -0
  17. package/out/commands/get-default/get-default.const.js +5 -0
  18. package/out/commands/get-default/get-default.types.js +2 -0
  19. package/out/commands/get-default/get-default.utils.js +33 -0
  20. package/out/commands/list/list.const.js +7 -0
  21. package/out/commands/list/list.types.js +2 -0
  22. package/out/commands/list/list.utils.js +43 -0
  23. package/out/commands/lock/lock.action.js +13 -0
  24. package/out/commands/lock/lock.js +10 -0
  25. package/out/commands/lock/lock.utils.js +52 -0
  26. package/out/commands/login/login.action.js +22 -0
  27. package/out/commands/login/login.const.js +10 -0
  28. package/out/commands/login/login.help.js +12 -0
  29. package/out/commands/login/login.js +17 -0
  30. package/out/commands/login/login.types.js +5 -0
  31. package/out/commands/login/login.utils.js +307 -0
  32. package/out/commands/reset/reset.action.js +28 -0
  33. package/out/commands/reset/reset.help.js +8 -0
  34. package/out/commands/reset/reset.js +14 -0
  35. package/out/commands/reset/reset.utils.js +2 -0
  36. package/out/commands/search/search.action.js +30 -0
  37. package/out/commands/search/search.constants.js +14 -0
  38. package/out/commands/search/search.help.js +6 -0
  39. package/out/commands/search/search.js +26 -0
  40. package/out/commands/search/search.types.js +16 -0
  41. package/out/commands/search/search.utils.js +61 -0
  42. package/out/commands/set-default/set-default.const.js +6 -0
  43. package/out/commands/set-default/set-default.types.js +2 -0
  44. package/out/commands/set-default/set-default.utils.js +39 -0
  45. package/out/commands/unlock/unlock.action.js +23 -0
  46. package/out/commands/unlock/unlock.help.js +2 -0
  47. package/out/commands/unlock/unlock.js +12 -0
  48. package/out/commands/unlock/unlock.type.js +2 -0
  49. package/out/commands/unlock/unlock.utils.js +133 -0
  50. package/out/js/I18n/index.js +80 -0
  51. package/out/js/I18n/resources/CLI_I18N_en.js +173 -0
  52. package/out/js/I18n/resources/CLI_I18N_es.js +3 -0
  53. package/out/js/I18n/resources/CLI_I18N_fr.js +3 -0
  54. package/out/js/I18n/resources/CLI_I18N_nl.js +3 -0
  55. package/out/js/I18n/resources/CLI_I18N_pt.js +3 -0
  56. package/out/js/I18n/resources/CLI_I18N_zh.js +3 -0
  57. package/out/js/crypto/aes.js +225 -0
  58. package/out/js/crypto/index.js +139 -0
  59. package/out/js/crypto/rsa.js +1945 -0
  60. package/out/js/crypto/zohovault.js +671 -0
  61. package/out/js/logger/index.js +10 -0
  62. package/out/old/Add.js +590 -0
  63. package/out/old/Default.js +209 -0
  64. package/out/old/Download.js +69 -0
  65. package/out/old/Generate.js +171 -0
  66. package/out/old/Get.js +225 -0
  67. package/out/old/List.js +197 -0
  68. package/out/old/Login.js +287 -0
  69. package/out/old/Logout.js +21 -0
  70. package/out/old/PasswordGenerator.js +718 -0
  71. package/out/old/PasswordPolicies.js +21 -0
  72. package/out/old/PasswordTypes.js +33 -0
  73. package/out/old/Update.js +682 -0
  74. package/out/old/cmd/addcmd.js +59 -0
  75. package/out/old/cmd/downloadcmd.js +76 -0
  76. package/out/old/cmd/generate-passwordcmd.js +127 -0
  77. package/out/old/cmd/generate-templatecmd.js +59 -0
  78. package/out/old/cmd/get-defaultcmd.js +48 -0
  79. package/out/old/cmd/getcmd.js +57 -0
  80. package/out/old/cmd/listcmd.js +54 -0
  81. package/out/old/cmd/logoutcmd.js +31 -0
  82. package/out/old/cmd/set-default.js +75 -0
  83. package/out/old/cmd/updatecmd.js +44 -0
  84. package/out/old/index.js +580 -0
  85. package/out/util/configuration.util.js +103 -0
  86. package/out/util/consts.util.js +97 -0
  87. package/out/util/dbutils/db.types.js +2 -0
  88. package/out/util/dbutils/db.utils.js +164 -0
  89. package/out/util/dbutils/dbtable.utils.js +19 -0
  90. package/out/util/dev.utils.js +14 -0
  91. package/out/util/encryptionutil/encryption.uitl.js +108 -0
  92. package/out/util/index.util.js +341 -0
  93. package/out/util/keyringutil/keyring.util.js +57 -0
  94. package/out/util/loader/loader.interface.js +2 -0
  95. package/out/util/loader/transfer.loader.js +28 -0
  96. package/out/util/login.util.js +352 -0
  97. package/out/util/passwordtypes.util.js +91 -0
  98. package/out/util/print.util.js +4 -0
  99. package/out/util/search.util.js +359 -0
  100. package/out/util/types.util.js +7 -0
  101. package/out/zv.js +41 -0
  102. package/package.json +96 -0
@@ -0,0 +1,671 @@
1
+ //$Id$
2
+ //ignorei18n_start
3
+ var Zohovault = {};
4
+ /**
5
+ *
6
+ * Secure Hash Algorithm (SHA256)
7
+ * http://www.webtoolkit.info/
8
+ *
9
+ * Original code by Angel Marin, Paul Johnston.
10
+ *
11
+ **/
12
+ Zohovault.hash = function (s) {
13
+ var chrsz = 8;
14
+ var hexcase = 0;
15
+ function safe_add(x, y) {
16
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF);
17
+ var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
18
+ return (msw << 16) | (lsw & 0xFFFF);
19
+ }
20
+ function S(X, n) { return (X >>> n) | (X << (32 - n)); }
21
+ function R(X, n) { return (X >>> n); }
22
+ function Ch(x, y, z) { return ((x & y) ^ ((~x) & z)); }
23
+ function Maj(x, y, z) { return ((x & y) ^ (x & z) ^ (y & z)); }
24
+ function Sigma0256(x) { return (S(x, 2) ^ S(x, 13) ^ S(x, 22)); }
25
+ function Sigma1256(x) { return (S(x, 6) ^ S(x, 11) ^ S(x, 25)); }
26
+ function Gamma0256(x) { return (S(x, 7) ^ S(x, 18) ^ R(x, 3)); }
27
+ function Gamma1256(x) { return (S(x, 17) ^ S(x, 19) ^ R(x, 10)); }
28
+ function core_sha256(m, l) {
29
+ var K = new Array(0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0xFC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x6CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2);
30
+ var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19);
31
+ var W = new Array(64);
32
+ var a, b, c, d, e, f, g, h, i, j;
33
+ var T1, T2;
34
+ m[l >> 5] |= 0x80 << (24 - l % 32);
35
+ m[((l + 64 >> 9) << 4) + 15] = l;
36
+ for (var i = 0; i < m.length; i += 16) {
37
+ a = HASH[0];
38
+ b = HASH[1];
39
+ c = HASH[2];
40
+ d = HASH[3];
41
+ e = HASH[4];
42
+ f = HASH[5];
43
+ g = HASH[6];
44
+ h = HASH[7];
45
+ for (var j = 0; j < 64; j++) {
46
+ if (j < 16) {
47
+ W[j] = m[j + i];
48
+ }
49
+ else {
50
+ W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);
51
+ }
52
+ T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
53
+ T2 = safe_add(Sigma0256(a), Maj(a, b, c));
54
+ h = g;
55
+ g = f;
56
+ f = e;
57
+ e = safe_add(d, T1);
58
+ d = c;
59
+ c = b;
60
+ b = a;
61
+ a = safe_add(T1, T2);
62
+ }
63
+ HASH[0] = safe_add(a, HASH[0]);
64
+ HASH[1] = safe_add(b, HASH[1]);
65
+ HASH[2] = safe_add(c, HASH[2]);
66
+ HASH[3] = safe_add(d, HASH[3]);
67
+ HASH[4] = safe_add(e, HASH[4]);
68
+ HASH[5] = safe_add(f, HASH[5]);
69
+ HASH[6] = safe_add(g, HASH[6]);
70
+ HASH[7] = safe_add(h, HASH[7]);
71
+ }
72
+ return HASH;
73
+ }
74
+ function str2binb(str) {
75
+ var bin = Array();
76
+ var mask = (1 << chrsz) - 1;
77
+ for (var i = 0; i < str.length * chrsz; i += chrsz) {
78
+ bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i % 32);
79
+ }
80
+ return bin;
81
+ }
82
+ function Utf8Encode(string) {
83
+ string = string.replace(/\r\n/g, "\n");
84
+ var utftext = "";
85
+ for (var n = 0; n < string.length; n++) {
86
+ var c = string.charCodeAt(n);
87
+ if (c < 128) {
88
+ utftext += String.fromCharCode(c);
89
+ }
90
+ else if ((c > 127) && (c < 2048)) {
91
+ utftext += String.fromCharCode((c >> 6) | 192);
92
+ utftext += String.fromCharCode((c & 63) | 128);
93
+ }
94
+ else {
95
+ utftext += String.fromCharCode((c >> 12) | 224);
96
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
97
+ utftext += String.fromCharCode((c & 63) | 128);
98
+ }
99
+ }
100
+ return utftext;
101
+ }
102
+ function binb2hex(binarray) {
103
+ var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; //No I18N
104
+ var str = "";
105
+ for (var i = 0; i < binarray.length * 4; i++) {
106
+ str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) +
107
+ hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 0xF);
108
+ }
109
+ return str;
110
+ }
111
+ s = Utf8Encode(s);
112
+ return binb2hex(core_sha256(str2binb(s), s.length * chrsz));
113
+ };
114
+ /**
115
+ *
116
+ * UTF-8 data encode / decode
117
+ * http://www.webtoolkit.info/
118
+ *
119
+ **/
120
+ Zohovault.Utf8 = {
121
+ // public method for url encoding
122
+ encode: function (string) {
123
+ string = string.replace(/\r\n/g, "\n");
124
+ var utftext = "";
125
+ for (var n = 0; n < string.length; n++) {
126
+ var c = string.charCodeAt(n);
127
+ if (c < 128) {
128
+ utftext += String.fromCharCode(c);
129
+ }
130
+ else if ((c > 127) && (c < 2048)) {
131
+ utftext += String.fromCharCode((c >> 6) | 192);
132
+ utftext += String.fromCharCode((c & 63) | 128);
133
+ }
134
+ else {
135
+ utftext += String.fromCharCode((c >> 12) | 224);
136
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
137
+ utftext += String.fromCharCode((c & 63) | 128);
138
+ }
139
+ }
140
+ return utftext;
141
+ },
142
+ // public method for url decoding
143
+ decode: function (utftext) {
144
+ var string = "";
145
+ var i = 0;
146
+ var c1, c2, c3;
147
+ var c = c1 = c2 = 0;
148
+ while (i < utftext.length) {
149
+ c = utftext.charCodeAt(i);
150
+ if (c < 128) {
151
+ string += String.fromCharCode(c);
152
+ i++;
153
+ }
154
+ else if ((c > 191) && (c < 224)) {
155
+ c2 = utftext.charCodeAt(i + 1);
156
+ string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
157
+ i += 2;
158
+ }
159
+ else {
160
+ c2 = utftext.charCodeAt(i + 1);
161
+ c3 = utftext.charCodeAt(i + 2);
162
+ string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
163
+ i += 3;
164
+ }
165
+ }
166
+ return string;
167
+ }
168
+ };
169
+ /**
170
+ *
171
+ * Base64 encode / decode
172
+ * http://www.webtoolkit.info/
173
+ *
174
+ **/
175
+ Zohovault.Base64 = {
176
+ // private property
177
+ _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", //No I18N
178
+ // public method for encoding
179
+ encode: function (input) {
180
+ var output = "";
181
+ var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
182
+ var i = 0;
183
+ input = Zohovault.Utf8.encode(input);
184
+ while (i < input.length) {
185
+ chr1 = input.charCodeAt(i++);
186
+ chr2 = input.charCodeAt(i++);
187
+ chr3 = input.charCodeAt(i++);
188
+ enc1 = chr1 >> 2;
189
+ enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
190
+ enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
191
+ enc4 = chr3 & 63;
192
+ if (isNaN(chr2)) {
193
+ enc3 = enc4 = 64;
194
+ }
195
+ else if (isNaN(chr3)) {
196
+ enc4 = 64;
197
+ }
198
+ output = output +
199
+ this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
200
+ this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
201
+ }
202
+ return output;
203
+ },
204
+ // public method for decoding
205
+ decode: function (input) {
206
+ var output = "";
207
+ var chr1, chr2, chr3;
208
+ var enc1, enc2, enc3, enc4;
209
+ var i = 0;
210
+ input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
211
+ while (i < input.length) {
212
+ enc1 = this._keyStr.indexOf(input.charAt(i++));
213
+ enc2 = this._keyStr.indexOf(input.charAt(i++));
214
+ enc3 = this._keyStr.indexOf(input.charAt(i++));
215
+ enc4 = this._keyStr.indexOf(input.charAt(i++));
216
+ chr1 = (enc1 << 2) | (enc2 >> 4);
217
+ chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
218
+ chr3 = ((enc3 & 3) << 6) | enc4;
219
+ output = output + String.fromCharCode(chr1);
220
+ if (enc3 != 64) {
221
+ output = output + String.fromCharCode(chr2);
222
+ }
223
+ if (enc4 != 64) {
224
+ output = output + String.fromCharCode(chr3);
225
+ }
226
+ }
227
+ output = Zohovault.Utf8.decode(output);
228
+ return output;
229
+ }
230
+ };
231
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
232
+ /* AES implementation in JavaScript (c) Chris Veness 2005-2011 */
233
+ /* - see http://csrc.nist.gov/publications/PubsFIPS.html#197 */
234
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
235
+ Zohovault.AES = {}; // Aes namespace
236
+ /**
237
+ * AES Cipher function: encrypt 'input' state with Rijndael algorithm
238
+ * applies Nr rounds (10/12/14) using key schedule w for 'add round key' stage
239
+ *
240
+ * @param {Number[]} input 16-byte (128-bit) input state array
241
+ * @param {Number[][]} w Key schedule as 2D byte-array (Nr+1 x Nb bytes)
242
+ * @returns {Number[]} Encrypted output state array
243
+ */
244
+ Zohovault.AES.cipher = function (input, w) {
245
+ var Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
246
+ var Nr = w.length / Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys
247
+ var state = [[], [], [], []]; // initialise 4xNb byte-array 'state' with input [§3.4]
248
+ for (var i = 0; i < 4 * Nb; i++) {
249
+ state[i % 4][Math.floor(i / 4)] = input[i];
250
+ }
251
+ state = Zohovault.AES.addRoundKey(state, w, 0, Nb);
252
+ for (var round = 1; round < Nr; round++) {
253
+ state = Zohovault.AES.subBytes(state, Nb);
254
+ state = Zohovault.AES.shiftRows(state, Nb);
255
+ state = Zohovault.AES.mixColumns(state, Nb);
256
+ state = Zohovault.AES.addRoundKey(state, w, round, Nb);
257
+ }
258
+ state = Zohovault.AES.subBytes(state, Nb);
259
+ state = Zohovault.AES.shiftRows(state, Nb);
260
+ state = Zohovault.AES.addRoundKey(state, w, Nr, Nb);
261
+ var output = new Array(4 * Nb); // convert state to 1-d array before returning [§3.4]
262
+ for (var i = 0; i < 4 * Nb; i++) {
263
+ output[i] = state[i % 4][Math.floor(i / 4)];
264
+ }
265
+ return output;
266
+ };
267
+ /**
268
+ * Perform Key Expansion to generate a Key Schedule
269
+ *
270
+ * @param {Number[]} key Key as 16/24/32-byte array
271
+ * @returns {Number[][]} Expanded key schedule as 2D byte-array (Nr+1 x Nb bytes)
272
+ */
273
+ Zohovault.AES.keyExpansion = function (key) {
274
+ var Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
275
+ var Nk = key.length / 4; // key length (in words): 4/6/8 for 128/192/256-bit keys
276
+ var Nr = Nk + 6; // no of rounds: 10/12/14 for 128/192/256-bit keys
277
+ var w = new Array(Nb * (Nr + 1));
278
+ var temp = new Array(4);
279
+ for (var i = 0; i < Nk; i++) {
280
+ var r = [key[4 * i], key[4 * i + 1], key[4 * i + 2], key[4 * i + 3]];
281
+ w[i] = r;
282
+ }
283
+ for (var i = Nk; i < (Nb * (Nr + 1)); i++) {
284
+ w[i] = new Array(4);
285
+ for (var t = 0; t < 4; t++) {
286
+ temp[t] = w[i - 1][t];
287
+ }
288
+ if (i % Nk == 0) {
289
+ temp = Zohovault.AES.subWord(Zohovault.AES.rotWord(temp));
290
+ for (var t = 0; t < 4; t++) {
291
+ temp[t] ^= Zohovault.AES.rCon[i / Nk][t];
292
+ }
293
+ }
294
+ else if (Nk > 6 && i % Nk == 4) {
295
+ temp = Zohovault.AES.subWord(temp);
296
+ }
297
+ for (var t = 0; t < 4; t++) {
298
+ w[i][t] = w[i - Nk][t] ^ temp[t];
299
+ }
300
+ }
301
+ return w;
302
+ };
303
+ /*
304
+ * ---- remaining routines are private, not called externally ----
305
+ */
306
+ Zohovault.AES.subBytes = function (s, Nb) {
307
+ for (var r = 0; r < 4; r++) {
308
+ for (var c = 0; c < Nb; c++) {
309
+ s[r][c] = Zohovault.AES.sBox[s[r][c]];
310
+ }
311
+ }
312
+ return s;
313
+ };
314
+ Zohovault.AES.shiftRows = function (s, Nb) {
315
+ var t = new Array(4);
316
+ for (var r = 1; r < 4; r++) {
317
+ for (var c = 0; c < 4; c++) {
318
+ t[c] = s[r][(c + r) % Nb];
319
+ } // shift into temp copy
320
+ for (var c = 0; c < 4; c++) {
321
+ s[r][c] = t[c];
322
+ } // and copy back
323
+ } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES):
324
+ return s; // see asmaes.sourceforge.net/rijndael/rijndaelImplementation.pdf
325
+ };
326
+ Zohovault.AES.mixColumns = function (s, Nb) {
327
+ for (var c = 0; c < 4; c++) {
328
+ var a = new Array(4); // 'a' is a copy of the current column from 's'
329
+ var b = new Array(4); // 'b' is a•{02} in GF(2^8)
330
+ for (var i = 0; i < 4; i++) {
331
+ a[i] = s[i][c];
332
+ b[i] = s[i][c] & 0x80 ? s[i][c] << 1 ^ 0x011b : s[i][c] << 1;
333
+ }
334
+ // a[n] ^ b[n] is a•{03} in GF(2^8)
335
+ s[0][c] = b[0] ^ a[1] ^ b[1] ^ a[2] ^ a[3]; // 2*a0 + 3*a1 + a2 + a3
336
+ s[1][c] = a[0] ^ b[1] ^ a[2] ^ b[2] ^ a[3]; // a0 * 2*a1 + 3*a2 + a3
337
+ s[2][c] = a[0] ^ a[1] ^ b[2] ^ a[3] ^ b[3]; // a0 + a1 + 2*a2 + 3*a3
338
+ s[3][c] = a[0] ^ b[0] ^ a[1] ^ a[2] ^ b[3]; // 3*a0 + a1 + a2 + 2*a3
339
+ }
340
+ return s;
341
+ };
342
+ Zohovault.AES.addRoundKey = function (state, w, rnd, Nb) {
343
+ for (var r = 0; r < 4; r++) {
344
+ for (var c = 0; c < Nb; c++) {
345
+ state[r][c] ^= w[rnd * 4 + c][r];
346
+ }
347
+ }
348
+ return state;
349
+ };
350
+ Zohovault.AES.subWord = function (w) {
351
+ for (var i = 0; i < 4; i++) {
352
+ w[i] = Zohovault.AES.sBox[w[i]];
353
+ }
354
+ return w;
355
+ };
356
+ Zohovault.AES.rotWord = function (w) {
357
+ var tmp = w[0];
358
+ for (var i = 0; i < 3; i++) {
359
+ w[i] = w[i + 1];
360
+ }
361
+ w[3] = tmp;
362
+ return w;
363
+ };
364
+ // sBox is pre-computed multiplicative inverse in GF(2^8) used in subBytes and keyExpansion [§5.1.1]
365
+ Zohovault.AES.sBox = [0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
366
+ 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
367
+ 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
368
+ 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
369
+ 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
370
+ 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
371
+ 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
372
+ 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
373
+ 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
374
+ 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
375
+ 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
376
+ 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
377
+ 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
378
+ 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
379
+ 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
380
+ 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16];
381
+ // rCon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [§5.2]
382
+ Zohovault.AES.rCon = [[0x00, 0x00, 0x00, 0x00],
383
+ [0x01, 0x00, 0x00, 0x00],
384
+ [0x02, 0x00, 0x00, 0x00],
385
+ [0x04, 0x00, 0x00, 0x00],
386
+ [0x08, 0x00, 0x00, 0x00],
387
+ [0x10, 0x00, 0x00, 0x00],
388
+ [0x20, 0x00, 0x00, 0x00],
389
+ [0x40, 0x00, 0x00, 0x00],
390
+ [0x80, 0x00, 0x00, 0x00],
391
+ [0x1b, 0x00, 0x00, 0x00],
392
+ [0x36, 0x00, 0x00, 0x00]];
393
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
394
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
395
+ /* AES Counter-mode implementation in JavaScript (c) Chris Veness 2005-2011 */
396
+ /* - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf */
397
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
398
+ /**
399
+ * Encrypt a text using AES encryption in Counter mode of operation
400
+ *
401
+ * Unicode multi-byte character safe
402
+ *
403
+ * @param {String} plaintext Source text to be encrypted
404
+ * @param {String} password The password to use to generate a key
405
+ * @param {Number} nBits Number of bits to be used in the key (128, 192, or 256)
406
+ * @returns {string} Encrypted text
407
+ */
408
+ Zohovault.AES.encrypt = function (plaintext, password, nBits) {
409
+ var blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
410
+ if (!(nBits == 128 || nBits == 192 || nBits == 256)) {
411
+ return '';
412
+ } // standard allows 128/192/256 bit keys
413
+ plaintext = Utf8.encode(plaintext);
414
+ password = Utf8.encode(password);
415
+ //var t = new Date(); // timer
416
+ // use AES itself to encrypt password to get cipher key (using plain password as source for key
417
+ // expansion) - gives us well encrypted key (though hashed key might be preferred for prod'n use)
418
+ var nBytes = nBits / 8; // no bytes in key (16/24/32)
419
+ var pwBytes = new Array(nBytes);
420
+ for (var i = 0; i < nBytes; i++) { // use 1st 16/24/32 chars of password for key
421
+ pwBytes[i] = isNaN(password.charCodeAt(i)) ? 0 : password.charCodeAt(i);
422
+ }
423
+ var key = Zohovault.AES.cipher(pwBytes, Zohovault.AES.keyExpansion(pwBytes)); // gives us 16-byte key
424
+ key = key.concat(key.slice(0, nBytes - 16)); // expand key to 16/24/32 bytes long
425
+ // initialise 1st 8 bytes of counter block with nonce (NIST SP800-38A §B.2): [0-1] = millisec,
426
+ // [2-3] = random, [4-7] = seconds, together giving full sub-millisec uniqueness up to Feb 2106
427
+ var counterBlock = new Array(blockSize);
428
+ var nonce = (new Date()).getTime(); // timestamp: milliseconds since 1-Jan-1970
429
+ var nonceMs = nonce % 1000;
430
+ var nonceSec = Math.floor(nonce / 1000);
431
+ var nonceRnd = Math.floor(Math.random() * 0xffff);
432
+ for (var i = 0; i < 2; i++) {
433
+ counterBlock[i] = (nonceMs >>> i * 8) & 0xff;
434
+ }
435
+ for (var i = 0; i < 2; i++) {
436
+ counterBlock[i + 2] = (nonceRnd >>> i * 8) & 0xff;
437
+ }
438
+ for (var i = 0; i < 4; i++) {
439
+ counterBlock[i + 4] = (nonceSec >>> i * 8) & 0xff;
440
+ }
441
+ // and convert it to a string to go on the front of the ciphertext
442
+ var ctrTxt = '';
443
+ for (var i = 0; i < 8; i++) {
444
+ ctrTxt += String.fromCharCode(counterBlock[i]);
445
+ }
446
+ // generate key schedule - an expansion of the key into distinct Key Rounds for each round
447
+ var keySchedule = Zohovault.AES.keyExpansion(key);
448
+ var blockCount = Math.ceil(plaintext.length / blockSize);
449
+ var ciphertxt = new Array(blockCount); // ciphertext as array of strings
450
+ for (var b = 0; b < blockCount; b++) {
451
+ // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
452
+ // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB)
453
+ for (var c = 0; c < 4; c++) {
454
+ counterBlock[15 - c] = (b >>> c * 8) & 0xff;
455
+ }
456
+ for (var c = 0; c < 4; c++) {
457
+ counterBlock[15 - c - 4] = (b / 0x100000000 >>> c * 8);
458
+ }
459
+ var cipherCntr = Zohovault.AES.cipher(counterBlock, keySchedule); // -- encrypt counter block --
460
+ // block size is reduced on final block
461
+ var blockLength = b < blockCount - 1 ? blockSize : (plaintext.length - 1) % blockSize + 1;
462
+ var cipherChar = new Array(blockLength);
463
+ for (var i = 0; i < blockLength; i++) { // -- xor plaintext with ciphered counter char-by-char --
464
+ cipherChar[i] = cipherCntr[i] ^ plaintext.charCodeAt(b * blockSize + i);
465
+ cipherChar[i] = String.fromCharCode(cipherChar[i]);
466
+ }
467
+ ciphertxt[b] = cipherChar.join('');
468
+ }
469
+ // Array.join is more efficient than repeated string concatenation in IE
470
+ var ciphertext = ctrTxt + ciphertxt.join('');
471
+ ciphertext = Base64.encode(ciphertext); // encode in base64
472
+ //alert((new Date()) - t);
473
+ return ciphertext;
474
+ };
475
+ /**
476
+ * Decrypt a text encrypted by AES in counter mode of operation
477
+ *
478
+ * @param {String} ciphertext Source text to be encrypted
479
+ * @param {String} password The password to use to generate a key
480
+ * @param {Number} nBits Number of bits to be used in the key (128, 192, or 256)
481
+ * @returns {String} Decrypted text
482
+ */
483
+ Zohovault.AES.decrypt = function (ciphertext, password, nBits) {
484
+ var blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
485
+ if (!(nBits == 128 || nBits == 192 || nBits == 256)) {
486
+ return '';
487
+ } // standard allows 128/192/256 bit keys
488
+ ciphertext = Base64.decode(ciphertext);
489
+ password = Utf8.encode(password);
490
+ //var t = new Date(); // timer
491
+ // use AES to encrypt password (mirroring encrypt routine)
492
+ var nBytes = nBits / 8; // no bytes in key
493
+ var pwBytes = new Array(nBytes);
494
+ for (var i = 0; i < nBytes; i++) {
495
+ pwBytes[i] = isNaN(password.charCodeAt(i)) ? 0 : password.charCodeAt(i);
496
+ }
497
+ var key = Zohovault.AES.cipher(pwBytes, Zohovault.AES.keyExpansion(pwBytes));
498
+ key = key.concat(key.slice(0, nBytes - 16)); // expand key to 16/24/32 bytes long
499
+ // recover nonce from 1st 8 bytes of ciphertext
500
+ var counterBlock = new Array(8);
501
+ var ctrTxt = ciphertext.slice(0, 8);
502
+ for (var i = 0; i < 8; i++) {
503
+ counterBlock[i] = ctrTxt.charCodeAt(i);
504
+ }
505
+ // generate key schedule
506
+ var keySchedule = Zohovault.AES.keyExpansion(key);
507
+ // separate ciphertext into blocks (skipping past initial 8 bytes)
508
+ var nBlocks = Math.ceil((ciphertext.length - 8) / blockSize);
509
+ var ct = new Array(nBlocks);
510
+ for (var b = 0; b < nBlocks; b++) {
511
+ ct[b] = ciphertext.slice(8 + b * blockSize, 8 + b * blockSize + blockSize);
512
+ }
513
+ ciphertext = ct; // ciphertext is now array of block-length strings
514
+ // plaintext will get generated block-by-block into array of block-length strings
515
+ var plaintxt = new Array(ciphertext.length);
516
+ for (var b = 0; b < nBlocks; b++) {
517
+ // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
518
+ for (var c = 0; c < 4; c++) {
519
+ counterBlock[15 - c] = ((b) >>> c * 8) & 0xff;
520
+ }
521
+ for (var c = 0; c < 4; c++) {
522
+ counterBlock[15 - c - 4] = (((b + 1) / 0x100000000 - 1) >>> c * 8) & 0xff;
523
+ }
524
+ var cipherCntr = Zohovault.AES.cipher(counterBlock, keySchedule); // encrypt counter block
525
+ var plaintxtByte = new Array(ciphertext[b].length);
526
+ for (var i = 0; i < ciphertext[b].length; i++) {
527
+ // -- xor plaintxt with ciphered counter byte-by-byte --
528
+ plaintxtByte[i] = cipherCntr[i] ^ ciphertext[b].charCodeAt(i);
529
+ plaintxtByte[i] = String.fromCharCode(plaintxtByte[i]);
530
+ }
531
+ plaintxt[b] = plaintxtByte.join('');
532
+ }
533
+ // join array of blocks into single plaintext string
534
+ var plaintext = plaintxt.join('');
535
+ plaintext = Utf8.decode(plaintext); // decode from UTF8 back to Unicode multi-byte chars
536
+ //alert((new Date()) - t);
537
+ return plaintext;
538
+ };
539
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
540
+ /* Base64 class: Base 64 encoding / decoding (c) Chris Veness 2002-2012 */
541
+ /* note: depends on Utf8 class */
542
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
543
+ var Base64 = {}; // Base64 namespace
544
+ Base64.code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
545
+ /**
546
+ * Encode string into Base64, as defined by RFC 4648 [http://tools.ietf.org/html/rfc4648]
547
+ * (instance method extending String object). As per RFC 4648, no newlines are added.
548
+ *
549
+ * @param {String} str The string to be encoded as base-64
550
+ * @param {Boolean} [utf8encode=false] Flag to indicate whether str is Unicode string to be encoded
551
+ * to UTF8 before conversion to base64; otherwise string is assumed to be 8-bit characters
552
+ * @returns {String} Base64-encoded string
553
+ */
554
+ Base64.encode = function (str, utf8encode) {
555
+ utf8encode = (typeof utf8encode == 'undefined') ? false : utf8encode;
556
+ var o1, o2, o3, bits, h1, h2, h3, h4, e = [], pad = '', c, plain, coded;
557
+ var b64 = Base64.code;
558
+ plain = utf8encode ? str.encodeUTF8() : str;
559
+ c = plain.length % 3; // pad string to length of multiple of 3
560
+ if (c > 0) {
561
+ while (c++ < 3) {
562
+ pad += '=';
563
+ plain += '\0';
564
+ }
565
+ }
566
+ // note: doing padding here saves us doing special-case packing for trailing 1 or 2 chars
567
+ for (c = 0; c < plain.length; c += 3) { // pack three octets into four hexets
568
+ o1 = plain.charCodeAt(c);
569
+ o2 = plain.charCodeAt(c + 1);
570
+ o3 = plain.charCodeAt(c + 2);
571
+ bits = o1 << 16 | o2 << 8 | o3;
572
+ h1 = bits >> 18 & 0x3f;
573
+ h2 = bits >> 12 & 0x3f;
574
+ h3 = bits >> 6 & 0x3f;
575
+ h4 = bits & 0x3f;
576
+ // use hextets to index into code string
577
+ e[c / 3] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
578
+ }
579
+ coded = e.join(''); // join() is far faster than repeated string concatenation in IE
580
+ // replace 'A's from padded nulls with '='s
581
+ coded = coded.slice(0, coded.length - pad.length) + pad;
582
+ return coded;
583
+ };
584
+ /**
585
+ * Decode string from Base64, as defined by RFC 4648 [http://tools.ietf.org/html/rfc4648]
586
+ * (instance method extending String object). As per RFC 4648, newlines are not catered for.
587
+ *
588
+ * @param {String} str The string to be decoded from base-64
589
+ * @param {Boolean} [utf8decode=false] Flag to indicate whether str is Unicode string to be decoded
590
+ * from UTF8 after conversion from base64
591
+ * @returns {String} decoded string
592
+ */
593
+ Base64.decode = function (str, utf8decode) {
594
+ utf8decode = (typeof utf8decode == 'undefined') ? false : utf8decode;
595
+ var o1, o2, o3, h1, h2, h3, h4, bits, d = [], plain, coded;
596
+ var b64 = Base64.code;
597
+ coded = utf8decode ? str.decodeUTF8() : str;
598
+ for (var c = 0; c < coded.length; c += 4) { // unpack four hexets into three octets
599
+ h1 = b64.indexOf(coded.charAt(c));
600
+ h2 = b64.indexOf(coded.charAt(c + 1));
601
+ h3 = b64.indexOf(coded.charAt(c + 2));
602
+ h4 = b64.indexOf(coded.charAt(c + 3));
603
+ bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
604
+ o1 = bits >>> 16 & 0xff;
605
+ o2 = bits >>> 8 & 0xff;
606
+ o3 = bits & 0xff;
607
+ d[c / 4] = String.fromCharCode(o1, o2, o3);
608
+ // check for padding
609
+ if (h4 == 0x40) {
610
+ d[c / 4] = String.fromCharCode(o1, o2);
611
+ }
612
+ if (h3 == 0x40) {
613
+ d[c / 4] = String.fromCharCode(o1);
614
+ }
615
+ }
616
+ plain = d.join(''); // join() is far faster than repeated string concatenation in IE
617
+ return utf8decode ? plain.decodeUTF8() : plain;
618
+ };
619
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
620
+ /* Utf8 class: encode / decode between multi-byte Unicode characters and UTF-8 multiple */
621
+ /* single-byte character encoding (c) Chris Veness 2002-2012 */
622
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
623
+ var Utf8 = {}; // Utf8 namespace
624
+ /**
625
+ * Encode multi-byte Unicode string into utf-8 multiple single-byte characters
626
+ * (BMP / basic multilingual plane only)
627
+ *
628
+ * Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars
629
+ *
630
+ * @param {String} strUni Unicode string to be encoded as UTF-8
631
+ * @returns {String} encoded string
632
+ */
633
+ Utf8.encode = function (strUni) {
634
+ // use regular expressions & String.replace callback function for better efficiency
635
+ // than procedural approaches
636
+ var strUtf = strUni.replace(/[\u0080-\u07ff]/g, // U+0080 - U+07FF => 2 bytes 110yyyyy, 10zzzzzz
637
+ function (c) {
638
+ var cc = c.charCodeAt(0);
639
+ return String.fromCharCode(0xc0 | cc >> 6, 0x80 | cc & 0x3f);
640
+ });
641
+ strUtf = strUtf.replace(/[\u0800-\uffff]/g, // U+0800 - U+FFFF => 3 bytes 1110xxxx, 10yyyyyy, 10zzzzzz
642
+ function (c) {
643
+ var cc = c.charCodeAt(0);
644
+ return String.fromCharCode(0xe0 | cc >> 12, 0x80 | cc >> 6 & 0x3F, 0x80 | cc & 0x3f);
645
+ });
646
+ return strUtf;
647
+ };
648
+ /**
649
+ * Decode utf-8 encoded string back into multi-byte Unicode characters
650
+ *
651
+ * @param {String} strUtf UTF-8 string to be decoded back to Unicode
652
+ * @returns {String} decoded string
653
+ */
654
+ Utf8.decode = function (strUtf) {
655
+ // note: decode 3-byte chars first as decoded 2-byte strings could appear to be 3-byte char!
656
+ var strUni = strUtf.replace(/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte chars
657
+ function (c) {
658
+ var cc = ((c.charCodeAt(0) & 0x0f) << 12) | ((c.charCodeAt(1) & 0x3f) << 6) | (c.charCodeAt(2) & 0x3f);
659
+ return String.fromCharCode(cc);
660
+ });
661
+ strUni = strUni.replace(/[\u00c0-\u00df][\u0080-\u00bf]/g, // 2-byte chars
662
+ function (c) {
663
+ var cc = (c.charCodeAt(0) & 0x1f) << 6 | c.charCodeAt(1) & 0x3f;
664
+ return String.fromCharCode(cc);
665
+ });
666
+ return strUni;
667
+ };
668
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
669
+ //ignorei18n_end
670
+ export default Zohovault;
671
+ //# sourceMappingURL=zohovault.js.map
@@ -0,0 +1,10 @@
1
+ import pkg from "log4js";
2
+ import { DB_PATH } from "../../util/consts.util.js";
3
+ const { configure, getLogger, shutdown } = pkg;
4
+ export const Logger = getLogger();
5
+ configure({
6
+ appenders: { cheese: { type: 'file', filename: `${DB_PATH}/error.log`, maxLogSize: 10485760, backups: 3, compress: true } }, // NO I18N
7
+ categories: { default: { appenders: ['cheese'], level: 'info' } }
8
+ });
9
+ export const LoggerShutdown = shutdown;
10
+ //# sourceMappingURL=index.js.map