Merge branch 'charlesmchen/2fa'

pull/1/head
Matthew Chen 7 years ago
commit 7437152688

@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (2.3.5)
CFPropertyList (2.3.6)
activesupport (4.2.10)
i18n (~> 0.7)
minitest (~> 5.1)
@ -9,32 +9,33 @@ GEM
tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
atomos (0.1.2)
babosa (1.0.2)
claide (1.0.2)
cocoapods (1.3.1)
cocoapods (1.4.0)
activesupport (>= 4.0.2, < 5)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.3.1)
cocoapods-deintegrate (>= 1.0.1, < 2.0)
cocoapods-core (= 1.4.0)
cocoapods-deintegrate (>= 1.0.2, < 2.0)
cocoapods-downloader (>= 1.1.3, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-stats (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.2.0, < 2.0)
cocoapods-trunk (>= 1.3.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (~> 2.0.1)
gh_inspector (~> 1.0)
molinillo (~> 0.5.7)
molinillo (~> 0.6.4)
nap (~> 1.0)
ruby-macho (~> 1.1)
xcodeproj (>= 1.5.1, < 2.0)
cocoapods-core (1.3.1)
xcodeproj (>= 1.5.4, < 2.0)
cocoapods-core (1.4.0)
activesupport (>= 4.0.2, < 6)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.1)
cocoapods-deintegrate (1.0.2)
cocoapods-downloader (1.1.3)
cocoapods-plugins (1.0.0)
nap
@ -48,6 +49,7 @@ GEM
colored2 (3.1.2)
commander-fastlane (4.4.5)
highline (~> 1.7.2)
concurrent-ruby (1.0.5)
declarative (0.0.10)
declarative-option (0.1.0)
domain_name (0.5.20170404)
@ -98,7 +100,7 @@ GEM
xcpretty-travis-formatter (>= 0.0.3)
fourflusher (2.0.1)
fuzzy_match (2.0.4)
gh_inspector (1.0.3)
gh_inspector (1.1.2)
google-api-client (0.13.6)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 0.5)
@ -118,7 +120,8 @@ GEM
http-cookie (1.0.3)
domain_name (~> 0.5)
httpclient (2.8.3)
i18n (0.8.6)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
json (2.1.0)
jwt (1.5.6)
little-plugger (1.1.4)
@ -130,8 +133,8 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_magick (4.5.1)
minitest (5.10.3)
molinillo (0.5.7)
minitest (5.11.3)
molinillo (0.6.4)
multi_json (1.12.2)
multi_xml (0.6.0)
multipart-post (2.0.0)
@ -161,7 +164,7 @@ GEM
unicode-display_width (~> 1.1, >= 1.1.1)
thread_safe (0.3.6)
tty-screen (0.5.0)
tzinfo (1.2.3)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uber (0.1.0)
unf (0.1.4)
@ -169,8 +172,9 @@ GEM
unf_ext (0.0.7.4)
unicode-display_width (1.3.0)
word_wrap (1.0.0)
xcodeproj (1.5.2)
xcodeproj (1.5.6)
CFPropertyList (~> 2.3.3)
atomos (~> 0.1.2)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.2.3)
@ -187,4 +191,4 @@ DEPENDENCIES
fastlane
BUNDLED WITH
1.14.6
1.16.1

@ -211,7 +211,7 @@ SPEC CHECKSUMS:
PureLayout: 4d550abe49a94f24c2808b9b95db9131685fe4cd
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c
SignalServiceKit: c639443811f2670986006f5b661cb1a862de66ab
SignalServiceKit: 5cc6e8e249f381c5eaee8693c0dff20fc1a3eee0
SocketRocket: dbb1554b8fc288ef8ef370d6285aeca7361be31e
SQLCipher: f9fcf29b2e59ced7defc2a2bdd0ebe79b40d4990
SSZipArchive: 14401ade5f8e82aba1ff03e9f88e9de60937ae60
@ -222,4 +222,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: 66db99df53e7593362ebb004bea5d2215ca00e8e
COCOAPODS: 1.3.1
COCOAPODS: 1.4.0

@ -1 +1 @@
Subproject commit 29babe215072d52688ea5b18592f308bfc190612
Subproject commit 267e347b1eb97f8fd2e03a881b1a1c0c1de20e0f

@ -51,6 +51,7 @@
344F249A200FD03300CFB4F4 /* MessageApprovalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 344F2496200FD03200CFB4F4 /* MessageApprovalViewController.swift */; };
344F249B200FD03300CFB4F4 /* SharingThreadPickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 344F2497200FD03200CFB4F4 /* SharingThreadPickerViewController.m */; };
344F249C200FD03300CFB4F4 /* AttachmentApprovalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 344F2498200FD03200CFB4F4 /* AttachmentApprovalViewController.swift */; };
345BC30C2047030700257B7C /* OWS2FASettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 345BC30B2047030600257B7C /* OWS2FASettingsViewController.m */; };
3461284B1FD0B94000532771 /* SAELoadViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3461284A1FD0B93F00532771 /* SAELoadViewController.swift */; };
346129341FD1A88700532771 /* OWSSwiftUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346129331FD1A88700532771 /* OWSSwiftUtils.swift */; };
346129391FD1B47300532771 /* OWSPreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = 346129371FD1B47200532771 /* OWSPreferences.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -568,6 +569,8 @@
344F2496200FD03200CFB4F4 /* MessageApprovalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MessageApprovalViewController.swift; path = SignalMessaging/attachments/MessageApprovalViewController.swift; sourceTree = SOURCE_ROOT; };
344F2497200FD03200CFB4F4 /* SharingThreadPickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SharingThreadPickerViewController.m; path = SignalMessaging/attachments/SharingThreadPickerViewController.m; sourceTree = SOURCE_ROOT; };
344F2498200FD03200CFB4F4 /* AttachmentApprovalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AttachmentApprovalViewController.swift; path = SignalMessaging/attachments/AttachmentApprovalViewController.swift; sourceTree = SOURCE_ROOT; };
345BC30A2047030600257B7C /* OWS2FASettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWS2FASettingsViewController.h; sourceTree = "<group>"; };
345BC30B2047030600257B7C /* OWS2FASettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWS2FASettingsViewController.m; sourceTree = "<group>"; };
3461284A1FD0B93F00532771 /* SAELoadViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SAELoadViewController.swift; sourceTree = "<group>"; };
346129331FD1A88700532771 /* OWSSwiftUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSSwiftUtils.swift; sourceTree = "<group>"; };
346129371FD1B47200532771 /* OWSPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSPreferences.h; sourceTree = "<group>"; };
@ -1469,6 +1472,8 @@
34B3F8571E8DF1700035BE1A /* NotificationSettingsOptionsViewController.m */,
34B3F8581E8DF1700035BE1A /* NotificationSettingsViewController.h */,
34B3F8591E8DF1700035BE1A /* NotificationSettingsViewController.m */,
345BC30A2047030600257B7C /* OWS2FASettingsViewController.h */,
345BC30B2047030600257B7C /* OWS2FASettingsViewController.m */,
34CCAF391F0C2748004084F4 /* OWSAddToContactViewController.h */,
34CCAF3A1F0C2748004084F4 /* OWSAddToContactViewController.m */,
347E0B772003CD7400BC2F76 /* OWSBackupExportViewController.h */,
@ -3102,6 +3107,7 @@
4523149E1F7E916B003A428C /* SlideOffAnimatedTransition.swift in Sources */,
452C468F1E427E200087B011 /* OutboundCallInitiator.swift in Sources */,
45F170BB1E2FC5D3003FC1F2 /* CallAudioService.swift in Sources */,
345BC30C2047030700257B7C /* OWS2FASettingsViewController.m in Sources */,
34B3F8711E8DF1700035BE1A /* AboutTableViewController.m in Sources */,
34B3F88D1E8DF1700035BE1A /* OWSQRCodeScanningViewController.m in Sources */,
34BECE2E1F7ABCE000D7438D /* GifPickerViewController.swift in Sources */,

