From fa1d69c28fb7a6197bf135eb64e318f19f4e9052 Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 5 May 2024 16:54:28 +0200 Subject: [PATCH 1/3] #278 initial commit --- packages/app/src/app-worker.ts | 7 ++++++ packages/app/src/app/duck.js | 9 +++++++ packages/app/src/app/sagas.js | 13 +++++++++- packages/app/src/applications/Application.tsx | 25 +++++++++++++++---- .../services/services/session/interface.ts | 8 ++++++ .../app/src/services/services/session/main.ts | 7 +++++- .../src/services/services/session/worker.ts | 18 +++++++++++++ 7 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 packages/app/src/services/services/session/worker.ts diff --git a/packages/app/src/app-worker.ts b/packages/app/src/app-worker.ts index 1b7e7b1e..c6837478 100644 --- a/packages/app/src/app-worker.ts +++ b/packages/app/src/app-worker.ts @@ -42,6 +42,8 @@ import { AutolaunchProviderServiceImpl } from './services/services/autolaunch/au import { ManifestServiceImpl } from './services/services/manifest/main'; import { IMenuServiceObserverOnClickItemParam } from './services/services/menu/interface'; import { SDKv2ServiceImpl } from './services/services/sdkv2/worker'; +import { SessionServiceImpl } from './services/services/session/main'; +import { SessionProviderServiceImpl } from './services/services/session/worker'; import services from './services/servicesManager'; import { configureStore } from './store/configureStore.worker'; import { BasicAuthDetailsProviderServiceImpl } from './tab-webcontents/basicAuthDetailsProvider'; @@ -90,6 +92,7 @@ export class BrowserXAppWorker { this.initWebContentsOverrideProvider().catch(handleError()); this.initSDKv2(); this.initAutoLaunch().catch(handleError()); + this.initSessionService(); } catch (e) { handleError()(e); remote.app.exit(1); @@ -394,6 +397,10 @@ export class BrowserXAppWorker { return services.autolaunch.setAutolaunchProvider(new AutolaunchProviderServiceImpl(this.store)); } + private initSessionService() { + (services.defaultSession as SessionServiceImpl).init(new SessionProviderServiceImpl(this.store)) + } + private dispatch(action: any) { return this.store.dispatch(action); } diff --git a/packages/app/src/app/duck.js b/packages/app/src/app/duck.js index 5a064bf4..cc0b191c 100644 --- a/packages/app/src/app/duck.js +++ b/packages/app/src/app/duck.js @@ -32,6 +32,7 @@ export const OPEN_PROCESS_MANAGER = 'browserX/app/OPEN_PROCESS_MANAGER'; export const TOGGLE_PROMPT_DOWNLOAD = 'browserX/app/TOGGLE_PROMPT_DOWNLOAD'; export const SET_APP_METADATA = 'browserX/app/SET_APP_METADATA'; +export const DISABLE_SSL_CERT_VERIFICATION = 'browserX/app/DISABLE_SSL_CERT_VERIFICATION'; // Action creators export const ready = () => ({ type: READY }); @@ -133,6 +134,11 @@ export const setAppMetadata = (metadata) => { }; }; +export const disableSslCertVerification = (partition) => ({ + type: DISABLE_SSL_CERT_VERIFICATION, + partition, +}); + // Reducer export default function app(state = new Map(), action) { switch (action.type) { @@ -178,6 +184,9 @@ export default function app(state = new Map(), action) { case TOGGLE_PROMPT_DOWNLOAD: return state.set('promptDownload', Boolean(action.promptDownload)); + case DISABLE_SSL_CERT_VERIFICATION: + return state.set('disableSslCertVerification', action.partition); + case SET_APP_METADATA: return state .set('appName', action.name) diff --git a/packages/app/src/app/sagas.js b/packages/app/src/app/sagas.js index c38fa85c..eb863ad5 100644 --- a/packages/app/src/app/sagas.js +++ b/packages/app/src/app/sagas.js @@ -36,7 +36,8 @@ import { setLoadingScreenVisibility, TOGGLE_PROMPT_DOWNLOAD, TOGGLE_KBD_SHORTCUTS, - TOGGLE_MAXIMIZE + TOGGLE_MAXIMIZE, + DISABLE_SSL_CERT_VERIFICATION, } from './duck'; import { DELAY } from '../persistence/backend'; import { getWindowCurrentTabId } from '../windows/get'; @@ -249,6 +250,15 @@ function* sagaHandleOpenProcessManager() { yield callService('processManager', 'open', undefined); } +function* sagaDisableSslCertVerification() { + + + require('electron-log').info('>>>>>>>>>>>', process.type); + + + +} + /** * Will load the app metadata in the state. */ @@ -275,6 +285,7 @@ export default function* main(bxApp) { takeEveryWitness(TOGGLE_KBD_SHORTCUTS, sagaToggleKbdShortcutsOverlay), takeEveryWitness(CHANGE_APP_FOCUS_STATE, onChangeAppFocusState), takeEveryWitness(OPEN_PROCESS_MANAGER, sagaHandleOpenProcessManager), + takeEveryWitness(DISABLE_SSL_CERT_VERIFICATION, sagaDisableSslCertVerification), // For dev purpose takeEveryWitness('STATION_MANUAL_ERR', sagaTriggerError) ]); diff --git a/packages/app/src/applications/Application.tsx b/packages/app/src/applications/Application.tsx index e7a34f3b..7545d5f0 100644 --- a/packages/app/src/applications/Application.tsx +++ b/packages/app/src/applications/Application.tsx @@ -7,7 +7,8 @@ import { GradientType, withGradient } from '@getstation/theme'; import ElectronWebview from '../common/components/ElectronWebview'; import * as classNames from 'classnames'; import { clipboard } from 'electron'; -import * as remote from '@electron/remote'; +import services from '../services/servicesManager'; +// import * as remote from '@electron/remote'; // @ts-ignore no declaration file import { fetchFavicon, setFetchFaviconTimeout } from '@getstation/fetch-favicon'; import Maybe from 'graphql/tsutils/Maybe'; @@ -51,6 +52,7 @@ import LazyWebview from './LazyWebview'; import { withGetApplicationState } from './queries@local.gql.generated'; import { getApplicationDescription } from './selectors'; import { ApplicationImmutable } from './types'; +// @ts-ignore no declaration file import { getForeFrontNavigationStateProperty } from './utils'; type WebviewMethod = (webview: ElectronWebview) => void; @@ -97,6 +99,7 @@ export interface OwnProps { loading: boolean, manifestURL: Maybe, applicationId: string, + appstoreApplicationId: string, applicationName: Maybe, applicationIcon: Maybe, @@ -388,12 +391,10 @@ class ApplicationImpl extends React.PureComponent { const webview = this.webView.view; webview.addEventListener('dom-ready', () => { - const webContents = remote.webContents.fromId(webview.getWebContentsId()); - webview.addEventListener('did-navigate-in-page', (e: any) => this.handleDidNavigateInPage(e)); webview.addEventListener('did-navigate', (e: any) => this.handleDidNavigate(e)); webview.addEventListener('ipc-message', (e: any) => this.handleIPCMessage(e)); - this.props.onWebcontentsAttached(webContents.id); + this.props.onWebcontentsAttached(webview.getWebContentsId()); }); } } @@ -403,7 +404,8 @@ class ApplicationImpl extends React.PureComponent { const useNativeWindowOpen = !this.props.notUseNativeWindowOpen; const tabUrl = tab.get('url', ''); const { - applicationId, applicationName, applicationIcon, themeColor, manifestURL, + applicationId, applicationName, applicationIcon, + appstoreApplicationId, themeColor, manifestURL, askResetApplication, onChooseAccount, crashed, errorCode, errorDescription, canGoBack, themeGradient, email, @@ -411,6 +413,18 @@ class ApplicationImpl extends React.PureComponent { useDefaultSession, } = this.props; + const partition = useDefaultSession ? '' : `persist:${applicationId}`; + + // disable SSL check for private applications + if (!useDefaultSession && Number(appstoreApplicationId) > 1000000) { + services.defaultSession.disableSslCertVerification(partition); + + // const appSession = remote.session.fromPartition(partition); + // appSession.setCertificateVerifyProc((_, callback) => { + // callback(0); + // }) + } + return (
{ + // @ts-ignore + disableSslCertVerification(partition: string) : Promise {} +} + @service('session') export class SessionService extends ServiceBase implements RPC.Interface { // ⚠️This class will also have to handle WhatsApp User-Agent @@ -13,4 +19,6 @@ export class SessionService extends ServiceBase implements RPC.Interface {} // @ts-ignore getCookies(filter: Electron.CookiesGetFilter): Promise {} + // @ts-ignore + disableSslCertVerification(partition: string) : Promise {} } diff --git a/packages/app/src/services/services/session/main.ts b/packages/app/src/services/services/session/main.ts index 7be81844..3272912a 100644 --- a/packages/app/src/services/services/session/main.ts +++ b/packages/app/src/services/services/session/main.ts @@ -1,12 +1,13 @@ import * as Electron from 'electron'; import { waitDefaultSession } from '../../api/sessions'; import { RPC } from '../../lib/types'; -import { SessionService } from './interface'; +import { SessionService, SessionProviderService } from './interface'; export type SessionOptions = { partition: string }; export class SessionServiceImpl extends SessionService implements RPC.Interface { private session?: Electron.Session; + private provider?: RPC.Node; constructor(uuid?: string, options?: SessionOptions) { super(uuid, { ready: false }); @@ -16,6 +17,10 @@ export class SessionServiceImpl extends SessionService implements RPC.Interface< }); } + init(provider: RPC.Node) { + this.provider = provider; + } + async getUserAgent(): Promise { const session = await this.getSession(); return session.getUserAgent(); diff --git a/packages/app/src/services/services/session/worker.ts b/packages/app/src/services/services/session/worker.ts new file mode 100644 index 00000000..30766c65 --- /dev/null +++ b/packages/app/src/services/services/session/worker.ts @@ -0,0 +1,18 @@ +// @ts-ignore: no declaration file +import { disableSslCertVerification } from '../../../app/duck'; +import { StationStoreWorker } from '../../../types'; +import { RPC } from '../../lib/types'; +import { SessionProviderService } from './interface'; + +export class SessionProviderServiceImpl extends SessionProviderService implements RPC.Interface { + store: StationStoreWorker; + + constructor(store: StationStoreWorker, uuid?: string) { + super(uuid); + this.store = store; + } + + async disableSslCertVerification(partition: string) { + this.store.dispatch(disableSslCertVerification(partition)); + } +} From 8a2fa1a8ba9cf6d3c1049dee8ac5063d785d8181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Charles?= Date: Wed, 8 May 2024 01:21:51 +0200 Subject: [PATCH 2/3] chore: fix usage of disableSslCertVerification --- packages/app/src/app-worker.ts | 5 ----- packages/app/src/app/duck.js | 3 --- packages/app/src/app/sagas.js | 9 ++------- packages/app/src/applications/Application.tsx | 13 +++++-------- .../src/services/services/session/interface.ts | 6 ------ .../app/src/services/services/session/main.ts | 14 ++++++++------ .../src/services/services/session/worker.ts | 18 ------------------ 7 files changed, 15 insertions(+), 53 deletions(-) delete mode 100644 packages/app/src/services/services/session/worker.ts diff --git a/packages/app/src/app-worker.ts b/packages/app/src/app-worker.ts index c6837478..b2b2e1ea 100644 --- a/packages/app/src/app-worker.ts +++ b/packages/app/src/app-worker.ts @@ -92,7 +92,6 @@ export class BrowserXAppWorker { this.initWebContentsOverrideProvider().catch(handleError()); this.initSDKv2(); this.initAutoLaunch().catch(handleError()); - this.initSessionService(); } catch (e) { handleError()(e); remote.app.exit(1); @@ -397,10 +396,6 @@ export class BrowserXAppWorker { return services.autolaunch.setAutolaunchProvider(new AutolaunchProviderServiceImpl(this.store)); } - private initSessionService() { - (services.defaultSession as SessionServiceImpl).init(new SessionProviderServiceImpl(this.store)) - } - private dispatch(action: any) { return this.store.dispatch(action); } diff --git a/packages/app/src/app/duck.js b/packages/app/src/app/duck.js index cc0b191c..cc3a20d0 100644 --- a/packages/app/src/app/duck.js +++ b/packages/app/src/app/duck.js @@ -184,9 +184,6 @@ export default function app(state = new Map(), action) { case TOGGLE_PROMPT_DOWNLOAD: return state.set('promptDownload', Boolean(action.promptDownload)); - case DISABLE_SSL_CERT_VERIFICATION: - return state.set('disableSslCertVerification', action.partition); - case SET_APP_METADATA: return state .set('appName', action.name) diff --git a/packages/app/src/app/sagas.js b/packages/app/src/app/sagas.js index eb863ad5..d15d76d4 100644 --- a/packages/app/src/app/sagas.js +++ b/packages/app/src/app/sagas.js @@ -250,13 +250,8 @@ function* sagaHandleOpenProcessManager() { yield callService('processManager', 'open', undefined); } -function* sagaDisableSslCertVerification() { - - - require('electron-log').info('>>>>>>>>>>>', process.type); - - - +function* sagaDisableSslCertVerification({ partition }) { + yield callService('defaultSession', 'disableSslCertVerification', partition); } /** diff --git a/packages/app/src/applications/Application.tsx b/packages/app/src/applications/Application.tsx index 7545d5f0..2ad9d8f8 100644 --- a/packages/app/src/applications/Application.tsx +++ b/packages/app/src/applications/Application.tsx @@ -7,7 +7,6 @@ import { GradientType, withGradient } from '@getstation/theme'; import ElectronWebview from '../common/components/ElectronWebview'; import * as classNames from 'classnames'; import { clipboard } from 'electron'; -import services from '../services/servicesManager'; // import * as remote from '@electron/remote'; // @ts-ignore no declaration file import { fetchFavicon, setFetchFaviconTimeout } from '@getstation/fetch-favicon'; @@ -42,6 +41,7 @@ import { } from '../tab-webcontents/duck'; import { getTabWebcontentsById, getWebcontentsAuthInfo, getWebcontentsAuthState } from '../tab-webcontents/selectors'; import { updateLoadingState, updateTabBadge, updateTabFavicons, updateTabTitle, updateTabURL } from '../tabs/duck'; +import { disableSslCertVerification } from '../app/duck'; import { getTabId, getTabLoadingState } from '../tabs/get'; import { StationTabImmutable } from '../tabs/types'; import { RecursiveImmutableMap, StationState } from '../types'; @@ -145,6 +145,7 @@ export interface DispatchProps { onChooseAccount: Function, onApplicationRemoved: Function, updateResetAppModal: Function, + disableSslCertVerification: (partition: string) => any, } export interface ComputedProps { @@ -404,7 +405,7 @@ class ApplicationImpl extends React.PureComponent { const useNativeWindowOpen = !this.props.notUseNativeWindowOpen; const tabUrl = tab.get('url', ''); const { - applicationId, applicationName, applicationIcon, + applicationId, applicationName, applicationIcon, appstoreApplicationId, themeColor, manifestURL, askResetApplication, onChooseAccount, crashed, errorCode, errorDescription, @@ -417,12 +418,7 @@ class ApplicationImpl extends React.PureComponent { // disable SSL check for private applications if (!useDefaultSession && Number(appstoreApplicationId) > 1000000) { - services.defaultSession.disableSslCertVerification(partition); - - // const appSession = remote.session.fromPartition(partition); - // appSession.setCertificateVerifyProc((_, callback) => { - // callback(0); - // }) + this.props.disableSslCertVerification(partition); } return ( @@ -564,6 +560,7 @@ const Application = compose( onChooseAccount: (identityId) => setConfigData(applicationId, { identityId }), onApplicationRemoved: uninstallApplication, updateResetAppModal: (appFocus) => updateUI('confirmResetApplicationModal', 'isVisible', appFocus), + disableSslCertVerification: disableSslCertVerification, }, dispatch ); diff --git a/packages/app/src/services/services/session/interface.ts b/packages/app/src/services/services/session/interface.ts index 7166fd63..acda258e 100644 --- a/packages/app/src/services/services/session/interface.ts +++ b/packages/app/src/services/services/session/interface.ts @@ -3,12 +3,6 @@ import { ServiceBase } from '../../lib/class'; import { service } from '../../lib/decorator'; import { RPC } from '../../lib/types'; -@service('session') -export class SessionProviderService extends ServiceBase implements RPC.Interface { - // @ts-ignore - disableSslCertVerification(partition: string) : Promise {} -} - @service('session') export class SessionService extends ServiceBase implements RPC.Interface { // ⚠️This class will also have to handle WhatsApp User-Agent diff --git a/packages/app/src/services/services/session/main.ts b/packages/app/src/services/services/session/main.ts index 3272912a..d0fe0596 100644 --- a/packages/app/src/services/services/session/main.ts +++ b/packages/app/src/services/services/session/main.ts @@ -1,13 +1,12 @@ import * as Electron from 'electron'; import { waitDefaultSession } from '../../api/sessions'; import { RPC } from '../../lib/types'; -import { SessionService, SessionProviderService } from './interface'; +import { SessionService } from './interface'; export type SessionOptions = { partition: string }; export class SessionServiceImpl extends SessionService implements RPC.Interface { private session?: Electron.Session; - private provider?: RPC.Node; constructor(uuid?: string, options?: SessionOptions) { super(uuid, { ready: false }); @@ -17,10 +16,6 @@ export class SessionServiceImpl extends SessionService implements RPC.Interface< }); } - init(provider: RPC.Node) { - this.provider = provider; - } - async getUserAgent(): Promise { const session = await this.getSession(); return session.getUserAgent(); @@ -31,6 +26,13 @@ export class SessionServiceImpl extends SessionService implements RPC.Interface< return session.cookies.get(filter); } + async disableSslCertVerification(partition: string) : Promise { + const session = Electron.session.fromPartition(partition); + session.setCertificateVerifyProc((_, callback) => { + callback(0); + }); + } + private async initSession(options?: SessionOptions): Promise { if (options && options.partition) { return Electron.session.fromPartition(options.partition); diff --git a/packages/app/src/services/services/session/worker.ts b/packages/app/src/services/services/session/worker.ts deleted file mode 100644 index 30766c65..00000000 --- a/packages/app/src/services/services/session/worker.ts +++ /dev/null @@ -1,18 +0,0 @@ -// @ts-ignore: no declaration file -import { disableSslCertVerification } from '../../../app/duck'; -import { StationStoreWorker } from '../../../types'; -import { RPC } from '../../lib/types'; -import { SessionProviderService } from './interface'; - -export class SessionProviderServiceImpl extends SessionProviderService implements RPC.Interface { - store: StationStoreWorker; - - constructor(store: StationStoreWorker, uuid?: string) { - super(uuid); - this.store = store; - } - - async disableSslCertVerification(partition: string) { - this.store.dispatch(disableSslCertVerification(partition)); - } -} From c456de295927e75509220fbc0016039695cc1dd0 Mon Sep 17 00:00:00 2001 From: Victor Date: Sat, 11 May 2024 01:25:38 +0200 Subject: [PATCH 3/3] code cleanup --- packages/app/src/app-worker.ts | 2 -- packages/app/src/applications/Application.tsx | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/app/src/app-worker.ts b/packages/app/src/app-worker.ts index b2b2e1ea..1b7e7b1e 100644 --- a/packages/app/src/app-worker.ts +++ b/packages/app/src/app-worker.ts @@ -42,8 +42,6 @@ import { AutolaunchProviderServiceImpl } from './services/services/autolaunch/au import { ManifestServiceImpl } from './services/services/manifest/main'; import { IMenuServiceObserverOnClickItemParam } from './services/services/menu/interface'; import { SDKv2ServiceImpl } from './services/services/sdkv2/worker'; -import { SessionServiceImpl } from './services/services/session/main'; -import { SessionProviderServiceImpl } from './services/services/session/worker'; import services from './services/servicesManager'; import { configureStore } from './store/configureStore.worker'; import { BasicAuthDetailsProviderServiceImpl } from './tab-webcontents/basicAuthDetailsProvider'; diff --git a/packages/app/src/applications/Application.tsx b/packages/app/src/applications/Application.tsx index 2ad9d8f8..2e76674a 100644 --- a/packages/app/src/applications/Application.tsx +++ b/packages/app/src/applications/Application.tsx @@ -7,7 +7,6 @@ import { GradientType, withGradient } from '@getstation/theme'; import ElectronWebview from '../common/components/ElectronWebview'; import * as classNames from 'classnames'; import { clipboard } from 'electron'; -// import * as remote from '@electron/remote'; // @ts-ignore no declaration file import { fetchFavicon, setFetchFaviconTimeout } from '@getstation/fetch-favicon'; import Maybe from 'graphql/tsutils/Maybe'; @@ -41,6 +40,7 @@ import { } from '../tab-webcontents/duck'; import { getTabWebcontentsById, getWebcontentsAuthInfo, getWebcontentsAuthState } from '../tab-webcontents/selectors'; import { updateLoadingState, updateTabBadge, updateTabFavicons, updateTabTitle, updateTabURL } from '../tabs/duck'; +// @ts-ignore no declaration file import { disableSslCertVerification } from '../app/duck'; import { getTabId, getTabLoadingState } from '../tabs/get'; import { StationTabImmutable } from '../tabs/types';