diff --git a/ChatSecure.xcodeproj/project.pbxproj b/ChatSecure.xcodeproj/project.pbxproj index 947bf56e5..1058d3fa7 100644 --- a/ChatSecure.xcodeproj/project.pbxproj +++ b/ChatSecure.xcodeproj/project.pbxproj @@ -156,7 +156,6 @@ D93DDAF21BA79A2800CD8331 /* OTRXMPPServerListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 63039E971B0D43FE007C9978 /* OTRXMPPServerListViewController.m */; }; D93DDAF31BA79A2800CD8331 /* OTRXMPPLoginHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 634680821B0404CE00D9A1C5 /* OTRXMPPLoginHandler.m */; }; D93DDAF51BA79A2800CD8331 /* OTRGoolgeOAuthLoginHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 634680891B041F2F00D9A1C5 /* OTRGoolgeOAuthLoginHandler.m */; }; - D93DDAF61BA79A2900CD8331 /* OTRChatSecureIDCreateAccountHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 63C7E64A1B20F5730085FA06 /* OTRChatSecureIDCreateAccountHandler.m */; }; D93DDAF71BA79A2900CD8331 /* OTRXMPPCreateAccountHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 6346808C1B04206400D9A1C5 /* OTRXMPPCreateAccountHandler.m */; }; D93DDAF81BA79A2900CD8331 /* OTRLoginHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 63BE425D1B320EE20017058C /* OTRLoginHandler.m */; }; D93DDAF91BA79A2900CD8331 /* OTRAboutViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 633106131A16D1A300C17BAE /* OTRAboutViewController.m */; }; @@ -297,8 +296,7 @@ D93DDBA71BA79AA900CD8331 /* OTRXLFormCreator.h in Headers */ = {isa = PBXBuildFile; fileRef = 638C7CF31B02BF0D004F8EC3 /* OTRXLFormCreator.h */; settings = {ATTRIBUTES = (Public, ); }; }; D93DDBA81BA79AAA00CD8331 /* OTRXMPPServerListViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 63039E961B0D43FE007C9978 /* OTRXMPPServerListViewController.h */; settings = {ATTRIBUTES = (Public, ); }; }; D93DDBA91BA79AAB00CD8331 /* OTRXMPPLoginHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 634680811B0404CE00D9A1C5 /* OTRXMPPLoginHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; - D93DDBAB1BA79AAE00CD8331 /* OTRGoolgeOAuthLoginHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 634680881B041F2F00D9A1C5 /* OTRGoolgeOAuthLoginHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; - D93DDBAC1BA79AAF00CD8331 /* OTRChatSecureIDCreateAccountHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 63C7E6491B20F5730085FA06 /* OTRChatSecureIDCreateAccountHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; + D93DDBAB1BA79AAE00CD8331 /* OTRGoolgeOAuthLoginHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 634680881B041F2F00D9A1C5 /* OTRGoolgeOAuthLoginHandler.h */; settings = {ATTRIBUTES = (Private, ); }; }; D93DDBAD1BA79AB000CD8331 /* OTRXMPPCreateAccountHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 6346808B1B04206400D9A1C5 /* OTRXMPPCreateAccountHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; D93DDBAE1BA79AB100CD8331 /* OTRLoginHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 63BE425C1B320EE20017058C /* OTRLoginHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; D93DDBAF1BA79AB200CD8331 /* OTRAboutViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 633106121A16D1A300C17BAE /* OTRAboutViewController.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -374,6 +372,10 @@ D9AE3A331BA8D9AB00255537 /* OTRConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 633105EF1A16D1A300C17BAE /* OTRConstants.m */; }; D9AE3A341BA8DAB600255537 /* OTRLanguageManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6331051B1A16D1A300C17BAE /* OTRLanguageManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; D9AE3A351BA8DAB600255537 /* OTRLanguageManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6331051C1A16D1A300C17BAE /* OTRLanguageManager.m */; }; + D9B9B1331DC7F3AC0007F5A7 /* UserInfoProfileCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9B9B1311DC7F3AC0007F5A7 /* UserInfoProfileCell.swift */; }; + D9B9B1351DC7F3BF0007F5A7 /* UserInfoProfileCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D9B9B1321DC7F3AC0007F5A7 /* UserInfoProfileCell.xib */; }; + D9B9B1371DC802480007F5A7 /* OTRUserInfoProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = D9B9B1361DC802480007F5A7 /* OTRUserInfoProfile.h */; settings = {ATTRIBUTES = (Public, ); }; }; + D9BEF8E01DCE6E12009945D1 /* OTRXMPPManager_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = D9BEF8DF1DCE6E12009945D1 /* OTRXMPPManager_Private.h */; }; D9CBBC581C642BAA005CD715 /* EnablePushViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9CBBC571C642BAA005CD715 /* EnablePushViewController.swift */; }; D9EEEDD31D2739A800B8BC54 /* OTRvCard.h in Headers */ = {isa = PBXBuildFile; fileRef = D9EEEDD11D27388600B8BC54 /* OTRvCard.h */; settings = {ATTRIBUTES = (Public, ); }; }; DDE1CAF4312DE1C724A33B72 /* Pods_ChatSecureCorePods_ChatSecureCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 31610826406FD0CB714045AD /* Pods_ChatSecureCorePods_ChatSecureCore.framework */; }; @@ -752,8 +754,6 @@ 63C0C4441BE184910086B529 /* OTRRoomOccupantsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTRRoomOccupantsViewController.swift; sourceTree = ""; }; 63C5B6681A82F3EE0011BEA8 /* OTRAudioPlaybackController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRAudioPlaybackController.h; sourceTree = ""; }; 63C5B6691A82F3EE0011BEA8 /* OTRAudioPlaybackController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRAudioPlaybackController.m; sourceTree = ""; }; - 63C7E6491B20F5730085FA06 /* OTRChatSecureIDCreateAccountHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRChatSecureIDCreateAccountHandler.h; sourceTree = ""; }; - 63C7E64A1B20F5730085FA06 /* OTRChatSecureIDCreateAccountHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRChatSecureIDCreateAccountHandler.m; sourceTree = ""; }; 63C7E64C1B20F69F0085FA06 /* OTRXMPPServerInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OTRXMPPServerInfo.h; path = ChatSecure/Classes/Model/OTRXMPPServerInfo.h; sourceTree = SOURCE_ROOT; }; 63C7E64D1B20F69F0085FA06 /* OTRXMPPServerInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OTRXMPPServerInfo.m; path = ChatSecure/Classes/Model/OTRXMPPServerInfo.m; sourceTree = SOURCE_ROOT; }; 63CBD68F1C642B9E00AC6D1F /* BuddyActions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BuddyActions.swift; path = YapActions/BuddyActions.swift; sourceTree = ""; }; @@ -840,6 +840,7 @@ D9BE65431B6A08ED002D4136 /* XMPPServerInfoCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMPPServerInfoCell.h; sourceTree = ""; }; D9BE65441B6A08ED002D4136 /* XMPPServerInfoCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPServerInfoCell.m; sourceTree = ""; }; D9BE65451B6A08ED002D4136 /* XMPPServerInfoCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = XMPPServerInfoCell.xib; path = Interface/XMPPServerInfoCell.xib; sourceTree = ""; }; + D9BEF8DF1DCE6E12009945D1 /* OTRXMPPManager_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRXMPPManager_Private.h; sourceTree = ""; }; D9C6E69D1B7148EF00572273 /* OTRUsernameCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = OTRUsernameCell.xib; path = Interface/OTRUsernameCell.xib; sourceTree = ""; }; D9C6E6A01B71575300572273 /* OTRUsernameCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTRUsernameCell.swift; sourceTree = ""; }; D9CBBC571C642BAA005CD715 /* EnablePushViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EnablePushViewController.swift; path = "ChatSecure/Classes/View Controllers/Onboarding/EnablePushViewController.swift"; sourceTree = SOURCE_ROOT; }; @@ -1006,6 +1007,7 @@ 633105321A16D1A300C17BAE /* XMPP */ = { isa = PBXGroup; children = ( + D9BEF8DF1DCE6E12009945D1 /* OTRXMPPManager_Private.h */, 63B916E01B743198003B778F /* OTRStreamManagementYapStorage.h */, 63B916E11B743198003B778F /* OTRStreamManagementYapStorage.m */, 637DBB1A1B7D5A23003845B7 /* OTRXMPPMessageYapStroage.h */, @@ -1328,8 +1330,6 @@ 634680821B0404CE00D9A1C5 /* OTRXMPPLoginHandler.m */, 634680881B041F2F00D9A1C5 /* OTRGoolgeOAuthLoginHandler.h */, 634680891B041F2F00D9A1C5 /* OTRGoolgeOAuthLoginHandler.m */, - 63C7E6491B20F5730085FA06 /* OTRChatSecureIDCreateAccountHandler.h */, - 63C7E64A1B20F5730085FA06 /* OTRChatSecureIDCreateAccountHandler.m */, 6346808B1B04206400D9A1C5 /* OTRXMPPCreateAccountHandler.h */, 6346808C1B04206400D9A1C5 /* OTRXMPPCreateAccountHandler.m */, 63BE425C1B320EE20017058C /* OTRLoginHandler.h */, @@ -1698,12 +1698,71 @@ D93DDBBF1BA79AC700CD8331 /* OTRMessagesHoldTalkViewController.h in Headers */, D93DDBC01BA79AC800CD8331 /* OTRNewBuddyViewController.h in Headers */, D93DDBC11BA79ACA00CD8331 /* OTRQRCodeViewController.h in Headers */, + 6369855A1BC875110083FC53 /* OTRXMPPRoomManager.h in Headers */, + 63BB66AF1BC5D2F40004A619 /* OTRXMPPRoomYapStorage.h in Headers */, + D935EF0B1CFFA19A005A1AC8 /* OTRBuddyApprovalCell.h in Headers */, + 639C352A1C3DDDDE00132330 /* OTRXMPPBuddyManager.h in Headers */, + D93DDBC71BA79AD200CD8331 /* XMPPServerInfoCell.h in Headers */, + D93DDB311BA79A7000CD8331 /* UIViewController+ChatSecure.h in Headers */, + D93DDB301BA79A7000CD8331 /* UIImage+ChatSecure.h in Headers */, + D93DDB2F1BA79A7000CD8331 /* UIActivityViewController+ChatSecure.h in Headers */, + D93DDB2E1BA79A7000CD8331 /* UIActivity+ChatSecure.h in Headers */, + D9BEF8E01DCE6E12009945D1 /* OTRXMPPManager_Private.h in Headers */, + D93DDB2D1BA79A7000CD8331 /* UIActionSheet+ChatSecure.h in Headers */, + D93DDB471BA79A7200CD8331 /* OTRvCardYapDatabaseStorage.h in Headers */, + D93DDB4C1BA79A7300CD8331 /* OTRYapDatabaseRosterStorage.h in Headers */, + D93DDB4B1BA79A7300CD8331 /* OTRXMPPTorManager.h in Headers */, + D93DDB891BA79A8C00CD8331 /* OTRXMPPTorAccount.h in Headers */, + D93DDBA81BA79AAA00CD8331 /* OTRXMPPServerListViewController.h in Headers */, + D93DDB4E1BA79A7300CD8331 /* OTRXMPPServerInfo.h in Headers */, + D93DDB4A1BA79A7300CD8331 /* OTRXMPPProxyStream.h in Headers */, + D93DDB931BA79A9400CD8331 /* OTRXMPPPresenceSubscriptionRequest.h in Headers */, + D93DDB461BA79A7200CD8331 /* OTRXMPPMessageYapStroage.h in Headers */, + D93DDB9F1BA79AA100CD8331 /* OTRXMPPError.h in Headers */, + D93DDB481BA79A7200CD8331 /* OTRXMPPBudyTimers.h in Headers */, + D93DDB921BA79A9300CD8331 /* OTRXMPPBuddy.h in Headers */, + D93DDBA21BA79AA400CD8331 /* OTRWelcomeAccountTableViewDelegate.h in Headers */, + D93DDB831BA79A8800CD8331 /* OTRViewSetting.h in Headers */, + D93DDB8C1BA79A8E00CD8331 /* OTRVideoItem.h in Headers */, + D93DDB821BA79A8700CD8331 /* OTRValueSetting.h in Headers */, + D93DDB9E1BA79AA000CD8331 /* OTRUtilities.h in Headers */, + D93DDBDE1BA79AF900CD8331 /* OTRTouchAndHoldGestureRecognizer.h in Headers */, + D93DDB3F1BA79A7100CD8331 /* OTRTorManager.h in Headers */, + D93DDB741BA79A8000CD8331 /* OTRToastOptions.h in Headers */, + D93DDBDB1BA79AF300CD8331 /* OTRTitleSubtitleView.h in Headers */, + D93DDBCF1BA79ADE00CD8331 /* OTRTextFieldTableViewCell.h in Headers */, + D93DDB451BA79A7200CD8331 /* OTRStreamManagementYapStorage.h in Headers */, + D93DDB8E1BA79A9000CD8331 /* OTRStreamManagementStorageObject.h in Headers */, + D93DDBCE1BA79ADD00CD8331 /* OTRStatusMessageCell.h in Headers */, + D93DDBDA1BA79AF100CD8331 /* OTRSocialButtonsView.h in Headers */, + D93DDB811BA79A8700CD8331 /* OTRShareSetting.h in Headers */, + D93DDBC31BA79ACC00CD8331 /* OTRSettingsViewController.h in Headers */, + D93DDB801BA79A8600CD8331 /* OTRSettingsGroup.h in Headers */, + D93DDBCD1BA79ADB00CD8331 /* OTRSettingTableViewCell.h in Headers */, D93DDBC21BA79ACB00CD8331 /* OTRSettingDetailViewController.h in Headers */, D93DDBC31BA79ACC00CD8331 /* OTRSettingsViewController.h in Headers */, D978BC921BABE0F4009246CF /* OTRTheme.h in Headers */, D93DDBC51BA79ACF00CD8331 /* OTRCircleView.h in Headers */, D93DDBC61BA79AD000CD8331 /* OTRCircleButtonView.h in Headers */, - D93DDBC71BA79AD200CD8331 /* XMPPServerInfoCell.h in Headers */, + D93DDBB51BA79ABA00CD8331 /* OTRChooseAccountViewController.h in Headers */, + D93DDB961BA79A9800CD8331 /* OTRChatDemo.h in Headers */, + D93DDBB31BA79AB700CD8331 /* OTRCertificatesViewController.h in Headers */, + D93DDB761BA79A8100CD8331 /* OTRCertificateSetting.h in Headers */, + D93DDB951BA79A9600CD8331 /* OTRCertificatePinning.h in Headers */, + D93DDBB21BA79AB600CD8331 /* OTRCertificateDomainViewController.h in Headers */, + D93DDBD01BA79AE000CD8331 /* OTRButtonView.h in Headers */, + D93DDBB11BA79AB500CD8331 /* OTRBuddyViewController.h in Headers */, + D93DDB751BA79A8000CD8331 /* OTRBoolSetting.h in Headers */, + D93DDBDD1BA79AF700CD8331 /* OTRAudioTrashView.h in Headers */, + D93DDB411BA79A7100CD8331 /* OTRAudioSessionManager.h in Headers */, + 6326D9AF1DC3D0F100D72403 /* OTRYapMessageSendAction.h in Headers */, + D93DDB421BA79A7100CD8331 /* OTRAudioPlaybackController.h in Headers */, + D93DDB8D1BA79A8F00CD8331 /* OTRAudioItem.h in Headers */, + D93DDBD11BA79AE200CD8331 /* OTRAudioControlsView.h in Headers */, + D93DDB351BA79A7000CD8331 /* OTRAttachmentPicker.h in Headers */, + D93DDBA41BA79AA600CD8331 /* OTRAddBuddyQRCodeViewController.h in Headers */, + D93DDB6F1BA79A7E00CD8331 /* OTRActivityItemProvider.h in Headers */, + D93DDBB01BA79AB300CD8331 /* OTRAcknowledgementsViewController.h in Headers */, D93DDBC81BA79AD300CD8331 /* OTRAccountTableViewCell.h in Headers */, D93DDBC91BA79AD500CD8331 /* OTRBuddyImageCell.h in Headers */, D93DDBCA1BA79AD700CD8331 /* OTRBuddyInfoCell.h in Headers */, @@ -2288,7 +2347,8 @@ D93DDAF21BA79A2800CD8331 /* OTRXMPPServerListViewController.m in Sources */, D93DDAF31BA79A2800CD8331 /* OTRXMPPLoginHandler.m in Sources */, D93DDAF51BA79A2800CD8331 /* OTRGoolgeOAuthLoginHandler.m in Sources */, - D93DDAF61BA79A2900CD8331 /* OTRChatSecureIDCreateAccountHandler.m in Sources */, + D92AC2091DB023D8007BD3E7 /* UserProfileViewController.swift in Sources */, + 6326D9B01DC3D0F100D72403 /* OTRYapMessageSendAction.m in Sources */, D93DDAF71BA79A2900CD8331 /* OTRXMPPCreateAccountHandler.m in Sources */, D93DDAF81BA79A2900CD8331 /* OTRLoginHandler.m in Sources */, D93DDAF91BA79A2900CD8331 /* OTRAboutViewController.m in Sources */, diff --git a/ChatSecure/Classes/Controllers/OTRAccountsManager.m b/ChatSecure/Classes/Controllers/OTRAccountsManager.m index 5b2005923..40fd92304 100644 --- a/ChatSecure/Classes/Controllers/OTRAccountsManager.m +++ b/ChatSecure/Classes/Controllers/OTRAccountsManager.m @@ -38,9 +38,9 @@ @implementation OTRAccountsManager + (void)removeAccount:(OTRAccount*)account { + [account removeKeychainPassword:nil]; [[OTRDatabaseManager sharedInstance].readWriteDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - - [transaction setObject:nil forKey:account.uniqueId inCollection:[OTRAccount collection]]; + [transaction removeObjectForKey:account.uniqueId inCollection:[OTRAccount collection]]; }]; } diff --git a/ChatSecure/Classes/Controllers/OTRNotificationController.m b/ChatSecure/Classes/Controllers/OTRNotificationController.m index 660452668..59d97ec13 100644 --- a/ChatSecure/Classes/Controllers/OTRNotificationController.m +++ b/ChatSecure/Classes/Controllers/OTRNotificationController.m @@ -106,47 +106,10 @@ - (UIViewController *)topViewController - (void)showLoginSuccessNotification:(NSNotification *)notification { - if (!self.enabled) { - return; - } - UIViewController *topViewController = [self topViewController]; - if (![topViewController isKindOfClass:[OTRBaseLoginViewController class]]) { - OTRXMPPManager *xmppManager = notification.object; - NSString *accountName = nil; - if (xmppManager) { - accountName = [xmppManager accountName]; - accountName = [XMPPJID jidWithString:accountName].bare; - } - //OTRToastOptions *options = [[OTRToastOptions alloc] initWithText:CONNECTED_STRING subtitleText:accountName optionType:OTRToastOptionTypeSuccess]; - //[CRToastManager showNotificationWithOptions:[options dictionary] completionBlock:nil]; - } } - (void)showLoginFailureNotification:(NSNotification *)notification { - if (!self.enabled) { - return; - } - BOOL isUserInitiated = [[notification.userInfo objectForKey:kOTRProtocolLoginUserInitiated] boolValue]; - - UIViewController *topViewController = [self topViewController]; - if ([topViewController isKindOfClass:[UINavigationController class]]) { - topViewController = ((UINavigationController *)topViewController).topViewController; - } - - BOOL correctViewController = !([topViewController isKindOfClass:[OTRBaseLoginViewController class]] || [topViewController isKindOfClass:[OTRSettingsViewController class]]); - - - if (correctViewController && isUserInitiated) { - OTRXMPPManager *xmppManager = notification.object; - NSString *accountName = nil; - if (xmppManager) { - accountName = [xmppManager accountName]; - accountName = [XMPPJID jidWithString:accountName].bare; - } - //OTRToastOptions *options = [[OTRToastOptions alloc] initWithText:ACCOUNT_DISCONNECTED_STRING subtitleText:accountName optionType:OTRToastOptionTypeFailure]; - //[CRToastManager showNotificationWithOptions:[options dictionary] completionBlock:nil]; - } } #pragma - mark Public Methods diff --git a/ChatSecure/Classes/Controllers/OTRProtocol.h b/ChatSecure/Classes/Controllers/OTRProtocol.h index 15343a9a8..08e85c3b7 100644 --- a/ChatSecure/Classes/Controllers/OTRProtocol.h +++ b/ChatSecure/Classes/Controllers/OTRProtocol.h @@ -54,15 +54,15 @@ typedef NS_ENUM(NSInteger, OTRLoginStatus) { - (void) sendMessage:(OTRMessage*)message; -- (void) connectWithPassword:(NSString *)password; -- (void) connectWithPassword:(NSString *)password userInitiated:(BOOL)userInitiated; +- (void) connect; +- (void) connectUserInitiated:(BOOL)userInitiated; - (void) disconnect; - (void) disconnectSocketOnly:(BOOL)socketOnly; - (void) addBuddy:(OTRBuddy *)newBuddy; -- (void) removeBuddies:(NSArray *)buddies; -- (void) blockBuddies:(NSArray *)buddies; +- (void) removeBuddies:(NSArray *)buddies; +- (void) blockBuddies:(NSArray *)buddies; - (id) initWithAccount:(OTRAccount*)account; @@ -71,6 +71,4 @@ typedef NS_ENUM(NSInteger, OTRLoginStatus) { @protocol OTRXMPPProtocol - (void)sendChatState:(int)chatState withBuddy:(OTRBuddy *)buddy; - (void) setDisplayName:(NSString *) newDisplayName forBuddy:(OTRBuddy *)buddy; - -- (void) teardownStream; -@end \ No newline at end of file +@end diff --git a/ChatSecure/Classes/Controllers/OTRProtocolManager.m b/ChatSecure/Classes/Controllers/OTRProtocolManager.m index 53b4c00cd..8e6b4fd2a 100644 --- a/ChatSecure/Classes/Controllers/OTRProtocolManager.m +++ b/ChatSecure/Classes/Controllers/OTRProtocolManager.m @@ -67,8 +67,8 @@ - (void)removeProtocolForAccount:(OTRAccount *)account @synchronized(self.protocolManagerDictionary) { if (account) { id protocol = [self.protocolManagerDictionary objectForKey:account.uniqueId]; - if (protocol && [protocol respondsToSelector:@selector(teardownStream)]) { - [protocol teardownStream]; + if (protocol && [protocol respondsToSelector:@selector(disconnect)]) { + [protocol disconnect]; } [self.KVOController unobserve:protocol]; [self.protocolManagerDictionary removeObjectForKey:account.uniqueId]; @@ -156,7 +156,7 @@ - (void)loginAccount:(OTRAccount *)account userInitiated:(BOOL)userInitiated [OTROAuthRefresher refreshAccount:(OTROAuthXMPPAccount *)account completion:^(id token, NSError *error) { if (!error) { ((OTROAuthXMPPAccount *)account).accountSpecificToken = token; - [protocol connectWithPassword:account.password userInitiated:userInitiated]; + [protocol connectUserInitiated:userInitiated]; } else { DDLogError(@"Error Refreshing Token"); @@ -165,7 +165,7 @@ - (void)loginAccount:(OTRAccount *)account userInitiated:(BOOL)userInitiated } else { - [protocol connectWithPassword:account.password userInitiated:userInitiated]; + [protocol connectUserInitiated:userInitiated]; } } diff --git a/ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager.h b/ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager.h index 79d984ee8..fc4bb2e01 100644 --- a/ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager.h +++ b/ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager.h @@ -22,7 +22,7 @@ @import Foundation; @import UIKit; - +@import XMPPFramework; #import "OTRBuddy.h" #import "OTRMessage.h" #import "XMPPFramework.h" @@ -38,60 +38,22 @@ #import "OTRCertificatePinning.h" #import "OTRXMPPError.h" #import "OTRConstants.h" -#import - -@class OTRYapDatabaseRosterStorage,OTRXMPPAccount, OTRvCardYapDatabaseStorage, OTRXMPPManager, OTRXMPPRoomManager; - -extern NSString *const OTRXMPPRegisterSucceededNotificationName; -extern NSString *const OTRXMPPRegisterFailedNotificationName; - - - -/** - This notification is sent every time there is a change in the login status and if it goes 'backwards' there - should be an error or a user initiated disconnect. - - @{ - OTRXMPPOldLoginStatusKey : @(OTRLoginStatus) - OTRXMPPNewLoginStatusKey : @(OTRLoginStatus) - OTRXMPPLoginErrorKey : NSError* - } -*/ - -extern NSString *const OTRXMPPLoginStatusNotificationName; -extern NSString *const OTRXMPPOldLoginStatusKey; -extern NSString *const OTRXMPPNewLoginStatusKey; -extern NSString *const OTRXMPPLoginErrorKey; +@class OTRXMPPAccount, OTRXMPPRoomManager; +@class OTROMEMOSignalCoordinator; +@interface OTRXMPPManager : NSObject -@interface OTRXMPPManager : NSObject +@property (nonatomic, strong, readonly) OTRXMPPAccount *account; -@property (nonatomic, readonly) XMPPStream *xmppStream; -@property (nonatomic, readonly) XMPPReconnect *xmppReconnect; @property (nonatomic, readonly) XMPPRoster *xmppRoster; -@property (nonatomic, readonly) OTRYapDatabaseRosterStorage *xmppRosterStorage; -@property (nonatomic, readonly) XMPPvCardTempModule *xmppvCardTempModule; -@property (nonatomic, readonly) XMPPvCardAvatarModule *xmppvCardAvatarModule; -@property (nonatomic, readonly) XMPPCapabilities *xmppCapabilities; -@property (nonatomic, readonly) XMPPCapabilitiesCoreDataStorage *xmppCapabilitiesStorage; -@property (nonatomic, readonly) OTRCertificatePinning * certificatePinningModule; @property (nonatomic, readonly) OTRXMPPRoomManager *roomManager; -@property BOOL didSecure; - -@property (nonatomic, strong, readonly) OTRXMPPAccount *account; +@property (nonatomic, strong) OTROMEMOSignalCoordinator *omemoSignalCoordinator; @property (nonatomic, weak) id pushController; -- (BOOL)connectWithJID:(NSString*) myJID password:(NSString*)myPassword; -- (void)disconnect; - -- (void) teardownStream; - -- (NSString *)accountName; - -- (void)failedToConnect:(NSError *)error; -- (void)registerNewAccountWithPassword:(NSString *)newPassword; +/** Call this if you want to register a new account on a compatible server */ +- (BOOL)startRegisteringNewAccount; //Chat State @@ -108,3 +70,21 @@ extern NSString *const OTRXMPPLoginErrorKey; - (void) sendDeliveryReceiptForMessage:(OTRMessage*)message; @end + + +/** + This notification is sent every time there is a change in the login status and if it goes 'backwards' there + should be an error or a user initiated disconnect. + + @{ + OTRXMPPOldLoginStatusKey : @(OTRLoginStatus) + OTRXMPPNewLoginStatusKey : @(OTRLoginStatus) + OTRXMPPLoginErrorKey : NSError* + } + */ +extern NSString *const OTRXMPPLoginStatusNotificationName; +extern NSString *const OTRXMPPOldLoginStatusKey; +extern NSString *const OTRXMPPNewLoginStatusKey; +extern NSString *const OTRXMPPLoginErrorKey; +extern NSString *const OTRXMPPRegisterSucceededNotificationName; +extern NSString *const OTRXMPPRegisterFailedNotificationName; diff --git a/ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager.m b/ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager.m index 886655455..e6673191e 100644 --- a/ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager.m +++ b/ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager.m @@ -59,12 +59,11 @@ #import "OTRNotificationController.h" #import "XMPPStreamManagement.h" #import "OTRStreamManagementYapStorage.h" -#import "XMPPMessageCarbons.h" -#import "OTRXMPPMessageYapStroage.h" -#import "OTRKit.h" +@import OTRKit; #import "OTRXMPPRoomManager.h" -#import -#import "OTRXMPPBuddyManager.h" +#import "OTRXMPPBudyTimers.h" +#import "OTRXMPPError.h" +#import "OTRXMPPManager_Private.h" @import OTRAssets; #import "XMPPIQ+XEP_0357.h" @@ -83,42 +82,7 @@ NSString *const OTRXMPPLoginErrorKey = @"OTRXMPPLoginErrorKey"; -@interface OTRXMPPManager() - -@property (nonatomic) OTRProtocolConnectionStatus connectionStatus; - -@property (nonatomic, strong) XMPPStream *xmppStream; -@property (nonatomic, strong) XMPPReconnect *xmppReconnect; -@property (nonatomic, strong) XMPPRoster *xmppRoster; -@property (nonatomic, strong) XMPPvCardTempModule *xmppvCardTempModule; -@property (nonatomic, strong) XMPPvCardAvatarModule *xmppvCardAvatarModule; -@property (nonatomic, strong) XMPPCapabilities *xmppCapabilities; -@property (nonatomic, strong) NSString *password; -@property (nonatomic, strong) XMPPJID *JID; -@property (nonatomic, strong) XMPPCapabilitiesCoreDataStorage *xmppCapabilitiesStorage; -@property (nonatomic, strong) OTRYapDatabaseRosterStorage * xmppRosterStorage; -@property (nonatomic, strong) OTRCertificatePinning * certificatePinningModule; -@property (nonatomic, strong) NSMutableDictionary * buddyTimers; -@property (nonatomic) dispatch_queue_t workQueue; -@property (nonatomic) BOOL isRegisteringNewAccount; -@property (nonatomic, strong) XMPPStreamManagement *streamManagement; -@property (nonatomic, strong) XMPPMessageCarbons *messageCarbons; -@property (nonatomic, strong) OTRXMPPMessageYapStroage *messageStorage; -@property (nonatomic) BOOL userInitiatedConnection; -@property (nonatomic) OTRLoginStatus loginStatus; -@property (nonatomic, strong) OTRXMPPBuddyManager* xmppBuddyManager; - -@property (nonatomic, strong) YapDatabaseConnection *databaseConnection; -@property (nonatomic, strong) XMPPMessageDeliveryReceipts *deliveryReceipts; - -- (void)setupStream; -- (void)teardownStream; - -- (void)goOnline; -- (void)goOffline; -- (void)failedToConnect:(NSError *)error; -@end @implementation OTRXMPPManager @@ -164,7 +128,7 @@ - (void)setupStream { NSAssert(_xmppStream == nil, @"Method setupStream invoked multiple times"); - self.xmppStream = [[XMPPStream alloc] init]; + _xmppStream = [[XMPPStream alloc] init]; //Used to fetch correct account from XMPPStream in delegate methods especailly self.xmppStream.tag = self.account.uniqueId; @@ -404,27 +368,15 @@ - (void)failedToRegisterNewAccount:(NSError *)error } } -- (void)refreshStreamJID:(NSString *)myJID withPassword:(NSString *)myPassword -{ - int r = arc4random() % 99999; - - NSString * resource = [NSString stringWithFormat:@"%@%d",[OTRBranding xmppResource],r]; - - self.JID = [XMPPJID jidWithString:myJID resource:resource]; - - [self.xmppStream setMyJID:self.JID]; - - self.password = myPassword; -} - (void)authenticateWithStream:(XMPPStream *)stream { NSError * error = nil; BOOL status = YES; if ([stream supportsXOAuth2GoogleAuthentication] && self.account.accountType == OTRAccountTypeGoogleTalk) { - status = [stream authenticateWithGoogleAccessToken:self.password error:&error]; + status = [stream authenticateWithGoogleAccessToken:self.account.password error:&error]; } else { - status = [stream authenticateWithPassword:self.password error:&error]; + status = [stream authenticateWithPassword:self.account.password error:&error]; } } @@ -441,19 +393,16 @@ - (NSArray *)myFeaturesForXMPPCapabilities:(XMPPCapabilities *)sender #pragma mark Connect/disconnect //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -- (BOOL)connectWithJID:(NSString*) myJID password:(NSString*)myPassword; +- (BOOL)startConnection { - self.password = myPassword; self.connectionStatus = OTRProtocolConnectionStatusConnecting; - self.JID = [XMPPJID jidWithString:myJID resource:self.account.resource]; + XMPPJID *jid = [XMPPJID jidWithString:self.account.username resource:self.account.resource]; - if (![self.JID.domain isEqualToString:self.xmppStream.myJID.domain]) { + if (![jid.domain isEqualToString:self.xmppStream.myJID.domain]) { [self.xmppStream disconnect]; } - - [self.xmppStream setMyJID:self.JID]; - //DDLogInfo(@"myJID %@",myJID); + self.xmppStream.myJID = jid; if (![self.xmppStream isDisconnected]) { [self authenticateWithStream:self.xmppStream]; return YES; @@ -533,30 +482,32 @@ - (void)disconnect [self disconnectSocketOnly:NO]; } -- (void)registerNewAccountWithPassword:(NSString *)newPassword +- (BOOL)startRegisteringNewAccount { self.isRegisteringNewAccount = YES; if (self.xmppStream.isConnected) { [self.xmppStream disconnect]; + return NO; } - [self connectWithJID:self.account.username password:newPassword]; + return [self startConnection]; } -- (void)registerNewAccountWithPassword:(NSString *)newPassword stream:(XMPPStream *)stream +- (BOOL)continueRegisteringNewAccount { NSError * error = nil; - if ([stream supportsInBandRegistration]) { - [stream registerWithPassword:self.password error:&error]; - if(error) - { + if ([self.xmppStream supportsInBandRegistration]) { + [self.xmppStream registerWithPassword:self.account.password error:&error]; + if (error) { [self failedToRegisterNewAccount:error]; + return NO; } - } - else{ + } else { error = [NSError errorWithDomain:OTRXMPPErrorDomain code:OTRXMPPUnsupportedAction userInfo:nil]; [self failedToRegisterNewAccount:error]; + return NO; } + return YES; } @@ -605,7 +556,7 @@ - (void)xmppStreamDidConnect:(XMPPStream *)sender DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD); if (self.isRegisteringNewAccount) { - [self registerNewAccountWithPassword:self.password stream:sender]; + [self continueRegisteringNewAccount]; } else{ [self authenticateWithStream:sender]; @@ -656,8 +607,7 @@ - (void)xmppStreamDidAuthenticate:(XMPPStream *)sender [self changeLoginStatus:OTRLoginStatusAuthenticated error:nil]; // Refetch capabilities to check for XEP-0357 support - XMPPJID *jid = [XMPPJID jidWithString:[self.JID bare]]; - [self.xmppCapabilities fetchCapabilitiesForJID:jid]; + [self.xmppCapabilities fetchCapabilitiesForJID:self.xmppStream.myJID.bareJID]; // Fetch latest vCard from server so we can update nickname //[self.xmppvCardTempModule fetchvCardTempForJID:self.JID ignoreStorage:YES]; @@ -752,7 +702,7 @@ - (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule // update my vCard to local nickname setting // currently this will clobber whatever you have on the server - if ([self.JID isEqualToJID:jid options:XMPPJIDCompareBare]) { + if ([self.xmppStream.myJID isEqualToJID:jid options:XMPPJIDCompareBare]) { if (self.account.displayName.length && vCardTemp.nickname.length && ![vCardTemp.nickname isEqualToString:self.account.displayName]) { @@ -779,7 +729,7 @@ - (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule DDLogVerbose(@"%@: %@ %@ %@ %@", THIS_FILE, THIS_METHOD, vCardTempModule, jid, error); // update my vCard to local nickname setting - if ([self.JID isEqualToJID:jid options:XMPPJIDCompareBare] && + if ([self.xmppStream.myJID isEqualToJID:jid options:XMPPJIDCompareBare] && self.account.displayName.length) { XMPPvCardTemp *vCardTemp = [XMPPvCardTemp vCardTemp]; vCardTemp.nickname = self.account.displayName; @@ -991,32 +941,26 @@ - (void) sendMessage:(OTRMessage*)message } } -- (NSString*) accountName -{ - return [self.JID full]; - -} - - (NSString*) type { return kOTRProtocolTypeXMPP; } -- (void) connectWithPassword:(NSString *)password userInitiated:(BOOL)userInitiated +- (void) connectUserInitiated:(BOOL)userInitiated { // Don't issue a reconnect if we're already connected and authenticated if ([self.xmppStream isConnected] && [self.xmppStream isAuthenticated]) { return; } self.userInitiatedConnection = userInitiated; - [self connectWithJID:self.account.username password:password]; + [self startConnection]; if (self.userInitiatedConnection) { [[OTRNotificationController sharedInstance] showAccountConnectingNotificationWithAccountName:self.account.username]; } } --(void)connectWithPassword:(NSString *)password +-(void)connect { - [self connectWithPassword:password userInitiated:NO]; + [self connectUserInitiated:NO]; } -(void)sendChatState:(OTRChatState)chatState withBuddyID:(NSString *)buddyUniqueId diff --git a/ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager_Private.h b/ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager_Private.h new file mode 100644 index 000000000..47ff79198 --- /dev/null +++ b/ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager_Private.h @@ -0,0 +1,58 @@ +// +// OTRXMPPManager_Private.h +// ChatSecure +// +// Created by Chris Ballinger on 11/5/16. +// Copyright © 2016 Chris Ballinger. All rights reserved. +// + +#import "OTRXMPPManager.h" +#import "OTRCertificatePinning.h" +#import "OTRXMPPMessageYapStroage.h" +#import "OTRXMPPBuddyManager.h" +#import +#import "OTRYapDatabaseRosterStorage.h" +#import "OTRXMPPRoomManager.h" + +@interface OTRXMPPManager() +@property (nonatomic) OTRProtocolConnectionStatus connectionStatus; +@property (nonatomic, strong) XMPPStream *xmppStream; +@property (nonatomic, strong) XMPPReconnect *xmppReconnect; +@property (nonatomic, strong) XMPPRoster *xmppRoster; +@property (nonatomic, strong) XMPPvCardTempModule *xmppvCardTempModule; +@property (nonatomic, strong) XMPPvCardAvatarModule *xmppvCardAvatarModule; +@property (nonatomic, strong) XMPPCapabilities *xmppCapabilities; +@property (nonatomic, strong) XMPPCapabilitiesCoreDataStorage *xmppCapabilitiesStorage; +@property (nonatomic, strong) OTRYapDatabaseRosterStorage * xmppRosterStorage; +@property (nonatomic, strong) OTRCertificatePinning * certificatePinningModule; +@property (nonatomic, strong) NSMutableDictionary * buddyTimers; +@property (nonatomic) dispatch_queue_t workQueue; +@property (nonatomic) BOOL isRegisteringNewAccount; +@property (nonatomic, strong) XMPPStreamManagement *streamManagement; +@property (nonatomic, strong) XMPPMessageCarbons *messageCarbons; +@property (nonatomic, strong) OTRXMPPMessageYapStroage *messageStorage; +@property (nonatomic) BOOL userInitiatedConnection; +@property (nonatomic) OTRLoginStatus loginStatus; +@property (nonatomic, strong) OTRXMPPBuddyManager* xmppBuddyManager; + +@property (nonatomic, strong) OMEMOModule *omemoModule; + + +@property (nonatomic, strong) YapDatabaseConnection *databaseConnection; +@property (nonatomic, strong) XMPPMessageDeliveryReceipts *deliveryReceipts; +@property (nonatomic, strong) OTRXMPPMessageStatusModule *messageStatusModule; +@property (nonatomic, strong) OTRStreamManagementDelegate *streamManagementDelegate; + +- (void)setupStream; +- (void)teardownStream; + +- (void)goOnline; +- (void)goOffline; +- (void)failedToConnect:(NSError *)error; + + + +/** wtf. why isn't this being picked up by OTRProtocol */ +- (void) connectUserInitiated:(BOOL)userInitiated; + +@end diff --git a/ChatSecure/Classes/Controllers/XMPP/OTRXMPPTorManager.m b/ChatSecure/Classes/Controllers/XMPP/OTRXMPPTorManager.m index 0e3f92d59..caf8e4a5b 100644 --- a/ChatSecure/Classes/Controllers/XMPP/OTRXMPPTorManager.m +++ b/ChatSecure/Classes/Controllers/XMPP/OTRXMPPTorManager.m @@ -10,6 +10,10 @@ #import "OTRTorManager.h" #import "XMPPStream.h" #import "OTRXMPPTorAccount.h" +#import "OTRXMPPError.h" +#import "OTRProtocol.h" +#import "OTRXMPPManager_Private.h" + @interface OTRXMPPTorManager() @property (nonatomic, strong) OTRXMPPTorAccount *account; @@ -17,34 +21,22 @@ @interface OTRXMPPTorManager() @implementation OTRXMPPTorManager -@synthesize xmppStream = _xmppStream; - -- (void)connectWithPassword:(NSString *)password userInitiated:(BOOL)userInitiated -{ +- (void) connectUserInitiated:(BOOL)userInitiated { if ([OTRTorManager sharedInstance].torManager.isConnected) { - [super connectWithPassword:password userInitiated:userInitiated]; - } - else { + [super connectUserInitiated:userInitiated]; + } else { NSError * error = [NSError errorWithDomain:OTRXMPPErrorDomain code:OTRXMPPTorError userInfo:@{NSLocalizedDescriptionKey:NSLocalizedString(@"Need to connect to Tor first.", @"")}]; [self failedToConnect:error]; } } -- (void)connectWithPassword:(NSString *)password -{ - [self connectWithPassword:password userInitiated:NO]; -} - --(XMPPStream *)xmppStream -{ - if (!_xmppStream) { - _xmppStream = [super xmppStream]; - NSString *proxyHost = [OTRTorManager sharedInstance].torManager.SOCKSHost; - NSUInteger proxyPort = [OTRTorManager sharedInstance].torManager.SOCKSPort; - [_xmppStream setProxyHost:proxyHost port:proxyPort version:GCDAsyncSocketSOCKSVersion5]; - [_xmppStream setProxyUsername:[[NSUUID UUID] UUIDString] password:[[NSUUID UUID] UUIDString]]; - } - return _xmppStream; +// override +- (void) setupStream { + [super setupStream]; + NSString *proxyHost = [OTRTorManager sharedInstance].torManager.SOCKSHost; + NSUInteger proxyPort = [OTRTorManager sharedInstance].torManager.SOCKSPort; + [self.xmppStream setProxyHost:proxyHost port:proxyPort version:GCDAsyncSocketSOCKSVersion5]; + [self.xmppStream setProxyUsername:[[NSUUID UUID] UUIDString] password:[[NSUUID UUID] UUIDString]]; } - (NSString *)accountDomainWithError:(NSError**)error; diff --git a/ChatSecure/Classes/Model/Yap Storage/Accounts/OTRAccount.h b/ChatSecure/Classes/Model/Yap Storage/Accounts/OTRAccount.h index 3b4428eb4..0d4d3f1e4 100644 --- a/ChatSecure/Classes/Model/Yap Storage/Accounts/OTRAccount.h +++ b/ChatSecure/Classes/Model/Yap Storage/Accounts/OTRAccount.h @@ -35,6 +35,7 @@ extern NSString *const OTRXMPPTorImageName; @property (nonatomic, strong) NSString *displayName; @property (nonatomic, readonly) OTRAccountType accountType; @property (nonatomic, strong) NSString *username; +/** Setting rememberPassword to false will remove keychain passwords */ @property (nonatomic) BOOL rememberPassword; @property (nonatomic) BOOL autologin; @@ -44,7 +45,13 @@ extern NSString *const OTRXMPPTorImageName; */ @property (nonatomic, strong) NSData *avatarData; +/** + * To remove the keychain password, you must explicitly call removeKeychainPassword + * instead of setting empty string or nil + */ @property (nonatomic, strong) NSString *password; +/** Removes the account password from keychain */ +- (BOOL) removeKeychainPassword:(NSError**)error; - (id)initWithAccountType:(OTRAccountType)accountType; diff --git a/ChatSecure/Classes/Model/Yap Storage/Accounts/OTRAccount.m b/ChatSecure/Classes/Model/Yap Storage/Accounts/OTRAccount.m index e9554a12f..7c1220bd1 100644 --- a/ChatSecure/Classes/Model/Yap Storage/Accounts/OTRAccount.m +++ b/ChatSecure/Classes/Model/Yap Storage/Accounts/OTRAccount.m @@ -37,6 +37,8 @@ @interface OTRAccount () @implementation OTRAccount @synthesize accountType = _accountType; +/** This value is only used when rememberPassword is false */ +@synthesize password = _password; - (id)init { @@ -95,32 +97,50 @@ - (Class)protocolClass { return nil; } +- (BOOL) removeKeychainPassword:(NSError**)error { + NSError *internalError = nil; + BOOL result = [SAMKeychain deletePasswordForService:kOTRServiceName account:self.uniqueId error:&internalError]; + if (!result) { + DDLogError(@"Error deleting password from keychain: %@%@", [internalError localizedDescription], [internalError userInfo]); + } else { + DDLogInfo(@"Password for %@ deleted from keychain.", self.username); + } + if (*error) { + *error = internalError; + } + return result; +} + - (void)setPassword:(NSString *) password { - - if (!password.length || !self.rememberPassword) { - NSError *error = nil; - [SAMKeychain deletePasswordForService:kOTRServiceName account:self.uniqueId error:&error]; - if (error) { - DDLogError(@"Error deleting password from keychain: %@%@", [error localizedDescription], [error userInfo]); - } + // Store password in-memory only if rememberPassword is false + // Also remove keychain value + if (!self.rememberPassword) { + [self removeKeychainPassword:nil]; + _password = password; + return; + } + if (!password.length) { + NSAssert(password.length > 0, @"Improperly removing password!"); + DDLogError(@"Improperly removing password! To remove password call removeKeychainPassword!"); return; } NSError *error = nil; - [SAMKeychain setPassword:password forService:kOTRServiceName account:self.uniqueId error:&error]; - if (error) { + BOOL result = [SAMKeychain setPassword:password forService:kOTRServiceName account:self.uniqueId error:&error]; + if (!result) { DDLogError(@"Error saving password to keychain: %@%@", [error localizedDescription], [error userInfo]); } } - (NSString *)password { if (!self.rememberPassword) { - return nil; + [self removeKeychainPassword:nil]; + return _password; } NSError *error = nil; NSString *password = [SAMKeychain passwordForService:kOTRServiceName account:self.uniqueId error:&error]; if (error) { + //NSAssert(password.length > 0, @"Looking for password in keychain but it wasn't found!"); DDLogError(@"Error retreiving password from keychain: %@%@", [error localizedDescription], [error userInfo]); - error = nil; } return password; } diff --git a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRBaseLoginViewController.h b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRBaseLoginViewController.h index 73feb11b7..a2c4b956b 100644 --- a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRBaseLoginViewController.h +++ b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRBaseLoginViewController.h @@ -16,7 +16,7 @@ @property (nonatomic, strong) OTRAccount *account; -@property (nonatomic, strong) id createLoginHandler; +@property (nonatomic, strong) id loginHandler; @property (nonatomic) BOOL readOnly; diff --git a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRBaseLoginViewController.m b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRBaseLoginViewController.m index ad154b990..fe1d949e5 100644 --- a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRBaseLoginViewController.m +++ b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRBaseLoginViewController.m @@ -59,7 +59,7 @@ - (void)viewWillAppear:(BOOL)animated [self.navigationController setNavigationBarHidden:NO animated:animated]; [self.tableView reloadData]; - [self.createLoginHandler moveAccountValues:self.account intoForm:self.form]; + [self.loginHandler moveAccountValues:self.account intoForm:self.form]; // We need to refresh the username row with the default selected server [self updateUsernameRow]; @@ -68,7 +68,7 @@ - (void)viewWillAppear:(BOOL)animated - (void)setAccount:(OTRAccount *)account { _account = account; - [self.createLoginHandler moveAccountValues:self.account intoForm:self.form]; + [self.loginHandler moveAccountValues:self.account intoForm:self.form]; } - (void) cancelButtonPressed:(id)sender { @@ -91,7 +91,7 @@ - (void)loginButtonPressed:(id)sender __weak __typeof__(self) weakSelf = self; self.loginAttempts += 1; - [self.createLoginHandler performActionWithValidForm:self.form account:self.account progress:^(NSInteger progress, NSString *summaryString) { + [self.loginHandler performActionWithValidForm:self.form account:self.account progress:^(NSInteger progress, NSString *summaryString) { __typeof__(self) strongSelf = weakSelf; NSLog(@"Tor Progress %d: %@", (int)progress, summaryString); [[MBProgressHUD HUDForView:strongSelf.view] setProgress:progress/100.0f]; @@ -367,7 +367,7 @@ + (instancetype)loginViewControllerForAccount:(OTRAccount *)account { OTRBaseLoginViewController *baseLoginViewController = [[self alloc] initWithForm:[OTRXLFormCreator formForAccount:account] style:UITableViewStyleGrouped]; baseLoginViewController.account = account; - baseLoginViewController.createLoginHandler = [OTRLoginHandler loginHandlerForAccount:account]; + baseLoginViewController.loginHandler = [OTRLoginHandler loginHandlerForAccount:account]; return baseLoginViewController; } diff --git a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRChatSecureIDCreateAccountHandler.h b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRChatSecureIDCreateAccountHandler.h deleted file mode 100644 index 3f3a90266..000000000 --- a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRChatSecureIDCreateAccountHandler.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// OTRChatSecureIDCreateAccountHandler.h -// ChatSecure -// -// Created by David Chiles on 6/4/15. -// Copyright (c) 2015 Chris Ballinger. All rights reserved. -// - -#import "OTRXMPPCreateAccountHandler.h" - -@interface OTRChatSecureIDCreateAccountHandler : OTRXMPPCreateAccountHandler - - - -@end diff --git a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRChatSecureIDCreateAccountHandler.m b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRChatSecureIDCreateAccountHandler.m deleted file mode 100644 index ae64d58ce..000000000 --- a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRChatSecureIDCreateAccountHandler.m +++ /dev/null @@ -1,89 +0,0 @@ -// -// OTRChatSecureIDCreateAccountHandler.m -// ChatSecure -// -// Created by David Chiles on 6/4/15. -// Copyright (c) 2015 Chris Ballinger. All rights reserved. -// - -#import "OTRChatSecureIDCreateAccountHandler.h" -#import "OTRXMPPServerInfo.h" -#import "OTRXMPPManager.h" -#import "OTRPasswordGenerator.h" -#import "OTRProtocolManager.h" - -@interface OTRChatSecureIDCreateAccountHandler () - -@property (nonatomic, strong) NSMutableArray *serverList; -@property (nonatomic, strong) OTRXMPPAccount *account; - -@end - -@implementation OTRChatSecureIDCreateAccountHandler - -- (instancetype)init -{ - if (self = [super init]) { - self.serverList = [[OTRXMPPServerInfo defaultServerList] mutableCopy]; - } - return self; -} - -- (void)prepareForXMPPConnectionFrom:(XLFormDescriptor *)form account:(OTRXMPPAccount *)account -{ - [super prepareForXMPPConnectionFrom:form account:account]; - [self moveServerInfo:[self.serverList firstObject] intoAccount:account]; - account.rememberPassword = YES; - account.autologin = YES; - self.account = account; -} - -- (void)moveServerInfo:(OTRXMPPServerInfo *)serverInfo intoAccount:(OTRXMPPAccount *)account -{ - NSString *user = [XMPPJID jidWithString:account.username].user; - if (![user length]) { - user = account.username; - } - account.username = [XMPPJID jidWithUser:user domain:serverInfo.domain resource:nil].bare; - account.domain = serverInfo.domain; -} - -- (void)attemptToCreateAccount -{ - OTRXMPPServerInfo *serverInfo = [self.serverList firstObject]; - if (!serverInfo) { - //error no more servers to find - } else { - [self performActionWithValidForm:nil account:self.account progress:nil completion:self.completion]; - } -} - -- (void)performActionWithValidForm:(XLFormDescriptor *)form account:(OTRAccount *)account progress:(void (^)(NSInteger progress, NSString *summaryString))progress completion:(void (^)(OTRAccount * account, NSError *error))completion -{ - self.password = [OTRPasswordGenerator passwordWithLength:25];//Create random password - [super performActionWithValidForm:form account:account progress:progress completion:completion]; -} -- (void)receivedNotification:(NSNotification *)notification -{ - OTRLoginStatus newStatus = [notification.userInfo[OTRXMPPNewLoginStatusKey] integerValue]; - NSError *error = notification.userInfo[OTRXMPPLoginErrorKey]; - - if(error && [self.serverList count]) { - //Unable to create account but there are more servers to try with - [self.serverList removeObjectAtIndex:0]; - - //remove old xmpp manager that is not needed anymore - [[OTRProtocolManager sharedInstance] removeProtocolForAccount:self.account]; - - [self attemptToCreateAccount]; - } else { - //successfully created account - //need to save password - if (newStatus == OTRLoginStatusAuthenticated) { - self.account.password = self.password; - } - [super receivedNotification:notification]; - } -} - -@end diff --git a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRExistingAccountViewController.m b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRExistingAccountViewController.m index bd633f0b6..cd1171494 100644 --- a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRExistingAccountViewController.m +++ b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRExistingAccountViewController.m @@ -20,7 +20,6 @@ #import "GTMOAuth2ViewControllerTouch.h" #import "OTRSecrets.h" #import "OTRDatabaseManager.h" -#import "OTRChatSecureIDCreateAccountHandler.h" #import "OTRWelcomeAccountTableViewDelegate.h" @import OTRAssets; @@ -103,7 +102,7 @@ - (NSArray *)defaultAccountArray __typeof__(self) strongSelf = weakSelf; OTRBaseLoginViewController *loginViewController = [[OTRBaseLoginViewController alloc] init]; loginViewController.form = [OTRXLFormCreator formForAccountType:OTRAccountTypeJabber createAccount:NO]; - loginViewController.createLoginHandler = [[OTRXMPPLoginHandler alloc] init]; + loginViewController.loginHandler = [[OTRXMPPLoginHandler alloc] init]; [strongSelf.navigationController pushViewController:loginViewController animated:YES]; }]]; @@ -123,7 +122,7 @@ - (NSArray *)defaultAccountArray OTRBaseLoginViewController *loginViewController = [[OTRBaseLoginViewController alloc] initWithForm:[OTRXLFormCreator formForAccount:googleAccount] style:UITableViewStyleGrouped]; loginViewController.account = googleAccount; OTRGoolgeOAuthLoginHandler *loginHandler = [[OTRGoolgeOAuthLoginHandler alloc] init]; - loginViewController.createLoginHandler = loginHandler; + loginViewController.loginHandler = loginHandler; NSMutableArray *viewControllers = [strongSelf.navigationController.viewControllers mutableCopy]; [viewControllers removeObject:viewController]; diff --git a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRGoolgeOAuthLoginHandler.m b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRGoolgeOAuthLoginHandler.m index 99739a2a2..e78bd49dd 100644 --- a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRGoolgeOAuthLoginHandler.m +++ b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRGoolgeOAuthLoginHandler.m @@ -30,8 +30,7 @@ - (void)performActionWithValidForm:(XLFormDescriptor *)form account:(OTROAuthXMP // Override superclass to prevent password clash - (void) finishConnectingWithForm:(XLFormDescriptor *)form account:(OTRXMPPAccount *)account { [self prepareForXMPPConnectionFrom:form account:account]; - NSString *password = account.password; - [self.xmppManager connectWithPassword:password userInitiated:YES]; + [self.xmppManager connectUserInitiated:YES]; } @end diff --git a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRXMPPCreateAccountHandler.h b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRXMPPCreateAccountHandler.h index d5cfdf6cf..27d6df4a7 100644 --- a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRXMPPCreateAccountHandler.h +++ b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRXMPPCreateAccountHandler.h @@ -11,6 +11,4 @@ @interface OTRXMPPCreateAccountHandler : OTRXMPPLoginHandler -@property (nonatomic, strong) NSString *password; - @end diff --git a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRXMPPCreateAccountHandler.m b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRXMPPCreateAccountHandler.m index 21d8d0798..0cbe9c314 100644 --- a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRXMPPCreateAccountHandler.m +++ b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRXMPPCreateAccountHandler.m @@ -79,15 +79,17 @@ - (void) finishRegisteringWithForm:(XLFormDescriptor *)form account:(OTRAccount [self prepareForXMPPConnectionFrom:form account:(OTRXMPPAccount *)account]; XLFormRowDescriptor *passwordRow = [form formRowWithTag:kOTRXLFormPasswordTextFieldTag]; NSString *passwordFromForm = [passwordRow value]; + NSString *password = nil; if (passwordRow.sectionDescriptor.isHidden == NO && passwordRow.isHidden == NO && passwordFromForm.length > 0) { - _password = passwordFromForm; + password = passwordFromForm; } else { // if no password provided, generate a strong one - _password = [OTRPasswordGenerator passwordWithLength:11]; + password = [OTRPasswordGenerator passwordWithLength:11]; } - [self.xmppManager registerNewAccountWithPassword:self.password]; + account.password = password; + [self.xmppManager startRegisteringNewAccount]; } @end diff --git a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRXMPPLoginHandler.m b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRXMPPLoginHandler.m index 99bb233d7..7871c62cf 100644 --- a/ChatSecure/Classes/View Controllers/Login View Controllers/OTRXMPPLoginHandler.m +++ b/ChatSecure/Classes/View Controllers/Login View Controllers/OTRXMPPLoginHandler.m @@ -20,7 +20,6 @@ #import "OTRTorManager.h" @interface OTRXMPPLoginHandler() -@property (nonatomic, strong) NSString *password; @end @implementation OTRXMPPLoginHandler @@ -95,14 +94,11 @@ - (OTRXMPPAccount *)moveValues:(XLFormDescriptor *)form intoAccount:(OTRXMPPAcco NSString *password = [[form formRowWithTag:kOTRXLFormPasswordTextFieldTag] value]; if (password && password.length > 0) { - self.password = password; + account.password = password; } else if (account.password.length == 0) { // No password in field, generate strong password for user - self.password = [OTRPasswordGenerator passwordWithLength:20]; - } else { - self.password = account.password; + account.password = [OTRPasswordGenerator passwordWithLength:20]; } - NSNumber *autologin = [[form formRowWithTag:kOTRXLFormLoginAutomaticallySwitchTag] value]; if (autologin) { @@ -224,7 +220,10 @@ - (void)performActionWithValidForm:(XLFormDescriptor *)form account:(OTRXMPPAcco - (void) finishConnectingWithForm:(XLFormDescriptor *)form account:(OTRXMPPAccount *)account { [self prepareForXMPPConnectionFrom:form account:account]; NSString *password = [[form formRowWithTag:kOTRXLFormPasswordTextFieldTag] value]; - [self.xmppManager connectWithPassword:password userInitiated:YES]; + if (password.length > 0) { + account.password = password; + } + [self.xmppManager connectUserInitiated:YES]; } - (void)receivedNotification:(NSNotification *)notification @@ -233,10 +232,7 @@ - (void)receivedNotification:(NSNotification *)notification NSError *error = notification.userInfo[OTRXMPPLoginErrorKey]; OTRAccount *account = self.xmppManager.account; - if (newStatus == OTRLoginStatusAuthenticated) { - // Account has been created, so save the password - account.password = self.password; - + if (newStatus == OTRLoginStatusAuthenticated) { if (self.completion) { self.completion(account,nil); } diff --git a/ChatSecure/Classes/View Controllers/Onboarding/OTRWelcomeViewController.swift b/ChatSecure/Classes/View Controllers/Onboarding/OTRWelcomeViewController.swift index c874a9dd8..372a7da37 100644 --- a/ChatSecure/Classes/View Controllers/Onboarding/OTRWelcomeViewController.swift +++ b/ChatSecure/Classes/View Controllers/Onboarding/OTRWelcomeViewController.swift @@ -44,7 +44,7 @@ public class OTRWelcomeViewController: UIViewController { if segue.identifier == "createNewAccountSegue" { let createAccountVC: OTRBaseLoginViewController = segue.destinationViewController as! OTRBaseLoginViewController createAccountVC.form = OTRXLFormCreator.formForAccountType(OTRAccountType.Jabber, createAccount: true) - createAccountVC.createLoginHandler = OTRXMPPCreateAccountHandler() + createAccountVC.loginHandler = OTRXMPPCreateAccountHandler() } }