2014-10-29 21:58:58 +01:00
|
|
|
//
|
|
|
|
// FingerprintViewController.m
|
|
|
|
// Signal
|
|
|
|
//
|
|
|
|
// Created by Dylan Bourgeois on 02/11/14.
|
|
|
|
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "FingerprintViewController.h"
|
|
|
|
|
2014-12-04 00:23:36 +01:00
|
|
|
#import <AxolotlKit/NSData+keyVersionByte.h>
|
|
|
|
#import <25519/Curve25519.h>
|
2015-01-14 22:30:01 +01:00
|
|
|
#import "DJWActionSheet+OWS.h"
|
2014-12-04 00:23:36 +01:00
|
|
|
#import "TSStorageManager.h"
|
|
|
|
#import "TSStorageManager+IdentityKeyStore.h"
|
2014-12-27 01:08:05 +01:00
|
|
|
#import "TSStorageManager+SessionStore.h"
|
2014-12-06 22:27:43 +01:00
|
|
|
#import "PresentIdentityQRCodeViewController.h"
|
|
|
|
#import "ScanIdentityBarcodeViewController.h"
|
2014-12-27 01:08:05 +01:00
|
|
|
#import "SignalsNavigationController.h"
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2014-12-11 00:05:41 +01:00
|
|
|
#import "TSFingerprintGenerator.h"
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
@interface FingerprintViewController ()
|
2014-12-04 00:23:36 +01:00
|
|
|
@property TSContactThread *thread;
|
2015-01-27 21:17:49 +01:00
|
|
|
@property (nonatomic) BOOL isPresentingDialog;
|
2014-10-29 21:58:58 +01:00
|
|
|
@end
|
|
|
|
|
2015-01-27 21:17:49 +01:00
|
|
|
static NSString* const kPresentIdentityQRCodeViewSegue = @"PresentIdentityQRCodeViewSegue";
|
|
|
|
static NSString* const kScanIdentityBarcodeViewSegue = @"ScanIdentityBarcodeViewSegue";
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
@implementation FingerprintViewController
|
|
|
|
|
2014-12-04 00:23:36 +01:00
|
|
|
- (void)configWithThread:(TSThread *)thread{
|
|
|
|
self.thread = (TSContactThread*)thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
2014-11-21 14:38:37 +01:00
|
|
|
[self.view setAlpha:0];
|
|
|
|
|
2015-01-27 21:17:49 +01:00
|
|
|
UILongPressGestureRecognizer *longpressToResetSession = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(shredAndDelete:)];
|
|
|
|
longpressToResetSession.minimumPressDuration = 1.0;
|
|
|
|
[self.view addGestureRecognizer:longpressToResetSession];
|
2015-02-18 23:21:03 +01:00
|
|
|
_infoTheirFingerprint.text = NSLocalizedString(@"FINGERPRINT_INFO_THEIRS", @"");
|
|
|
|
_infoMyFingerprint.text = NSLocalizedString(@"FINGERPRINT_INFO_YOURS", @"");
|
|
|
|
_presentationLabel.text = NSLocalizedString(@"FINGERPRINT_INFO_ABOUT", @"");
|
|
|
|
_userFingerprintTitleLabel.text = NSLocalizedString(@"FINGERPRINT_YOURS",@"");
|
2015-02-22 16:28:52 +01:00
|
|
|
|
|
|
|
if ([UIScreen mainScreen].bounds.size.height <= 480) {
|
|
|
|
self.presentationLabel.hidden = YES;
|
|
|
|
self.myFPBorderView.hidden = YES;
|
|
|
|
}
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-04 00:23:36 +01:00
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
2014-11-21 14:38:37 +01:00
|
|
|
{
|
2014-12-27 01:08:05 +01:00
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
[self setTheirKeyInformation];
|
2014-12-04 00:23:36 +01:00
|
|
|
|
|
|
|
NSData *myPublicKey = [[TSStorageManager sharedManager] identityKeyPair].publicKey;
|
2014-12-11 00:05:41 +01:00
|
|
|
self.userFingerprintLabel.text = [TSFingerprintGenerator getFingerprintForDisplay:myPublicKey];
|
2014-12-04 00:23:36 +01:00
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
[UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
|
|
|
[self.view setAlpha:1];
|
|
|
|
} completion:nil];
|
2015-01-27 21:17:49 +01:00
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
}
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
}
|
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
- (void)setTheirKeyInformation {
|
2014-12-27 01:08:05 +01:00
|
|
|
self.contactFingerprintTitleLabel.text = self.thread.name;
|
|
|
|
NSData *identityKey = [[TSStorageManager sharedManager] identityKeyForRecipientId:self.thread.contactIdentifier];
|
|
|
|
self.contactFingerprintLabel.text = [TSFingerprintGenerator getFingerprintForDisplay:identityKey];
|
2015-01-14 22:30:01 +01:00
|
|
|
|
|
|
|
if([self.contactFingerprintLabel.text length] == 0) {
|
|
|
|
// no fingerprint, hide this view
|
|
|
|
_presentationLabel.hidden = YES;
|
|
|
|
_theirFingerprintView.hidden = YES;
|
|
|
|
}
|
|
|
|
|
2014-12-27 01:08:05 +01:00
|
|
|
}
|
|
|
|
|
2014-12-06 22:27:43 +01:00
|
|
|
-(NSData*) getMyPublicIdentityKey {
|
|
|
|
return [[TSStorageManager sharedManager] identityKeyPair].publicKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(NSData*) getTheirPublicIdentityKey {
|
|
|
|
return [[TSStorageManager sharedManager] identityKeyForRecipientId:self.thread.contactIdentifier];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
|
|
#pragma mark - Action
|
2014-12-04 00:23:36 +01:00
|
|
|
- (IBAction)closeButtonAction:(id)sender
|
2014-10-29 21:58:58 +01:00
|
|
|
{
|
2014-11-21 14:38:37 +01:00
|
|
|
[UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
|
|
|
[self.view setAlpha:0];
|
|
|
|
} completion:^(BOOL succeeded){
|
2015-02-17 00:14:50 +01:00
|
|
|
[self dismissViewControllerAnimated:NO completion:nil];
|
2014-11-21 14:38:37 +01:00
|
|
|
}];
|
2014-12-27 01:08:05 +01:00
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-12 17:15:00 +01:00
|
|
|
|
2014-12-04 00:23:36 +01:00
|
|
|
- (IBAction)shredAndDelete:(id)sender
|
2014-10-29 21:58:58 +01:00
|
|
|
{
|
2015-01-27 21:17:49 +01:00
|
|
|
if(!_isPresentingDialog) {
|
|
|
|
_isPresentingDialog = YES;
|
2015-02-18 23:21:03 +01:00
|
|
|
[DJWActionSheet showInView:self.view withTitle:NSLocalizedString(@"FINGERPRINT_SHRED_KEYMATERIAL_CONFIRMATION", @"") cancelButtonTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"") destructiveButtonTitle:nil otherButtonTitles:@[NSLocalizedString(@"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON", @"")]
|
2015-01-27 21:17:49 +01:00
|
|
|
tapBlock:^(DJWActionSheet *actionSheet, NSInteger tappedButtonIndex) {
|
|
|
|
_isPresentingDialog = NO;
|
|
|
|
if (tappedButtonIndex == actionSheet.cancelButtonIndex) {
|
2015-08-14 00:19:29 +02:00
|
|
|
DDLogDebug(@"User Cancelled");
|
2015-01-27 21:17:49 +01:00
|
|
|
} else if (tappedButtonIndex == actionSheet.destructiveButtonIndex) {
|
2015-08-14 00:19:29 +02:00
|
|
|
DDLogDebug(@"Destructive button tapped");
|
|
|
|
} else {
|
2015-01-27 21:17:49 +01:00
|
|
|
switch (tappedButtonIndex) {
|
|
|
|
case 0:
|
|
|
|
[self shredKeyingMaterial];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-12-27 01:08:05 +01:00
|
|
|
}
|
2015-01-27 21:17:49 +01:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-17 00:14:50 +01:00
|
|
|
-(IBAction) showFingerprint {
|
2015-01-27 21:17:49 +01:00
|
|
|
[self performSegueWithIdentifier:kPresentIdentityQRCodeViewSegue sender:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-17 00:14:50 +01:00
|
|
|
-(IBAction) scanFingerprint {
|
2015-01-27 21:17:49 +01:00
|
|
|
[self performSegueWithIdentifier:kScanIdentityBarcodeViewSegue sender:self];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-06 22:27:43 +01:00
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
2015-01-27 21:17:49 +01:00
|
|
|
if([[segue identifier] isEqualToString:kPresentIdentityQRCodeViewSegue]){
|
2014-12-06 22:27:43 +01:00
|
|
|
[segue.destinationViewController setIdentityKey:[[self getMyPublicIdentityKey] prependKeyType]];
|
|
|
|
}
|
2015-01-27 21:17:49 +01:00
|
|
|
else if([[segue identifier] isEqualToString:kScanIdentityBarcodeViewSegue]){
|
2014-12-06 22:27:43 +01:00
|
|
|
[segue.destinationViewController setIdentityKey:[[self getTheirPublicIdentityKey] prependKeyType]];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (IBAction)unwindToIdentityKeyWasVerified:(UIStoryboardSegue *)segue{
|
|
|
|
// Can later be used to mark identity key as verified if we want step above TOFU in UX
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-17 00:14:50 +01:00
|
|
|
- (IBAction)unwindIdentityVerificationCancel:(UIStoryboardSegue *)segue{
|
2015-08-14 00:19:29 +02:00
|
|
|
DDLogDebug(@"action cancelled");
|
2014-12-06 22:27:43 +01:00
|
|
|
// Can later be used to mark identity key as verified if we want step above TOFU in UX
|
|
|
|
}
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
#pragma mark - Shredding & Deleting
|
|
|
|
|
2014-12-27 01:08:05 +01:00
|
|
|
- (void)shredKeyingMaterial {
|
|
|
|
[[TSStorageManager sharedManager] removeIdentityKeyForRecipient:self.thread.contactIdentifier];
|
|
|
|
[[TSStorageManager sharedManager] deleteAllSessionsForContact:self.thread.contactIdentifier];
|
2015-01-14 22:30:01 +01:00
|
|
|
[self setTheirKeyInformation];
|
2014-12-27 01:08:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)shredDiscussionsWithContact {
|
2015-01-22 10:49:19 +01:00
|
|
|
UINavigationController *nVC = (UINavigationController*)self.presentingViewController;
|
|
|
|
for (UIViewController __strong *vc in nVC.viewControllers) {
|
|
|
|
if ([vc isKindOfClass:[MessagesViewController class]]) {
|
|
|
|
vc = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-27 01:08:05 +01:00
|
|
|
[self.thread remove]; // this removes the thread and all it's discussion (YapDatabaseRelationships)
|
|
|
|
__block SignalsNavigationController *vc = (SignalsNavigationController*)[self presentingViewController];
|
|
|
|
[vc dismissViewControllerAnimated:YES completion:^{
|
|
|
|
[vc popToRootViewControllerAnimated:YES];
|
|
|
|
}];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|