Skip to content

Commit

Permalink
Merge branch 'release/v0.16.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
manuroe committed Apr 24, 2020
2 parents 110a156 + 46f4287 commit 1cfec19
Show file tree
Hide file tree
Showing 19 changed files with 264 additions and 182 deletions.
18 changes: 18 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Changes in Matrix iOS SDK in 0.16.1 (2020-04-24)
================================================

Improvements:
* MXHTTPClient: Log HTTP requests methods.
* MXCrypto: Make trustLevelSummaryForUserIds async (vector-im/riot-ios/issues/3126).
* MXJingleCallAudioSessionConfigurator: Remove workaround since it is no longer needed (PR #815).

Bug fix:
* Fix race condition in MXSecretShareManager (vector-im/riot-ios/issues/3123).
* Too much MXDeviceInfoTrustLevelDidChangeNotification and MXCrossSigningInfoTrustLevelDidChangeNotification (vector-im/riot-ios/issues/3121).
* VoiP: Fix remote ice candidates being added before remote description is setup (vector-im/riot-ios/issues/1784).
* MXDeviceListOperationsPool: Post MXDeviceListDidUpdateUsersDevicesNotification notification only for new changes never seen before (vector-im/riot-ios/issues/3120).
* MXIdentityService: Fix registration by email and all IS services by fixing Open Id token.

API break:
* MXCrypto: trustLevelSummaryForUserIds: is now async.

Changes in Matrix iOS SDK in 0.16.0 (2020-04-17)
================================================

Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "MatrixSDK"
s.version = "0.16.0"
s.version = "0.16.1"
s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)"

s.description = <<-DESC
Expand Down
7 changes: 6 additions & 1 deletion MatrixSDK/Crypto/CrossSigning/Data/MXCrossSigningInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ - (instancetype)initWithUserId:(NSString *)userId
return self;
}

- (BOOL)updateTrustLevel:(MXUserTrustLevel*)trustLevel;
- (void)setTrustLevel:(MXUserTrustLevel*)trustLevel
{
_trustLevel = trustLevel;
}

- (BOOL)updateTrustLevel:(MXUserTrustLevel*)trustLevel
{
BOOL updated = NO;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype)initWithUserId:(NSString *)userId;

- (void)setTrustLevel:(MXUserTrustLevel*)trustLevel;
- (BOOL)updateTrustLevel:(MXUserTrustLevel*)trustLevel;
- (void)addCrossSigningKey:(MXCrossSigningKey*)crossSigningKey type:(NSString*)type;

Expand Down
6 changes: 4 additions & 2 deletions MatrixSDK/Crypto/CrossSigning/MXCrossSigning.m
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,10 @@ - (void)resetTrust
@(isCrossSigningVerified));

MXUserTrustLevel *newTrustLevel = [MXUserTrustLevel trustLevelWithCrossSigningVerified:isCrossSigningVerified locallyVerified:crossSigningInfo.trustLevel.isLocallyVerified];
[crossSigningInfo updateTrustLevel:newTrustLevel];
[self.crypto.store storeCrossSigningKeys:crossSigningInfo];
if ([crossSigningInfo updateTrustLevel:newTrustLevel])
{
[self.crypto.store storeCrossSigningKeys:crossSigningInfo];
}

// Update trust on associated devices
[self checkTrustLevelForDevicesOfUser:crossSigningInfo.userId];
Expand Down
5 changes: 5 additions & 0 deletions MatrixSDK/Crypto/Data/MXDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ - (MXDeviceVerification)verified

#pragma mark - SDK-Private methods

- (void)setTrustLevel:(MXDeviceTrustLevel *)trustLevel
{
_trustLevel = trustLevel;
}

