NsisUpdater.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.NsisUpdater = void 0;
  6. function _bluebirdLst() {
  7. const data = require("bluebird-lst");
  8. _bluebirdLst = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _builderUtilRuntime() {
  14. const data = require("builder-util-runtime");
  15. _builderUtilRuntime = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _child_process() {
  21. const data = require("child_process");
  22. _child_process = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. var path = _interopRequireWildcard(require("path"));
  28. require("source-map-support/register");
  29. function _BaseUpdater() {
  30. const data = require("./BaseUpdater");
  31. _BaseUpdater = function () {
  32. return data;
  33. };
  34. return data;
  35. }
  36. function _FileWithEmbeddedBlockMapDifferentialDownloader() {
  37. const data = require("./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader");
  38. _FileWithEmbeddedBlockMapDifferentialDownloader = function () {
  39. return data;
  40. };
  41. return data;
  42. }
  43. function _GenericDifferentialDownloader() {
  44. const data = require("./differentialDownloader/GenericDifferentialDownloader");
  45. _GenericDifferentialDownloader = function () {
  46. return data;
  47. };
  48. return data;
  49. }
  50. function _main() {
  51. const data = require("./main");
  52. _main = function () {
  53. return data;
  54. };
  55. return data;
  56. }
  57. function _Provider() {
  58. const data = require("./Provider");
  59. _Provider = function () {
  60. return data;
  61. };
  62. return data;
  63. }
  64. function _fsExtraP() {
  65. const data = require("fs-extra-p");
  66. _fsExtraP = function () {
  67. return data;
  68. };
  69. return data;
  70. }
  71. function _windowsExecutableCodeSignatureVerifier() {
  72. const data = require("./windowsExecutableCodeSignatureVerifier");
  73. _windowsExecutableCodeSignatureVerifier = function () {
  74. return data;
  75. };
  76. return data;
  77. }
  78. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  79. class NsisUpdater extends _BaseUpdater().BaseUpdater {
  80. constructor(options, app) {
  81. super(options, app);
  82. }
  83. /*** @private */
  84. doDownloadUpdate(updateInfo, cancellationToken) {
  85. var _this = this;
  86. return (0, _bluebirdLst().coroutine)(function* () {
  87. const provider = yield _this.provider;
  88. const fileInfo = (0, _Provider().findFile)(provider.resolveFiles(updateInfo), "exe");
  89. const requestHeaders = yield _this.computeRequestHeaders();
  90. const downloadOptions = {
  91. skipDirCreation: true,
  92. headers: requestHeaders,
  93. cancellationToken,
  94. sha512: fileInfo.info.sha512
  95. };
  96. return yield _this.executeDownload({
  97. fileExtension: "exe",
  98. downloadOptions,
  99. fileInfo,
  100. updateInfo,
  101. task: (() => {
  102. var _ref = (0, _bluebirdLst().coroutine)(function* (destinationFile, packageFile, removeTempDirIfAny) {
  103. if (yield _this.differentialDownloadInstaller(fileInfo, destinationFile, requestHeaders, provider)) {
  104. yield _this.httpExecutor.download(fileInfo.url.href, destinationFile, downloadOptions);
  105. }
  106. const signatureVerificationStatus = yield _this.verifySignature(destinationFile);
  107. if (signatureVerificationStatus != null) {
  108. yield removeTempDirIfAny(); // noinspection ThrowInsideFinallyBlockJS
  109. throw (0, _builderUtilRuntime().newError)(`New version ${updateInfo.version} is not signed by the application owner: ${signatureVerificationStatus}`, "ERR_UPDATER_INVALID_SIGNATURE");
  110. }
  111. const packageInfo = fileInfo.packageInfo;
  112. if (packageInfo != null && packageFile != null) {
  113. if (yield _this.differentialDownloadWebPackage(packageInfo, packageFile, provider)) {
  114. try {
  115. yield _this.httpExecutor.download(packageInfo.path, packageFile, {
  116. skipDirCreation: true,
  117. headers: requestHeaders,
  118. cancellationToken,
  119. sha512: packageInfo.sha512
  120. });
  121. } catch (e) {
  122. try {
  123. yield (0, _fsExtraP().unlink)(packageFile);
  124. } catch (ignored) {// ignore
  125. }
  126. throw e;
  127. }
  128. }
  129. }
  130. });
  131. return function task(_x, _x2, _x3) {
  132. return _ref.apply(this, arguments);
  133. };
  134. })()
  135. });
  136. })();
  137. } // $certificateInfo = (Get-AuthenticodeSignature 'xxx\yyy.exe'
  138. // | where {$_.Status.Equals([System.Management.Automation.SignatureStatus]::Valid) -and $_.SignerCertificate.Subject.Contains("CN=siemens.com")})
  139. // | Out-String ; if ($certificateInfo) { exit 0 } else { exit 1 }
  140. verifySignature(tempUpdateFile) {
  141. var _this2 = this;
  142. return (0, _bluebirdLst().coroutine)(function* () {
  143. let publisherName;
  144. try {
  145. publisherName = (yield _this2.configOnDisk.value).publisherName;
  146. if (publisherName == null) {
  147. return null;
  148. }
  149. } catch (e) {
  150. if (e.code === "ENOENT") {
  151. // no app-update.yml
  152. return null;
  153. }
  154. throw e;
  155. }
  156. return yield (0, _windowsExecutableCodeSignatureVerifier().verifySignature)(Array.isArray(publisherName) ? publisherName : [publisherName], tempUpdateFile, _this2._logger);
  157. })();
  158. }
  159. doInstall(installerPath, isSilent, isForceRunAfter) {
  160. const args = ["--updated"];
  161. if (isSilent) {
  162. args.push("/S");
  163. }
  164. if (isForceRunAfter) {
  165. args.push("--force-run");
  166. }
  167. const packagePath = this.downloadedUpdateHelper.packageFile;
  168. if (packagePath != null) {
  169. // only = form is supported
  170. args.push(`--package-file="${packagePath}"`);
  171. }
  172. const spawnOptions = {
  173. detached: true,
  174. stdio: "ignore"
  175. };
  176. try {
  177. (0, _child_process().spawn)(installerPath, args, spawnOptions).unref();
  178. } catch (e) {
  179. // yes, such errors dispatched not as error event
  180. // https://github.com/electron-userland/electron-builder/issues/1129
  181. if (e.code === "UNKNOWN" || e.code === "EACCES") {
  182. // Node 8 sends errors: https://nodejs.org/dist/latest-v8.x/docs/api/errors.html#errors_common_system_errors
  183. this._logger.info("Access denied or UNKNOWN error code on spawn, will be executed again using elevate");
  184. try {
  185. (0, _child_process().spawn)(path.join(process.resourcesPath, "elevate.exe"), [installerPath].concat(args), spawnOptions).unref();
  186. } catch (e) {
  187. this.dispatchError(e);
  188. }
  189. } else {
  190. this.dispatchError(e);
  191. }
  192. }
  193. return true;
  194. }
  195. differentialDownloadInstaller(fileInfo, installerPath, requestHeaders, provider) {
  196. var _this3 = this;
  197. return (0, _bluebirdLst().coroutine)(function* () {
  198. if (process.env.__NSIS_DIFFERENTIAL_UPDATE__ == null) {
  199. return true;
  200. }
  201. try {
  202. const blockMapData = JSON.parse((yield provider.httpRequest((0, _main().newUrlFromBase)(`${fileInfo.url.pathname}.blockMap.json`, fileInfo.url, true))));
  203. yield new (_GenericDifferentialDownloader().GenericDifferentialDownloader)(fileInfo.info, _this3.httpExecutor, {
  204. newUrl: fileInfo.url.href,
  205. oldFile: path.join(_this3.app.getPath("userData"), "installer.exe"),
  206. logger: _this3._logger,
  207. newFile: installerPath,
  208. useMultipleRangeRequest: provider.useMultipleRangeRequest,
  209. requestHeaders
  210. }).download(blockMapData);
  211. } catch (e) {
  212. _this3._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`); // during test (developer machine mac) we must throw error
  213. return process.platform === "win32";
  214. }
  215. return false;
  216. })();
  217. }
  218. differentialDownloadWebPackage(packageInfo, packagePath, provider) {
  219. var _this4 = this;
  220. return (0, _bluebirdLst().coroutine)(function* () {
  221. if (packageInfo.blockMapSize == null) {
  222. return true;
  223. }
  224. try {
  225. yield new (_FileWithEmbeddedBlockMapDifferentialDownloader().FileWithEmbeddedBlockMapDifferentialDownloader)(packageInfo, _this4.httpExecutor, {
  226. newUrl: packageInfo.path,
  227. oldFile: path.join(process.resourcesPath, "..", "package.7z"),
  228. logger: _this4._logger,
  229. newFile: packagePath,
  230. requestHeaders: _this4.requestHeaders,
  231. useMultipleRangeRequest: provider.useMultipleRangeRequest
  232. }).download();
  233. } catch (e) {
  234. _this4._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`); // during test (developer machine mac or linux) we must throw error
  235. return process.platform === "win32";
  236. }
  237. return false;
  238. })();
  239. }
  240. } exports.NsisUpdater = NsisUpdater;
  241. //# sourceMappingURL=NsisUpdater.js.map