From 0f8a5c100c612c1b2e5d1840f5fc91932ed256b0 Mon Sep 17 00:00:00 2001 From: Kyrylo Hrechykhin Date: Tue, 20 Dec 2022 16:48:09 +0100 Subject: [PATCH 1/4] add possibility to ignore not supported fuses --- src/config.ts | 1 + src/index.ts | 12 +++++++----- test/index.spec.ts | 47 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/config.ts b/src/config.ts index bc75ead..c0bfdde 100644 --- a/src/config.ts +++ b/src/config.ts @@ -18,6 +18,7 @@ export enum FuseV1Options { export type FuseV1Config = { version: FuseVersion.V1; resetAdHocDarwinSignature?: boolean; + ignoreNotSupportedFuses?: boolean; } & Partial>; export type FuseConfig = FuseV1Config; diff --git a/src/index.ts b/src/index.ts index 0d9e7bf..e38884b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,11 +15,13 @@ const buildFuseV1Wire = (config: FuseV1Config, wireLength: number) => { (fuseOption) => parseInt(fuseOption, 10) >= wireLength, ); if (badFuseOption !== undefined) { - throw new Error( - `Trying to configure ${ - FuseV1Options[badFuseOption as any] - } but the fuse wire in this version of Electron is not long enough`, - ); + if (!config.ignoreNotSupportedFuses) { + throw new Error( + `Trying to configure ${ + FuseV1Options[badFuseOption as any] + } but the fuse wire in this version of Electron is not long enough`, + ); + } } return [ diff --git a/test/index.spec.ts b/test/index.spec.ts index 7179f80..702d7fb 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -20,7 +20,7 @@ describe('getCurrentFuseWire()', () => { }); it('should return the expected defaults for Electron v20.0.0', async () => { - const electronPath = await getElectronLocally('20.0.0', 'darwin', 'x64'); + const electronPath = await getElectronLocally('20.0.0', process.platform, process.arch); expect(readableFuseWire(await getCurrentFuseWire(electronPath))).toMatchInlineSnapshot(` { "EnableCookieEncryption": "DISABLE", @@ -35,16 +35,18 @@ describe('getCurrentFuseWire()', () => { }); for (const [platform, arch] of supportedPlatforms) { - it(`should work on ${platform}/${arch}`, async () => { - const electronPath = await getElectronLocally('20.0.0', platform, arch); - await expect(getCurrentFuseWire(electronPath)).resolves.toBeTruthy(); - }); + if (process.platform === platform) { + it(`should work on ${platform}/${arch}`, async () => { + const electronPath = await getElectronLocally('20.0.0', platform, arch); + await expect(getCurrentFuseWire(electronPath)).resolves.toBeTruthy(); + }); + } } }); describe('flipFuses()', () => { it('should allow toggling a single fuse', async () => { - const electronPath = await getElectronLocally('20.0.0', 'darwin', 'x64'); + const electronPath = await getElectronLocally('20.0.0', process.platform, process.arch); expect((await getCurrentFuseWire(electronPath))[FuseV1Options.EnableCookieEncryption]).toEqual( FuseState.DISABLE, ); @@ -59,7 +61,7 @@ describe('flipFuses()', () => { }); it('should allow toggling multiple fuses', async () => { - const electronPath = await getElectronLocally('20.0.0', 'darwin', 'x64'); + const electronPath = await getElectronLocally('20.0.0', process.platform, process.arch); expect((await getCurrentFuseWire(electronPath))[FuseV1Options.EnableCookieEncryption]).toEqual( FuseState.DISABLE, ); @@ -79,6 +81,37 @@ describe('flipFuses()', () => { ).toEqual(FuseState.ENABLE); }); + it('should throw exception by default if unsupported fuse is specified', async () => { + const electronPath = await getElectronLocally('20.0.0', process.platform, process.arch); + const fuseConfig = await getCurrentFuseWire(electronPath); + expect(FuseV1Options.LoadBrowserProcessSpecificV8Snapshot in fuseConfig).toBeFalsy(); + + await expect( + flipFuses(electronPath, { + version: FuseVersion.V1, + [FuseV1Options.LoadBrowserProcessSpecificV8Snapshot]: true, + }), + ).rejects.toThrow('LoadBrowserProcessSpecificV8Snapshot'); + }); + + it('should toggle only supported fuses if ignoreNotSupportedFuses is true', async () => { + const electronPath = await getElectronLocally('20.0.0', process.platform, process.arch); + const fuseConfig = await getCurrentFuseWire(electronPath); + expect(FuseV1Options.LoadBrowserProcessSpecificV8Snapshot in fuseConfig).toBeFalsy(); + expect(fuseConfig[FuseV1Options.EnableCookieEncryption]).toEqual(FuseState.DISABLE); + + await flipFuses(electronPath, { + version: FuseVersion.V1, + ignoreNotSupportedFuses: true, + [FuseV1Options.EnableCookieEncryption]: true, + [FuseV1Options.LoadBrowserProcessSpecificV8Snapshot]: true, + }); + + const newFuseConfig = await getCurrentFuseWire(electronPath); + expect(FuseV1Options.LoadBrowserProcessSpecificV8Snapshot in newFuseConfig).toBeFalsy(); + expect(newFuseConfig[FuseV1Options.EnableCookieEncryption]).toEqual(FuseState.ENABLE); + }); + if (process.platform === 'darwin') { it('should work on universal macOS applications', async () => { const electronPathX64 = await getElectronLocally('20.0.0', 'darwin', 'x64'); From da1ad85a5f104e7b94f9b9d196439e42042964df Mon Sep 17 00:00:00 2001 From: Kyrylo Hrechykhin Date: Tue, 20 Dec 2022 16:49:43 +0100 Subject: [PATCH 2/4] fixed small formatting issue --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e38884b..c0ac505 100644 --- a/src/index.ts +++ b/src/index.ts @@ -126,7 +126,7 @@ export const getCurrentFuseWire = async ( if (fuseWirePosition - SENTINEL.length === -1) { throw new Error( - 'Could not find sentinel in the provided ELectron binary, fuses are only supported in Electron 12 and higher', + 'Could not find sentinel in the provided Electron binary, fuses are only supported in Electron 12 and higher', ); } const fuseWireVersion = (electron[fuseWirePosition] as any) as FuseVersion; From 65e18dbfae12937bcd48fefaefae40a8a6feeef8 Mon Sep 17 00:00:00 2001 From: Kyrylo Hrechykhin Date: Wed, 21 Dec 2022 16:26:55 +0100 Subject: [PATCH 3/4] do not return ignoreNotSupportedFuses value while fuses read --- src/bin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index 14605f5..e7fa3fd 100755 --- a/src/bin.ts +++ b/src/bin.ts @@ -62,7 +62,7 @@ if (mode === 'read') { getCurrentFuseWire(argv.app) .then((config) => { - const { version, resetAdHocDarwinSignature, ...rest } = config; + const { version, resetAdHocDarwinSignature, ignoreNotSupportedFuses, ...rest } = config; console.log(`Fuse Version: ${chalk.cyan(`v${version}`)}`); switch (config.version) { @@ -101,7 +101,7 @@ if (mode === 'read') { getCurrentFuseWire(argv.app) .then((config) => { - const { version, resetAdHocDarwinSignature, ...rest } = config; + const { version, resetAdHocDarwinSignature, ignoreNotSupportedFuses, ...rest } = config; console.log(`Fuse Version: ${chalk.cyan(`v${version}`)}`); const keyPairs = argv._ || []; From 5ae15d52b62780db6938610dff2d0335d343e199 Mon Sep 17 00:00:00 2001 From: Kyrylo Hrechykhin Date: Fri, 27 Jan 2023 10:31:31 +0100 Subject: [PATCH 4/4] resolve comments --- src/bin.ts | 7 ++++--- src/config.ts | 2 +- src/index.ts | 14 ++++++-------- test/index.spec.ts | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index e7fa3fd..d7dd1b5 100755 --- a/src/bin.ts +++ b/src/bin.ts @@ -62,7 +62,7 @@ if (mode === 'read') { getCurrentFuseWire(argv.app) .then((config) => { - const { version, resetAdHocDarwinSignature, ignoreNotSupportedFuses, ...rest } = config; + const { version, resetAdHocDarwinSignature, ignoreUnsupportedFuses, ...rest } = config; console.log(`Fuse Version: ${chalk.cyan(`v${version}`)}`); switch (config.version) { @@ -101,7 +101,7 @@ if (mode === 'read') { getCurrentFuseWire(argv.app) .then((config) => { - const { version, resetAdHocDarwinSignature, ignoreNotSupportedFuses, ...rest } = config; + const { version } = config; console.log(`Fuse Version: ${chalk.cyan(`v${version}`)}`); const keyPairs = argv._ || []; @@ -155,10 +155,11 @@ if (mode === 'read') { console.log('Writing to app:', chalk.cyan(path.basename(argv.app!))); function adaptConfig(config: FuseConfig): FuseConfig { - const { version, resetAdHocDarwinSignature, ...rest } = config; + const { version, resetAdHocDarwinSignature, ignoreUnsupportedFuses, ...rest } = config; const fuseConfig: FuseConfig = { version, resetAdHocDarwinSignature, + ignoreUnsupportedFuses, }; for (const key of Object.keys(rest)) { diff --git a/src/config.ts b/src/config.ts index c0bfdde..95f6fd6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -18,7 +18,7 @@ export enum FuseV1Options { export type FuseV1Config = { version: FuseVersion.V1; resetAdHocDarwinSignature?: boolean; - ignoreNotSupportedFuses?: boolean; + ignoreUnsupportedFuses?: boolean; } & Partial>; export type FuseConfig = FuseV1Config; diff --git a/src/index.ts b/src/index.ts index c0ac505..a5a6d77 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,14 +14,12 @@ const buildFuseV1Wire = (config: FuseV1Config, wireLength: number) => { const badFuseOption = Object.keys(nonVersionConfig).find( (fuseOption) => parseInt(fuseOption, 10) >= wireLength, ); - if (badFuseOption !== undefined) { - if (!config.ignoreNotSupportedFuses) { - throw new Error( - `Trying to configure ${ - FuseV1Options[badFuseOption as any] - } but the fuse wire in this version of Electron is not long enough`, - ); - } + if (badFuseOption !== undefined && !config.ignoreUnsupportedFuses) { + throw new Error( + `Trying to configure ${ + FuseV1Options[badFuseOption as any] + } but the fuse wire in this version of Electron is not long enough`, + ); } return [ diff --git a/test/index.spec.ts b/test/index.spec.ts index 702d7fb..8709e5a 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -102,7 +102,7 @@ describe('flipFuses()', () => { await flipFuses(electronPath, { version: FuseVersion.V1, - ignoreNotSupportedFuses: true, + ignoreUnsupportedFuses: true, [FuseV1Options.EnableCookieEncryption]: true, [FuseV1Options.LoadBrowserProcessSpecificV8Snapshot]: true, });