- (BOOL)updateTrustLevel:(MXDeviceTrustLevel*)trustLevel
{
BOOL updated = NO;
Expand Down
1 change: 1 addition & 0 deletions MatrixSDK/Crypto/Data/MXDeviceInfo_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN

@interface MXDeviceInfo ()

- (void)setTrustLevel:(MXDeviceTrustLevel*)trustLevel;
- (BOOL)updateTrustLevel:(MXDeviceTrustLevel*)trustLevel;

@end
Expand Down
37 changes: 29 additions & 8 deletions MatrixSDK/Crypto/Data/MXDeviceListOperationsPool.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,19 @@ - (void)doKeyDownloadForUsers:(NSArray<NSString *> *)users token:(NSString *)tok
if (crossSigningKeys)
{
NSLog(@"[MXDeviceListOperationsPool] doKeyDownloadForUsers: Got cross-signing keys for %@: %@", userId, crossSigningKeys);

MXCrossSigningInfo *storedCrossSigningKeys = [self->crypto.store crossSigningKeysForUser:userId];

// Use current trust level
MXUserTrustLevel *oldTrustLevel = storedCrossSigningKeys.trustLevel;
[crossSigningKeys setTrustLevel:oldTrustLevel];

// Compute trust on this user
// Note this overwrites the previous value
BOOL isCrossSigningVerified = [self->crypto.crossSigning isUserWithCrossSigningKeysVerified:crossSigningKeys];

BOOL wasLocallyVerified = [self->crypto.store crossSigningKeysForUser:userId].trustLevel.isLocallyVerified;
MXUserTrustLevel *newTrustLevel = [MXUserTrustLevel trustLevelWithCrossSigningVerified:isCrossSigningVerified
locallyVerified:wasLocallyVerified];
locallyVerified:oldTrustLevel.isLocallyVerified];

[crossSigningKeys updateTrustLevel:newTrustLevel];

// Note that keys which aren't in the response will be removed from the store
Expand Down Expand Up @@ -167,25 +172,41 @@ - (void)doKeyDownloadForUsers:(NSArray<NSString *> *)users token:(NSString *)tok
// So, transfer its previous value
previousLocalState = previouslyStoredDeviceKeys.trustLevel.localVerificationStatus;
}


// Use current trust level
MXDeviceTrustLevel *oldTrustLevel = [MXDeviceTrustLevel trustLevelWithLocalVerificationStatus:previousLocalState
crossSigningVerified:previouslyStoredDeviceKeys.trustLevel.isCrossSigningVerified];
[mutabledevices[deviceId] setTrustLevel:oldTrustLevel];


BOOL crossSigningVerified = [self->crypto.crossSigning isDeviceVerified:mutabledevices[deviceId]];
MXDeviceTrustLevel *trustLevel = [MXDeviceTrustLevel trustLevelWithLocalVerificationStatus:previousLocalState
crossSigningVerified:crossSigningVerified];

[mutabledevices[deviceId] updateTrustLevel:trustLevel];
}

usersDevices[userId] = mutabledevices.allValues;
NSArray *mutableDevicesValues = mutabledevices.allValues;
usersDevices[userId] = mutableDevicesValues;

if (![mutabledevices isEqualToDictionary:storedDevices])
{
updatedUsersDevices[userId] = usersDevices[userId];
NSArray *storedDevicesValues = storedDevices.allValues;

// Keep only devices that are not identical to those present in the database
NSArray *updatedUserDevices = [mutableDevicesValues filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
return ![storedDevicesValues containsObject:evaluatedObject];
}]];

if (updatedUserDevices.count)
{
updatedUsersDevices[userId] = updatedUserDevices;
}

// Update the store
// Note that devices which aren't in the response will be removed from the store
[self->crypto.store storeDevicesForUser:userId devices:mutabledevices];
}

}
}

