diff --git a/src/platform.ts b/src/platform.ts index 34810889..ee205da6 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -137,6 +137,9 @@ export class App { await this.removeDefaultApp(); if (this.opts.prebuiltAsar) { await this.copyPrebuiltAsar(); + this.asarIntegrity = { + [this.appRelativePath(this.appAsarPath)]: this.getAsarIntegrity(this.appAsarPath), + }; } else { await this.buildApp(); } @@ -243,18 +246,22 @@ export class App { await promisifyHooks(this.opts.beforeAsar, this.hookArgsWithOriginalResourcesAppDir); await asar.createPackageWithOptions(this.originalResourcesAppDir, this.appAsarPath, this.asarOptions); - const { headerString } = asar.getRawHeader(this.appAsarPath); this.asarIntegrity = { - [this.appRelativePath(this.appAsarPath)]: { - algorithm: 'SHA256', - hash: crypto.createHash('SHA256').update(headerString).digest('hex'), - }, + [this.appRelativePath(this.appAsarPath)]: this.getAsarIntegrity(this.appAsarPath), }; await fs.remove(this.originalResourcesAppDir); await promisifyHooks(this.opts.afterAsar, this.hookArgsWithOriginalResourcesAppDir); } + getAsarIntegrity(path: string): Pick { + const { headerString } = asar.getRawHeader(path); + return { + algorithm: 'SHA256', + hash: crypto.createHash('SHA256').update(headerString).digest('hex'), + }; + } + async copyExtraResources() { if (!this.opts.extraResource) { return Promise.resolve(); diff --git a/test/darwin.js b/test/darwin.js index b8a0dc1e..cc4aba72 100644 --- a/test/darwin.js +++ b/test/darwin.js @@ -498,4 +498,22 @@ if (!(process.env.CI && process.platform === 'win32')) { } }) })) + + test.serial('prebuilt asar integrity hashes are automatically inserted', darwinTest(async (t, baseOpts) => { + const opts = { + ...baseOpts, + dir: util.fixtureSubdir('asar-prebuilt') + } + opts.prebuiltAsar = path.join(opts.dir, 'app.asar') + const finalPath = (await packager(opts))[0] + const plistObj = await parseInfoPlist(t, opts, finalPath) + t.is(typeof plistObj.ElectronAsarIntegrity, 'object') + // Note: If you update test/fixtures/asar-prebuilt/app.asar, ths hash should also be updated. + t.deepEqual(plistObj.ElectronAsarIntegrity, { + 'Resources/app.asar': { + algorithm: 'SHA256', + hash: '5efe069acf1f8d2622f2da149fcedcd5e17f9e7f4bc6f7ffe89255ee96647d4f' + } + }) + })) }