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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,32 +1,35 @@
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 $503d2a3d296fcf21$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
-
23
- var $c0cdc003fbf917f0$require$exec = $bU6Ve$child_process.exec;
24
28
 
25
- async function $c0cdc003fbf917f0$var$execSimple(command) {
26
- if (typeof command !== "string") throw new TypeError("execSimple: command must be a string");
29
+ async function $25b78d6746d4ad48$export$8d71c74f97c0202e(command) {
27
30
  if (process.env.VERBOSE) console.log(command);
28
31
  return new Promise((resolve, reject)=>{
29
- $c0cdc003fbf917f0$require$exec(command, {
32
+ (0, $bU6Ve$child_process.exec)(command, {
30
33
  encoding: "binary",
31
34
  maxBuffer: 5120
32
35
  }, (error, stdout, stderr)=>{
@@ -38,34 +41,11 @@ async function $c0cdc003fbf917f0$var$execSimple(command) {
38
41
  reject(error);
39
42
  return;
40
43
  }
41
- if (stdout) resolve(stdout.toString("utf8").trim());
44
+ if (stdout) resolve(stdout.trim());
42
45
  });
43
46
  });
44
47
  }
45
- async function $c0cdc003fbf917f0$var$execAsBuffer(command) {
46
- if (typeof command !== "string") throw new TypeError("execAsBuffer: command must be a string");
47
- if (process.env.VERBOSE) console.log(command);
48
- return await new Promise((resolve, reject)=>{
49
- $c0cdc003fbf917f0$require$exec(command, {
50
- encoding: "binary",
51
- maxBuffer: 5120
52
- }, (error, stdout, stderr)=>{
53
- if (error) {
54
- reject(error);
55
- return;
56
- }
57
- if (stderr) {
58
- reject(error);
59
- return;
60
- }
61
- let stdoutAsBuffer = stdout;
62
- if (typeof stdoutAsBuffer === "string" && stdoutAsBuffer.length > 0) // noinspection JSCheckFunctionSignatures
63
- stdoutAsBuffer = Buffer.from(stdoutAsBuffer, "binary").slice(0, -1);
64
- if (stdoutAsBuffer && stdoutAsBuffer.length > 0) resolve(stdoutAsBuffer);
65
- });
66
- });
67
- }
68
- function $c0cdc003fbf917f0$var$toStringValue(r) {
48
+ function $25b78d6746d4ad48$export$33d3adc27420eed5(r) {
69
49
  if (process.env.VERBOSE) console.log("Printing value", r);
70
50
  if (r) {
71
51
  if (typeof r === "string") return r;
@@ -73,7 +53,7 @@ function $c0cdc003fbf917f0$var$toStringValue(r) {
73
53
  return r.toString("utf8");
74
54
  }
75
55
  }
76
- function $c0cdc003fbf917f0$var$printStringValue(r) {
56
+ function $25b78d6746d4ad48$export$1ed1ce2ec2b4f5a3(r) {
77
57
  if (process.env.VERBOSE) console.log("Printing value", r);
78
58
  if (r) {
79
59
  if (typeof r === "string") console.log(r);
@@ -81,11 +61,7 @@ function $c0cdc003fbf917f0$var$printStringValue(r) {
81
61
  console.log(r.toString("utf8"));
82
62
  }
83
63
  }
84
- /**
85
- *
86
- * @param result
87
- * @returns {string|null}
88
- */ function $c0cdc003fbf917f0$var$toStringOrNull(result) {
64
+ function $25b78d6746d4ad48$export$d53bf2de587a369(result) {
89
65
  if (result == null) return null;
90
66
  if (process.env.VERBOSE) console.log("result", result);
91
67
  if (typeof result === "string" && result.length > 0) return result;
@@ -93,22 +69,85 @@ function $c0cdc003fbf917f0$var$printStringValue(r) {
93
69
  return result.toString("utf8");
94
70
  return null;
95
71
  }
72
+ function $25b78d6746d4ad48$export$99ce3e33a555daf1(input) {
73
+ return typeof input !== "string" || input.length === 0;
74
+ }
75
+ function $25b78d6746d4ad48$export$5348b46700dd771c(input) {
76
+ return typeof input == "string" && input.length > 0;
77
+ }
96
78
 
97
- /**
98
- *
99
- * @param {string} file
100
- * @param {string} sql
101
- * @returns {Promise<Buffer[]>}
102
- */ async function $c0cdc003fbf917f0$var$doSqliteQuery1(file, sql) {
103
- if (typeof sql !== "string") throw new TypeError("doSqliteQuery1: sql must be a string");
104
- 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`);
106
- if (process.env.VERBOSE) {
107
- console.log(`doSqliteQuery1: file ${file}`);
108
- console.log(`doSqliteQuery1: sql ${sql}`);
79
+
80
+
81
+ var $fac425c10fbbada5$require$merge = $bU6Ve$lodash.merge;
82
+ const $fac425c10fbbada5$export$a7b6bc01c63cdfc3 = {};
83
+ $fac425c10fbbada5$require$merge($fac425c10fbbada5$export$a7b6bc01c63cdfc3, process.env);
84
+ const $fac425c10fbbada5$export$a7c5707626fc90f = $fac425c10fbbada5$export$a7b6bc01c63cdfc3["HOME"];
85
+ if (!$fac425c10fbbada5$export$a7c5707626fc90f) throw new Error("HOME environment variable is not set");
86
+
87
+
88
+
89
+
90
+
91
+ async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: name , maxDepth: maxDepth = 2 }) {
92
+ if (typeof path !== "string") throw new Error("path must be a string");
93
+ if (typeof name !== "string") throw new Error("name must be a string");
94
+ const rootSegments = path.split("/").length;
95
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Searching for ${name} in ${path}`);
96
+ const files = [];
97
+ let readdirSync;
98
+ try {
99
+ readdirSync = $bU6Ve$fs.readdirSync(path);
100
+ } catch (e) {
101
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Error reading ${path}`, e);
102
+ return [];
109
103
  }
110
- const sqlite3 = $bU6Ve$sqlite3;
111
- const db = new sqlite3.Database(file);
104
+ for (const file of readdirSync){
105
+ const filePath = path + "/" + file;
106
+ let stat;
107
+ try {
108
+ stat = $bU6Ve$fs.statSync(filePath);
109
+ } catch (e1) {
110
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.error(`Error getting stat for ${filePath}`, e1);
111
+ continue;
112
+ }
113
+ if (stat.isDirectory()) {
114
+ if (filePath.split("/").length < rootSegments + maxDepth) try {
115
+ const subFiles = await $e62c2c56eb720f29$export$2c9faf86071156ae({
116
+ path: filePath,
117
+ name: name,
118
+ maxDepth: 2
119
+ });
120
+ files.push(...subFiles);
121
+ } catch (e2) {
122
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.error(e2);
123
+ }
124
+ } else if (file === name) files.push(filePath);
125
+ }
126
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) {
127
+ if (files.length > 0) {
128
+ console.log(`Found ${files.length} ${name} files`);
129
+ console.log(files);
130
+ }
131
+ }
132
+ return files;
133
+ }
134
+
135
+
136
+
137
+
138
+ function $3d7e27b54f670f46$export$bc926c43858bd3cb(obj) {
139
+ return obj.domain !== undefined && obj.name !== undefined && obj.value !== undefined;
140
+ }
141
+ function $3d7e27b54f670f46$export$963c8d651337e4a4(obj) {
142
+ return obj.domain !== undefined && obj.name !== undefined && obj.value !== undefined;
143
+ }
144
+
145
+
146
+
147
+
148
+ async function $a085b524d8ee9fce$export$f19f611d1fa7c6f3(file, sql) {
149
+ if (!$bU6Ve$fs.existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
150
+ const db = new $bU6Ve$sqlite3.Database(file);
112
151
  return new Promise((resolve, reject)=>{
113
152
  db.all(sql, (err, rows)=>{
114
153
  if (err) {
@@ -123,11 +162,17 @@ function $c0cdc003fbf917f0$var$printStringValue(r) {
123
162
  return;
124
163
  }
125
164
  if (Array.isArray(rows1)) {
126
- if (process.env.VERBOSE) console.log(`doSqliteQuery1: ${rows1.length} rows`);
127
- // noinspection JSCheckFunctionSignatures
128
- const buffers = rows1.flatMap((row)=>Object.values(row)).map((v)=>Buffer.from(v, "binary"));
129
- if (process.env.VERBOSE) console.log(`doSqliteQuery1: ${buffers.length} buffers`);
130
- resolve(buffers);
165
+ const cookieRows = rows1.map((row)=>{
166
+ return {
167
+ domain: row["host_key"],
168
+ name: row["name"],
169
+ value: row["encrypted_value"],
170
+ meta: {
171
+ file: file
172
+ }
173
+ };
174
+ });
175
+ resolve(cookieRows);
131
176
  return;
132
177
  }
133
178
  if (process.env.VERBOSE) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
@@ -137,124 +182,101 @@ function $c0cdc003fbf917f0$var$printStringValue(r) {
137
182
  });
138
183
  });
139
184
  }
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;
157
- try {
158
- const result = $bU6Ve$jsonwebtoken.decode(token, {
159
- complete: true
185
+
186
+
187
+
188
+ class $269fe42bfd555305$export$2e2bcd8739ae039 extends (0, $503d2a3d296fcf21$export$2e2bcd8739ae039) {
189
+ async queryCookies(name, domain) {
190
+ if (process.platform !== "darwin") throw new Error("This only works on macOS");
191
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).FIREFOX_ONLY) return [];
192
+ return $269fe42bfd555305$var$getChromeCookies({
193
+ requireJwt: false,
194
+ name: name,
195
+ domain: domain
160
196
  });
161
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(result);
162
- return true;
163
- } catch (err) {
164
- return false;
165
197
  }
166
198
  }
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);
184
- });
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);
199
+ async function $269fe42bfd555305$var$getPromise1(name, domain, file) {
200
+ try {
201
+ return await $269fe42bfd555305$var$getEncryptedChromeCookie({
202
+ name: name,
203
+ domain: domain,
204
+ file: file
192
205
  });
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);
206
+ } catch (e) {
207
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error getting encrypted cookie", e);
208
+ return [];
209
+ }
210
+ }
211
+ async function $269fe42bfd555305$var$getPromise(name, domain) {
212
+ try {
213
+ const files = await (0, $e62c2c56eb720f29$export$2c9faf86071156ae)({
214
+ path: $269fe42bfd555305$var$chromeLocal,
215
+ name: "Cookies"
199
216
  });
200
- }).catch((e)=>{
201
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error("Error getting Chrome or Firefox cookie", e);
202
- }).then($af7abeb0794bd6fa$require$toStringValue);
217
+ const promises = files.map((file)=>$269fe42bfd555305$var$getPromise1(name, domain, file));
218
+ const results1 = await Promise.all(promises);
219
+ return results1.flat().filter((0, $3d7e27b54f670f46$export$bc926c43858bd3cb));
220
+ } catch (error) {
221
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("error", error);
222
+ return [];
223
+ }
203
224
  }
204
- /**
205
- *
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 `;
225
- }
226
- if (typeof domain === "string") sql += `host LIKE '${domain}';`;
225
+ async function $269fe42bfd555305$var$decryptValue(password, encryptedValue) {
226
+ let d;
227
+ try {
228
+ d = await $269fe42bfd555305$var$decrypt(password, encryptedValue);
229
+ } catch (e) {
230
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error decrypting cookie", e);
231
+ d = null;
227
232
  }
228
- return await $af7abeb0794bd6fa$require$doSqliteQuery1(file, sql).then((rows)=>{
229
- return rows.map($af7abeb0794bd6fa$require$toStringOrNull).find((v)=>v !== null);
233
+ return d ?? encryptedValue.toString("utf-8");
234
+ }
235
+ async function $269fe42bfd555305$var$getChromeCookies({ name: name , domain: domain = "%" , requireJwt: requireJwt = false }) {
236
+ const encryptedDataItems = await $269fe42bfd555305$var$getPromise(name, domain);
237
+ const password = await $269fe42bfd555305$var$getChromePassword();
238
+ const decrypted = encryptedDataItems.filter(({ value: value })=>value != null && value.length > 0).map(async (cookieRow)=>{
239
+ const encryptedValue = cookieRow.value;
240
+ const decryptedValue = await $269fe42bfd555305$var$decryptValue(password, encryptedValue);
241
+ const meta = {};
242
+ (0, $bU6Ve$lodash.merge)(meta, cookieRow.meta ?? {});
243
+ return {
244
+ domain: cookieRow.domain,
245
+ name: cookieRow.name,
246
+ value: decryptedValue,
247
+ meta: meta
248
+ };
230
249
  });
250
+ const results = (await Promise.all(decrypted)).filter((0, $3d7e27b54f670f46$export$963c8d651337e4a4));
251
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("results", results);
252
+ return results;
231
253
  }
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 , }) {
235
- if (name && typeof name !== "string") throw new Error("name must be a string");
236
- if (domain && typeof domain !== "string") throw new Error("domain must be a string");
237
- 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}`);
254
+ const $269fe42bfd555305$var$chromeLocal = $bU6Ve$path.join((0, $fac425c10fbbada5$export$a7c5707626fc90f), "Library", "Application Support", "Google", "Chrome");
255
+ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , domain: domain , file: file = $bU6Ve$path.join($269fe42bfd555305$var$chromeLocal, "Default", "Cookies") }) {
256
+ if (!(0, $bU6Ve$fs.existsSync)(file)) throw new Error(`File ${file} does not exist`);
257
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) {
258
+ const s = file.split("/").slice(-3).join("/");
259
+ console.log(`Trying Chrome (at ${s}) cookie ${name} for domain ${domain}`);
260
+ }
240
261
  let sql;
241
- sql = `SELECT encrypted_value FROM cookies`;
242
- if (typeof name === "string" || typeof domain === "string") {
262
+ sql = `SELECT encrypted_value, name, host_key FROM cookies`;
263
+ const wildcardRegexp = /^([*%])$/i;
264
+ const specifiedName = name.match(wildcardRegexp) == null;
265
+ const specifiedDomain = domain.match(wildcardRegexp) == null;
266
+ if (specifiedName || specifiedDomain) {
243
267
  sql += ` WHERE `;
244
- if (typeof name === "string") {
268
+ if (specifiedName) {
245
269
  sql += `name = '${name}'`;
246
- if (typeof domain === "string") sql += ` AND `;
270
+ if (specifiedDomain) sql += ` AND `;
247
271
  }
248
- if (typeof domain === "string") sql += `host_key LIKE '${domain}';`;
272
+ if (specifiedDomain) sql += `host_key LIKE '${domain}';`;
249
273
  }
250
- return await $af7abeb0794bd6fa$require$doSqliteQuery1(file, sql);
274
+ return (0, $a085b524d8ee9fce$export$f19f611d1fa7c6f3)(file, sql);
275
+ }
276
+ async function $269fe42bfd555305$var$getChromePassword() {
277
+ return (0, $25b78d6746d4ad48$export$8d71c74f97c0202e)('security find-generic-password -w -s "Chrome Safe Storage"');
251
278
  }
252
- /**
253
- *
254
- * @param {string} password
255
- * @param {Buffer} encryptedData
256
- * @returns {Promise<string>}
257
- */ async function $af7abeb0794bd6fa$var$decrypt(password, encryptedData) {
279
+ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
258
280
  if (typeof password !== "string") throw new Error("password must be a string: " + password);
259
281
  let encryptedData1;
260
282
  encryptedData1 = encryptedData;
@@ -262,30 +284,31 @@ async function $af7abeb0794bd6fa$var$getEncryptedChromeCookie({ name: name , dom
262
284
  if (!(encryptedData1 instanceof Buffer)) {
263
285
  if (Array.isArray(encryptedData1) && encryptedData1[0] instanceof Buffer) {
264
286
  [encryptedData1] = encryptedData1;
265
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`encryptedData is an array of buffers, selected first: ${encryptedData1}`);
287
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`encryptedData is an array of buffers, selected first: ${encryptedData1}`);
266
288
  } else throw new Error("encryptedData must be a Buffer: " + encryptedData1);
267
289
  encryptedData1 = Buffer.from(encryptedData1);
268
290
  }
269
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying to decrypt with password ${password}`);
291
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying to decrypt with password ${password}`);
270
292
  return new Promise((resolve, reject)=>{
271
- (0, ($parcel$interopDefault($bU6Ve$crypto))).pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer)=>{
293
+ $bU6Ve$crypto.pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer)=>{
272
294
  try {
273
295
  if (error) {
274
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2", error);
296
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2", error);
275
297
  reject(error);
276
298
  return;
277
299
  }
278
300
  if (buffer.length !== 16) {
279
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, buffer length is not 16", buffer.length);
301
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, buffer length is not 16", buffer.length);
280
302
  reject(new Error("Buffer length is not 16"));
281
303
  return;
282
304
  }
283
- const iv = new Buffer.from(new Array(17).join(" "), "binary");
284
- const decipher = (0, ($parcel$interopDefault($bU6Ve$crypto))).createDecipheriv("aes-128-cbc", buffer, iv);
305
+ const str = new Array(17).join(" ");
306
+ const iv = Buffer.from(str, "binary");
307
+ const decipher = $bU6Ve$crypto.createDecipheriv("aes-128-cbc", buffer, iv);
285
308
  decipher.setAutoPadding(false);
286
309
  if (encryptedData1 && encryptedData1.slice) encryptedData1 = encryptedData1.slice(3);
287
310
  if (encryptedData1.length % 16 !== 0) {
288
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16", encryptedData1.length);
311
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16", encryptedData1.length);
289
312
  reject(new Error("encryptedData length is not a multiple of 16"));
290
313
  return;
291
314
  }
@@ -293,138 +316,162 @@ async function $af7abeb0794bd6fa$var$getEncryptedChromeCookie({ name: name , dom
293
316
  try {
294
317
  decipher.final("utf-8");
295
318
  } catch (e) {
296
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing decipher.final()", e);
319
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing decipher.final()", e);
297
320
  reject(e);
298
321
  return;
299
322
  }
300
- let padding = decoded[decoded.length - 1];
323
+ const padding = decoded[decoded.length - 1];
301
324
  if (padding) decoded = decoded.slice(0, 0 - padding);
302
325
  // noinspection JSCheckFunctionSignatures
303
- decoded = decoded.toString("utf8");
304
- resolve(decoded);
326
+ const decodedString = decoded.toString("utf8");
327
+ resolve(decodedString);
305
328
  } catch (e1) {
306
329
  reject(e1);
307
330
  }
308
331
  });
309
332
  });
310
333
  }
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
- });
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+ class $7bb7da9a77b2fd99$export$2e2bcd8739ae039 extends (0, $503d2a3d296fcf21$export$2e2bcd8739ae039) {
344
+ async queryCookies(name, domain) {
345
+ if (process.platform !== "darwin") throw new Error("This only works on macOS");
346
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).CHROME_ONLY) return [];
347
+ const cookies = await this.#getFirefoxCookie({
348
+ name: name,
349
+ domain: domain
333
350
  });
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
- });
351
+ return Array.isArray(cookies) ? cookies.map((0, $25b78d6746d4ad48$export$d53bf2de587a369)) : [];
352
+ }
353
+ /**
354
+ *
355
+ * @param name
356
+ * @param domain
357
+ * @returns {Promise<Buffer>}
358
+ */ async #getFirefoxCookie(//
359
+ { name: name , domain: domain }) {
360
+ const files = await (0, $e62c2c56eb720f29$export$2c9faf86071156ae)({
361
+ path: $bU6Ve$path.join((0, $fac425c10fbbada5$export$a7c5707626fc90f), "Library", "Application Support", "Firefox", "Profiles"),
362
+ name: "cookies.sqlite"
339
363
  });
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;
364
+ const all = await Promise.all(files.map((file)=>{
365
+ return this.#queryCookiesDb(file, name, domain);
366
+ }));
367
+ return all.flat();
368
+ }
369
+ #queryCookiesDb(file, name1, domain1) {
370
+ if (file && !(0, $bU6Ve$fs.existsSync)(file)) throw new Error(`File ${file} does not exist`);
371
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying Firefox cookie ${name1} for domain ${domain1}`);
372
+ let sql;
373
+ //language=SQL
374
+ sql = "SELECT value FROM moz_cookies";
375
+ if (typeof name1 === "string" || typeof domain1 === "string") {
376
+ sql += ` WHERE `;
377
+ if (typeof name1 === "string") {
378
+ sql += `name = '${name1}'`;
379
+ if (typeof domain1 === "string") sql += ` AND `;
380
+ }
381
+ if (typeof domain1 === "string") sql += `host LIKE '${domain1}';`;
360
382
  }
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
- });
383
+ return (0, $a085b524d8ee9fce$export$f19f611d1fa7c6f3)(file, sql).then((rows)=>{
384
+ return rows.map((row)=>{
385
+ return {
386
+ domain: row.domain,
387
+ name: row.name,
388
+ value: row.value.toString("utf8")
389
+ };
390
+ });
391
+ }).catch(()=>[]);
392
+ }
368
393
  }
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;
394
+
395
+
396
+
397
+ class $fad6f51bd5c7bae2$export$2e2bcd8739ae039 extends (0, $503d2a3d296fcf21$export$2e2bcd8739ae039) {
398
+ }
399
+
400
+
401
+
402
+ class $f72befa528c23ca7$export$2e2bcd8739ae039 extends (0, $503d2a3d296fcf21$export$2e2bcd8739ae039) {
403
+ #strategies;
404
+ constructor(){
405
+ super();
406
+ this.#strategies = [
407
+ (0, $269fe42bfd555305$export$2e2bcd8739ae039),
408
+ (0, $7bb7da9a77b2fd99$export$2e2bcd8739ae039),
409
+ (0, $fad6f51bd5c7bae2$export$2e2bcd8739ae039),
410
+ ].map((strategy)=>{
411
+ return new strategy();
412
+ });
388
413
  }
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);
414
+ async queryCookies(name, domain) {
415
+ const results = await Promise.all(this.#strategies.map(async (strategy)=>{
416
+ // @ts-ignore
417
+ const cookies = strategy.queryCookies(name, domain);
418
+ return cookies.catch(()=>[]);
419
+ }));
420
+ return results.flat();
411
421
  }
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
- }
422
+ }
423
+
424
+
425
+
426
+
427
+
428
+
429
+ function $9a6b2ace073cf1d7$export$2e2bcd8739ae039(token) {
430
+ try {
431
+ const result = (0, ($parcel$interopDefault($bU6Ve$jsonwebtoken))).decode(token, {
432
+ complete: true
433
+ });
434
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(result);
435
+ return true;
436
+ } catch (err) {
437
+ return false;
417
438
  }
418
- return files;
419
439
  }
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
- };
440
+
441
+
442
+ async function $7a068a32d4710f0b$export$e6d428437cf2cacb({ name: name , domain: domain }, strategy = new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)()) {
443
+ const results = await strategy.queryCookies(name, domain);
444
+ const results1 = (0, $bU6Ve$lodash.uniqBy)(results, JSON.stringify);
445
+ const jwtCookies = [];
446
+ for (const result of results1){
447
+ const value = result.value;
448
+ if ((0, $9a6b2ace073cf1d7$export$2e2bcd8739ae039)(value)) jwtCookies.push(result);
449
+ }
450
+ const resultsUniq = (0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).REQUIRE_JWT ? jwtCookies : results1;
451
+ return (0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).SINGLE ? [
452
+ resultsUniq[0]
453
+ ] : resultsUniq;
454
+ }
455
+
456
+
457
+
458
+
459
+
460
+ async function $af7abeb0794bd6fa$export$4be65e66cfa2648a(params) {
461
+ const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(params, new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)());
462
+ if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
463
+ else throw new Error("Cookie not found");
464
+ }
465
+ async function $af7abeb0794bd6fa$export$c44c5fdef43f0941(params) {
466
+ const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(params, new (0, $7bb7da9a77b2fd99$export$2e2bcd8739ae039)());
467
+ if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
468
+ else throw new Error("Cookie not found");
469
+ }
470
+ async function $af7abeb0794bd6fa$export$e5637297e9eb6f2e(params) {
471
+ const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(params, new (0, $269fe42bfd555305$export$2e2bcd8739ae039)());
472
+ if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
473
+ else throw new Error("Cookie not found");
474
+ }
428
475
 
429
476
 
430
477
  //# sourceMappingURL=main.js.map