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)); + } +}