Skip to content

Commit

Permalink
Merge pull request #3255 from bbirman/passcodedeprecations
Browse files Browse the repository at this point in the history
Passcode deprecations
  • Loading branch information
bbirman committed Aug 13, 2020
2 parents 7c2d72c + 1842a9c commit b9822f9
Show file tree
Hide file tree
Showing 28 changed files with 288 additions and 104 deletions.
Expand Up @@ -27,7 +27,7 @@

@end

@interface SalesforceSDKManager () <SalesforceSDKManagerFlow, SFSecurityLockoutDelegate>
@interface SalesforceSDKManager () <SalesforceSDKManagerFlow>
{
BOOL _isLaunching;
UIViewController* _snapshotViewController;
Expand Down
Expand Up @@ -216,7 +216,6 @@ - (instancetype)init {
#endif
self.sdkManagerFlow = self;
self.delegates = [NSHashTable weakObjectsHashTable];
[SFSecurityLockout addDelegate:self];
[[NSNotificationCenter defaultCenter] addObserver:self.sdkManagerFlow selector:@selector(handleAppForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self.sdkManagerFlow selector:@selector(handleAppBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self.sdkManagerFlow selector:@selector(handleAppTerminate:) name:UIApplicationWillTerminateNotification object:nil];
Expand All @@ -233,10 +232,14 @@ - (instancetype)init {

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUserWillLogout:) name:kSFNotificationUserWillLogout object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self.sdkManagerFlow selector:@selector(handleUserDidLogout:) name:kSFNotificationUserDidLogout object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUserWillSwitch:) name:kSFNotificationUserWillSwitch object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUserDidSwitch:) name:kSFNotificationUserDidSwitch object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUserWillSwitch:) name:kSFNotificationUserWillSwitch object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUserDidSwitch:) name:kSFNotificationUserDidSwitch object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(passcodeFlowWillBegin:) name:kSFPasscodeFlowWillBegin object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(passcodeFlowDidComplete:) name:kSFPasscodeFlowCompleted object:nil];

SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in MobileSDK 9.0
[SFPasscodeManager sharedManager].preferredPasscodeProvider = kSFPasscodeProviderPBKDF2;
SFSDK_USE_DEPRECATED_END
self.useSnapshotView = YES;
[self computeWebViewUserAgent]; // web view user agent is computed asynchronously so very first call to self.userAgentString(...) will be missing it
self.userAgentString = [self defaultUserAgentString];
Expand Down Expand Up @@ -697,8 +700,9 @@ - (void)handleAppForeground:(NSNotification *)notification
[SFSDKCoreLogger i:[self class] format:@"Passcode validation succeeded, or was not required, on app foreground. Triggering postAppForeground handler."];
[self sendPostAppForegroundIfRequired];
}];

SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
[SFSecurityLockout validateTimer];
SFSDK_USE_DEPRECATED_END
}
}
}
Expand Down Expand Up @@ -782,14 +786,18 @@ - (void)handleAppWillResignActive:(NSNotification *)notification
- (void)handleAuthCompleted:(NSNotification *)notification
{
// Will set up the passcode timer for auth that occurs out of band from SDK Manager launch.
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
[SFSecurityLockout setupTimer];
SFSDK_USE_DEPRECATED_END
[SFSecurityLockout startActivityMonitoring];
}

