Fix registration.
This commit is contained in:
parent
736d0c421d
commit
63260ee94d
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
@ -13,11 +13,19 @@ import SignalServiceKit
|
|||
@objc
|
||||
public class AccountManager: NSObject {
|
||||
|
||||
// MARK: - Dependencies
|
||||
|
||||
var pushManager: PushManager {
|
||||
// dependency injection hack since PushManager has *alot* of dependencies, and would induce a cycle.
|
||||
return PushManager.shared()
|
||||
}
|
||||
|
||||
var profileManager: OWSProfileManager {
|
||||
return OWSProfileManager.shared()
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
@objc
|
||||
public override init() {
|
||||
super.init()
|
||||
|
@ -58,22 +66,20 @@ public class AccountManager: NSObject {
|
|||
Logger.debug("registering with signal server")
|
||||
let registrationPromise: Promise<Void> = firstly {
|
||||
return self.registerForTextSecure(verificationCode: verificationCode, pin: pin)
|
||||
}.then {
|
||||
return self.syncPushTokens()
|
||||
}.recover { (error) -> Promise<Void> in
|
||||
switch error {
|
||||
case PushRegistrationError.pushNotSupported(let description):
|
||||
// This can happen with:
|
||||
// - simulators, none of which support receiving push notifications
|
||||
// - on iOS11 devices which have disabled "Allow Notifications" and disabled "Enable Background Refresh" in the system settings.
|
||||
Logger.info("Recovered push registration error. Registering for manual message fetcher because push not supported: \(description)")
|
||||
return self.enableManualMessageFetching()
|
||||
default:
|
||||
throw error
|
||||
}.then { _ -> Promise<Void> in
|
||||
return self.syncPushTokens().recover { (error) -> Promise<Void> in
|
||||
switch error {
|
||||
case PushRegistrationError.pushNotSupported(let description):
|
||||
// This can happen with:
|
||||
// - simulators, none of which support receiving push notifications
|
||||
// - on iOS11 devices which have disabled "Allow Notifications" and disabled "Enable Background Refresh" in the system settings.
|
||||
Logger.info("Recovered push registration error. Registering for manual message fetcher because push not supported: \(description)")
|
||||
return self.enableManualMessageFetching()
|
||||
default:
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}.then { (_) in
|
||||
self.tsAccountManager.performUpdateAccountAttributes()
|
||||
}.done { (_) in
|
||||
}.done { (_) -> Void in
|
||||
self.completeRegistration()
|
||||
}
|
||||
|
||||
|
@ -86,9 +92,9 @@ public class AccountManager: NSObject {
|
|||
pin: String?) -> Promise<Void> {
|
||||
return Promise { resolver in
|
||||
tsAccountManager.verifyAccount(withCode: verificationCode,
|
||||
pin: pin,
|
||||
success: resolver.fulfill,
|
||||
failure: resolver.reject)
|
||||
pin: pin,
|
||||
success: resolver.fulfill,
|
||||
failure: resolver.reject)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
@ -8,7 +8,7 @@ import SignalMessaging
|
|||
|
||||
class DebugUIProfile: DebugUIPage {
|
||||
|
||||
// MARK: Dependencies
|
||||
// MARK: - Dependencies
|
||||
|
||||
var messageSender: MessageSender {
|
||||
return SSKEnvironment.shared.messageSender
|
||||
|
@ -17,7 +17,7 @@ class DebugUIProfile: DebugUIPage {
|
|||
return OWSProfileManager.shared()
|
||||
}
|
||||
|
||||
// MARK: Overrides
|
||||
// MARK: - Overrides
|
||||
|
||||
override func name() -> String {
|
||||
return "Profile"
|
||||
|
|
|
@ -398,8 +398,32 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
case 200:
|
||||
case 204: {
|
||||
OWSLogInfo(@"Verification code accepted.");
|
||||
[TSPreKeyManager createPreKeysWithSuccess:successBlock failure:failureBlock];
|
||||
[self.profileManager fetchLocalUsersProfile];
|
||||
|
||||
[self storeServerAuthToken:authToken];
|
||||
|
||||
[[[SignalServiceRestClient new] updateAccountAttributesObjC]
|
||||
.thenInBackground(^{
|
||||
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
|
||||
[TSPreKeyManager
|
||||
createPreKeysWithSuccess:^{
|
||||
resolve(@(1));
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
resolve(error);
|
||||
}];
|
||||
}];
|
||||
})
|
||||
.then(^{
|
||||
[self.profileManager fetchLocalUsersProfile];
|
||||
})
|
||||
.then(^{
|
||||
successBlock();
|
||||
})
|
||||
.catchInBackground(^(NSError *error) {
|
||||
OWSLogError(@"Error: %@", error);
|
||||
failureBlock(error);
|
||||
}) retainUntilComplete];
|
||||
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSPreKeyManager.h"
|
||||
|
@ -13,6 +13,8 @@
|
|||
#import <SignalCoreKit/NSDate+OWS.h>
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// Time before deletion of signed prekeys (measured in seconds)
|
||||
#define kSignedPreKeysDeletionTime (7 * kDayInterval)
|
||||
|
||||
|
@ -107,12 +109,10 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
|
|||
|
||||
+ (void)checkPreKeysIfNecessary
|
||||
{
|
||||
if (!CurrentAppContext().isMainApp) {
|
||||
if (!CurrentAppContext().isMainAppAndActive) {
|
||||
return;
|
||||
}
|
||||
OWSAssertDebug(CurrentAppContext().isMainAppAndActive);
|
||||
|
||||
if (!self.tsAccountManager.isRegistered) {
|
||||
if (!self.tsAccountManager.isRegisteredAndReady) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -156,6 +156,8 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
|
|||
|
||||
+ (void)createPreKeysWithSuccess:(void (^)(void))successHandler failure:(void (^)(NSError *error))failureHandler
|
||||
{
|
||||
OWSAssertDebug(!self.tsAccountManager.isRegisteredAndReady);
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
SSKCreatePreKeysOperation *operation = [SSKCreatePreKeysOperation new];
|
||||
[self.operationQueue addOperations:@[ operation ] waitUntilFinished:YES];
|
||||
|
@ -175,6 +177,8 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
|
|||
|
||||
+ (void)rotateSignedPreKeyWithSuccess:(void (^)(void))successHandler failure:(void (^)(NSError *error))failureHandler
|
||||
{
|
||||
OWSAssertDebug(!self.tsAccountManager.isRegisteredAndReady);
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
SSKRotateSignedPreKeyOperation *operation = [SSKRotateSignedPreKeyOperation new];
|
||||
[self.operationQueue addOperations:@[ operation ] waitUntilFinished:YES];
|
||||
|
@ -197,6 +201,9 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
|
|||
if (!CurrentAppContext().isMainApp) {
|
||||
return;
|
||||
}
|
||||
if (!self.tsAccountManager.isRegisteredAndReady) {
|
||||
return;
|
||||
}
|
||||
|
||||
SSKRefreshPreKeysOperation *operation = [SSKRefreshPreKeysOperation new];
|
||||
[self.operationQueue addOperation:operation];
|
||||
|
@ -292,3 +299,5 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -1252,11 +1252,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
void (^handle404)(void) = ^{
|
||||
OWSLogWarn(@"Unregistered recipient: %@", recipient.uniqueId);
|
||||
|
||||
TSThread *_Nullable thread = messageSend.thread;
|
||||
OWSAssertDebug(thread);
|
||||
|
||||
dispatch_async([OWSDispatch sendingQueue], ^{
|
||||
[self unregisteredRecipient:recipient message:message thread:thread];
|
||||
if (![messageSend.message isKindOfClass:[OWSOutgoingSyncMessage class]]) {
|
||||
TSThread *_Nullable thread = messageSend.thread;
|
||||
OWSAssertDebug(thread);
|
||||
[self unregisteredRecipient:recipient message:message thread:thread];
|
||||
}
|
||||
|
||||
NSError *error = OWSErrorMakeNoSuchSignalRecipientError();
|
||||
// No need to retry if the recipient is not registered.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
@ -155,6 +155,10 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
|
|||
func registrationStateDidChange() {
|
||||
AssertIsOnMainThread()
|
||||
|
||||
guard tsAccountManager.isRegisteredAndReady() else {
|
||||
return
|
||||
}
|
||||
|
||||
// Any error is silently ignored
|
||||
ensureSenderCertificate(certificateExpirationPolicy: .strict).retainUntilComplete()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSNetworkManager.h"
|
||||
|
@ -37,10 +37,19 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
|
|||
|
||||
@implementation TSNetworkManager
|
||||
|
||||
#pragma mark - Dependencies
|
||||
|
||||
+ (TSAccountManager *)tsAccountManager
|
||||
{
|
||||
return TSAccountManager.sharedInstance;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@synthesize udSessionManager = _udSessionManager;
|
||||
@synthesize udSerialQueue = _udSerialQueue;
|
||||
|
||||
#pragma mark Singleton implementation
|
||||
#pragma mark - Singleton
|
||||
|
||||
+ (instancetype)sharedManager
|
||||
{
|
||||
|
@ -108,7 +117,7 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
|
|||
OWSLogInfo(@"Non-UD request succeeded : %@", request);
|
||||
|
||||
if (request.shouldHaveAuthorizationHeaders) {
|
||||
[TSAccountManager.sharedInstance setIsDeregistered:NO];
|
||||
[TSNetworkManager.tsAccountManager setIsDeregistered:NO];
|
||||
}
|
||||
|
||||
successBlock(task, responseObject);
|
||||
|
@ -406,7 +415,12 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
|
|||
// * etc.
|
||||
if ([task.originalRequest.URL.absoluteString hasPrefix:textSecureServerURL]
|
||||
&& request.shouldHaveAuthorizationHeaders) {
|
||||
[TSAccountManager.sharedInstance setIsDeregistered:YES];
|
||||
if (self.tsAccountManager.isRegisteredAndReady) {
|
||||
[self.tsAccountManager setIsDeregistered:YES];
|
||||
} else {
|
||||
OWSFailDebug(
|
||||
@"Ignoring auth failure; not registered and ready: %@.", task.originalRequest.URL.absoluteString);
|
||||
}
|
||||
} else {
|
||||
OWSLogWarn(@"Ignoring %d for URL: %@", (int)statusCode, task.originalRequest.URL.absoluteString);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSWebSocket.h"
|
||||
|
@ -639,7 +639,11 @@ NSString *const kNSNotification_OWSWebSocketStateDidChange = @"kNSNotification_O
|
|||
if (responseStatus == 403) {
|
||||
// This should be redundant with our check for the socket
|
||||
// failing due to 403, but let's be thorough.
|
||||
[self.tsAccountManager setIsDeregistered:YES];
|
||||
if (self.tsAccountManager.isRegisteredAndReady) {
|
||||
[self.tsAccountManager setIsDeregistered:YES];
|
||||
} else {
|
||||
OWSFailDebug(@"Ignoring auth failure; not registered and ready.");
|
||||
}
|
||||
}
|
||||
|
||||
NSError *error = OWSErrorWithCodeDescription(OWSErrorCodeMessageResponseFailed,
|
||||
|
@ -705,7 +709,11 @@ NSString *const kNSNotification_OWSWebSocketStateDidChange = @"kNSNotification_O
|
|||
if ([error.domain isEqualToString:SRWebSocketErrorDomain] && error.code == 2132) {
|
||||
NSNumber *_Nullable statusCode = error.userInfo[SRHTTPResponseErrorKey];
|
||||
if (statusCode.unsignedIntegerValue == 403) {
|
||||
[self.tsAccountManager setIsDeregistered:YES];
|
||||
if (self.tsAccountManager.isRegisteredAndReady) {
|
||||
[self.tsAccountManager setIsDeregistered:YES];
|
||||
} else {
|
||||
OWSFailDebug(@"Ignoring auth failure; not registered and ready.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -932,7 +940,7 @@ NSString *const kNSNotification_OWSWebSocketStateDidChange = @"kNSNotification_O
|
|||
return NO;
|
||||
}
|
||||
|
||||
if (![self.tsAccountManager isRegistered]) {
|
||||
if (![self.tsAccountManager isRegisteredAndReady]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue