2017-11-14 17:21:01 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RoomKeyRequestViewController.h"
|
|
|
|
|
|
|
|
#import "AppDelegate.h"
|
2019-04-16 15:55:40 +00:00
|
|
|
#import "Riot-Swift.h"
|
2017-11-14 17:21:01 +00:00
|
|
|
|
2020-03-18 16:39:26 +00:00
|
|
|
@interface RoomKeyRequestViewController () <KeyVerificationCoordinatorBridgePresenterDelegate>
|
2017-11-14 17:21:01 +00:00
|
|
|
{
|
2019-01-05 02:28:03 +00:00
|
|
|
void (^onComplete)(void);
|
2017-11-14 17:21:01 +00:00
|
|
|
|
2020-03-18 16:39:26 +00:00
|
|
|
KeyVerificationCoordinatorBridgePresenter *keyVerificationCoordinatorBridgePresenter;
|
2017-12-05 14:47:39 +00:00
|
|
|
|
|
|
|
BOOL wasNewDevice;
|
2017-11-14 17:21:01 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RoomKeyRequestViewController
|
|
|
|
|
2019-01-05 02:28:03 +00:00
|
|
|
- (instancetype)initWithDeviceInfo:(MXDeviceInfo *)deviceInfo wasNewDevice:(BOOL)theWasNewDevice andMatrixSession:(MXSession *)session onComplete:(void (^)(void))onCompleteBlock
|
2017-11-14 17:21:01 +00:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
_mxSession = session;
|
|
|
|
_device = deviceInfo;
|
2017-12-05 14:47:39 +00:00
|
|
|
wasNewDevice = theWasNewDevice;
|
2017-11-14 17:21:01 +00:00
|
|
|
onComplete = onCompleteBlock;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)show
|
|
|
|
{
|
|
|
|
// Show it modally on the root view controller
|
|
|
|
UIViewController *rootViewController = [AppDelegate theDelegate].window.rootViewController;
|
|
|
|
if (rootViewController)
|
|
|
|
{
|
|
|
|
NSString *title = NSLocalizedStringFromTable(@"e2e_room_key_request_title", @"Vector", nil);
|
2017-12-05 14:47:39 +00:00
|
|
|
NSString *message;
|
|
|
|
if (wasNewDevice)
|
|
|
|
{
|
|
|
|
message = [NSString stringWithFormat:NSLocalizedStringFromTable(@"e2e_room_key_request_message_new_device", @"Vector", nil), _device.displayName];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
message = [NSString stringWithFormat:NSLocalizedStringFromTable(@"e2e_room_key_request_message", @"Vector", nil), _device.displayName];
|
|
|
|
}
|
|
|
|
|
2017-11-14 17:21:01 +00:00
|
|
|
_alertController = [UIAlertController alertControllerWithTitle:title
|
|
|
|
message:message
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
|
|
|
[_alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"e2e_room_key_request_start_verification", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-11-15 11:25:00 +00:00
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
|
2017-11-14 17:21:01 +00:00
|
|
|
self->_alertController = nil;
|
|
|
|
[self showVerificationView];
|
|
|
|
}
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[_alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"e2e_room_key_request_share_without_verifying", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
|
|
|
|
self->_alertController = nil;
|
|
|
|
|
|
|
|
// Accept the received requests from this device
|
|
|
|
[self.mxSession.crypto acceptAllPendingKeyRequestsFromUser:self.device.userId andDevice:self.device.deviceId onComplete:^{
|
|
|
|
|
|
|
|
onComplete();
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[_alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"e2e_room_key_request_ignore_request", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
2017-11-15 11:25:00 +00:00
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
|
|
|
|
self->_alertController = nil;
|
|
|
|
|
|
|
|
// Ignore all pending requests from this device
|
|
|
|
[self.mxSession.crypto ignoreAllPendingKeyRequestsFromUser:self.device.userId andDevice:self.device.deviceId onComplete:^{
|
|
|
|
|
|
|
|
onComplete();
|
|
|
|
}];
|
2017-11-14 17:21:01 +00:00
|
|
|
}
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[rootViewController presentViewController:_alertController animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)hide
|
|
|
|
{
|
|
|
|
if (_alertController)
|
|
|
|
{
|
2017-11-15 11:25:00 +00:00
|
|
|
[_alertController dismissViewControllerAnimated:YES completion:nil];
|
2017-11-14 17:21:01 +00:00
|
|
|
_alertController = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)showVerificationView
|
|
|
|
{
|
|
|
|
// Show it modally on the root view controller
|
|
|
|
UIViewController *rootViewController = [AppDelegate theDelegate].window.rootViewController;
|
|
|
|
if (rootViewController)
|
|
|
|
{
|
2020-03-18 16:39:26 +00:00
|
|
|
keyVerificationCoordinatorBridgePresenter = [[KeyVerificationCoordinatorBridgePresenter alloc] initWithSession:_mxSession];
|
|
|
|
keyVerificationCoordinatorBridgePresenter.delegate = self;
|
2019-04-16 15:55:40 +00:00
|
|
|
|
2020-03-18 16:39:26 +00:00
|
|
|
[keyVerificationCoordinatorBridgePresenter presentFrom:rootViewController otherUserId:_device.userId otherDeviceId:_device.deviceId animated:YES];
|
2017-11-14 17:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-16 15:55:40 +00:00
|
|
|
#pragma mark - DeviceVerificationCoordinatorBridgePresenterDelegate
|
2017-11-14 17:21:01 +00:00
|
|
|
|
2020-03-18 16:39:26 +00:00
|
|
|
- (void)keyVerificationCoordinatorBridgePresenterDelegateDidComplete:(KeyVerificationCoordinatorBridgePresenter *)coordinatorBridgePresenter otherUserId:(NSString * _Nonnull)otherUserId otherDeviceId:(NSString * _Nonnull)otherDeviceId
|
2020-04-14 10:50:53 +00:00
|
|
|
{
|
|
|
|
[self dismissKeyVerificationCoordinatorBridgePresenter];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyVerificationCoordinatorBridgePresenterDelegateDidCancel:(KeyVerificationCoordinatorBridgePresenter * _Nonnull)coordinatorBridgePresenter
|
|
|
|
{
|
|
|
|
[self dismissKeyVerificationCoordinatorBridgePresenter];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dismissKeyVerificationCoordinatorBridgePresenter
|
2017-11-14 17:21:01 +00:00
|
|
|
{
|
2020-03-18 16:39:26 +00:00
|
|
|
[keyVerificationCoordinatorBridgePresenter dismissWithAnimated:YES completion:nil];
|
|
|
|
keyVerificationCoordinatorBridgePresenter = nil;
|
2020-04-14 10:50:53 +00:00
|
|
|
|
2019-04-16 15:55:40 +00:00
|
|
|
// Check device new status
|
2020-01-15 07:38:35 +00:00
|
|
|
[self.mxSession.crypto downloadKeys:@[self.device.userId] forceDownload:NO success:^(MXUsersDevicesMap<MXDeviceInfo *> *usersDevicesInfoMap, NSDictionary<NSString *,MXCrossSigningInfo *> *crossSigningKeysMap) {
|
2020-04-14 10:50:53 +00:00
|
|
|
|
2019-04-16 15:55:40 +00:00
|
|
|
MXDeviceInfo *deviceInfo = [usersDevicesInfoMap objectForDevice:self.device.deviceId forUser:self.device.userId];
|
2020-01-16 08:19:39 +00:00
|
|
|
if (deviceInfo && deviceInfo.trustLevel.localVerificationStatus == MXDeviceVerified)
|
2019-04-16 15:55:40 +00:00
|
|
|
{
|
|
|
|
// Accept the received requests from this device
|
|
|
|
// As the device is now verified, all other key requests will be automatically accepted.
|
|
|
|
[self.mxSession.crypto acceptAllPendingKeyRequestsFromUser:self.device.userId andDevice:self.device.deviceId onComplete:^{
|
2020-04-14 10:50:53 +00:00
|
|
|
|
2019-04-16 15:55:40 +00:00
|
|
|
onComplete();
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Come back to self.alertController - ie, reopen it
|
|
|
|
[self show];
|
|
|
|
}
|
|
|
|
} failure:^(NSError *error) {
|
2020-04-14 10:50:53 +00:00
|
|
|
|
2019-04-16 15:55:40 +00:00
|
|
|
// Should not happen (the device is in the crypto db)
|
|
|
|
[self show];
|
|
|
|
}];
|
2017-11-14 17:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|