@mherod/get-cookie 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +24 -13
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -112,13 +112,16 @@ async function doSqliteQuery1(file, sql) {
|
|
|
112
112
|
}
|
|
113
113
|
const rows1 = rows;
|
|
114
114
|
if (rows1.length === 0) {
|
|
115
|
+
if (process.env.VERBOSE) {
|
|
116
|
+
console.log(`No rows found`);
|
|
117
|
+
}
|
|
115
118
|
resolve(null);
|
|
116
119
|
return;
|
|
117
120
|
}
|
|
118
121
|
if (Array.isArray(rows1)) {
|
|
119
122
|
// noinspection JSCheckFunctionSignatures
|
|
120
123
|
const [value] = rows1.flatMap(row => Object.values(row));
|
|
121
|
-
resolve(value);
|
|
124
|
+
resolve(Buffer.from(value));
|
|
122
125
|
return;
|
|
123
126
|
}
|
|
124
127
|
resolve(rows1);
|
|
@@ -161,10 +164,11 @@ async function doSqliteQuery(file, sql) {
|
|
|
161
164
|
*/
|
|
162
165
|
async function decrypt(password, encryptedData) {
|
|
163
166
|
if (typeof password !== 'string') {
|
|
164
|
-
throw new Error('password must be a string');
|
|
167
|
+
throw new Error('password must be a string: ' + password);
|
|
165
168
|
}
|
|
166
|
-
|
|
167
|
-
|
|
169
|
+
const encryptedData1 = encryptedData;
|
|
170
|
+
if (encryptedData1 == null || typeof encryptedData1 !== 'object') {
|
|
171
|
+
throw new Error('encryptedData must be a object: ' + encryptedData1);
|
|
168
172
|
}
|
|
169
173
|
if (process.env.VERBOSE) {
|
|
170
174
|
console.log(`Trying to decrypt with password ${password}`);
|
|
@@ -172,7 +176,6 @@ async function decrypt(password, encryptedData) {
|
|
|
172
176
|
return await new Promise((resolve, reject) => {
|
|
173
177
|
crypto.pbkdf2(password, 'saltysalt', 1003, 16, 'sha1', (error, buffer) => {
|
|
174
178
|
try {
|
|
175
|
-
|
|
176
179
|
if (error) {
|
|
177
180
|
if (process.env.VERBOSE) {
|
|
178
181
|
console.log("Error doing pbkdf2", error);
|
|
@@ -180,6 +183,7 @@ async function decrypt(password, encryptedData) {
|
|
|
180
183
|
reject(error);
|
|
181
184
|
return;
|
|
182
185
|
}
|
|
186
|
+
|
|
183
187
|
if (buffer.length !== 16) {
|
|
184
188
|
if (process.env.VERBOSE) {
|
|
185
189
|
console.log("Error doing pbkdf2, buffer length is not 16", buffer.length);
|
|
@@ -191,17 +195,20 @@ async function decrypt(password, encryptedData) {
|
|
|
191
195
|
const iv = new Buffer.from(new Array(17).join(' '), 'binary');
|
|
192
196
|
const decipher = crypto.createDecipheriv('aes-128-cbc', buffer, iv);
|
|
193
197
|
decipher.setAutoPadding(false);
|
|
194
|
-
encryptedData = encryptedData.slice(3);
|
|
195
198
|
|
|
196
|
-
if (
|
|
199
|
+
if (encryptedData1 && encryptedData1.slice) {
|
|
200
|
+
encryptedData = encryptedData1.slice(3);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (encryptedData1.length % 16 !== 0) {
|
|
197
204
|
if (process.env.VERBOSE) {
|
|
198
|
-
console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16",
|
|
205
|
+
console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16", encryptedData1.length);
|
|
199
206
|
}
|
|
200
207
|
reject(new Error('encryptedData length is not a multiple of 16'));
|
|
201
208
|
return;
|
|
202
209
|
}
|
|
203
210
|
|
|
204
|
-
let decoded = decipher.update(
|
|
211
|
+
let decoded = decipher.update(encryptedData1, 'binary', 'utf8');
|
|
205
212
|
// let decoded = decipher.update(encryptedData);
|
|
206
213
|
try {
|
|
207
214
|
decipher.final('utf-8');
|
|
@@ -240,8 +247,10 @@ async function getChromeCookie({name, domain}) {
|
|
|
240
247
|
if (domain && typeof domain !== 'string') {
|
|
241
248
|
throw new Error('domain must be a string');
|
|
242
249
|
}
|
|
243
|
-
const
|
|
244
|
-
const
|
|
250
|
+
const chromePasswordPromise = getChromePassword();
|
|
251
|
+
const encryptedChromeCookiePromise = getEncryptedChromeCookie(name, domain);
|
|
252
|
+
const password = await chromePasswordPromise;
|
|
253
|
+
const encryptedData = await encryptedChromeCookiePromise;
|
|
245
254
|
if (process.env.VERBOSE) {
|
|
246
255
|
console.log("Received encrypted", encryptedData);
|
|
247
256
|
}
|
|
@@ -249,7 +258,9 @@ async function getChromeCookie({name, domain}) {
|
|
|
249
258
|
try {
|
|
250
259
|
s = await decrypt(password, encryptedData);
|
|
251
260
|
} catch (e) {
|
|
252
|
-
|
|
261
|
+
if (process.env.VERBOSE) {
|
|
262
|
+
console.error("Error decrypting", e);
|
|
263
|
+
}
|
|
253
264
|
throw new Error('Failed to decrypt');
|
|
254
265
|
}
|
|
255
266
|
if (process.env.VERBOSE) {
|
|
@@ -303,7 +314,7 @@ module.exports = {
|
|
|
303
314
|
if (process.argv) {
|
|
304
315
|
if (process.argv.length > 2) {
|
|
305
316
|
const name = process.argv[2];
|
|
306
|
-
const domain = process.argv[3];
|
|
317
|
+
const domain = process.argv[3] ?? '%';
|
|
307
318
|
|
|
308
319
|
if (process.argv.includes('--verbose')) {
|
|
309
320
|
process.env.VERBOSE = "true";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mherod/get-cookie",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Node.js module for querying a local user's Chrome cookie",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": "index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
-
"installGlobal": "npm install --force --global ."
|
|
12
|
+
"installGlobal": "rm -rf /usr/local/bin/get-cookie ; npm install --force --global ."
|
|
13
13
|
},
|
|
14
14
|
"keywords": [],
|
|
15
15
|
"author": "Matthew Herod",
|