@mherod/get-cookie 1.3.0 → 2.0.0-beta.1

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/dist/main.js CHANGED
@@ -1,32 +1,37 @@
1
1
  #!/usr/bin/env node
2
- var $bU6Ve$jsonwebtoken = require("jsonwebtoken");
2
+ var $bU6Ve$lodash = require("lodash");
3
3
  var $bU6Ve$fs = require("fs");
4
4
  var $bU6Ve$crypto = require("crypto");
5
- var $bU6Ve$lodash = require("lodash");
5
+ var $bU6Ve$path = require("path");
6
6
  var $bU6Ve$child_process = require("child_process");
7
7
  var $bU6Ve$sqlite3 = require("sqlite3");
8
+ var $bU6Ve$jsonwebtoken = require("jsonwebtoken");
8
9
 
10
+ function $parcel$export(e, n, v, s) {
11
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
12
+ }
9
13
  function $parcel$interopDefault(a) {
10
14
  return a && a.__esModule ? a.default : a;
11
15
  }
12
16
 
17
+ $parcel$export(module.exports, "getCookie", () => $af7abeb0794bd6fa$export$4be65e66cfa2648a);
18
+ $parcel$export(module.exports, "getFirefoxCookie", () => $af7abeb0794bd6fa$export$c44c5fdef43f0941);
19
+ $parcel$export(module.exports, "getChromeCookie", () => $af7abeb0794bd6fa$export$e5637297e9eb6f2e);
20
+ class $36bba8acd7b702be$export$2e2bcd8739ae039 {
21
+ async queryCookies(name, domain) {
22
+ if (process.env.NODE_ENV === "development") console.log("queryCookie", name, domain);
23
+ return [];
24
+ }
25
+ }
13
26
 
14
27
 
15
- var $fa5ed5287f8fdf72$require$merge = $bU6Ve$lodash.merge;
16
- const $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3 = {};
17
- $fa5ed5287f8fdf72$require$merge($fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3, process.env);
18
-
19
-
20
- if (process.platform !== "darwin") throw new Error("This script only works on macOS");
21
- var $c0cdc003fbf917f0$exports = {};
22
28
 
23
- var $c0cdc003fbf917f0$require$exec = $bU6Ve$child_process.exec;
24
29
 
