Only enable UD if UD is supported by all linked devices.

pull/1/head
Matthew Chen 7 years ago
parent bdf6ba15d2
commit 64aa43edb1

@ -166,7 +166,7 @@ public class ProfileFetcherJob: NSObject {
return return
} }
guard let verifier = verifier, let udAccessKey = udManager.udAccessKeyForRecipient(recipientId) else { guard let verifier = verifier, let udAccessKey = udManager.rawUDAccessKeyForRecipient(recipientId) else {
udManager.setUnidentifiedAccessMode(.disabled, recipientId: recipientId) udManager.setUnidentifiedAccessMode(.disabled, recipientId: recipientId)
return return
} }

@ -36,9 +36,17 @@ public enum UnidentifiedAccessMode: Int {
@objc @objc
func getAccess(forRecipientId recipientId: RecipientIdentifier) -> SSKUnidentifiedAccessPair? func getAccess(forRecipientId recipientId: RecipientIdentifier) -> SSKUnidentifiedAccessPair?
// Returns the UD access key for a given recipient if they are // Returns the UD access key for a given recipient if:
// a UD recipient and we have a valid profile key for them. //
@objc func udAccessKeyForRecipient(_ recipientId: RecipientIdentifier) -> SMKUDAccessKey? // * UD is enabled.
// * Their UD mode is enabled or unrestricted.
// * We have a valid profile key for them.
@objc func enabledUDAccessKeyForRecipient(_ recipientId: RecipientIdentifier) -> SMKUDAccessKey?
// Returns the UD access key for a given recipient if:
//
// * We have a valid profile key for them.
@objc func rawUDAccessKeyForRecipient(_ recipientId: RecipientIdentifier) -> SMKUDAccessKey?
// MARK: - Local State // MARK: - Local State
@ -122,24 +130,24 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
return nil return nil
} }
guard let theirAccessKey = self.udAccessKeyForRecipient(recipientId) else { guard let theirAccessKey = enabledUDAccessKeyForRecipient(recipientId) else {
return nil return nil
} }
guard let ourSenderCertificate = self.senderCertificate() else { guard let ourSenderCertificate = senderCertificate() else {
return nil return nil
} }
guard let ourAccessKey: SMKUDAccessKey = { guard let ourAccessKey: SMKUDAccessKey = {
if self.shouldAllowUnrestrictedAccessLocal() { if shouldAllowUnrestrictedAccessLocal() {
return SMKUDAccessKey(randomKeyData: ()) return SMKUDAccessKey(randomKeyData: ())
} else { } else {
guard let localNumber = self.tsAccountManager.localNumber() else { guard let localNumber = tsAccountManager.localNumber() else {
owsFailDebug("localNumber was unexpectedly nil") owsFailDebug("localNumber was unexpectedly nil")
return nil return nil
} }
return self.udAccessKeyForRecipient(localNumber) return enabledUDAccessKeyForRecipient(localNumber)
} }
}() else { }() else {
return nil return nil
@ -170,7 +178,7 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
// Returns the UD access key for a given recipient // Returns the UD access key for a given recipient
// if we have a valid profile key for them. // if we have a valid profile key for them.
@objc @objc
public func udAccessKeyForRecipient(_ recipientId: RecipientIdentifier) -> SMKUDAccessKey? { public func enabledUDAccessKeyForRecipient(_ recipientId: RecipientIdentifier) -> SMKUDAccessKey? {
guard isUDEnabled() else { guard isUDEnabled() else {
return nil return nil
} }
@ -178,7 +186,13 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
if theirAccessMode == .unrestricted { if theirAccessMode == .unrestricted {
return SMKUDAccessKey(randomKeyData: ()) return SMKUDAccessKey(randomKeyData: ())
} }
return rawUDAccessKeyForRecipient(recipientId)
}
// Returns the UD access key for a given recipient
// if we have a valid profile key for them.
@objc
public func rawUDAccessKeyForRecipient(_ recipientId: RecipientIdentifier) -> SMKUDAccessKey? {
guard let profileKey = profileManager.profileKeyData(forRecipientId: recipientId) else { guard let profileKey = profileManager.profileKeyData(forRecipientId: recipientId) else {
// Mark as "not a UD recipient". // Mark as "not a UD recipient".
return nil return nil
@ -291,7 +305,13 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
@objc @objc
public func isUDEnabled() -> Bool { public func isUDEnabled() -> Bool {
return true // Only enable UD if UD is supported by all linked devices,
// so that sync messages can also be sent via UD.
guard let localNumber = tsAccountManager.localNumber() else {
return false
}
let ourAccessMode = unidentifiedAccessMode(recipientId: localNumber)
return ourAccessMode == .enabled || ourAccessMode == .unrestricted
} }
@objc @objc

Loading…
Cancel
Save