summaryrefslogtreecommitdiff
path: root/macui
diff options
context:
space:
mode:
authorGrant Limberg <grant.limberg@zerotier.com>2017-03-22 09:58:13 -0700
committerGrant Limberg <grant.limberg@zerotier.com>2017-03-22 09:58:13 -0700
commitd72eee6cf710601ef2f164a01aba6afdbcfb1fca (patch)
treee284672740eecfd33a8a027797b510c6971359b2 /macui
parent6bb19e7947bfa955afb288126158fe0155ebd7f4 (diff)
downloadinfinitytier-d72eee6cf710601ef2f164a01aba6afdbcfb1fca.tar.gz
infinitytier-d72eee6cf710601ef2f164a01aba6afdbcfb1fca.zip
If we get a 401 error from the ZeroTier service in the macOS UI, try re-copying the auth token
Diffstat (limited to 'macui')
-rw-r--r--macui/ZeroTier One/ServiceCom.h1
-rw-r--r--macui/ZeroTier One/ServiceCom.m40
2 files changed, 40 insertions, 1 deletions
diff --git a/macui/ZeroTier One/ServiceCom.h b/macui/ZeroTier One/ServiceCom.h
index 74ab2b35..c2b4692f 100644
--- a/macui/ZeroTier One/ServiceCom.h
+++ b/macui/ZeroTier One/ServiceCom.h
@@ -26,6 +26,7 @@
NSString *baseURL;
NSURLSession *session;
BOOL _isQuitting;
+ BOOL _resetKey;
}
+ (ServiceCom*)sharedInstance;
diff --git a/macui/ZeroTier One/ServiceCom.m b/macui/ZeroTier One/ServiceCom.m
index dd03b3f7..06d676bb 100644
--- a/macui/ZeroTier One/ServiceCom.m
+++ b/macui/ZeroTier One/ServiceCom.m
@@ -46,6 +46,7 @@
baseURL = @"http://127.0.0.1:9993";
session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
_isQuitting = NO;
+ _resetKey = NO;
}
return self;
@@ -54,6 +55,37 @@
- (NSString*)key:(NSError* __autoreleasing *)err
{
static NSString *k = nil;
+ static NSUInteger resetCount = 10;
+
+ if (_resetKey && k != nil) {
+ k = nil;
+ ++resetCount;
+ NSLog(@"ResetCount: %lu", (unsigned long)resetCount);
+ if (resetCount > 10) {
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ NSAlert *alert = [NSAlert alertWithMessageText:@"Error obtaining Auth Token"
+ defaultButton:@"Quit"
+ alternateButton:@"Retry"
+ otherButton:nil
+ informativeTextWithFormat:@"Please ensure ZeroTier is installed correctly"];
+ alert.alertStyle = NSCriticalAlertStyle;
+
+ NSModalResponse res;
+ if (!_isQuitting) {
+ res = [alert runModal];
+ }
+ else {
+ return;
+ }
+
+ if(res == 1) {
+ _isQuitting = YES;
+ [NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
+ }
+ }];
+ return @"";
+ }
+ }
if (k == nil) {
NSError *error = nil;
@@ -67,10 +99,12 @@
appSupportDir = [[appSupportDir URLByAppendingPathComponent:@"ZeroTier"] URLByAppendingPathComponent:@"One"];
NSURL *authtokenURL = [appSupportDir URLByAppendingPathComponent:@"authtoken.secret"];
- if ([[NSFileManager defaultManager] fileExistsAtPath:[authtokenURL path]]) {
+ if (!_resetKey && [[NSFileManager defaultManager] fileExistsAtPath:[authtokenURL path]]) {
k = [NSString stringWithContentsOfURL:authtokenURL
encoding:NSUTF8StringEncoding
error:&error];
+
+ k = [k stringByReplacingOccurrencesOfString:@"\n" withString:@""];
if (error) {
NSLog(@"Error: %@", error);
@@ -80,6 +114,7 @@
}
}
else {
+ _resetKey = NO;
NSURL *sysAppSupportDir = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSSystemDomainMask appropriateForURL:nil create:false error:nil];
sysAppSupportDir = [[sysAppSupportDir URLByAppendingPathComponent:@"ZeroTier"] URLByAppendingPathComponent:@"One"];
@@ -249,6 +284,9 @@
completionHandler(networks);
}
+ else if (status == 401) {
+ self->_resetKey = YES;
+ }
}];
[task resume];
}