Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove feature_dehydration #138

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions src/Lifecycle.ts
florianduros marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -664,43 +664,6 @@ export async function setLoggedIn(credentials: IMatrixClientCreds): Promise<Matr
return doSetLoggedIn(Object.assign({}, credentials, { pickleKey }), true, true);
}

/**
* Hydrates an existing session by using the credentials provided. This will
* not clear any local storage, unlike setLoggedIn().
*
* Stops the existing Matrix client (without clearing its data) and starts a
* new one in its place. This additionally starts all other react-sdk services
* which use the new Matrix client.
*
* If the credentials belong to a different user from the session already stored,
* the old session will be cleared automatically.
*
* @param {IMatrixClientCreds} credentials The credentials to use
*
* @returns {Promise} promise which resolves to the new MatrixClient once it has been started
*/
export async function hydrateSession(credentials: IMatrixClientCreds): Promise<MatrixClient> {
const oldUserId = MatrixClientPeg.safeGet().getUserId();
const oldDeviceId = MatrixClientPeg.safeGet().getDeviceId();

stopMatrixClient(); // unsets MatrixClientPeg.get()
localStorage.removeItem("mx_soft_logout");
_isLoggingOut = false;

const overwrite = credentials.userId !== oldUserId || credentials.deviceId !== oldDeviceId;
if (overwrite) {
logger.warn("Clearing all data: Old session belongs to a different user/session");
}

if (!credentials.pickleKey && credentials.deviceId !== undefined) {
logger.info("Lifecycle#hydrateSession: Pickle key not provided - trying to get one");
credentials.pickleKey =
(await PlatformPeg.get()?.getPickleKey(credentials.userId, credentials.deviceId)) ?? undefined;
}

return doSetLoggedIn(credentials, overwrite, false);
}

/**
* When we have a authenticated via OIDC-native flow and have a refresh token
* try to create a token refresher.
Expand Down Expand Up @@ -799,18 +762,6 @@ async function doSetLoggedIn(
PosthogAnalytics.instance.startListeningToSettingsChanges(client);
}

if (credentials.freshLogin && SettingsStore.getValue("feature_dehydration")) {
// If we just logged in, try to rehydrate a device instead of using a
// new device. If it succeeds, we'll get a new device ID, so make sure
// we persist that ID to localStorage
const newDeviceId = await client.rehydrateDevice();
if (newDeviceId) {
credentials.deviceId = newDeviceId;
}

delete credentials.freshLogin;
}

if (localStorage) {
try {
await persistCredentials(credentials);
Expand Down
15 changes: 0 additions & 15 deletions src/SecurityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { MatrixClientPeg } from "./MatrixClientPeg";
import { _t } from "./languageHandler";
import { isSecureBackupRequired } from "./utils/WellKnownUtils";
import AccessSecretStorageDialog, { KeyParams } from "./components/views/dialogs/security/AccessSecretStorageDialog";
import SettingsStore from "./settings/SettingsStore";
import { ModuleRunner } from "./modules/ModuleRunner";
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
import InteractiveAuthDialog from "./components/views/dialogs/InteractiveAuthDialog";
Expand Down Expand Up @@ -276,20 +275,6 @@ async function doAccessSecretStorage(func: () => Promise<void>, forceReset: bool
});
logger.debug("accessSecretStorage: bootstrapSecretStorage");
await crypto.bootstrapSecretStorage({});

const keyId = Object.keys(secretStorageKeys)[0];
if (keyId && SettingsStore.getValue("feature_dehydration")) {
let dehydrationKeyInfo = {};
if (secretStorageKeyInfo[keyId] && secretStorageKeyInfo[keyId].passphrase) {
dehydrationKeyInfo = { passphrase: secretStorageKeyInfo[keyId].passphrase };
}
logger.log("accessSecretStorage: Setting dehydration key");
await cli.setDehydrationKey(secretStorageKeys[keyId], dehydrationKeyInfo, "Backup device");
} else if (!keyId) {
logger.warn("accessSecretStorage: Not setting dehydration key: no SSSS key found");
} else {
logger.log("accessSecretStorage: Not setting dehydration key: feature disabled");
}
}

logger.debug("accessSecretStorage: 4S now ready");
Expand Down
4 changes: 2 additions & 2 deletions src/components/structures/auth/SoftLogout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
return;
}

Lifecycle.hydrateSession(credentials).catch((e) => {
Lifecycle.setLoggedIn(credentials).catch((e) => {
logger.error(e);
this.setState({ busy: false, errorText: _t("auth|failed_soft_logout_auth") });
});
Expand Down Expand Up @@ -204,7 +204,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
return false;
}

return Lifecycle.hydrateSession(credentials)
return Lifecycle.setLoggedIn(credentials)
.then(() => {
if (this.props.onTokenLoginCompleted) {
this.props.onTokenLoginCompleted();
Expand Down
1 change: 0 additions & 1 deletion src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,6 @@
"click_for_info": "Click for more info",
"currently_experimental": "Currently experimental.",
"custom_themes": "Support adding custom themes",
"dehydration": "Offline encrypted messaging using dehydrated devices",
"dynamic_room_predecessors": "Dynamic room predecessors",
"dynamic_room_predecessors_description": "Enable MSC3946 (to support late-arriving room archives)",
"element_call_video_rooms": "Element Call video rooms",
Expand Down
8 changes: 0 additions & 8 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,6 @@ export const SETTINGS: { [setting: string]: ISetting } = {
supportedLevelsAreOrdered: true,
default: false,
},
"feature_dehydration": {
isFeature: true,
labsGroup: LabGroup.Encryption,
displayName: _td("labs|dehydration"),
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG_PRIORITISED,
supportedLevelsAreOrdered: true,
default: false,
},
"feature_exclude_insecure_devices": {
isFeature: true,
labsGroup: LabGroup.Encryption,
Expand Down
Loading