Merge branch 'charlesmchen/udFixes'

This commit is contained in:
Matthew Chen 2018-10-11 13:01:01 -04:00
commit d8a0baf9ee
6 changed files with 64 additions and 7 deletions

View File

@ -945,12 +945,32 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
//
// If _both_ of these pieces of state agree that there are no linked
// devices, then can safely skip sending sync message.
//
// NOTE: Sync messages sent via UD include the local device.
// 1. Check OWSDevice's state.
BOOL mayHaveLinkedDevices = [OWSDeviceManager.sharedManager mayHaveLinkedDevices:self.dbConnection];
// 2. Check SignalRecipient's state.
BOOL hasDeviceMessages = deviceMessages.count > 0;
BOOL hasDeviceMessages = NO;
for (NSDictionary<NSString *, id> *deviceMessage in deviceMessages) {
NSString *_Nullable destination = deviceMessage[@"destination"];
if (!destination) {
OWSFailDebug(@"Sync device message missing destination: %@", deviceMessage);
continue;
}
if (![destination isEqualToString:messageSend.localNumber]) {
OWSFailDebug(@"Sync device message has invalid destination: %@", deviceMessage);
continue;
}
NSNumber *_Nullable destinationDeviceId = deviceMessage[@"destinationDeviceId"];
if (!destinationDeviceId) {
OWSFailDebug(@"Sync device message missing destination device id: %@", deviceMessage);
continue;
}
if (destinationDeviceId.intValue != OWSDevicePrimaryDeviceId) {
hasDeviceMessages = YES;
break;
}
}
OWSLogInfo(@"mayHaveLinkedDevices: %d, hasDeviceMessages: %d", mayHaveLinkedDevices, hasDeviceMessages);

View File

@ -26,6 +26,8 @@ public enum UnidentifiedAccessMode: Int {
@objc func trustRoot() -> ECPublicKey
@objc func isUDEnabled() -> Bool
// MARK: - Recipient State
@objc
@ -173,6 +175,9 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
// if we have a valid profile key for them.
@objc
public func udAccessKeyForRecipient(_ recipientId: RecipientIdentifier) -> SMKUDAccessKey? {
guard isUDEnabled() else {
return nil
}
let theirAccessMode = unidentifiedAccessMode(recipientId: recipientId)
if theirAccessMode == .unrestricted {
return SMKUDAccessKey(randomKeyData: ())
@ -281,6 +286,11 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
}
}
@objc
public func isUDEnabled() -> Bool {
return !IsUsingProductionService()
}
@objc
public func trustRoot() -> ECPublicKey {
guard let trustRootData = NSData(fromBase64String: kUDTrustRoot) else {

View File

@ -264,6 +264,10 @@ NSString *const kNSNotification_OWSWebSocketStateDidChange = @"kNSNotification_O
return OWSWebsocketSecurityPolicy.sharedPolicy;
}
- (id<OWSUDManager>)udManager {
return SSKEnvironment.shared.udManager;
}
#pragma mark -
// We want to observe these notifications lazily to avoid accessing
@ -1024,6 +1028,11 @@ NSString *const kNSNotification_OWSWebSocketStateDidChange = @"kNSNotification_O
}
#endif
if (!self.udManager.isUDEnabled && self.webSocketType == OWSWebSocketTypeUD) {
OWSLogWarn(@"Suppressing UD socket in prod.");
return;
}
if (!AppReadiness.isAppReady) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{

View File

@ -37,10 +37,11 @@ typedef NS_ENUM(NSInteger, TSWhisperMessageType) {
//#define contactDiscoveryURL @"https://api.directory.signal.org"
//// TODO: The production value is not yet known.
//#define kUDTrustRoot @"BbqY1DzohE4NUZoVF+L18oUPrK3kILllLEJh2UnPSsEx"
//#define USING_PRODUCTION_SERVICE
//#else
//
//// Staging
// Staging
#define textSecureWebSocketAPI @"wss://textsecure-service-staging.whispersystems.org/v1/websocket/"
#define textSecureServerURL @"https://textsecure-service-staging.whispersystems.org/"
#define textSecureCDNServerURL @"https://cdn-staging.signal.org"
@ -48,9 +49,11 @@ typedef NS_ENUM(NSInteger, TSWhisperMessageType) {
#define textSecureCDNReflectorHost @"meek-signal-cdn-staging.appspot.com";
#define contactDiscoveryURL @"https://api-staging.directory.signal.org"
#define kUDTrustRoot @"BbqY1DzohE4NUZoVF+L18oUPrK3kILllLEJh2UnPSsEx"
//
//#endif
BOOL IsUsingProductionService(void);
#define textSecureAccountsAPI @"v1/accounts"
#define textSecureAttributesAPI @"/attributes/"

View File

@ -0,0 +1,14 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSConstants.h"
BOOL IsUsingProductionService()
{
#ifdef USING_PRODUCTION_SERVICE
return YES;
#else
return NO;
#endif
}

View File

@ -12,6 +12,7 @@ static const NSUInteger ddLogLevel = DDLogLevelAll;
static const NSUInteger ddLogLevel = DDLogLevelInfo;
#endif
#import "OWSAnalytics.h"
#import "SSKAsserts.h"
#import "TSConstants.h"
#import <SignalCoreKit/NSObject+OWS.h>
#import <SignalCoreKit/OWSAsserts.h>
#import "SSKAsserts.h"