@ -24,7 +24,6 @@
#import "OWSDatabaseMigration.h"
#import "OWSNavigationController.h"
#import "OWSProgressView.h"
#import "OWSViewController.h"
#import "OWSWebRTCDataProtos.pb.h"
#import "PrivacySettingsTableViewController.h"
#import "ProfileViewController.h"
@ -53,6 +52,7 @@
#import <SignalMessaging/OWSPreferences.h>
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalMessaging/OWSSounds.h>
#import <SignalMessaging/OWSViewController.h>
#import <SignalMessaging/Release.h>
#import <SignalMessaging/ThreadUtil.h>
#import <SignalMessaging/UIColor+OWS.h>

@ -1,8 +1,8 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -1,8 +1,8 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -1,8 +1,8 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -1,8 +1,8 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -1,8 +1,8 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -1,8 +1,8 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -1,8 +1,8 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
#import <UIKit/UIKit.h>
@class TSThread;

@ -2,7 +2,7 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -1,8 +1,8 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -1,9 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSConversationSettingsViewDelegate.h"
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -38,21 +38,15 @@
OWSTableSection *soundsSection = [OWSTableSection new];
soundsSection.headerTitle
= NSLocalizedString(@"SETTINGS_SECTION_SOUNDS", @"Header Label for the sounds section of settings views.");
[soundsSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:@"UITableViewCellStyleValue1"];
cell.textLabel.text = NSLocalizedString(@"SETTINGS_ITEM_NOTIFICATION_SOUND",
@"Label for settings view that allows user to change the notification sound.");
OWSSound sound = [OWSSounds globalNotificationSound];
cell.detailTextLabel.text = [OWSSounds displayNameForSound:sound];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
actionBlock:^{
OWSSoundSettingsViewController *vc = [OWSSoundSettingsViewController new];
[weakSelf.navigationController pushViewController:vc animated:YES];
}]];
[soundsSection
addItem:[OWSTableItem disclosureItemWithText:
NSLocalizedString(@"SETTINGS_ITEM_NOTIFICATION_SOUND",
@"Label for settings view that allows user to change the notification sound.")
detailText:[OWSSounds displayNameForSound:[OWSSounds globalNotificationSound]]
actionBlock:^{
OWSSoundSettingsViewController *vc = [OWSSoundSettingsViewController new];
[weakSelf.navigationController pushViewController:vc animated:YES];
}]];
NSString *inAppSoundsLabelText = NSLocalizedString(@"NOTIFICATIONS_SECTION_INAPP",
@"Table cell switch label. When disabled, Signal will not play notification sounds while the app is in the "
@ -65,23 +59,15 @@
OWSTableSection *backgroundSection = [OWSTableSection new];
backgroundSection.headerTitle = NSLocalizedString(@"SETTINGS_NOTIFICATION_CONTENT_TITLE", @"table section header");
[backgroundSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:@"UITableViewCellStyleValue1"];
NotificationType notifType = [prefs notificationPreviewType];
NSString *detailString = [prefs nameForNotificationPreviewType:notifType];
cell.textLabel.text = NSLocalizedString(@"NOTIFICATIONS_SHOW", nil);
cell.detailTextLabel.text = detailString;
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
actionBlock:^{
NotificationSettingsOptionsViewController *vc =
[NotificationSettingsOptionsViewController new];
[weakSelf.navigationController pushViewController:vc animated:YES];
}]];
[backgroundSection
addItem:[OWSTableItem
disclosureItemWithText:NSLocalizedString(@"NOTIFICATIONS_SHOW", nil)
detailText:[prefs nameForNotificationPreviewType:[prefs notificationPreviewType]]
actionBlock:^{
NotificationSettingsOptionsViewController *vc =
[NotificationSettingsOptionsViewController new];
[weakSelf.navigationController pushViewController:vc animated:YES];
}]];
backgroundSection.footerTitle
= NSLocalizedString(@"SETTINGS_NOTIFICATION_CONTENT_DESCRIPTION", @"table section footer");
[contents addSection:backgroundSection];

@ -0,0 +1,25 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, Enable2FAMode) {
OWS2FASettingsMode_Status = 0,
OWS2FASettingsMode_SelectPIN,
OWS2FASettingsMode_ConfirmPIN,
};
@interface OWS2FASettingsViewController : OWSViewController
@property (nonatomic) Enable2FAMode mode;
// When confirming the PIN, this is the PIN that was
// initially entered by the user.
@property (nonatomic, nullable) NSString *candidatePin;
@end
NS_ASSUME_NONNULL_END

