Merge branch 'charlesmchen/accountAttributesVsPin'

pull/1/head
Matthew Chen 7 years ago
commit 09d561823b

@ -1,16 +1,17 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@interface TSAttributes : NSObject
+ (NSDictionary *)attributesFromStorageWithManualMessageFetching:(BOOL)isEnabled;
+ (NSDictionary *)attributesFromStorageWithManualMessageFetching:(BOOL)isEnabled pin:(nullable NSString *)pin;
+ (NSDictionary *)attributesWithSignalingKey:(NSString *)signalingKey
serverAuthToken:(NSString *)authToken
manualMessageFetching:(BOOL)isEnabled;
manualMessageFetching:(BOOL)isEnabled
pin:(nullable NSString *)pin;
@end

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSAttributes.h"
@ -9,28 +9,35 @@ NS_ASSUME_NONNULL_BEGIN
@implementation TSAttributes
+ (NSDictionary *)attributesFromStorageWithManualMessageFetching:(BOOL)isEnabled
+ (NSDictionary *)attributesFromStorageWithManualMessageFetching:(BOOL)isEnabled pin:(nullable NSString *)pin
{
return [self attributesWithSignalingKey:TSAccountManager.signalingKey
serverAuthToken:TSAccountManager.serverAuthToken
manualMessageFetching:isEnabled];
manualMessageFetching:isEnabled
pin:pin];
}
+ (NSDictionary *)attributesWithSignalingKey:(NSString *)signalingKey
serverAuthToken:(NSString *)authToken
manualMessageFetching:(BOOL)isEnabled
pin:(nullable NSString *)pin
{
OWSAssert(signalingKey.length > 0);
OWSAssert(authToken.length > 0);
return @{
NSMutableDictionary *result = [@{
@"signalingKey" : signalingKey,
@"AuthKey" : authToken,
@"voice" : @(YES), // all Signal-iOS clients support voice
@"video" : @(YES), // all Signal-iOS clients support WebRTC-based voice and video calls.
@"fetchesMessages" : @(isEnabled), // devices that don't support push must tell the server they fetch messages manually
@"fetchesMessages" :
@(isEnabled), // devices that don't support push must tell the server they fetch messages manually
@"registrationId" : [NSString stringWithFormat:@"%i", [TSAccountManager getOrGenerateRegistrationId]]
};
} mutableCopy];
if (pin.length > 0) {
result[@"pin"] = pin;
}
return [result copy];
}
@end

@ -3,13 +3,14 @@
//
#import "OWSRequestFactory.h"
#import "NSData+Base64.h"
#import "OWS2FAManager.h"
#import "OWSDevice.h"
#import "TSAttributes.h"
#import "TSConstants.h"
#import "TSRequest.h"
#import <AxolotlKit/NSData+keyVersionByte.h>
#import <AxolotlKit/SignedPreKeyRecord.h>
#import <SignalServiceKit/NSData+Base64.h>
NS_ASSUME_NONNULL_BEGIN
@ -171,10 +172,12 @@ NS_ASSUME_NONNULL_BEGIN
+ (TSRequest *)updateAttributesRequestWithManualMessageFetching:(BOOL)enableManualMessageFetching
{
NSString *path = [textSecureAccountsAPI stringByAppendingString:textSecureAttributesAPI];
NSString *_Nullable pin = [OWS2FAManager.sharedManager pinCode];
return [TSRequest
requestWithUrl:[NSURL URLWithString:path]
method:@"PUT"
parameters:[TSAttributes attributesFromStorageWithManualMessageFetching:enableManualMessageFetching]];
parameters:[TSAttributes attributesFromStorageWithManualMessageFetching:enableManualMessageFetching
pin:pin]];
}
+ (TSRequest *)unregisterAccountRequest

