From d75c881182125f7e63a741123495c980b81c159c Mon Sep 17 00:00:00 2001 From: Andy Uhnak Date: Mon, 18 Jul 2022 09:42:41 +0100 Subject: [PATCH 1/2] Convert verification request and transaction to protocols --- .../Verification/MXKeyVerificationManager.h | 14 +-- .../Verification/MXKeyVerificationManager.m | 116 +++++++++--------- .../MXKeyVerificationManager_Private.h | 12 +- .../Requests/MXKeyVerificationByDMRequest.h | 2 +- .../MXKeyVerificationByToDeviceRequest.h | 2 +- .../Requests/MXKeyVerificationRequest.h | 9 +- .../Requests/MXKeyVerificationRequest.m | 14 ++- .../MXKeyVerificationRequest_Private.h | 2 +- .../Verification/Status/MXKeyVerification.h | 4 +- .../Status/MXKeyVerificationStatusResolver.h | 2 +- .../Status/MXKeyVerificationStatusResolver.m | 10 +- .../MXKeyVerificationTransaction.h | 10 +- .../MXKeyVerificationTransaction.m | 13 +- .../MXKeyVerificationTransaction_Private.h | 2 +- .../Transactions/QRCode/MXQRCodeTransaction.h | 2 +- .../SAS/MXIncomingSASTransaction.h | 2 +- .../SAS/MXOutgoingSASTransaction.h | 2 +- .../Transactions/SAS/MXSASTransaction.h | 8 +- .../Transactions/SAS/MXSASTransaction.m | 9 +- .../SAS/MXSASTransaction_Private.h | 2 +- .../MXCrossSigningVerificationTests.m | 48 ++++---- MatrixSDKTests/MXCryptoKeyVerificationTests.m | 90 +++++++------- changelog.d/pr-1528.misc | 1 + 23 files changed, 209 insertions(+), 167 deletions(-) create mode 100644 changelog.d/pr-1528.misc diff --git a/MatrixSDK/Crypto/Verification/MXKeyVerificationManager.h b/MatrixSDK/Crypto/Verification/MXKeyVerificationManager.h index 50f029fcda..01fbd4107b 100644 --- a/MatrixSDK/Crypto/Verification/MXKeyVerificationManager.h +++ b/MatrixSDK/Crypto/Verification/MXKeyVerificationManager.h @@ -103,7 +103,7 @@ FOUNDATION_EXPORT NSString *const MXKeyVerificationManagerNotificationTransactio - (void)requestVerificationByToDeviceWithUserId:(NSString*)userId deviceIds:(nullable NSArray*)deviceIds methods:(NSArray*)methods - success:(void(^)(MXKeyVerificationRequest *request))success + success:(void(^)(id request))success failure:(void(^)(NSError *error))failure; /** @@ -120,13 +120,13 @@ FOUNDATION_EXPORT NSString *const MXKeyVerificationManagerNotificationTransactio roomId:(nullable NSString*)roomId fallbackText:(NSString*)fallbackText methods:(NSArray*)methods - success:(void(^)(MXKeyVerificationRequest *request))success + success:(void(^)(id request))success failure:(void(^)(NSError *error))failure; /** All pending verification requests. */ -@property (nonatomic, readonly) NSArray *pendingRequests; +@property (nonatomic, readonly) NSArray> *pendingRequests; #pragma mark - Transactions @@ -143,7 +143,7 @@ FOUNDATION_EXPORT NSString *const MXKeyVerificationManagerNotificationTransactio - (void)beginKeyVerificationWithUserId:(NSString*)userId andDeviceId:(NSString*)deviceId method:(NSString*)method - success:(void(^)(MXKeyVerificationTransaction *transaction))success + success:(void(^)(id transaction))success failure:(void(^)(NSError *error))failure __attribute__((deprecated("Start key verification with a request (requestVerificationByToDeviceWithUserId) instead"))); /** @@ -153,9 +153,9 @@ FOUNDATION_EXPORT NSString *const MXKeyVerificationManagerNotificationTransactio @param success a block called when the operation succeeds. @param failure a block called when the operation fails. */ -- (void)beginKeyVerificationFromRequest:(MXKeyVerificationRequest*)request +- (void)beginKeyVerificationFromRequest:(id)request method:(NSString*)method - success:(void(^)(MXKeyVerificationTransaction *transaction))success + success:(void(^)(id transaction))success failure:(void(^)(NSError *error))failure; /** @@ -163,7 +163,7 @@ FOUNDATION_EXPORT NSString *const MXKeyVerificationManagerNotificationTransactio @param complete a block called with all transactions. */ -- (void)transactions:(void(^)(NSArray *transactions))complete; +- (void)transactions:(void(^)(NSArray> *transactions))complete; #pragma mark - Verification status diff --git a/MatrixSDK/Crypto/Verification/MXKeyVerificationManager.m b/MatrixSDK/Crypto/Verification/MXKeyVerificationManager.m index a0e9f2671a..e86cdd7f64 100644 --- a/MatrixSDK/Crypto/Verification/MXKeyVerificationManager.m +++ b/MatrixSDK/Crypto/Verification/MXKeyVerificationManager.m @@ -63,13 +63,13 @@ @interface MXKeyVerificationManager () dispatch_queue_t cryptoQueue; // All running transactions - MXUsersDevicesMap *transactions; + MXUsersDevicesMap *transactions; // Timer to cancel transactions NSTimer *transactionTimeoutTimer; // All pending requests // Request id -> request - NSMutableDictionary *pendingRequestsMap; + NSMutableDictionary *pendingRequestsMap; // Timer to cancel requests NSTimer *requestTimeoutTimer; @@ -90,7 +90,7 @@ @implementation MXKeyVerificationManager - (void)requestVerificationByToDeviceWithUserId:(NSString*)userId deviceIds:(nullable NSArray*)deviceIds methods:(NSArray*)methods - success:(void(^)(MXKeyVerificationRequest *request))success + success:(void(^)(id request))success failure:(void(^)(NSError *error))failure { MXLogDebug(@"[MXKeyVerification] requestVerificationByToDeviceWithUserId: %@. deviceIds: %@", userId, deviceIds); @@ -140,7 +140,7 @@ - (void)otherDeviceIdsOfUser:(NSString*)userId - (void)requestVerificationByToDeviceWithUserId2:(NSString*)userId deviceIds:(NSArray*)deviceIds methods:(NSArray*)methods - success:(void(^)(MXKeyVerificationRequest *request))success + success:(void(^)(id request))success failure:(void(^)(NSError *error))failure { NSParameterAssert(deviceIds.count > 0); @@ -178,7 +178,7 @@ - (void)requestVerificationByDMWithUserId:(NSString*)userId roomId:(nullable NSString*)roomId fallbackText:(NSString*)fallbackText methods:(NSArray*)methods - success:(void(^)(MXKeyVerificationRequest *request))success + success:(void(^)(id request))success failure:(void(^)(NSError *error))failure { if (roomId) @@ -218,7 +218,7 @@ - (void)requestVerificationByDMWithUserId2:(NSString*)userId roomId:(NSString*)roomId fallbackText:(NSString*)fallbackText methods:(NSArray*)methods - success:(void(^)(MXKeyVerificationRequest *request))success + success:(void(^)(id request))success failure:(void(^)(NSError *error))failure { MXLogDebug(@"[MXKeyVerification] requestVerificationByDMWithUserId: %@. RoomId: %@", userId, roomId); @@ -235,7 +235,7 @@ - (void)requestVerificationByDMWithUserId2:(NSString*)userId MXRoom *room = [self.crypto.mxSession roomWithRoomId:roomId]; MXEvent *event = [room fakeRoomMessageEventWithEventId:eventId andContent:request.JSONDictionary threadId:nil]; - MXKeyVerificationRequest *request = [self verificationRequestInDMEvent:event]; + MXDefaultKeyVerificationRequest *request = [self verificationRequestInDMEvent:event]; [request updateState:MXKeyVerificationRequestStatePending notifiy:YES]; [self addPendingRequest:request notify:NO]; @@ -245,7 +245,7 @@ - (void)requestVerificationByDMWithUserId2:(NSString*)userId #pragma mark Current requests -- (NSArray *)pendingRequests +- (NSArray> *)pendingRequests { return pendingRequestsMap.allValues; } @@ -256,15 +256,15 @@ - (void)requestVerificationByDMWithUserId2:(NSString*)userId - (void)beginKeyVerificationWithUserId:(NSString*)userId andDeviceId:(NSString*)deviceId method:(NSString*)method - success:(void(^)(MXKeyVerificationTransaction *transaction))success + success:(void(^)(id transaction))success failure:(void(^)(NSError *error))failure { [self beginKeyVerificationWithUserId:userId andDeviceId:deviceId transactionId:nil dmRoomId:nil dmEventId:nil method:method success:success failure:failure]; } -- (void)beginKeyVerificationFromRequest:(MXKeyVerificationRequest*)request +- (void)beginKeyVerificationFromRequest:(id)request method:(NSString*)method - success:(void(^)(MXKeyVerificationTransaction *transaction))success + success:(void(^)(id transaction))success failure:(void(^)(NSError *error))failure { MXLogDebug(@"[MXKeyVerification] beginKeyVerificationFromRequest: event: %@", request.requestId); @@ -298,7 +298,7 @@ - (void)beginKeyVerificationFromRequest:(MXKeyVerificationRequest*)request if ([request isKindOfClass:MXKeyVerificationByDMRequest.class]) { MXKeyVerificationByDMRequest *requestByDM = (MXKeyVerificationByDMRequest*)request; - [self beginKeyVerificationWithUserId:request.otherUser andDeviceId:request.otherDevice transactionId:request.requestId dmRoomId:requestByDM.roomId dmEventId:requestByDM.eventId method:method success:^(MXKeyVerificationTransaction *transaction) { + [self beginKeyVerificationWithUserId:request.otherUser andDeviceId:request.otherDevice transactionId:request.requestId dmRoomId:requestByDM.roomId dmEventId:requestByDM.eventId method:method success:^(id transaction) { [self removePendingRequestWithRequestId:request.requestId]; success(transaction); } failure:failure]; @@ -306,7 +306,7 @@ - (void)beginKeyVerificationFromRequest:(MXKeyVerificationRequest*)request break; case MXKeyVerificationTransportToDevice: - [self beginKeyVerificationWithUserId:request.otherUser andDeviceId:request.otherDevice transactionId:request.requestId dmRoomId:nil dmEventId:nil method:method success:^(MXKeyVerificationTransaction * _Nonnull transaction) { + [self beginKeyVerificationWithUserId:request.otherUser andDeviceId:request.otherDevice transactionId:request.requestId dmRoomId:nil dmEventId:nil method:method success:^(id _Nonnull transaction) { [self removePendingRequestWithRequestId:request.requestId]; success(transaction); } failure:failure]; @@ -320,7 +320,7 @@ - (void)beginKeyVerificationWithUserId:(NSString*)userId dmRoomId:(nullable NSString*)dmRoomId dmEventId:(nullable NSString*)dmEventId method:(NSString*)method - success:(void(^)(MXKeyVerificationTransaction *transaction))success + success:(void(^)(id transaction))success failure:(void(^)(NSError *error))failure { MXLogDebug(@"[MXKeyVerification] beginKeyVerification: device: %@:%@ roomId: %@ method:%@", userId, deviceId, dmRoomId, method); @@ -328,7 +328,7 @@ - (void)beginKeyVerificationWithUserId:(NSString*)userId // Make sure we have other device keys [self loadDeviceWithDeviceId:deviceId andUserId:userId success:^(MXDeviceInfo *otherDevice) { - MXKeyVerificationTransaction *transaction; + id transaction; NSError *error; // We support only SAS at the moment @@ -377,7 +377,7 @@ - (void)beginKeyVerificationWithUserId:(NSString*)userId }]; } -- (void)createQRCodeTransactionFromRequest:(MXKeyVerificationRequest*)request +- (void)createQRCodeTransactionFromRequest:(id)request qrCodeData:(nullable MXQRCodeData*)qrCodeData success:(void(^)(MXQRCodeTransaction *transaction))success failure:(void(^)(NSError *error))failure @@ -502,13 +502,13 @@ - (void)removeQRCodeTransactionWithTransactionId:(NSString*)transactionId } } -- (void)transactions:(void(^)(NSArray *transactions))complete +- (void)transactions:(void(^)(NSArray> *transactions))complete { MXWeakify(self); dispatch_async(self->cryptoQueue, ^{ MXStrongifyAndReturnIfNil(self); - NSArray *transactions = self->transactions.allObjects; + NSArray> *transactions = self->transactions.allObjects; dispatch_async(dispatch_get_main_queue(), ^{ complete(transactions); }); @@ -575,8 +575,8 @@ - (nullable NSString *)keyVerificationIdFromDMEvent:(MXEvent*)event - (nullable MXKeyVerification *)pendingKeyVerificationWithKeyVerificationId:(NSString*)keyVerificationId { - MXKeyVerificationTransaction *transaction = [self transactionWithTransactionId:keyVerificationId]; - MXKeyVerificationRequest *request = [self pendingRequestWithRequestId:keyVerificationId]; + id transaction = [self transactionWithTransactionId:keyVerificationId]; + MXDefaultKeyVerificationRequest *request = [self pendingRequestWithRequestId:keyVerificationId]; return [self->statusResolver keyVerificationFromRequest:request andTransaction:transaction]; } @@ -639,7 +639,7 @@ - (void)dealloc #pragma mark - Requests -- (MXHTTPOperation*)sendToOtherInRequest:(MXKeyVerificationRequest*)request +- (MXHTTPOperation*)sendToOtherInRequest:(id)request eventType:(NSString*)eventType content:(NSDictionary*)content success:(dispatch_block_t)success @@ -706,14 +706,14 @@ - (void)notifyOthersOfAcceptanceWithTransactionId:(NSString*)transactionId } failure:failure]; } -- (void)cancelVerificationRequest:(MXKeyVerificationRequest*)request +- (void)cancelVerificationRequest:(id)request success:(void(^)(void))success failure:(void(^)(NSError *error))failure { MXTransactionCancelCode *cancelCode = MXTransactionCancelCode.user; // If there is transaction in progress, cancel it - MXKeyVerificationTransaction *transaction = [self transactionWithTransactionId:request.requestId]; + id transaction = [self transactionWithTransactionId:request.requestId]; if (transaction) { [self cancelTransaction:transaction code:cancelCode success:success failure:failure]; @@ -733,7 +733,7 @@ - (void)cancelVerificationRequest:(MXKeyVerificationRequest*)request #pragma mark - Transactions -- (MXHTTPOperation*)sendToOtherInTransaction:(MXKeyVerificationTransaction*)transaction +- (MXHTTPOperation*)sendToOtherInTransaction:(id)transaction eventType:(NSString*)eventType content:(NSDictionary*)content success:(void (^)(void))success @@ -757,7 +757,7 @@ - (MXHTTPOperation*)sendToOtherInTransaction:(MXKeyVerificationTransaction*)tran return operation; } -- (void)cancelTransaction:(MXKeyVerificationTransaction*)transaction +- (void)cancelTransaction:(id)transaction code:(MXTransactionCancelCode*)code success:(void (^)(void))success failure:(void (^)(NSError *error))failure @@ -932,7 +932,7 @@ - (void)handleReadyEvent:(MXEvent*)event isToDeviceEvent:(BOOL)isToDeviceEvent } NSString *requestId = keyVerificationReady.transactionId; - MXKeyVerificationRequest *request = [self pendingRequestWithRequestId:requestId]; + MXDefaultKeyVerificationRequest *request = [self pendingRequestWithRequestId:requestId]; if (request) { @@ -968,7 +968,7 @@ - (void)handleCancelEvent:(MXEvent*)event if (cancelContent) { - MXKeyVerificationTransaction *transaction = [self transactionWithTransactionId:cancelContent.transactionId]; + MXDefaultKeyVerificationTransaction *transaction = [self transactionWithTransactionId:cancelContent.transactionId]; if (transaction) { [transaction handleCancel:cancelContent]; @@ -976,7 +976,7 @@ - (void)handleCancelEvent:(MXEvent*)event } NSString *requestId = cancelContent.transactionId; - MXKeyVerificationRequest *request = [self pendingRequestWithRequestId:requestId]; + MXDefaultKeyVerificationRequest *request = [self pendingRequestWithRequestId:requestId]; if (request) { [request handleCancel:cancelContent]; @@ -1026,7 +1026,7 @@ - (void)handleSASKeyVerificationStart:(MXSASKeyVerificationStart*)keyVerificatio } NSString *requestId = keyVerificationStart.transactionId; - MXKeyVerificationRequest *request = [self pendingRequestWithRequestId:requestId]; + MXDefaultKeyVerificationRequest *request = [self pendingRequestWithRequestId:requestId]; if (request) { // We have a start response. The request is complete @@ -1058,7 +1058,7 @@ - (void)handleSASKeyVerificationStart:(MXSASKeyVerificationStart*)keyVerificatio // Make sure we have other device keys [self loadDeviceWithDeviceId:keyVerificationStart.fromDevice andUserId:event.sender success:^(MXDeviceInfo *otherDevice) { - MXKeyVerificationTransaction *existingTransaction = [self transactionWithUser:event.sender andDevice:keyVerificationStart.fromDevice]; + id existingTransaction = [self transactionWithUser:event.sender andDevice:keyVerificationStart.fromDevice]; if ([existingTransaction isKindOfClass:MXQRCodeTransaction.class]) { @@ -1082,7 +1082,7 @@ - (void)handleSASKeyVerificationStart:(MXSASKeyVerificationStart*)keyVerificatio } // Multiple keyshares between two devices: any two devices may only have at most one key verification in flight at a time. - NSArray *transactionsWithUser = [self transactionsWithUser:event.sender]; + NSArray> *transactionsWithUser = [self transactionsWithUser:event.sender]; if (transactionsWithUser.count) { MXLogDebug(@"[MXKeyVerification] handleStartEvent: already existing transaction with the user. Cancel both"); @@ -1132,7 +1132,7 @@ - (void)handleAcceptEvent:(MXEvent*)event if (acceptContent) { - MXSASTransaction *transaction = [self sasTransactionWithTransactionId:acceptContent.transactionId]; + MXDefaultSASTransaction *transaction = [self sasTransactionWithTransactionId:acceptContent.transactionId]; if (transaction) { [transaction handleAccept:acceptContent]; @@ -1157,7 +1157,7 @@ - (void)handleKeyEvent:(MXEvent*)event if (keyContent) { - MXSASTransaction *transaction = [self sasTransactionWithTransactionId:keyContent.transactionId]; + MXDefaultSASTransaction *transaction = [self sasTransactionWithTransactionId:keyContent.transactionId]; if (transaction) { [transaction handleKey:keyContent]; @@ -1182,7 +1182,7 @@ - (void)handleMacEvent:(MXEvent*)event if (macContent) { - MXSASTransaction *transaction = [self sasTransactionWithTransactionId:macContent.transactionId]; + MXDefaultSASTransaction *transaction = [self sasTransactionWithTransactionId:macContent.transactionId]; if (transaction) { [transaction handleMac:macContent]; @@ -1215,7 +1215,7 @@ - (void)handleDoneEvent:(MXEvent*)event MXLogDebug(@"[MXKeyVerification] handleDoneEvent. Not handled for SAS transaction: %@", event); } - MXKeyVerificationTransaction *transaction = [self transactionWithTransactionId:doneEvent.transactionId]; + id transaction = [self transactionWithTransactionId:doneEvent.transactionId]; if (transaction && transaction.otherDeviceId) { BOOL eventFromMyDevice = [transaction.otherDeviceId isEqualToString:self.crypto.mxSession.myDeviceId]; @@ -1251,7 +1251,7 @@ - (void)handleQRCodeKeyVerificationStart:(MXQRCodeKeyVerificationStart*)keyVerif } NSString *requestId = keyVerificationStart.transactionId; - MXKeyVerificationRequest *request = [self pendingRequestWithRequestId:requestId]; + MXDefaultKeyVerificationRequest *request = [self pendingRequestWithRequestId:requestId]; if (request) { // We have a start response. The request is complete @@ -1529,7 +1529,7 @@ - (void)computeReadyMethodsFromVerificationRequestWithId:(NSString*)transactionI andSupportedMethods:(NSArray*)supportedMethods completion:(void (^)(NSArray* readyMethods, MXQRCodeData *qrCodeData))completion; { - MXKeyVerificationRequest *keyVerificationRequest = [self pendingRequestWithRequestId:transactionId]; + MXDefaultKeyVerificationRequest *keyVerificationRequest = [self pendingRequestWithRequestId:transactionId]; if (!keyVerificationRequest) { @@ -1661,12 +1661,12 @@ - (nullable MXKeyVerificationByDMRequest*)verificationRequestInDMEvent:(MXEvent* return request; } -- (nullable MXKeyVerificationRequest*)pendingRequestWithRequestId:(NSString*)requestId +- (nullable MXDefaultKeyVerificationRequest*)pendingRequestWithRequestId:(NSString*)requestId { return pendingRequestsMap[requestId]; } -- (void)addPendingRequest:(MXKeyVerificationRequest *)request notify:(BOOL)notify +- (void)addPendingRequest:(id)request notify:(BOOL)notify { if (!pendingRequestsMap[request.requestId]) { @@ -1700,7 +1700,7 @@ - (void)removePendingRequestWithRequestId:(NSString*)requestId - (nullable NSDate*)oldestRequestDate { NSDate *oldestRequestDate; - for (MXKeyVerificationRequest *request in pendingRequestsMap.allValues) + for (id request in pendingRequestsMap.allValues) { if (!oldestRequestDate || request.timestamp < oldestRequestDate.timeIntervalSince1970) @@ -1711,7 +1711,7 @@ - (nullable NSDate*)oldestRequestDate return oldestRequestDate; } -- (BOOL)isRequestStillValid:(MXKeyVerificationRequest*)request +- (BOOL)isRequestStillValid:(id)request { NSDate *requestDate = [NSDate dateWithTimeIntervalSince1970:(request.timestamp / 1000)]; return (requestDate.timeIntervalSinceNow > -_requestTimeout); @@ -1759,7 +1759,7 @@ - (void)onRequestTimeoutTimer - (void)checkRequestTimeoutsWithCompletion:(dispatch_block_t)completionBlock { dispatch_group_t group = dispatch_group_create(); - for (MXKeyVerificationRequest *request in pendingRequestsMap.allValues) + for (id request in pendingRequestsMap.allValues) { if (![self isRequestStillValid:request]) { @@ -1780,20 +1780,20 @@ - (void)checkRequestTimeoutsWithCompletion:(dispatch_block_t)completionBlock #pragma mark - Transactions queue -- (MXKeyVerificationTransaction*)transactionWithUser:(NSString*)userId andDevice:(NSString*)deviceId +- (id)transactionWithUser:(NSString*)userId andDevice:(NSString*)deviceId { return [transactions objectForDevice:deviceId forUser:userId]; } -- (NSArray*)transactionsWithUser:(NSString*)userId +- (NSArray>*)transactionsWithUser:(NSString*)userId { return [transactions objectsForUser:userId]; } -- (MXKeyVerificationTransaction*)transactionWithTransactionId:(NSString*)transactionId +- (MXDefaultKeyVerificationTransaction *)transactionWithTransactionId:(NSString*)transactionId { - MXKeyVerificationTransaction *transaction; - for (MXKeyVerificationTransaction *t in transactions.allObjects) + MXDefaultKeyVerificationTransaction *transaction; + for (MXDefaultKeyVerificationTransaction *t in transactions.allObjects) { if ([t.transactionId isEqualToString:transactionId]) { @@ -1805,15 +1805,15 @@ - (MXKeyVerificationTransaction*)transactionWithTransactionId:(NSString*)transac return transaction; } -- (MXSASTransaction*)sasTransactionWithTransactionId:(NSString*)transactionId +- (MXDefaultSASTransaction *)sasTransactionWithTransactionId:(NSString*)transactionId { - MXSASTransaction *sasTransaction; + MXDefaultSASTransaction *sasTransaction; - MXKeyVerificationTransaction *transaction = [self transactionWithTransactionId:transactionId]; + MXDefaultKeyVerificationTransaction *transaction = [self transactionWithTransactionId:transactionId]; - if ([transaction isKindOfClass:MXSASTransaction.class]) + if ([transaction isKindOfClass:[MXDefaultSASTransaction class]]) { - sasTransaction = (MXSASTransaction *)transaction; + sasTransaction = (MXDefaultSASTransaction *)transaction; } return sasTransaction; @@ -1823,7 +1823,7 @@ - (MXQRCodeTransaction*)qrCodeTransactionWithTransactionId:(NSString*)transactio { MXQRCodeTransaction *qrCodeTransaction; - MXKeyVerificationTransaction *transaction = [self transactionWithTransactionId:transactionId]; + id transaction = [self transactionWithTransactionId:transactionId]; if ([transaction isKindOfClass:MXQRCodeTransaction.class]) { @@ -1833,7 +1833,7 @@ - (MXQRCodeTransaction*)qrCodeTransactionWithTransactionId:(NSString*)transactio return qrCodeTransaction; } -- (void)addTransaction:(MXKeyVerificationTransaction*)transaction +- (void)addTransaction:(id)transaction { [transactions setObject:transaction forUser:transaction.otherUserId andDevice:transaction.otherDeviceId]; [self scheduleTransactionTimeoutTimer]; @@ -1848,7 +1848,7 @@ - (void)addTransaction:(MXKeyVerificationTransaction*)transaction - (void)removeTransactionWithTransactionId:(NSString*)transactionId { - MXKeyVerificationTransaction *transaction = [self transactionWithTransactionId:transactionId]; + id transaction = [self transactionWithTransactionId:transactionId]; if (transaction) { [transactions removeObjectForUser:transaction.otherUserId andDevice:transaction.otherDeviceId]; @@ -1859,7 +1859,7 @@ - (void)removeTransactionWithTransactionId:(NSString*)transactionId - (nullable NSDate*)oldestTransactionCreationDate { NSDate *oldestCreationDate; - for (MXKeyVerificationTransaction *transaction in transactions.allObjects) + for (id transaction in transactions.allObjects) { if (!oldestCreationDate || transaction.creationDate.timeIntervalSince1970 < oldestCreationDate.timeIntervalSince1970) @@ -1870,7 +1870,7 @@ - (nullable NSDate*)oldestTransactionCreationDate return oldestCreationDate; } -- (BOOL)isCreationDateValid:(MXKeyVerificationTransaction*)transaction +- (BOOL)isCreationDateValid:(id)transaction { return (transaction.creationDate.timeIntervalSinceNow > -MXTransactionTimeout); } @@ -1934,7 +1934,7 @@ - (void)onTransactionTimeoutTimer - (void)checkTransactionTimeouts { - for (MXKeyVerificationTransaction *transaction in transactions.allObjects) + for (id transaction in transactions.allObjects) { if (![self isCreationDateValid:transaction]) { diff --git a/MatrixSDK/Crypto/Verification/MXKeyVerificationManager_Private.h b/MatrixSDK/Crypto/Verification/MXKeyVerificationManager_Private.h index 4d2e84716b..9ad0f6fcd7 100644 --- a/MatrixSDK/Crypto/Verification/MXKeyVerificationManager_Private.h +++ b/MatrixSDK/Crypto/Verification/MXKeyVerificationManager_Private.h @@ -55,7 +55,7 @@ NS_ASSUME_NONNULL_BEGIN @return a MXHTTPOperation instance. */ -- (MXHTTPOperation*)sendToOtherInRequest:(MXKeyVerificationRequest*)request +- (MXHTTPOperation*)sendToOtherInRequest:(id)request eventType:(NSString*)eventType content:(NSDictionary*)content success:(dispatch_block_t)success @@ -68,11 +68,11 @@ NS_ASSUME_NONNULL_BEGIN @param success a block called when the operation succeeds. @param failure a block called when the operation fails. */ -- (void)cancelVerificationRequest:(MXKeyVerificationRequest*)request +- (void)cancelVerificationRequest:(id)request success:(void(^)(void))success failure:(void(^)(NSError *error))failure; -- (BOOL)isRequestStillValid:(MXKeyVerificationRequest*)request; +- (BOOL)isRequestStillValid:(id)request; - (void)removePendingRequestWithRequestId:(NSString*)requestId; @@ -91,7 +91,7 @@ NS_ASSUME_NONNULL_BEGIN success:(void(^)(MXQRCodeTransaction *transaction))success failure:(void(^)(NSError *error))failure; -- (void)createQRCodeTransactionFromRequest:(MXKeyVerificationRequest*)request +- (void)createQRCodeTransactionFromRequest:(id)request qrCodeData:(nullable MXQRCodeData*)qrCodeData success:(void(^)(MXQRCodeTransaction *transaction))success failure:(void(^)(NSError *error))failure; @@ -112,7 +112,7 @@ NS_ASSUME_NONNULL_BEGIN @return a MXHTTPOperation instance. */ -- (MXHTTPOperation*)sendToOtherInTransaction:(MXKeyVerificationTransaction*)transaction +- (MXHTTPOperation*)sendToOtherInTransaction:(id)transaction eventType:(NSString*)eventType content:(NSDictionary*)content success:(void (^)(void))success @@ -126,7 +126,7 @@ NS_ASSUME_NONNULL_BEGIN @param success A block object called when the operation succeeds. @param failure A block object called when the operation fails. */ -- (void)cancelTransaction:(MXKeyVerificationTransaction*)transaction +- (void)cancelTransaction:(id)transaction code:(MXTransactionCancelCode*)code success:(void (^)(void))success failure:(void (^)(NSError *error))failure; diff --git a/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationByDMRequest.h b/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationByDMRequest.h index ee9ac1d13b..00d5d2b3e9 100644 --- a/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationByDMRequest.h +++ b/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationByDMRequest.h @@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN /** An handler on an interactive request for verification by Direct Message. */ -@interface MXKeyVerificationByDMRequest : MXKeyVerificationRequest +@interface MXKeyVerificationByDMRequest : MXDefaultKeyVerificationRequest @property (nonatomic, readonly) NSString *roomId; @property (nonatomic, readonly) NSString *eventId; diff --git a/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationByToDeviceRequest.h b/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationByToDeviceRequest.h index ec22138912..ff9e034dae 100644 --- a/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationByToDeviceRequest.h +++ b/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationByToDeviceRequest.h @@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN /** An handler on an interactive request for verification by to_device events. */ -@interface MXKeyVerificationByToDeviceRequest : MXKeyVerificationRequest +@interface MXKeyVerificationByToDeviceRequest : MXDefaultKeyVerificationRequest @property (nonatomic, readonly) MXKeyVerificationRequestByToDeviceJSONModel *request; diff --git a/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest.h b/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest.h index da07a47237..ac96bc45e7 100644 --- a/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest.h +++ b/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest.h @@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN /** An handler on an interactive verification request. */ -@interface MXKeyVerificationRequest : NSObject +@protocol MXKeyVerificationRequest /** Accept an incoming key verification request. @@ -107,4 +107,11 @@ Accept an incoming key verification request. @end +/** + Default implementation of verification request used by the SDK + */ +@interface MXDefaultKeyVerificationRequest : NSObject + +@end + NS_ASSUME_NONNULL_END diff --git a/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest.m b/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest.m index 117869c222..aeea57bf9d 100644 --- a/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest.m +++ b/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest.m @@ -24,13 +24,23 @@ #pragma mark - Constants NSString * const MXKeyVerificationRequestDidChangeNotification = @"MXKeyVerificationRequestDidChangeNotification"; -@interface MXKeyVerificationRequest() +@interface MXDefaultKeyVerificationRequest() @property (nonatomic, readwrite) MXKeyVerificationRequestState state; @end -@implementation MXKeyVerificationRequest +@implementation MXDefaultKeyVerificationRequest + +@synthesize event = _event; +@synthesize fromDevice = _fromDevice; +@synthesize methods = _methods; +@synthesize otherDevice = _otherDevice; +@synthesize otherUser = _otherUser; +@synthesize reasonCancelCode = _reasonCancelCode; +@synthesize requestId = _requestId; +@synthesize timestamp = _timestamp; +@synthesize transport = _transport; #pragma mark - SDK-Private methods - diff --git a/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest_Private.h b/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest_Private.h index 62f816498e..c3462a138c 100644 --- a/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest_Private.h +++ b/MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest_Private.h @@ -25,7 +25,7 @@ /** The `MXKeyVerificationRequest` extension exposes internal operations. */ -@interface MXKeyVerificationRequest () +@interface MXDefaultKeyVerificationRequest () @property (nonatomic, readonly, weak) MXKeyVerificationManager *manager; diff --git a/MatrixSDK/Crypto/Verification/Status/MXKeyVerification.h b/MatrixSDK/Crypto/Verification/Status/MXKeyVerification.h index 71eb0f8dc3..a94835f79c 100644 --- a/MatrixSDK/Crypto/Verification/Status/MXKeyVerification.h +++ b/MatrixSDK/Crypto/Verification/Status/MXKeyVerification.h @@ -54,8 +54,8 @@ typedef NS_ENUM(NSInteger, MXKeyVerificationState) @property (nonatomic) MXKeyVerificationState state; // Those values may be not provided if there are not in progress -@property (nonatomic, nullable) MXKeyVerificationRequest *request; -@property (nonatomic, nullable) MXKeyVerificationTransaction *transaction; +@property (nonatomic, nullable) id request; +@property (nonatomic, nullable) id transaction; @property (nonatomic, readonly) BOOL isRequestAccepted; diff --git a/MatrixSDK/Crypto/Verification/Status/MXKeyVerificationStatusResolver.h b/MatrixSDK/Crypto/Verification/Status/MXKeyVerificationStatusResolver.h index 89489d9d9e..68c531e228 100644 --- a/MatrixSDK/Crypto/Verification/Status/MXKeyVerificationStatusResolver.h +++ b/MatrixSDK/Crypto/Verification/Status/MXKeyVerificationStatusResolver.h @@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN success:(void(^)(MXKeyVerification *keyVerification))success failure:(void(^)(NSError *error))failure; -- (nullable MXKeyVerification*)keyVerificationFromRequest:(nullable MXKeyVerificationRequest*)request andTransaction:(nullable MXKeyVerificationTransaction*)transaction; +- (nullable MXKeyVerification*)keyVerificationFromRequest:(nullable id)request andTransaction:(nullable id)transaction; @end diff --git a/MatrixSDK/Crypto/Verification/Status/MXKeyVerificationStatusResolver.m b/MatrixSDK/Crypto/Verification/Status/MXKeyVerificationStatusResolver.m index 7be84277cc..284beaa71b 100644 --- a/MatrixSDK/Crypto/Verification/Status/MXKeyVerificationStatusResolver.m +++ b/MatrixSDK/Crypto/Verification/Status/MXKeyVerificationStatusResolver.m @@ -98,7 +98,7 @@ - (nullable MXHTTPOperation *)keyVerificationWithKeyVerificationId:(NSString*)ke return operation; } -- (nullable MXKeyVerification*)keyVerificationFromRequest:(nullable MXKeyVerificationRequest*)request andTransaction:(nullable MXKeyVerificationTransaction*)transaction +- (nullable MXKeyVerification*)keyVerificationFromRequest:(nullable id)request andTransaction:(nullable id)transaction { if (!request && !transaction) { @@ -140,7 +140,7 @@ - (nullable MXKeyVerification *)makeKeyVerificationFromOriginalDMEvent:(nullable { MXKeyVerification *keyVerification; - MXKeyVerificationRequest *request = [self verificationRequestInDMEvent:originalEvent events:events]; + id request = [self verificationRequestInDMEvent:originalEvent events:events]; if (request) { @@ -334,7 +334,7 @@ - (MXKeyVerificationState)stateFromRequestState:(MXKeyVerificationRequestState)r return state; } -- (MXKeyVerificationState)stateFromRequest:(nullable MXKeyVerificationRequest*)request andTransaction:(nullable MXKeyVerificationTransaction*)transaction +- (MXKeyVerificationState)stateFromRequest:(nullable id)request andTransaction:(nullable id)transaction { MXKeyVerificationState keyVerificationState = MXKeyVerificationStateRequestPending; @@ -377,9 +377,9 @@ - (MXKeyVerificationState)stateFromRequest:(nullable MXKeyVerificationRequest*)r break; } } - else if ([transaction isKindOfClass:MXSASTransaction.class]) + else if ([transaction conformsToProtocol:@protocol(MXSASTransaction)]) { - MXSASTransaction *sasTransaction = (MXSASTransaction*)transaction; + id sasTransaction = (id)transaction; switch (sasTransaction.state) { case MXSASTransactionStateVerified: diff --git a/MatrixSDK/Crypto/Verification/Transactions/MXKeyVerificationTransaction.h b/MatrixSDK/Crypto/Verification/Transactions/MXKeyVerificationTransaction.h index 2e93ff0cb9..bf928b0201 100644 --- a/MatrixSDK/Crypto/Verification/Transactions/MXKeyVerificationTransaction.h +++ b/MatrixSDK/Crypto/Verification/Transactions/MXKeyVerificationTransaction.h @@ -34,11 +34,10 @@ typedef NS_ENUM(NSInteger, MXKeyVerificationTransport) { MXKeyVerificationTransportDirectMessage, }; - /** An handler on an interactive device verification. */ -@interface MXKeyVerificationTransaction: NSObject +@protocol MXKeyVerificationTransaction /** The transaction id. @@ -113,4 +112,11 @@ typedef NS_ENUM(NSInteger, MXKeyVerificationTransport) { @end +/** + Default implementation of verification transaction used by the SDK + */ +@interface MXDefaultKeyVerificationTransaction: NSObject + +@end + NS_ASSUME_NONNULL_END diff --git a/MatrixSDK/Crypto/Verification/Transactions/MXKeyVerificationTransaction.m b/MatrixSDK/Crypto/Verification/Transactions/MXKeyVerificationTransaction.m index 738406995d..3beecfb938 100644 --- a/MatrixSDK/Crypto/Verification/Transactions/MXKeyVerificationTransaction.m +++ b/MatrixSDK/Crypto/Verification/Transactions/MXKeyVerificationTransaction.m @@ -27,7 +27,16 @@ NSString * const MXKeyVerificationTransactionDidChangeNotification = @"MXKeyVerificationTransactionDidChangeNotification"; -@implementation MXKeyVerificationTransaction +@implementation MXDefaultKeyVerificationTransaction + +@synthesize creationDate = _creationDate; +@synthesize dmEventId = _dmEventId; +@synthesize dmRoomId = _dmRoomId; +@synthesize error = _error; +@synthesize isIncoming = _isIncoming; +@synthesize otherDevice = _otherDevice; +@synthesize reasonCancelCode = _reasonCancelCode; +@synthesize transport = _transport; - (instancetype)initWithOtherDevice:(MXDeviceInfo*)otherDevice andManager:(MXKeyVerificationManager*)manager; { @@ -36,7 +45,7 @@ - (instancetype)initWithOtherDevice:(MXDeviceInfo*)otherDevice andManager:(MXKey { _manager = manager; _otherDevice = otherDevice; - _transactionId = [MXKeyVerificationTransaction createUniqueIdWithOtherUser:self.otherUserId otherDevice:self.otherDeviceId myUser:manager.crypto.mxSession.matrixRestClient.credentials]; + _transactionId = [MXDefaultKeyVerificationTransaction createUniqueIdWithOtherUser:self.otherUserId otherDevice:self.otherDeviceId myUser:manager.crypto.mxSession.matrixRestClient.credentials]; _creationDate = [NSDate date]; } return self; diff --git a/MatrixSDK/Crypto/Verification/Transactions/MXKeyVerificationTransaction_Private.h b/MatrixSDK/Crypto/Verification/Transactions/MXKeyVerificationTransaction_Private.h index 910cf77f0e..ff5f78451d 100644 --- a/MatrixSDK/Crypto/Verification/Transactions/MXKeyVerificationTransaction_Private.h +++ b/MatrixSDK/Crypto/Verification/Transactions/MXKeyVerificationTransaction_Private.h @@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MXKeyVerificationTransaction` extension exposes internal operations. */ -@interface MXKeyVerificationTransaction () +@interface MXDefaultKeyVerificationTransaction () @property (nonatomic, readonly, weak) MXKeyVerificationManager *manager; @property (nonatomic, readwrite) NSString *transactionId; diff --git a/MatrixSDK/Crypto/Verification/Transactions/QRCode/MXQRCodeTransaction.h b/MatrixSDK/Crypto/Verification/Transactions/QRCode/MXQRCodeTransaction.h index dd7b3db250..3e10a2f09c 100644 --- a/MatrixSDK/Crypto/Verification/Transactions/QRCode/MXQRCodeTransaction.h +++ b/MatrixSDK/Crypto/Verification/Transactions/QRCode/MXQRCodeTransaction.h @@ -40,7 +40,7 @@ typedef NS_ENUM(NSInteger, MXQRCodeTransactionState) { /** An handler on an interactive device verification based on QR Code. */ -@interface MXQRCodeTransaction : MXKeyVerificationTransaction +@interface MXQRCodeTransaction : MXDefaultKeyVerificationTransaction @property (nonatomic) MXQRCodeTransactionState state; diff --git a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXIncomingSASTransaction.h b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXIncomingSASTransaction.h index cd50408776..4996a2c141 100644 --- a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXIncomingSASTransaction.h +++ b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXIncomingSASTransaction.h @@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN /** An handler on an incoming SAS device verification. */ -@interface MXIncomingSASTransaction : MXSASTransaction +@interface MXIncomingSASTransaction : MXDefaultSASTransaction /** Accept the device verification request. diff --git a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXOutgoingSASTransaction.h b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXOutgoingSASTransaction.h index 8bed16643f..e4998e64a7 100644 --- a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXOutgoingSASTransaction.h +++ b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXOutgoingSASTransaction.h @@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN /** An handler on an outgoing SAS device verification. */ -@interface MXOutgoingSASTransaction : MXSASTransaction +@interface MXOutgoingSASTransaction : MXDefaultSASTransaction /** Start the device verification process. diff --git a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransaction.h b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransaction.h index f5233ceb1d..aa0f8e1a0e 100644 --- a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransaction.h +++ b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransaction.h @@ -48,7 +48,7 @@ typedef enum : NSUInteger /** An handler on an interactive device verification based on Short Authentication Code. */ -@interface MXSASTransaction : MXKeyVerificationTransaction +@protocol MXSASTransaction @property (nonatomic) MXSASTransactionState state; @@ -75,4 +75,10 @@ typedef enum : NSUInteger @end +/** + Default implementation of SAS transaction used by the SDK + */ +@interface MXDefaultSASTransaction : MXDefaultKeyVerificationTransaction +@end + NS_ASSUME_NONNULL_END diff --git a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransaction.m b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransaction.m index 1bf97eab47..7daefee12f 100644 --- a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransaction.m +++ b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransaction.m @@ -46,14 +46,17 @@ static NSArray *kSasEmojis; -@implementation MXSASTransaction +@implementation MXDefaultSASTransaction + +@synthesize state = _state; +@synthesize sasBytes = _sasBytes; - (NSString *)sasDecimal { NSString *sasDecimal; if (_sasBytes && [self.accepted.shortAuthenticationString containsObject:MXKeyVerificationSASModeDecimal]) { - sasDecimal = [[MXSASTransaction decimalRepresentationForSas:_sasBytes] componentsJoinedByString:@" "]; + sasDecimal = [[MXDefaultSASTransaction decimalRepresentationForSas:_sasBytes] componentsJoinedByString:@" "]; } return sasDecimal; @@ -64,7 +67,7 @@ - (NSString *)sasDecimal NSArray *sasEmoji; if (_sasBytes && [self.accepted.shortAuthenticationString containsObject:MXKeyVerificationSASModeEmoji]) { - sasEmoji = [MXSASTransaction emojiRepresentationForSas:_sasBytes]; + sasEmoji = [MXDefaultSASTransaction emojiRepresentationForSas:_sasBytes]; } return sasEmoji; diff --git a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransaction_Private.h b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransaction_Private.h index 75d092210c..39cc5f78e7 100644 --- a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransaction_Private.h +++ b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransaction_Private.h @@ -37,7 +37,7 @@ FOUNDATION_EXPORT NSArray *kKnownShortCodes; /** The `MXKeyVerificationTransaction` extension exposes internal operations. */ -@interface MXSASTransaction () +@interface MXDefaultSASTransaction () @property (nonatomic) OLMSAS *olmSAS; @property (nonatomic, nullable) MXSASKeyVerificationStart *startContent; diff --git a/MatrixSDKTests/MXCrossSigningVerificationTests.m b/MatrixSDKTests/MXCrossSigningVerificationTests.m index 26a7435ab6..917e706abf 100644 --- a/MatrixSDKTests/MXCrossSigningVerificationTests.m +++ b/MatrixSDKTests/MXCrossSigningVerificationTests.m @@ -34,7 +34,7 @@ @interface MXKeyVerificationManager (Testing) -- (MXKeyVerificationTransaction*)transactionWithTransactionId:(NSString*)transactionId; +- (id)transactionWithTransactionId:(NSString*)transactionId; - (MXQRCodeTransaction*)qrCodeTransactionWithTransactionId:(NSString*)transactionId; @end @@ -77,7 +77,7 @@ - (void)observeSASIncomingTransactionInSession:(MXSession*)session block:(void ( { id observer = [[NSNotificationCenter defaultCenter] addObserverForName:MXKeyVerificationManagerNewTransactionNotification object:session.crypto.keyVerificationManager queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { - MXKeyVerificationTransaction *transaction = notif.userInfo[MXKeyVerificationManagerNotificationTransactionKey]; + idtransaction = notif.userInfo[MXKeyVerificationManagerNotificationTransactionKey]; if (transaction.isIncoming && [transaction isKindOfClass:MXIncomingSASTransaction.class]) { block((MXIncomingSASTransaction*)transaction); @@ -95,7 +95,7 @@ - (void)observeNewQRCodeTransactionInSession:(MXSession*)session block:(void (^) { id observer = [[NSNotificationCenter defaultCenter] addObserverForName:MXKeyVerificationManagerNewTransactionNotification object:session.crypto.keyVerificationManager queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { - MXKeyVerificationTransaction *transaction = notif.userInfo[MXKeyVerificationManagerNotificationTransactionKey]; + idtransaction = notif.userInfo[MXKeyVerificationManagerNotificationTransactionKey]; if ([transaction isKindOfClass:MXQRCodeTransaction.class]) { block((MXQRCodeTransaction*)transaction); @@ -109,7 +109,7 @@ - (void)observeNewQRCodeTransactionInSession:(MXSession*)session block:(void (^) [observers addObject:observer]; } -- (void)observeTransactionUpdate:(MXKeyVerificationTransaction*)transaction block:(void (^)(void))block +- (void)observeTransactionUpdate:(id)transaction block:(void (^)(void))block { id observer = [[NSNotificationCenter defaultCenter] addObserverForName:MXKeyVerificationTransactionDidChangeNotification object:transaction queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { block(); @@ -118,15 +118,15 @@ - (void)observeTransactionUpdate:(MXKeyVerificationTransaction*)transaction bloc [observers addObject:observer]; } -- (void)observeKeyVerificationRequestChangeWithBlock:(void (^)(MXKeyVerificationRequest * _Nullable request))block +- (void)observeKeyVerificationRequestChangeWithBlock:(void (^)(id _Nullable request))block { id observer = [[NSNotificationCenter defaultCenter] addObserverForName:MXKeyVerificationRequestDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { - MXKeyVerificationRequest *request = notif.object; + idrequest = notif.object; - if ([request isKindOfClass:MXKeyVerificationRequest.class]) + if ([request conformsToProtocol:@protocol(MXKeyVerificationRequest)]) { - block((MXKeyVerificationRequest*)request); + block((id)request); } else { @@ -149,14 +149,14 @@ - (void)bootstrapCrossSigningOnSession:(MXSession*)session } -- (void)observeKeyVerificationRequestInSession:(MXSession*)session block:(void (^)(MXKeyVerificationRequest * _Nullable request))block +- (void)observeKeyVerificationRequestInSession:(MXSession*)session block:(void (^)(id _Nullable request))block { id observer = [[NSNotificationCenter defaultCenter] addObserverForName:MXKeyVerificationManagerNewRequestNotification object:session.crypto.keyVerificationManager queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { - MXKeyVerificationRequest *request = notif.userInfo[MXKeyVerificationManagerNotificationRequestKey]; - if ([request isKindOfClass:MXKeyVerificationRequest.class]) + id request = notif.userInfo[MXKeyVerificationManagerNotificationRequestKey]; + if ([request conformsToProtocol:@protocol(MXKeyVerificationRequest)]) { - block((MXKeyVerificationRequest*)request); + block((id)request); } else { @@ -196,7 +196,7 @@ - (void)testSelfVerificationWithSAS [aliceSession2.crypto.keyVerificationManager requestVerificationByToDeviceWithUserId:alice.userId deviceIds:@[alice.deviceId] methods:@[MXKeyVerificationMethodSAS, @"toto"] - success:^(MXKeyVerificationRequest *requestFromBobPOV) + success:^(id requestFromBobPOV) { requestId = requestFromBobPOV.requestId; @@ -213,7 +213,7 @@ - (void)testSelfVerificationWithSAS __block MXOutgoingSASTransaction *sasTransactionFromAlicePOV; // - Alice gets the requests notification - [self observeKeyVerificationRequestInSession:aliceSession1 block:^(MXKeyVerificationRequest * _Nullable requestFromAlicePOV) { + [self observeKeyVerificationRequestInSession:aliceSession1 block:^(id _Nullable requestFromAlicePOV) { XCTAssertEqualObjects(requestFromAlicePOV.requestId, requestId); // Wait a bit @@ -229,12 +229,12 @@ - (void)testSelfVerificationWithSAS // - Alice accepts it [requestFromAlicePOV acceptWithMethods:@[MXKeyVerificationMethodSAS] success:^{ - MXKeyVerificationRequest *requestFromAlicePOV2 = aliceSession1.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromAlicePOV2 = aliceSession1.crypto.keyVerificationManager.pendingRequests.firstObject; XCTAssertNotNil(requestFromAlicePOV2); XCTAssertEqualObjects(requestFromAlicePOV2.myMethods, @[MXKeyVerificationMethodSAS]); // - Alice begins a SAS verification - [aliceSession1.crypto.keyVerificationManager beginKeyVerificationFromRequest:requestFromAlicePOV2 method:MXKeyVerificationMethodSAS success:^(MXKeyVerificationTransaction * _Nonnull transactionFromAlicePOV) { + [aliceSession1.crypto.keyVerificationManager beginKeyVerificationFromRequest:requestFromAlicePOV2 method:MXKeyVerificationMethodSAS success:^(id _Nonnull transactionFromAlicePOV) { XCTAssertEqualObjects(transactionFromAlicePOV.transactionId, requestFromAlicePOV.requestId); @@ -402,7 +402,7 @@ - (void)testVerificationByDMFullFlow roomId:roomId fallbackText:fallbackText methods:@[MXKeyVerificationMethodSAS, @"toto"] - success:^(MXKeyVerificationRequest *request) + success:^(id request) { requestId = request.requestId; } @@ -434,12 +434,12 @@ - (void)testVerificationByDMFullFlow // Wait a bit dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ // - Alice rejects the incoming request - MXKeyVerificationRequest *requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; XCTAssertNotNil(requestFromAlicePOV); [requestFromAlicePOV acceptWithMethods:@[MXKeyVerificationMethodSAS] success:^{ - [aliceSession.crypto.keyVerificationManager beginKeyVerificationFromRequest:requestFromAlicePOV method:MXKeyVerificationMethodSAS success:^(MXKeyVerificationTransaction * _Nonnull transactionFromAlicePOV) { + [aliceSession.crypto.keyVerificationManager beginKeyVerificationFromRequest:requestFromAlicePOV method:MXKeyVerificationMethodSAS success:^(id _Nonnull transactionFromAlicePOV) { XCTAssertEqualObjects(transactionFromAlicePOV.transactionId, event.eventId); @@ -636,7 +636,7 @@ - (void)testVerifyingAnotherUserQRCodeVerificationFullFlow roomId:roomId fallbackText:fallbackText methods:@[MXKeyVerificationMethodQRCodeShow, MXKeyVerificationMethodQRCodeScan, MXKeyVerificationMethodReciprocate] - success:^(MXKeyVerificationRequest *request) + success:^(id request) { requestId = request.requestId; } @@ -666,7 +666,7 @@ - (void)testVerifyingAnotherUserQRCodeVerificationFullFlow // Wait a bit dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ // - Alice accepts the incoming request - MXKeyVerificationRequest *requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; XCTAssertNotNil(requestFromAlicePOV); [requestFromAlicePOV acceptWithMethods:@[MXKeyVerificationMethodQRCodeShow, MXKeyVerificationMethodReciprocate] success:^{ @@ -808,7 +808,7 @@ - (void)testVerifyingAnotherUserQRCodeVerificationFullFlow onEvent:checkDoneDone]; // -> Bob gets the requests notification - [self observeKeyVerificationRequestChangeWithBlock:^(MXKeyVerificationRequest * _Nullable request) { + [self observeKeyVerificationRequestChangeWithBlock:^(id _Nullable request) { if (!request.isFromMyUser) { @@ -818,8 +818,8 @@ - (void)testVerifyingAnotherUserQRCodeVerificationFullFlow XCTAssertEqualObjects(request.requestId, requestId); XCTAssertTrue(request.isFromMyUser); - MXKeyVerificationRequest *requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; - MXKeyVerificationRequest *requestFromBobPOV = bobSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromBobPOV = bobSession.crypto.keyVerificationManager.pendingRequests.firstObject; XCTAssertNotNil(requestFromAlicePOV); XCTAssertEqual(requestFromAlicePOV.transport, MXKeyVerificationTransportDirectMessage); diff --git a/MatrixSDKTests/MXCryptoKeyVerificationTests.m b/MatrixSDKTests/MXCryptoKeyVerificationTests.m index 305050a95b..607b7c97f2 100644 --- a/MatrixSDKTests/MXCryptoKeyVerificationTests.m +++ b/MatrixSDKTests/MXCryptoKeyVerificationTests.m @@ -33,7 +33,7 @@ @interface MXKeyVerificationManager (Testing) -- (MXKeyVerificationTransaction*)transactionWithTransactionId:(NSString*)transactionId; +- (id)transactionWithTransactionId:(NSString*)transactionId; @end @@ -75,7 +75,7 @@ - (void)observeSASIncomingTransactionInSession:(MXSession*)session block:(void ( { id observer = [[NSNotificationCenter defaultCenter] addObserverForName:MXKeyVerificationManagerNewTransactionNotification object:session.crypto.keyVerificationManager queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { - MXKeyVerificationTransaction *transaction = notif.userInfo[MXKeyVerificationManagerNotificationTransactionKey]; + id transaction = notif.userInfo[MXKeyVerificationManagerNotificationTransactionKey]; if (transaction.isIncoming && [transaction isKindOfClass:MXIncomingSASTransaction.class]) { block((MXIncomingSASTransaction*)transaction); @@ -89,7 +89,7 @@ - (void)observeSASIncomingTransactionInSession:(MXSession*)session block:(void ( [observers addObject:observer]; } -- (void)observeTransactionUpdate:(MXKeyVerificationTransaction*)transaction block:(void (^)(void))block +- (void)observeTransactionUpdate:(id)transaction block:(void (^)(void))block { id observer = [[NSNotificationCenter defaultCenter] addObserverForName:MXKeyVerificationTransactionDidChangeNotification object:transaction queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { block(); @@ -98,14 +98,14 @@ - (void)observeTransactionUpdate:(MXKeyVerificationTransaction*)transaction bloc [observers addObject:observer]; } -- (void)observeKeyVerificationRequestInSession:(MXSession*)session block:(void (^)(MXKeyVerificationRequest * _Nullable request))block +- (void)observeKeyVerificationRequestInSession:(MXSession*)session block:(void (^)(id _Nullable request))block { id observer = [[NSNotificationCenter defaultCenter] addObserverForName:MXKeyVerificationManagerNewRequestNotification object:session.crypto.keyVerificationManager queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { - MXKeyVerificationRequest *request = notif.userInfo[MXKeyVerificationManagerNotificationRequestKey]; - if ([request isKindOfClass:MXKeyVerificationRequest.class]) + id request = notif.userInfo[MXKeyVerificationManagerNotificationRequestKey]; + if ([request conformsToProtocol:@protocol(MXKeyVerificationRequest)]) { - block((MXKeyVerificationRequest*)request); + block((id)request); } else { @@ -117,7 +117,7 @@ - (void)observeKeyVerificationRequestInSession:(MXSession*)session block:(void ( } -- (void)observeKeyVerificationRequestUpdate:(MXKeyVerificationRequest*)request block:(void (^)(void))block +- (void)observeKeyVerificationRequestUpdate:(id)request block:(void (^)(void))block { id observer = [[NSNotificationCenter defaultCenter] addObserverForName:MXKeyVerificationRequestDidChangeNotification object:request queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { block(); @@ -149,7 +149,7 @@ - (void)testVerificationByToDeviceRequests [bobSession.crypto.keyVerificationManager requestVerificationByToDeviceWithUserId:alice.userId deviceIds:@[alice.deviceId] methods:@[MXKeyVerificationMethodSAS, @"toto"] - success:^(MXKeyVerificationRequest *request) + success:^(id request) { requestId = request.requestId; } @@ -161,12 +161,12 @@ - (void)testVerificationByToDeviceRequests // -> Alice gets the requests notification - [self observeKeyVerificationRequestInSession:aliceSession block:^(MXKeyVerificationRequest * _Nullable request) { + [self observeKeyVerificationRequestInSession:aliceSession block:^(id _Nullable request) { XCTAssertEqualObjects(request.requestId, requestId); XCTAssertFalse(request.isFromMyUser); - MXKeyVerificationRequest *requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; - MXKeyVerificationRequest *requestFromBobPOV = bobSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromBobPOV = bobSession.crypto.keyVerificationManager.pendingRequests.firstObject; XCTAssertNotNil(requestFromAlicePOV); XCTAssertEqual(requestFromAlicePOV.transport, MXKeyVerificationTransportToDevice); @@ -212,7 +212,7 @@ - (void)checkVerificationByToDeviceFullFlowWithBobSession:(MXSession*)bobSession [bobSession.crypto.keyVerificationManager requestVerificationByToDeviceWithUserId:alice.userId deviceIds:@[alice.deviceId] methods:@[MXKeyVerificationMethodSAS, @"toto"] - success:^(MXKeyVerificationRequest *requestFromBobPOV) + success:^(id requestFromBobPOV) { requestId = requestFromBobPOV.requestId; @@ -229,7 +229,7 @@ - (void)checkVerificationByToDeviceFullFlowWithBobSession:(MXSession*)bobSession __block MXOutgoingSASTransaction *sasTransactionFromAlicePOV; // - Alice gets the requests notification - [self observeKeyVerificationRequestInSession:aliceSession block:^(MXKeyVerificationRequest * _Nullable requestFromAlicePOV) { + [self observeKeyVerificationRequestInSession:aliceSession block:^(id _Nullable requestFromAlicePOV) { XCTAssertNotNil(requestFromAlicePOV.requestId); XCTAssertNotNil(requestId); XCTAssertEqualObjects(requestFromAlicePOV.requestId, requestId); @@ -247,12 +247,12 @@ - (void)checkVerificationByToDeviceFullFlowWithBobSession:(MXSession*)bobSession // - Alice accepts it [requestFromAlicePOV acceptWithMethods:@[MXKeyVerificationMethodSAS] success:^{ - MXKeyVerificationRequest *requestFromAlicePOV2 = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromAlicePOV2 = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; XCTAssertNotNil(requestFromAlicePOV2); XCTAssertEqualObjects(requestFromAlicePOV2.myMethods, @[MXKeyVerificationMethodSAS]); // - Alice begins a SAS verification - [aliceSession.crypto.keyVerificationManager beginKeyVerificationFromRequest:requestFromAlicePOV2 method:MXKeyVerificationMethodSAS success:^(MXKeyVerificationTransaction * _Nonnull transactionFromAlicePOV) { + [aliceSession.crypto.keyVerificationManager beginKeyVerificationFromRequest:requestFromAlicePOV2 method:MXKeyVerificationMethodSAS success:^(id _Nonnull transactionFromAlicePOV) { XCTAssertEqualObjects(transactionFromAlicePOV.transactionId, requestFromAlicePOV.requestId); @@ -443,7 +443,7 @@ - (void)testVerificationByToDeviceRequestCancellation [aliceSession1.crypto.keyVerificationManager requestVerificationByToDeviceWithUserId:aliceUserId deviceIds:nil methods:methods - success:^(MXKeyVerificationRequest *requestFromAliceDevice1POV) + success:^(id requestFromAliceDevice1POV) { // -> The other device list should have been computed well MXKeyVerificationByToDeviceRequest *toDeviceRequestFromAliceDevice1POV = (MXKeyVerificationByToDeviceRequest*)requestFromAliceDevice1POV; @@ -475,7 +475,7 @@ - (void)testVerificationByToDeviceRequestCancellation dispatch_group_t cancelledGroup = dispatch_group_create(); dispatch_group_enter(cancelledGroup); - [self observeKeyVerificationRequestInSession:aliceSession2 block:^(MXKeyVerificationRequest * _Nullable requestFromAliceDevice2POV) { + [self observeKeyVerificationRequestInSession:aliceSession2 block:^(id _Nullable requestFromAliceDevice2POV) { [self observeKeyVerificationRequestUpdate:requestFromAliceDevice2POV block:^{ if (requestFromAliceDevice2POV.state == MXKeyVerificationRequestStateCancelled) { @@ -485,7 +485,7 @@ - (void)testVerificationByToDeviceRequestCancellation }]; dispatch_group_enter(cancelledGroup); - [self observeKeyVerificationRequestInSession:aliceSession3 block:^(MXKeyVerificationRequest * _Nullable requestFromAliceDevice3POV) { + [self observeKeyVerificationRequestInSession:aliceSession3 block:^(id _Nullable requestFromAliceDevice3POV) { [self observeKeyVerificationRequestUpdate:requestFromAliceDevice3POV block:^{ if (requestFromAliceDevice3POV.state == MXKeyVerificationRequestStateCancelled) { @@ -521,7 +521,7 @@ - (void)testVerificationByToDeviceRequestWithNoOtherDevice [aliceSession.crypto.keyVerificationManager requestVerificationByToDeviceWithUserId:aliceUserId deviceIds:nil methods:methods - success:^(MXKeyVerificationRequest *requestFromAliceDevice1POV) + success:^(id requestFromAliceDevice1POV) { XCTFail(@"The request should not succeed "); [expectation fulfill]; @@ -570,7 +570,7 @@ - (void)testLegacyVerificationByToDeviceFullFlow MXCredentials *bob = bobSession.matrixRestClient.credentials; // - Alice begins SAS verification of Bob's device - [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:bob.userId andDeviceId:bob.deviceId method:MXKeyVerificationMethodSAS success:^(MXKeyVerificationTransaction * _Nonnull transactionFromAlicePOV) { + [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:bob.userId andDeviceId:bob.deviceId method:MXKeyVerificationMethodSAS success:^(id _Nonnull transactionFromAlicePOV) { MXOutgoingSASTransaction *sasTransactionFromAlicePOV = (MXOutgoingSASTransaction*)transactionFromAlicePOV; @@ -676,7 +676,7 @@ - (void)testLegacyAliceDoingVerificationOnANonExistingDevice [matrixSDKTestsE2EData doE2ETestWithAliceInARoom:self readyToTest:^(MXSession *aliceSession, NSString *roomId, XCTestExpectation *expectation) { // - Alice begins SAS verification of a non-existing device - [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:@"@bob:foo.bar" andDeviceId:@"DEVICEID" method:MXKeyVerificationMethodSAS success:^(MXKeyVerificationTransaction * _Nonnull transaction) { + [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:@"@bob:foo.bar" andDeviceId:@"DEVICEID" method:MXKeyVerificationMethodSAS success:^(id _Nonnull transaction) { // -> The request should fail XCTFail(@"The request should fail"); @@ -700,7 +700,7 @@ - (void)testLegacyAliceDoingVerificationOnANotYetKnownDevice MXCredentials *bob = bobSession.matrixRestClient.credentials; // - Alice begins SAS verification of a device she has never talked too - [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:bob.userId andDeviceId:bob.deviceId method:MXKeyVerificationMethodSAS success:^(MXKeyVerificationTransaction * _Nonnull transactionFromAlicePOV) { + [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:bob.userId andDeviceId:bob.deviceId method:MXKeyVerificationMethodSAS success:^(id _Nonnull transactionFromAlicePOV) { // -> The request should succeed MXOutgoingSASTransaction *sasTransactionFromAlicePOV = (MXOutgoingSASTransaction*)transactionFromAlicePOV; @@ -739,7 +739,7 @@ - (void)testLegacyAliceStartThenAliceCancel // - Alice begins SAS verification of Bob's device MXCredentials *bob = bobSession.matrixRestClient.credentials; - [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:bob.userId andDeviceId:bob.deviceId method:MXKeyVerificationMethodSAS success:^(MXKeyVerificationTransaction * _Nonnull transactionFromAlicePOV) { + [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:bob.userId andDeviceId:bob.deviceId method:MXKeyVerificationMethodSAS success:^(id _Nonnull transactionFromAlicePOV) { // -> Alice must see the transaction as a MXOutgoingSASTransaction XCTAssert(transactionFromAlicePOV); @@ -800,7 +800,7 @@ - (void)testLegacyAliceStartThenBobCancel // - Alice begins SAS verification of Bob's device MXCredentials *bob = bobSession.matrixRestClient.credentials; - [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:bob.userId andDeviceId:bob.deviceId method:MXKeyVerificationMethodSAS success:^(MXKeyVerificationTransaction * _Nonnull transactionFromAlicePOV) { + [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:bob.userId andDeviceId:bob.deviceId method:MXKeyVerificationMethodSAS success:^(id _Nonnull transactionFromAlicePOV) { MXOutgoingSASTransaction *sasTransactionFromAlicePOV = (MXOutgoingSASTransaction*)transactionFromAlicePOV; @@ -844,7 +844,7 @@ - (void)testLegacyAliceStartTwoVerificationsAtSameTime MXCredentials *bob = bobSession.matrixRestClient.credentials; // - Alice begins SAS verification of Bob's device - [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:bob.userId andDeviceId:bob.deviceId method:MXKeyVerificationMethodSAS success:^(MXKeyVerificationTransaction * _Nonnull transactionFromAlicePOV) { + [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:bob.userId andDeviceId:bob.deviceId method:MXKeyVerificationMethodSAS success:^(id _Nonnull transactionFromAlicePOV) { MXOutgoingSASTransaction *sasTransactionFromAlicePOV = (MXOutgoingSASTransaction*)transactionFromAlicePOV; @@ -862,7 +862,7 @@ - (void)testLegacyAliceStartTwoVerificationsAtSameTime }]; // - Alice starts another SAS verification of Bob's device - [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:bob.userId andDeviceId:bob.deviceId method:MXKeyVerificationMethodSAS success:^(MXKeyVerificationTransaction * _Nonnull transaction2FromAlicePOV) { + [aliceSession.crypto.keyVerificationManager beginKeyVerificationWithUserId:bob.userId andDeviceId:bob.deviceId method:MXKeyVerificationMethodSAS success:^(id _Nonnull transaction2FromAlicePOV) { MXOutgoingSASTransaction *sasTransaction2FromAlicePOV = (MXOutgoingSASTransaction*)transaction2FromAlicePOV; @@ -920,7 +920,7 @@ - (void)testVerificationByDMRequests roomId:roomId fallbackText:fallbackText methods:@[MXKeyVerificationMethodSAS, @"toto"] - success:^(MXKeyVerificationRequest *request) + success:^(id request) { requestId = request.requestId; } @@ -932,12 +932,12 @@ - (void)testVerificationByDMRequests // -> Alice gets the requests notification - [self observeKeyVerificationRequestInSession:aliceSession block:^(MXKeyVerificationRequest * _Nullable request) { + [self observeKeyVerificationRequestInSession:aliceSession block:^(id _Nullable request) { XCTAssertEqualObjects(request.requestId, requestId); XCTAssertFalse(request.isFromMyUser); - MXKeyVerificationRequest *requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; - MXKeyVerificationRequest *requestFromBobPOV = bobSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromBobPOV = bobSession.crypto.keyVerificationManager.pendingRequests.firstObject; XCTAssertNotNil(requestFromAlicePOV); XCTAssertEqual(requestFromAlicePOV.transport, MXKeyVerificationTransportDirectMessage); @@ -1000,7 +1000,7 @@ - (void)checkVerificationByDMFullFlowWithAliceSession:(MXSession*)aliceSession b roomId:roomId fallbackText:fallbackText methods:methods - success:^(MXKeyVerificationRequest *requestFromBobPOV) + success:^(id requestFromBobPOV) { requestId = requestFromBobPOV.requestId; XCTAssertEqualObjects(requestFromBobPOV.otherUser, alice.userId); @@ -1032,7 +1032,7 @@ - (void)checkVerificationByDMFullFlowWithAliceSession:(MXSession*)aliceSession b // Wait a bit dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ - MXKeyVerificationRequest *requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; XCTAssertNotNil(requestFromAlicePOV); XCTAssertEqualObjects(requestFromAlicePOV.methods, methods); @@ -1045,12 +1045,12 @@ - (void)checkVerificationByDMFullFlowWithAliceSession:(MXSession*)aliceSession b // - Alice accepts it [requestFromAlicePOV acceptWithMethods:@[MXKeyVerificationMethodSAS] success:^{ - MXKeyVerificationRequest *requestFromAlicePOV2 = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromAlicePOV2 = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; XCTAssertNotNil(requestFromAlicePOV2); XCTAssertEqualObjects(requestFromAlicePOV2.myMethods, @[MXKeyVerificationMethodSAS]); // - Alice begins a SAS verification - [aliceSession.crypto.keyVerificationManager beginKeyVerificationFromRequest:requestFromAlicePOV2 method:MXKeyVerificationMethodSAS success:^(MXKeyVerificationTransaction * _Nonnull transactionFromAlicePOV) { + [aliceSession.crypto.keyVerificationManager beginKeyVerificationFromRequest:requestFromAlicePOV2 method:MXKeyVerificationMethodSAS success:^(id _Nonnull transactionFromAlicePOV) { XCTAssertEqualObjects(transactionFromAlicePOV.transactionId, event.eventId); @@ -1216,7 +1216,7 @@ - (void)testVerificationByDMCancelledByAlice roomId:roomId fallbackText:fallbackText methods:@[MXKeyVerificationMethodSAS, @"toto"] - success:^(MXKeyVerificationRequest *request) + success:^(id request) { requestId = request.requestId; } @@ -1239,7 +1239,7 @@ - (void)testVerificationByDMCancelledByAlice // Wait a bit dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ // - Alice rejects the incoming request - MXKeyVerificationRequest *requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; XCTAssertNotNil(requestFromAlicePOV); [requestFromAlicePOV cancelWithCancelCode:MXTransactionCancelCode.user success:^{ @@ -1311,7 +1311,7 @@ - (void)testVerificationByDMWithRoomDetection roomId:nil fallbackText:fallbackText methods:@[MXKeyVerificationMethodSAS, @"toto"] - success:^(MXKeyVerificationRequest *request) + success:^(id request) { requestId = request.requestId; } failure:^(NSError * _Nonnull error) { @@ -1325,12 +1325,12 @@ - (void)testVerificationByDMWithRoomDetection }]; // -> Alice gets the requests notification - [self observeKeyVerificationRequestInSession:aliceSession block:^(MXKeyVerificationRequest * _Nullable request) { + [self observeKeyVerificationRequestInSession:aliceSession block:^(id _Nullable request) { XCTAssertEqualObjects(request.requestId, requestId); XCTAssertFalse(request.isFromMyUser); - MXKeyVerificationRequest *requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; - MXKeyVerificationRequest *requestFromBobPOV = bobSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromBobPOV = bobSession.crypto.keyVerificationManager.pendingRequests.firstObject; XCTAssertNotNil(requestFromAlicePOV); XCTAssertNotNil(requestFromBobPOV); @@ -1365,7 +1365,7 @@ - (void)testVerificationByDMWithNoRoom roomId:nil fallbackText:fallbackText methods:@[MXKeyVerificationMethodSAS, @"toto"] - success:^(MXKeyVerificationRequest *request) + success:^(id request) { requestId = request.requestId; } failure:^(NSError * _Nonnull error) { @@ -1387,14 +1387,14 @@ - (void)testVerificationByDMWithNoRoom }]; // -> Alice gets the requests notification - [self observeKeyVerificationRequestInSession:aliceSession block:^(MXKeyVerificationRequest * _Nullable request) { + [self observeKeyVerificationRequestInSession:aliceSession block:^(id _Nullable request) { XCTAssertEqualObjects(request.requestId, requestId); XCTAssertFalse(request.isFromMyUser); - MXKeyVerificationRequest *requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; - MXKeyVerificationRequest *requestFromBobPOV = bobSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromAlicePOV = aliceSession.crypto.keyVerificationManager.pendingRequests.firstObject; + id requestFromBobPOV = bobSession.crypto.keyVerificationManager.pendingRequests.firstObject; XCTAssertNotNil(requestFromAlicePOV); XCTAssertNotNil(requestFromBobPOV); diff --git a/changelog.d/pr-1528.misc b/changelog.d/pr-1528.misc new file mode 100644 index 0000000000..5f9a6f1dcb --- /dev/null +++ b/changelog.d/pr-1528.misc @@ -0,0 +1 @@ +Crypto: Convert verification request and transaction to protocols From 4079f2444b314ce3a3a0f0311590238973a113b3 Mon Sep 17 00:00:00 2001 From: Andy Uhnak Date: Mon, 18 Jul 2022 12:21:45 +0100 Subject: [PATCH 2/2] Fix and enable remaining key verification tests --- MatrixSDKTests/MXCryptoKeyVerificationTests.m | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/MatrixSDKTests/MXCryptoKeyVerificationTests.m b/MatrixSDKTests/MXCryptoKeyVerificationTests.m index 607b7c97f2..43f1b4d89a 100644 --- a/MatrixSDKTests/MXCryptoKeyVerificationTests.m +++ b/MatrixSDKTests/MXCryptoKeyVerificationTests.m @@ -214,10 +214,12 @@ - (void)checkVerificationByToDeviceFullFlowWithBobSession:(MXSession*)bobSession methods:@[MXKeyVerificationMethodSAS, @"toto"] success:^(id requestFromBobPOV) { - requestId = requestFromBobPOV.requestId; + XCTAssertNotNil(requestFromBobPOV); + XCTAssertNotNil(requestFromBobPOV.requestId); + requestId = requestFromBobPOV.requestId; - XCTAssertEqualObjects(requestFromBobPOV.otherUser, alice.userId); - XCTAssertNil(requestFromBobPOV.otherDevice); + XCTAssertEqualObjects(requestFromBobPOV.otherUser, alice.userId); + XCTAssertNil(requestFromBobPOV.otherDevice); } failure:^(NSError * _Nonnull error) { @@ -230,13 +232,16 @@ - (void)checkVerificationByToDeviceFullFlowWithBobSession:(MXSession*)bobSession // - Alice gets the requests notification [self observeKeyVerificationRequestInSession:aliceSession block:^(id _Nullable requestFromAlicePOV) { - XCTAssertNotNil(requestFromAlicePOV.requestId); - XCTAssertNotNil(requestId); - XCTAssertEqualObjects(requestFromAlicePOV.requestId, requestId); - // Wait a bit + // Wait a bit, `requestVerification` could complete after it sends out a few events observed by Alice's session dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + XCTAssertNotNil(requestId); + XCTAssertNotNil(requestFromAlicePOV); + XCTAssertNotNil(requestFromAlicePOV.requestId); + + XCTAssertEqualObjects(requestFromAlicePOV.requestId, requestId); + XCTAssertEqualObjects(requestFromAlicePOV.methods, methods); XCTAssertEqualObjects(requestFromAlicePOV.otherMethods, methods); XCTAssertNil(requestFromAlicePOV.myMethods); @@ -385,8 +390,7 @@ - (void)testVerificationByToDeviceFullFlowWithAliceWith2Devices /** Same tests as testVerificationByToDeviceFullFlow but with bob with 2 sessions */ -// TODO: Test currently broken -- (void)xtestVerificationByToDeviceFullFlowWith2Devices +- (void)testVerificationByToDeviceFullFlowWith2Devices { // - Alice and Bob are in a room [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoom:self cryptedBob:YES warnOnUnknowDevices:YES aliceStore:[[MXMemoryStore alloc] init] bobStore:[[MXMemoryStore alloc] init] readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -401,8 +405,7 @@ - (void)xtestVerificationByToDeviceFullFlowWith2Devices /** Same tests as testVerificationByToDeviceFullFlow but with only alice verifying her 2 devices. */ -// TODO: Test currently broken -- (void)xtestVerificationByToDeviceSelfVerificationFullFlow +- (void)testVerificationByToDeviceSelfVerificationFullFlow { // - Alice and Bob are in a room [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoom:self cryptedBob:YES warnOnUnknowDevices:YES aliceStore:[[MXMemoryStore alloc] init] bobStore:[[MXMemoryStore alloc] init] readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -952,8 +955,7 @@ - (void)testVerificationByDMRequests /** Nomical case: The full flow */ -// TODO: test is currently broken -- (void)xtestVerificationByDMFullFlow +- (void)testVerificationByDMFullFlow { // - Alice and Bob are in a room [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoom:self cryptedBob:YES warnOnUnknowDevices:YES aliceStore:[[MXMemoryStore alloc] init] bobStore:[[MXMemoryStore alloc] init] readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) {