@mherod/get-cookie 1.2.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/.idea/prettier.xml +8 -0
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -0
- package/dist/main.js +499 -0
- package/dist/main.js.map +1 -0
- package/package.json +38 -5
- package/src/browsers/AbstractCookieQueryStrategy.js +8 -0
- package/src/browsers/ChromeCookieQueryStrategy.js +263 -0
- package/src/browsers/CompositeCookieQueryStrategy.js +28 -0
- package/src/browsers/FirefoxCookieQueryStrategy.js +77 -0
- package/src/browsers/SafariCookieQueryStrategy.js +3 -0
- package/src/cli.js +70 -0
- package/src/findAllFiles.js +73 -0
- package/src/global.js +7 -0
- package/src/index.js +61 -0
- package/src/isValidJwt.js +17 -0
- package/src/queryCookies.js +28 -0
- package/src/utils.js +181 -0
- package/cli.js +0 -48
- package/index.js +0 -424
- package/utils.js +0 -175
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="PrettierConfiguration">
|
|
4
|
+
<option name="myRunOnSave" value="true" />
|
|
5
|
+
<option name="myRunOnReformat" value="true" />
|
|
6
|
+
<option name="myFilesPattern" value="src/{**/*,*}.{js,json}" />
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var e=require("lodash"),r=require("fs"),n=require("crypto"),o=require("path"),t=require("child_process"),i=require("sqlite3"),s=require("jsonwebtoken");function l(e,r,n,o){Object.defineProperty(e,r,{get:n,set:o,enumerable:!0,configurable:!0})}function a(e){return e&&e.__esModule?e.default:e}var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},u={},f={},g=c.parcelRequire5c26;null==g&&((g=function(e){if(e in u)return u[e].exports;if(e in f){var r=f[e];delete f[e];var n={id:e,exports:{}};return u[e]=n,r.call(n.exports,n,n.exports),n.exports}var o=new Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}).register=function(e,r){f[e]=r},c.parcelRequire5c26=g),g.register("1rMxC",(function(e,r){var n=g("9MSW1"),o=g("lITtf"),t=g("hZLs7");const i=process.argv;if(i&&i.length>2){if(i.includes("--version")||i.includes("-v"))return void console.log(n.version);const e=i[2];let r;r=null!=i[3]&&i[3].indexOf(".")>-1?i[3]:"%";const s="true";i.includes("--require-jwt")&&(o.env.REQUIRE_JWT=s),i.includes("--verbose")&&(o.env.VERBOSE=s),i.includes("--chrome-only")&&(o.env.CHROME_ONLY=s),i.includes("--firefox-only")&&(o.env.FIREFOX_ONLY=s),i.includes("--ignore-expired")&&(o.env.IGNORE_EXPIRED=s),i.includes("--single")&&(o.env.SINGLE=s),o.env.VERBOSE&&console.log("Verbose mode",i),async function(e,r){try{const n=await(0,t.queryCookies)({name:e,domain:r});if(n.length>0)for(const e of n)console.log(e);else console.error("No results")}catch(e){console.error(e)}}(e,r).then((()=>{})).catch(console.error)}})),g.register("9MSW1",(function(e,r){e.exports=JSON.parse('{"name":"@mherod/get-cookie","version":"2.0.0-beta.1","description":"Node.js module for querying a local user\'s Chrome cookie","source":"src/index.js","bin":"dist/cli.js","main":"dist/main.js","module":"dist/module.js","publishConfig":{"access":"public"},"scripts":{"clean":"git clean -fXd","build":"parcel build","test":"jest","postbuild":"npm run install:global","prepublish":"npm run build","install:global":"npm install --force --global .","postinstall:global":"find $NVM_BIN -exec chmod +x {} \\\\; || true","prettier":"prettier --write \'src/{**/*,*}.{js,json}\'"},"targets":{"main":{"source":"src/index.js","distDir":"dist","engines":{"node":"16"}},"cli":{"source":"src/cli.js","distDir":"dist","engines":{"node":"16"}}},"@parcel/transformer-js":{"inlineFS":false,"inlineEnvironment":false},"engines":{"node":"16"},"keywords":[],"author":"Matthew Herod","license":"ISC","dependencies":{"jsonwebtoken":"^8.5.1","lodash":"^4.17.21","sqlite3":"^5.0.8"},"devDependencies":{"jest":"^28.1.0","prettier":"^2.7.1"}}')})),g.register("lITtf",(function(r,n){l(r.exports,"env",(()=>t)),l(r.exports,"HOME",(()=>i));var o=e.merge;const t={};o(t,process.env);const i=t.HOME;if(!i)throw new Error("HOME environment variable is not set")})),g.register("hZLs7",(function(r,n){l(r.exports,"queryCookies",(()=>s));var o=g("2LoRB"),t=g("lITtf"),i=g("3K0UF");async function s({name:r,domain:n},s=new(0,o.default)){const l=await s.queryCookies(r,n),a=(0,e.uniq)(l).map((e=>({name:r,domain:n,value:e}))),c=[];for(const e of a){const r=e.value;(0,i.default)(r)&&c.push(e)}const u=t.env.REQUIRE_JWT?c:a,f=(0,e.uniq)(u).map((e=>e.value));return t.env.SINGLE?[f[0]]:f}})),g.register("2LoRB",(function(e,r){l(e.exports,"default",(()=>s));var n=g("eM6gm"),o=g("4nk4i"),t=g("9icZo"),i=g("4ayVE");class s extends i.default{#e;constructor(){super(),this.#e=[n.default,o.default,t.default].map((e=>new e))}async queryCookies(e,r){return(await Promise.all(this.#e.map((async n=>n.queryCookies(e,r).catch((()=>[])))))).flat()}}})),g.register("eM6gm",(function(e,t){l(e.exports,"default",(()=>f));var i=g("4ayVE"),s=g("7c49e"),c=g("lITtf"),u=g("ecbtg");class f extends i.default{async queryCookies(e,t){if("darwin"!==process.platform)throw new Error("This only works on macOS");if(c.env.FIREFOX_ONLY)return[];const i=await async function({name:e,domain:t="%",requireJwt:i=!1}){if((0,s.invalidString)(e))throw new Error("name must be a string");if((0,s.invalidString)(t))throw new Error("domain must be a string");const l=await async function(e,n){try{const t=(await(0,u.findAllFiles)({path:d,name:"Cookies"})).map((t=>async function(e,n,t){try{return await async function({name:e,domain:n,file:t=o.join(d,"Default","Cookies")}){if(e&&"string"!=typeof e)throw new Error("name must be a string");if(n&&"string"!=typeof n)throw new Error("domain must be a string");if(t&&"string"!=typeof t)throw new Error("file must be a string");if(!(0,r.existsSync)(t))throw new Error(`File ${t} does not exist`);if(c.env.VERBOSE){const r=t.split("/").slice(-3).join("/");console.log(`Trying Chrome (at ${r}) cookie ${e} for domain ${n}`)}let i;i="SELECT encrypted_value FROM cookies",("string"==typeof e||"string"==typeof n)&&(i+=" WHERE ","string"==typeof e&&(i+=`name = '${e}'`,"string"==typeof n&&(i+=" AND ")),"string"==typeof n&&(i+=`host_key LIKE '${n}';`));return(0,s.doSqliteQuery1)(t,i)}({name:e,domain:n,file:t})}catch(e){return c.env.VERBOSE&&console.log("Error getting encrypted cookie",e),[]}}(e,n,t))),i=(await Promise.all(t)).flat();return c.env.VERBOSE&&console.log("getEncryptedChromeCookie results",i),i.filter((e=>e))}catch(e){return c.env.VERBOSE&&console.log("error",e),[]}}(e,t),f=await async function(){return(0,s.execSimple)('security find-generic-password -w -s "Chrome Safe Storage"')}(),g=l.filter((e=>null!=e&&e.length>0)).map((async e=>{let r;c.env.VERBOSE&&console.log("Received encrypted",e);try{r=await async function(e,r){if("string"!=typeof e)throw new Error("password must be a string: "+e);let o;if(o=r,null==o||"object"!=typeof o)throw new Error("encryptedData must be a object: "+o);if(!(o instanceof Buffer)){if(!(Array.isArray(o)&&o[0]instanceof Buffer))throw new Error("encryptedData must be a Buffer: "+o);[o]=o,c.env.VERBOSE&&console.log(`encryptedData is an array of buffers, selected first: ${o}`),o=Buffer.from(o)}c.env.VERBOSE&&console.log(`Trying to decrypt with password ${e}`);return new Promise(((r,t)=>{a(n).pbkdf2(e,"saltysalt",1003,16,"sha1",((e,i)=>{try{if(e)return c.env.VERBOSE&&console.log("Error doing pbkdf2",e),void t(e);if(16!==i.length)return c.env.VERBOSE&&console.log("Error doing pbkdf2, buffer length is not 16",i.length),void t(new Error("Buffer length is not 16"));const s=new Buffer.from(new Array(17).join(" "),"binary"),l=a(n).createDecipheriv("aes-128-cbc",i,s);if(l.setAutoPadding(!1),o&&o.slice&&(o=o.slice(3)),o.length%16!=0)return c.env.VERBOSE&&console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16",o.length),void t(new Error("encryptedData length is not a multiple of 16"));let u=l.update(o);try{l.final("utf-8")}catch(e){return c.env.VERBOSE&&console.log("Error doing decipher.final()",e),void t(e)}const f=u[u.length-1];f&&(u=u.slice(0,0-f)),u=u.toString("utf8"),r(u)}catch(e){t(e)}}))}))}(f,e)}catch(e){return c.env.VERBOSE&&console.log("Error decrypting cookie",e),null}return r?(c.env.VERBOSE&&console.log("Decrypted",r),r):null})),p=await Promise.all(g);c.env.VERBOSE&&console.log("results",p);return p.map(s.toStringOrNull)}({name:e,domain:t});return i.map(s.toStringValue)}}const d=o.join(c.HOME,"Library","Application Support","Google","Chrome")})),g.register("4ayVE",(function(e,r){l(e.exports,"default",(()=>n));class n{async queryCookies(e,r){return"development"===process.env.NODE_ENV&&console.log("queryCookie",e,r),[]}}})),g.register("7c49e",(function(e,n){async function o(e){if("string"!=typeof e)throw new TypeError("execSimple: command must be a string");return process.env.VERBOSE&&console.log(e),new Promise(((r,n)=>{(0,t.exec)(e,{encoding:"binary",maxBuffer:5120},((e,o,t)=>{e||t?n(e):o&&r(o.toString("utf8").trim())}))}))}function s(e){if(process.env.VERBOSE&&console.log("Printing value",e),e){if("string"==typeof e)return e;if(e.toString)return e.toString("utf8")}}function c(e){return null==e?null:(process.env.VERBOSE&&console.log("result",e),"string"==typeof e&&e.length>0?e:e.slice&&e.toString?e.toString("utf8"):null)}async function u(e,n){if("string"!=typeof n)throw new TypeError("doSqliteQuery1: sql must be a string");if("string"!=typeof e)throw new TypeError("doSqliteQuery1: file must be a string");if(!a(r).existsSync(e))throw new Error(`doSqliteQuery1: file ${e} does not exist`);process.env.VERBOSE&&(console.log(`doSqliteQuery1: file ${e}`),console.log(`doSqliteQuery1: sql ${n}`));const o=new i.Database(e);return new Promise(((e,r)=>{o.all(n,((n,o)=>{if(n)return process.env.VERBOSE&&console.log(`doSqliteQuery1: error ${n}`),void r(n);const t=o;if(null==t||0===t.length)return process.env.VERBOSE&&console.log("doSqliteQuery1: no rows"),void e([]);if(Array.isArray(t)){process.env.VERBOSE&&console.log(`doSqliteQuery1: ${t.length} rows`);const r=t.flatMap((e=>Object.values(e))).map((e=>Buffer.from(e,"binary")));return process.env.VERBOSE&&console.log(`doSqliteQuery1: ${r.length} buffers`),void e(r)}process.env.VERBOSE&&console.log(`doSqliteQuery1: rows ${JSON.stringify(t)}`),e([t])}))}))}function f(e){return"string"!=typeof e||0===e.length}l(e.exports,"execSimple",(()=>o)),l(e.exports,"toStringValue",(()=>s)),l(e.exports,"toStringOrNull",(()=>c)),l(e.exports,"doSqliteQuery1",(()=>u)),l(e.exports,"invalidString",(()=>f))})),g.register("ecbtg",(function(e,n){l(e.exports,"findAllFiles",(()=>t));var o=g("lITtf");async function t({path:e,name:n,maxDepth:i=2}){if("string"!=typeof e)throw new Error("path must be a string");if("string"!=typeof n)throw new Error("name must be a string");const s=e.split("/").length;o.env.VERBOSE&&console.log(`Searching for ${n} in ${e}`);const l=[];let c;try{c=a(r).readdirSync(e)}catch(r){return o.env.VERBOSE&&console.log(`Error reading ${e}`,r),l}for(const u of c){const c=e+"/"+u;let f;try{f=a(r).statSync(c)}catch(e){o.env.VERBOSE&&console.error(`Error getting stat for ${c}`,e);continue}if(f.isDirectory()){if(c.split("/").length<s+i)try{const e=await t({path:c,name:n,rootSegments:s,maxDepth:2});l.push(...e)}catch(e){o.env.VERBOSE&&console.error(e)}}else u===n&&l.push(c)}return o.env.VERBOSE&&l.length>0&&(console.log(`Found ${l.length} ${n} files`),console.log(l)),l}})),g.register("4nk4i",(function(e,n){l(e.exports,"default",(()=>c));var t=g("4ayVE"),i=g("lITtf"),s=g("7c49e"),a=g("ecbtg");class c extends t.default{async queryCookies(e,r){if("darwin"!==process.platform)throw new Error("This only works on macOS");if(i.env.CHROME_ONLY)return[];const n=await this.#r({name:e,domain:r});return Array.isArray(n)?n.map(s.toStringOrNull):[]}async#r({name:e,domain:r}){if(e&&"string"!=typeof e)throw new Error("name must be a string");if(r&&"string"!=typeof r)throw new Error("domain must be a string");const n=await(0,a.findAllFiles)({path:o.join(i.HOME,"Library","Application Support","Firefox","Profiles"),name:"cookies.sqlite"});return Promise.all(n.map((n=>this.#n(n,e,r)))).flat()}#n(e,n,o){if(e&&!(0,r.existsSync)(e))throw new Error(`File ${e} does not exist`);let t;return i.env.VERBOSE&&console.log(`Trying Firefox cookie ${n} for domain ${o}`),t="SELECT value FROM moz_cookies","string"!=typeof n&&"string"!=typeof o||(t+=" WHERE ","string"==typeof n&&(t+=`name = '${n}'`,"string"==typeof o&&(t+=" AND ")),"string"==typeof o&&(t+=`host LIKE '${o}';`)),(0,s.doSqliteQuery1)(e,t).then((e=>e.map(s.toStringOrNull))).catch((()=>[]))}}})),g.register("9icZo",(function(e,r){l(e.exports,"default",(()=>o));var n=g("4ayVE");class o extends n.default{}})),g.register("3K0UF",(function(e,r){l(e.exports,"default",(()=>o));var n=g("lITtf");function o(e){if("string"!=typeof e)return!1;try{const r=a(s).decode(e,{complete:!0});return n.env.VERBOSE&&console.log(r),!0}catch(e){return!1}}})),g("1rMxC");
|
|
3
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";0yBAAA,IAAAA,EAAAC,EAAA,S,0BAMA,MAAMC,EAAOC,QAAQD,KAiBrB,GAAIA,GAAQA,EAAKE,OAAS,EAAG,CAC3B,GAAIF,EAAKG,SAAS,cAAgBH,EAAKG,SAAS,MAE9C,YADAC,QAAQC,IAAIP,EAAAQ,SAId,MAAMC,EAAOP,EAAK,GAElB,IAAIQ,EAEFA,EADa,MAAXR,EAAK,IAAcA,EAAK,GAAGS,QAAQ,MAAO,EACnCT,EAAK,GAEL,IAGX,MAAMU,EAAM,OAERV,EAAKG,SAAS,mBAChBQ,EAAAC,IAAIC,YAAcH,GAEhBV,EAAKG,SAAS,eAChBQ,EAAAC,IAAIE,QAAUJ,GAEZV,EAAK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AMrJ,EAASiF,EAAAqE,GAAaC,OAAOF,EAAO,CAAEG,UAAU,IAItD,OAHIpK,EAAAC,IAAIE,SACNV,QAAQC,IAAIkB,IAEP,C,CACP,MAAOuH,GACP,OAAO,C","sources":["src/cli.js","package.json","src/global.js","src/queryCookies.js","src/browsers/CompositeCookieQueryStrategy.js","src/browsers/ChromeCookieQueryStrategy.js","src/browsers/AbstractCookieQueryStrategy.js","src/utils.js","src/findAllFiles.js","src/browsers/FirefoxCookieQueryStrategy.js","src/browsers/SafariCookieQueryStrategy.js","src/isValidJwt.js"],"sourcesContent":["#!/usr/bin/env node\n\nimport { version } from \"../package.json\";\nimport { env } from \"./global\";\nimport { queryCookies } from \"./queryCookies\";\n\nconst argv = process.argv;\n\nasync function cliQueryCookies(name, domain) {\n try {\n const results = await queryCookies({ name, domain });\n if (results.length > 0) {\n for (const result of results) {\n console.log(result);\n }\n } else {\n console.error(\"No results\");\n }\n } catch (e) {\n console.error(e);\n }\n}\n\nif (argv && argv.length > 2) {\n if (argv.includes(\"--version\") || argv.includes(\"-v\")) {\n console.log(version);\n return;\n }\n\n const name = argv[2];\n\n let domain;\n if (argv[3] != null && argv[3].indexOf(\".\") > -1) {\n domain = argv[3];\n } else {\n domain = \"%\";\n }\n\n const tru = `${true}`;\n\n if (argv.includes(\"--require-jwt\")) {\n env.REQUIRE_JWT = tru;\n }\n if (argv.includes(\"--verbose\")) {\n env.VERBOSE = tru;\n }\n if (argv.includes(\"--chrome-only\")) {\n env.CHROME_ONLY = tru;\n }\n if (argv.includes(\"--firefox-only\")) {\n env.FIREFOX_ONLY = tru;\n }\n if (argv.includes(\"--ignore-expired\")) {\n env.IGNORE_EXPIRED = tru;\n }\n\n if (argv.includes(\"--single\")) {\n env.SINGLE = tru;\n }\n\n if (env.VERBOSE) {\n console.log(\"Verbose mode\", argv);\n }\n\n cliQueryCookies(name, domain)\n .then(() => {\n //\n })\n .catch(console.error);\n}\n","{\n \"name\": \"@mherod/get-cookie\",\n \"version\": \"2.0.0-beta.1\",\n \"description\": \"Node.js module for querying a local user's Chrome cookie\",\n \"source\": \"src/index.js\",\n \"bin\": \"dist/cli.js\",\n \"main\": \"dist/main.js\",\n \"module\": \"dist/module.js\",\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"scripts\": {\n \"clean\": \"git clean -fXd\",\n \"build\": \"parcel build\",\n \"test\": \"jest\",\n \"postbuild\": \"npm run install:global\",\n \"prepublish\": \"npm run build\",\n \"install:global\": \"npm install --force --global .\",\n \"postinstall:global\": \"find $NVM_BIN -exec chmod +x {} \\\\; || true\",\n \"prettier\": \"prettier --write 'src/{**/*,*}.{js,json}'\"\n },\n \"targets\": {\n \"main\": {\n \"source\": \"src/index.js\",\n \"distDir\": \"dist\",\n \"engines\": {\n \"node\": \"16\"\n }\n },\n \"cli\": {\n \"source\": \"src/cli.js\",\n \"distDir\": \"dist\",\n \"engines\": {\n \"node\": \"16\"\n }\n }\n },\n \"@parcel/transformer-js\": {\n \"inlineFS\": false,\n \"inlineEnvironment\": false\n },\n \"engines\": {\n \"node\": \"16\"\n },\n \"keywords\": [],\n \"author\": \"Matthew Herod\",\n \"license\": \"ISC\",\n \"dependencies\": {\n \"jsonwebtoken\": \"^8.5.1\",\n \"lodash\": \"^4.17.21\",\n \"sqlite3\": \"^5.0.8\"\n },\n \"devDependencies\": {\n \"jest\": \"^28.1.0\",\n \"prettier\": \"^2.7.1\"\n }\n}\n","const { merge } = require(\"lodash\");\nexport const env = {};\nmerge(env, process.env);\nexport const HOME = env[\"HOME\"];\nif (!HOME) {\n throw new Error(\"HOME environment variable is not set\");\n}\n","import CompositeCookieQueryStrategy from \"./browsers/CompositeCookieQueryStrategy\";\nimport { uniq } from \"lodash\";\nimport { env } from \"./global\";\nimport isValidJwt from \"./isValidJwt\";\n\nexport async function queryCookies(\n { name, domain },\n strategy = new CompositeCookieQueryStrategy()\n) {\n const results = await strategy.queryCookies(name, domain);\n const results1 = uniq(results).map((cookie) => {\n return {\n name: name,\n domain: domain,\n value: cookie,\n };\n });\n const jwtCookies = [];\n for (const result of results1) {\n const value = result.value;\n if (isValidJwt(value)) {\n jwtCookies.push(result);\n }\n }\n const results2 = env.REQUIRE_JWT ? jwtCookies : results1;\n const resultsUniq = uniq(results2).map((cookie) => cookie.value);\n return env.SINGLE ? [resultsUniq[0]] : resultsUniq;\n}\n","import ChromeCookieQueryStrategy from \"./ChromeCookieQueryStrategy\";\nimport FirefoxCookieQueryStrategy from \"./FirefoxCookieQueryStrategy\";\nimport SafariCookieQueryStrategy from \"./SafariCookieQueryStrategy\";\nimport AbstractCookieQueryStrategy from \"./AbstractCookieQueryStrategy\";\n\nexport default class CompositeCookieQueryStrategy extends AbstractCookieQueryStrategy {\n #strategies;\n\n constructor() {\n super();\n this.#strategies = [\n ChromeCookieQueryStrategy,\n FirefoxCookieQueryStrategy,\n SafariCookieQueryStrategy,\n ].map((strategy) => {\n return new strategy();\n });\n }\n\n async queryCookies(name, domain) {\n const results = await Promise.all(\n this.#strategies.map(async (strategy) => {\n return strategy.queryCookies(name, domain).catch(() => []);\n })\n );\n return results.flat();\n }\n}\n","import AbstractCookieQueryStrategy from \"./AbstractCookieQueryStrategy\";\nimport {\n doSqliteQuery1,\n execSimple,\n invalidString,\n toStringOrNull,\n toStringValue,\n} from \"../utils\";\nimport { env, HOME } from \"../global\";\nimport { existsSync } from \"fs\";\nimport { findAllFiles } from \"../findAllFiles\";\nimport crypto from \"crypto\";\nimport * as path from \"path\";\n\nexport default class ChromeCookieQueryStrategy extends AbstractCookieQueryStrategy {\n async queryCookies(name, domain) {\n if (process.platform !== \"darwin\") {\n throw new Error(\"This only works on macOS\");\n }\n if (env.FIREFOX_ONLY) {\n return [];\n }\n const cookies = await getChromeCookies({ name, domain });\n return cookies.map(toStringValue);\n }\n}\n\nasync function getPromise1(name, domain, file) {\n try {\n return await getEncryptedChromeCookie({\n name: name,\n domain: domain,\n file: file,\n });\n } catch (e) {\n if (env.VERBOSE) {\n console.log(\"Error getting encrypted cookie\", e);\n }\n return [];\n }\n}\n\nasync function getPromise(name, domain) {\n try {\n const files = await findAllFiles({\n path: chromeLocal,\n name: \"Cookies\",\n });\n const promises = files.map((file) => getPromise1(name, domain, file));\n const results1 = await Promise.all(promises);\n const results2 = results1.flat();\n if (env.VERBOSE) {\n console.log(\"getEncryptedChromeCookie results\", results2);\n }\n return results2.filter((result) => result);\n } catch (error) {\n if (env.VERBOSE) {\n console.log(\"error\", error);\n }\n return [];\n }\n}\n\n/**\n *\n * @param {string|undefined} name\n * @param {string} domain\n * @param {boolean} requireJwt\n * @returns {Promise<[string]>}\n */\nasync function getChromeCookies({ name, domain = \"%\", requireJwt = false }) {\n if (invalidString(name)) {\n throw new Error(\"name must be a string\");\n }\n if (invalidString(domain)) {\n throw new Error(\"domain must be a string\");\n }\n const encryptedDataItems = await getPromise(name, domain);\n const password = await getChromePassword();\n const decrypted = encryptedDataItems\n .filter((encryptedData) => {\n return encryptedData != null && encryptedData.length > 0;\n })\n .map(async (encryptedData) => {\n if (env.VERBOSE) {\n console.log(\"Received encrypted\", encryptedData);\n }\n let d;\n try {\n d = await decrypt(password, encryptedData);\n } catch (e) {\n if (env.VERBOSE) {\n console.log(\"Error decrypting cookie\", e);\n }\n return null;\n }\n if (d) {\n if (env.VERBOSE) {\n console.log(\"Decrypted\", d);\n }\n return d;\n }\n return null;\n });\n const results = await Promise.all(decrypted);\n if (env.VERBOSE) {\n console.log(\"results\", results);\n }\n return results.map(toStringOrNull);\n}\n\nconst chromeLocal = path.join(\n HOME,\n \"Library\",\n \"Application Support\",\n \"Google\",\n \"Chrome\"\n);\n\nasync function getEncryptedChromeCookie({\n name,\n domain,\n file = path.join(chromeLocal, \"Default\", \"Cookies\"),\n}) {\n if (name && typeof name !== \"string\") {\n throw new Error(\"name must be a string\");\n }\n if (domain && typeof domain !== \"string\") {\n throw new Error(\"domain must be a string\");\n }\n if (file && typeof file !== \"string\") {\n throw new Error(\"file must be a string\");\n }\n if (!existsSync(file)) {\n throw new Error(`File ${file} does not exist`);\n }\n if (env.VERBOSE) {\n const s = file.split(\"/\").slice(-3).join(\"/\");\n console.log(`Trying Chrome (at ${s}) cookie ${name} for domain ${domain}`);\n }\n let sql;\n sql = `SELECT encrypted_value FROM cookies`;\n if (typeof name === \"string\" || typeof domain === \"string\") {\n sql += ` WHERE `;\n if (typeof name === \"string\") {\n sql += `name = '${name}'`;\n if (typeof domain === \"string\") {\n sql += ` AND `;\n }\n }\n if (typeof domain === \"string\") {\n sql += `host_key LIKE '${domain}';`;\n }\n }\n return doSqliteQuery1(file, sql);\n}\n\n/**\n *\n * @returns {Promise<string>}\n */\nasync function getChromePassword() {\n return execSimple(\n 'security find-generic-password -w -s \"Chrome Safe Storage\"'\n );\n}\n\n/**\n *\n * @param {string} password\n * @param {Buffer} encryptedData\n * @returns {Promise<string>}\n */\nasync function decrypt(password, encryptedData) {\n if (typeof password !== \"string\") {\n throw new Error(\"password must be a string: \" + password);\n }\n let encryptedData1;\n encryptedData1 = encryptedData;\n if (encryptedData1 == null || typeof encryptedData1 !== \"object\") {\n throw new Error(\"encryptedData must be a object: \" + encryptedData1);\n }\n if (!(encryptedData1 instanceof Buffer)) {\n if (Array.isArray(encryptedData1) && encryptedData1[0] instanceof Buffer) {\n [encryptedData1] = encryptedData1;\n if (env.VERBOSE) {\n console.log(\n `encryptedData is an array of buffers, selected first: ${encryptedData1}`\n );\n }\n } else {\n throw new Error(\"encryptedData must be a Buffer: \" + encryptedData1);\n }\n encryptedData1 = Buffer.from(encryptedData1);\n }\n if (env.VERBOSE) {\n console.log(`Trying to decrypt with password ${password}`);\n }\n return new Promise((resolve, reject) => {\n crypto.pbkdf2(password, \"saltysalt\", 1003, 16, \"sha1\", (error, buffer) => {\n try {\n if (error) {\n if (env.VERBOSE) {\n console.log(\"Error doing pbkdf2\", error);\n }\n reject(error);\n return;\n }\n\n if (buffer.length !== 16) {\n if (env.VERBOSE) {\n console.log(\n \"Error doing pbkdf2, buffer length is not 16\",\n buffer.length\n );\n }\n reject(new Error(\"Buffer length is not 16\"));\n return;\n }\n\n const iv = new Buffer.from(new Array(17).join(\" \"), \"binary\");\n const decipher = crypto.createDecipheriv(\"aes-128-cbc\", buffer, iv);\n decipher.setAutoPadding(false);\n\n if (encryptedData1 && encryptedData1.slice) {\n encryptedData1 = encryptedData1.slice(3);\n }\n\n if (encryptedData1.length % 16 !== 0) {\n if (env.VERBOSE) {\n console.log(\n \"Error doing pbkdf2, encryptedData length is not a multiple of 16\",\n encryptedData1.length\n );\n }\n reject(new Error(\"encryptedData length is not a multiple of 16\"));\n return;\n }\n\n let decoded = decipher.update(encryptedData1);\n try {\n decipher.final(\"utf-8\");\n } catch (e) {\n if (env.VERBOSE) {\n console.log(\"Error doing decipher.final()\", e);\n }\n reject(e);\n return;\n }\n\n const padding = decoded[decoded.length - 1];\n if (padding) {\n decoded = decoded.slice(0, 0 - padding);\n }\n // noinspection JSCheckFunctionSignatures\n decoded = decoded.toString(\"utf8\");\n resolve(decoded);\n } catch (e) {\n reject(e);\n }\n });\n });\n}\n","export default class AbstractCookieQueryStrategy {\n async queryCookies(name, domain) {\n if (process.env.NODE_ENV === \"development\") {\n console.log(\"queryCookie\", name, domain);\n }\n return [];\n }\n}\n","// noinspection JSUnusedGlobalSymbols\n\nimport { exec } from \"child_process\";\n\nimport fs from \"fs\";\n\nexport async function execSimple(command) {\n if (typeof command !== \"string\") {\n throw new TypeError(\"execSimple: command must be a string\");\n }\n if (process.env.VERBOSE) {\n console.log(command);\n }\n return new Promise((resolve, reject) => {\n exec(\n command,\n { encoding: \"binary\", maxBuffer: 5 * 1024 },\n (error, stdout, stderr) => {\n if (error) {\n reject(error);\n return;\n }\n if (stderr) {\n reject(error);\n return;\n }\n if (stdout) {\n resolve(stdout.toString(\"utf8\").trim());\n }\n }\n );\n });\n}\n\nexport async function execAsBuffer(command) {\n if (typeof command !== \"string\") {\n throw new TypeError(\"execAsBuffer: command must be a string\");\n }\n if (process.env.VERBOSE) {\n console.log(command);\n }\n return await new Promise((resolve, reject) => {\n exec(\n command,\n { encoding: \"binary\", maxBuffer: 5 * 1024 },\n (error, stdout, stderr) => {\n if (error) {\n reject(error);\n return;\n }\n if (stderr) {\n reject(error);\n return;\n }\n let stdoutAsBuffer = stdout;\n if (typeof stdoutAsBuffer === \"string\" && stdoutAsBuffer.length > 0) {\n // noinspection JSCheckFunctionSignatures\n stdoutAsBuffer = Buffer.from(stdoutAsBuffer, \"binary\").slice(0, -1);\n }\n if (stdoutAsBuffer && stdoutAsBuffer.length > 0) {\n resolve(stdoutAsBuffer);\n }\n }\n );\n });\n}\n\nexport function toStringValue(r) {\n if (process.env.VERBOSE) {\n console.log(\"Printing value\", r);\n }\n if (r) {\n if (typeof r === \"string\") {\n return r;\n } else if (r.toString) {\n // noinspection JSCheckFunctionSignatures\n return r.toString(\"utf8\");\n }\n }\n}\n\nexport function printStringValue(r) {\n if (process.env.VERBOSE) {\n console.log(\"Printing value\", r);\n }\n if (r) {\n if (typeof r === \"string\") {\n console.log(r);\n } else if (r.toString) {\n // noinspection JSCheckFunctionSignatures\n console.log(r.toString(\"utf8\"));\n }\n }\n}\n\n/**\n *\n * @param result\n * @returns {string|null}\n */\nexport function toStringOrNull(result) {\n if (result == null) {\n return null;\n }\n if (process.env.VERBOSE) {\n console.log(\"result\", result);\n }\n if (typeof result === \"string\" && result.length > 0) {\n return result;\n }\n if (result.slice && result.toString) {\n // noinspection JSCheckFunctionSignatures\n return result.toString(\"utf8\");\n }\n return null;\n}\n\n/**\n *\n * @param {string} file\n * @param {string} sql\n * @returns {Promise<Buffer[]>}\n */\nexport async function doSqliteQuery1(file, sql) {\n if (typeof sql !== \"string\") {\n throw new TypeError(\"doSqliteQuery1: sql must be a string\");\n }\n if (typeof file !== \"string\") {\n throw new TypeError(\"doSqliteQuery1: file must be a string\");\n }\n if (!fs.existsSync(file)) {\n throw new Error(`doSqliteQuery1: file ${file} does not exist`);\n }\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: file ${file}`);\n console.log(`doSqliteQuery1: sql ${sql}`);\n }\n const sqlite3 = require(\"sqlite3\");\n const db = new sqlite3.Database(file);\n return new Promise((resolve, reject) => {\n db.all(sql, (err, rows) => {\n if (err) {\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: error ${err}`);\n }\n reject(err);\n return;\n }\n const rows1 = rows;\n if (rows1 == null || rows1.length === 0) {\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: no rows`);\n }\n resolve([]);\n return;\n }\n if (Array.isArray(rows1)) {\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: ${rows1.length} rows`);\n }\n // noinspection JSCheckFunctionSignatures\n const buffers = rows1\n .flatMap((row) => Object.values(row))\n .map((v) => Buffer.from(v, \"binary\"));\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: ${buffers.length} buffers`);\n }\n resolve(buffers);\n return;\n }\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);\n }\n resolve([rows1]);\n });\n });\n}\n\nexport function invalidString(input) {\n return typeof input !== \"string\" || input.length === 0;\n}\n","import { env } from \"./global\";\nimport fs from \"fs\";\n\n/**\n *\n * @param path\n * @param name\n * @param rootSegments\n * @param maxDepth\n * @returns {Promise<[string]>}\n */\nexport async function findAllFiles({ path, name, maxDepth = 2 }) {\n if (typeof path !== \"string\") {\n throw new Error(\"path must be a string\");\n }\n if (typeof name !== \"string\") {\n throw new Error(\"name must be a string\");\n }\n\n const rootSegments = path.split(\"/\").length;\n\n if (env.VERBOSE) {\n console.log(`Searching for ${name} in ${path}`);\n }\n const files = [];\n let readdirSync;\n try {\n readdirSync = fs.readdirSync(path);\n } catch (e) {\n if (env.VERBOSE) {\n console.log(`Error reading ${path}`, e);\n }\n return files;\n }\n for (const file of readdirSync) {\n const filePath = path + \"/\" + file;\n let stat;\n try {\n stat = fs.statSync(filePath);\n } catch (e) {\n if (env.VERBOSE) {\n console.error(`Error getting stat for ${filePath}`, e);\n }\n continue;\n }\n if (stat.isDirectory()) {\n if (filePath.split(\"/\").length < rootSegments + maxDepth) {\n try {\n const subFiles = await findAllFiles({\n path: filePath,\n name: name,\n rootSegments: rootSegments,\n maxDepth: 2,\n });\n files.push(...subFiles);\n } catch (e) {\n if (env.VERBOSE) {\n console.error(e);\n }\n }\n }\n } else if (file === name) {\n files.push(filePath);\n }\n }\n if (env.VERBOSE) {\n if (files.length > 0) {\n console.log(`Found ${files.length} ${name} files`);\n console.log(files);\n }\n }\n return files;\n}\n","import AbstractCookieQueryStrategy from \"./AbstractCookieQueryStrategy\";\nimport { env, HOME } from \"../global\";\nimport { existsSync } from \"fs\";\nimport { doSqliteQuery1, toStringOrNull } from \"../utils\";\nimport { findAllFiles } from \"../findAllFiles\";\nimport * as path from \"path\";\n\nexport default class FirefoxCookieQueryStrategy extends AbstractCookieQueryStrategy {\n async queryCookies(name, domain) {\n if (process.platform !== \"darwin\") {\n throw new Error(\"This only works on macOS\");\n }\n if (env.CHROME_ONLY) {\n return [];\n }\n const cookies = await this.#getFirefoxCookie({ name, domain });\n return Array.isArray(cookies) ? cookies.map(toStringOrNull) : [];\n }\n\n /**\n *\n * @param name\n * @param domain\n * @returns {Promise<Buffer>}\n */\n async #getFirefoxCookie({ name, domain }) {\n if (name && typeof name !== \"string\") {\n throw new Error(\"name must be a string\");\n }\n if (domain && typeof domain !== \"string\") {\n throw new Error(\"domain must be a string\");\n }\n const files = await findAllFiles({\n path: path.join(\n HOME,\n \"Library\",\n \"Application Support\",\n \"Firefox\",\n \"Profiles\"\n ),\n name: \"cookies.sqlite\",\n });\n const all = Promise.all(\n files.map((file) => {\n return this.#queryCookiesDb(file, name, domain);\n })\n );\n return all.flat();\n }\n\n #queryCookiesDb(file, name, domain) {\n if (file && !existsSync(file)) {\n throw new Error(`File ${file} does not exist`);\n }\n if (env.VERBOSE) {\n console.log(`Trying Firefox cookie ${name} for domain ${domain}`);\n }\n let sql;\n //language=SQL\n sql = \"SELECT value FROM moz_cookies\";\n if (typeof name === \"string\" || typeof domain === \"string\") {\n sql += ` WHERE `;\n if (typeof name === \"string\") {\n sql += `name = '${name}'`;\n if (typeof domain === \"string\") {\n sql += ` AND `;\n }\n }\n if (typeof domain === \"string\") {\n sql += `host LIKE '${domain}';`;\n }\n }\n return doSqliteQuery1(file, sql)\n .then((rows) => rows.map(toStringOrNull))\n .catch(() => []);\n }\n}\n","import AbstractCookieQueryStrategy from \"./AbstractCookieQueryStrategy\";\n\nexport default class SafariCookieQueryStrategy extends AbstractCookieQueryStrategy {}\n","import jsonwebtoken from \"jsonwebtoken\";\nimport { env } from \"./global\";\n\nexport default function isValidJwt(token) {\n if (typeof token !== \"string\") {\n return false;\n }\n try {\n const result = jsonwebtoken.decode(token, { complete: true });\n if (env.VERBOSE) {\n console.log(result);\n }\n return true;\n } catch (err) {\n return false;\n }\n}\n"],"names":["$9MSW1","parcelRequire","argv","process","length","includes","console","log","version","name","domain","indexOf","tru","$lITtf","env","REQUIRE_JWT","VERBOSE","CHROME_ONLY","FIREFOX_ONLY","IGNORE_EXPIRED","SINGLE","async","results","$hZLs7","queryCookies","result","error","e","cliQueryCookies","then","catch","module","exports","JSON","parse","$hEvgT$lodash","merge","$fd08bc5d4f8fdcf9$export$a7b6bc01c63cdfc3","$fd08bc5d4f8fdcf9$require$merge","$fd08bc5d4f8fdcf9$export$a7c5707626fc90f","Error","$2LoRB","$d19cf14407a2b8de$export$e6d428437cf2cacb","strategy","default","results1","uniq","map","cookie","value","jwtCookies","$3K0UF","push","results2","resultsUniq","$eM6gm","$203341eb2d58b49d$export$2e2bcd8739ae039","$4ayVE","strategies","constructor","super","this","$4nk4i","$9icZo","Promise","all","flat","$ac1a6810304d0e5a$export$2e2bcd8739ae039","platform","cookies","requireJwt","$7c49e","invalidString","encryptedDataItems","promises","$ecbtg","findAllFiles","path","$ac1a6810304d0e5a$var$chromeLocal","file","$hEvgT$path","join","$hEvgT$fs","existsSync","s","split","slice","sql","doSqliteQuery1","$ac1a6810304d0e5a$var$getEncryptedChromeCookie","$ac1a6810304d0e5a$var$getPromise1","filter","$ac1a6810304d0e5a$var$getPromise","password","execSimple","$ac1a6810304d0e5a$var$getChromePassword","decrypted","encryptedData","d","encryptedData1","Buffer","Array","isArray","from","resolve","reject","$parcel$interopDefault","$hEvgT$crypto","pbkdf2","buffer","iv","decipher","createDecipheriv","setAutoPadding","decoded","update","final","padding","toString","e1","$ac1a6810304d0e5a$var$decrypt","toStringOrNull","$ac1a6810304d0e5a$var$getChromeCookies","toStringValue","HOME","$309330c1f15c5ef9$export$2e2bcd8739ae039","NODE_ENV","$53ccdf0f5343f791$export$8d71c74f97c0202e","command","TypeError","$hEvgT$child_process","exec","encoding","maxBuffer","stdout","stderr","trim","$53ccdf0f5343f791$export$33d3adc27420eed5","r","$53ccdf0f5343f791$export$d53bf2de587a369","$53ccdf0f5343f791$export$f19f611d1fa7c6f3","db","$hEvgT$sqlite3","Database","err","rows","rows1","buffers","flatMap","row","Object","values","v","stringify","$53ccdf0f5343f791$export$99ce3e33a555daf1","input","$a55b15957c212836$export$2c9faf86071156ae","maxDepth","rootSegments","files","readdirSync","filePath","stat","statSync","isDirectory","subFiles","e2","$32f8e090b018228f$export$2e2bcd8739ae039","getFirefoxCookie","queryCookiesDb","name1","domain1","$6c3fdee19ee6f263$export$2e2bcd8739ae039","$2b96604c173979a6$export$2e2bcd8739ae039","token","$hEvgT$jsonwebtoken","decode","complete"],"version":3,"file":"cli.js.map","sourceRoot":"../"}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var $bU6Ve$lodash = require("lodash");
|
|
3
|
+
var $bU6Ve$fs = require("fs");
|
|
4
|
+
var $bU6Ve$crypto = require("crypto");
|
|
5
|
+
var $bU6Ve$path = require("path");
|
|
6
|
+
var $bU6Ve$child_process = require("child_process");
|
|
7
|
+
var $bU6Ve$sqlite3 = require("sqlite3");
|
|
8
|
+
var $bU6Ve$jsonwebtoken = require("jsonwebtoken");
|
|
9
|
+
|
|
10
|
+
function $parcel$export(e, n, v, s) {
|
|
11
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
12
|
+
}
|
|
13
|
+
function $parcel$interopDefault(a) {
|
|
14
|
+
return a && a.__esModule ? a.default : a;
|
|
15
|
+
}
|
|
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
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
async function $c0cdc003fbf917f0$export$8d71c74f97c0202e(command) {
|
|
31
|
+
if (typeof command !== "string") throw new TypeError("execSimple: command must be a string");
|
|
32
|
+
if (process.env.VERBOSE) console.log(command);
|
|
33
|
+
return new Promise((resolve, reject)=>{
|
|
34
|
+
(0, $bU6Ve$child_process.exec)(command, {
|
|
35
|
+
encoding: "binary",
|
|
36
|
+
maxBuffer: 5120
|
|
37
|
+
}, (error, stdout, stderr)=>{
|
|
38
|
+
if (error) {
|
|
39
|
+
reject(error);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (stderr) {
|
|
43
|
+
reject(error);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (stdout) resolve(stdout.toString("utf8").trim());
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async function $c0cdc003fbf917f0$export$1704cc27537f7088(command) {
|
|
51
|
+
if (typeof command !== "string") throw new TypeError("execAsBuffer: command must be a string");
|
|
52
|
+
if (process.env.VERBOSE) console.log(command);
|
|
53
|
+
return await new Promise((resolve, reject)=>{
|
|
54
|
+
(0, $bU6Ve$child_process.exec)(command, {
|
|
55
|
+
encoding: "binary",
|
|
56
|
+
maxBuffer: 5120
|
|
57
|
+
}, (error, stdout, stderr)=>{
|
|
58
|
+
if (error) {
|
|
59
|
+
reject(error);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (stderr) {
|
|
63
|
+
reject(error);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
let stdoutAsBuffer = stdout;
|
|
67
|
+
if (typeof stdoutAsBuffer === "string" && stdoutAsBuffer.length > 0) // noinspection JSCheckFunctionSignatures
|
|
68
|
+
stdoutAsBuffer = Buffer.from(stdoutAsBuffer, "binary").slice(0, -1);
|
|
69
|
+
if (stdoutAsBuffer && stdoutAsBuffer.length > 0) resolve(stdoutAsBuffer);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function $c0cdc003fbf917f0$export$33d3adc27420eed5(r) {
|
|
74
|
+
if (process.env.VERBOSE) console.log("Printing value", r);
|
|
75
|
+
if (r) {
|
|
76
|
+
if (typeof r === "string") return r;
|
|
77
|
+
else if (r.toString) // noinspection JSCheckFunctionSignatures
|
|
78
|
+
return r.toString("utf8");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function $c0cdc003fbf917f0$export$1ed1ce2ec2b4f5a3(r) {
|
|
82
|
+
if (process.env.VERBOSE) console.log("Printing value", r);
|
|
83
|
+
if (r) {
|
|
84
|
+
if (typeof r === "string") console.log(r);
|
|
85
|
+
else if (r.toString) // noinspection JSCheckFunctionSignatures
|
|
86
|
+
console.log(r.toString("utf8"));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function $c0cdc003fbf917f0$export$d53bf2de587a369(result) {
|
|
90
|
+
if (result == null) return null;
|
|
91
|
+
if (process.env.VERBOSE) console.log("result", result);
|
|
92
|
+
if (typeof result === "string" && result.length > 0) return result;
|
|
93
|
+
if (result.slice && result.toString) // noinspection JSCheckFunctionSignatures
|
|
94
|
+
return result.toString("utf8");
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function $c0cdc003fbf917f0$export$f19f611d1fa7c6f3(file, sql) {
|
|
99
|
+
if (typeof sql !== "string") throw new TypeError("doSqliteQuery1: sql must be a string");
|
|
100
|
+
if (typeof file !== "string") throw new TypeError("doSqliteQuery1: file must be a string");
|
|
101
|
+
if (!(0, ($parcel$interopDefault($bU6Ve$fs))).existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
102
|
+
if (process.env.VERBOSE) {
|
|
103
|
+
console.log(`doSqliteQuery1: file ${file}`);
|
|
104
|
+
console.log(`doSqliteQuery1: sql ${sql}`);
|
|
105
|
+
}
|
|
106
|
+
const sqlite3 = $bU6Ve$sqlite3;
|
|
107
|
+
const db = new sqlite3.Database(file);
|
|
108
|
+
return new Promise((resolve, reject)=>{
|
|
109
|
+
db.all(sql, (err, rows)=>{
|
|
110
|
+
if (err) {
|
|
111
|
+
if (process.env.VERBOSE) console.log(`doSqliteQuery1: error ${err}`);
|
|
112
|
+
reject(err);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const rows1 = rows;
|
|
116
|
+
if (rows1 == null || rows1.length === 0) {
|
|
117
|
+
if (process.env.VERBOSE) console.log(`doSqliteQuery1: no rows`);
|
|
118
|
+
resolve([]);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (Array.isArray(rows1)) {
|
|
122
|
+
if (process.env.VERBOSE) console.log(`doSqliteQuery1: ${rows1.length} rows`);
|
|
123
|
+
// noinspection JSCheckFunctionSignatures
|
|
124
|
+
const buffers = rows1.flatMap((row)=>Object.values(row)).map((v)=>Buffer.from(v, "binary"));
|
|
125
|
+
if (process.env.VERBOSE) console.log(`doSqliteQuery1: ${buffers.length} buffers`);
|
|
126
|
+
resolve(buffers);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (process.env.VERBOSE) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
130
|
+
resolve([
|
|
131
|
+
rows1
|
|
132
|
+
]);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
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;
|
|
159
|
+
try {
|
|
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;
|
|
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;
|
|
195
|
+
}
|
|
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
|
|
207
|
+
});
|
|
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
|
|
217
|
+
});
|
|
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"
|
|
228
|
+
});
|
|
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
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
*
|
|
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;
|
|
260
|
+
}
|
|
261
|
+
if (d) {
|
|
262
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Decrypted", d);
|
|
263
|
+
return d;
|
|
264
|
+
}
|
|
265
|
+
return null;
|
|
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));
|
|
270
|
+
}
|
|
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") , }) {
|
|
273
|
+
if (name && typeof name !== "string") throw new Error("name must be a string");
|
|
274
|
+
if (domain && typeof domain !== "string") throw new Error("domain must be a string");
|
|
275
|
+
if (file && typeof file !== "string") throw new Error("file must be a string");
|
|
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
|
+
}
|
|
281
|
+
let sql;
|
|
282
|
+
sql = `SELECT encrypted_value FROM cookies`;
|
|
283
|
+
if (typeof name === "string" || typeof domain === "string") {
|
|
284
|
+
sql += ` WHERE `;
|
|
285
|
+
if (typeof name === "string") {
|
|
286
|
+
sql += `name = '${name}'`;
|
|
287
|
+
if (typeof domain === "string") sql += ` AND `;
|
|
288
|
+
}
|
|
289
|
+
if (typeof domain === "string") sql += `host_key LIKE '${domain}';`;
|
|
290
|
+
}
|
|
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"');
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
*
|
|
301
|
+
* @param {string} password
|
|
302
|
+
* @param {Buffer} encryptedData
|
|
303
|
+
* @returns {Promise<string>}
|
|
304
|
+
*/ async function $1c57ad353fa3519e$var$decrypt(password, encryptedData) {
|
|
305
|
+
if (typeof password !== "string") throw new Error("password must be a string: " + password);
|
|
306
|
+
let encryptedData1;
|
|
307
|
+
encryptedData1 = encryptedData;
|
|
308
|
+
if (encryptedData1 == null || typeof encryptedData1 !== "object") throw new Error("encryptedData must be a object: " + encryptedData1);
|
|
309
|
+
if (!(encryptedData1 instanceof Buffer)) {
|
|
310
|
+
if (Array.isArray(encryptedData1) && encryptedData1[0] instanceof Buffer) {
|
|
311
|
+
[encryptedData1] = encryptedData1;
|
|
312
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`encryptedData is an array of buffers, selected first: ${encryptedData1}`);
|
|
313
|
+
} else throw new Error("encryptedData must be a Buffer: " + encryptedData1);
|
|
314
|
+
encryptedData1 = Buffer.from(encryptedData1);
|
|
315
|
+
}
|
|
316
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying to decrypt with password ${password}`);
|
|
317
|
+
return new Promise((resolve, reject)=>{
|
|
318
|
+
(0, ($parcel$interopDefault($bU6Ve$crypto))).pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer)=>{
|
|
319
|
+
try {
|
|
320
|
+
if (error) {
|
|
321
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2", error);
|
|
322
|
+
reject(error);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (buffer.length !== 16) {
|
|
326
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, buffer length is not 16", buffer.length);
|
|
327
|
+
reject(new Error("Buffer length is not 16"));
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const iv = new Buffer.from(new Array(17).join(" "), "binary");
|
|
331
|
+
const decipher = (0, ($parcel$interopDefault($bU6Ve$crypto))).createDecipheriv("aes-128-cbc", buffer, iv);
|
|
332
|
+
decipher.setAutoPadding(false);
|
|
333
|
+
if (encryptedData1 && encryptedData1.slice) encryptedData1 = encryptedData1.slice(3);
|
|
334
|
+
if (encryptedData1.length % 16 !== 0) {
|
|
335
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16", encryptedData1.length);
|
|
336
|
+
reject(new Error("encryptedData length is not a multiple of 16"));
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
let decoded = decipher.update(encryptedData1);
|
|
340
|
+
try {
|
|
341
|
+
decipher.final("utf-8");
|
|
342
|
+
} catch (e) {
|
|
343
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing decipher.final()", e);
|
|
344
|
+
reject(e);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const padding = decoded[decoded.length - 1];
|
|
348
|
+
if (padding) decoded = decoded.slice(0, 0 - padding);
|
|
349
|
+
// noinspection JSCheckFunctionSignatures
|
|
350
|
+
decoded = decoded.toString("utf8");
|
|
351
|
+
resolve(decoded);
|
|
352
|
+
} catch (e1) {
|
|
353
|
+
reject(e1);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
}
|
|
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
|
|
373
|
+
});
|
|
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"
|
|
387
|
+
});
|
|
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}';`;
|
|
406
|
+
}
|
|
407
|
+
return (0, $c0cdc003fbf917f0$export$f19f611d1fa7c6f3)(file, sql).then((rows)=>rows.map((0, $c0cdc003fbf917f0$export$d53bf2de587a369))).catch(()=>[]);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
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
|
+
});
|
|
429
|
+
}
|
|
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();
|
|
435
|
+
}
|
|
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;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
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
|
+
}
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
//# sourceMappingURL=main.js.map
|