From f09a78810339bc048a2c593e6a16f94cb4aa6690 Mon Sep 17 00:00:00 2001 From: Hinton Date: Mon, 5 Oct 2020 15:11:37 +0200 Subject: [PATCH 01/33] Initial PoC for browser <-> desktop communication --- package-lock.json | 672 +++++++++++++++++++++++- package.json | 13 +- proxy/app.ts | 22 + proxy/global.d.ts | 4 + proxy/ipc.ts | 61 +++ proxy/nativemessage.ts | 85 +++ proxy/tsconfig.json | 56 ++ scripts/chrome.json | 7 + src/global.d.ts | 4 + src/main.ts | 5 + src/package.json | 1 + src/services/nativeMessaging.service.ts | 33 ++ tsconfig.json | 1 + 13 files changed, 960 insertions(+), 4 deletions(-) create mode 100644 proxy/app.ts create mode 100644 proxy/global.d.ts create mode 100644 proxy/ipc.ts create mode 100644 proxy/nativemessage.ts create mode 100644 proxy/tsconfig.json create mode 100644 scripts/chrome.json create mode 100644 src/services/nativeMessaging.service.ts diff --git a/package-lock.json b/package-lock.json index e0fb213d..4ee0a01a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -409,6 +409,29 @@ } } }, + "@babel/parser": { + "version": "7.11.5", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.11.5.tgz", + "integrity": "sha512-X9rD8qqm695vgmeaQ4fvz/o3+Wk4ZzQvSHkDBgpYKxpD4qTAUm88ZKtHkVqIOsYFFbIQ6wQYhC6q7pjqVK0E0Q==", + "dev": true + }, + "@babel/runtime": { + "version": "7.11.2", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.11.2.tgz", + "integrity": "sha512-TeWkU52so0mPtDcaCTxNBI/IHiz0pZgr8VEFqXFtZWpYD08ZB6FaSwVAS8MKRQAP3bYKiVjwysOJgMFY28o6Tw==", + "dev": true, + "requires": { + "regenerator-runtime": "^0.13.4" + }, + "dependencies": { + "regenerator-runtime": { + "version": "0.13.7", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz", + "integrity": "sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==", + "dev": true + } + } + }, "@develar/schema-utils": { "version": "2.6.5", "resolved": "https://registry.npmjs.org/@develar/schema-utils/-/schema-utils-2.6.5.tgz", @@ -603,6 +626,32 @@ } } }, + "@nodelib/fs.scandir": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz", + "integrity": "sha512-eGmwYQn3gxo4r7jdQnkrrN6bY478C3P+a/y72IJukF8LjB6ZHeB3c+Ehacj3sYeSmUXGlnA67/PmbM9CVwL7Dw==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "2.0.3", + "run-parallel": "^1.1.9" + } + }, + "@nodelib/fs.stat": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.3.tgz", + "integrity": "sha512-bQBFruR2TAwoevBEd/NWMoAAtNGzTRgdrqnYCc7dhzfoNvqPzLyqlEQnzZ3kVnNrSp25iyxE00/3h2fqGAGArA==", + "dev": true + }, + "@nodelib/fs.walk": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.4.tgz", + "integrity": "sha512-1V9XOY4rDW0rehzbrcqAmHnz8e7SKvX27gh8Gt2WgB0+pdzdiLV83p72kZPU+jvMbS1qU5mauP2iOvO8rhmurQ==", + "dev": true, + "requires": { + "@nodelib/fs.scandir": "2.1.3", + "fastq": "^1.6.0" + } + }, "@nodert-win10-rs4/windows.security.credentials.ui": { "version": "0.4.4", "resolved": "https://registry.npmjs.org/@nodert-win10-rs4/windows.security.credentials.ui/-/windows.security.credentials.ui-0.4.4.tgz", @@ -661,9 +710,9 @@ "dev": true }, "@types/node": { - "version": "10.17.28", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.28.tgz", - "integrity": "sha512-dzjES1Egb4c1a89C7lKwQh8pwjYmlOAG9dW1pBgxEk57tMrLnssOfEthz8kdkNaBd7lIqQx7APm5+mZ619IiCQ==", + "version": "10.17.35", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.35.tgz", + "integrity": "sha512-gXx7jAWpMddu0f7a+L+txMplp3FnHl53OhQIF9puXKq3hDGY/GjH+MF04oWnV/adPSCrbtHumDCFwzq2VhltWA==", "dev": true }, "@types/node-forge": { @@ -2205,6 +2254,12 @@ "integrity": "sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug=", "dev": true }, + "byline": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/byline/-/byline-5.0.0.tgz", + "integrity": "sha1-dBxSFkaOrcRXsDQQEYrXfejB3bE=", + "dev": true + }, "cacache": { "version": "10.0.4", "resolved": "https://registry.npmjs.org/cacache/-/cacache-10.0.4.tgz", @@ -3329,6 +3384,12 @@ "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==" }, + "deep-is": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", + "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", + "dev": true + }, "default-compare": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/default-compare/-/default-compare-1.0.0.tgz", @@ -3730,6 +3791,11 @@ "object.defaults": "^1.1.0" } }, + "easy-stack": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/easy-stack/-/easy-stack-1.0.0.tgz", + "integrity": "sha1-EskbMIWjfwuqM26UhurEv5Tj54g=" + }, "ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -4858,6 +4924,19 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "escodegen": { + "version": "1.14.3", + "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.14.3.tgz", + "integrity": "sha512-qFcX0XJkdg+PB3xjZZG/wKSuT1PnQWx57+TVSjIMmILd2yC/6ByYElPwJnslDsuWuSAp4AwJGumarAAmJch5Kw==", + "dev": true, + "requires": { + "esprima": "^4.0.1", + "estraverse": "^4.2.0", + "esutils": "^2.0.2", + "optionator": "^0.8.1", + "source-map": "~0.6.1" + } + }, "eslint-scope": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.0.tgz", @@ -4894,6 +4973,11 @@ "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", "dev": true }, + "event-pubsub": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/event-pubsub/-/event-pubsub-4.3.0.tgz", + "integrity": "sha512-z7IyloorXvKbFx9Bpie2+vMJKKx1fH1EN5yiTfp8CiLOTptSYy1g8H4yDpGlEdshL1PBiFtBHepF2cNsqeEeFQ==" + }, "events": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/events/-/events-3.0.0.tgz", @@ -5129,17 +5213,100 @@ "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=", "dev": true }, + "fast-glob": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.4.tgz", + "integrity": "sha512-kr/Oo6PX51265qeuCYsyGypiO5uJFgBS0jksyG7FUeCyQzNwYnzrNIMR1NXfkZXsMYXYLRAHgISHBz8gQcxKHQ==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.0", + "merge2": "^1.3.0", + "micromatch": "^4.0.2", + "picomatch": "^2.2.1" + }, + "dependencies": { + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "glob-parent": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", + "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "micromatch": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz", + "integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==", + "dev": true, + "requires": { + "braces": "^3.0.1", + "picomatch": "^2.0.5" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + } + } + }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" }, + "fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", + "dev": true + }, "fastparse": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/fastparse/-/fastparse-1.1.1.tgz", "integrity": "sha1-0eJkOzipTXWDtHkGDmxK/8lAcfg=", "dev": true }, + "fastq": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.8.0.tgz", + "integrity": "sha512-SMIZoZdLh/fgofivvIkmknUXyPnvxRE3DhtZ5Me3Mrsk5gyPL42F0xr51TdRXskBxHfMp+07bcYzfsYEsSQA9Q==", + "dev": true, + "requires": { + "reusify": "^1.0.4" + } + }, "fd-slicer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.0.1.tgz", @@ -7613,6 +7780,24 @@ "integrity": "sha1-ftGxQQxqDg94z5XTuEQMY/eLhhQ=", "dev": true }, + "into-stream": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/into-stream/-/into-stream-5.1.1.tgz", + "integrity": "sha512-krrAJ7McQxGGmvaYbB7Q1mcA+cRwg9Ij2RfWIeVesNBgVDZmzY/Fa4IpZUT3bmdRzMzdf/mzltCG2Dq99IZGBA==", + "dev": true, + "requires": { + "from2": "^2.3.0", + "p-is-promise": "^3.0.0" + }, + "dependencies": { + "p-is-promise": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-3.0.0.tgz", + "integrity": "sha512-Wo8VsW4IRQSKVXsJCn7TomUaVtyfjVDn3nUP7kE967BQk0CwFpdbZs0X0uk5sW9mkBa9eNM7hCMaG93WUAwxYQ==", + "dev": true + } + } + }, "invert-kv": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz", @@ -8000,6 +8185,19 @@ "integrity": "sha512-M7kLczedRMYX4L8Mdh4MzyAMM9O5osx+4FcOQuTvr3A9F2D9S5JXheN0ewNbrvK2UatkTRhL5ejGmGSjNMiZuw==", "dev": true }, + "js-message": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.5.tgz", + "integrity": "sha1-IwDSSxrwjondCVvBpMnJz8uJLRU=" + }, + "js-queue": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/js-queue/-/js-queue-2.0.0.tgz", + "integrity": "sha1-NiITz4YPRo8BJfxslqvBdCUx+Ug=", + "requires": { + "easy-stack": "^1.0.0" + } + }, "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", @@ -8188,6 +8386,16 @@ "flush-write-stream": "^1.0.2" } }, + "levn": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", + "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", + "dev": true, + "requires": { + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2" + } + }, "liftoff": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/liftoff/-/liftoff-2.5.0.tgz", @@ -8857,6 +9065,12 @@ "trim-newlines": "^1.0.0" } }, + "merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true + }, "micromatch": { "version": "3.1.10", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz", @@ -9160,6 +9374,16 @@ } } }, + "multistream": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/multistream/-/multistream-2.1.1.tgz", + "integrity": "sha512-xasv76hl6nr1dEy3lPvy7Ej7K/Lx3O/FCvwge8PeVJpciPPoNCbaANcNiBug3IpdvTveZUcAV0DJzdnUDMesNQ==", + "dev": true, + "requires": { + "inherits": "^2.0.1", + "readable-stream": "^2.0.5" + } + }, "mute-stdout": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/mute-stdout/-/mute-stdout-1.0.1.tgz", @@ -9310,6 +9534,16 @@ } } }, + "node-ipc": { + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/node-ipc/-/node-ipc-9.1.1.tgz", + "integrity": "sha512-FAyICv0sIRJxVp3GW5fzgaf9jwwRQxAKDJlmNFUL5hOy+W4X/I5AypyHoq0DXXbo9o/gt79gj++4cMr4jVWE/w==", + "requires": { + "event-pubsub": "4.3.0", + "js-message": "1.0.5", + "js-queue": "2.0.0" + } + }, "node-libs-browser": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-2.2.0.tgz", @@ -9850,6 +10084,20 @@ "pinkie-promise": "^2.0.0" } }, + "optionator": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz", + "integrity": "sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA==", + "dev": true, + "requires": { + "deep-is": "~0.1.3", + "fast-levenshtein": "~2.0.6", + "levn": "~0.3.0", + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2", + "word-wrap": "~1.2.3" + } + }, "ora": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/ora/-/ora-3.4.0.tgz", @@ -10220,6 +10468,158 @@ "pinkie": "^2.0.0" } }, + "pkg": { + "version": "4.4.9", + "resolved": "https://registry.npmjs.org/pkg/-/pkg-4.4.9.tgz", + "integrity": "sha512-FK4GqHtcCY2PPPVaKViU0NyRzpo6gCS7tPKN5b7AkElqjAOCH1bsRKgohEnxThr6DWfTGByGqba2YHGR/BqbmA==", + "dev": true, + "requires": { + "@babel/parser": "^7.9.4", + "@babel/runtime": "^7.9.2", + "chalk": "^3.0.0", + "escodegen": "^1.14.1", + "fs-extra": "^8.1.0", + "globby": "^11.0.0", + "into-stream": "^5.1.1", + "minimist": "^1.2.5", + "multistream": "^2.1.1", + "pkg-fetch": "^2.6.9", + "progress": "^2.0.3", + "resolve": "^1.15.1", + "stream-meter": "^1.0.4" + }, + "dependencies": { + "ansi-styles": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "dev": true, + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, + "array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "requires": { + "path-type": "^4.0.0" + } + }, + "fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "globby": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.0.1.tgz", + "integrity": "sha512-iH9RmgwCmUJHi2z5o2l3eTtGBtXek1OYlHrbcxOYugyHLmAsZrPj43OtHThd62Buh/Vv6VyCBD2bdyWcGNQqoQ==", + "dev": true, + "requires": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.1.1", + "ignore": "^5.1.4", + "merge2": "^1.3.0", + "slash": "^3.0.0" + } + }, + "graceful-fs": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", + "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==", + "dev": true + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "ignore": { + "version": "5.1.8", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz", + "integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==", + "dev": true + }, + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true + }, + "path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true + }, + "resolve": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", + "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + }, + "slash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + } + } + }, "pkg-dir": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-2.0.0.tgz", @@ -10229,6 +10629,190 @@ "find-up": "^2.1.0" } }, + "pkg-fetch": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/pkg-fetch/-/pkg-fetch-2.6.9.tgz", + "integrity": "sha512-EnVR8LRILXBvaNP+wJOSY02c3+qDDfyEyR+aqAHLhcc9PBnbxFT9UZ1+If49goPQzQPn26TzF//fc6KXZ0aXEg==", + "dev": true, + "requires": { + "@babel/runtime": "^7.9.2", + "byline": "^5.0.0", + "chalk": "^3.0.0", + "expand-template": "^2.0.3", + "fs-extra": "^8.1.0", + "minimist": "^1.2.5", + "progress": "^2.0.3", + "request": "^2.88.0", + "request-progress": "^3.0.0", + "semver": "^6.3.0", + "unique-temp-dir": "^1.0.0" + }, + "dependencies": { + "ajv": { + "version": "6.12.5", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.5.tgz", + "integrity": "sha512-lRF8RORchjpKG50/WFf8xmg7sgCLFiYNNnqdKflk63whMQcWR5ngGjiSXkL9bjxy6B2npOK2HSMN49jEBMSkag==", + "dev": true, + "requires": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + }, + "ansi-styles": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "dev": true, + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true + }, + "fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "graceful-fs": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", + "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==", + "dev": true + }, + "har-validator": { + "version": "5.1.5", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.5.tgz", + "integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==", + "dev": true, + "requires": { + "ajv": "^6.12.3", + "har-schema": "^2.0.0" + } + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true + }, + "oauth-sign": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", + "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", + "dev": true + }, + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "dev": true + }, + "request": { + "version": "2.88.2", + "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", + "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==", + "dev": true, + "requires": { + "aws-sign2": "~0.7.0", + "aws4": "^1.8.0", + "caseless": "~0.12.0", + "combined-stream": "~1.0.6", + "extend": "~3.0.2", + "forever-agent": "~0.6.1", + "form-data": "~2.3.2", + "har-validator": "~5.1.3", + "http-signature": "~1.2.0", + "is-typedarray": "~1.0.0", + "isstream": "~0.1.2", + "json-stringify-safe": "~5.0.1", + "mime-types": "~2.1.19", + "oauth-sign": "~0.9.0", + "performance-now": "^2.1.0", + "qs": "~6.5.2", + "safe-buffer": "^5.1.2", + "tough-cookie": "~2.5.0", + "tunnel-agent": "^0.6.0", + "uuid": "^3.3.2" + } + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + }, + "tough-cookie": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", + "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", + "dev": true, + "requires": { + "psl": "^1.1.28", + "punycode": "^2.1.1" + } + } + } + }, "pkg-up": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/pkg-up/-/pkg-up-2.0.0.tgz", @@ -10350,6 +10934,12 @@ "which-pm-runs": "^1.0.0" } }, + "prelude-ls": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", + "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", + "dev": true + }, "prepend-http": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", @@ -10399,6 +10989,12 @@ "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" }, + "progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true + }, "progress-stream": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/progress-stream/-/progress-stream-1.2.0.tgz", @@ -10929,6 +11525,23 @@ "uuid": "^3.1.0" } }, + "request-progress": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/request-progress/-/request-progress-3.0.0.tgz", + "integrity": "sha1-TKdUCBx/7GP1BeT6qCWqBs1mnb4=", + "dev": true, + "requires": { + "throttleit": "^1.0.0" + }, + "dependencies": { + "throttleit": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/throttleit/-/throttleit-1.0.0.tgz", + "integrity": "sha1-nnhYNtr0Z0MUWlmEtiaNgoUorGw=", + "dev": true + } + } + }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -11020,6 +11633,12 @@ "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", "dev": true }, + "reusify": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", + "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dev": true + }, "rimraf": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", @@ -11048,6 +11667,12 @@ "is-promise": "^2.1.0" } }, + "run-parallel": { + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.9.tgz", + "integrity": "sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q==", + "dev": true + }, "run-queue": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/run-queue/-/run-queue-1.0.3.tgz", @@ -11785,6 +12410,15 @@ "xtend": "^4.0.0" } }, + "stream-meter": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/stream-meter/-/stream-meter-1.0.4.tgz", + "integrity": "sha1-Uq+Vql6nYKJJFxZwTb/5D3Ov3R0=", + "dev": true, + "requires": { + "readable-stream": "^2.1.4" + } + }, "stream-shift": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.0.tgz", @@ -12671,6 +13305,15 @@ "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", "optional": true }, + "type-check": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", + "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", + "dev": true, + "requires": { + "prelude-ls": "~1.1.2" + } + }, "type-fest": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", @@ -12716,6 +13359,12 @@ } } }, + "uid2": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/uid2/-/uid2-0.0.3.tgz", + "integrity": "sha1-SDEm4Rd03y9xuLY53NeZw3YWK4I=", + "dev": true + }, "unc-path-regex": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/unc-path-regex/-/unc-path-regex-0.1.2.tgz", @@ -12794,6 +13443,17 @@ "crypto-random-string": "^2.0.0" } }, + "unique-temp-dir": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unique-temp-dir/-/unique-temp-dir-1.0.0.tgz", + "integrity": "sha1-bc6VsmgcoAPuv7MEpBX5y6vMU4U=", + "dev": true, + "requires": { + "mkdirp": "^0.5.1", + "os-tmpdir": "^1.0.1", + "uid2": "0.0.3" + } + }, "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", @@ -14452,6 +15112,12 @@ } } }, + "word-wrap": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", + "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "dev": true + }, "worker-farm": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/worker-farm/-/worker-farm-1.7.0.tgz", diff --git a/package.json b/package.json index 2ebf0de3..9a26468a 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "build:main": "webpack --config webpack.main.js", "build:renderer": "gulp prebuild:renderer && webpack --config webpack.renderer.js", "build:renderer:watch": "gulp prebuild:renderer && webpack --config webpack.renderer.js --watch", + "build:proxy": "tsc --build proxy", "electron": "npm run build:main && concurrently -k -n Main,Rend -c yellow,cyan \"electron --inspect=5858 ./build --watch\" \"npm run build:renderer:watch\"", "clean:dist": "rimraf ./dist/*", "clean:l10n": "git push origin --delete l10n_master", @@ -42,6 +43,7 @@ "pack:mac:masdev": "npm run clean:dist && electron-builder --mac mas-dev -p never", "pack:win": "npm run clean:dist && electron-builder --win --x64 --ia32 -p never -c.win.certificateSubjectName=\"8bit Solutions LLC\"", "pack:win:ci": "npm run clean:dist && electron-builder --win --x64 --ia32 -p never", + "pack:proxy": "pkg build/proxy/app.js --out-path build/proxys", "dist:dir": "npm run build && npm run pack:dir", "dist:lin": "npm run build && npm run pack:lin", "dist:mac": "npm run build && npm run pack:mac", @@ -49,6 +51,7 @@ "dist:mac:masdev": "npm run build && npm run pack:mac:masdev", "dist:win": "npm run build && npm run pack:win", "dist:win:ci": "npm run build && npm run pack:win:ci", + "dist:proxy": "npm run build:proxy && npm run pack:proxy", "publish:lin": "npm run build && npm run clean:dist && electron-builder --linux --x64 -p always", "publish:mac": "npm run build && npm run clean:dist && electron-builder --mac -p always", "publish:mac:mas": "npm run dist:mac:mas && npm run upload:mas", @@ -119,6 +122,12 @@ "portable", "nsis-web", "appx" + ], + "extraResources": [ + { + "from": "build/proxys/app-win.exe", + "to": "proxy.exe" + } ] }, "linux": { @@ -251,17 +260,18 @@ "electron-notarize": "^0.2.1", "electron-rebuild": "^1.9.0", "electron-reload": "^1.5.0", - "mini-css-extract-plugin": "^0.9.0", "file-loader": "^2.0.0", "font-awesome": "4.7.0", "gulp": "^4.0.0", "gulp-google-webfonts": "^2.0.0", "html-loader": "^0.5.5", "html-webpack-plugin": "^3.2.0", + "mini-css-extract-plugin": "^0.9.0", "ngx-infinite-scroll": "7.0.1", "node-abi": "^2.9.0", "node-loader": "^0.6.0", "node-sass": "^4.13.1", + "pkg": "^4.4.9", "rimraf": "^2.6.2", "sass-loader": "^7.1.0", "ts-loader": "^8.0.2", @@ -299,6 +309,7 @@ "keytar": "4.13.0", "lunr": "2.3.3", "node-forge": "0.7.6", + "node-ipc": "^9.1.1", "nord": "0.2.1", "papaparse": "4.6.0", "rxjs": "6.6.2", diff --git a/proxy/app.ts b/proxy/app.ts new file mode 100644 index 00000000..57e1a049 --- /dev/null +++ b/proxy/app.ts @@ -0,0 +1,22 @@ +import NativeMessage from './nativemessage'; +import IPC from './ipc'; + +const args = process.argv.slice(2); + +class Proxy { + ipc: IPC; + nativeMessage: NativeMessage; + + constructor() { + this.ipc = new IPC(); + this.nativeMessage = new NativeMessage(this.ipc); + } + + run() { + this.ipc.connect(); + this.nativeMessage.listen(); + } +} + +const proxy = new Proxy(); +proxy.run(); diff --git a/proxy/global.d.ts b/proxy/global.d.ts new file mode 100644 index 00000000..685934dc --- /dev/null +++ b/proxy/global.d.ts @@ -0,0 +1,4 @@ +declare module 'node-ipc' { + const x: any; + export = x; +} diff --git a/proxy/ipc.ts b/proxy/ipc.ts new file mode 100644 index 00000000..1737750b --- /dev/null +++ b/proxy/ipc.ts @@ -0,0 +1,61 @@ +/* tslint:disable:no-console */ +import * as ipc from 'node-ipc'; +import { spawn } from 'child_process'; + +const StartDesktopCooldown = 60 * 1000; // 1 minute delay between attempts to start desktop + +ipc.config.id = 'proxy'; +ipc.config.retry = 1500; +ipc.config.logger = console.warn; // Stdout is used for native messaging + +export default class IPC { + private connected = false; + private lastStartedDesktop = 0; + + connect() { + ipc.connectTo('bitwarden', () => { + ipc.of.bitwarden.on('connect', () => { + this.connected = true; + console.error( + '## connected to bitwarden desktop ##', + ipc.config.delay + ); + ipc.of.bitwarden.emit('message', 'hello'); + }); + + ipc.of.bitwarden.on('disconnect', () => { + this.connected = false; + console.error('disconnected from world'); + }); + + ipc.of.bitwarden.on('message', (data: any) => { + console.error('got a message from world : ', data); + }); + + ipc.of.bitwarden.on('error', (err: any) => { + if (err.syscall === 'connect' && this.lastStartedDesktop + StartDesktopCooldown < Date.now()) { + this.lastStartedDesktop = Date.now(); + console.error('Attempting to start Bitwarden desktop application'); + this.startDesktop(); + } + console.error('error', err); + }); + }); + } + + isConnected() { + return this.connected; + } + + send(json: object) { + ipc.of.bitwarden.emit('message', json); + } + + // TODO: Do we want to start the desktop application? How do we get the install path? + private startDesktop() { + spawn( + 'C:\\Users\\Oscar\\Documents\\Projects\\Bitwarden\\desktop\\dist\\Bitwarden-Portable-1.22.2.exe', + { detached: true } + ); + } +} diff --git a/proxy/nativemessage.ts b/proxy/nativemessage.ts new file mode 100644 index 00000000..911fe904 --- /dev/null +++ b/proxy/nativemessage.ts @@ -0,0 +1,85 @@ +/* tslint:disable:no-console */ +import IPC from 'ipc'; + +// Mostly copied from the example on +// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging +export default class NativeMessage { + ipc: IPC; + + constructor(ipc: IPC) { + this.ipc = ipc; + } + + send(message: object) { + const messageBuffer = Buffer.from(JSON.stringify(message)); + + const headerBuffer = Buffer.alloc(4); + headerBuffer.writeUInt32LE(messageBuffer.length, 0); + + process.stdout.write(Buffer.concat([headerBuffer, messageBuffer])); + } + + listen() { + let payloadSize: number = null; + + // A queue to store the chunks as we read them from stdin. + // This queue can be flushed when `payloadSize` data has been read + const chunks: any = []; + + // Only read the size once for each payload + const sizeHasBeenRead = () => Boolean(payloadSize); + + // All the data has been read, reset everything for the next message + const flushChunksQueue = () => { + payloadSize = null; + chunks.splice(0); + }; + + const processData = () => { + // Create one big buffer with all all the chunks + const stringData = Buffer.concat(chunks); + console.error(stringData); + + // The browser will emit the size as a header of the payload, + // if it hasn't been read yet, do it. + // The next time we'll need to read the payload size is when all of the data + // of the current payload has been read (ie. data.length >= payloadSize + 4) + if (!sizeHasBeenRead()) { + payloadSize = stringData.readUInt32LE(0); + } + + // If the data we have read so far is >= to the size advertised in the header, + // it means we have all of the data sent. + // We add 4 here because that's the size of the bytes that old the payloadSize + if (stringData.length >= payloadSize + 4) { + // Remove the header + const contentWithoutSize = stringData + .slice(4, payloadSize + 4) + .toString(); + + // Reset the read size and the queued chunks + flushChunksQueue(); + + const json = JSON.parse(contentWithoutSize); + console.error(json); + + // Forward to desktop application + this.ipc.send(json); + } + }; + + process.stdin.on('readable', () => { + // A temporary variable holding the nodejs.Buffer of each + // chunk of data read off stdin + let chunk = null; + + // Read all of the available data + // tslint:disable-next-line:no-conditional-assignment + while ((chunk = process.stdin.read()) !== null) { + chunks.push(chunk); + } + + processData(); + }); + } +} diff --git a/proxy/tsconfig.json b/proxy/tsconfig.json new file mode 100644 index 00000000..e574539a --- /dev/null +++ b/proxy/tsconfig.json @@ -0,0 +1,56 @@ +{ + "compilerOptions": { + "moduleResolution": "node", + "noImplicitAny": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "module": "CommonJS", + "target": "ES2016", + "allowJs": true, + "sourceMap": true, + "types": ["sweetalert2", "node"], + "baseUrl": ".", + "outDir": "../build/proxy", + "paths": { + "tldjs": [ + "jslib/src/misc/tldjs.noop" + ], + "jslib/*": [ + "jslib/src/*" + ], + "@angular/*": [ + "node_modules/@angular/*" + ], + "electron": [ + "node_modules/electron" + ], + "electron-log": [ + "node_modules/electron-log" + ], + "electron-store": [ + "node_modules/electron-store" + ], + "node": [ + "node_modules/@types/node" + ], + "duo_web_sdk": [ + "node_modules/duo_web_sdk" + ] + } + }, + "angularCompilerOptions": { + "preserveWhitespaces": true + }, + "exclude": [ + "node_modules", + "jslib/node_modules", + "dist", + "dist-safari", + "jslib/dist", + "build", + "jslib/spec", + "jslib/src/cli", + "jslib/src/services/nodeApi.service.ts", + "jslib/src/services/lowdbStorage.service.ts" + ] +} diff --git a/scripts/chrome.json b/scripts/chrome.json new file mode 100644 index 00000000..15c5a491 --- /dev/null +++ b/scripts/chrome.json @@ -0,0 +1,7 @@ +{ + "name": "com.8bit.bitwarden", + "description": "Bitwarden Desktop Bridge", + "path": "C:\\Users\\Oscar\\Documents\\Projects\\Bitwarden\\desktop\\build\\proxys\\app-win.exe", + "type": "stdio", + "allowed_origins": ["chrome-extension://ijeheppnniijonkinoakkofcdhdfojda/"] +} diff --git a/src/global.d.ts b/src/global.d.ts index 4859a086..4fe5b43f 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,2 +1,6 @@ declare function escape(s: string): string; declare function unescape(s: string): string; +declare module 'node-ipc' { + const x: any; + export = x; +} diff --git a/src/main.ts b/src/main.ts index e582c4cf..0a12dc29 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,6 +18,7 @@ import { ElectronStorageService } from 'jslib/electron/services/electronStorage. import { TrayMain } from 'jslib/electron/tray.main'; import { UpdaterMain } from 'jslib/electron/updater.main'; import { WindowMain } from 'jslib/electron/window.main'; +import { NativeMessagingService } from './services/nativeMessaging.service'; export class Main { logService: ElectronLogService; @@ -33,6 +34,7 @@ export class Main { powerMonitorMain: PowerMonitorMain; trayMain: TrayMain; biometricMain: BiometricMain; + nativeMessagingService: NativeMessagingService; constructor() { // Set paths for portable builds @@ -116,6 +118,8 @@ export class Main { const BiometricDarwinMain = require('jslib/electron/biometric.darwin.main').default; this.biometricMain = new BiometricDarwinMain(this.storageService, this.i18nService); } + + this.nativeMessagingService = new NativeMessagingService(); } bootstrap() { @@ -153,6 +157,7 @@ export class Main { // tslint:disable-next-line console.error(e); }); + this.nativeMessagingService.listen(); } private processDeepLink(argv: string[]): void { diff --git a/src/package.json b/src/package.json index c4677395..7cb1060f 100644 --- a/src/package.json +++ b/src/package.json @@ -19,6 +19,7 @@ "electron-store": "1.3.0", "electron-updater": "4.3.5", "keytar": "4.13.0", + "node-ipc": "^9.1.1", "zxcvbn": "4.4.2" } } diff --git a/src/services/nativeMessaging.service.ts b/src/services/nativeMessaging.service.ts new file mode 100644 index 00000000..5af2647e --- /dev/null +++ b/src/services/nativeMessaging.service.ts @@ -0,0 +1,33 @@ +import * as ipc from 'node-ipc'; + +export class NativeMessagingService { + private connected = false; + + listen() { + ipc.config.id = 'bitwarden'; + ipc.config.retry = 1500; + + ipc.serve(() => { + ipc.server.on('message', (data: any, socket: any) => { + ipc.log('got a message : ', data); + ipc.server.emit(socket, 'message', data + ' world!'); + }); + + ipc.server.on('connect', () => { + this.connected = true; + }) + + ipc.server.on( + 'socket.disconnected', + (socket: any, destroyedSocketID: any) => { + this.connected = false; + ipc.log( + 'client ' + destroyedSocketID + ' has disconnected!' + ); + } + ); + }); + + ipc.server.start(); + } +} diff --git a/tsconfig.json b/tsconfig.json index bd8e9add..1d1e1899 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -43,6 +43,7 @@ "exclude": [ "node_modules", "jslib/node_modules", + "proxy", "dist", "dist-safari", "jslib/dist", From 24ef7e1ef6e40211d8a0d80f324948a1439da1ae Mon Sep 17 00:00:00 2001 From: Hinton Date: Mon, 5 Oct 2020 19:48:51 +0200 Subject: [PATCH 02/33] Generate app manifests and add install scripts for windows --- package-lock.json | 53 +++++++++++++++ package.json | 8 +++ proxy/ipc.ts | 21 +----- scripts/chrome.json | 7 -- src/main.ts | 4 +- src/services/nativeMessaging.service.ts | 87 +++++++++++++++++++++++++ 6 files changed, 154 insertions(+), 26 deletions(-) delete mode 100644 scripts/chrome.json diff --git a/package-lock.json b/package-lock.json index 4ee0a01a..9fbb1d11 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7559,6 +7559,11 @@ "integrity": "sha512-GguP+DRY+pJ3soyIiGPTvdiVXjZ+DbXOxGpXn3eMvNW4x4irjqXm4wHKscC+TfxSJ0yw/S1F24tqdMNsMZTiLA==", "dev": true }, + "if-async": { + "version": "3.7.4", + "resolved": "https://registry.npmjs.org/if-async/-/if-async-3.7.4.tgz", + "integrity": "sha1-VYaN6wCT08Z79xZudFNT+5vLIaI=" + }, "iferr": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/iferr/-/iferr-0.1.5.tgz", @@ -11339,6 +11344,49 @@ "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==", "dev": true }, + "regedit": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/regedit/-/regedit-3.0.3.tgz", + "integrity": "sha512-SpHmMKOtiEYx0MiRRC48apBsmThoZ4svZNsYoK8leHd5bdUHV1nYb8pk8gh6Moou7/S9EDi1QsjBTpyXVQrPuQ==", + "requires": { + "debug": "^4.1.0", + "if-async": "^3.7.4", + "stream-slicer": "0.0.6", + "through2": "^0.6.3" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "readable-stream": { + "version": "1.0.34", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", + "integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + }, + "through2": { + "version": "0.6.5", + "resolved": "https://registry.npmjs.org/through2/-/through2-0.6.5.tgz", + "integrity": "sha1-QaucZ7KdVyCQcUEOHXp6lozTrUg=", + "requires": { + "readable-stream": ">=1.0.33-1 <1.1.0-0", + "xtend": ">=4.0.0 <4.1.0-0" + } + } + } + }, "regenerate": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz", @@ -12425,6 +12473,11 @@ "integrity": "sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=", "dev": true }, + "stream-slicer": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/stream-slicer/-/stream-slicer-0.0.6.tgz", + "integrity": "sha1-+GsqxcJEC3oKh7cfM2ZcB4gEYTg=" + }, "strict-uri-encode": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz", diff --git a/package.json b/package.json index 9a26468a..f41ca3cf 100644 --- a/package.json +++ b/package.json @@ -127,6 +127,13 @@ { "from": "build/proxys/app-win.exe", "to": "proxy.exe" + }, + { + "from": "node_modules/regedit/vbs", + "to": "regedit/vbs", + "filter": [ + "**/*" + ] } ] }, @@ -312,6 +319,7 @@ "node-ipc": "^9.1.1", "nord": "0.2.1", "papaparse": "4.6.0", + "regedit": "^3.0.3", "rxjs": "6.6.2", "sweetalert2": "9.8.1", "tslib": "^2.0.1", diff --git a/proxy/ipc.ts b/proxy/ipc.ts index 1737750b..a8be8ac1 100644 --- a/proxy/ipc.ts +++ b/proxy/ipc.ts @@ -1,8 +1,5 @@ /* tslint:disable:no-console */ import * as ipc from 'node-ipc'; -import { spawn } from 'child_process'; - -const StartDesktopCooldown = 60 * 1000; // 1 minute delay between attempts to start desktop ipc.config.id = 'proxy'; ipc.config.retry = 1500; @@ -10,7 +7,6 @@ ipc.config.logger = console.warn; // Stdout is used for native messaging export default class IPC { private connected = false; - private lastStartedDesktop = 0; connect() { ipc.connectTo('bitwarden', () => { @@ -32,30 +28,19 @@ export default class IPC { console.error('got a message from world : ', data); }); + /* ipc.of.bitwarden.on('error', (err: any) => { - if (err.syscall === 'connect' && this.lastStartedDesktop + StartDesktopCooldown < Date.now()) { - this.lastStartedDesktop = Date.now(); - console.error('Attempting to start Bitwarden desktop application'); - this.startDesktop(); - } console.error('error', err); }); + */ }); } - isConnected() { + isConnected(): boolean { return this.connected; } send(json: object) { ipc.of.bitwarden.emit('message', json); } - - // TODO: Do we want to start the desktop application? How do we get the install path? - private startDesktop() { - spawn( - 'C:\\Users\\Oscar\\Documents\\Projects\\Bitwarden\\desktop\\dist\\Bitwarden-Portable-1.22.2.exe', - { detached: true } - ); - } } diff --git a/scripts/chrome.json b/scripts/chrome.json deleted file mode 100644 index 15c5a491..00000000 --- a/scripts/chrome.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "com.8bit.bitwarden", - "description": "Bitwarden Desktop Bridge", - "path": "C:\\Users\\Oscar\\Documents\\Projects\\Bitwarden\\desktop\\build\\proxys\\app-win.exe", - "type": "stdio", - "allowed_origins": ["chrome-extension://ijeheppnniijonkinoakkofcdhdfojda/"] -} diff --git a/src/main.ts b/src/main.ts index 0a12dc29..450ac644 100644 --- a/src/main.ts +++ b/src/main.ts @@ -119,7 +119,7 @@ export class Main { this.biometricMain = new BiometricDarwinMain(this.storageService, this.i18nService); } - this.nativeMessagingService = new NativeMessagingService(); + this.nativeMessagingService = new NativeMessagingService(app.getPath('userData'), app.getAppPath()); } bootstrap() { @@ -158,6 +158,8 @@ export class Main { console.error(e); }); this.nativeMessagingService.listen(); + this.nativeMessagingService.generateManifests(); + this.nativeMessagingService.enableManifest(); } private processDeepLink(argv: string[]): void { diff --git a/src/services/nativeMessaging.service.ts b/src/services/nativeMessaging.service.ts index 5af2647e..236f5ff4 100644 --- a/src/services/nativeMessaging.service.ts +++ b/src/services/nativeMessaging.service.ts @@ -1,8 +1,13 @@ +import * as fs from 'fs'; import * as ipc from 'node-ipc'; +import * as path from 'path'; +import * as util from 'util'; export class NativeMessagingService { private connected = false; + constructor(private userPath: string, private appPath: string) {} + listen() { ipc.config.id = 'bitwarden'; ipc.config.retry = 1500; @@ -30,4 +35,86 @@ export class NativeMessagingService { ipc.server.start(); } + + generateManifests() { + const baseJson = { + 'name': 'com.8bit.bitwarden', + 'description': 'Bitwarden desktop <-> browser bridge', + 'path': path.join(this.appPath, 'proxys', this.binaryName()), + 'type': 'stdio', + } + + const firefoxJson = {...baseJson, ...{ 'allowed_origins': ['446900e4-71c2-419f-a6a7-df9c091e268b']}} + const chromeJson = {...baseJson, ...{ 'allowed_origins': ['chrome-extension://ijeheppnniijonkinoakkofcdhdfojda/']}} + + fs.mkdir(path.join(this.userPath, 'browsers'), (err) => console.log); + + this.writeManifest('firefox.json', firefoxJson); + this.writeManifest('chrome.json', chromeJson); + } + + private writeManifest(filename: string, manifest: object) { + fs.writeFile( + path.join(this.userPath, 'browsers', filename), + JSON.stringify(manifest, null, 2), + (err) => console.log + ); + } + + private binaryName() { + switch (process.platform) { + case 'win32': + return 'app-win.exe' + case 'darwin': + return 'app-linux' + case 'linux': + default: + return 'app-macos' + } + } + + // Setup registry and/or directories + // TODO: Do other browsers use different directories? + enableManifest() { + switch (process.platform) { + case 'win32': + this.createWindowsRegistry('HKLM\\SOFTWARE\\Mozilla\\Firefox', 'HKCU\\SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.8bit.bitwarden', 'firefox.json') + this.createWindowsRegistry('HKCU\\SOFTWARE\\Google\\Chrome', 'HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.8bit.bitwarden', 'chrome.json') + break; + case 'darwin': + break; + case 'linux': + default: + break; + } + } + + private createWindowsRegistry(check: string, location: string, jsonFile: string) { + const regedit = require('regedit'); + regedit.setExternalVBSLocation('resources/regedit/vbs'); + + const list = util.promisify(regedit.list); + const createKey = util.promisify(regedit.createKey); + const putValue = util.promisify(regedit.putValue); + + // Check installed + list(check) + .then(() => { + // Create path + return createKey(location); + }) + .then(() => { + // Insert path to manifest + const obj: any = {}; + obj[location] = { + 'default': { + value: path.join(this.userPath, 'browsers', jsonFile), + type: 'REG_DEFAULT', + }, + } + + return putValue(obj); + }) + .catch() + } } From 830c4a45ee86ab4328d835c46b1fc352a88c4136 Mon Sep 17 00:00:00 2001 From: Hinton Date: Mon, 5 Oct 2020 20:05:48 +0200 Subject: [PATCH 03/33] Replace cosole logs with logService --- src/main.ts | 2 +- src/services/nativeMessaging.service.ts | 54 ++++++++++++++----------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/main.ts b/src/main.ts index 450ac644..142f03de 100644 --- a/src/main.ts +++ b/src/main.ts @@ -119,7 +119,7 @@ export class Main { this.biometricMain = new BiometricDarwinMain(this.storageService, this.i18nService); } - this.nativeMessagingService = new NativeMessagingService(app.getPath('userData'), app.getAppPath()); + this.nativeMessagingService = new NativeMessagingService(this.logService, app.getPath('userData'), app.getAppPath()); } bootstrap() { diff --git a/src/services/nativeMessaging.service.ts b/src/services/nativeMessaging.service.ts index 236f5ff4..ffe57652 100644 --- a/src/services/nativeMessaging.service.ts +++ b/src/services/nativeMessaging.service.ts @@ -1,12 +1,14 @@ -import * as fs from 'fs'; +import { promises as fs, existsSync } from 'fs'; import * as ipc from 'node-ipc'; import * as path from 'path'; import * as util from 'util'; +import { LogService } from 'jslib/abstractions/log.service'; + export class NativeMessagingService { private connected = false; - constructor(private userPath: string, private appPath: string) {} + constructor(private logService: LogService, private userPath: string, private appPath: string) {} listen() { ipc.config.id = 'bitwarden'; @@ -47,32 +49,15 @@ export class NativeMessagingService { const firefoxJson = {...baseJson, ...{ 'allowed_origins': ['446900e4-71c2-419f-a6a7-df9c091e268b']}} const chromeJson = {...baseJson, ...{ 'allowed_origins': ['chrome-extension://ijeheppnniijonkinoakkofcdhdfojda/']}} - fs.mkdir(path.join(this.userPath, 'browsers'), (err) => console.log); + if (!existsSync(path.join(this.userPath, 'browsers'))) { + fs.mkdir(path.join(this.userPath, 'browsers')) + .catch(this.logService.error) + } this.writeManifest('firefox.json', firefoxJson); this.writeManifest('chrome.json', chromeJson); } - private writeManifest(filename: string, manifest: object) { - fs.writeFile( - path.join(this.userPath, 'browsers', filename), - JSON.stringify(manifest, null, 2), - (err) => console.log - ); - } - - private binaryName() { - switch (process.platform) { - case 'win32': - return 'app-win.exe' - case 'darwin': - return 'app-linux' - case 'linux': - default: - return 'app-macos' - } - } - // Setup registry and/or directories // TODO: Do other browsers use different directories? enableManifest() { @@ -89,6 +74,25 @@ export class NativeMessagingService { } } + private writeManifest(filename: string, manifest: object) { + fs.writeFile( + path.join(this.userPath, 'browsers', filename), + JSON.stringify(manifest, null, 2) + ).catch(this.logService.error); + } + + private binaryName() { + switch (process.platform) { + case 'win32': + return 'app-win.exe' + case 'darwin': + return 'app-linux' + case 'linux': + default: + return 'app-macos' + } + } + private createWindowsRegistry(check: string, location: string, jsonFile: string) { const regedit = require('regedit'); regedit.setExternalVBSLocation('resources/regedit/vbs'); @@ -97,6 +101,8 @@ export class NativeMessagingService { const createKey = util.promisify(regedit.createKey); const putValue = util.promisify(regedit.putValue); + this.logService.debug(`Adding registry: ${location}`) + // Check installed list(check) .then(() => { @@ -115,6 +121,6 @@ export class NativeMessagingService { return putValue(obj); }) - .catch() + .catch(this.logService.error) } } From cb9c0b318e079fad815f2bf626a5d623f1247f29 Mon Sep 17 00:00:00 2001 From: Hinton Date: Mon, 5 Oct 2020 20:28:00 +0200 Subject: [PATCH 04/33] Add untested support for linux and macos --- src/main.ts | 1 - src/services/nativeMessaging.service.ts | 41 ++++++++++++++++--------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/main.ts b/src/main.ts index 142f03de..ede80322 100644 --- a/src/main.ts +++ b/src/main.ts @@ -159,7 +159,6 @@ export class Main { }); this.nativeMessagingService.listen(); this.nativeMessagingService.generateManifests(); - this.nativeMessagingService.enableManifest(); } private processDeepLink(argv: string[]): void { diff --git a/src/services/nativeMessaging.service.ts b/src/services/nativeMessaging.service.ts index ffe57652..1b9c2575 100644 --- a/src/services/nativeMessaging.service.ts +++ b/src/services/nativeMessaging.service.ts @@ -54,31 +54,44 @@ export class NativeMessagingService { .catch(this.logService.error) } - this.writeManifest('firefox.json', firefoxJson); - this.writeManifest('chrome.json', chromeJson); - } - - // Setup registry and/or directories - // TODO: Do other browsers use different directories? - enableManifest() { switch (process.platform) { case 'win32': - this.createWindowsRegistry('HKLM\\SOFTWARE\\Mozilla\\Firefox', 'HKCU\\SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.8bit.bitwarden', 'firefox.json') - this.createWindowsRegistry('HKCU\\SOFTWARE\\Google\\Chrome', 'HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.8bit.bitwarden', 'chrome.json') + const destination = path.join(this.userPath, 'browsers') + this.writeManifest(path.join(destination, 'firefox.json'), firefoxJson); + this.writeManifest(path.join(destination, 'chrome.json'), chromeJson); + + this.createWindowsRegistry('HKLM\\SOFTWARE\\Mozilla\\Firefox', 'HKCU\\SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.8bit.bitwarden', path.join(destination, 'firefox.json')) + this.createWindowsRegistry('HKCU\\SOFTWARE\\Google\\Chrome', 'HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.8bit.bitwarden', path.join(destination, 'chrome.json')) break; case 'darwin': + if (existsSync('~/Library/Application Support/Mozilla/')) { + fs.mkdir('~/Library/Application Support/Mozilla/NativeMessagingHosts/'); + this.writeManifest('~/Library/Application Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json', firefoxJson); + } + + if (existsSync('~/Library/Application Support/Google/Chrome/')) { + fs.mkdir('~/Library/Application Support/Google/Chrome/NativeMessagingHosts/'); + this.writeManifest('~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.8bit.bitwarden.json', chromeJson); + } break; case 'linux': + if (existsSync('~/.mozilla/')) { + fs.mkdir('~/.mozilla/native-messaging-hosts'); + this.writeManifest('~/.mozilla/native-messaging-hosts/com.8bit.bitwarden.json', firefoxJson); + } + + if (existsSync('~/.config/google-chrome/')) { + fs.mkdir('~/.config/google-chrome/NativeMessagingHosts/'); + this.writeManifest('~/.config/google-chrome/NativeMessagingHosts/com.8bit.bitwarden.json', chromeJson); + } + break; default: break; } } - private writeManifest(filename: string, manifest: object) { - fs.writeFile( - path.join(this.userPath, 'browsers', filename), - JSON.stringify(manifest, null, 2) - ).catch(this.logService.error); + private writeManifest(destination: string, manifest: object) { + fs.writeFile(destination, JSON.stringify(manifest, null, 2)).catch(this.logService.error); } private binaryName() { From 19edc24b0bde02920c7cad7a136ddf57bd27104d Mon Sep 17 00:00:00 2001 From: Hinton Date: Mon, 5 Oct 2020 20:58:58 +0200 Subject: [PATCH 05/33] Add extraResources to linux and mac --- package.json | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f41ca3cf..fffd95a4 100644 --- a/package.json +++ b/package.json @@ -114,6 +114,12 @@ "target": [ "dmg", "zip" + ], + "extraResources": [ + { + "from": "build/proxys/app-macos", + "to": "proxy" + } ] }, "win": { @@ -151,7 +157,13 @@ "Name": "Bitwarden", "Type": "Application", "GenericName": "Password Manager" - } + }, + "extraResources": [ + { + "from": "build/proxys/app-linux", + "to": "proxy" + } + ] }, "dmg": { "icon": "dmg.icns", From 45302e5bd543c12734c5b810e79d73bd23f57b4a Mon Sep 17 00:00:00 2001 From: Hinton Date: Wed, 7 Oct 2020 15:11:01 +0200 Subject: [PATCH 06/33] Add settings toggle to enable/disable browser integration --- proxy/nativemessage.ts | 2 +- src/app/accounts/settings.component.html | 10 +++ src/app/accounts/settings.component.ts | 7 ++ src/locales/en/messages.json | 6 ++ src/main.ts | 6 +- src/main/messaging.main.ts | 8 +++ src/services/nativeMessaging.service.ts | 89 +++++++++++++++++++----- 7 files changed, 107 insertions(+), 21 deletions(-) diff --git a/proxy/nativemessage.ts b/proxy/nativemessage.ts index 911fe904..0af48d98 100644 --- a/proxy/nativemessage.ts +++ b/proxy/nativemessage.ts @@ -1,7 +1,7 @@ /* tslint:disable:no-console */ import IPC from 'ipc'; -// Mostly copied from the example on +// Mostly based on the example from MDN, // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging export default class NativeMessage { ipc: IPC; diff --git a/src/app/accounts/settings.component.html b/src/app/accounts/settings.component.html index f54b90a2..ffc57907 100644 --- a/src/app/accounts/settings.component.html +++ b/src/app/accounts/settings.component.html @@ -88,6 +88,16 @@ {{'disableFaviconDesc' | i18n}} +
+
+ +
+ {{'enableBrowserIntegrationDesc' | i18n}} +