@ -0,0 +1,492 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWS2FASettingsViewController.h"
#import "OWSTableViewController.h"
#import "Signal-Swift.h"
#import "SignalMessaging.h"
#import <SignalMessaging/NSString+OWS.h>
#import <SignalMessaging/SignalMessaging-Swift.h>
#import <SignalMessaging/SignalMessaging.h>
#import <SignalMessaging/UIColor+OWS.h>
#import <SignalMessaging/UIFont+OWS.h>
#import <SignalMessaging/UIView+OWS.h>
#import <SignalServiceKit/OWS2FAManager.h>
NS_ASSUME_NONNULL_BEGIN
@interface OWS2FASettingsViewController () <UITextFieldDelegate>
@property (nonatomic, weak) UIViewController *root2FAViewController;
@property (nonatomic) UITextField *pinTextfield;
@property (nonatomic) OWSTableViewController *tableViewController;
@end
#pragma mark -
@implementation OWS2FASettingsViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = UIColor.whiteColor;
self.title = NSLocalizedString(@"ENABLE_2FA_VIEW_TITLE", @"Title for the 'enable two factor auth PIN' views.");
[self createContents];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(stateDidChange:)
name:NSNotificationName_2FAStateDidChange
object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)createContents
{
for (UIView *subview in self.view.subviews) {
[subview removeFromSuperview];
}
switch (self.mode) {
case OWS2FASettingsMode_Status:
[self createStatusContents];
break;
case OWS2FASettingsMode_SelectPIN:
[self createSelectCodeContents];
break;
case OWS2FASettingsMode_ConfirmPIN:
[self createConfirmCodeContents];
break;
}
}
- (void)viewWillAppear:(BOOL)animated
{
switch (self.mode) {
case OWS2FASettingsMode_Status:
break;
case OWS2FASettingsMode_SelectPIN:
case OWS2FASettingsMode_ConfirmPIN:
OWSAssert(![OWS2FAManager.sharedManager is2FAEnabled]);
break;
}
[super viewWillAppear:animated];
// If we're using a table, refresh its contents.
[self updateTableContents];
[self updateNavigationItems];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// If we're using a PIN textfield, select it.
[self.pinTextfield becomeFirstResponder];
}
- (UILabel *)createLabelWithText:(NSString *)text
{
UILabel *label = [UILabel new];
label.textColor = [UIColor blackColor];
label.text = text;
label.font = [UIFont ows_regularFontWithSize:ScaleFromIPhone5To7Plus(14.f, 16.f)];
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
return label;
}
- (void)createPinTextfield
{
self.pinTextfield = [UITextField new];
self.pinTextfield.textColor = [UIColor blackColor];
switch (self.mode) {
case OWS2FASettingsMode_SelectPIN:
self.pinTextfield.placeholder = NSLocalizedString(@"ENABLE_2FA_VIEW_SELECT_PIN_DEFAULT_TEXT",
@"Text field placeholder for 'two factor auth pin' when selecting a pin.");
break;
case OWS2FASettingsMode_ConfirmPIN:
self.pinTextfield.placeholder = NSLocalizedString(@"ENABLE_2FA_VIEW_CONFIRM_PIN_DEFAULT_TEXT",
@"Text field placeholder for 'two factor auth pin' when confirming a pin.");
break;
case OWS2FASettingsMode_Status:
OWSFail(@"%@ invalid mode.", self.logTag) break;
}
self.pinTextfield.font = [UIFont ows_mediumFontWithSize:ScaleFromIPhone5To7Plus(30.f, 36.f)];
self.pinTextfield.textAlignment = NSTextAlignmentCenter;
self.pinTextfield.keyboardType = UIKeyboardTypeNumberPad;
self.pinTextfield.delegate = self;
self.pinTextfield.secureTextEntry = YES;
self.pinTextfield.textAlignment = NSTextAlignmentCenter;
[self.pinTextfield addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
[self.view addSubview:self.pinTextfield];
}
- (void)createTableView
{
self.tableViewController = [OWSTableViewController new];
[self.view addSubview:self.tableViewController.view];
}
- (void)createStatusContents
{
const CGFloat kVSpacing = 30.f;
// TODO: Add hero image?
// TODO: Tweak background color?
NSString *instructions = ([OWS2FAManager.sharedManager is2FAEnabled]
? NSLocalizedString(@"ENABLE_2FA_VIEW_STATUS_ENABLED_INSTRUCTIONS",
@"Indicates that user has 'two factor auth pin' enabled.")
: NSLocalizedString(@"ENABLE_2FA_VIEW_STATUS_DISABLED_INSTRUCTIONS",
@"Indicates that user has 'two factor auth pin' disabled."));
UILabel *instructionsLabel = [self createLabelWithText:instructions];
[self createTableView];
[instructionsLabel autoPinToTopLayoutGuideOfViewController:self withInset:kVSpacing];
[instructionsLabel autoPinWidthToSuperviewWithMargin:self.hMargin];
[self.tableViewController.view autoPinWidthToSuperview];
[self.tableViewController.view autoPinEdge:ALEdgeTop
toEdge:ALEdgeBottom
ofView:instructionsLabel
withOffset:kVSpacing];
[self.tableViewController.view autoPinToBottomLayoutGuideOfViewController:self withInset:0];
[self updateTableContents];
}
- (void)createSelectCodeContents
{
[self createEnterPINContentsWithInstructions:NSLocalizedString(@"ENABLE_2FA_VIEW_SELECT_PIN_INSTRUCTIONS",
@"Indicates that user should select a 'two factor auth pin'.")];
}
- (void)createConfirmCodeContents
{
[self
createEnterPINContentsWithInstructions:NSLocalizedString(@"ENABLE_2FA_VIEW_CONFIRM_PIN_INSTRUCTIONS",
@"Indicates that user should confirm their 'two factor auth pin'.")];
}
- (CGFloat)hMargin
{
return 20.f;
}
- (void)createEnterPINContentsWithInstructions:(NSString *)instructionsText
{
const CGFloat kVSpacing = 30.f;
UILabel *instructionsLabel = [self createLabelWithText:instructionsText];
[self createPinTextfield];
[instructionsLabel autoPinTopToSuperviewWithMargin:kVSpacing];
[instructionsLabel autoPinWidthToSuperviewWithMargin:self.hMargin];
[self.pinTextfield autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:instructionsLabel withOffset:kVSpacing];
[self.pinTextfield autoPinWidthToSuperviewWithMargin:self.hMargin];
[self.pinTextfield autoHCenterInSuperview];
UIView *underscoreView = [UIView new];
underscoreView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:1.f];
[self.view addSubview:underscoreView];
[underscoreView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.pinTextfield withOffset:3];
[underscoreView autoPinWidthToSuperviewWithMargin:self.hMargin];
[underscoreView autoHCenterInSuperview];
[underscoreView autoSetDimension:ALDimensionHeight toSize:1.f];
[self updateNavigationItems];
}
- (void)updateTableContents
{
__weak OWS2FASettingsViewController *weakSelf = self;
// Only some modes use a table.
switch (self.mode) {
case OWS2FASettingsMode_Status: {
OWSTableContents *contents = [OWSTableContents new];
OWSTableSection *section = [OWSTableSection new];
if ([OWS2FAManager.sharedManager is2FAEnabled]) {
[section
addItem:[OWSTableItem disclosureItemWithText:
NSLocalizedString(@"ENABLE_2FA_VIEW_DISABLE_2FA",
@"Label for the 'enable two-factor auth' item in the settings view")
actionBlock:^{
[weakSelf tryToDisable2FA];
}]];
} else {
[section
addItem:[OWSTableItem disclosureItemWithText:
NSLocalizedString(@"ENABLE_2FA_VIEW_ENABLE_2FA",
@"Label for the 'enable two-factor auth' item in the settings view")
actionBlock:^{
[weakSelf showEnable2FAWorkUI];
}]];
}
[contents addSection:section];
self.tableViewController.contents = contents;
break;
}
case OWS2FASettingsMode_SelectPIN:
case OWS2FASettingsMode_ConfirmPIN:
return;
}
}
- (BOOL)shouldHaveNextButton
{
switch (self.mode) {
case OWS2FASettingsMode_Status:
return NO;
case OWS2FASettingsMode_SelectPIN:
case OWS2FASettingsMode_ConfirmPIN:
return [self hasValidPin];
}
}
- (void)updateNavigationItems
{
// Note: This affects how the "back" button will look if another
// view is pushed on top of this one, not how the "back"
// button looks when this view is visible.
self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"VERIFICATION_BACK_BUTTON",
@"button text for back button on verification view")
style:UIBarButtonItemStylePlain
target:self
action:@selector(backButtonWasPressed)];
if (self.shouldHaveNextButton) {
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(@"ENABLE_2FA_VIEW_NEXT_BUTTON",
@"Label for the 'next' button in the 'enable two factor auth' views.")
style:UIBarButtonItemStylePlain
target:self
action:@selector(nextButtonWasPressed)];
} else {
self.navigationItem.rightBarButtonItem = nil;
}
}
#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)insertionText
{
// TODO: ?
const NSUInteger kMaxPinLength = 14;
// * We only want to let the user enter decimal digits.
// * The user should be able to copy and paste freely.
// * Invalid input should be simply ignored.
//
// We accomplish this by being permissive and trying to "take as much of the user
// input as possible".
//
// * Always accept deletes.
// * Ignore invalid input.
// * Take partial input if possible.
NSString *oldText = textField.text;
// Construct the new contents of the text field by:
// 1. Determining the "left" substring: the contents of the old text _before_ the deletion range.
// Filtering will remove non-decimal digit characters.
NSString *left = [oldText substringToIndex:range.location].digitsOnly;
// 2. Determining the "right" substring: the contents of the old text _after_ the deletion range.
NSString *right = [oldText substringFromIndex:range.location + range.length].digitsOnly;
// 3. Determining the "center" substring: the contents of the new insertion text.
NSString *center = insertionText.digitsOnly;
// 4. Construct the "raw" new text by concatenating left, center and right.
NSString *textAfterChange = [[left stringByAppendingString:center] stringByAppendingString:right];
// 5. Ensure we don't exceed the maximum length for a PIN.
if (textAfterChange.length > kMaxPinLength) {
textAfterChange = [textAfterChange substringToIndex:kMaxPinLength];
}
// 6. Construct the final text.
textField.text = textAfterChange;
NSUInteger cursorPositionAfterChange = MIN(left.length + center.length, textAfterChange.length);
UITextPosition *pos =
[textField positionFromPosition:textField.beginningOfDocument offset:(NSInteger)cursorPositionAfterChange];
[textField setSelectedTextRange:[textField textRangeFromPosition:pos toPosition:pos]];
[self updateNavigationItems];
return NO;
}
- (void)textFieldDidChange:(id)sender
{
[self updateNavigationItems];
}
#pragma mark - Events
- (void)nextButtonWasPressed
{
switch (self.mode) {
case OWS2FASettingsMode_Status:
OWSFail(@"%@ status mode should not have a next button.", self.logTag);
return;
case OWS2FASettingsMode_SelectPIN: {
OWSAssert(self.hasValidPin);
OWS2FASettingsViewController *vc = [OWS2FASettingsViewController new];
vc.mode = OWS2FASettingsMode_ConfirmPIN;
vc.candidatePin = self.pinTextfield.text;
OWSAssert(self.root2FAViewController);
vc.root2FAViewController = self.root2FAViewController;
[self.navigationController pushViewController:vc animated:YES];
break;
}
case OWS2FASettingsMode_ConfirmPIN: {
OWSAssert(self.hasValidPin);
if ([self.pinTextfield.text isEqualToString:self.candidatePin]) {
[self tryToEnable2FA];
} else {
// Clear the PIN so that the user can try again.
self.pinTextfield.text = nil;
[OWSAlerts
showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")
message:NSLocalizedString(@"ENABLE_2FA_VIEW_PIN_DOES_NOT_MATCH",
@"Error indicating that the entered 'two-factor auth PINs' do not match.")];
}
break;
}
}
}
- (BOOL)hasValidPin
{
const NSUInteger kMinPinLength = 4;
return self.pinTextfield.text.length >= kMinPinLength;
}
- (void)showEnable2FAWorkUI
{
OWSAssert(![OWS2FAManager.sharedManager is2FAEnabled]);
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
OWS2FASettingsViewController *vc = [OWS2FASettingsViewController new];
vc.mode = OWS2FASettingsMode_SelectPIN;
vc.root2FAViewController = self;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)tryToDisable2FA
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
__weak OWS2FASettingsViewController *weakSelf = self;
[ModalActivityIndicatorViewController
presentFromViewController:self
canCancel:NO
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
[OWS2FAManager.sharedManager disable2FAWithSuccess:^{
[modalActivityIndicator dismissWithCompletion:^{
// TODO: Should we show an alert?
[weakSelf updateTableContents];
}];
}
failure:^(NSError *error) {
[modalActivityIndicator dismissWithCompletion:^{
[weakSelf updateTableContents];
[OWSAlerts
showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")
message:NSLocalizedString(@"ENABLE_2FA_VIEW_COULD_NOT_DISABLE_2FA",
@"Error indicating that attempt to disable 'two-factor "
@"auth' failed.")];
}];
}];
}];
}
- (void)tryToEnable2FA
{
OWSAssert(self.candidatePin.length > 0);
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
__weak OWS2FASettingsViewController *weakSelf = self;
[ModalActivityIndicatorViewController
presentFromViewController:self
canCancel:NO
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
[OWS2FAManager.sharedManager enable2FAWithPin:self.candidatePin
success:^{
[modalActivityIndicator dismissWithCompletion:^{
[weakSelf showCompleteUI];
}];
}
failure:^(NSError *error) {
[modalActivityIndicator dismissWithCompletion:^{
// The client may have fallen out of sync with the service.
// Try to get back to a known good state by disabling 2FA
// whenever enabling it fails.
[OWS2FAManager.sharedManager disable2FAWithSuccess:nil failure:nil];
[weakSelf updateTableContents];
[OWSAlerts
showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")
message:NSLocalizedString(@"ENABLE_2FA_VIEW_COULD_NOT_ENABLE_2FA",
@"Error indicating that attempt to enable 'two-factor "
@"auth' failed.")];
}];
}];
}];
}
- (void)showCompleteUI
{
OWSAssert([OWS2FAManager.sharedManager is2FAEnabled]);
OWSAssert(self.root2FAViewController);
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[self.navigationController popToViewController:self.root2FAViewController animated:NO];
}
- (void)backButtonWasPressed
{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)stateDidChange:(NSNotification *)notification
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
if (self.mode == OWS2FASettingsMode_Status) {
[self createContents];
}
}
@end
NS_ASSUME_NONNULL_END

