Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent a697072271
commit f2a9c10c20

@ -71,4 +71,9 @@ public class OWSMessageSend: NSObject {
self.localNumber = localNumber self.localNumber = localNumber
self.isLocalNumber = isLocalNumber self.isLocalNumber = isLocalNumber
} }
@objc
public var isUDSend: Bool {
return (!hasUDAuthFailed && udAccessKey != nil && senderCertificate != nil)
}
} }

@ -737,7 +737,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
} }
- (nullable NSArray<NSDictionary *> *)deviceMessagesForMessageSendSafe:(OWSMessageSend *)messageSend - (nullable NSArray<NSDictionary *> *)deviceMessagesForMessageSendSafe:(OWSMessageSend *)messageSend
isUDSend:(BOOL)isUDSend
error:(NSError **)errorHandle error:(NSError **)errorHandle
{ {
OWSAssertDebug(messageSend); OWSAssertDebug(messageSend);
@ -748,7 +747,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSArray<NSDictionary *> *deviceMessages; NSArray<NSDictionary *> *deviceMessages;
@try { @try {
deviceMessages = [self deviceMessagesForMessageSendUnsafe:messageSend isUDSend:isUDSend]; deviceMessages = [self deviceMessagesForMessageSendUnsafe:messageSend];
} @catch (NSException *exception) { } @catch (NSException *exception) {
if ([exception.name isEqualToString:UntrustedIdentityKeyException]) { if ([exception.name isEqualToString:UntrustedIdentityKeyException]) {
// This *can* happen under normal usage, but it should happen relatively rarely. // This *can* happen under normal usage, but it should happen relatively rarely.
@ -884,17 +883,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// Consume an attempt. // Consume an attempt.
messageSend.remainingAttempts = messageSend.remainingAttempts - 1; messageSend.remainingAttempts = messageSend.remainingAttempts - 1;
BOOL isUDSend
= (!messageSend.hasUDAuthFailed && messageSend.udAccessKey != nil && messageSend.senderCertificate != nil);
OWSLogVerbose(@"isUDSend: %d, hasUDAuthFailed: %d, udAccessKey: %d, senderCertificate: %d",
isUDSend,
messageSend.hasUDAuthFailed,
messageSend.udAccessKey != nil,
messageSend.senderCertificate != nil);
NSError *deviceMessagesError; NSError *deviceMessagesError;
NSArray<NSDictionary *> *_Nullable deviceMessages = NSArray<NSDictionary *> *_Nullable deviceMessages =
[self deviceMessagesForMessageSendSafe:messageSend isUDSend:isUDSend error:&deviceMessagesError]; [self deviceMessagesForMessageSendSafe:messageSend error:&deviceMessagesError];
if (deviceMessagesError || !deviceMessages) { if (deviceMessagesError || !deviceMessages) {
OWSAssertDebug(deviceMessagesError); OWSAssertDebug(deviceMessagesError);
return failureHandler(deviceMessagesError); return failureHandler(deviceMessagesError);
@ -971,13 +962,13 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
messages:deviceMessages messages:deviceMessages
timeStamp:message.timestamp]; timeStamp:message.timestamp];
if (isUDSend) { if (messageSend.isUDSend) {
DDLogVerbose(@"UD send."); DDLogVerbose(@"UD send.");
[request useUDAuth:messageSend.udAccessKey]; [request useUDAuth:messageSend.udAccessKey];
} }
// TODO: UD sends over websocket. // TODO: UD sends over websocket.
if (!messageSend.hasWebsocketSendFailed && TSSocketManager.canMakeRequests && !isUDSend) { if (!messageSend.hasWebsocketSendFailed && TSSocketManager.canMakeRequests && !messageSend.isUDSend) {
[TSSocketManager.sharedManager makeRequest:request [TSSocketManager.sharedManager makeRequest:request
success:^(id _Nullable responseObject) { success:^(id _Nullable responseObject) {
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages success:successHandler]; [self messageSendDidSucceed:messageSend deviceMessages:deviceMessages success:successHandler];
@ -1003,7 +994,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSInteger statusCode = response.statusCode; NSInteger statusCode = response.statusCode;
NSData *_Nullable responseData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey]; NSData *_Nullable responseData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
if (isUDSend && (statusCode == 401 || statusCode == 403)) { if (messageSend.isUDSend && (statusCode == 401 || statusCode == 403)) {
// If a UD send fails due to service response (as opposed to network // If a UD send fails due to service response (as opposed to network
// failure), mark recipient as _not_ in UD mode, then retry. // failure), mark recipient as _not_ in UD mode, then retry.
// //
@ -1286,7 +1277,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
} }
// NOTE: This method uses exceptions for control flow. // NOTE: This method uses exceptions for control flow.
- (NSArray<NSDictionary *> *)deviceMessagesForMessageSendUnsafe:(OWSMessageSend *)messageSend isUDSend:(BOOL)isUDSend - (NSArray<NSDictionary *> *)deviceMessagesForMessageSendUnsafe:(OWSMessageSend *)messageSend
{ {
OWSAssertDebug(messageSend.message); OWSAssertDebug(messageSend.message);
OWSAssertDebug(messageSend.recipient); OWSAssertDebug(messageSend.recipient);
@ -1312,7 +1303,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
messageDict = [self encryptedMessageForMessageSend:messageSend messageDict = [self encryptedMessageForMessageSend:messageSend
deviceId:deviceNumber deviceId:deviceNumber
plainText:plainText plainText:plainText
isUDSend:isUDSend
transaction:transaction]; transaction:transaction];
} @catch (NSException *exception) { } @catch (NSException *exception) {
encryptionException = exception; encryptionException = exception;
@ -1346,7 +1336,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// NOTE: This method uses exceptions for control flow. // NOTE: This method uses exceptions for control flow.
- (void)ensureRecipientHasSessionForMessageSend:(OWSMessageSend *)messageSend - (void)ensureRecipientHasSessionForMessageSend:(OWSMessageSend *)messageSend
deviceId:(NSNumber *)deviceId deviceId:(NSNumber *)deviceId
isUDSend:(BOOL)isUDSend
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssertDebug(messageSend); OWSAssertDebug(messageSend);
@ -1369,7 +1358,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
TSRequest *request = TSRequest *request =
[OWSRequestFactory recipientPrekeyRequestWithRecipient:recipientId deviceId:[deviceId stringValue]]; [OWSRequestFactory recipientPrekeyRequestWithRecipient:recipientId deviceId:[deviceId stringValue]];
if (isUDSend) { if (messageSend.isUDSend) {
DDLogVerbose(@"UD prekey request."); DDLogVerbose(@"UD prekey request.");
[request useUDAuth:messageSend.udAccessKey]; [request useUDAuth:messageSend.udAccessKey];
} }
@ -1434,7 +1423,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
- (NSDictionary *)encryptedMessageForMessageSend:(OWSMessageSend *)messageSend - (NSDictionary *)encryptedMessageForMessageSend:(OWSMessageSend *)messageSend
deviceId:(NSNumber *)deviceId deviceId:(NSNumber *)deviceId
plainText:(NSData *)plainText plainText:(NSData *)plainText
isUDSend:(BOOL)isUDSend
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssertDebug(messageSend); OWSAssertDebug(messageSend);
@ -1451,7 +1439,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// This may throw an exception. // This may throw an exception.
[self ensureRecipientHasSessionForMessageSend:messageSend [self ensureRecipientHasSessionForMessageSend:messageSend
deviceId:deviceId deviceId:deviceId
isUDSend:isUDSend
transaction:transaction]; transaction:transaction];
SessionCipher *cipher = [[SessionCipher alloc] initWithSessionStore:storage SessionCipher *cipher = [[SessionCipher alloc] initWithSessionStore:storage
@ -1463,7 +1450,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSData *_Nullable serializedMessage; NSData *_Nullable serializedMessage;
TSWhisperMessageType messageType; TSWhisperMessageType messageType;
if (isUDSend) { if (messageSend.isUDSend) {
NSError *error; NSError *error;
SMKSecretSessionCipher *_Nullable secretCipher = SMKSecretSessionCipher *_Nullable secretCipher =
[[SMKSecretSessionCipher alloc] initWithSessionStore:self.primaryStorage [[SMKSecretSessionCipher alloc] initWithSessionStore:self.primaryStorage

@ -223,9 +223,13 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
@objc @objc
public func trustRoot() -> ECPublicKey { public func trustRoot() -> ECPublicKey {
let trustRootData: Data = NSData(fromBase64String: kUDTrustRoot) as Data guard let trustRootData = NSData(fromBase64String: kUDTrustRoot) else {
// This exits.
owsFail("Invalid trust root data.")
}
do { do {
return try ECPublicKey(serializedKeyData: trustRootData) return try ECPublicKey(serializedKeyData: trustRootData as Data)
} catch { } catch {
// This exits. // This exits.
owsFail("Invalid trust root.") owsFail("Invalid trust root.")

Loading…
Cancel
Save