summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-05-06 21:02:59 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-05-06 21:02:59 -0700
commit4426899e8c9469518325f39f173151b3535ac20e (patch)
treeef4253b6b083075ae721e354c0e01ee7b938cda8
parentd56e9fce415e5b764091921dd5cedde175fbcf7d (diff)
downloadinfinitytier-4426899e8c9469518325f39f173151b3535ac20e.tar.gz
infinitytier-4426899e8c9469518325f39f173151b3535ac20e.zip
Add support for local user account caching of authtoken.secret as in old UI -- this is now pretty much working.
-rwxr-xr-x.gitignore2
-rw-r--r--ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/project.xcworkspace/xcuserdata/api.xcuserdatad/UserInterfaceState.xcuserstatebin19568 -> 0 bytes
-rw-r--r--ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/xcuserdata/api.xcuserdatad/xcschemes/MacGap.xcscheme88
-rw-r--r--ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/xcuserdata/api.xcuserdatad/xcschemes/xcschememanagement.plist22
-rw-r--r--ext/mac-ui-macgap1-wrapper/MacGap/AppDelegate.m153
5 files changed, 95 insertions, 170 deletions
diff --git a/.gitignore b/.gitignore
index f789b3b7..4a24c4db 100755
--- a/.gitignore
+++ b/.gitignore
@@ -39,4 +39,4 @@
/root-topology/*.secret
/root-topology/test/supernodes
/root-topology/test/test-root-topology
-xcuserdata
+/ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/project.xcworkspace/xcuserdata/*
diff --git a/ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/project.xcworkspace/xcuserdata/api.xcuserdatad/UserInterfaceState.xcuserstate b/ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/project.xcworkspace/xcuserdata/api.xcuserdatad/UserInterfaceState.xcuserstate
deleted file mode 100644
index 6dfcf6d0..00000000
--- a/ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/project.xcworkspace/xcuserdata/api.xcuserdatad/UserInterfaceState.xcuserstate
+++ /dev/null
Binary files differ
diff --git a/ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/xcuserdata/api.xcuserdatad/xcschemes/MacGap.xcscheme b/ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/xcuserdata/api.xcuserdatad/xcschemes/MacGap.xcscheme
deleted file mode 100644
index 2555dc89..00000000
--- a/ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/xcuserdata/api.xcuserdatad/xcschemes/MacGap.xcscheme
+++ /dev/null
@@ -1,88 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<Scheme
- LastUpgradeVersion = "0630"
- version = "1.3">
- <BuildAction
- parallelizeBuildables = "YES"
- buildImplicitDependencies = "YES">
- <BuildActionEntries>
- <BuildActionEntry
- buildForTesting = "YES"
- buildForRunning = "YES"
- buildForProfiling = "YES"
- buildForArchiving = "YES"
- buildForAnalyzing = "YES">
- <BuildableReference
- BuildableIdentifier = "primary"
- BlueprintIdentifier = "FAE451B914BA79C600190544"
- BuildableName = "ZeroTier One.app"
- BlueprintName = "MacGap"
- ReferencedContainer = "container:MacGap.xcodeproj">
- </BuildableReference>
- </BuildActionEntry>
- </BuildActionEntries>
- </BuildAction>
- <TestAction
- selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
- selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
- shouldUseLaunchSchemeArgsEnv = "YES"
- buildConfiguration = "Debug">
- <Testables>
- </Testables>
- <MacroExpansion>
- <BuildableReference
- BuildableIdentifier = "primary"
- BlueprintIdentifier = "FAE451B914BA79C600190544"
- BuildableName = "ZeroTier One.app"
- BlueprintName = "MacGap"
- ReferencedContainer = "container:MacGap.xcodeproj">
- </BuildableReference>
- </MacroExpansion>
- </TestAction>
- <LaunchAction
- selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
- selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
- launchStyle = "0"
- useCustomWorkingDirectory = "NO"
- buildConfiguration = "Debug"
- ignoresPersistentStateOnLaunch = "NO"
- debugDocumentVersioning = "YES"
- allowLocationSimulation = "YES">
- <BuildableProductRunnable
- runnableDebuggingMode = "0">
- <BuildableReference
- BuildableIdentifier = "primary"
- BlueprintIdentifier = "FAE451B914BA79C600190544"
- BuildableName = "ZeroTier One.app"
- BlueprintName = "MacGap"
- ReferencedContainer = "container:MacGap.xcodeproj">
- </BuildableReference>
- </BuildableProductRunnable>
- <AdditionalOptions>
- </AdditionalOptions>
- </LaunchAction>
- <ProfileAction
- shouldUseLaunchSchemeArgsEnv = "YES"
- savedToolIdentifier = ""
- useCustomWorkingDirectory = "NO"
- buildConfiguration = "Release"
- debugDocumentVersioning = "YES">
- <BuildableProductRunnable
- runnableDebuggingMode = "0">
- <BuildableReference
- BuildableIdentifier = "primary"
- BlueprintIdentifier = "FAE451B914BA79C600190544"
- BuildableName = "ZeroTier One.app"
- BlueprintName = "MacGap"
- ReferencedContainer = "container:MacGap.xcodeproj">
- </BuildableReference>
- </BuildableProductRunnable>
- </ProfileAction>
- <AnalyzeAction
- buildConfiguration = "Debug">
- </AnalyzeAction>
- <ArchiveAction
- buildConfiguration = "Release"
- revealArchiveInOrganizer = "YES">
- </ArchiveAction>
-</Scheme>
diff --git a/ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/xcuserdata/api.xcuserdatad/xcschemes/xcschememanagement.plist b/ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/xcuserdata/api.xcuserdatad/xcschemes/xcschememanagement.plist
deleted file mode 100644
index 921f1a6f..00000000
--- a/ext/mac-ui-macgap1-wrapper/MacGap.xcodeproj/xcuserdata/api.xcuserdatad/xcschemes/xcschememanagement.plist
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
- <key>SchemeUserState</key>
- <dict>
- <key>MacGap.xcscheme</key>
- <dict>
- <key>orderHint</key>
- <integer>0</integer>
- </dict>
- </dict>
- <key>SuppressBuildableAutocreation</key>
- <dict>
- <key>FAE451B914BA79C600190544</key>
- <dict>
- <key>primary</key>
- <true/>
- </dict>
- </dict>
-</dict>
-</plist>
diff --git a/ext/mac-ui-macgap1-wrapper/MacGap/AppDelegate.m b/ext/mac-ui-macgap1-wrapper/MacGap/AppDelegate.m
index 96a3e820..3e25ca13 100644
--- a/ext/mac-ui-macgap1-wrapper/MacGap/AppDelegate.m
+++ b/ext/mac-ui-macgap1-wrapper/MacGap/AppDelegate.m
@@ -7,6 +7,8 @@
//
#import "AppDelegate.h"
+#include <sys/stat.h>
+#include <sys/types.h>
@implementation AppDelegate
@@ -29,75 +31,108 @@
}
- (void) applicationDidFinishLaunching:(NSNotification *)aNotification {
- // Create authorization reference
- OSStatus status;
- AuthorizationRef authorizationRef;
-
- // AuthorizationCreate and pass NULL as the initial
- // AuthorizationRights set so that the AuthorizationRef gets created
- // successfully, and then later call AuthorizationCopyRights to
- // determine or extend the allowable rights.
- // http://developer.apple.com/qa/qa2001/qa1172.html
- status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef);
- if (status != errAuthorizationSuccess)
- {
- NSLog(@"Error Creating Initial Authorization: %d", status);
- return;
- }
-
- // kAuthorizationRightExecute == "system.privilege.admin"
- AuthorizationItem right = {kAuthorizationRightExecute, 0, NULL, 0};
- AuthorizationRights rights = {1, &right};
- AuthorizationFlags flags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed |
- kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights;
-
- // Call AuthorizationCopyRights to determine or extend the allowable rights.
- status = AuthorizationCopyRights(authorizationRef, &rights, NULL, flags, NULL);
- if (status != errAuthorizationSuccess)
- {
- NSLog(@"Copy Rights Unsuccessful: %d", status);
- return;
- }
-
- // use rm tool with -rf
- char *tool = "/bin/cat";
- char *args[] = {"/Library/Application Support/ZeroTier/One/authtoken.secret", NULL};
- FILE *pipe = NULL;
-
- status = AuthorizationExecuteWithPrivileges(authorizationRef, tool, kAuthorizationFlagDefaults, args, &pipe);
- if (status != errAuthorizationSuccess)
- {
- NSLog(@"Error: %d", status);
- }
-
- char url[16384];
- memset(url,0,sizeof(url));
- if (pipe) {
- char buf[16384];
+ char buf[16384],userAuthTokenPath[4096];
- FILE *pf = fopen("/Library/Application Support/ZeroTier/One/zerotier-one.port","r");
+ FILE *pf = fopen("/Library/Application Support/ZeroTier/One/zerotier-one.port","r");
+ long port = 9993; // default
+ if (pf) {
long n = fread(buf,1,sizeof(buf)-1,pf);
- long port = 9993; // default
if (n > 0) {
buf[n] = (char)0;
port = strtol(buf,(char **)0,10);
}
fclose(pf);
+ }
- n = (long)fread(buf,1,sizeof(buf)-1,pipe);
- if (n > 0) {
- buf[n] = (char)0;
- snprintf(url,sizeof(url),"http://127.0.0.1:%ld/index.html?authToken=%s",port,buf);
+ char url[16384];
+ memset(url,0,sizeof(url));
+
+ const char *homeDir = getenv("HOME");
+ if (homeDir) {
+ snprintf(userAuthTokenPath,sizeof(userAuthTokenPath),"%s/Library/Application Support/ZeroTier/One/authtoken.secret",homeDir);
+ pf = fopen(userAuthTokenPath,"r");
+ if (pf) {
+ long n = fread(buf,1,sizeof(buf)-1,pf);
+ if (n > 0) {
+ buf[n] = (char)0;
+ snprintf(url,sizeof(url),"http://127.0.0.1:%ld/index.html?authToken=%s",port,buf);
+ }
+ fclose(pf);
+ }
+ }
+
+ if (!url[0]) {
+ // Create authorization reference
+ OSStatus status;
+ AuthorizationRef authorizationRef;
+
+ // AuthorizationCreate and pass NULL as the initial
+ // AuthorizationRights set so that the AuthorizationRef gets created
+ // successfully, and then later call AuthorizationCopyRights to
+ // determine or extend the allowable rights.
+ // http://developer.apple.com/qa/qa2001/qa1172.html
+ status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef);
+ if (status != errAuthorizationSuccess)
+ {
+ NSLog(@"Error Creating Initial Authorization: %d", status);
+ return;
+ }
+
+ // kAuthorizationRightExecute == "system.privilege.admin"
+ AuthorizationItem right = {kAuthorizationRightExecute, 0, NULL, 0};
+ AuthorizationRights rights = {1, &right};
+ AuthorizationFlags flags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed |
+ kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights;
+
+ // Call AuthorizationCopyRights to determine or extend the allowable rights.
+ status = AuthorizationCopyRights(authorizationRef, &rights, NULL, flags, NULL);
+ if (status != errAuthorizationSuccess)
+ {
+ NSLog(@"Copy Rights Unsuccessful: %d", status);
+ return;
}
- fclose(pipe);
+
+ // use rm tool with -rf
+ char *tool = "/bin/cat";
+ char *args[] = {"/Library/Application Support/ZeroTier/One/authtoken.secret", NULL};
+ FILE *pipe = NULL;
+
+ status = AuthorizationExecuteWithPrivileges(authorizationRef, tool, kAuthorizationFlagDefaults, args, &pipe);
+ if (status != errAuthorizationSuccess)
+ {
+ NSLog(@"Error: %d", status);
+ }
+
+ if (pipe) {
+ long n = (long)fread(buf,1,sizeof(buf)-1,pipe);
+ if (n > 0) {
+ buf[n] = (char)0;
+ snprintf(url,sizeof(url),"http://127.0.0.1:%ld/index.html?authToken=%s",port,buf);
+
+ if (homeDir) {
+ snprintf(userAuthTokenPath,sizeof(userAuthTokenPath),"%s/Library/Application Support/ZeroTier",homeDir);
+ mkdir(userAuthTokenPath,0755);
+ snprintf(userAuthTokenPath,sizeof(userAuthTokenPath),"%s/Library/Application Support/ZeroTier/One",homeDir);
+ mkdir(userAuthTokenPath,0755);
+ snprintf(userAuthTokenPath,sizeof(userAuthTokenPath),"%s/Library/Application Support/ZeroTier/One/authtoken.secret",homeDir);
+ pf = fopen(userAuthTokenPath,"w");
+ if (pf) {
+ fwrite(buf,1,strlen(buf),pf);
+ fclose(pf);
+ chmod(userAuthTokenPath,0600);
+ }
+ }
+ }
+ fclose(pipe);
+ }
+
+ // The only way to guarantee that a credential acquired when you
+ // request a right is not shared with other authorization instances is
+ // to destroy the credential. To do so, call the AuthorizationFree
+ // function with the flag kAuthorizationFlagDestroyRights.
+ // http://developer.apple.com/documentation/Security/Conceptual/authorization_concepts/02authconcepts/chapter_2_section_7.html
+ status = AuthorizationFree(authorizationRef, kAuthorizationFlagDestroyRights);
}
-
- // The only way to guarantee that a credential acquired when you
- // request a right is not shared with other authorization instances is
- // to destroy the credential. To do so, call the AuthorizationFree
- // function with the flag kAuthorizationFlagDestroyRights.
- // http://developer.apple.com/documentation/Security/Conceptual/authorization_concepts/02authconcepts/chapter_2_section_7.html
- status = AuthorizationFree(authorizationRef, kAuthorizationFlagDestroyRights);
NSString *urlStr = [[NSString alloc] initWithCString:url];
self.windowController = [[WindowController alloc] initWithURL: urlStr];