@ -1,9 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSQRCodeScanningViewController.h"
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -1,9 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <SignalMessaging/OWSViewController.h>
#import <UIKit/UIKit.h>
#import <ZXingObjC/ZXingObjC.h>

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSQRCodeScanningViewController.h"
@ -149,16 +149,6 @@ NS_ASSUME_NONNULL_BEGIN
}
}
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.logTag;
}
@end
NS_ASSUME_NONNULL_END

@ -1,9 +1,13 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSTableViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface PrivacySettingsTableViewController : OWSTableViewController
@end
NS_ASSUME_NONNULL_END

@ -4,9 +4,11 @@
#import "PrivacySettingsTableViewController.h"
#import "BlockListViewController.h"
#import "OWS2FASettingsViewController.h"
#import "Signal-Swift.h"
#import <SignalMessaging/Environment.h>
#import <SignalMessaging/OWSPreferences.h>
#import <SignalServiceKit/OWS2FAManager.h>
#import <SignalServiceKit/OWSReadReceiptManager.h>
NS_ASSUME_NONNULL_BEGIN
@ -120,6 +122,25 @@ NS_ASSUME_NONNULL_BEGIN
}]];
[contents addSection:historyLogsSection];
OWSTableSection *twoFactorAuthSection = [OWSTableSection new];
twoFactorAuthSection.headerTitle = NSLocalizedString(
@"SETTINGS_TWO_FACTOR_AUTH_TITLE", @"Title for the 'two factor auth' section of the privacy settings.");
[twoFactorAuthSection
addItem:
[OWSTableItem
disclosureItemWithText:NSLocalizedString(@"SETTINGS_TWO_FACTOR_AUTH_ITEM",
@"Label for the 'two factor auth' item of the privacy settings.")
detailText:
([OWS2FAManager.sharedManager is2FAEnabled]
? NSLocalizedString(@"SETTINGS_TWO_FACTOR_AUTH_ENABLED",
@"Indicates that 'two factor auth' is enabled in the privacy settings.")
: NSLocalizedString(@"SETTINGS_TWO_FACTOR_AUTH_DISABLED",
@"Indicates that 'two factor auth' is disabled in the privacy settings."))
actionBlock:^{
[weakSelf show2FASettings];
}]];
[contents addSection:twoFactorAuthSection];
self.contents = contents;
}
@ -131,7 +152,6 @@ NS_ASSUME_NONNULL_BEGIN
[self.navigationController pushViewController:vc animated:YES];
}
- (void)clearHistoryLogs
{
UIAlertController *alertController =
@ -214,16 +234,13 @@ NS_ASSUME_NONNULL_BEGIN
[SignalApp.sharedApp.callService createCallUIAdapter];
}
#pragma mark - Log util
+ (NSString *)tag
- (void)show2FASettings
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
- (NSString *)tag
{
return self.class.logTag;
OWS2FASettingsViewController *vc = [OWS2FASettingsViewController new];
vc.mode = OWS2FASettingsMode_Status;
[self.navigationController pushViewController:vc animated:YES];
}
@end

