fix: Allow EnableEmbeddedAsarIntegrityValidation when multiple asars are present in app (#124)
- When an application uses multiple asars (`webapp.asar`, `anything.asar`, etc.), `EnableEmbeddedAsarIntegrityValidation` fuse breaks the application due to not all asars having integrity generated for them. Fixes: #116 - **Also fixes bug** to correctly test `makeUniversalApp no asar mode should shim two different app folders`, (it was not having an asar integrity generated for the shimmed asar) Functionality added: - Moves all asar integrity generation to **after** all app assets have been merged/shimmed/copied. This allows other asars that were provided to also be scanned and have asar integrity generated for them. - Extracted common Integrity logic to a single file `integrity.ts` - Adds unit test for multi-asar apps
This commit is contained in:
51
src/integrity.ts
Normal file
51
src/integrity.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import * as fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { AppFileType, getAllAppFiles } from './file-utils';
|
||||
import { sha } from './sha';
|
||||
import { generateAsarIntegrity } from './asar-utils';
|
||||
|
||||
type IntegrityMap = {
|
||||
[filepath: string]: string;
|
||||
};
|
||||
|
||||
export interface HeaderHash {
|
||||
algorithm: 'SHA256';
|
||||
hash: string;
|
||||
}
|
||||
|
||||
export interface AsarIntegrity {
|
||||
[key: string]: HeaderHash;
|
||||
}
|
||||
|
||||
export async function computeIntegrityData(contentsPath: string): Promise<AsarIntegrity> {
|
||||
const root = await fs.realpath(contentsPath);
|
||||
|
||||
const resourcesRelativePath = 'Resources';
|
||||
const resourcesPath = path.resolve(root, resourcesRelativePath);
|
||||
|
||||
const resources = await getAllAppFiles(resourcesPath);
|
||||
const resourceAsars = resources
|
||||
.filter((file) => file.type === AppFileType.APP_CODE)
|
||||
.reduce<IntegrityMap>(
|
||||
(prev, file) => ({
|
||||
...prev,
|
||||
[path.join(resourcesRelativePath, file.relativePath)]: path.join(
|
||||
resourcesPath,
|
||||
file.relativePath,
|
||||
),
|
||||
}),
|
||||
{},
|
||||
);
|
||||
|
||||
// sort to produce constant result
|
||||
const allAsars = Object.entries(resourceAsars).sort(([name1], [name2]) =>
|
||||
name1.localeCompare(name2),
|
||||
);
|
||||
const hashes = await Promise.all(allAsars.map(async ([, from]) => generateAsarIntegrity(from)));
|
||||
const asarIntegrity: AsarIntegrity = {};
|
||||
for (let i = 0; i < allAsars.length; i++) {
|
||||
const [asar] = allAsars[i];
|
||||
asarIntegrity[asar] = hashes[i];
|
||||
}
|
||||
return asarIntegrity;
|
||||
}
|
||||
Reference in New Issue
Block a user