Skip to content

Commit

Permalink
include asar integrity when using --prebuilt-asar
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrostfigma committed Aug 13, 2024
1 parent 426b886 commit 2a77d23
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<FileRecord['integrity'], 'algorithm' | 'hash'> {
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();
Expand Down
18 changes: 18 additions & 0 deletions test/darwin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
})
}))
}

0 comments on commit 2a77d23

Please sign in to comment.