25
- async function $c0cdc003fbf917f0$var$execSimple(command) {
30
+ async function $c0cdc003fbf917f0$export$8d71c74f97c0202e(command) {
26
31
  if (typeof command !== "string") throw new TypeError("execSimple: command must be a string");
27
32
  if (process.env.VERBOSE) console.log(command);
28
33
  return new Promise((resolve, reject)=>{
29
- $c0cdc003fbf917f0$require$exec(command, {
34
+ (0, $bU6Ve$child_process.exec)(command, {
30
35
  encoding: "binary",
31
36
  maxBuffer: 5120
32
37
  }, (error, stdout, stderr)=>{
@@ -42,11 +47,11 @@ async function $c0cdc003fbf917f0$var$execSimple(command) {
42
47
  });
43
48
  });
44
49
  }
45
- async function $c0cdc003fbf917f0$var$execAsBuffer(command) {
50
+ async function $c0cdc003fbf917f0$export$1704cc27537f7088(command) {
46
51
  if (typeof command !== "string") throw new TypeError("execAsBuffer: command must be a string");
47
52
  if (process.env.VERBOSE) console.log(command);
48
53
  return await new Promise((resolve, reject)=>{
49
- $c0cdc003fbf917f0$require$exec(command, {
54
+ (0, $bU6Ve$child_process.exec)(command, {
50
55
  encoding: "binary",
51
56
  maxBuffer: 5120
52
57
  }, (error, stdout, stderr)=>{
@@ -65,7 +70,7 @@ async function $c0cdc003fbf917f0$var$execAsBuffer(command) {
65
70
  });
66
71
  });
67
72
  }
68
- function $c0cdc003fbf917f0$var$toStringValue(r) {
73
+ function $c0cdc003fbf917f0$export$33d3adc27420eed5(r) {
69
74
  if (process.env.VERBOSE) console.log("Printing value", r);
70
75
  if (r) {
71
76
  if (typeof r === "string") return r;
@@ -73,7 +78,7 @@ function $c0cdc003fbf917f0$var$toStringValue(r) {
73
78
  return r.toString("utf8");
74
79
  }
75
80
  }
76
- function $c0cdc003fbf917f0$var$printStringValue(r) {
81
+ function $c0cdc003fbf917f0$export$1ed1ce2ec2b4f5a3(r) {
77
82
  if (process.env.VERBOSE) console.log("Printing value", r);
78
83
  if (r) {
79
84
  if (typeof r === "string") console.log(r);
@@ -81,11 +86,7 @@ function $c0cdc003fbf917f0$var$printStringValue(r) {
81
86
  console.log(r.toString("utf8"));
82
87
  }
83
88
  }
84
- /**
85
- *
86
- * @param result
87
- * @returns {string|null}
88
- */ function $c0cdc003fbf917f0$var$toStringOrNull(result) {
89
+ function $c0cdc003fbf917f0$export$d53bf2de587a369(result) {
89
90
  if (result == null) return null;
90
91
  if (process.env.VERBOSE) console.log("result", result);
91
92
  if (typeof result === "string" && result.length > 0) return result;
@@ -94,15 +95,10 @@ function $c0cdc003fbf917f0$var$printStringValue(r) {
94
95
  return null;
95
96
  }
96
97
 
97
- /**
98
- *
99
- * @param {string} file
100
- * @param {string} sql
101
- * @returns {Promise<Buffer[]>}
102
- */ async function $c0cdc003fbf917f0$var$doSqliteQuery1(file, sql) {
98
+ async function $c0cdc003fbf917f0$export$f19f611d1fa7c6f3(file, sql) {
103
99
  if (typeof sql !== "string") throw new TypeError("doSqliteQuery1: sql must be a string");
104
100
  if (typeof file !== "string") throw new TypeError("doSqliteQuery1: file must be a string");
105
- if (!$bU6Ve$fs.existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
101
+ if (!(0, ($parcel$interopDefault($bU6Ve$fs))).existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
106
102
  if (process.env.VERBOSE) {
107
103
  console.log(`doSqliteQuery1: file ${file}`);
108
104
  console.log(`doSqliteQuery1: sql ${sql}`);
@@ -137,106 +133,151 @@ function $c0cdc003fbf917f0$var$printStringValue(r) {
137
133
  });
138
134
  });
139
135
  }
140
- $c0cdc003fbf917f0$exports = {
141
- execSimple: $c0cdc003fbf917f0$var$execSimple,
142
- execAsBuffer: $c0cdc003fbf917f0$var$execAsBuffer,
143
- printStringValue: $c0cdc003fbf917f0$var$printStringValue,
144
- toStringValue: $c0cdc003fbf917f0$var$toStringValue,
145
- toStringOrNull: $c0cdc003fbf917f0$var$toStringOrNull,
146
- doSqliteQuery1: $c0cdc003fbf917f0$var$doSqliteQuery1
147
- };
148
-
149
-
150
- var $af7abeb0794bd6fa$require$execSimple = $c0cdc003fbf917f0$exports.execSimple;
151
- var $af7abeb0794bd6fa$require$toStringOrNull = $c0cdc003fbf917f0$exports.toStringOrNull;
152
- var $af7abeb0794bd6fa$require$doSqliteQuery1 = $c0cdc003fbf917f0$exports.doSqliteQuery1;
153
- var $af7abeb0794bd6fa$require$toStringValue = $c0cdc003fbf917f0$exports.toStringValue;
154
-
155
- function $af7abeb0794bd6fa$var$isValidJwt(token) {
156
- if (typeof token !== "string") return false;
136
+ function $c0cdc003fbf917f0$export$99ce3e33a555daf1(input) {
137
+ return typeof input !== "string" || input.length === 0;
138
+ }
139
+
140
+
141
+
142
+ var $fa5ed5287f8fdf72$require$merge = $bU6Ve$lodash.merge;
143
+ const $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3 = {};
144
+ $fa5ed5287f8fdf72$require$merge($fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3, process.env);
145
+ const $fa5ed5287f8fdf72$export$a7c5707626fc90f = $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3["HOME"];
146
+ if (!$fa5ed5287f8fdf72$export$a7c5707626fc90f) throw new Error("HOME environment variable is not set");
147
+
148
+
149
+
150
+
151
+
152
+ async function $d6c2e79f3cdd498d$export$2c9faf86071156ae({ path: path , name: name , maxDepth: maxDepth = 2 }) {
153
+ if (typeof path !== "string") throw new Error("path must be a string");
154
+ if (typeof name !== "string") throw new Error("name must be a string");
155
+ const rootSegments = path.split("/").length;
156
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Searching for ${name} in ${path}`);
157
+ const files = [];
158
+ let readdirSync;
157
159
  try {
158
- const result = $bU6Ve$jsonwebtoken.decode(token, {
159
- complete: true
160
- });
161
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(result);
162
- return true;
163
- } catch (err) {
164
- return false;
160
+ readdirSync = (0, ($parcel$interopDefault($bU6Ve$fs))).readdirSync(path);
161
+ } catch (e) {
162
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Error reading ${path}`, e);
163
+ return files;
165
164
  }
165
+ for (const file of readdirSync){
166
+ const filePath = path + "/" + file;
167
+ let stat;
168
+ try {
169
+ stat = (0, ($parcel$interopDefault($bU6Ve$fs))).statSync(filePath);
170
+ } catch (e1) {
171
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error(`Error getting stat for ${filePath}`, e1);
172
+ continue;
173
+ }
174
+ if (stat.isDirectory()) {
175
+ if (filePath.split("/").length < rootSegments + maxDepth) try {
176
+ const subFiles = await $d6c2e79f3cdd498d$export$2c9faf86071156ae({
177
+ path: filePath,
178
+ name: name,
179
+ rootSegments: rootSegments,
180
+ maxDepth: 2
181
+ });
182
+ files.push(...subFiles);
183
+ } catch (e2) {
184
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error(e2);
185
+ }
186
+ } else if (file === name) files.push(filePath);
187
+ }
188
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) {
189
+ if (files.length > 0) {
190
+ console.log(`Found ${files.length} ${name} files`);
191
+ console.log(files);
192
+ }
193
+ }
194
+ return files;
166
195
  }
167
- /**
168
- *
169
- * @returns {Promise<string>}
170
- */ async function $af7abeb0794bd6fa$var$getChromePassword() {
171
- return $af7abeb0794bd6fa$require$execSimple('security find-generic-password -w -s "Chrome Safe Storage"');
172
- }
173
- /**
174
- *
175
- * @param params
176
- * @returns {Promise<string>}
177
- */ async function $af7abeb0794bd6fa$var$getCookie(params) {
178
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).CHROME_ONLY) {
179
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("chrome only");
180
- return $af7abeb0794bd6fa$var$getChromeCookie(params).then((cookie)=>{
181
- if (cookie && cookie.length > 0) return $af7abeb0794bd6fa$require$toStringValue(cookie);
182
- }).catch((err)=>{
183
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error(err);
196
+
197
+
198
+
199
+
200
+ class $1c57ad353fa3519e$export$2e2bcd8739ae039 extends (0, $36bba8acd7b702be$export$2e2bcd8739ae039) {
201
+ async queryCookies(name, domain) {
202
+ if (process.platform !== "darwin") throw new Error("This only works on macOS");
203
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).FIREFOX_ONLY) return [];
204
+ const cookies = await $1c57ad353fa3519e$var$getChromeCookies({
205
+ name: name,
206
+ domain: domain
184
207
  });
185
- } else if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).FIREFOX_ONLY) {
186
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("firefox only");
187
- return $af7abeb0794bd6fa$var$getFirefoxCookie(params).then((b)=>b.toString("utf8")).then((cookie)=>{
188
- if (cookie && cookie.length > 0) return $af7abeb0794bd6fa$require$toStringValue(cookie);
189
- else console.log("No cookie found");
190
- }).catch((err)=>{
191
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error("Error getting Firefox cookie", err);
208
+ return cookies.map((0, $c0cdc003fbf917f0$export$33d3adc27420eed5));
209
+ }
210
+ }
211
+ async function $1c57ad353fa3519e$var$getPromise1(name, domain, file) {
212
+ try {
213
+ return await $1c57ad353fa3519e$var$getEncryptedChromeCookie({
214
+ name: name,
215
+ domain: domain,
216
+ file: file
192
217
  });
193
- } else return await $af7abeb0794bd6fa$var$getChromeCookie(params).catch((err)=>{
194
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error("Error getting Chrome cookie", err);
195
- }).then((r)=>{
196
- if (typeof r === "string" && r.trim().length > 0) return r;
197
- else return $af7abeb0794bd6fa$var$getFirefoxCookie(params).catch((err)=>{
198
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error("Error getting Firefox cookie", err);
218
+ } catch (e) {
219
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error getting encrypted cookie", e);
220
+ return [];
221
+ }
222
+ }
223
+ async function $1c57ad353fa3519e$var$getPromise(name, domain) {
224
+ try {
225
+ const files = await (0, $d6c2e79f3cdd498d$export$2c9faf86071156ae)({
226
+ path: $1c57ad353fa3519e$var$chromeLocal,
227
+ name: "Cookies"
199
228
  });
200
- }).catch((e)=>{
201
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error("Error getting Chrome or Firefox cookie", e);
202
- }).then($af7abeb0794bd6fa$require$toStringValue);
229
+ const promises = files.map((file)=>$1c57ad353fa3519e$var$getPromise1(name, domain, file));
230
+ const results1 = await Promise.all(promises);
231
+ const results2 = results1.flat();
232
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("getEncryptedChromeCookie results", results2);
233
+ return results2.filter((result)=>result);
234
+ } catch (error) {
235
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("error", error);
236
+ return [];
237
+ }
203
238
  }
204
239
  /**
205
240
  *
206
- * @param name
207
- * @param domain
208
- * @returns {Promise<Buffer>}
209
- */ async function $af7abeb0794bd6fa$var$getFirefoxCookie({ name: name , domain: domain }) {
210
- if (name && typeof name !== "string") throw new Error("name must be a string");
211
- if (domain && typeof domain !== "string") throw new Error("domain must be a string");
212
- const [file] = await $af7abeb0794bd6fa$var$findAllFiles({
213
- path: `${(0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).HOME}/Library/Application Support/Firefox/Profiles`,
214
- name: "cookies.sqlite"
215
- });
216
- if (file && !(0, ($parcel$interopDefault($bU6Ve$fs))).existsSync(file)) throw new Error(`File ${file} does not exist`);
217
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying Firefox cookie ${name} for domain ${domain}`);
218
- let sql;
219
- sql = "SELECT value FROM moz_cookies";
220
- if (typeof name === "string" || typeof domain === "string") {
221
- sql += ` WHERE `;
222
- if (typeof name === "string") {
223
- sql += `name = '${name}'`;
224
- if (typeof domain === "string") sql += ` AND `;
241
+ * @param {string|undefined} name
242
+ * @param {string} domain
243
+ * @param {boolean} requireJwt
244
+ * @returns {Promise<[string]>}
245
+ */ async function $1c57ad353fa3519e$var$getChromeCookies({ name: name , domain: domain = "%" , requireJwt: requireJwt = false }) {
246
+ if ((0, $c0cdc003fbf917f0$export$99ce3e33a555daf1)(name)) throw new Error("name must be a string");
247
+ if ((0, $c0cdc003fbf917f0$export$99ce3e33a555daf1)(domain)) throw new Error("domain must be a string");
248
+ const encryptedDataItems = await $1c57ad353fa3519e$var$getPromise(name, domain);
249
+ const password = await $1c57ad353fa3519e$var$getChromePassword();
250
+ const decrypted = encryptedDataItems.filter((encryptedData)=>{
251
+ return encryptedData != null && encryptedData.length > 0;
252
+ }).map(async (encryptedData)=>{
253
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Received encrypted", encryptedData);
254
+ let d;
255
+ try {
256
+ d = await $1c57ad353fa3519e$var$decrypt(password, encryptedData);
257
+ } catch (e) {
258
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error decrypting cookie", e);
259
+ return null;
225
260
  }
226
- if (typeof domain === "string") sql += `host LIKE '${domain}';`;
227
- }
228
- return await $af7abeb0794bd6fa$require$doSqliteQuery1(file, sql).then((rows)=>{
229
- return rows.map($af7abeb0794bd6fa$require$toStringOrNull).find((v)=>v !== null);
261
+ if (d) {
262
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Decrypted", d);
263
+ return d;
264
+ }
265
+ return null;
230
266
  });
267
+ const results = await Promise.all(decrypted);
268
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("results", results);
269
+ return results.map((0, $c0cdc003fbf917f0$export$d53bf2de587a369));
231
270
  }
232
- const $af7abeb0794bd6fa$var$defaultChromeRoot = `${(0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).HOME}/Library/Application Support/Google/Chrome`;
233
- const $af7abeb0794bd6fa$var$defaultChromeCookies = `${$af7abeb0794bd6fa$var$defaultChromeRoot}/Default/Cookies`;
234
- async function $af7abeb0794bd6fa$var$getEncryptedChromeCookie({ name: name , domain: domain , file: file = $af7abeb0794bd6fa$var$defaultChromeCookies , }) {
271
+ const $1c57ad353fa3519e$var$chromeLocal = $bU6Ve$path.join((0, $fa5ed5287f8fdf72$export$a7c5707626fc90f), "Library", "Application Support", "Google", "Chrome");
272
+ async function $1c57ad353fa3519e$var$getEncryptedChromeCookie({ name: name , domain: domain , file: file = $bU6Ve$path.join($1c57ad353fa3519e$var$chromeLocal, "Default", "Cookies") , }) {
235
273
  if (name && typeof name !== "string") throw new Error("name must be a string");
236
274
  if (domain && typeof domain !== "string") throw new Error("domain must be a string");
237
275
  if (file && typeof file !== "string") throw new Error("file must be a string");
238
- if (!(0, ($parcel$interopDefault($bU6Ve$fs))).existsSync(file)) throw new Error(`File ${file} does not exist`);
239
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying Chrome (at ${file.split("/").slice(-3).join("/")}) cookie ${name} for domain ${domain}`);
276
+ if (!(0, $bU6Ve$fs.existsSync)(file)) throw new Error(`File ${file} does not exist`);
277
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) {
278
+ const s = file.split("/").slice(-3).join("/");
279
+ console.log(`Trying Chrome (at ${s}) cookie ${name} for domain ${domain}`);
280
+ }
240
281
  let sql;
241
282
  sql = `SELECT encrypted_value FROM cookies`;
242
283
  if (typeof name === "string" || typeof domain === "string") {
@@ -247,14 +288,20 @@ async function $af7abeb0794bd6fa$var$getEncryptedChromeCookie({ name: name , dom
247
288
  }
248
289
  if (typeof domain === "string") sql += `host_key LIKE '${domain}';`;
249
290
  }
250
- return await $af7abeb0794bd6fa$require$doSqliteQuery1(file, sql);
291
+ return (0, $c0cdc003fbf917f0$export$f19f611d1fa7c6f3)(file, sql);
292
+ }
293
+ /**
294
+ *
295
+ * @returns {Promise<string>}
296
+ */ async function $1c57ad353fa3519e$var$getChromePassword() {
297
+ return (0, $c0cdc003fbf917f0$export$8d71c74f97c0202e)('security find-generic-password -w -s "Chrome Safe Storage"');
251
298
  }
252
299
  /**
253
300
  *
254
301
  * @param {string} password
255
302
  * @param {Buffer} encryptedData
256
303
  * @returns {Promise<string>}
257
- */ async function $af7abeb0794bd6fa$var$decrypt(password, encryptedData) {
304
+ */ async function $1c57ad353fa3519e$var$decrypt(password, encryptedData) {
258
305
  if (typeof password !== "string") throw new Error("password must be a string: " + password);
259
306
  let encryptedData1;
260
307
  encryptedData1 = encryptedData;
@@ -297,7 +344,7 @@ async function $af7abeb0794bd6fa$var$getEncryptedChromeCookie({ name: name , dom
297
344
  reject(e);
298
345
  return;
299
346
  }
300
- let padding = decoded[decoded.length - 1];
347
+ const padding = decoded[decoded.length - 1];
301
348
  if (padding) decoded = decoded.slice(0, 0 - padding);
302
349
  // noinspection JSCheckFunctionSignatures
303
350
  decoded = decoded.toString("utf8");
@@ -308,123 +355,145 @@ async function $af7abeb0794bd6fa$var$getEncryptedChromeCookie({ name: name , dom
308
355
  });
309
356
  });
310
357
  }
311
- /**
312
- *
313
- * @param {string|undefined} name
314
- * @param {string} domain
315
- * @param {boolean} requireJwt
316
- * @returns {Promise<string>}
317
- */ async function $af7abeb0794bd6fa$var$getChromeCookie({ name: name , domain: domain = "%" , requireJwt: requireJwt = false }) {
318
- if (name && typeof name !== "string") throw new Error("name must be a string");
319
- if (typeof domain !== "string") throw new Error("domain must be a string");
320
- const encryptedDataItems = await $af7abeb0794bd6fa$var$findAllFiles({
321
- path: $af7abeb0794bd6fa$var$defaultChromeRoot,
322
- name: "Cookies"
323
- }).then((files)=>{
324
- const promises = files.map((file)=>{
325
- return $af7abeb0794bd6fa$var$getEncryptedChromeCookie({
326
- name: name,
327
- domain: domain,
328
- file: file
329
- }).catch((e)=>{
330
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error getting encrypted cookie", e);
331
- return [];
332
- });
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+ class $d66ab4010a2fe667$export$2e2bcd8739ae039 extends (0, $36bba8acd7b702be$export$2e2bcd8739ae039) {
367
+ async queryCookies(name, domain) {
368
+ if (process.platform !== "darwin") throw new Error("This only works on macOS");
369
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).CHROME_ONLY) return [];
370
+ const cookies = await this.#getFirefoxCookie({
371
+ name: name,
372
+ domain: domain
333
373
  });
334
- return Promise.all(promises).then((results)=>results.flat()).then((results)=>{
335
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("getEncryptedChromeCookie results", results);
336
- return results.filter((result)=>{
337
- return result;
338
- });
374
+ return Array.isArray(cookies) ? cookies.map((0, $c0cdc003fbf917f0$export$d53bf2de587a369)) : [];
375
+ }
376
+ /**
377
+ *
378
+ * @param name
379
+ * @param domain
380
+ * @returns {Promise<Buffer>}
381
+ */ async #getFirefoxCookie({ name: name , domain: domain }) {
382
+ if (name && typeof name !== "string") throw new Error("name must be a string");
383
+ if (domain && typeof domain !== "string") throw new Error("domain must be a string");
384
+ const files = await (0, $d6c2e79f3cdd498d$export$2c9faf86071156ae)({
385
+ path: $bU6Ve$path.join((0, $fa5ed5287f8fdf72$export$a7c5707626fc90f), "Library", "Application Support", "Firefox", "Profiles"),
386
+ name: "cookies.sqlite"
339
387
  });
340
- }).catch((error)=>{
341
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("error", error);
342
- return [];
343
- });
344
- const password = await $af7abeb0794bd6fa$var$getChromePassword();
345
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("encryptedDataItems", encryptedDataItems);
346
- const decrypted = encryptedDataItems.filter((encryptedData)=>{
347
- return encryptedData != null && encryptedData.length > 0;
348
- }).map(async (encryptedData)=>{
349
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Received encrypted", encryptedData);
350
- let decrypted;
351
- try {
352
- decrypted = await $af7abeb0794bd6fa$var$decrypt(password, encryptedData);
353
- } catch (e) {
354
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error decrypting cookie", e);
355
- return null;
356
- }
357
- if (decrypted) {
358
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Decrypted", decrypted);
359
- return decrypted;
388
+ const all = Promise.all(files.map((file)=>{
389
+ return this.#queryCookiesDb(file, name, domain);
390
+ }));
391
+ return all.flat();
392
+ }
393
+ #queryCookiesDb(file, name1, domain1) {
394
+ if (file && !(0, $bU6Ve$fs.existsSync)(file)) throw new Error(`File ${file} does not exist`);
395
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying Firefox cookie ${name1} for domain ${domain1}`);
396
+ let sql;
397
+ //language=SQL
398
+ sql = "SELECT value FROM moz_cookies";
399
+ if (typeof name1 === "string" || typeof domain1 === "string") {
400
+ sql += ` WHERE `;
401
+ if (typeof name1 === "string") {
402
+ sql += `name = '${name1}'`;
403
+ if (typeof domain1 === "string") sql += ` AND `;
404
+ }
405
+ if (typeof domain1 === "string") sql += `host LIKE '${domain1}';`;
360
406
  }
361
- return null;
362
- });
363
- const results = await Promise.all(decrypted);
364
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("results", results);
365
- return results.map($af7abeb0794bd6fa$require$toStringOrNull).find((result)=>{
366
- return typeof result === "string" && result.length > 0 && (requireJwt === false || $af7abeb0794bd6fa$var$isValidJwt(result));
367
- });
407
+ return (0, $c0cdc003fbf917f0$export$f19f611d1fa7c6f3)(file, sql).then((rows)=>rows.map((0, $c0cdc003fbf917f0$export$d53bf2de587a369))).catch(()=>[]);
408
+ }
368
409
  }
369
- /**
370
- *
371
- * @param path
372
- * @param name
373
- * @param rootSegments
374
- * @param maxDepth
375
- * @returns {Promise<[string]>}
376
- */ async function $af7abeb0794bd6fa$var$findAllFiles({ path: path , name: name , maxDepth: maxDepth = 2 }) {
377
- if (typeof path !== "string") throw new Error("path must be a string");
378
- if (typeof name !== "string") throw new Error("name must be a string");
379
- const rootSegments = path.split("/").length;
380
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Searching for ${name} in ${path}`);
381
- const files = [];
382
- let readdirSync;
383
- try {
384
- readdirSync = (0, ($parcel$interopDefault($bU6Ve$fs))).readdirSync(path);
385
- } catch (e) {
386
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Error reading ${path}`, e);
387
- return files;
410
+
411
+
412
+
413
+ class $ebf338ffba2ec9e7$export$2e2bcd8739ae039 extends (0, $36bba8acd7b702be$export$2e2bcd8739ae039) {
414
+ }
415
+
416
+
417
+
418
+ class $b4be7ecb8cbd1374$export$2e2bcd8739ae039 extends (0, $36bba8acd7b702be$export$2e2bcd8739ae039) {
419
+ #strategies;
420
+ constructor(){
421
+ super();
422
+ this.#strategies = [
423
+ (0, $1c57ad353fa3519e$export$2e2bcd8739ae039),
424
+ (0, $d66ab4010a2fe667$export$2e2bcd8739ae039),
425
+ (0, $ebf338ffba2ec9e7$export$2e2bcd8739ae039),
426
+ ].map((strategy)=>{
427
+ return new strategy();
428
+ });
388
429
  }
389
- for (const file of readdirSync){
390
- const filePath = path + "/" + file;
391
- let stat;
392
- try {
393
- stat = (0, ($parcel$interopDefault($bU6Ve$fs))).statSync(filePath);
394
- } catch (e1) {
395
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error(`Error getting stat for ${filePath}`, e1);
396
- continue;
397
- }
398
- if (stat.isDirectory()) {
399
- if (filePath.split("/").length < rootSegments + maxDepth) try {
400
- const subFiles = await $af7abeb0794bd6fa$var$findAllFiles({
401
- path: filePath,
402
- name: name,
403
- rootSegments: rootSegments,
404
- maxDepth: 2
405
- });
406
- files.push(...subFiles);
407
- } catch (e2) {
408
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error(e2);
409
- }
410
- } else if (file === name) files.push(filePath);
430
+ async queryCookies(name, domain) {
431
+ const results = await Promise.all(this.#strategies.map(async (strategy)=>{
432
+ return strategy.queryCookies(name, domain).catch(()=>[]);
433
+ }));
434
+ return results.flat();
411
435
  }
412
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) {
413
- if (files.length > 0) {
414
- console.log(`Found ${files.length} ${name} files`);
415
- console.log(files);
416
- }
436
+ }
437
+
438
+
439
+
440
+
441
+
442
+
443
+ function $e0bc45c44166a2ff$export$2e2bcd8739ae039(token) {
444
+ if (typeof token !== "string") return false;
445
+ try {
446
+ const result = (0, ($parcel$interopDefault($bU6Ve$jsonwebtoken))).decode(token, {
447
+ complete: true
448
+ });
449
+ if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(result);
450
+ return true;
451
+ } catch (err) {
452
+ return false;
417
453
  }
418
- return files;
419
454
  }
420
- // noinspection JSUnusedGlobalSymbols
421
- module.exports = {
422
- getDecryptedCookie: $af7abeb0794bd6fa$var$getChromeCookie,
423
- getChromeCookie: $af7abeb0794bd6fa$var$getChromeCookie,
424
- getFirefoxCookie: $af7abeb0794bd6fa$var$getFirefoxCookie,
425
- getCookie: $af7abeb0794bd6fa$var$getCookie,
426
- decrypt: $af7abeb0794bd6fa$var$decrypt
427
- };
455
+
456
+
457
+ async function $8dc1bcea169affbc$export$e6d428437cf2cacb({ name: name , domain: domain }, strategy = new (0, $b4be7ecb8cbd1374$export$2e2bcd8739ae039)()) {
458
+ const results = await strategy.queryCookies(name, domain);
459
+ const results1 = (0, $bU6Ve$lodash.uniq)(results).map((cookie)=>{
460
+ return {
461
+ name: name,
462
+ domain: domain,
463
+ value: cookie
464
+ };
465
+ });
466
+ const jwtCookies = [];
467
+ for (const result of results1){
468
+ const value = result.value;
469
+ if ((0, $e0bc45c44166a2ff$export$2e2bcd8739ae039)(value)) jwtCookies.push(result);
470
+ }
471
+ const results2 = (0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).REQUIRE_JWT ? jwtCookies : results1;
472
+ const resultsUniq = (0, $bU6Ve$lodash.uniq)(results2).map((cookie)=>cookie.value);
473
+ return (0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).SINGLE ? [
474
+ resultsUniq[0]
475
+ ] : resultsUniq;
476
+ }
477
+
478
+
479
+
480
+
481
+
482
+ async function $af7abeb0794bd6fa$export$4be65e66cfa2648a(params) {
483
+ const cookies = await (0, $8dc1bcea169affbc$export$e6d428437cf2cacb)(params, new (0, $b4be7ecb8cbd1374$export$2e2bcd8739ae039)());
484
+ if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
485
+ else throw new Error("Cookie not found");
486
+ }
487
+ async function $af7abeb0794bd6fa$export$c44c5fdef43f0941(params) {
488
+ const cookies = await (0, $8dc1bcea169affbc$export$e6d428437cf2cacb)(params, new (0, $d66ab4010a2fe667$export$2e2bcd8739ae039)());
489
+ if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
490
+ else throw new Error("Cookie not found");
491
+ }
492
+ async function $af7abeb0794bd6fa$export$e5637297e9eb6f2e(params) {
493
+ const cookies = await (0, $8dc1bcea169affbc$export$e6d428437cf2cacb)(params, new (0, $1c57ad353fa3519e$export$2e2bcd8739ae039)());
494
+ if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
495
+ else throw new Error("Cookie not found");
496
+ }
428
497
 
429
498
 
430
499
  //# sourceMappingURL=main.js.map