123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- //
- // CCManageCryptoCloud.m
- // Crypto Cloud Technology Nextcloud
- //
- // Created by Marino Faggiana on 13/02/17.
- // Copyright (c) 2017 TWS. All rights reserved.
- //
- // Author Marino Faggiana <m.faggiana@twsweb.it>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- #import "CCManageCryptoCloud.h"
- #import "AppDelegate.h"
- @implementation CCManageCryptoCloud
- - (id)initWithCoder:(NSCoder *)aDecoder
- {
- self = [super initWithCoder:aDecoder];
-
- if (self) {
-
- [self initializeForm];
- }
-
- return self;
- }
- - (void)initializeForm
- {
- XLFormDescriptor *form ;
- XLFormSectionDescriptor *section;
- XLFormRowDescriptor *row;
-
- form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_crypto_cloud_system_", nil)];
-
- section = [XLFormSectionDescriptor formSection];
- [form addFormSection:section];
- section.footerTitle = NSLocalizedString(@"_footer_crypto_cloud_", nil);
-
- // Activation Crypto Cloud Mode
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"activatecryptocloud" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_activation_crypto_cloud_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIImage imageNamed:image_settingsCryptoCloud] forKey:@"imageView.image"];
- row.action.formSelector = @selector(activateCryptoCloud:);
- row.hidden = @(YES);
- [section addFormRow:row];
-
- // Deactivation Crypto Cloud Mode
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"deactivatecryptocloud" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_deactivation_crypto_cloud_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIImage imageNamed:image_settingsRemoveCryptoCloud] forKey:@"imageView.image"];
- row.action.formSelector = @selector(disactivateCryptoCloud:);
- row.hidden = @(YES);
- [section addFormRow:row];
- section = [XLFormSectionDescriptor formSection];
- [form addFormSection:section];
-
- self.form = form;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- // Color
- [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
- [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
- }
- // Apparirà
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- // Color
- [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
- [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
-
- [self reloadForm];
- }
- - (void)activateCryptoCloud:(XLFormRowDescriptor *)sender
- {
- [self deselectFormRow:sender];
-
- CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
- viewController.delegate = self;
-
- viewController.type = BKPasscodeViewControllerNewPasscodeType;
- viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
- viewController.passcodeInputView.maximumLength = 64;
-
- viewController.title = NSLocalizedString(@"_key_aes_256_", nil);
-
- viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
- viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
-
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
- [self presentViewController:navigationController animated:YES completion:nil];
- }
- - (void)disactivateCryptoCloud:(XLFormRowDescriptor *)sender
- {
- CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
- viewController.delegate = self;
-
- viewController.type = BKPasscodeViewControllerCheckPasscodeType;
-
- viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
- viewController.passcodeInputView.maximumLength = 64;
-
- viewController.title = NSLocalizedString(@"_check_key_aes_256_", nil);
-
- viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
- viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
-
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
- [self presentViewController:navigationController animated:YES completion:nil];
- }
- - (void)closeCryptoCloudSecurity
- {
- // @"Attivazione avvenuta correttamente, ora potrai usufruire di tutte le funzionalità aggiuntive. Ti ricordiamo che i file cifrati possono essere decifrati sono sui dispositivi iOS"
- UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_info_", nil) message:NSLocalizedString(@"_alert_activation_crypto_cloud_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
- [alertView show];
- }
- - (void)activateSecurityOptions
- {
- CCManageCryptoCloudSecurity *vc = [[CCManageCryptoCloudSecurity alloc] initWithDelegate:self];
- UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
-
- [nc setModalPresentationStyle:UIModalPresentationFormSheet];
- [self presentViewController:nc animated:YES completion:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark == BKPasscodeViewController ==
- #pragma --------------------------------------------------------------------------------------------
- - (void)passcodeViewController:(BKPasscodeViewController *)aViewController didFinishWithPasscode:(NSString *)aPasscode
- {
- switch (aViewController.type) {
-
- case BKPasscodeViewControllerNewPasscodeType: {
-
- // min passcode 4 chars
- if ([aPasscode length] >= 4) {
-
- [CCUtility setKeyChainPasscodeForUUID:[CCUtility getUUID] conPasscode:aPasscode];
-
- // verify
- NSString *pwd = [CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]];
-
- if ([pwd isEqualToString:aPasscode] == NO || pwd == nil) {
-
- UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:@"Fatal error writing key" delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
- [alertView show];
-
- } else {
-
- // Crypto Cloud Mode : Activated
- app.isCryptoCloudMode = YES;
-
- // force reload all directory for all users
- [CCCoreData clearAllDateReadDirectory];
-
- // Request : Send Passcode email
- [self performSelector:@selector(activateSecurityOptions) withObject:nil afterDelay:0.1];
- }
-
- } else {
-
- UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_passcode_too_short_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
- [alertView show];
- }
-
- [aViewController dismissViewControllerAnimated:YES completion:nil];
- }
- break;
-
- case BKPasscodeViewControllerCheckPasscodeType: {
-
- // Crypto Cloud Mode : Deactivated
- [CCUtility adminRemovePasscode];
- app.isCryptoCloudMode = NO;
-
- // force reload all directory for all users and all metadata cryptated
- [CCCoreData clearAllDateReadDirectory];
- [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(cryptated == 1)"]];
-
- UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_info_", nil) message:NSLocalizedString(@"_alert_deactivation_crypto_cloud_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
- [alertView show];
-
- [aViewController dismissViewControllerAnimated:YES completion:nil];
- }
- break;
-
- default:
-
- break;
- }
- }
- - (void)passcodeViewController:(BKPasscodeViewController *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
- {
- if (aViewController.type == BKPasscodeViewControllerCheckPasscodeType) {
-
- NSString *key = [CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]];
-
- if ([aPasscode isEqualToString:key]) {
-
- self.lockUntilDate = nil;
- self.failedAttempts = 0;
- aResultHandler(YES);
-
- } else {
-
- aResultHandler(NO);
- }
- }
- }
- - (void)passcodeViewControllerDidFailAttempt:(BKPasscodeViewController *)aViewController
- {
- self.failedAttempts++;
-
- if (self.failedAttempts > 5) {
-
- NSTimeInterval timeInterval = 60;
-
- if (self.failedAttempts > 6) {
-
- NSUInteger multiplier = self.failedAttempts - 6;
-
- timeInterval = (5 * 60) * multiplier;
-
- if (timeInterval > 3600 * 24) {
- timeInterval = 3600 * 24;
- }
- }
-
- self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
- }
- }
- - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(BKPasscodeViewController *)aViewController
- {
- return self.failedAttempts;
- }
- - (NSDate *)passcodeViewControllerLockUntilDate:(BKPasscodeViewController *)aViewController
- {
- return self.lockUntilDate;
- }
- - (void)passcodeViewCloseButtonPressed:(id)sender
- {
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark === Reload Form ===
- #pragma --------------------------------------------------------------------------------------------
- - (void)reloadForm
- {
- XLFormRowDescriptor *rowActivateCryptoCloud = [self.form formRowWithTag:@"activatecryptocloud"];
- XLFormRowDescriptor *rowDeactivateCryptoCloud = [self.form formRowWithTag:@"deactivatecryptocloud"];
- XLFormRowDescriptor *rowSendMailEncryptPass = [self.form formRowWithTag:@"sendmailencryptpass"];
- if (app.isCryptoCloudMode) {
-
- rowActivateCryptoCloud.hidden = @(YES);
- rowDeactivateCryptoCloud.hidden = @(NO);
- rowSendMailEncryptPass.hidden = @(NO);
-
- } else {
-
- rowActivateCryptoCloud.hidden = @(NO);
- rowDeactivateCryptoCloud.hidden = @(YES);
- rowSendMailEncryptPass.hidden = @(YES);
- }
- [self.tableView reloadData];
- }
- @end
|