mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
Merge pull request #7630 from vector-im/stefan/deviceDehydration
Device dehydration v2
This commit is contained in:
@@ -305,15 +305,5 @@
|
||||
*/
|
||||
- (void)showAuthenticationFallBackView;
|
||||
|
||||
#pragma mark - Device rehydration
|
||||
|
||||
/**
|
||||
Call this method at an appropriate time to attempt rehydrating from an existing dehydrated device
|
||||
@param keyData Secret key data
|
||||
@param credentials Account credentials
|
||||
*/
|
||||
|
||||
- (void)attemptDeviceRehydrationWithKeyData:(NSData *)keyData credentials:(MXCredentials *)credentials;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -1495,68 +1495,6 @@
|
||||
[self _createAccountWithCredentials:credentials];
|
||||
}
|
||||
|
||||
- (void)attemptDeviceRehydrationWithKeyData:(NSData *)keyData
|
||||
credentials:(MXCredentials *)credentials
|
||||
{
|
||||
[self attemptDeviceRehydrationWithKeyData:keyData
|
||||
credentials:credentials
|
||||
retry:YES];
|
||||
}
|
||||
|
||||
- (void)attemptDeviceRehydrationWithKeyData:(NSData *)keyData
|
||||
credentials:(MXCredentials *)credentials
|
||||
retry:(BOOL)retry
|
||||
{
|
||||
MXLogDebug(@"[MXKAuthenticationViewController] attemptDeviceRehydration: starting device rehydration");
|
||||
|
||||
if (keyData == nil)
|
||||
{
|
||||
MXLogError(@"[MXKAuthenticationViewController] attemptDeviceRehydration: no key provided for device rehydration");
|
||||
[self _createAccountWithCredentials:credentials];
|
||||
return;
|
||||
}
|
||||
|
||||
MXRestClient *mxRestClient = [[MXRestClient alloc] initWithCredentials:credentials andOnUnrecognizedCertificateBlock:^BOOL(NSData *certificate) {
|
||||
return NO;
|
||||
} andPersistentTokenDataHandler:^(void (^handler)(NSArray<MXCredentials *> *credentials, void (^completion)(BOOL didUpdateCredentials))) {
|
||||
[[MXKAccountManager sharedManager] readAndWriteCredentials:handler];
|
||||
} andUnauthenticatedHandler: nil];
|
||||
|
||||
MXWeakify(self);
|
||||
[[MXKAccountManager sharedManager].dehydrationService rehydrateDeviceWithMatrixRestClient:mxRestClient dehydrationKey:keyData success:^(NSString * deviceId) {
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
|
||||
if (deviceId)
|
||||
{
|
||||
MXLogDebug(@"[MXKAuthenticationViewController] attemptDeviceRehydration: device %@ rehydrated successfully.", deviceId);
|
||||
credentials.deviceId = deviceId;
|
||||
}
|
||||
else
|
||||
{
|
||||
MXLogDebug(@"[MXKAuthenticationViewController] attemptDeviceRehydration: device rehydration has been canceled.");
|
||||
}
|
||||
|
||||
[self _createAccountWithCredentials:credentials];
|
||||
} failure:^(NSError *error) {
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
|
||||
if (retry)
|
||||
{
|
||||
MXLogErrorDetails(@"[MXKAuthenticationViewController] attemptDeviceRehydration: device rehydration failed due to error: Retrying", @{
|
||||
@"error": error ?: @"unknown"
|
||||
});
|
||||
[self attemptDeviceRehydrationWithKeyData:keyData credentials:credentials retry:NO];
|
||||
return;
|
||||
}
|
||||
|
||||
MXLogErrorDetails(@"[MXKAuthenticationViewController] attemptDeviceRehydration: device rehydration failed due to error", @{
|
||||
@"error": error ?: @"unknown"
|
||||
});
|
||||
|
||||
[self _createAccountWithCredentials:credentials];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)_createAccountWithCredentials:(MXCredentials *)credentials
|
||||
{
|
||||
MXKAccount *account = [[MXKAccount alloc] initWithCredentials:credentials];
|
||||
|
||||
@@ -360,13 +360,6 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer
|
||||
|
||||
#pragma mark - Sync filter
|
||||
|
||||
/**
|
||||
Call this method at an appropriate time to attempt dehydrating to a new backup device
|
||||
*/
|
||||
- (void)attemptDeviceDehydrationWithKeyData:(NSData *)keyData
|
||||
success:(void (^)(void))success
|
||||
failure:(void (^)(NSError *error))failure;
|
||||
|
||||
/**
|
||||
Handle unauthenticated errors from the server triggering hard/soft logouts as appropriate.
|
||||
*/
|
||||
|
||||
@@ -1715,70 +1715,6 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)attemptDeviceDehydrationWithKeyData:(NSData *)keyData
|
||||
success:(void (^)(void))success
|
||||
failure:(void (^)(NSError *error))failure
|
||||
{
|
||||
[self attemptDeviceDehydrationWithKeyData:keyData retry:YES success:success failure:failure];
|
||||
}
|
||||
|
||||
- (void)attemptDeviceDehydrationWithKeyData:(NSData *)keyData
|
||||
retry:(BOOL)retry
|
||||
success:(void (^)(void))success
|
||||
failure:(void (^)(NSError *error))failure
|
||||
{
|
||||
if (keyData == nil)
|
||||
{
|
||||
MXLogWarning(@"[MXKAccount] attemptDeviceDehydrationWithRetry: no key provided for device dehydration");
|
||||
|
||||
if (failure)
|
||||
{
|
||||
failure(nil);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (![mxSession.crypto.crossSigning isKindOfClass:[MXLegacyCrossSigning class]]) {
|
||||
MXLogFailure(@"Device dehydratation is currently only supported by legacy cross signing, add support to all implementations");
|
||||
if (failure)
|
||||
{
|
||||
failure(nil);
|
||||
}
|
||||
return;
|
||||
}
|
||||
MXLegacyCrossSigning *crossSigning = (MXLegacyCrossSigning *)mxSession.crypto.crossSigning;;
|
||||
|
||||
MXLogDebug(@"[MXKAccount] attemptDeviceDehydrationWithRetry: starting device dehydration");
|
||||
[[MXKAccountManager sharedManager].dehydrationService dehydrateDeviceWithMatrixRestClient:mxRestClient crossSigning:crossSigning dehydrationKey:keyData success:^(NSString *deviceId) {
|
||||
MXLogDebug(@"[MXKAccount] attemptDeviceDehydrationWithRetry: device successfully dehydrated");
|
||||
|
||||
if (success)
|
||||
{
|
||||
success();
|
||||
}
|
||||
} failure:^(NSError *error) {
|
||||
if (retry)
|
||||
{
|
||||
[self attemptDeviceDehydrationWithKeyData:keyData retry:NO success:success failure:failure];
|
||||
MXLogErrorDetails(@"[MXKAccount] attemptDeviceDehydrationWithRetry: device dehydration failed due to error: Retrying.", @{
|
||||
@"error": error ?: @"unknown"
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
MXLogErrorDetails(@"[MXKAccount] attemptDeviceDehydrationWithRetry: device dehydration failed due to error", @{
|
||||
@"error": error ?: @"unknown"
|
||||
});
|
||||
|
||||
if (failure)
|
||||
{
|
||||
failure(error);
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)onMatrixSessionStateChange
|
||||
{
|
||||
// Check if pause has been requested
|
||||
|
||||
@@ -104,8 +104,6 @@ extern NSString *const MXKAccountManagerDataType;
|
||||
*/
|
||||
@property (nonatomic) BOOL isPushAvailable;
|
||||
|
||||
@property (nonatomic, readonly) MXDehydrationService *dehydrationService;
|
||||
|
||||
/**
|
||||
Retrieve the MXKAccounts manager.
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@ NSString *const MXKAccountManagerDataType = @"org.matrix.kit.MXKAccountManagerDa
|
||||
if (self)
|
||||
{
|
||||
_storeClass = [MXFileStore class];
|
||||
_dehydrationService = [MXDehydrationService new];
|
||||
_savingAccountsEnabled = YES;
|
||||
|
||||
// Migrate old account file to new format
|
||||
|
||||
Reference in New Issue
Block a user