@ -1,12 +1,14 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN
@class HomeViewController;
@interface ProfileViewController : UIViewController
@interface ProfileViewController : OWSViewController
- (instancetype)init NS_UNAVAILABLE;

@ -1,8 +1,8 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -1,9 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSConversationSettingsViewDelegate.h"
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -484,14 +484,4 @@ NSString *const PushManagerUserInfoKeysCallBackSignalRecipientId = @"PushManager
});
}
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.logTag;
}
@end

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSBezierPathView.h"
@ -93,13 +93,6 @@ NS_ASSUME_NONNULL_BEGIN
[self setNeedsDisplay];
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
@end
NS_ASSUME_NONNULL_END

@ -643,6 +643,45 @@
/* No comment provided by engineer. */
"EMPTY_INBOX_TITLE" = "Squeaky Freaking Clean.";
/* Text field placeholder for 'two factor auth pin' when confirming a pin. */
"ENABLE_2FA_VIEW_CONFIRM_PIN_DEFAULT_TEXT" = "••••••";
/* Indicates that user should confirm their 'two factor auth pin'. */
"ENABLE_2FA_VIEW_CONFIRM_PIN_INSTRUCTIONS" = "Confirm your PIN.";
/* Error indicating that attempt to disable 'two-factor auth' failed. */
"ENABLE_2FA_VIEW_COULD_NOT_DISABLE_2FA" = "Could not disable two-step verification.";
/* Error indicating that attempt to enable 'two-factor auth' failed. */
"ENABLE_2FA_VIEW_COULD_NOT_ENABLE_2FA" = "Could not enable two-step verification.";
/* Label for the 'enable two-factor auth' item in the settings view */
"ENABLE_2FA_VIEW_DISABLE_2FA" = "Disable";
/* Label for the 'enable two-factor auth' item in the settings view */
"ENABLE_2FA_VIEW_ENABLE_2FA" = "Enable";
/* Label for the 'next' button in the 'enable two factor auth' views. */
"ENABLE_2FA_VIEW_NEXT_BUTTON" = "Next";
/* Error indicating that the entered 'two-factor auth PINs' do not match. */
"ENABLE_2FA_VIEW_PIN_DOES_NOT_MATCH" = "Pin does not match.";
/* Text field placeholder for 'two factor auth pin' when selecting a pin. */
"ENABLE_2FA_VIEW_SELECT_PIN_DEFAULT_TEXT" = "******";
/* Indicates that user should select a 'two factor auth pin'. */
"ENABLE_2FA_VIEW_SELECT_PIN_INSTRUCTIONS" = "Enter a PIN which you'll be asked for when you register your phone number with Signal. Your PIN must have at least 4 digits.";
/* Indicates that user has 'two factor auth pin' disabled. */
"ENABLE_2FA_VIEW_STATUS_DISABLED_INSTRUCTIONS" = "For added security, enable two-step verification, which will require a PIN when registering your phone number with Signal again.";
/* Indicates that user has 'two factor auth pin' enabled. */
"ENABLE_2FA_VIEW_STATUS_ENABLED_INSTRUCTIONS" = "Two-step verification is enabled. You'll need to enter your PIN when registering your phone number with Signal again.";
/* Title for the 'enable two factor auth PIN' views. */
"ENABLE_2FA_VIEW_TITLE" = "Two-Step Verification";
/* Call setup status label */
"END_CALL_RESPONDER_IS_BUSY" = "Busy.";
@ -1623,6 +1662,18 @@
/* No comment provided by engineer. */
"SETTINGS_SUPPORT" = "Support";
/* Indicates that 'two factor auth' is disabled in the privacy settings. */
"SETTINGS_TWO_FACTOR_AUTH_DISABLED" = "Disabled";
/* Indicates that 'two factor auth' is enabled in the privacy settings. */
"SETTINGS_TWO_FACTOR_AUTH_ENABLED" = "Enabled";
/* Label for the 'two factor auth' item of the privacy settings. */
"SETTINGS_TWO_FACTOR_AUTH_ITEM" = "Two-Step Verification";
/* Title for the 'two factor auth' section of the privacy settings. */
"SETTINGS_TWO_FACTOR_AUTH_TITLE" = "Two-Step Verification";
/* No comment provided by engineer. */
"SETTINGS_VERSION" = "Version";

@ -2,7 +2,7 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN
@ -44,11 +44,6 @@ extern const CGFloat kOWSTable_DefaultCellHeight;
#pragma mark -
typedef NS_ENUM(NSInteger, OWSTableItemType) {
OWSTableItemTypeDefault,
OWSTableItemTypeAction,
};
typedef void (^OWSTableActionBlock)(void);
typedef void (^OWSTableSubPageBlock)(UIViewController *viewController);
typedef UITableViewCell *_Nonnull (^OWSTableCustomCellBlock)(void);
@ -72,6 +67,10 @@ typedef UITableViewCell *_Nonnull (^OWSTableCustomCellBlock)(void);
+ (OWSTableItem *)disclosureItemWithText:(NSString *)text actionBlock:(nullable OWSTableActionBlock)actionBlock;
+ (OWSTableItem *)disclosureItemWithText:(NSString *)text
detailText:(NSString *)detailText
actionBlock:(nullable OWSTableActionBlock)actionBlock;
+ (OWSTableItem *)disclosureItemWithText:(NSString *)text
customRowHeight:(CGFloat)customRowHeight
actionBlock:(nullable OWSTableActionBlock)actionBlock;

