Skip to content

Commit

Permalink
Deprecate MXLegacyCrypto
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderas committed Apr 17, 2023
1 parent 7e2f507 commit 22c5ac7
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 634 deletions.
12 changes: 2 additions & 10 deletions MatrixSDK/Background/MXBackgroundSyncService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public enum MXBackgroundSyncServiceError: Error {
/// - Parameter credentials: account credentials
public init(
withCredentials credentials: MXCredentials,
isCryptoSDKEnabled: Bool = false,
persistTokenDataHandler: MXRestClientPersistTokenDataHandler? = nil,
unauthenticatedHandler: MXRestClientUnauthenticatedHandler? = nil
) {
Expand All @@ -90,16 +89,9 @@ public enum MXBackgroundSyncServiceError: Error {
self.restClient = restClient

store = MXBackgroundStore(withCredentials: credentials)
// We can flush any crypto data if our sync response store is empty
let resetBackgroundCryptoStore = syncResponseStoreManager.syncToken() == nil

if isCryptoSDKEnabled {
MXLog.debug("[MXBackgroundSyncService] init: constructing crypto v2")
crypto = MXBackgroundCryptoV2(credentials: credentials, restClient: restClient)
} else {
MXLog.debug("[MXBackgroundSyncService] init: constructing legacy crypto")
crypto = MXLegacyBackgroundCrypto(credentials: credentials, resetBackgroundCryptoStore: resetBackgroundCryptoStore)
}
MXLog.debug("[MXBackgroundSyncService] init: constructing crypto")
crypto = MXBackgroundCryptoV2(credentials: credentials, restClient: restClient)

pushRulesManager = MXBackgroundPushRulesManager(withCredentials: credentials)
MXLog.debug("[MXBackgroundSyncService] init complete")
Expand Down
18 changes: 0 additions & 18 deletions MatrixSDK/Contrib/Swift/MXSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,6 @@ public extension MXSession {
__setStore(store, success: currySuccess(completion), failure: curryFailure(completion))
}


/**
Enable End-to-End encryption.
In case of enabling, the operation will complete when the session will be ready
to make encrytion with other users devices
- parameters:
- isEnabled: `false` stops crypto and erases crypto data.
- completion: A block called when the SDK has completed a catchup, or times out.
- response: Indicates whether the sync was successful.
*/
@nonobjc func enableCrypto(_ isEnabled: Bool, completion: @escaping (_ response: MXResponse<Void>) -> Void) {
__enableCrypto(isEnabled, success: currySuccess(completion), failure: curryFailure(completion))
}



/// Create a new room with the given parameters.
/// - Parameters:
/// - name: Name of the room
Expand Down
29 changes: 0 additions & 29 deletions MatrixSDK/Crypto/MXCrypto.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@ @implementation MXLegacyCrypto
__block id<MXCrypto> crypto;

#ifdef MX_CRYPTO
if (MXSDKOptions.sharedInstance.enableCryptoSDK)
{
MXLogFailure(@"[MXCrypto] createCryptoWithMatrixSession: Crypto V2 should not be created directly, use initializeCryptoWithMatrixSession instead");
return nil;
}

dispatch_queue_t cryptoQueue = [MXLegacyCrypto dispatchQueueForUser:mxSession.matrixRestClient.credentials.userId];
dispatch_sync(cryptoQueue, ^{

Expand All @@ -180,29 +174,6 @@ + (void)initializeCryptoWithMatrixSession:(MXSession *)mxSession
complete:(void (^)(id<MXCrypto> crypto, NSError *error))complete
{
#ifdef MX_CRYPTO

if (MXSDKOptions.sharedInstance.enableCryptoSDK)
{
BOOL enableCrypto = [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession || [MXCryptoV2Factory.shared hasCryptoDataFor:mxSession];
if (enableCrypto)
{
[MXCryptoV2Factory.shared buildCryptoWithSession:mxSession
migrationProgress:migrationProgress
success:^(id<MXCrypto> crypto) {
complete(crypto, nil); }
failure:^(NSError *error) {
complete(nil, error);
}];
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
complete(nil, nil);
});
}
return;
}

[self initalizeLegacyCryptoWithMatrixSession:mxSession complete:complete];
#else
complete(nil);
Expand Down
6 changes: 0 additions & 6 deletions MatrixSDK/Data/EventTimeline/Room/MXRoomEventTimeline.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ - (void)initialiseState:(NSArray<MXEvent *> *)stateEvents

- (void)destroy
{
[room.mxSession resetReplayAttackCheckInTimeline:_timelineId];

if (httpOperation)
{
// Cancel the current server request
Expand Down Expand Up @@ -190,8 +188,6 @@ - (BOOL)canPaginate:(MXTimelineDirection)direction

- (void)resetPagination
{
[room.mxSession resetReplayAttackCheckInTimeline:_timelineId];

// Reset the back state to the current room state
backState = [[MXRoomState alloc] initBackStateWith:_state];

Expand All @@ -203,8 +199,6 @@ - (MXHTTPOperation *)resetPaginationAroundInitialEventWithLimit:(NSUInteger)limi
{
NSParameterAssert(success);
NSAssert(_initialEventId, @"[MXRoomEventTimeline] resetPaginationAroundInitialEventWithLimit cannot be called on live timeline");

[room.mxSession resetReplayAttackCheckInTimeline:_timelineId];

// Reset the store
if (!store.isPermanent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ public class MXThreadEventTimeline: NSObject, MXEventTimeline {
}

public func destroy() {
thread.session?.resetReplayAttackCheck(inTimeline: timelineId)

removeAllListeners()

currentHttpOperation?.cancel()
Expand Down Expand Up @@ -132,8 +130,6 @@ public class MXThreadEventTimeline: NSObject, MXEventTimeline {
}

public func resetPagination() {
thread.session?.resetReplayAttackCheck(inTimeline: timelineId)

// Reset store pagination
storeMessagesEnumerator = store.messagesEnumerator(forRoom: thread.roomId)

Expand All @@ -150,8 +146,6 @@ public class MXThreadEventTimeline: NSObject, MXEventTimeline {
fatalError("[MXThreadEventTimeline][\(timelineId)] resetPaginationAroundInitialEventWithLimit cannot be called on live timeline")
}

thread.session?.resetReplayAttackCheck(inTimeline: timelineId)

// Reset the store
if !store.isPermanent {
store.deleteAllData()
Expand Down
20 changes: 0 additions & 20 deletions MatrixSDK/MXSDKOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic) BOOL enableRoomSharedHistoryOnInvite;

/**
Use the newer rust-based `MatrixCryptoSDK` instead of the legacy `MatrixSDK`'s internal crypto module.
@remark YES by default
*/
@property (nonatomic) BOOL enableCryptoSDK;

/**
Flag indicating whether this account requires a re-verification after migrating to Crypto SDK
Expand All @@ -220,11 +213,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic) BOOL needsVerificationUpgrade;

/**
The text-based identifier for the crypto module being used (e.g. native vs rust)
*/
@property (nonatomic, readonly) NSString *cryptoModuleId;

/**
Enable symmetric room key backups
Expand All @@ -239,14 +227,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic) BOOL enableNewClientInformationFeature;

/**
Enable the calculating and display of progress during session startup, incl store migration,
syncing and response processing.
@remark YES by default
*/
@property (nonatomic) BOOL enableStartupProgress;

@end

NS_ASSUME_NONNULL_END
7 changes: 0 additions & 7 deletions MatrixSDK/MXSDKOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,14 @@ - (instancetype)init
_authEnableRefreshTokens = NO;
_enableThreads = NO;
_enableRoomSharedHistoryOnInvite = NO;
_enableCryptoSDK = YES;
_needsVerificationUpgrade = NO;
_enableSymmetricBackup = NO;
_enableNewClientInformationFeature = NO;
_enableStartupProgress = YES;
}

return self;
}

- (NSString *)cryptoModuleId
{
return self.enableCryptoSDK ? @"rust" : @"native";
}

- (void)setRoomListDataManagerClass:(Class)roomListDataManagerClass
{
// Sanity check
Expand Down
20 changes: 2 additions & 18 deletions MatrixSDK/MXSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,17 +776,9 @@ typedef void (^MXOnBackgroundSyncFail)(NSError *error);
- (void)enableVoIPWithCallStack:(id<MXCallStack>)callStack;

/**
Enable End-to-End encryption.
In case of enabling, the operation will complete when the session will be ready
to make encrytion with other users devices
@param enableCrypto NO stops crypto and erases crypto data.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
Disable End-to-End encryption.
*/
- (void)enableCrypto:(BOOL)enableCrypto success:(void (^)(void))success failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
- (void)disableCrypto;

/**
Get the versions of the specification supported by the server.
Expand Down Expand Up @@ -1596,14 +1588,6 @@ typedef void (^MXOnBackgroundSyncFail)(NSError *error);
inTimeline:(NSString*)timeline
onComplete:(void (^)(NSArray<MXEvent*> *failedEvents))onComplete;

/**
Reset replay attack data for the given timeline.
@param timeline the id of the timeline.
*/
- (void)resetReplayAttackCheckInTimeline:(NSString*)timeline;


#pragma mark - Global events listeners
/**
Register a global listener to events related to the current session.
Expand Down
Loading

0 comments on commit 22c5ac7

Please sign in to comment.