- (void)handleIDPInitiatedAuthCompleted:(NSNotification *)notification
{
// Will set up the passcode timer for auth that occurs out of band from SDK Manager launch.
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
[SFSecurityLockout setupTimer];
SFSDK_USE_DEPRECATED_END
[SFSecurityLockout startActivityMonitoring];
NSDictionary *userInfo = notification.userInfo;
SFUserAccount *userAccount = userInfo[kSFNotificationUserInfoAccountKey];
Expand All @@ -804,7 +812,9 @@ - (void)handleIDPUserAddCompleted:(NSNotification *)notification
SFUserAccount *userAccount = userInfo[kSFNotificationUserInfoAccountKey];
// this is the only user context in the idp app.
if ([userAccount isEqual:[SFUserAccountManager sharedInstance].currentUser]) {
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
[SFSecurityLockout setupTimer];
SFSDK_USE_DEPRECATED_END
[SFSecurityLockout startActivityMonitoring];
[[SFUserAccountManager sharedInstance] switchToUser:userAccount];
[self sendPostLaunch];
Expand All @@ -820,6 +830,7 @@ - (void)handlePostLogout
// Close the passcode screen and reset passcode monitoring.
[SFSecurityLockout cancelPasscodeScreen];
[SFSecurityLockout stopActivityMonitoring];
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
[SFSecurityLockout removeTimer];
[self sendPostLogout];
}
Expand All @@ -841,6 +852,7 @@ - (void)handleUserDidSwitch:(SFUserAccount *)fromUser toUser:(SFUserAccount *)to
- (void)savePasscodeActivityInfo
{
[SFSecurityLockout removeTimer];
SFSDK_USE_DEPRECATED_END
[SFInactivityTimerCenter saveActivityTimestamp];
}

Expand Down Expand Up @@ -888,14 +900,16 @@ - (void)dismissSnapshot
if ([self isSnapshotPresented]) {
if (self.snapshotPresentationAction && self.snapshotDismissalAction) {
self.snapshotDismissalAction(_snapshotViewController);
if ([SFSecurityLockout isPasscodeNeeded]) {
if ([SFSecurityLockout shouldLock]) {
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
[SFSecurityLockout validateTimer];
}
} else {
[[SFSDKWindowManager sharedManager].snapshotWindow.viewController dismissViewControllerAnimated:NO completion:^{
[[SFSDKWindowManager sharedManager].snapshotWindow dismissWindowAnimated:NO withCompletion:^{
if ([SFSecurityLockout isPasscodeNeeded]) {
[SFSecurityLockout validateTimer];
SFSDK_USE_DEPRECATED_END
}
}];
}];
Expand Down Expand Up @@ -957,7 +971,9 @@ - (void)authAtLaunch

SFUserAccountManagerSuccessCallbackBlock successBlock = ^(SFOAuthInfo *authInfo,SFUserAccount *userAccount) {
[SFSDKCoreLogger i:[self class] format:@"Authentication (%@) succeeded. Launch completed.", authInfo.authTypeDescription];
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
[SFSecurityLockout setupTimer];
SFSDK_USE_DEPRECATED_END
[SFSecurityLockout startActivityMonitoring];
[self authValidatedToPostAuth:SFSDKLaunchActionAuthenticated];
};
Expand Down Expand Up @@ -992,7 +1008,9 @@ - (void)authBypassAtLaunch
// stays on the screen, masking the main UI.
[[SFUserAccountManager sharedInstance] dismissAuthViewControllerIfPresent];

SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
[SFSecurityLockout setupTimer];
SFSDK_USE_DEPRECATED_END
[SFSecurityLockout startActivityMonitoring];
[self authValidatedToPostAuth:noAuthLaunchAction];
}
Expand Down Expand Up @@ -1138,18 +1156,17 @@ - (void)userAccountManager:(SFUserAccountManager *)userAccountManager
[self.sdkManagerFlow handleUserDidSwitch:fromUser toUser:toUser];
}

#pragma mark - SFSecurityLockoutDelegate
#pragma mark - SFSecurityLockout

- (void)passcodeFlowWillBegin:(SFAppLockControllerMode)mode
{
- (void)passcodeFlowWillBegin:(NSNotification *)notification {
self.passcodeDisplayed = YES;
}

- (void)passcodeFlowDidComplete:(BOOL)success
{
- (void)passcodeFlowDidComplete:(NSNotification *)notification {
self.passcodeDisplayed = NO;
[self sendPostAppForegroundIfRequired];
}

@end

NSString *SFAppTypeGetDescription(SFAppType appType){
Expand Down
Expand Up @@ -29,6 +29,7 @@

#import <Foundation/Foundation.h>
#import "SFSDKViewControllerConfig.h"
#import "SalesforceSDKConstants.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -46,7 +47,7 @@ NS_SWIFT_NAME(AppLockViewControllerConfig)
* but users will be unable to unlock the app if their pin is longer than the specified
* length.
*/
@property (nonatomic) BOOL forcePasscodeLength;
@property (nonatomic) BOOL forcePasscodeLength SFSDK_DEPRECATED(8.3, 9.0, "Will be removed.");

/**
* The number of allowed passcode entry attempts before the user is logged out.
Expand Down Expand Up @@ -121,7 +122,7 @@ NS_SWIFT_NAME(AppLockViewControllerConfig)
/**
* Length of the user's passcode.
*/
@property (nonatomic) NSUInteger passcodeLength;
@property (nonatomic) NSUInteger passcodeLength SFSDK_DEPRECATED(8.3, 9.0, "Will be internal.");

@end

Expand Down
Expand Up @@ -54,7 +54,9 @@ -(instancetype) init {
_buttonFont = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
_touchIdImage = [SFSDKResourceUtils imageNamed:@"touchId"];
_faceIdImage = [SFSDKResourceUtils imageNamed:@"faceId"];
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
_passcodeLength = [SFSecurityLockout passcodeLength];
SFSDK_USE_DEPRECATED_END
}
return self;
}
Expand Down
Expand Up @@ -32,7 +32,7 @@

NS_ASSUME_NONNULL_BEGIN

NS_SWIFT_NAME(AppLockViewController)
NS_SWIFT_NAME(AppLockViewController) SFSDK_DEPRECATED(8.3, 9.0, "Will be internal.")
@interface SFSDKAppLockViewController : SFSDKNavigationController

- (instancetype)initWithMode:(SFAppLockControllerMode)mode andViewConfig:(SFSDKAppLockViewConfig *)config;
Expand Down
Expand Up @@ -36,6 +36,7 @@
#import "SFSDKWindowManager.h"
#import "SFSecurityLockout.h"
#import "SFSDKViewUtils.h"
#import "SFSecurityLockout+Internal.h"

@interface SFSDKAppLockViewController () <SFSDKPasscodeCreateDelegate,SFSDKBiometricViewDelegate,SFSDKPasscodeVerifyDelegate>

Expand All @@ -46,7 +47,10 @@ @interface SFSDKAppLockViewController () <SFSDKPasscodeCreateDelegate,SFSDKBiome

@end

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
@implementation SFSDKAppLockViewController
#pragma clang diagnostic pop

- (instancetype)initWithMode:(SFAppLockControllerMode)mode andViewConfig:(SFSDKAppLockViewConfig *)config
{
Expand Down Expand Up @@ -88,6 +92,7 @@ - (void)setupNavBar

- (void)passcodeCreated:(NSString *)passcode updateMode:(BOOL)isUpdateMode
{
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
[[SFPasscodeManager sharedManager] changePasscode:passcode];
[SFSecurityLockout setUpgradePasscodeLength:[passcode length]];
if ([SFSecurityLockout biometricState] == SFBiometricUnlockAvailable) {
Expand All @@ -97,6 +102,7 @@ - (void)passcodeCreated:(NSString *)passcode updateMode:(BOOL)isUpdateMode
[self.navigationController popViewControllerAnimated:NO];
[SFSecurityLockout unlock:action];
}
SFSDK_USE_DEPRECATED_END
}

#pragma mark - SFSDKPasscodeVerifyDelegate
Expand All @@ -107,14 +113,18 @@ - (void)passcodeVerified
[self promptBiometricEnrollment];
} else {
[self.navigationController popViewControllerAnimated:NO];
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
[SFSecurityLockout unlock:SFSecurityLockoutActionPasscodeVerified];
SFSDK_USE_DEPRECATED_END
}
}

- (void)passcodeFailed
{
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
[[SFPasscodeManager sharedManager] resetPasscode];
[SFSecurityLockout wipeState];
SFSDK_USE_DEPRECATED_END
}

#pragma mark - SFSDKBiometricViewDelegate
Expand All @@ -123,9 +133,11 @@ - (void)biometricUnlockSucceeded:(BOOL)isVerificationMode
{
[SFSecurityLockout userAllowedBiometricUnlock:YES];

SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
if ([SFSecurityLockout locked]) {
[self.navigationController popViewControllerAnimated:NO];
[SFSecurityLockout unlock:SFSecurityLockoutActionBiometricVerified];
SFSDK_USE_DEPRECATED_END
} else {
[self dismissStandaloneBiometricSetup];
}
Expand All @@ -141,9 +153,11 @@ - (void)biometricUnlockFailed:(BOOL)isVerificationMode
} else {
[SFSecurityLockout userAllowedBiometricUnlock:NO];

SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
if ([SFSecurityLockout locked]) {
[self.navigationController popViewControllerAnimated:NO];
[SFSecurityLockout unlock:SFSecurityLockoutActionPasscodeCreated];
SFSDK_USE_DEPRECATED_END
} else {
[self dismissStandaloneBiometricSetup];
}
Expand All @@ -152,7 +166,9 @@ - (void)biometricUnlockFailed:(BOOL)isVerificationMode

- (void)dismissStandaloneBiometricSetup
{
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
[SFSecurityLockout setupTimer];
SFSDK_USE_DEPRECATED_END
[[[SFSDKWindowManager sharedManager] passcodeWindow].viewController dismissViewControllerAnimated:NO completion:^{
[[SFSDKWindowManager sharedManager].passcodeWindow dismissWindowAnimated:NO withCompletion:^{}];
}];
Expand Down
Expand Up @@ -100,7 +100,9 @@ - (void)loadView
self.passcodeTextView.layer.borderWidth = kSFViewBorderWidth;
self.passcodeTextView.accessibilityIdentifier = @"passcodeTextField";
self.passcodeTextView.accessibilityLabel = [SFSDKResourceUtils localizedString:@"accessibilityPasscodeFieldLabel"];
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
self.passcodeTextView.accessibilityHint = [[NSString alloc] initWithFormat:[SFSDKResourceUtils localizedString:@"accessibilityPasscodeLengthHint"], self.viewConfig.passcodeLength];
SFSDK_USE_DEPRECATED_END
self.passcodeTextView.secureTextEntry = YES;
self.passcodeTextView.isAccessibilityElement = YES;
[self.passcodeTextView clearPasscode];
Expand Down Expand Up @@ -200,11 +202,13 @@ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRang
return NO;
}

if (self.passcodeTextView.passcodeInput.length < self.viewConfig.passcodeLength) {
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
if (self.passcodeTextView.passcodeInput.length < self.viewConfig.passcodeLength) {
[self.passcodeTextView.passcodeInput appendString:rString];
}

if ([self.passcodeTextView.passcodeInput length] == self.viewConfig.passcodeLength) {
SFSDK_USE_DEPRECATED_END
if (self.firstPasscodeValidated) {
if ([self.passcodeTextView.passcodeInput isEqualToString:self.initialPasscode] ) {
if ([self.passcodeTextView isFirstResponder]) {
Expand Down
Expand Up @@ -58,8 +58,10 @@ - (instancetype)initWithFrame:(CGRect)frame andViewConfig:(SFSDKAppLockViewConfi
{
if (self = [super initWithFrame:frame]) {
_subLayerRefs = [[NSMutableArray alloc] init];
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
_passcodeLength = config.passcodeLength;
_passcodeLengthKnown = (config.passcodeLength != 0);
SFSDK_USE_DEPRECATED_END
_viewConfig = config;
self.keyboardType = UIKeyboardTypeNumberPad;
self.backgroundColor = config.secondaryBackgroundColor;
Expand Down
Expand Up @@ -98,7 +98,9 @@ - (instancetype)initWithViewConfig:(SFSDKAppLockViewConfig *)config
if (self.remainingAttempts == 0) {
[self resetReaminingAttemps];
}
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
self.passcodeLengthKnown = (self.viewConfig.passcodeLength != 0);
SFSDK_USE_DEPRECATED_END
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(layoutVerifyButton:) name:UIKeyboardDidShowNotification object:nil];
}
return self;
Expand All @@ -122,7 +124,9 @@ - (void)loadView
self.passcodeTextView.secureTextEntry = YES;
self.passcodeTextView.isAccessibilityElement = YES;
if (self.passcodeLengthKnown) {
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
self.passcodeTextView.accessibilityHint = [NSString stringWithFormat:[SFSDKResourceUtils localizedString:@"accessibilityPasscodeLengthHint"], self.viewConfig.passcodeLength];
SFSDK_USE_DEPRECATED_END
}
[self.passcodeTextView clearPasscode];
[self.view addSubview:self.passcodeTextView];
Expand Down Expand Up @@ -228,7 +232,9 @@ - (void)showVerifyPasscode
#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)rString
{
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
NSUInteger length = (self.passcodeLengthKnown) ? self.viewConfig.passcodeLength : kSFMaxPasscodeLength;
SFSDK_USE_DEPRECATED_END

// This fixes deleting if VoiceOver is on.
if (UIAccessibilityIsVoiceOverRunning() && [rString isEqualToString:@""]) {
Expand Down Expand Up @@ -283,6 +289,7 @@ - (void)resetReaminingAttemps

- (void)verifyPasscode
{
SFSDK_USE_DEPRECATED_BEGIN // TODO: Remove in Mobile SDK 9.0
if ([[SFPasscodeManager sharedManager] verifyPasscode:self.passcodeTextView.passcodeInput]) {
if ([self.passcodeTextView isFirstResponder]) {
[self.passcodeTextView resignFirstResponder];
Expand All @@ -292,6 +299,7 @@ - (void)verifyPasscode
// This can happen when upgrading to new UX that requires actual length.
if ([SFSecurityLockout passcodeLength] == 0) {
[SFSecurityLockout setUpgradePasscodeLength:[self.passcodeTextView.passcodeInput length]];
SFSDK_USE_DEPRECATED_END
}
[self validatePasscodeConfirmed:self.passcodeTextView.passcodeInput];
} else {
Expand Down
Expand Up @@ -27,7 +27,7 @@
#import "SFGeneratedKeyStore.h"
#import "SFPasscodeKeyStore.h"

@interface SFKeyStoreManager () <SFPasscodeManagerDelegate>
@interface SFKeyStoreManager ()

@property (nonatomic, strong) SFGeneratedKeyStore *generatedKeyStore;

Expand Down

0 comments on commit b9822f9

Please sign in to comment.