@ -83,7 +83,6 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
@interface OWSTableItem ()
@property (nonatomic) OWSTableItemType itemType;
@property (nonatomic, nullable) NSString *title;
@property (nonatomic, nullable) OWSTableActionBlock actionBlock;
@ -102,7 +101,6 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
OWSAssert(title.length > 0);
OWSTableItem *item = [OWSTableItem new];
item.itemType = OWSTableItemTypeAction;
item.actionBlock = actionBlock;
item.title = title;
return item;
@ -116,7 +114,6 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
OWSAssert(customRowHeight > 0);
OWSTableItem *item = [OWSTableItem new];
item.itemType = (actionBlock != nil ? OWSTableItemTypeAction : OWSTableItemTypeDefault);
item.actionBlock = actionBlock;
item.customCell = customCell;
item.customRowHeight = @(customRowHeight);
@ -140,7 +137,6 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
OWSAssert(customCellBlock);
OWSTableItem *item = [OWSTableItem new];
item.itemType = (actionBlock != nil ? OWSTableItemTypeAction : OWSTableItemTypeDefault);
item.actionBlock = actionBlock;
item.customCellBlock = customCellBlock;
return item;
@ -164,7 +160,6 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
OWSAssert(actionBlock);
OWSTableItem *item = [OWSTableItem new];
item.itemType = OWSTableItemTypeAction;
item.actionBlock = actionBlock;
item.customCellBlock = ^{
UITableViewCell *cell = [UITableViewCell new];
@ -188,13 +183,34 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
return item;
}
+ (OWSTableItem *)disclosureItemWithText:(NSString *)text
detailText:(NSString *)detailText
actionBlock:(nullable OWSTableActionBlock)actionBlock
{
OWSAssert(text.length > 0);
OWSAssert(actionBlock);
OWSTableItem *item = [OWSTableItem new];
item.actionBlock = actionBlock;
item.customCellBlock = ^{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:@"UITableViewCellStyleValue1"];
cell.textLabel.text = text;
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
cell.textLabel.textColor = [UIColor blackColor];
cell.detailTextLabel.text = detailText;
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
};
return item;
}
+ (OWSTableItem *)subPageItemWithText:(NSString *)text actionBlock:(nullable OWSTableSubPageBlock)actionBlock
{
OWSAssert(text.length > 0);
OWSAssert(actionBlock);
OWSTableItem *item = [OWSTableItem new];
item.itemType = OWSTableItemTypeAction;
__weak OWSTableItem *weakItem = item;
item.actionBlock = ^{
OWSTableItem *strongItem = weakItem;
@ -233,7 +249,6 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
OWSAssert(actionBlock);
OWSTableItem *item = [OWSTableItem new];
item.itemType = OWSTableItemTypeAction;
item.actionBlock = actionBlock;
item.customCellBlock = ^{
UITableViewCell *cell = [UITableViewCell new];
@ -250,7 +265,6 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
OWSAssert(text.length > 0);
OWSTableItem *item = [OWSTableItem new];
item.itemType = OWSTableItemTypeAction;
item.customCellBlock = ^{
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = text;
@ -282,7 +296,6 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
OWSAssert(text.length > 0);
OWSTableItem *item = [OWSTableItem new];
item.itemType = OWSTableItemTypeAction;
item.customCellBlock = ^{
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = text;
@ -300,7 +313,6 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
OWSAssert(accessoryText.length > 0);
OWSTableItem *item = [OWSTableItem new];
item.itemType = OWSTableItemTypeAction;
item.customCellBlock = ^{
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = text;
@ -337,7 +349,6 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
OWSAssert(selector);
OWSTableItem *item = [OWSTableItem new];
item.itemType = OWSTableItemTypeAction;
__weak id weakTarget = target;
item.customCellBlock = ^{
UITableViewCell *cell = [UITableViewCell new];

@ -1,9 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import "UIView+OWS.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -2,7 +2,7 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
NS_ASSUME_NONNULL_BEGIN

@ -1,8 +1,8 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSViewController.h"
#import <SignalMessaging/OWSViewController.h>
@class TSThread;

@ -381,23 +381,11 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste
- (void)unsetRecordedAPNSTokens
{
DDLogWarn(@"%@ Forgetting recorded APNS tokens", self.tag);
DDLogWarn(@"%@ Forgetting recorded APNS tokens", self.logTag);
[self setValueForKey:OWSPreferencesKeyLastRecordedPushToken toValue:nil];
[self setValueForKey:OWSPreferencesKeyLastRecordedVoipToken toValue:nil];
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end
NS_ASSUME_NONNULL_END

@ -215,18 +215,6 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
[storage asyncRegisterExtension:[self databaseExtension] withName:OWSMessageContentJobFinderExtensionName];
}
#pragma mark Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.logTag;
}
@end
#pragma mark - Queue Processing
@ -365,18 +353,6 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
}];
}
#pragma mark Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.logTag;
}
@end
#pragma mark - OWSBatchMessageProcessor

@ -339,18 +339,6 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
}];
}
#pragma mark Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.logTag;
}
@end
#pragma mark - OWSMessageReceiver

@ -1,4 +1,6 @@
// Copyright (c) 2016 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSDeviceProvisioningRequest.h"
#import "TSConstants.h"
@ -17,7 +19,10 @@ NS_ASSUME_NONNULL_BEGIN
}
self.HTTPMethod = @"PUT";
[self.parameters addEntriesFromDictionary:@{ @"body" : [messageBody base64EncodedString] }];
self.parameters = @{
@"body" : [messageBody base64EncodedString],
};
return self;
}

@ -0,0 +1,19 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@class TSRequest;
@interface OWSRequestFactory : NSObject
- (instancetype)init NS_UNAVAILABLE;
+ (TSRequest *)enable2FARequestWithPin:(NSString *)pin;
+ (TSRequest *)disable2FARequest;
@end
NS_ASSUME_NONNULL_END

@ -0,0 +1,31 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSRequestFactory.h"
#import "TSConstants.h"
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@implementation OWSRequestFactory
+ (TSRequest *)enable2FARequestWithPin:(NSString *)pin;
{
OWSAssert(pin.length > 0);
return [TSRequest requestWithUrl:[NSURL URLWithString:textSecure2FAAPI]
method:@"PUT"
parameters:@{
@"pin" : pin,
}];
}
+ (TSRequest *)disable2FARequest
{
return [TSRequest requestWithUrl:[NSURL URLWithString:textSecure2FAAPI] method:@"DELETE" parameters:@{}];
}
@end
NS_ASSUME_NONNULL_END