Expand Down
123 changes: 73 additions & 50 deletions MatrixSDK/Crypto/KeySharing/Secret/MXSecretShareManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,49 @@ - (MXHTTPOperation *)requestSecret:(NSString*)secretId
{
NSLog(@"[MXSecretShareManager] requestSecret: %@ to %@", secretId, deviceIds);

MXCredentials *myUser = _crypto.mxSession.matrixRestClient.credentials;

MXSecretShareRequest *request = [MXSecretShareRequest new];
request.name = secretId;
request.action = MXSecretShareRequestAction.request;
request.requestingDeviceId = myUser.deviceId;
request.requestId = [MXTools generateTransactionId];

MXPendingSecretShareRequest *pendingRequest = [MXPendingSecretShareRequest new];
pendingRequest.request = request;
pendingRequest.onSecretReceivedBlock = onSecretReceived;
pendingRequest.requestedDeviceIds = deviceIds;

pendingSecretShareRequests[request.requestId] = pendingRequest;
// Create an empty operation that will be mutated later
MXHTTPOperation *operation = [[MXHTTPOperation alloc] init];

MXWeakify(self);
return [self sendMessage:request.JSONDictionary toDeviceIds:deviceIds success:^{
dispatch_async(_crypto.cryptoQueue, ^{
MXStrongifyAndReturnIfNil(self);

dispatch_async(dispatch_get_main_queue(), ^{
success(request.requestId);
});
MXCredentials *myUser = self.crypto.mxSession.matrixRestClient.credentials;

} failure:^(NSError *error) {
MXStrongifyAndReturnIfNil(self);
MXSecretShareRequest *request = [MXSecretShareRequest new];
request.name = secretId;
request.action = MXSecretShareRequestAction.request;
request.requestingDeviceId = myUser.deviceId;
request.requestId = [MXTools generateTransactionId];

[self->pendingSecretShareRequests removeObjectForKey:request.requestId];
MXPendingSecretShareRequest *pendingRequest = [MXPendingSecretShareRequest new];
pendingRequest.request = request;
pendingRequest.onSecretReceivedBlock = onSecretReceived;
pendingRequest.requestedDeviceIds = deviceIds;

dispatch_async(dispatch_get_main_queue(), ^{
failure(error);
});
}];
self->pendingSecretShareRequests[request.requestId] = pendingRequest;

MXWeakify(self);
MXHTTPOperation *operation2 = [self sendMessage:request.JSONDictionary toDeviceIds:deviceIds success:^{

dispatch_async(dispatch_get_main_queue(), ^{
success(request.requestId);
});

} failure:^(NSError *error) {
MXStrongifyAndReturnIfNil(self);

[self->pendingSecretShareRequests removeObjectForKey:request.requestId];

dispatch_async(dispatch_get_main_queue(), ^{
failure(error);
});
}];

[operation mutateTo:operation2];
});

return operation;
}

- (MXHTTPOperation *)cancelRequestWithRequestId:(NSString*)requestId
Expand All @@ -96,34 +108,45 @@ - (MXHTTPOperation *)cancelRequestWithRequestId:(NSString*)requestId
{
NSLog(@"[MXSecretShareManager] cancelRequestWithRequestId: %@", requestId);

MXPendingSecretShareRequest *pendingRequest = pendingSecretShareRequests[requestId];
if (!pendingRequest)
{
NSLog(@"[MXSecretShareManager] cancelRequestWithRequestId: Unknown request: %@", requestId);
failure(nil);
return nil;
}

[self->pendingSecretShareRequests removeObjectForKey:requestId];
// Create an empty operation that will be mutated later
MXHTTPOperation *operation = [[MXHTTPOperation alloc] init];

MXCredentials *myUser = _crypto.mxSession.matrixRestClient.credentials;

MXSecretShareRequest *request = [MXSecretShareRequest new];
request.action = MXSecretShareRequestAction.requestCancellation;
request.requestingDeviceId = myUser.deviceId;
request.requestId = requestId;

return [self sendMessage:request.JSONDictionary toDeviceIds:pendingRequest.requestedDeviceIds success:^{
dispatch_async(dispatch_get_main_queue(), ^{
success();
});
MXWeakify(self);
dispatch_async(_crypto.cryptoQueue, ^{
MXStrongifyAndReturnIfNil(self);

} failure:^(NSError *error) {
MXPendingSecretShareRequest *pendingRequest = self->pendingSecretShareRequests[requestId];
if (!pendingRequest)
{
NSLog(@"[MXSecretShareManager] cancelRequestWithRequestId: Unknown request: %@", requestId);
failure(nil);
}

dispatch_async(dispatch_get_main_queue(), ^{
failure(error);
});
}];
[self->pendingSecretShareRequests removeObjectForKey:requestId];

MXCredentials *myUser = self.crypto.mxSession.matrixRestClient.credentials;

MXSecretShareRequest *request = [MXSecretShareRequest new];
request.action = MXSecretShareRequestAction.requestCancellation;
request.requestingDeviceId = myUser.deviceId;
request.requestId = requestId;

MXHTTPOperation *operation2 = [self sendMessage:request.JSONDictionary toDeviceIds:pendingRequest.requestedDeviceIds success:^{
dispatch_async(dispatch_get_main_queue(), ^{
success();
});

} failure:^(NSError *error) {

dispatch_async(dispatch_get_main_queue(), ^{
failure(error);
});
}];

[operation mutateTo:operation2];
});

return operation;
}


