Commit 5a89b2d6 authored by Felix Paul Kühne's avatar Felix Paul Kühne

Move passcode lock to a designated object which will take care of anything keychain related

parent 83fe7d46
......@@ -21,15 +21,11 @@
#import "NSString+SupportedMedia.h"
#import "UIDevice+VLC.h"
#import "VLCPlaylistViewController.h"
#import "VLCPlaybackNavigationController.h"
#import "PAPasscodeViewController.h"
#import "VLCHTTPUploaderController.h"
#import "VLCMenuTableViewController.h"
#import "VLCMigrationViewController.h"
#import <BoxSDK/BoxSDK.h>
#import "VLCNotificationRelay.h"
#import "VLCPlaybackController.h"
#import "VLCNavigationController.h"
#import "VLCWatchMessage.h"
#import "VLCPlaybackController+MediaLibrary.h"
#import "VLCPlayerDisplayController.h"
......@@ -37,13 +33,14 @@
#import <DropboxSDK/DropboxSDK.h>
#import <HockeySDK/HockeySDK.h>
#import "VLCSidebarController.h"
#import "VLCKeychainCoordinator.h"
NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorized";
#define BETA_DISTRIBUTION 1
@interface VLCAppDelegate () <PAPasscodeViewControllerDelegate, VLCMediaFileDiscovererDelegate> {
PAPasscodeViewController *_passcodeLockController;
@interface VLCAppDelegate () <VLCMediaFileDiscovererDelegate>
{
int _idleCounter;
int _networkActivityCounter;
BOOL _passcodeValidated;
......@@ -67,7 +64,6 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
skipLoopFilterDefaultValue = kVLCSettingSkipLoopFilterNonRef;
NSDictionary *appDefaults = @{kVLCSettingPasscodeKey : @"",
kVLCSettingPasscodeOnKey : @(NO),
kVLCSettingContinueAudioInBackgroundKey : @(YES),
kVLCSettingStretchAudio : @(NO),
kVLCSettingTextEncoding : kVLCSettingTextEncodingDefaultValue,
......@@ -102,6 +98,12 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
[hockeyManager startManager];
[hockeyManager.authenticator authenticateInstallation];
/* listen to validation notification */
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(passcodeWasValidated:)
name:VLCPasscodeValidated
object:nil];
// Change the keyboard for UISearchBar
[[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];
// For the cursor
......@@ -178,6 +180,11 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
return YES;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - Handoff
- (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType
......@@ -433,6 +440,12 @@ continueUserActivity:(NSUserActivity *)userActivity
#pragma mark - pass code validation
- (void)passcodeWasValidated:(NSNotification *)aNotifcation
{
_passcodeValidated = YES;
[self.playlistViewController updateViewContents];
}
- (BOOL)passcodeValidated
{
return _passcodeValidated;
......@@ -440,39 +453,13 @@ continueUserActivity:(NSUserActivity *)userActivity
- (void)validatePasscode
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *passcode = [defaults objectForKey:kVLCSettingPasscodeKey];
if ([passcode isEqualToString:@""] || ![[defaults objectForKey:kVLCSettingPasscodeOnKey] boolValue]) {
_passcodeValidated = YES;
return;
}
if (!_passcodeValidated) {
_passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionEnter];
_passcodeLockController.delegate = self;
_passcodeLockController.passcode = passcode;
if (self.window.rootViewController.presentedViewController)
[self.window.rootViewController dismissViewControllerAnimated:NO completion:nil];
VLCKeychainCoordinator *keychainCoordinator = [VLCKeychainCoordinator defaultCoordinator];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_passcodeLockController];
navCon.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentViewController:navCon animated:NO completion:nil];
if (!_passcodeValidated && [keychainCoordinator passcodeLockEnabled]) {
[keychainCoordinator validatePasscode];
}
}
- (void)PAPasscodeViewControllerDidEnterPasscode:(PAPasscodeViewController *)controller
{
_passcodeValidated = YES;
[self.playlistViewController updateViewContents];
[self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)PAPasscodeViewController:(PAPasscodeViewController *)controller didFailToEnterPasscode:(NSInteger)attempts
{
// FIXME: handle countless failed passcode attempts
}
#pragma mark - idle timer preventer
- (void)disableIdleTimer
{
......
/*****************************************************************************
* VLCKeychainCoordinator.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
extern NSString *const VLCPasscodeValidated;
@interface VLCKeychainCoordinator : NSObject
+ (instancetype)defaultCoordinator;
@property (readonly) BOOL passcodeLockEnabled;
- (void)validatePasscode;
- (void)setPasscode:(NSString *)passcode;
@end
/*****************************************************************************
* VLCKeychainCoordinator.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCKeychainCoordinator.h"
#import "PAPasscodeViewController.h"
#import "VLCAppDelegate.h"
NSString *const VLCPasscodeValidated = @"VLCPasscodeValidated";
@interface VLCKeychainCoordinator () <PAPasscodeViewControllerDelegate>
{
PAPasscodeViewController *_passcodeLockController;
}
@end
@implementation VLCKeychainCoordinator
+ (instancetype)defaultCoordinator
{
static VLCKeychainCoordinator *sharedInstance = nil;
static dispatch_once_t pred;
dispatch_once(&pred, ^{
sharedInstance = [VLCKeychainCoordinator new];
});
return sharedInstance;
}
- (BOOL)passcodeLockEnabled
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *passcode = [defaults objectForKey:kVLCSettingPasscodeKey];
if (!passcode)
return NO;
if (passcode.length == 0)
return NO;
return YES;
}
- (void)validatePasscode
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *passcode = [defaults objectForKey:kVLCSettingPasscodeKey];
if ([passcode isEqualToString:@""]) {
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPasscodeValidated object:self];
}
_passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionEnter];
_passcodeLockController.delegate = self;
_passcodeLockController.passcode = passcode;
VLCAppDelegate *appDelegate = (VLCAppDelegate *)[UIApplication sharedApplication].delegate;
if (appDelegate.window.rootViewController.presentedViewController)
[appDelegate.window.rootViewController dismissViewControllerAnimated:NO completion:nil];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_passcodeLockController];
navCon.modalPresentationStyle = UIModalPresentationFullScreen;
[appDelegate.window.rootViewController presentViewController:navCon animated:NO completion:nil];
}
- (void)PAPasscodeViewControllerDidEnterPasscode:(PAPasscodeViewController *)controller
{
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPasscodeValidated object:self];
VLCAppDelegate *appDelegate = (VLCAppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)PAPasscodeViewController:(PAPasscodeViewController *)controller didFailToEnterPasscode:(NSInteger)attempts
{
// FIXME: handle countless failed passcode attempts
}
- (void)setPasscode:(NSString *)passcode
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:passcode forKey:kVLCSettingPasscodeKey];
[defaults synchronize];
}
@end
......@@ -24,6 +24,7 @@
#import "VLCThumbnailsCache.h"
#import <WatchKit/WatchKit.h>
#import "VLCPlaylistViewController.h"
#import "VLCKeychainCoordinator.h"
NSString *const VLCPlaybackControllerPlaybackDidStart = @"VLCPlaybackControllerPlaybackDidStart";
NSString *const VLCPlaybackControllerPlaybackDidPause = @"VLCPlaybackControllerPlaybackDidPause";
......@@ -866,7 +867,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyPlaybackRate] = @(_mediaPlayer.isPlaying ? _mediaPlayer.rate : 0.0);
/* don't leak sensitive information to the OS, if passcode lock is enabled */
if (![[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingPasscodeOnKey] boolValue]) {
if (![[VLCKeychainCoordinator defaultCoordinator] passcodeLockEnabled]) {
if (title)
currentlyPlayingTrackInfo[MPMediaItemPropertyTitle] = title;
if (artist.length > 0)
......
......@@ -17,6 +17,7 @@
#import "IASKSettingsReader.h"
#import "IASKAppSettingsViewController.h"
#import "PAPasscodeViewController.h"
#import "VLCKeychainCoordinator.h"
@interface VLCSettingsController ()<PAPasscodeViewControllerDelegate, IASKSettingsDelegate>
......@@ -47,6 +48,8 @@
PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
passcodeLockController.delegate = self;
[self.viewController presentViewController:passcodeLockController animated:YES completion:nil];
} else {
[[VLCKeychainCoordinator defaultCoordinator] setPasscode:nil];
}
}
if ([notification.object isEqual:kVLCSettingPlaybackGestures]) {
......@@ -64,18 +67,14 @@
- (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
[defaults synchronize];
[[VLCKeychainCoordinator defaultCoordinator] setPasscode:nil];
[controller dismissViewControllerAnimated:YES completion:nil];
}
- (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
[defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
[defaults synchronize];
[[VLCKeychainCoordinator defaultCoordinator] setPasscode:controller.passcode];
[controller dismissViewControllerAnimated:YES completion:nil];
}
......
......@@ -166,6 +166,7 @@
7DAE0C3A1B2F085F00C53996 /* VLCDiscoveryListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DAE0C391B2F085F00C53996 /* VLCDiscoveryListViewController.m */; };
7DB638AB185BC0890003887C /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7DB638AA185BC0890003887C /* Images.xcassets */; };
7DB847D71A5871570002DC30 /* VLCOneDriveObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DB847D61A5871570002DC30 /* VLCOneDriveObject.m */; };
7DBB788A1B30423B00894467 /* VLCKeychainCoordinator.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DBB78891B30423B00894467 /* VLCKeychainCoordinator.m */; };
7DBBF182183AB3B80009A339 /* VLCAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DBBF181183AB3B80009A339 /* VLCAppDelegate.m */; };
7DBBF19A183AB4300009A339 /* VLCCloudStorageTableViewCell~ipad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7DBBF185183AB4300009A339 /* VLCCloudStorageTableViewCell~ipad.xib */; };
7DBBF19B183AB4300009A339 /* VLCCloudStorageTableViewCell~iphone.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7DBBF186183AB4300009A339 /* VLCCloudStorageTableViewCell~iphone.xib */; };
......@@ -608,6 +609,8 @@
7DB638AA185BC0890003887C /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = "vlc-ios/Images.xcassets"; sourceTree = "<group>"; };
7DB847D51A5871570002DC30 /* VLCOneDriveObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCOneDriveObject.h; path = Sources/VLCOneDriveObject.h; sourceTree = SOURCE_ROOT; };
7DB847D61A5871570002DC30 /* VLCOneDriveObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCOneDriveObject.m; path = Sources/VLCOneDriveObject.m; sourceTree = SOURCE_ROOT; };
7DBB78881B30423B00894467 /* VLCKeychainCoordinator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCKeychainCoordinator.h; path = Sources/VLCKeychainCoordinator.h; sourceTree = SOURCE_ROOT; };
7DBB78891B30423B00894467 /* VLCKeychainCoordinator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCKeychainCoordinator.m; path = Sources/VLCKeychainCoordinator.m; sourceTree = SOURCE_ROOT; };
7DBBF180183AB3B80009A339 /* VLCAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCAppDelegate.h; path = Sources/VLCAppDelegate.h; sourceTree = SOURCE_ROOT; };
7DBBF181183AB3B80009A339 /* VLCAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCAppDelegate.m; path = Sources/VLCAppDelegate.m; sourceTree = SOURCE_ROOT; };
7DBBF185183AB4300009A339 /* VLCCloudStorageTableViewCell~ipad.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = "VLCCloudStorageTableViewCell~ipad.xib"; path = "Resources/VLCCloudStorageTableViewCell~ipad.xib"; sourceTree = SOURCE_ROOT; };
......@@ -1041,14 +1044,7 @@
7DCA8DA11B25BBB700946349 /* Library Sharing */,
7D30F3D1183AB2F100FFC021 /* VLCNetworkListCell.h */,
7D30F3D2183AB2F100FFC021 /* VLCNetworkListCell.m */,
7DAE0C2C1B2EDF7A00C53996 /* VLCNetworkListViewController.h */,
7DAE0C2D1B2EDF7A00C53996 /* VLCNetworkListViewController.m */,
7DAE0C2F1B2EDFD600C53996 /* VLCUPnPServerListViewController.h */,
7DAE0C301B2EDFD600C53996 /* VLCUPnPServerListViewController.m */,
7DAE0C321B2EE0C200C53996 /* VLCFTPServerListViewController.h */,
7DAE0C331B2EE0C200C53996 /* VLCFTPServerListViewController.m */,
7DAE0C381B2F085F00C53996 /* VLCDiscoveryListViewController.h */,
7DAE0C391B2F085F00C53996 /* VLCDiscoveryListViewController.m */,
7DBB78871B3028C400894467 /* Server browsing */,
7D30F3D5183AB2F100FFC021 /* VLCServerListViewController.h */,
7D30F3D6183AB2F100FFC021 /* VLCServerListViewController.m */,
7D30F3DA183AB2F900FFC021 /* VLCNetworkLoginViewController.h */,
......@@ -1302,6 +1298,8 @@
7D6B08BB174A72A900A05173 /* VLCConstants.h */,
7DBBF180183AB3B80009A339 /* VLCAppDelegate.h */,
7DBBF181183AB3B80009A339 /* VLCAppDelegate.m */,
7DBB78881B30423B00894467 /* VLCKeychainCoordinator.h */,
7DBB78891B30423B00894467 /* VLCKeychainCoordinator.m */,
A7D03A4817A4249F0022C16F /* MediaDiscovering */,
7D2339AB176DE70E008D223C /* Menu */,
7D5F7ABA175265CB006CCCFA /* HTTP Connectivity */,
......@@ -1373,6 +1371,21 @@
name = Imported;
sourceTree = "<group>";
};
7DBB78871B3028C400894467 /* Server browsing */ = {
isa = PBXGroup;
children = (
7DAE0C2C1B2EDF7A00C53996 /* VLCNetworkListViewController.h */,
7DAE0C2D1B2EDF7A00C53996 /* VLCNetworkListViewController.m */,
7DAE0C2F1B2EDFD600C53996 /* VLCUPnPServerListViewController.h */,
7DAE0C301B2EDFD600C53996 /* VLCUPnPServerListViewController.m */,
7DAE0C321B2EE0C200C53996 /* VLCFTPServerListViewController.h */,
7DAE0C331B2EE0C200C53996 /* VLCFTPServerListViewController.m */,
7DAE0C381B2F085F00C53996 /* VLCDiscoveryListViewController.h */,
7DAE0C391B2F085F00C53996 /* VLCDiscoveryListViewController.m */,
);
name = "Server browsing";
sourceTree = "<group>";
};
7DC19AEB1868C91400810BF7 /* First Steps */ = {
isa = PBXGroup;
children = (
......@@ -1984,6 +1997,7 @@
7DB847D71A5871570002DC30 /* VLCOneDriveObject.m in Sources */,
7DAE0C2E1B2EDF7A00C53996 /* VLCNetworkListViewController.m in Sources */,
7D1052E91A4DCC1100295F08 /* VLCOneDriveTableViewController.m in Sources */,
7DBB788A1B30423B00894467 /* VLCKeychainCoordinator.m in Sources */,
7D30F3D7183AB2F100FFC021 /* VLCNetworkListCell.m in Sources */,
265D511C1922746C00E38383 /* VLCLocalPlexFolderListViewController.m in Sources */,
7D1052EE1A4DCD1E00295F08 /* VLCOneDriveController.m in Sources */,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment