2015-12-07 03:31:43 +01:00
|
|
|
//
|
2018-01-23 19:58:45 +01:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2015-12-07 03:31:43 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "TSConstants.h"
|
|
|
|
|
2016-11-03 21:10:06 +01:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2017-04-08 03:28:34 +02:00
|
|
|
extern NSString *const TSRegistrationErrorDomain;
|
|
|
|
extern NSString *const TSRegistrationErrorUserInfoHTTPStatus;
|
2017-12-04 18:38:44 +01:00
|
|
|
extern NSString *const RegistrationStateDidChangeNotification;
|
2018-06-15 18:45:11 +02:00
|
|
|
extern NSString *const DeregistrationStateDidChangeNotification;
|
2017-05-10 22:00:36 +02:00
|
|
|
extern NSString *const kNSNotificationName_LocalNumberDidChange;
|
2015-12-07 03:31:43 +01:00
|
|
|
|
2018-03-05 15:30:58 +01:00
|
|
|
@class OWSPrimaryStorage;
|
2016-11-03 21:10:06 +01:00
|
|
|
@class TSNetworkManager;
|
2018-01-23 19:58:45 +01:00
|
|
|
@class YapDatabaseReadWriteTransaction;
|
2015-12-07 03:31:43 +01:00
|
|
|
|
|
|
|
@interface TSAccountManager : NSObject
|
|
|
|
|
2018-06-18 17:10:09 +02:00
|
|
|
// This property is exposed for testing purposes only.
|
|
|
|
#ifdef DEBUG
|
|
|
|
@property (nonatomic, nullable) NSString *phoneNumberAwaitingVerification;
|
|
|
|
#endif
|
2018-05-30 21:28:03 +02:00
|
|
|
|
2016-12-18 22:08:26 +01:00
|
|
|
#pragma mark - Initializers
|
|
|
|
|
2017-04-01 00:45:46 +02:00
|
|
|
- (instancetype)init NS_UNAVAILABLE;
|
|
|
|
|
2016-11-03 21:10:06 +01:00
|
|
|
- (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager
|
2018-03-05 15:30:58 +01:00
|
|
|
primaryStorage:(OWSPrimaryStorage *)primaryStorage NS_DESIGNATED_INITIALIZER;
|
2016-11-03 21:10:06 +01:00
|
|
|
|
|
|
|
+ (instancetype)sharedInstance;
|
|
|
|
|
2016-12-18 22:08:26 +01:00
|
|
|
@property (nonatomic, strong, readonly) TSNetworkManager *networkManager;
|
|
|
|
|
2015-12-07 03:31:43 +01:00
|
|
|
/**
|
|
|
|
* Returns if a user is registered or not
|
|
|
|
*
|
|
|
|
* @return registered or not
|
|
|
|
*/
|
|
|
|
+ (BOOL)isRegistered;
|
2018-05-08 20:58:29 +02:00
|
|
|
- (BOOL)isRegistered;
|
2016-11-03 21:10:06 +01:00
|
|
|
|
2015-12-07 03:31:43 +01:00
|
|
|
/**
|
2017-01-03 22:32:53 +01:00
|
|
|
* Returns current phone number for this device, which may not yet have been registered.
|
2015-12-07 03:31:43 +01:00
|
|
|
*
|
|
|
|
* @return E164 formatted phone number
|
|
|
|
*/
|
2016-11-03 21:10:06 +01:00
|
|
|
+ (nullable NSString *)localNumber;
|
2017-08-02 21:15:31 +02:00
|
|
|
- (nullable NSString *)localNumber;
|
2015-12-07 03:31:43 +01:00
|
|
|
|
2017-10-10 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* Symmetric key that's used to encrypt message payloads from the server,
|
|
|
|
*
|
|
|
|
* @return signaling key
|
|
|
|
*/
|
|
|
|
+ (nullable NSString *)signalingKey;
|
|
|
|
- (nullable NSString *)signalingKey;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The server auth token allows the Signal client to connect to the Signal server
|
|
|
|
*
|
|
|
|
* @return server authentication token
|
|
|
|
*/
|
|
|
|
+ (nullable NSString *)serverAuthToken;
|
|
|
|
- (nullable NSString *)serverAuthToken;
|
|
|
|
|
2015-12-07 03:31:43 +01:00
|
|
|
/**
|
|
|
|
* The registration ID is unique to an installation of TextSecure, it allows to know if the app was reinstalled
|
|
|
|
*
|
|
|
|
* @return registrationID;
|
|
|
|
*/
|
|
|
|
|
|
|
|
+ (uint32_t)getOrGenerateRegistrationId;
|
2018-01-23 19:58:45 +01:00
|
|
|
+ (uint32_t)getOrGenerateRegistrationId:(YapDatabaseReadWriteTransaction *)transaction;
|
2015-12-07 03:31:43 +01:00
|
|
|
|
|
|
|
#pragma mark - Register with phone number
|
|
|
|
|
|
|
|
+ (void)registerWithPhoneNumber:(NSString *)phoneNumber
|
2017-11-08 20:04:51 +01:00
|
|
|
success:(void (^)(void))successBlock
|
2016-11-03 21:10:06 +01:00
|
|
|
failure:(void (^)(NSError *error))failureBlock
|
2015-12-07 03:31:43 +01:00
|
|
|
smsVerification:(BOOL)isSMS;
|
|
|
|
|
2017-11-08 20:04:51 +01:00
|
|
|
+ (void)rerequestSMSWithSuccess:(void (^)(void))successBlock failure:(void (^)(NSError *error))failureBlock;
|
2015-12-07 03:31:43 +01:00
|
|
|
|
2017-11-08 20:04:51 +01:00
|
|
|
+ (void)rerequestVoiceWithSuccess:(void (^)(void))successBlock failure:(void (^)(NSError *error))failureBlock;
|
2015-12-07 03:31:43 +01:00
|
|
|
|
2016-11-03 21:10:06 +01:00
|
|
|
- (void)verifyAccountWithCode:(NSString *)verificationCode
|
2018-03-01 20:42:54 +01:00
|
|
|
pin:(nullable NSString *)pin
|
2017-11-08 20:04:51 +01:00
|
|
|
success:(void (^)(void))successBlock
|
2016-11-03 21:10:06 +01:00
|
|
|
failure:(void (^)(NSError *error))failureBlock;
|
2015-12-07 03:31:43 +01:00
|
|
|
|
Rework push registration
== Account Registration ==
Not complete until push tokens are uploaded
== Remote Notifications Registration ==
Extracted from PushManager
- wait for notification-settings registration to complete before
requesting push tokens, otherwise it's possible token requests will
be ignored.
- Less state required for push notification callbacks, specifically, we
no longer need to ensure we've created a promise before the
registration delegate methods get called.
- no more TOCFuture in Signal-iOS (still in SSK for now). It's not in
cases of inexplicable behavior - one a recently, push notification
premature free, in redphone, and more popular use, and I've seen two
futures inexplicably being nil. Instead, let's consolidate around
PromiseKit for popularly used, maintained, strongly-typed futures.
- separate logic for registering for vanilla push/voip notifications
(few dependencies) from responding to UILocalNotifications (lots of
dependencies). Ultimately I'd like to consolidate the remaining
UILocalNotifications logic with the existing NotificationsManager
== Misc ==
more debug logging
more uniform logging
remove stale logic around newly registered user
// FREEBIE
2017-09-20 23:47:12 +02:00
|
|
|
// Called once registration is complete - meaning the following have succeeded:
|
|
|
|
// - obtained signal server credentials
|
|
|
|
// - uploaded pre-keys
|
|
|
|
// - uploaded push tokens
|
|
|
|
- (void)didRegister;
|
|
|
|
|
2015-12-07 03:31:43 +01:00
|
|
|
#if TARGET_OS_IPHONE
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register's the device's push notification token with the server
|
|
|
|
*
|
|
|
|
* @param pushToken Apple's Push Token
|
|
|
|
*/
|
2016-11-03 21:10:06 +01:00
|
|
|
- (void)registerForPushNotificationsWithPushToken:(NSString *)pushToken
|
|
|
|
voipToken:(NSString *)voipToken
|
2017-11-08 20:04:51 +01:00
|
|
|
success:(void (^)(void))successHandler
|
2016-11-03 21:10:06 +01:00
|
|
|
failure:(void (^)(NSError *error))failureHandler
|
2017-11-08 20:25:21 +01:00
|
|
|
NS_SWIFT_NAME(registerForPushNotifications(pushToken:voipToken:success:failure:));
|
2015-12-07 03:31:43 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-11-08 20:04:51 +01:00
|
|
|
+ (void)unregisterTextSecureWithSuccess:(void (^)(void))success failure:(void (^)(NSError *error))failureBlock;
|
2015-12-07 03:31:43 +01:00
|
|
|
|
2018-06-18 16:54:06 +02:00
|
|
|
#pragma mark - De-Registration
|
2018-06-15 18:45:11 +02:00
|
|
|
|
2018-06-18 17:10:09 +02:00
|
|
|
// De-registration reflects whether or not the "last known contact"
|
|
|
|
// with the service was:
|
|
|
|
//
|
|
|
|
// * A 403 from the service, indicating de-registration.
|
|
|
|
// * A successful auth'd request _or_ websocket connection indicating
|
|
|
|
// valid registration.
|
2018-06-15 18:45:11 +02:00
|
|
|
- (BOOL)isDeregistered;
|
|
|
|
- (void)setIsDeregistered:(BOOL)isDeregistered;
|
|
|
|
|
2018-06-18 16:54:06 +02:00
|
|
|
#pragma mark - Re-registration
|
|
|
|
|
|
|
|
// Re-registration is the process of re-registering _with the same phone number_.
|
|
|
|
|
|
|
|
// Returns YES on success.
|
|
|
|
- (BOOL)resetForReregistration;
|
|
|
|
- (NSString *)reregisterationPhoneNumber;
|
|
|
|
- (BOOL)isReregistering;
|
|
|
|
|
2018-10-01 22:08:11 +02:00
|
|
|
#pragma mark - Manual Message Fetch
|
|
|
|
|
|
|
|
- (BOOL)isManualMessageFetchEnabled;
|
|
|
|
- (void)setIsManualMessageFetchEnabled:(BOOL)value;
|
|
|
|
|
2015-12-07 03:31:43 +01:00
|
|
|
@end
|
2016-11-03 21:10:06 +01:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|