Skip to content

Commit

Permalink
Better Tor account creation and tor integration
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchiles committed Oct 24, 2014
1 parent 90a592c commit b6f8ef0
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 66 deletions.
18 changes: 16 additions & 2 deletions ChatSecure.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
634FF44C18D8EA2400022993 /* OTRComposeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 63AC173E18C7AA7A00E6624C /* OTRComposeViewController.m */; };
6350796719353635002C8A69 /* OTRYapPushTokenReceived.m in Sources */ = {isa = PBXBuildFile; fileRef = 6350796619353635002C8A69 /* OTRYapPushTokenReceived.m */; };
6350796A1935365A002C8A69 /* OTRYapPushTokenOwned.m in Sources */ = {isa = PBXBuildFile; fileRef = 635079691935365A002C8A69 /* OTRYapPushTokenOwned.m */; };
6350B3E819F865D100364C0A /* OTRDomainCellInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 6350B3E719F865D100364C0A /* OTRDomainCellInfo.m */; };
6352DC8815AF9F16007AD0B4 /* OTRNewAccountViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6352DC8715AF9F16007AD0B4 /* OTRNewAccountViewController.m */; };
636FE4B3161B76CF002B28EF /* OTRFacebookLoginViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 636FE4B2161B76CF002B28EF /* OTRFacebookLoginViewController.m */; };
636FE4B6161B76EA002B28EF /* OTRGoogleTalkLoginViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 636FE4B5161B76EA002B28EF /* OTRGoogleTalkLoginViewController.m */; };
Expand Down Expand Up @@ -352,6 +353,8 @@
6350796619353635002C8A69 /* OTRYapPushTokenReceived.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRYapPushTokenReceived.m; sourceTree = "<group>"; };
635079681935365A002C8A69 /* OTRYapPushTokenOwned.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRYapPushTokenOwned.h; sourceTree = "<group>"; };
635079691935365A002C8A69 /* OTRYapPushTokenOwned.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRYapPushTokenOwned.m; sourceTree = "<group>"; };
6350B3E619F865D100364C0A /* OTRDomainCellInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRDomainCellInfo.h; sourceTree = "<group>"; };
6350B3E719F865D100364C0A /* OTRDomainCellInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRDomainCellInfo.m; sourceTree = "<group>"; };
6352DC8615AF9F16007AD0B4 /* OTRNewAccountViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRNewAccountViewController.h; sourceTree = "<group>"; };
6352DC8715AF9F16007AD0B4 /* OTRNewAccountViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRNewAccountViewController.m; sourceTree = "<group>"; };
63534A54187B6F7F00061776 /* ChatSecure 4.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "ChatSecure 4.xcdatamodel"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -780,6 +783,15 @@
name = "OAUTH Login";
sourceTree = "<group>";
};
6350B3E519F865BB00364C0A /* View Models */ = {
isa = PBXGroup;
children = (
6350B3E619F865D100364C0A /* OTRDomainCellInfo.h */,
6350B3E719F865D100364C0A /* OTRDomainCellInfo.m */,
);
name = "View Models";
sourceTree = "<group>";
};
636FE4BD161B7733002B28EF /* LoginViewControllers */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -948,6 +960,7 @@
63CAF8F618FF260000C3337E /* Views */ = {
isa = PBXGroup;
children = (
6350B3E519F865BB00364C0A /* View Models */,
63CAF8F718FF260C00C3337E /* Cells */,
63CAF8FC18FF277200C3337E /* OTRLockButton.h */,
63CAF8FD18FF277200C3337E /* OTRLockButton.m */,
Expand Down Expand Up @@ -1650,6 +1663,7 @@
639C60C118CA988400CC4DF4 /* OTRLanguageSetting.m in Sources */,
634357F919143FF70062FD26 /* OTRDatabasePassphraseViewController.m in Sources */,
6335C0DB191059EB00E506E5 /* OTRPushAccountViewController.m in Sources */,
6350B3E819F865D100364C0A /* OTRDomainCellInfo.m in Sources */,
D987BAD91901A6CF005B2382 /* OTRPurchaseController.m in Sources */,
63D0BF5019BA35B3002FF6A4 /* OTRAcknowledgementsViewController.m in Sources */,
6397538618CA8222005D6063 /* OTRManagedOAuthAccount.m in Sources */,
Expand Down Expand Up @@ -1817,7 +1831,7 @@
"$(inherited)",
);
PRODUCT_NAME = ChatSecure;
PROVISIONING_PROFILE = "6e1ddacd-f2aa-4a68-9bed-a62b45a92c35";
PROVISIONING_PROFILE = "eba8b7bf-5edf-4e18-8d32-790efa92a02d";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
};
Expand Down Expand Up @@ -1862,7 +1876,7 @@
"$(inherited)",
);
PRODUCT_NAME = ChatSecure;
PROVISIONING_PROFILE = "1707f4f6-b9ad-48c2-8f53-4c11f8774921";
PROVISIONING_PROFILE = "eba8b7bf-5edf-4e18-8d32-790efa92a02d";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
};
Expand Down
26 changes: 6 additions & 20 deletions ChatSecure/OTRCreateAccountChooserViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,10 @@
#import "OTRXMPPCreateAccountViewController.h"
#import "UIAlertView+Blocks.h"
#import "OTRXMPPAccount.h"