@ -1,14 +1,9 @@
//
// TSContactsIntersection.m
// TextSecureiOS
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
// Created by Frederic Jacobs on 10/12/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
//
#import "TSConstants.h"
#import "TSContactsIntersectionRequest.h"
#import "TSConstants.h"
@implementation TSContactsIntersectionRequest
@ -16,9 +11,15 @@
self = [self
initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", textSecureDirectoryAPI, @"tokens"]]];
if (!self) {
return nil;
}
self.HTTPMethod = @"PUT";
[self.parameters addEntriesFromDictionary:@{ @"contacts" : hashes }];
self.parameters = @{
@"contacts" : hashes,
};
return self;
}

@ -1,23 +1,21 @@
//
// TSGetRecipientPrekey.m
// TextSecureiOS
//
// Created by Christine Corbett Moran on 11/30/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSConstants.h"
#import "TSRecipientPrekeyRequest.h"
#import "TSConstants.h"
@implementation TSRecipientPrekeyRequest
- (TSRequest *)initWithRecipient:(NSString *)recipientNumber deviceId:(NSString *)deviceId {
NSString *recipientInformation = recipientNumber;
self = [super
initWithURL:[NSURL
URLWithString:[NSString
stringWithFormat:@"%@/%@/%@", textSecureKeysAPI, recipientNumber, deviceId]]];
self = [super initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@/%@",
textSecureKeysAPI,
recipientInformation,
deviceId]]];
if (!self) {
return nil;
}
self.HTTPMethod = @"GET";
self.parameters = nil;

@ -1,15 +1,15 @@
//
// TSRegisterForPushRequest.h
// TextSecureiOS
//
// Created by Frederic Jacobs on 10/13/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface TSRegisterForPushRequest : TSRequest
- (id)initWithPushIdentifier:(NSString *)identifier voipIdentifier:(NSString *)voipId;
@end
NS_ASSUME_NONNULL_END

@ -1,14 +1,11 @@
//
// TSRegisterForPushRequest.m
// TextSecureiOS
//
// Created by Frederic Jacobs on 10/13/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSRegisterForPushRequest.h"
#import "TSConstants.h"
#import "TSRegisterForPushRequest.h"
NS_ASSUME_NONNULL_BEGIN
@implementation TSRegisterForPushRequest
@ -16,15 +13,21 @@
self =
[super initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", textSecureAccountsAPI, @"apn"]]];
self.HTTPMethod = @"PUT";
if (!self) {
return nil;
}
self.parameters = [@{ @"apnRegistrationId" : identifier } mutableCopy];
self.HTTPMethod = @"PUT";
if (voipId) {
[self.parameters setObject:voipId forKeyedSubscript:@"voipRegistrationId"];
}
OWSAssert(voipId);
self.parameters = @{
@"apnRegistrationId" : identifier,
@"voipRegistrationId" : voipId ?: @"",
};
return self;
}
@end
NS_ASSUME_NONNULL_END

@ -1,14 +1,13 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSConstants.h"
#import "TSRegisterPrekeysRequest.h"
#import <Curve25519Kit/Curve25519.h>
#import "TSConstants.h"
#import <AxolotlKit/NSData+keyVersionByte.h>
#import <AxolotlKit/PreKeyRecord.h>
#import <AxolotlKit/SignedPreKeyStore.h>
#import <Curve25519Kit/Curve25519.h>
@implementation TSRegisterPrekeysRequest
@ -17,6 +16,10 @@
signedPreKeyRecord:(SignedPreKeyRecord *)signedRecord
preKeyLastResort:(PreKeyRecord *)lastResort {
self = [super initWithURL:[NSURL URLWithString:textSecureKeysAPI]];
if (!self) {
return nil;
}
self.HTTPMethod = @"PUT";
NSString *publicIdentityKey = [[identityKeyPublic prependKeyType] base64EncodedStringWithOptions:0];

@ -1,20 +1,23 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSRegisterSignedPrekeyRequest.h"
#import "TSConstants.h"
#import <Curve25519Kit/Curve25519.h>
#import <AxolotlKit/NSData+keyVersionByte.h>
#import <AxolotlKit/PreKeyRecord.h>
#import <AxolotlKit/SignedPreKeyStore.h>
#import <Curve25519Kit/Curve25519.h>
@implementation TSRegisterSignedPrekeyRequest
- (id)initWithSignedPreKeyRecord:(SignedPreKeyRecord *)signedRecord
{
self = [super initWithURL:[NSURL URLWithString:textSecureSignedKeysAPI]];
if (!self) {
return nil;
}
self.HTTPMethod = @"PUT";
NSDictionary *serializedKeyRegistrationParameters = [self dictionaryFromSignedPreKey:signedRecord];

@ -1,11 +1,13 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
@interface TSRequest : NSMutableURLRequest
@property (nonatomic, retain) NSMutableDictionary *parameters;
@property (nonatomic) NSDictionary *parameters;
- (void)makeAuthenticatedRequest;
+ (instancetype)requestWithUrl:(NSURL *)url
method:(NSString *)method
parameters:(NSDictionary<NSString *, id> *)parameters;
@end

@ -13,7 +13,11 @@
self = [super initWithURL:URL
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:textSecureHTTPTimeOut];
self.parameters = [NSMutableDictionary dictionary];
if (!self) {
return nil;
}
self.parameters = @{};
return self;
}
@ -33,11 +37,14 @@
return nil;
}
#pragma clang diagnostic pop
- (void)makeAuthenticatedRequest {
OWSAssert([TSAccountManager serverAuthToken]);
[self.parameters addEntriesFromDictionary:@{ @"Authorization" : [TSAccountManager serverAuthToken] }];
+ (instancetype)requestWithUrl:(NSURL *)url
method:(NSString *)method
parameters:(NSDictionary<NSString *, id> *)parameters
{
TSRequest *request = [[TSRequest alloc] initWithURL:url];
[request setHTTPMethod:method];
request.parameters = parameters;
return request;
}
@end

@ -12,6 +12,9 @@
textSecureAccountsAPI,
[self stringForTransport:transport],
phoneNumber]]];
if (!self) {
return nil;
}
self.parameters = nil;
[self setHTTPMethod:@"GET"];
@ -30,7 +33,4 @@
}
}
- (void)makeAuthenticatedRequest {
}
@end

@ -1,14 +1,9 @@
//
// TSSubmitMessageRequest.m
// TextSecureiOS
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
// Created by Christine Corbett Moran on 11/30/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
//
#import "TSConstants.h"
#import "TSSubmitMessageRequest.h"
#import "TSConstants.h"
@implementation TSSubmitMessageRequest
@ -18,17 +13,21 @@
timeStamp:(uint64_t)timeStamp {
self =
[super initWithURL:[NSURL URLWithString:[textSecureMessagesAPI stringByAppendingString:contactRegisteredID]]];
if (!self) {
return nil;
}
NSMutableDictionary *allMessages =
[@{ @"messages" : messages,
@"timestamp" : [NSNumber numberWithUnsignedLongLong:timeStamp] } mutableCopy];
NSMutableDictionary *parameters = [@{
@"messages" : messages,
@"timestamp" : @(timeStamp),
} mutableCopy];
if (relay) {
[allMessages setObject:relay forKey:@"relay"];
parameters[@"relay"] = relay;
}
[self setHTTPMethod:@"PUT"];
[self setParameters:allMessages];
self.parameters = parameters;
return self;
}

