Skip to content

Commit

Permalink
chore: Remove deprecated encrypted DB PoC (#16282)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc authored Nov 28, 2023
1 parent 7e421f4 commit f31ff9b
Show file tree
Hide file tree
Showing 22 changed files with 19 additions and 586 deletions.
1 change: 0 additions & 1 deletion .env.localhost
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ ENABLE_DEV_BACKEND_API="true"
# DATADOG_CLIENT_TOKEN=pub4b424d9327fb397fc97261df265dd961

#FEATURE_DEFAULT_LOGIN_TEMPORARY_CLIENT="false"
#FEATURE_PERSIST_TEMPORARY_CLIENTS="false"
#FEATURE_APPLOCK_UNFOCUS_TIMEOUT="30"
#FEATURE_APPLOCK_SCHEDULED_TIMEOUT="30"
#FEATURE_ENABLE_MLS="true"
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"@wireapp/core": "42.21.0",
"@wireapp/react-ui-kit": "9.11.0",
"@wireapp/store-engine-dexie": "2.1.6",
"@wireapp/store-engine-sqleet": "1.8.9",
"@wireapp/webapp-events": "0.18.3",
"amplify": "https://github.com/wireapp/amplify#head=master",
"beautiful-react-hooks": "^5.0.1",
Expand Down
1 change: 0 additions & 1 deletion server/config/client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export function generateConfig(params: ConfigGeneratorParams, env: Env) {
MLS_CONFIG_DEFAULT_CIPHERSUITE: env.FEATURE_MLS_CONFIG_DEFAULT_CIPHERSUITE
? Number(env.FEATURE_MLS_CONFIG_DEFAULT_CIPHERSUITE)
: undefined,
PERSIST_TEMPORARY_CLIENTS: env.FEATURE_PERSIST_TEMPORARY_CLIENTS != 'false',
SHOW_LOADING_INFORMATION: env.FEATURE_SHOW_LOADING_INFORMATION == 'true',
USE_CORE_CRYPTO: env.FEATURE_USE_CORE_CRYPTO == 'true',
MAX_USERS_TO_PING_WITHOUT_ALERT:
Expand Down
3 changes: 0 additions & 3 deletions server/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ export type Env = {
/** Set a default federation domain in case no domain can be found */
FEATURE_FEDERATION_DOMAIN: string;

/** Wether the temporary clients should use IndexedDB. If set to false, they will use an in-memory database */
FEATURE_PERSIST_TEMPORARY_CLIENTS: string;

/** Feature toggle for the log in with a username. Can be set to true or false */
FEATURE_ENABLE_USERNAME_LOGIN: string;

Expand Down
21 changes: 0 additions & 21 deletions src/script/auth/module/action/AuthAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ import type {TeamData} from '@wireapp/api-client/lib/team/';
import {LowDiskSpaceError} from '@wireapp/store-engine/lib/engine/error';
import {StatusCodes as HTTP_STATUS, StatusCodes} from 'http-status-codes';

import type {CRUDEngine} from '@wireapp/store-engine';
import {SQLeetEngine} from '@wireapp/store-engine-sqleet';

import {isAxiosError, isBackendError} from 'Util/TypePredicateUtil';
import {isTemporaryClientAndNonPersistent} from 'Util/util';

import {AuthActionCreator} from './creator/';
import {LabeledError} from './LabeledError';
Expand All @@ -45,15 +41,6 @@ import type {LoginDataState, RegistrationDataState} from '../reducer/authReducer
type LoginLifecycleFunction = (dispatch: ThunkDispatch, getState: () => RootState, global: Api) => Promise<void>;

export class AuthAction {
doFlushDatabase = (): ThunkAction => {
return async (dispatch, getState, {core}) => {
const storeEngine: CRUDEngine = (core as any).storeEngine;
if (storeEngine instanceof SQLeetEngine) {
await (core as any).storeEngine.save();
}
};
};

doLogin = (loginData: LoginData, getEntropy?: () => Promise<Uint8Array>): ThunkAction => {
const onBeforeLogin: LoginLifecycleFunction = async (dispatch, getState, {actions: {authAction}}) =>
dispatch(authAction.doSilentLogout());
Expand Down Expand Up @@ -364,7 +351,6 @@ export class AuthAction {
await dispatch(selfAction.fetchSelf());
await (clientType !== ClientType.NONE &&
dispatch(clientAction.doInitializeClient(clientType, undefined, undefined, entropyData)));
await dispatch(authAction.doFlushDatabase());
dispatch(AuthActionCreator.successfulRegisterWireless(registrationData));
} catch (error) {
dispatch(AuthActionCreator.failedRegisterWireless(error));
Expand Down Expand Up @@ -425,13 +411,6 @@ export class AuthAction {
return async (dispatch, getState, {getConfig, core, actions: {localStorageAction}}) => {
try {
await core.logout();
if (isTemporaryClientAndNonPersistent(false)) {
/**
* WEBAPP-6804: Our current implementation of "websql" has the drawback that a mounted database can only get unmounted by refreshing the page.
* @see https://github.com/wireapp/websql/blob/v0.0.15/packages/worker/src/Database.ts#L142-L145
*/
window.location.reload();
}
dispatch(AuthActionCreator.successfulLogout());
} catch (error) {
dispatch(AuthActionCreator.failedLogout(error));
Expand Down
3 changes: 0 additions & 3 deletions src/script/auth/page/InitialInvite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const InitialInviteComponent = ({
resetInviteErrors,
invite,
isTeamFlow,
doFlushDatabase,
removeLocalStorage,
}: Props & ConnectedProps & DispatchProps) => {
const {formatMessage: _} = useIntl();
Expand All @@ -73,7 +72,6 @@ const InitialInviteComponent = ({
const [error, setError] = useState(null);

const onInviteDone = async () => {
await doFlushDatabase();
// Remove local storage item for 2FA logout if token expires.
removeLocalStorage(QUERY_KEY.JOIN_EXPIRES);
window.location.replace(pathWithParams(EXTERNAL_ROUTE.WEBAPP));
Expand Down Expand Up @@ -215,7 +213,6 @@ type DispatchProps = ReturnType<typeof mapDispatchToProps>;
const mapDispatchToProps = (dispatch: Dispatch<AnyAction>) =>
bindActionCreators(
{
doFlushDatabase: ROOT_ACTIONS.authAction.doFlushDatabase,
invite: ROOT_ACTIONS.invitationAction.invite,
removeLocalStorage: ROOT_ACTIONS.localStorageAction.deleteLocalStorage,
resetInviteErrors: ROOT_ACTIONS.invitationAction.resetInviteErrors,
Expand Down
2 changes: 0 additions & 2 deletions src/script/auth/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const QUERY_KEY = {
LANGUAGE: 'hl',
LOCALE: 'hl',
LOGOUT_REASON: 'reason',
PERSIST_TEMPORARY_CLIENTS: 'persist_temporary_clients',
SSO_AUTO_LOGIN: 'sso_auto_login',
SCOPE: 'scope',
TRACKING: 'tracking',
Expand All @@ -57,7 +56,6 @@ export const FORWARDED_QUERY_KEYS = [
QUERY_KEY.ACCOUNT_ID,
QUERY_KEY.ENVIRONMENT,
QUERY_KEY.LOCALE,
QUERY_KEY.PERSIST_TEMPORARY_CLIENTS,
QUERY_KEY.TRACKING,
...Object.values(OAUTH_QUERY_KEYS),
];
Expand Down
1 change: 0 additions & 1 deletion src/script/auth/util/test/mockStoreFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const defaultGetConfig = () => ({
ENABLE_DEBUG: true,
ENABLE_PHONE_LOGIN: true,
ENABLE_SSO: true,
PERSIST_TEMPORARY_CLIENTS: true,
},
});

Expand Down
9 changes: 0 additions & 9 deletions src/script/event/EventService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,6 @@ export class EventService {
...categorizedEvent,
primary_key: await this.storageService.save(StorageSchemata.OBJECT_STORE.EVENTS, undefined, categorizedEvent),
} as EventRecord;
if (this.storageService.isTemporaryAndNonPersistent) {
/**
* Dexie supports auto-incrementing primary keys and saves those keys to a predefined column.
* The SQLeetEngine also supports auto-incrementing primary keys but it does not save them to a predefined column, so we have to do that manually:
*/
await this.storageService.update(StorageSchemata.OBJECT_STORE.EVENTS, savedEvent.primary_key, {
primary_key: savedEvent.primary_key,
});
}
return savedEvent;
}

Expand Down
8 changes: 1 addition & 7 deletions src/script/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {Context} from '@wireapp/api-client/lib/auth';
import {ClientClassification, ClientType} from '@wireapp/api-client/lib/client/';
import {EVENTS as CoreEvents} from '@wireapp/core/lib/Account';
import {amplify} from 'amplify';
import Dexie from 'dexie';
import platform from 'platform';
import {container} from 'tsyringe';

Expand Down Expand Up @@ -120,7 +119,6 @@ export function doRedirect(signOutReason: SIGN_OUT_REASON) {
url = appendParameter(url, `${URLParameter.REASON}=${signOutReason}`);
}

Dexie.delete('/sqleet');
window.location.replace(url);
}

Expand Down Expand Up @@ -638,11 +636,7 @@ export class App {
this.repository.calling.destroy();

if (selfUser.isActivatedAccount()) {
if (this.service.storage.isTemporaryAndNonPersistent) {
this.logout(SIGN_OUT_REASON.CLIENT_REMOVED, true);
} else {
this.repository.storage.terminate('window.onunload');
}
this.repository.storage.terminate('window.onunload');
} else {
this.repository.conversation.leaveGuestRoom();
this.repository.storage.deleteDatabase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
*
*/

import {useRef} from 'react';

import {ErrorBoundary} from 'react-error-boundary';
import {container} from 'tsyringe';

Expand All @@ -31,8 +29,6 @@ import {ContentState} from 'src/script/page/useAppState';
import {useKoSubscribableChildren} from 'Util/ComponentUtil';
import {t} from 'Util/LocalizerUtil';
import {getLogger} from 'Util/Logger';
import {loadValue} from 'Util/StorageUtil';
import {isTemporaryClientAndNonPersistent} from 'Util/util';

import {AccountInput} from './accountPreferences/AccountInput';
import {AccountLink} from './accountPreferences/AccountLink';
Expand All @@ -54,7 +50,6 @@ import {Config} from '../../../../Config';
import {ConversationRepository} from '../../../../conversation/ConversationRepository';
import {User} from '../../../../entity/User';
import {PropertiesRepository} from '../../../../properties/PropertiesRepository';
import {StorageKey} from '../../../../storage';
import {TeamState} from '../../../../team/TeamState';
import {RichProfileRepository} from '../../../../user/RichProfileRepository';
import type {UserRepository} from '../../../../user/UserRepository';
Expand Down Expand Up @@ -100,8 +95,6 @@ export const AccountPreferences = ({
]);
const canEditProfile = managedBy === User.CONFIG.MANAGED_BY.WIRE;
const isDesktop = Runtime.isDesktopApp();
const persistedAuth = loadValue(StorageKey.AUTH.PERSIST);
const isTemporaryAndNonPersistent = useRef(isTemporaryClientAndNonPersistent(!!persistedAuth));
const config = Config.getConfig();
const brandName = config.BRAND_NAME;
const isConsentCheckEnabled = config.FEATURE.CHECK_CONSENT;
Expand Down Expand Up @@ -245,9 +238,7 @@ export const AccountPreferences = ({

{isActivatedAccount && (
<>
{!isTemporaryAndNonPersistent.current && (
<HistoryBackupSection brandName={brandName} importFile={importFile} switchContent={switchContent} />
)}
<HistoryBackupSection brandName={brandName} importFile={importFile} switchContent={switchContent} />

<AccountSecuritySection selfUser={selfUser} userRepository={userRepository} />

Expand Down
9 changes: 2 additions & 7 deletions src/script/service/CoreSingleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
*
*/

import {ClientType} from '@wireapp/api-client/lib/client/';
import {container, singleton} from 'tsyringe';

import {Account} from '@wireapp/core';

import {isTemporaryClientAndNonPersistent, supportsCoreCryptoProteus, supportsMLS} from 'Util/util';
import {supportsCoreCryptoProteus, supportsMLS} from 'Util/util';

import {APIClient} from './APIClientSingleton';
import {createStorageEngine, DatabaseTypes} from './StoreEngineProvider';
Expand Down Expand Up @@ -50,11 +49,7 @@ export class Core extends Account {
constructor(apiClient = container.resolve(APIClient)) {
super(apiClient, {
createStore: (storeName, context) => {
const dbType = isTemporaryClientAndNonPersistent(context.clientType === ClientType.PERMANENT)
? DatabaseTypes.ENCRYPTED
: DatabaseTypes.PERMANENT;

return createStorageEngine(storeName, dbType);
return createStorageEngine(storeName, DatabaseTypes.PERMANENT);
},
cryptoProtocolConfig: {
coreCrypoWasmFilePath: '/min/core-crypto.wasm',
Expand Down
20 changes: 1 addition & 19 deletions src/script/service/StoreEngineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,28 @@
*
*/

import Dexie from 'dexie';

import type {CRUDEngine} from '@wireapp/store-engine';
import {MemoryEngine} from '@wireapp/store-engine';
import {IndexedDBEngine} from '@wireapp/store-engine-dexie';
import {SQLeetEngine} from '@wireapp/store-engine-sqleet';

import {saveRandomEncryptionKey} from 'Util/ephemeralValueStore';

import {DexieDatabase} from '../storage/DexieDatabase';
import {SQLeetSchemata} from '../storage/SQLeetSchemata';

export enum DatabaseTypes {
/** a permament storage that will still live after logout */
PERMANENT,
/** a storage that is encrypted on disk */
ENCRYPTED,
/** a storage that will be lost when the app is reloaded */
EFFEMERAL,
}

const providePermanentEngine = async (storeName: string, requestPersistentStorage: boolean): Promise<CRUDEngine> => {
const db = new DexieDatabase(storeName);

const engine = new IndexedDBEngine();
try {
await engine.initWithDb(db, requestPersistentStorage);
} catch (error) {
await engine.initWithDb(db, false);
}
return engine as CRUDEngine; // FIXME: the type of IndexedDBEngine needs fixing on the web packages side
};

const provideTemporaryAndNonPersistentEngine = async (storeName: string): Promise<CRUDEngine> => {
await Dexie.delete('/sqleet');
const encryptionKey = await saveRandomEncryptionKey();
const engine = new SQLeetEngine('/worker/sqleet-worker.js', SQLeetSchemata.getLatest(), encryptionKey);
await engine.init(storeName);
return engine;
};

Expand All @@ -66,9 +51,6 @@ export async function createStorageEngine(
case DatabaseTypes.PERMANENT:
return providePermanentEngine(storeName, requestPersistentStorage);

case DatabaseTypes.ENCRYPTED:
return provideTemporaryAndNonPersistentEngine(storeName);

case DatabaseTypes.EFFEMERAL:
return new MemoryEngine();
}
Expand Down
Loading

0 comments on commit f31ff9b

Please sign in to comment.