-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: When application uses multiple ASARs, `EnableEmbeddedAsarIntegri…
…tyValidation` fuse breaks the application due to not all ASARs having integrity generated for them. Fixes: #116
- Loading branch information
Showing
8 changed files
with
250 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ jobs: | |
test: | ||
name: Test | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: | ||
- '20.5' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.