@ -1,10 +1,10 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSUpdateAttributesRequest.h"
#import "TSAttributes.h"
#import "TSConstants.h"
#import "TSUpdateAttributesRequest.h"
NS_ASSUME_NONNULL_BEGIN
@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
if (self) {
[self setHTTPMethod:@"PUT"];
[self.parameters addEntriesFromDictionary:[TSAttributes attributesFromStorageWithManualMessageFetching:enableManualMessageFetching]];
self.parameters = [TSAttributes attributesFromStorageWithManualMessageFetching:enableManualMessageFetching];
}
return self;

@ -1,11 +1,11 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSVerifyCodeRequest.h"
#import "TSAccountManager.h"
#import "TSAttributes.h"
#import "TSConstants.h"
#import "TSVerifyCodeRequest.h"
@implementation TSVerifyCodeRequest
@ -17,11 +17,10 @@
initWithURL:[NSURL URLWithString:[NSString
stringWithFormat:@"%@/code/%@", textSecureAccountsAPI, verificationCode]]];
NSDictionary *attributes =
[TSAttributes attributesWithSignalingKey:signalingKey serverAuthToken:authKey manualMessageFetching:NO];
_numberToValidate = phoneNumber;
[self.parameters addEntriesFromDictionary:attributes];
self.parameters =
[TSAttributes attributesWithSignalingKey:signalingKey serverAuthToken:authKey manualMessageFetching:NO];
[self setHTTPMethod:@"PUT"];

@ -98,8 +98,9 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
[sessionManager.requestSerializer
setAuthorizationHeaderFieldWithUsername:((TSVerifyCodeRequest *)request).numberToValidate
password:[request.parameters objectForKey:@"AuthKey"]];
[request.parameters removeObjectForKey:@"AuthKey"];
[sessionManager PUT:request.URL.absoluteString parameters:request.parameters success:success failure:failure];
NSMutableDictionary *parameters = [request.parameters mutableCopy];
[parameters removeObjectForKey:@"AuthKey"];
[sessionManager PUT:request.URL.absoluteString parameters:parameters success:success failure:failure];
} else {
if (![request isKindOfClass:[TSRequestVerificationCodeRequest class]]) {
[sessionManager.requestSerializer

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSFingerprint.h"
@ -309,16 +309,6 @@ static uint32_t const OWSFingerprintDefaultHashIterations = 5200;
return qrImage;
}
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.logTag;
}
@end
NS_ASSUME_NONNULL_END

@ -101,16 +101,4 @@
return lastPreKeyId;
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@+PreKeyStore]", self.class];
}
- (NSString *)tag
{
return self.class.logTag;
}
@end

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#ifndef TextSecureKit_Constants_h
@ -51,6 +51,7 @@ typedef NS_ENUM(NSInteger, TSWhisperMessageType) {
#define textSecureProfileAPIFormat @"v1/profile/%@"
#define textSecureSetProfileNameAPIFormat @"v1/profile/name/%@"
#define textSecureProfileAvatarFormAPI @"v1/profile/form/avatar"
#define textSecure2FAAPI @"/v1/accounts/pin"
#define SignalApplicationGroup @"group.org.whispersystems.signal.group"

@ -0,0 +1,29 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
extern NSString *const NSNotificationName_2FAStateDidChange;
typedef void (^OWS2FASuccess)(void);
typedef void (^OWS2FAFailure)(NSError *error);
// This class can be safely accessed and used from any thread.
@interface OWS2FAManager : NSObject
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)sharedManager;
- (BOOL)is2FAEnabled;
- (void)enable2FAWithPin:(NSString *)pin
success:(nullable OWS2FASuccess)success
failure:(nullable OWS2FAFailure)failure;
- (void)disable2FAWithSuccess:(nullable OWS2FASuccess)success failure:(nullable OWS2FAFailure)failure;
@end
NS_ASSUME_NONNULL_END

@ -0,0 +1,134 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWS2FAManager.h"
#import "NSNotificationCenter+OWS.h"
#import "OWSRequestFactory.h"
#import "TSNetworkManager.h"
#import "TSStorageManager.h"
#import "YapDatabaseConnection+OWS.h"
NS_ASSUME_NONNULL_BEGIN
NSString *const NSNotificationName_2FAStateDidChange = @"NSNotificationName_2FAStateDidChange";
NSString *const kOWS2FAManager_Collection = @"kOWS2FAManager_Collection";
NSString *const kOWS2FAManager_IsEnabledKey = @"kOWS2FAManager_IsEnabledKey";
@interface OWS2FAManager ()
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
@property (nonatomic, readonly) TSNetworkManager *networkManager;
@end
#pragma mark -
@implementation OWS2FAManager
+ (instancetype)sharedManager
{
static OWS2FAManager *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] initDefault];
});
return sharedMyManager;
}
- (instancetype)initDefault
{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
TSNetworkManager *networkManager = [TSNetworkManager sharedManager];
return [self initWithStorageManager:storageManager networkManager:networkManager];
}
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
networkManager:(TSNetworkManager *)networkManager
{
self = [super init];
if (!self) {
return self;
}
OWSAssert(storageManager);
OWSAssert(networkManager);
_dbConnection = storageManager.newDatabaseConnection;
_networkManager = networkManager;
OWSSingletonAssert();
return self;
}
- (BOOL)is2FAEnabled
{
return [self.dbConnection boolForKey:kOWS2FAManager_IsEnabledKey
inCollection:kOWS2FAManager_Collection
defaultValue:NO];
}
- (void)setIs2FAEnabled:(BOOL)value
{
[self.dbConnection setBool:value forKey:kOWS2FAManager_IsEnabledKey inCollection:kOWS2FAManager_Collection];
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:NSNotificationName_2FAStateDidChange
object:nil
userInfo:nil];
}
- (void)enable2FAWithPin:(NSString *)pin success:(nullable OWS2FASuccess)success failure:(nullable OWS2FAFailure)failure
{
OWSAssert(pin.length > 0);
OWSAssert(success);
OWSAssert(failure);
TSRequest *request = [OWSRequestFactory enable2FARequestWithPin:pin];
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
OWSAssertIsOnMainThread();
[self setIs2FAEnabled:YES];
if (success) {
success();
}
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
OWSAssertIsOnMainThread();
if (failure) {
failure(error);
}
}];
}
- (void)disable2FAWithSuccess:(nullable OWS2FASuccess)success failure:(nullable OWS2FAFailure)failure
{
TSRequest *request = [OWSRequestFactory disable2FARequest];
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
OWSAssertIsOnMainThread();
[self setIs2FAEnabled:NO];
if (success) {
success();
}
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
OWSAssertIsOnMainThread();
if (failure) {
failure(error);
}
}];
}
@end
NS_ASSUME_NONNULL_END
Loading…
Cancel
Save