@interface OTRCreateAccountChooserViewController ()

@property (nonatomic,strong) NSArray * defaultDomains;

@end
#import "OTRDomainCellInfo.h"

@implementation OTRCreateAccountChooserViewController

- (id)init
{
if (self = [super init]) {
self.defaultDomains = @[@"dukgo.com",@"jabber.ccc.de",@"jabberpl.org",@"neko.im",@"rkquery.de",@"xmpp.jp"];
}
return self;
}

- (NSArray*)accounts
{
return @[[OTRNewAccountViewController XMPPCellDictionary],
Expand Down Expand Up @@ -55,13 +42,12 @@ - (void)pushCreateAccountViewControllerWithAccountType:(OTRAccountType)accountTy
{
NSArray * hostnamesArray = nil;
OTRXMPPAccount * newAccount = (OTRXMPPAccount *)[OTRAccount accountForAccountType:accountType];
if(accountType == OTRAccountTypeJabber)
{
hostnamesArray = self.defaultDomains;

if(accountType == OTRAccountTypeJabber) {
hostnamesArray = [OTRDomainCellInfo defaultDomainCellInfoArray];
}
else if (accountType == OTRAccountTypeXMPPTor)
{
hostnamesArray = self.defaultDomains;
else if (accountType == OTRAccountTypeXMPPTor) {
hostnamesArray = [OTRDomainCellInfo defaultTorDomainCellInfoArray];
}

if ([hostnamesArray count]) {
Expand Down
28 changes: 28 additions & 0 deletions ChatSecure/OTRDomainCellInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// OTRDomainCellInfo.h
// ChatSecure
//
// Created by David Chiles on 10/22/14.
// Copyright (c) 2014 Chris Ballinger. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface OTRDomainCellInfo : NSObject

//Better display name for the server or orginization
@property (nonatomic, strong, readonly) NSString *displayName;

//The domain that should be appended to the username may differ from domain in some cases such as TOR
@property (nonatomic, strong, readonly) NSString *usernameDomain;

//The server domain to connect to
@property (nonatomic, strong, readonly) NSString *domain;


+ (instancetype) domainCellInfoWithDisplayName:(NSString *)displayName usernameDomain:(NSString *)usernameDomain domain:(NSString *)domain;

+ (NSArray *)defaultDomainCellInfoArray;
+ (NSArray *)defaultTorDomainCellInfoArray;

@end
71 changes: 71 additions & 0 deletions ChatSecure/OTRDomainCellInfo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// OTRDomainCellInfo.m
// ChatSecure
//
// Created by David Chiles on 10/22/14.
// Copyright (c) 2014 Chris Ballinger. All rights reserved.
//

#import "OTRDomainCellInfo.h"

@interface OTRDomainCellInfo ()

@property (nonatomic, strong) NSString *displayName;
@property (nonatomic, strong) NSString *domain;
@property (nonatomic, strong) NSString *usernameDomain;

@end

@implementation OTRDomainCellInfo

- (instancetype) initWithDisplayName:(NSString *)displayName usernameDomain:(NSString *)usernameDomain domain:(NSString *)domain
{
if (self = [self init]) {

self.domain = domain;

if ([displayName length]) {
self.displayName = displayName;
} else {
self.displayName = domain;
}

if ([usernameDomain length]) {
self.usernameDomain = usernameDomain;
} else {
self.usernameDomain = domain;
}


}
return self;
}

+ (instancetype) domainCellInfoWithDisplayName:(NSString *)displayName usernameDomain:(NSString *)usernameDomain domain:(NSString *)domain
{
return [[self alloc] initWithDisplayName:displayName usernameDomain:usernameDomain domain:domain];
}

+ (NSArray *)defaultDomainCellInfoArray
{
return @[[self domainCellInfoWithDisplayName:@"Dukgo" usernameDomain:nil domain:@"dukgo.com"],
[self domainCellInfoWithDisplayName:@"Computer Chaos Club" usernameDomain:nil domain:@"jabber.ccc.de"],
[self domainCellInfoWithDisplayName:@"The Calyx Institute" usernameDomain:nil domain:@"jabber.calyxinstitute.org"],
[self domainCellInfoWithDisplayName:nil usernameDomain:nil domain:@"jabberpl.org"],
[self domainCellInfoWithDisplayName:nil usernameDomain:nil domain:@"rkquery.de"],
[self domainCellInfoWithDisplayName:nil usernameDomain:nil domain:@"xmpp.jp"]
];
}
+ (NSArray *)defaultTorDomainCellInfoArray
{
return @[
[self domainCellInfoWithDisplayName:@"The Calyx Institute" usernameDomain:@"jabber.calyxinstitute.org" domain:@"ijeeynrc6x2uy5ob.onion"],
[self domainCellInfoWithDisplayName:@"Computer Chaos Club" usernameDomain:@"jabber.ccc.de" domain:@"okj7xc6j2szr2y75.onion"],
[self domainCellInfoWithDisplayName:@"Dukgo" usernameDomain:nil domain:@"dukgo.com"],
[self domainCellInfoWithDisplayName:nil usernameDomain:nil domain:@"jabberpl.org"],
[self domainCellInfoWithDisplayName:nil usernameDomain:nil domain:@"rkquery.de"],
[self domainCellInfoWithDisplayName:nil usernameDomain:nil domain:@"xmpp.jp"]
];
}

@end
2 changes: 0 additions & 2 deletions ChatSecure/OTRLoginViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ extern NSUInteger const kNewCertAlertViewTag;
@property (nonatomic, strong) UIBarButtonItem *loginButton;
@property (nonatomic, strong) UIBarButtonItem *cancelButton;

@property (nonatomic, strong) NSTimer * timeoutTimer;

@property (nonatomic, strong) NSMutableArray * tableViewArray;

@property (nonatomic, strong) UITableView * loginViewTableView;
Expand Down
14 changes: 1 addition & 13 deletions ChatSecure/OTRLoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ @interface OTRLoginViewController ()

@implementation OTRLoginViewController

- (void) dealloc {
[_timeoutTimer invalidate];
}

- (id) initWithAccount:(OTRAccount *)account{
if (self = [super init]) {
self.account = account;
Expand Down Expand Up @@ -360,11 +356,6 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}
}

-(void) timeout:(NSTimer *) timer
{
//[timeoutTimer invalidate];
[self hideHUD];
}
- (void)hideHUD {
if (self.HUD) {
[self.HUD hide:YES];
Expand Down Expand Up @@ -421,7 +412,6 @@ - (void)loginButtonPressed:(id)sender {
id<OTRProtocol> protocol = [[OTRProtocolManager sharedInstance] protocolForAccount:self.account];
[protocol connectWithPassword:self.passwordTextField.text];
}
self.timeoutTimer = [NSTimer scheduledTimerWithTimeInterval:45.0 target:self selector:@selector(timeout:) userInfo:nil repeats:NO];
}

- (void)showHUDWithText:(NSString *)text
Expand All @@ -431,11 +421,9 @@ - (void)showHUDWithText:(NSString *)text
self.HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:self.HUD];
}

self.HUD.mode = MBProgressHUDModeIndeterminate;
self.HUD.labelText = text;
[self.HUD show:YES];

self.timeoutTimer = [NSTimer scheduledTimerWithTimeInterval:45.0 target:self selector:@selector(timeout:) userInfo:nil repeats:NO];
}

- (void)cancelPressed:(id)sender {
Expand Down
3 changes: 0 additions & 3 deletions ChatSecure/OTRNewAccountViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
#import "OTRAccount.h"

@interface OTRNewAccountViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray * accountsCellArray;
}

- (NSArray *)accounts;
- (void)didSelectAccountType:(OTRAccountType)accountType;
Expand Down
10 changes: 6 additions & 4 deletions ChatSecure/OTRNewAccountViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

@interface OTRNewAccountViewController ()

@property (nonatomic, strong) NSArray *accountsCellArray;

@end

@implementation OTRNewAccountViewController
Expand All @@ -55,7 +57,7 @@ - (void)viewDidLoad



accountsCellArray = [self accounts];
self.accountsCellArray = [self accounts];

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:CANCEL_STRING style:UIBarButtonItemStyleBordered target:self action:@selector(cancelPressed:)];

Expand All @@ -76,7 +78,7 @@ -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [accountsCellArray count];
return [self.accountsCellArray count];

}

Expand All @@ -94,7 +96,7 @@ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary * cellAccount = [accountsCellArray objectAtIndex:indexPath.row];
NSDictionary * cellAccount = [self.accountsCellArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellAccount[kOTRDisplayNameKey];
cell.textLabel.font = [UIFont boldSystemFontOfSize:19];
cell.imageView.image = cellAccount[kOTRProviderImageKey];
Expand All @@ -117,7 +119,7 @@ -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];

OTRAccountType accountType = (OTRAccountType)[accountsCellArray[indexPath.row][kOTRAccountTypeKey] unsignedIntegerValue];
OTRAccountType accountType = (OTRAccountType)[self.accountsCellArray[indexPath.row][kOTRAccountTypeKey] unsignedIntegerValue];
[self didSelectAccountType:accountType];
}

Expand Down
3 changes: 2 additions & 1 deletion ChatSecure/OTRTorManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ - (instancetype) init {
NSBundle *cpaProxyBundle = [NSBundle bundleWithURL:cpaProxyBundleURL];
NSString *torrcPath = [cpaProxyBundle pathForResource:@"torrc" ofType:nil];
NSString *geoipPath = [cpaProxyBundle pathForResource:@"geoip" ofType:nil];
NSString *dataDirectory = [[[[[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask] lastObject] URLByAppendingPathComponent:@"com.ChatSecure.Tor"] path];

// Initialize a CPAProxyManager
CPAConfiguration *configuration = [CPAConfiguration configurationWithTorrcPath:torrcPath geoipPath:geoipPath torDataDirectoryPath:nil];
CPAConfiguration *configuration = [CPAConfiguration configurationWithTorrcPath:torrcPath geoipPath:geoipPath torDataDirectoryPath:dataDirectory];
self.torManager = [CPAProxyManager proxyWithConfiguration:configuration];
}
return self;
Expand Down
Loading

0 comments on commit b6f8ef0

Please sign in to comment.