Skip to content

Commit

Permalink
Fix some OTR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisballinger committed Mar 12, 2016
1 parent deb2482 commit ecd51ae
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
15 changes: 11 additions & 4 deletions ChatSecure/Classes/Controllers/OTREncryptionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ - (void) otrKit:(OTRKit*)otrKit

- (void) otrKit:(OTRKit *)otrKit handleMessageEvent:(OTRKitMessageEvent)event message:(NSString *)message username:(NSString *)username accountName:(NSString *)accountName protocol:(NSString *)protocol tag:(id)tag error:(NSError *)error {
//incoming and outgoing errors and other events
DDLogWarn(@"Message Event: %d Error:%@",(int)event,[OTREncryptionManager errorForMessageEvent:event].localizedDescription);
DDLogWarn(@"Message Event: %d Error:%@",(int)event,[OTREncryptionManager errorForMessageEvent:event string:nil].localizedDescription);

if ([tag isKindOfClass:[OTRMessage class]]) {
__block NSError *error = nil;
Expand All @@ -325,7 +325,7 @@ - (void) otrKit:(OTRKit *)otrKit handleMessageEvent:(OTRKitMessageEvent)event me
case OTRKitMessageEventReceivedMessageMalformed:
case OTRKitMessageEventReceivedMessageGeneralError:
case OTRKitMessageEventReceivedMessageUnrecognized:
error = [OTREncryptionManager errorForMessageEvent:event];
error = [OTREncryptionManager errorForMessageEvent:event string:message];
break;
default:
break;
Expand All @@ -334,8 +334,11 @@ - (void) otrKit:(OTRKit *)otrKit handleMessageEvent:(OTRKitMessageEvent)event me
[[OTRDatabaseManager sharedInstance].readWriteDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
OTRMessage *message = (OTRMessage *)tag;
message.error = error;
message.text = [OTREncryptionManager errorForMessageEvent:event string:nil].localizedDescription;
[message saveWithTransaction:transaction];
}];
// automatically renegotiate a new session when there's an error
[self.otrKit initiateEncryptionWithUsername:username accountName:accountName protocol:protocol];
}
}
}
Expand Down Expand Up @@ -378,13 +381,17 @@ - (void)otrKit:(OTRKit *)otrKit didFinishGeneratingPrivateKeyForAccountName:(NSS

#pragma - mark Class Methods

+ (NSError *)errorForMessageEvent:(OTRKitMessageEvent)event
+ (NSError *)errorForMessageEvent:(OTRKitMessageEvent)event string:(NSString*)string
{

NSString *eventString = [OTREncryptionManager stringForEvent:event];

NSInteger code = 200 + event;
NSMutableDictionary *userInfo = [@{NSLocalizedDescriptionKey:ENCRYPTION_ERROR_STRING} mutableCopy];
NSMutableString *description = [NSMutableString stringWithString:ENCRYPTION_ERROR_STRING];
if (string.length) {
[description appendFormat:@"\n\n%@", string];
}
NSMutableDictionary *userInfo = [@{NSLocalizedDescriptionKey:description} mutableCopy];
if ([eventString length]) {
[userInfo setObject:eventString forKey:NSLocalizedFailureReasonErrorKey];
}
Expand Down
9 changes: 7 additions & 2 deletions ChatSecure/Classes/Model/Yap Storage/OTRBuddy.m
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,20 @@ + (instancetype)fetchBuddyWithUsername:(NSString *)username withAccountUniqueId:
{
__block OTRBuddy *finalBuddy = nil;


[[transaction ext:OTRYapDatabaseRelationshipName] enumerateEdgesWithName:OTRBuddyEdges.account destinationKey:accountUniqueId collection:[OTRAccount collection] usingBlock:^(YapDatabaseRelationshipEdge *edge, BOOL *stop) {
OTRBuddy * buddy = [transaction objectForKey:edge.sourceKey inCollection:[OTRBuddy collection]];
OTRBuddy * buddy = [transaction objectForKey:edge.sourceKey inCollection:edge.sourceCollection];
if ([buddy.username isEqualToString:username]) {
*stop = YES;
finalBuddy = buddy;
}
}];

if (finalBuddy) {
finalBuddy = [finalBuddy copy];
}

return [finalBuddy copy];
return finalBuddy;
}

+ (void)resetAllChatStatesWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
Expand Down
4 changes: 2 additions & 2 deletions ChatSecure/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.1.2</string>
<string>3.2.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -35,7 +35,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>21</string>
<string>25</string>
<key>FacebookAppID</key>
<string>447241325394334</string>
<key>FacebookDisplayName</key>
Expand Down
2 changes: 1 addition & 1 deletion Submodules/OTRKit
Submodule OTRKit updated 1 files
+15 −4 OTRKit/OTRKit.m

0 comments on commit ecd51ae

Please sign in to comment.