@ -24,13 +24,8 @@ NS_ASSUME_NONNULL_BEGIN
NSURL *url =
[NSURL URLWithString:[NSString stringWithFormat:@"%@/code/%@", textSecureAccountsAPI, verificationCode]];
NSMutableDictionary *parameters =
[[TSAttributes attributesWithSignalingKey:signalingKey serverAuthToken:authKey manualMessageFetching:NO]
mutableCopy];
if (pin) {
OWSAssert(pin.length > 0);
parameters[@"pin"] = pin;
}
NSDictionary *parameters =
[TSAttributes attributesWithSignalingKey:signalingKey serverAuthToken:authKey manualMessageFetching:NO pin:pin];
self = [super initWithURL:url method:@"PUT" parameters:parameters];
_numberToValidate = phoneNumber;

@ -14,7 +14,6 @@ NS_ASSUME_NONNULL_BEGIN
NSString *const NSNotificationName_2FAStateDidChange = @"NSNotificationName_2FAStateDidChange";
NSString *const kOWS2FAManager_Collection = @"kOWS2FAManager_Collection";
NSString *const kOWS2FAManager_IsEnabledKey = @"kOWS2FAManager_IsEnabledKey";
NSString *const kOWS2FAManager_LastSuccessfulReminderDateKey = @"kOWS2FAManager_LastSuccessfulReminderDateKey";
NSString *const kOWS2FAManager_PinCode = @"kOWS2FAManager_PinCode";
NSString *const kOWS2FAManager_RepetitionInterval = @"kOWS2FAManager_RepetitionInterval";
@ -71,16 +70,19 @@ const NSUInteger kDaySecs = kHourSecs * 24;
return self;
}
- (nullable NSString *)pinCode
{
return [self.dbConnection objectForKey:kOWS2FAManager_PinCode inCollection:kOWS2FAManager_Collection];
}
- (BOOL)is2FAEnabled
{
return [self.dbConnection boolForKey:kOWS2FAManager_IsEnabledKey
inCollection:kOWS2FAManager_Collection
defaultValue:NO];
return self.pinCode != nil;
}
- (void)setIs2FAEnabled:(BOOL)value
- (void)set2FANotEnabled
{
[self.dbConnection setBool:value forKey:kOWS2FAManager_IsEnabledKey inCollection:kOWS2FAManager_Collection];
[self.dbConnection removeObjectForKey:kOWS2FAManager_PinCode inCollection:kOWS2FAManager_Collection];
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:NSNotificationName_2FAStateDidChange
object:nil
@ -89,8 +91,13 @@ const NSUInteger kDaySecs = kHourSecs * 24;
- (void)mark2FAAsEnabledWithPin:(NSString *)pin
{
[self setIs2FAEnabled:YES];
[self storePinCode:pin];
OWSAssert(pin.length > 0);
[self.dbConnection setObject:pin forKey:kOWS2FAManager_PinCode inCollection:kOWS2FAManager_Collection];
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:NSNotificationName_2FAStateDidChange
object:nil
userInfo:nil];
}
- (void)requestEnable2FAWithPin:(NSString *)pin
@ -107,6 +114,7 @@ const NSUInteger kDaySecs = kHourSecs * 24;
OWSAssertIsOnMainThread();
[self mark2FAAsEnabledWithPin:pin];
if (success) {
success();
}
@ -127,7 +135,7 @@ const NSUInteger kDaySecs = kHourSecs * 24;
success:^(NSURLSessionDataTask *task, id responseObject) {
OWSAssertIsOnMainThread();
[self setIs2FAEnabled:NO];
[self set2FANotEnabled];
if (success) {
success();
@ -145,16 +153,6 @@ const NSUInteger kDaySecs = kHourSecs * 24;
#pragma mark - Reminders
- (void)storePinCode:(nullable NSString *)pinCode
{
[self.dbConnection setObject:pinCode forKey:kOWS2FAManager_PinCode inCollection:kOWS2FAManager_Collection];
}
- (nullable NSString *)pinCode
{
return [self.dbConnection objectForKey:kOWS2FAManager_PinCode inCollection:kOWS2FAManager_Collection];
}
- (nullable NSDate *)lastSuccessfulReminderDate
{
return [self.dbConnection dateForKey:kOWS2FAManager_LastSuccessfulReminderDateKey

Loading…
Cancel
Save