summaryrefslogtreecommitdiff
path: root/ZeroTier One/ServiceCom.swift
diff options
context:
space:
mode:
authorGrant Limberg <grant.limberg@red.com>2016-05-31 17:19:22 -0700
committerGrant Limberg <grant.limberg@red.com>2016-05-31 17:23:11 -0700
commit975bcb8affa7fbd7ca534dac9ec8d642e6c977f7 (patch)
tree75f5f57d31302fddf2bc20d54bb6713fe08f873e /ZeroTier One/ServiceCom.swift
parent51e74f8d4f200a7e3be9a6ac4bef8486f83a5d5d (diff)
downloadinfinitytier-975bcb8affa7fbd7ca534dac9ec8d642e6c977f7.tar.gz
infinitytier-975bcb8affa7fbd7ca534dac9ec8d642e6c977f7.zip
some OS X Authentication Services wizardry to get /Library/Application Support/ZeroTier/One/authtoken.secret and copy it to ~/Library/Application Support/ZeroTier/One/authtoken.secret
Diffstat (limited to 'ZeroTier One/ServiceCom.swift')
-rw-r--r--ZeroTier One/ServiceCom.swift31
1 files changed, 30 insertions, 1 deletions
diff --git a/ZeroTier One/ServiceCom.swift b/ZeroTier One/ServiceCom.swift
index 3aa9dc54..e2526610 100644
--- a/ZeroTier One/ServiceCom.swift
+++ b/ZeroTier One/ServiceCom.swift
@@ -30,7 +30,36 @@ class ServiceCom: NSObject {
Holder.key = try String(contentsOfURL: authtokenURL)
}
else {
- // TODO: Elevate priviledge to copy /Library/Application Support/ZeroTier/One/authtoken.secret to the user's local AppSupport directory
+ try NSFileManager.defaultManager().createDirectoryAtURL(appSupportDir, withIntermediateDirectories: true, attributes: nil)
+
+ var authRef: AuthorizationRef = nil
+ var status = AuthorizationCreate(nil, nil, .Defaults, &authRef)
+
+ if status != errAuthorizationSuccess {
+ NSLog("Authorization Failed! \(status)")
+ return ""
+ }
+
+ var authItem = AuthorizationItem(name: kAuthorizationRightExecute, valueLength: 0, value: nil, flags: 0)
+ var authRights = AuthorizationRights(count: 1, items: &authItem)
+ let authFlags: AuthorizationFlags = [.Defaults, .InteractionAllowed, .PreAuthorize, .ExtendRights]
+
+ status = AuthorizationCopyRights(authRef, &authRights, nil, authFlags, nil)
+
+ if status != errAuthorizationSuccess {
+ NSLog("Authorization Failed! \(status)")
+ return ""
+ }
+
+ let localKey = getAdminAuthToken(authRef)
+ AuthorizationFree(authRef, .DestroyRights)
+
+ if localKey != nil && localKey.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0 {
+ NSLog("\(localKey)")
+ Holder.key = localKey
+
+ try localKey.writeToURL(authtokenURL, atomically: true, encoding: NSUTF8StringEncoding)
+ }
}
}
catch {