@mherod/get-cookie 1.0.3 → 1.0.6

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 (2) hide show
  1. package/index.js +46 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env node
2
+
1
3
  const crypto = require('crypto');
2
4
  const {exec} = require("child_process");
3
5
  const fs = require("fs");
@@ -27,6 +29,10 @@ async function getChromePassword() {
27
29
  });
28
30
  }
29
31
 
32
+ async function getCookie() {
33
+ throw new Error('Not implemented');
34
+ }
35
+
30
36
  /**
31
37
  *
32
38
  * @param name
@@ -40,7 +46,7 @@ async function getFirefoxCookie({name, domain}) {
40
46
  if (domain && typeof domain !== 'string') {
41
47
  throw new Error('domain must be a string');
42
48
  }
43
- const file = await findFile(`${process.env.HOME}/Library/Application Support/Firefox/Profiles/`, "cookies.sqlite")
49
+ const file = await findFile(`${process.env.HOME}/Library/Application Support/Firefox/Profiles`, "cookies.sqlite")
44
50
  if (!fs.existsSync(file)) {
45
51
  throw new Error(`File ${file} does not exist`);
46
52
  }
@@ -49,7 +55,7 @@ async function getFirefoxCookie({name, domain}) {
49
55
  }
50
56
  return await new Promise((resolve, reject) => {
51
57
  let sql;
52
- sql = `SELECT value FROM moz_cookies`;
58
+ sql = "SELECT value FROM moz_cookies";
53
59
  if (typeof name === 'string' || typeof domain === 'string') {
54
60
  sql += ` WHERE `;
55
61
  if (typeof name === 'string') {
@@ -66,7 +72,7 @@ async function getFirefoxCookie({name, domain}) {
66
72
  if (process.env.VERBOSE) {
67
73
  console.log(command);
68
74
  }
69
- exec(command, {encoding: 'binary', maxBuffer: 1024}, (error, stdout, stderr) => {
75
+ exec(command, {encoding: 'binary', maxBuffer: 5 * 1024}, (error, stdout, stderr) => {
70
76
  if (error) {
71
77
  reject(error);
72
78
  return;
@@ -121,7 +127,7 @@ async function getEncryptedChromeCookie(name, domain) {
121
127
  if (process.env.VERBOSE) {
122
128
  console.log(command);
123
129
  }
124
- exec(command, {encoding: 'binary', maxBuffer: 1024}, (error, stdout, stderr) => {
130
+ exec(command, {encoding: 'binary', maxBuffer: 5 * 1024}, (error, stdout, stderr) => {
125
131
  if (error) {
126
132
  reject(error);
127
133
  return;
@@ -180,6 +186,14 @@ async function decrypt(password, encryptedData) {
180
186
  decipher.setAutoPadding(false);
181
187
  encryptedData = encryptedData.slice(3);
182
188
 
189
+ if (encryptedData.length % 16 !== 0) {
190
+ if (process.env.VERBOSE) {
191
+ console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16", encryptedData.length);
192
+ }
193
+ reject(new Error('encryptedData length is not a multiple of 16'));
194
+ return;
195
+ }
196
+
183
197
  let decoded = decipher.update(encryptedData, 'binary', 'utf8');
184
198
  // let decoded = decipher.update(encryptedData);
185
199
  try {
@@ -258,18 +272,22 @@ function printStringValue(r) {
258
272
  if (process.env.VERBOSE) {
259
273
  console.log("Printing value", r);
260
274
  }
261
- if (typeof r === 'string') {
262
- console.log(r);
263
- } else {
264
- // noinspection JSCheckFunctionSignatures
265
- console.log(r.toString('utf8'));
275
+ if (r) {
276
+ if (typeof r === 'string') {
277
+ console.log(r);
278
+ } else if (r.toString) {
279
+ // noinspection JSCheckFunctionSignatures
280
+ console.log(r.toString('utf8'));
281
+ }
266
282
  }
267
283
  }
268
284
 
269
285
  // noinspection JSUnusedGlobalSymbols
270
286
  module.exports = {
271
287
  getDecryptedCookie: getChromeCookie,
272
- getChromeCookie
288
+ getChromeCookie,
289
+ getFirefoxCookie,
290
+ getCookie
273
291
  };
274
292
 
275
293
  if (process.argv) {
@@ -290,12 +308,22 @@ if (process.argv) {
290
308
  process.env.IGNORE_EXPIRED = "true";
291
309
  }
292
310
 
311
+ if (process.env.VERBOSE) {
312
+ console.log("Verbose mode", process.argv);
313
+ }
314
+
293
315
  if (process.env.CHROME_ONLY) {
294
316
  if (process.env.VERBOSE) {
295
317
  console.log('chrome only');
296
318
  }
297
319
  getChromeCookie({name, domain})
298
- .then(printStringValue)
320
+ .then(cookie => {
321
+ if (cookie && cookie.length > 0) {
322
+ printStringValue(cookie);
323
+ } else {
324
+ console.log('No cookie found');
325
+ }
326
+ })
299
327
  .catch(err => {
300
328
  if (process.env.VERBOSE) {
301
329
  console.error(err);
@@ -306,7 +334,13 @@ if (process.argv) {
306
334
  console.log('firefox only');
307
335
  }
308
336
  getFirefoxCookie({name, domain})
309
- .then(printStringValue)
337
+ .then(cookie => {
338
+ if (cookie && cookie.length > 0) {
339
+ printStringValue(cookie);
340
+ } else {
341
+ console.log('No cookie found');
342
+ }
343
+ })
310
344
  .catch(err => {
311
345
  if (process.env.VERBOSE) {
312
346
  console.error("Error getting Firefox cookie", err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mherod/get-cookie",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "Node.js module for querying a local user's Chrome cookie",
5
5
  "main": "index.js",
6
6
  "bin": "index.js",