Expand Down
4 changes: 2 additions & 2 deletions MatrixSDK/Crypto/MXCrypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ extern NSString *const MXDeviceListDidUpdateUsersDevicesNotification;
Get the stored summary of users trust level (trusted users and devices count).
@param userIds The user ids.
@return the trust summary.
@param onComplete the callback called once operation is done.
*/
- (MXUsersTrustLevelSummary *)trustLevelSummaryForUserIds:(NSArray<NSString*>*)userIds;
- (void)trustLevelSummaryForUserIds:(NSArray<NSString*>*)userIds onComplete:(void (^)(MXUsersTrustLevelSummary *trustLevelSummary))onComplete;


#pragma mark - Users keys
Expand Down
67 changes: 40 additions & 27 deletions MatrixSDK/Crypto/MXCrypto.m
Original file line number Diff line number Diff line change
Expand Up @@ -1049,45 +1049,58 @@ - (void)trustLevelSummaryForUserIds:(NSArray<NSString*>*)userIds

// Read data from the store
// It has been updated in the process of the downloadKeys response
success([self trustLevelSummaryForUserIds:userIds]);
[self trustLevelSummaryForUserIds:userIds onComplete:^(MXUsersTrustLevelSummary *trustLevelSummary) {
success(trustLevelSummary);
}];

} failure:failure];
}

- (MXUsersTrustLevelSummary *)trustLevelSummaryForUserIds:(NSArray<NSString*>*)userIds
- (void)trustLevelSummaryForUserIds:(NSArray<NSString*>*)userIds onComplete:(void (^)(MXUsersTrustLevelSummary *trustLevelSummary))onComplete;
{
NSUInteger usersCount = 0;
NSUInteger trustedUsersCount = 0;
NSUInteger devicesCount = 0;
NSUInteger trustedDevicesCount = 0;

for (NSString *userId in userIds)
{
usersCount++;
// Use cargoQueue for potential huge read requests from the store
MXWeakify(self);
dispatch_async(cargoQueue, ^{
MXStrongifyAndReturnIfNil(self);

MXUserTrustLevel *userTrustLevel = [self trustLevelForUser:userId];
if (userTrustLevel.isVerified)
NSUInteger usersCount = 0;
NSUInteger trustedUsersCount = 0;
NSUInteger devicesCount = 0;
NSUInteger trustedDevicesCount = 0;

for (NSString *userId in userIds)
{
trustedUsersCount++;

for (MXDeviceInfo *device in [self.store devicesForUser:userId].allValues)
usersCount++;

MXUserTrustLevel *userTrustLevel = [self trustLevelForUser:userId];
if (userTrustLevel.isVerified)
{
devicesCount++;
if (device.trustLevel.isVerified)
trustedUsersCount++;

for (MXDeviceInfo *device in [self.store devicesForUser:userId].allValues)
{
trustedDevicesCount++;
devicesCount++;
if (device.trustLevel.isVerified)
{
trustedDevicesCount++;
}
}
}
}
}

NSProgress *trustedUsersProgress = [NSProgress progressWithTotalUnitCount:usersCount];
trustedUsersProgress.completedUnitCount = trustedUsersCount;

NSProgress *trustedDevicesProgress = [NSProgress progressWithTotalUnitCount:devicesCount];
trustedDevicesProgress.completedUnitCount = trustedDevicesCount;

return [[MXUsersTrustLevelSummary alloc] initWithTrustedUsersProgress:trustedUsersProgress andTrustedDevicesProgress:trustedDevicesProgress];

NSProgress *trustedUsersProgress = [NSProgress progressWithTotalUnitCount:usersCount];
trustedUsersProgress.completedUnitCount = trustedUsersCount;

NSProgress *trustedDevicesProgress = [NSProgress progressWithTotalUnitCount:devicesCount];
trustedDevicesProgress.completedUnitCount = trustedDevicesCount;

MXUsersTrustLevelSummary *trustLevelSummary = [[MXUsersTrustLevelSummary alloc] initWithTrustedUsersProgress:trustedUsersProgress
andTrustedDevicesProgress:trustedDevicesProgress];

dispatch_async(dispatch_get_main_queue(), ^{
onComplete(trustLevelSummary);
});
});
}

#pragma mark - Users keys
Expand Down
Loading

0 comments on commit 1cfec19

Please sign in to comment.