Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4cba79d

Browse files
authored
Schedule dehydration on reload if the dehydration key is already cached locally (#29021)
* Schedule dehydration on reload* fix test and use the right function to check dehydration is enabled* use dehydration helper function when scheduling dehydration on restart* fix test by passing in client object
1 parentb64471e commit4cba79d

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

‎src/MatrixClientPeg.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import PlatformPeg from "./PlatformPeg";
4141
import{formatList}from"./utils/FormattingUtils";
4242
importSdkConfigfrom"./SdkConfig";
4343
import{setDeviceIsolationMode}from"./settings/controllers/DeviceIsolationModeController.ts";
44+
import{initialiseDehydration}from"./utils/device/dehydration";
4445

4546
exportinterfaceIMatrixClientCreds{
4647
homeserverUrl:string;
@@ -340,7 +341,20 @@ class MatrixClientPegClass implements IMatrixClientPeg {
340341

341342
setDeviceIsolationMode(this.matrixClient,SettingsStore.getValue("feature_exclude_insecure_devices"));
342343

343-
// TODO: device dehydration and whathaveyou
344+
// Start dehydration. This code is only for the case where the client
345+
// gets restarted, so we only do this if we already have the dehydration
346+
// key cached, and we don't have to try to rehydrate a device. If this
347+
// is a new login, we will start dehydration after Secret Storage is
348+
// unlocked.
349+
try{
350+
awaitinitialiseDehydration({onlyIfKeyCached:true,rehydrate:false},this.matrixClient);
351+
}catch(e){
352+
// We may get an error dehydrating, such as if cross-signing and
353+
// SSSS are not set up yet. Just log the error and continue.
354+
// If SSSS gets set up later, we will re-try dehydration.
355+
console.log("Error starting device dehydration",e);
356+
}
357+
344358
return;
345359
}
346360

‎src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
332332
setupNewKeyBackup:!backupInfo,
333333
});
334334
}
335-
awaitinitialiseDehydration(true);
335+
awaitinitialiseDehydration({createNewKey:true});
336336

337337
this.setState({
338338
phase:Phase.Stored,

‎src/utils/device/dehydration.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ Please see LICENSE files in the repository root for full details.
77
*/
88

99
import{logger}from"matrix-js-sdk/src/logger";
10-
import{CryptoApi}from"matrix-js-sdk/src/crypto-api";
10+
import{CryptoApi,StartDehydrationOpts}from"matrix-js-sdk/src/crypto-api";
1111

12+
importtype{MatrixClient}from"matrix-js-sdk/src/matrix";
1213
import{MatrixClientPeg}from"../../MatrixClientPeg";
1314

1415
/**
@@ -21,14 +22,14 @@ import { MatrixClientPeg } from "../../MatrixClientPeg";
2122
*
2223
* Dehydration can currently only be enabled by setting a flag in the .well-known file.
2324
*/
24-
asyncfunctiondeviceDehydrationEnabled(crypto:CryptoApi|undefined):Promise<boolean>{
25+
asyncfunctiondeviceDehydrationEnabled(client:MatrixClient,crypto:CryptoApi|undefined):Promise<boolean>{
2526
if(!crypto){
2627
returnfalse;
2728
}
2829
if(!(awaitcrypto.isDehydrationSupported())){
2930
returnfalse;
3031
}
31-
constwellknown=awaitMatrixClientPeg.safeGet().waitForClientWellKnown();
32+
constwellknown=awaitclient.waitForClientWellKnown();
3233
return!!wellknown?.["org.matrix.msc3814"];
3334
}
3435

@@ -40,10 +41,11 @@ async function deviceDehydrationEnabled(crypto: CryptoApi | undefined): Promise<
4041
*@param createNewKey: force a new dehydration key to be created, even if one
4142
* already exists. This is used when we reset secret storage.
4243
*/
43-
exportasyncfunctioninitialiseDehydration(createNewKey:boolean=false):Promise<void>{
44-
constcrypto=MatrixClientPeg.safeGet().getCrypto();
45-
if(awaitdeviceDehydrationEnabled(crypto)){
44+
exportasyncfunctioninitialiseDehydration(opts:StartDehydrationOpts={},client?:MatrixClient):Promise<void>{
45+
client=client||MatrixClientPeg.safeGet();
46+
constcrypto=client.getCrypto();
47+
if(awaitdeviceDehydrationEnabled(client,crypto)){
4648
logger.log("Device dehydration enabled");
47-
awaitcrypto!.startDehydration(createNewKey);
49+
awaitcrypto!.startDehydration(opts);
4850
}
4951
}

‎test/unit-tests/MatrixClientPeg-test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,27 @@ describe("MatrixClientPeg", () => {
8686
expect(mockInitRustCrypto).toHaveBeenCalledWith({storageKey:cryptoStoreKey});
8787
});
8888

89+
it("should try to start dehydration if dehydration is enabled",async()=>{
90+
constmockInitRustCrypto=jest.spyOn(testPeg.safeGet(),"initRustCrypto").mockResolvedValue(undefined);
91+
constmockStartDehydration=jest.fn();
92+
jest.spyOn(testPeg.safeGet(),"getCrypto").mockReturnValue({
93+
isDehydrationSupported:jest.fn().mockResolvedValue(true),
94+
startDehydration:mockStartDehydration,
95+
setDeviceIsolationMode:jest.fn(),
96+
}asany);
97+
jest.spyOn(testPeg.safeGet(),"waitForClientWellKnown").mockResolvedValue({
98+
"m.homeserver":{
99+
base_url:"http://example.com",
100+
},
101+
"org.matrix.msc3814":true,
102+
}asany);
103+
104+
constcryptoStoreKey=newUint8Array([1,2,3,4]);
105+
awaittestPeg.start({rustCryptoStoreKey:cryptoStoreKey});
106+
expect(mockInitRustCrypto).toHaveBeenCalledWith({storageKey:cryptoStoreKey});
107+
expect(mockStartDehydration).toHaveBeenCalledWith({onlyIfKeyCached:true,rehydrate:false});
108+
});
109+
89110
it("Should migrate existing login",async()=>{
90111
constmockInitRustCrypto=jest.spyOn(testPeg.safeGet(),"initRustCrypto").mockResolvedValue(undefined);
91112

‎test/unit-tests/components/structures/MatrixChat-test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ describe("<MatrixChat />", () => {
128128
getCrypto:jest.fn().mockReturnValue({
129129
getVerificationRequestsToDeviceInProgress:jest.fn().mockReturnValue([]),
130130
isCrossSigningReady:jest.fn().mockReturnValue(false),
131+
isDehydrationSupported:jest.fn().mockReturnValue(false),
131132
getUserDeviceInfo:jest.fn().mockReturnValue(newMap()),
132133
getUserVerificationStatus:jest.fn().mockResolvedValue(newUserVerificationStatus(false,false,false)),
133134
getVersion:jest.fn().mockReturnValue("1"),
@@ -1005,6 +1006,7 @@ describe("<MatrixChat />", () => {
10051006
resetKeyBackup:jest.fn(),
10061007
isEncryptionEnabledInRoom:jest.fn().mockResolvedValue(false),
10071008
checkKeyBackupAndEnable:jest.fn().mockResolvedValue(null),
1009+
isDehydrationSupported:jest.fn().mockReturnValue(false),
10081010
};
10091011
loginClient.getCrypto.mockReturnValue(mockCryptoasany);
10101012
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp