-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: asar integrity (macos only for now)
- Loading branch information
Showing
11 changed files
with
96 additions
and
34 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
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,18 @@ | ||
{ | ||
"name": "asar-integrity", | ||
"version": "0.0.0-semantic-release", | ||
"main": "out/asarIntegrity.js", | ||
"author": "Vladimir Krivosheev", | ||
"license": "MIT", | ||
"repository": "electron-userland/electron-builder", | ||
"bugs": "https://github.com/electron-userland/electron-builder/issues", | ||
"homepage": "https://github.com/electron-userland/electron-builder", | ||
"files": [ | ||
"out" | ||
], | ||
"dependencies": { | ||
"bluebird-lst": "^1.0.2", | ||
"fs-extra-p": "^4.3.0" | ||
}, | ||
"typings": "./out/asar-integrity.d.ts" | ||
} |
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,34 @@ | ||
import BluebirdPromise from "bluebird-lst" | ||
import { createHash } from "crypto" | ||
import { createReadStream } from "fs" | ||
import { readdir } from "fs-extra-p" | ||
import * as path from "path" | ||
|
||
export async function computeData(resourcesPath: string): Promise<{ [key: string]: string; }> { | ||
// sort to produce constant result | ||
const names = (await readdir(resourcesPath)).filter(it => it.endsWith(".asar")).sort() | ||
const checksums = await BluebirdPromise.map(names, it => hashFile(path.join(resourcesPath, it), "sha512")) | ||
|
||
const result: { [key: string]: string; } = {} | ||
for (let i = 0; i < names.length; i++) { | ||
result[names[i]] = checksums[i] | ||
} | ||
return result | ||
} | ||
|
||
export function hashFile(file: string, algorithm: string) { | ||
return new BluebirdPromise<string>((resolve, reject) => { | ||
const hash = createHash(algorithm) | ||
hash | ||
.on("error", reject) | ||
.setEncoding("hex") | ||
|
||
createReadStream(file) | ||
.on("error", reject) | ||
.on("end", () => { | ||
hash.end() | ||
resolve(<string>hash.read()) | ||
}) | ||
.pipe(hash, {end: false}) | ||
}) | ||
} |
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,10 @@ | ||
{ | ||
"extends": "../tsconfig-base.json", | ||
"compilerOptions": { | ||
"outDir": "out" | ||
}, | ||
"declaration": true, | ||
"include": [ | ||
"src/**/*.ts" | ||
] | ||
} |
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
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