-
Notifications
You must be signed in to change notification settings - Fork 45
fix: Allow EnableEmbeddedAsarIntegrityValidation when multiple asars are present in app
#124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3ba0f9b
fix: When application uses multiple ASARs, `EnableEmbeddedAsarIntegri…
mmaietta 70dd4ab
Merge commit 'd90d573ccf69a5b14b91aa818c8b97e0e6840399' into multi-as…
mmaietta 61eb5ac
cleanup merge conflict overwrites
mmaietta abc909f
Merge branch 'main' into multi-asar-integrity
mmaietta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BlackHole1 this changed the way some resources are identified i.e. before:
{ "relativePath": "Contents/Resources/app.asar", "type": 4 }, { "relativePath": "Contents/Resources/app.asar.unpacked/node_modules/fsevents/fsevents.node", "type": 4 },And after:
{ "relativePath": "Contents/Resources/app.asar", "type": 4 }, { "relativePath": "Contents/Resources/app.asar.unpacked/node_modules/fsevents/fsevents.node", "type": 0 },(4 =
APP_CODEand 0 =MACHO)I'm not sure if that's intentional or not but in the second case, it's considering
fsevents.nodeasMACHOinstead ofAPP_CODEand it leads into running this check here for this file where it wouldn't hit it before, leading to this error for Electron apps that includes thefseventspackage and other packages with universal.nodebinaries:Do you think in the above example
app.asar.unpacked/.../fsevents.nodeshould be identified asAPP_CODEorMACHO? Trying to figure out what a fix for this would look likeIf it should stay
APP_CODE, maybe doingif (p.includes('.asar'))is a good enough fix..., or maybep.endsWith('.asar') || p.includes('.asar.unpacked/')to be stricterEdit: made a PR #133 with a tentative fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree that all contents in
unpackedfolder should beAPP_CODE, as.nodeis a macho file. I think your issue being reported here:Should be resolved through #126 though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, even better! I'll watch that PR and pin 2.0.1 in the meantime then, thanks for the pointer 👌