session-ios/Signal/src/view controllers/FingerprintViewController.m

182 lines
5.3 KiB
Mathematica
Raw Normal View History

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 "Cryptography.h"
#import <AxolotlKit/NSData+keyVersionByte.h>
#import <25519/Curve25519.h>
#import "NSData+hexString.h"
2014-10-29 21:58:58 +01:00
#import "DJWActionSheet.h"
2014-12-04 00:23:36 +01:00
#import "TSStorageManager.h"
#import "TSStorageManager+IdentityKeyStore.h"
#import "PresentIdentityQRCodeViewController.h"
#import "ScanIdentityBarcodeViewController.h"
#include "NSData+Base64.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;
2014-12-12 17:15:00 +01:00
@property BOOL didShowInfo;
2014-10-29 21:58:58 +01:00
@end
@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];
[self.view setAlpha:0];
2014-12-12 17:15:00 +01:00
[self hideInfo];
2014-10-29 21:58:58 +01:00
}
2014-12-04 00:23:36 +01:00
- (void)viewWillAppear:(BOOL)animated
{
2014-12-04 00:23:36 +01:00
self.contactFingerprintTitleLabel.text = self.thread.name;
NSData *identityKey = [[TSStorageManager sharedManager] identityKeyForRecipientId:self.thread.contactIdentifier];
2014-12-11 00:05:41 +01:00
self.contactFingerprintLabel.text = [TSFingerprintGenerator getFingerprintForDisplay:identityKey];
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
[UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{
[self.view setAlpha:1];
} completion:nil];
}
2014-10-29 21:58:58 +01:00
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(NSData*) getMyPublicIdentityKey {
return [[TSStorageManager sharedManager] identityKeyPair].publicKey;
}
-(NSData*) getTheirPublicIdentityKey {
return [[TSStorageManager sharedManager] identityKeyForRecipientId:self.thread.contactIdentifier];
}
2014-12-12 17:15:00 +01:00
-(void)showInfo
2014-10-29 21:58:58 +01:00
{
2014-12-12 17:15:00 +01:00
_didShowInfo = YES;
2014-10-29 21:58:58 +01:00
2014-12-12 17:15:00 +01:00
_infoArrowTop.hidden = NO;
_infoArrowBottom.hidden = NO;
_infoMyFingerprint.hidden = NO;
_infoTheirFingerprint.hidden = NO;
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^(){
_infoArrowTop.alpha = 1;
_infoArrowBottom.alpha = 1;
_infoMyFingerprint.alpha = 1;
_infoTheirFingerprint.alpha = 1;
_presentationLabel.alpha = 0;
} completion:nil];
_presentationLabel.hidden = YES;
}
-(void)hideInfo
{
_didShowInfo = NO;
_presentationLabel.hidden = NO;
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^(){
_infoArrowTop.alpha = 0;
_infoArrowBottom.alpha = 0;
_infoMyFingerprint.alpha = 0;
_infoTheirFingerprint.alpha = 0;
_presentationLabel.alpha = 1;
} completion:^(BOOL done){
if (done) {
_infoArrowTop.hidden = YES;
_infoArrowBottom.hidden = YES;
_infoMyFingerprint.hidden = YES;
_infoTheirFingerprint.hidden = YES;
}
}];
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
{
[UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{
[self.view setAlpha:0];
} completion:^(BOOL succeeded){
[self dismissViewControllerAnimated:YES completion:nil];
}];
2014-10-29 21:58:58 +01:00
}
2014-12-12 17:15:00 +01:00
- (IBAction)showInfoAction:(id)sender
{
if (!_didShowInfo) {
[self showInfo];
} else {
[self hideInfo];
}
}
2014-12-04 00:23:36 +01:00
- (IBAction)shredAndDelete:(id)sender
2014-10-29 21:58:58 +01:00
{
[DJWActionSheet showInView:self.view withTitle:@"Are you sure wou want to shred all communications with this contact ? This action is irreversible."
cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@[@"Shred all communications & delete contact"]
tapBlock:^(DJWActionSheet *actionSheet, NSInteger tappedButtonIndex) {
if (tappedButtonIndex == actionSheet.cancelButtonIndex) {
NSLog(@"User Cancelled");
} else if (tappedButtonIndex == actionSheet.destructiveButtonIndex) {
NSLog(@"Destructive button tapped");
}else {
[self shredAndDelete];
}
}];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@"PresentIdentityQRCodeViewSegue"]){
[segue.destinationViewController setIdentityKey:[[self getMyPublicIdentityKey] prependKeyType]];
}
else if([[segue identifier] isEqualToString:@"ScanIdentityBarcodeViewSegue"]){
[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
}
- (IBAction)unwindCancel:(UIStoryboardSegue *)segue{
NSLog(@"action cancelled");
// 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
- (void)shredAndDelete {
#warning unimplemented: shredAndDelete
2014-10-29 21:58:58 +01:00
}
@end