From 9d82e7587aac8215de70f51fb29324a4bac391aa Mon Sep 17 00:00:00 2001 From: Chris Ballinger Date: Sun, 13 Apr 2014 17:39:11 -0700 Subject: [PATCH] Open utun device --- CBTunService/Actions.h | 16 + CBTunService/CBTunService-Info.plist | 18 + CBTunService/CBTunService-Launchd.plist | 13 + CBTunService/PrivilegedAgent.h | 16 + CBTunService/PrivilegedAgent.m | 94 +++ CBTunService/PrivilegedServiceDelegate.h | 13 + CBTunService/PrivilegedServiceDelegate.m | 23 + CBTunService/main.m | 70 ++ PodSpecs/libplist.podspec | 19 - PodSpecs/libusbmuxd.podspec | 20 - Tether.xcodeproj/project.pbxproj | 289 ++++---- Tether/CBDeviceWindowController.m | 94 ++- Tether/CBMacAppDelegate.m | 4 + Tether/CBTunDevice.h | 16 - Tether/CBTunDevice.m | 121 ---- Tether/TetherMac-Info.plist | 5 + Tether/UTUN.h | 13 - Tether/UTUN.m | 868 ----------------------- TetherTests/TetherTests-Info.plist | 22 - TetherTests/TetherTests.m | 34 - TetherTests/en.lproj/InfoPlist.strings | 2 - 21 files changed, 531 insertions(+), 1239 deletions(-) create mode 100644 CBTunService/Actions.h create mode 100644 CBTunService/CBTunService-Info.plist create mode 100644 CBTunService/CBTunService-Launchd.plist create mode 100644 CBTunService/PrivilegedAgent.h create mode 100644 CBTunService/PrivilegedAgent.m create mode 100644 CBTunService/PrivilegedServiceDelegate.h create mode 100644 CBTunService/PrivilegedServiceDelegate.m create mode 100644 CBTunService/main.m delete mode 100644 PodSpecs/libplist.podspec delete mode 100644 PodSpecs/libusbmuxd.podspec delete mode 100644 Tether/CBTunDevice.h delete mode 100644 Tether/CBTunDevice.m delete mode 100644 Tether/UTUN.h delete mode 100644 Tether/UTUN.m delete mode 100644 TetherTests/TetherTests-Info.plist delete mode 100644 TetherTests/TetherTests.m delete mode 100644 TetherTests/en.lproj/InfoPlist.strings diff --git a/CBTunService/Actions.h b/CBTunService/Actions.h new file mode 100644 index 0000000..c7e4acb --- /dev/null +++ b/CBTunService/Actions.h @@ -0,0 +1,16 @@ +// +// Actions.h +// SMJobBless +// +// Created by Ludovic Delaveau on 8/5/12. +// +// + +#import + +@protocol TunHandler + +- (void)openTun:(void (^)(NSFileHandle *tun, NSError *error))reply; +- (void)closeTun; + +@end diff --git a/CBTunService/CBTunService-Info.plist b/CBTunService/CBTunService-Info.plist new file mode 100644 index 0000000..96eff8d --- /dev/null +++ b/CBTunService/CBTunService-Info.plist @@ -0,0 +1,18 @@ + + + + + CFBundleIdentifier + com.chrisballinger.CBTunService + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + CBTunService + CFBundleVersion + 1.1 + SMAuthorizedClients + + identifier com.chrisballinger.TetherMac and certificate leaf[subject.CN] = "3rd Party Mac Developer Application" + + + diff --git a/CBTunService/CBTunService-Launchd.plist b/CBTunService/CBTunService-Launchd.plist new file mode 100644 index 0000000..dc36e32 --- /dev/null +++ b/CBTunService/CBTunService-Launchd.plist @@ -0,0 +1,13 @@ + + + + + Label + com.chrisballinger.CBTunService + MachServices + + com.chrisballinger.CBTunService + + + + diff --git a/CBTunService/PrivilegedAgent.h b/CBTunService/PrivilegedAgent.h new file mode 100644 index 0000000..ef376f3 --- /dev/null +++ b/CBTunService/PrivilegedAgent.h @@ -0,0 +1,16 @@ +// +// PrivilegedActions.h +// SMJobBless +// +// Created by Ludovic Delaveau on 8/5/12. +// +// + +#import +#import "Actions.h" + +@interface PrivilegedAgent : NSObject + +@property (nonatomic, strong) NSFileHandle *tunHandle; + +@end diff --git a/CBTunService/PrivilegedAgent.m b/CBTunService/PrivilegedAgent.m new file mode 100644 index 0000000..772b171 --- /dev/null +++ b/CBTunService/PrivilegedAgent.m @@ -0,0 +1,94 @@ +// +// PrivilegedActions.m +// SMJobBless +// +// Created by Ludovic Delaveau on 8/5/12. +// +// + +#import +#import +#import "PrivilegedAgent.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include // exit, etc. + +int +tun(void) +{ + struct sockaddr_ctl sc; + struct ctl_info ctlInfo; + int fd; + + + memset(&ctlInfo, 0, sizeof(ctlInfo)); + if (strlcpy(ctlInfo.ctl_name, UTUN_CONTROL_NAME, sizeof(ctlInfo.ctl_name)) >= + sizeof(ctlInfo.ctl_name)) { + fprintf(stderr,"UTUN_CONTROL_NAME too long"); + return -1; + } + fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL); + + if (fd == -1) { + perror ("socket(SYSPROTO_CONTROL)"); + return -1; + } + if (ioctl(fd, CTLIOCGINFO, &ctlInfo) == -1) { + perror ("ioctl(CTLIOCGINFO)"); + close(fd); + return -1; + } + + sc.sc_id = ctlInfo.ctl_id; + sc.sc_len = sizeof(sc); + sc.sc_family = AF_SYSTEM; + sc.ss_sysaddr = AF_SYS_CONTROL; + sc.sc_unit = 2; /* Only have one, in this example... */ + + + // If the connect is successful, a tun%d device will be created, where "%d" + // is our unit number -1 + + if (connect(fd, (struct sockaddr *)&sc, sizeof(sc)) == -1) { + perror ("connect(AF_SYS_CONTROL)"); + close(fd); + return -1; + } + return fd; +} + +@implementation PrivilegedAgent + +- (void)openTun:(void (^)(NSFileHandle *tun, NSError *error))reply { + [self closeTun]; + int utunfd = tun(); + + NSError * error = nil; + + if (utunfd != -1) { + self.tunHandle = [[NSFileHandle alloc] initWithFileDescriptor:utunfd closeOnDealloc:YES]; + } else { + error = [NSError errorWithDomain:@"com.chrisballinger.CBTunService" code:100 userInfo:@{NSLocalizedDescriptionKey: @"Error opening TUN fd"}]; + } + + if (reply) { + reply(self.tunHandle, error); + } +} + +- (void)closeTun { + self.tunHandle = nil; +} + +@end diff --git a/CBTunService/PrivilegedServiceDelegate.h b/CBTunService/PrivilegedServiceDelegate.h new file mode 100644 index 0000000..6a61a4e --- /dev/null +++ b/CBTunService/PrivilegedServiceDelegate.h @@ -0,0 +1,13 @@ +// +// PrivilegedServiceDelegate.h +// SMJobBless +// +// Created by Ludovic Delaveau on 8/5/12. +// +// + +#import + +@interface PrivilegedServiceDelegate : NSObject + +@end diff --git a/CBTunService/PrivilegedServiceDelegate.m b/CBTunService/PrivilegedServiceDelegate.m new file mode 100644 index 0000000..a63046d --- /dev/null +++ b/CBTunService/PrivilegedServiceDelegate.m @@ -0,0 +1,23 @@ +// +// PrivilegedServiceDelegate.m +// SMJobBless +// +// Created by Ludovic Delaveau on 8/5/12. +// +// + +#import "PrivilegedServiceDelegate.h" +#import "Actions.h" +#import "PrivilegedAgent.h" + +@implementation PrivilegedServiceDelegate + +- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection { + newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(TunHandler)]; + newConnection.exportedObject = [[PrivilegedAgent alloc] init]; + [newConnection resume]; + + return YES; +} + +@end diff --git a/CBTunService/main.m b/CBTunService/main.m new file mode 100644 index 0000000..61f1471 --- /dev/null +++ b/CBTunService/main.m @@ -0,0 +1,70 @@ +/* + + File: SMJobBlessHelper.c +Abstract: A helper tool that doesn't do anything event remotely interesting. +See the ssd sample for how to use GCD and launchd to set up an on-demand +server via sockets. + Version: 1.2 + +Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple +Inc. ("Apple") in consideration of your agreement to the following +terms, and your use, installation, modification or redistribution of +this Apple software constitutes acceptance of these terms. If you do +not agree with these terms, please do not use, install, modify or +redistribute this Apple software. + +In consideration of your agreement to abide by the following terms, and +subject to these terms, Apple grants you a personal, non-exclusive +license, under Apple's copyrights in this original Apple software (the +"Apple Software"), to use, reproduce, modify and redistribute the Apple +Software, with or without modifications, in source and/or binary forms; +provided that if you redistribute the Apple Software in its entirety and +without modifications, you must retain this notice and the following +text and disclaimers in all such redistributions of the Apple Software. +Neither the name, trademarks, service marks or logos of Apple Inc. may +be used to endorse or promote products derived from the Apple Software +without specific prior written permission from Apple. Except as +expressly stated in this notice, no other rights or licenses, express or +implied, are granted by Apple herein, including but not limited to any +patent rights that may be infringed by your derivative works or by other +works in which the Apple Software may be incorporated. + +The Apple Software is provided by Apple on an "AS IS" basis. APPLE +MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. + +IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +Copyright (C) 2011 Apple Inc. All Rights Reserved. + + +*/ + +#import +#import +#import + +#import "PrivilegedServiceDelegate.h" + +int main(int argc, const char *argv[]) { + @autoreleasepool { + NSXPCListener *service = [[NSXPCListener alloc] initWithMachServiceName:@"com.chrisballinger.CBTunService"]; + PrivilegedServiceDelegate *serviceDelegate = [[PrivilegedServiceDelegate alloc] init]; + service.delegate = serviceDelegate; + [service resume]; + + dispatch_main(); + + return EXIT_SUCCESS; + } +} + diff --git a/PodSpecs/libplist.podspec b/PodSpecs/libplist.podspec deleted file mode 100644 index 43f634b..0000000 --- a/PodSpecs/libplist.podspec +++ /dev/null @@ -1,19 +0,0 @@ -Pod::Spec.new do |s| - s.name = 'libplist' - s.version = '1.11' - s.summary = 'A library to handle Apple Property List format in binary or XML' - - s.homepage = 'https://github.com/libimobiledevice/libplist' - s.license = { :type => 'LGPL2.1+', :file => 'COPYING.LESSER' } - - s.authors = { 'Chris Ballinger' => 'chris@chatsecure.org'} # Podspec maintainer - s.platform = :osx, '10.7' - s.source = { :git => 'https://github.com/libimobiledevice/libplist.git', :tag => s.version.to_s} - s.source_files = 'src/*.{h,c,m,cpp}', 'libcnary/*.{h,c,m,cpp}', 'libcnary/include/*.h' - s.public_header_files = 'include/*.h' - s.library = 'xml2' - s.preserve_paths = 'include/plist/*.*' - s.xcconfig = {"HEADER_SEARCH_PATHS" => '"$(SDKROOT)/usr/include/libxml2" "${PODS_ROOT}/libplist/include/"'} - s.requires_arc = false -end - diff --git a/PodSpecs/libusbmuxd.podspec b/PodSpecs/libusbmuxd.podspec deleted file mode 100644 index bbf742b..0000000 --- a/PodSpecs/libusbmuxd.podspec +++ /dev/null @@ -1,20 +0,0 @@ -Pod::Spec.new do |s| - s.name = 'libusbmuxd' - s.version = '1.0.9' - s.summary = 'A client library to multiplex connections from and to iOS devices' - - s.homepage = 'https://github.com/libimobiledevice/libusbmuxd' - s.license = { :type => 'LGPL2.1+', :file => 'COPYING.LGPLv2.1' } - - s.authors = { 'Chris Ballinger' => 'chris@chatsecure.org'} # Podspec maintainer - s.platform = :osx, '10.7' - s.source = { :git => 'https://github.com/libimobiledevice/libusbmuxd.git', :tag => s.version.to_s} - s.source_files = 'src/*.{h,c}', 'include/*.h' - s.public_header_files = 'include/*.h' - #s.preserve_paths = 'include/*.h' - s.dependency 'libplist', '~> 1.11' - s.xcconfig = {'OTHER_CFLAGS' => '$(inherited) -DHAS_PLIST', - 'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/libplist/include/"'} - s.requires_arc = false -end - diff --git a/Tether.xcodeproj/project.pbxproj b/Tether.xcodeproj/project.pbxproj index 11e4e32..2d05979 100644 --- a/Tether.xcodeproj/project.pbxproj +++ b/Tether.xcodeproj/project.pbxproj @@ -19,7 +19,12 @@ D931A611183012D600593FF9 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D931A610183012D600593FF9 /* Security.framework */; }; D931A61418304D1200593FF9 /* CBDeviceConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = D931A61318304D1200593FF9 /* CBDeviceConnection.m */; }; D950871618F6836900EF884A /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2CDD1E9FE263401C93089B68 /* libPods.a */; }; - D95309DA18CBE31E00393DB4 /* CBTunDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = D95309D918CBE31E00393DB4 /* CBTunDevice.m */; }; + D9792EE518FB563F002F2E28 /* ServiceManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9792EE418FB563F002F2E28 /* ServiceManagement.framework */; }; + D9792EF318FB58E2002F2E28 /* CBTunService.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = D9792EF218FB58E2002F2E28 /* CBTunService.1 */; }; + D9792EF718FB593A002F2E28 /* PrivilegedAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = D9792EDE18FB4DCF002F2E28 /* PrivilegedAgent.m */; }; + D9792EF818FB593A002F2E28 /* PrivilegedServiceDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D9792EE018FB4DCF002F2E28 /* PrivilegedServiceDelegate.m */; }; + D9792EF918FB593A002F2E28 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D9792ED618FB4CCE002F2E28 /* main.m */; }; + D9792EFC18FB59CB002F2E28 /* com.chrisballinger.CBTunService in CopyFiles */ = {isa = PBXBuildFile; fileRef = D9792EEE18FB58E2002F2E28 /* com.chrisballinger.CBTunService */; }; D9B7679B184A8734000566D6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9B7679A184A8734000566D6 /* Foundation.framework */; }; D9B7679D184A8734000566D6 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9B7679C184A8734000566D6 /* CoreGraphics.framework */; }; D9B7679F184A8734000566D6 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9B7679E184A8734000566D6 /* UIKit.framework */; }; @@ -27,11 +32,6 @@ D9B767A7184A8734000566D6 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D9B767A6184A8734000566D6 /* main.m */; }; D9B767AB184A8734000566D6 /* CBAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D9B767AA184A8734000566D6 /* CBAppDelegate.m */; }; D9B767AD184A8734000566D6 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D9B767AC184A8734000566D6 /* Images.xcassets */; }; - D9B767B3184A8734000566D6 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D90E3277182F07DC00A6F642 /* XCTest.framework */; }; - D9B767B4184A8734000566D6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9B7679A184A8734000566D6 /* Foundation.framework */; }; - D9B767B5184A8735000566D6 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9B7679E184A8734000566D6 /* UIKit.framework */; }; - D9B767BD184A8735000566D6 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D9B767BB184A8735000566D6 /* InfoPlist.strings */; }; - D9B767BF184A8735000566D6 /* TetherTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D9B767BE184A8735000566D6 /* TetherTests.m */; }; D9B767C9184A88BA000566D6 /* main-mac.m in Sources */ = {isa = PBXBuildFile; fileRef = D9B767C8184A88BA000566D6 /* main-mac.m */; }; D9B767CC184A8991000566D6 /* CBRootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D9B767CB184A8991000566D6 /* CBRootViewController.m */; }; D9B767D2184A8B32000566D6 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9B767D1184A8B32000566D6 /* MobileCoreServices.framework */; }; @@ -43,15 +43,38 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - D9B767B6184A8735000566D6 /* PBXContainerItemProxy */ = { + D9792EFA18FB59C4002F2E28 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = D90E324D182F07DC00A6F642 /* Project object */; proxyType = 1; - remoteGlobalIDString = D9B76798184A8734000566D6; - remoteInfo = Tether; + remoteGlobalIDString = D9792EED18FB58E2002F2E28; + remoteInfo = com.chrisballinger.CBTunService; }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + D9792EE818FB5744002F2E28 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = Contents/Library/LaunchServices; + dstSubfolderSpec = 1; + files = ( + D9792EFC18FB59CB002F2E28 /* com.chrisballinger.CBTunService in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D9792EEC18FB58E2002F2E28 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + D9792EF318FB58E2002F2E28 /* CBTunService.1 in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 2CDD1E9FE263401C93089B68 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 3344A729C1604CC882D91F05 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = ""; }; @@ -77,10 +100,18 @@ D931A610183012D600593FF9 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; D931A61218304D1200593FF9 /* CBDeviceConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CBDeviceConnection.h; sourceTree = ""; }; D931A61318304D1200593FF9 /* CBDeviceConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CBDeviceConnection.m; sourceTree = ""; }; - D940D2541855A2D200DBA886 /* UTUN.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTUN.h; sourceTree = ""; }; - D940D2551855A2D200DBA886 /* UTUN.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UTUN.m; sourceTree = ""; }; - D95309D818CBE31E00393DB4 /* CBTunDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CBTunDevice.h; sourceTree = ""; }; - D95309D918CBE31E00393DB4 /* CBTunDevice.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CBTunDevice.m; sourceTree = ""; }; + D9792ED118FB4CCE002F2E28 /* CBTunService-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CBTunService-Info.plist"; sourceTree = ""; }; + D9792ED618FB4CCE002F2E28 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + D9792EDB18FB4DCF002F2E28 /* Actions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Actions.h; sourceTree = ""; }; + D9792EDC18FB4DCF002F2E28 /* CBTunService-Launchd.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "CBTunService-Launchd.plist"; sourceTree = ""; }; + D9792EDD18FB4DCF002F2E28 /* PrivilegedAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrivilegedAgent.h; sourceTree = ""; }; + D9792EDE18FB4DCF002F2E28 /* PrivilegedAgent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PrivilegedAgent.m; sourceTree = ""; }; + D9792EDF18FB4DCF002F2E28 /* PrivilegedServiceDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrivilegedServiceDelegate.h; sourceTree = ""; }; + D9792EE018FB4DCF002F2E28 /* PrivilegedServiceDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PrivilegedServiceDelegate.m; sourceTree = ""; }; + D9792EE418FB563F002F2E28 /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; }; + D9792EEE18FB58E2002F2E28 /* com.chrisballinger.CBTunService */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = com.chrisballinger.CBTunService; sourceTree = BUILT_PRODUCTS_DIR; }; + D9792EF018FB58E2002F2E28 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; + D9792EF218FB58E2002F2E28 /* CBTunService.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = CBTunService.1; sourceTree = ""; }; D9B76799184A8734000566D6 /* Tether.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tether.app; sourceTree = BUILT_PRODUCTS_DIR; }; D9B7679A184A8734000566D6 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; D9B7679C184A8734000566D6 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -92,7 +123,6 @@ D9B767A9184A8734000566D6 /* CBAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CBAppDelegate.h; sourceTree = ""; }; D9B767AA184A8734000566D6 /* CBAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CBAppDelegate.m; sourceTree = ""; }; D9B767AC184A8734000566D6 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; - D9B767B2184A8734000566D6 /* TetherTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TetherTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; D9B767BA184A8735000566D6 /* TetherTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "TetherTests-Info.plist"; sourceTree = ""; }; D9B767BC184A8735000566D6 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; D9B767BE184A8735000566D6 /* TetherTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TetherTests.m; sourceTree = ""; }; @@ -116,6 +146,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + D9792EE518FB563F002F2E28 /* ServiceManagement.framework in Frameworks */, D931A611183012D600593FF9 /* Security.framework in Frameworks */, D9D81107182F83DD003DCCBB /* libxml2.dylib in Frameworks */, D90E3259182F07DC00A6F642 /* Cocoa.framework in Frameworks */, @@ -123,25 +154,22 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - D9B76796184A8734000566D6 /* Frameworks */ = { + D9792EEB18FB58E2002F2E28 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - D950871618F6836900EF884A /* libPods.a in Frameworks */, - D9B767D2184A8B32000566D6 /* MobileCoreServices.framework in Frameworks */, - D9B7679D184A8734000566D6 /* CoreGraphics.framework in Frameworks */, - D9B7679F184A8734000566D6 /* UIKit.framework in Frameworks */, - D9B7679B184A8734000566D6 /* Foundation.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; - D9B767AF184A8734000566D6 /* Frameworks */ = { + D9B76796184A8734000566D6 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - D9B767B3184A8734000566D6 /* XCTest.framework in Frameworks */, - D9B767B5184A8735000566D6 /* UIKit.framework in Frameworks */, - D9B767B4184A8734000566D6 /* Foundation.framework in Frameworks */, + D950871618F6836900EF884A /* libPods.a in Frameworks */, + D9B767D2184A8B32000566D6 /* MobileCoreServices.framework in Frameworks */, + D9B7679D184A8734000566D6 /* CoreGraphics.framework in Frameworks */, + D9B7679F184A8734000566D6 /* UIKit.framework in Frameworks */, + D9B7679B184A8734000566D6 /* Foundation.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -153,8 +181,10 @@ children = ( D9B767C7184A877A000566D6 /* USBMuxClient */, D90E325E182F07DC00A6F642 /* TetherMac */, - D9B767A0184A8734000566D6 /* Tether */, + D9B767A0184A8734000566D6 /* Tether-iOS */, D9B767B8184A8735000566D6 /* TetherTests */, + D9792ECF18FB4CCE002F2E28 /* CBTunService */, + D9792EEF18FB58E2002F2E28 /* CBTunService */, D90E3257182F07DC00A6F642 /* Frameworks */, D90E3256182F07DC00A6F642 /* Products */, 3344A729C1604CC882D91F05 /* Pods.xcconfig */, @@ -166,7 +196,7 @@ children = ( D90E3255182F07DC00A6F642 /* TetherMac.app */, D9B76799184A8734000566D6 /* Tether.app */, - D9B767B2184A8734000566D6 /* TetherTests.xctest */, + D9792EEE18FB58E2002F2E28 /* com.chrisballinger.CBTunService */, ); name = Products; sourceTree = ""; @@ -174,6 +204,7 @@ D90E3257182F07DC00A6F642 /* Frameworks */ = { isa = PBXGroup; children = ( + D9792EE418FB563F002F2E28 /* ServiceManagement.framework */, D9C40B4718F67BF2005CD748 /* libPods-libplist.a */, D9B767D1184A8B32000566D6 /* MobileCoreServices.framework */, D931A610183012D600593FF9 /* Security.framework */, @@ -202,8 +233,6 @@ D90E325E182F07DC00A6F642 /* TetherMac */ = { isa = PBXGroup; children = ( - D95309D818CBE31E00393DB4 /* CBTunDevice.h */, - D95309D918CBE31E00393DB4 /* CBTunDevice.m */, D9FEA97F18EA6E6C00EA736D /* CBNetworkServiceEditor.h */, D9FEA98018EA6E6C00EA736D /* CBNetworkServiceEditor.m */, D90E326A182F07DC00A6F642 /* CBMacAppDelegate.h */, @@ -234,7 +263,39 @@ name = "Supporting Files"; sourceTree = ""; }; - D9B767A0184A8734000566D6 /* Tether */ = { + D9792ECF18FB4CCE002F2E28 /* CBTunService */ = { + isa = PBXGroup; + children = ( + D9792EDB18FB4DCF002F2E28 /* Actions.h */, + D9792EDD18FB4DCF002F2E28 /* PrivilegedAgent.h */, + D9792EDE18FB4DCF002F2E28 /* PrivilegedAgent.m */, + D9792EDF18FB4DCF002F2E28 /* PrivilegedServiceDelegate.h */, + D9792EE018FB4DCF002F2E28 /* PrivilegedServiceDelegate.m */, + D9792ED618FB4CCE002F2E28 /* main.m */, + D9792ED018FB4CCE002F2E28 /* Supporting Files */, + ); + path = CBTunService; + sourceTree = ""; + }; + D9792ED018FB4CCE002F2E28 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + D9792EDC18FB4DCF002F2E28 /* CBTunService-Launchd.plist */, + D9792ED118FB4CCE002F2E28 /* CBTunService-Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + D9792EEF18FB58E2002F2E28 /* CBTunService */ = { + isa = PBXGroup; + children = ( + D9792EF018FB58E2002F2E28 /* main.c */, + D9792EF218FB58E2002F2E28 /* CBTunService.1 */, + ); + path = CBTunService; + sourceTree = ""; + }; + D9B767A0184A8734000566D6 /* Tether-iOS */ = { isa = PBXGroup; children = ( D9B767CA184A8991000566D6 /* CBRootViewController.h */, @@ -244,6 +305,7 @@ D9B767AC184A8734000566D6 /* Images.xcassets */, D9B767A1184A8734000566D6 /* Supporting Files */, ); + name = "Tether-iOS"; path = Tether; sourceTree = ""; }; @@ -279,8 +341,6 @@ D9B767C7184A877A000566D6 /* USBMuxClient */ = { isa = PBXGroup; children = ( - D940D2541855A2D200DBA886 /* UTUN.h */, - D940D2551855A2D200DBA886 /* UTUN.m */, D9B767D7184A978A000566D6 /* USBMuxDevice.h */, D9B767D8184A978A000566D6 /* USBMuxDevice.m */, D9B767D4184A9432000566D6 /* USBMuxDeviceConnection.h */, @@ -304,16 +364,35 @@ D90E3252182F07DC00A6F642 /* Frameworks */, D90E3253182F07DC00A6F642 /* Resources */, 551353FA86374048AD71A2B9 /* Copy Pods Resources */, + D9792EE818FB5744002F2E28 /* CopyFiles */, ); buildRules = ( ); dependencies = ( + D9792EFB18FB59C4002F2E28 /* PBXTargetDependency */, ); name = TetherMac; productName = Tether; productReference = D90E3255182F07DC00A6F642 /* TetherMac.app */; productType = "com.apple.product-type.application"; }; + D9792EED18FB58E2002F2E28 /* com.chrisballinger.CBTunService */ = { + isa = PBXNativeTarget; + buildConfigurationList = D9792EF418FB58E2002F2E28 /* Build configuration list for PBXNativeTarget "com.chrisballinger.CBTunService" */; + buildPhases = ( + D9792EEA18FB58E2002F2E28 /* Sources */, + D9792EEB18FB58E2002F2E28 /* Frameworks */, + D9792EEC18FB58E2002F2E28 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = com.chrisballinger.CBTunService; + productName = CBTunService; + productReference = D9792EEE18FB58E2002F2E28 /* com.chrisballinger.CBTunService */; + productType = "com.apple.product-type.tool"; + }; D9B76798184A8734000566D6 /* Tether */ = { isa = PBXNativeTarget; buildConfigurationList = D9B767C0184A8735000566D6 /* Build configuration list for PBXNativeTarget "Tether" */; @@ -331,24 +410,6 @@ productReference = D9B76799184A8734000566D6 /* Tether.app */; productType = "com.apple.product-type.application"; }; - D9B767B1184A8734000566D6 /* TetherTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = D9B767C3184A8735000566D6 /* Build configuration list for PBXNativeTarget "TetherTests" */; - buildPhases = ( - D9B767AE184A8734000566D6 /* Sources */, - D9B767AF184A8734000566D6 /* Frameworks */, - D9B767B0184A8734000566D6 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - D9B767B7184A8735000566D6 /* PBXTargetDependency */, - ); - name = TetherTests; - productName = TetherTests; - productReference = D9B767B2184A8734000566D6 /* TetherTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -366,9 +427,6 @@ }; }; }; - D9B767B1184A8734000566D6 = { - TestTargetID = D90E3254182F07DC00A6F642; - }; }; }; buildConfigurationList = D90E3250182F07DC00A6F642 /* Build configuration list for PBXProject "Tether" */; @@ -386,7 +444,7 @@ targets = ( D90E3254182F07DC00A6F642 /* TetherMac */, D9B76798184A8734000566D6 /* Tether */, - D9B767B1184A8734000566D6 /* TetherTests */, + D9792EED18FB58E2002F2E28 /* com.chrisballinger.CBTunService */, ); }; /* End PBXProject section */ @@ -413,14 +471,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - D9B767B0184A8734000566D6 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - D9B767BD184A8735000566D6 /* InfoPlist.strings in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ @@ -469,35 +519,36 @@ D931A61418304D1200593FF9 /* CBDeviceConnection.m in Sources */, D9D8110A182F8B80003DCCBB /* USBMuxClient.m in Sources */, D9FEA98118EA6E6C00EA736D /* CBNetworkServiceEditor.m in Sources */, - D95309DA18CBE31E00393DB4 /* CBTunDevice.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; - D9B76795184A8734000566D6 /* Sources */ = { + D9792EEA18FB58E2002F2E28 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - D9B767A7184A8734000566D6 /* main.m in Sources */, - D9B767AB184A8734000566D6 /* CBAppDelegate.m in Sources */, - D9B767CC184A8991000566D6 /* CBRootViewController.m in Sources */, + D9792EF718FB593A002F2E28 /* PrivilegedAgent.m in Sources */, + D9792EF818FB593A002F2E28 /* PrivilegedServiceDelegate.m in Sources */, + D9792EF918FB593A002F2E28 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; - D9B767AE184A8734000566D6 /* Sources */ = { + D9B76795184A8734000566D6 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - D9B767BF184A8735000566D6 /* TetherTests.m in Sources */, + D9B767A7184A8734000566D6 /* main.m in Sources */, + D9B767AB184A8734000566D6 /* CBAppDelegate.m in Sources */, + D9B767CC184A8991000566D6 /* CBRootViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - D9B767B7184A8735000566D6 /* PBXTargetDependency */ = { + D9792EFB18FB59C4002F2E28 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = D9B76798184A8734000566D6 /* Tether */; - targetProxy = D9B767B6184A8735000566D6 /* PBXContainerItemProxy */; + target = D9792EED18FB58E2002F2E28 /* com.chrisballinger.CBTunService */; + targetProxy = D9792EFA18FB59C4002F2E28 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -618,6 +669,7 @@ baseConfigurationReference = 3344A729C1604CC882D91F05 /* Pods.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; COMBINE_HIDPI_IMAGES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Tether/TetherMac-Prefix.pch"; @@ -642,6 +694,7 @@ baseConfigurationReference = 3344A729C1604CC882D91F05 /* Pods.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; COMBINE_HIDPI_IMAGES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Tether/TetherMac-Prefix.pch"; @@ -661,62 +714,58 @@ }; name = Release; }; - D9B767C1184A8735000566D6 /* Debug */ = { + D9792EF518FB58E2002F2E28 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CLANG_ENABLE_MODULES = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(DEVELOPER_FRAMEWORKS_DIR)", - ); - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "Tether/Tether-Prefix.pch"; + CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = "Tether/Tether-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + OTHER_LDFLAGS = ( + "-sectcreate", + __TEXT, + __info_plist, + "CBTunService/CBTunService-Info.plist", + "-sectcreate", + __TEXT, + __launchd_plist, + "CBTunService/CBTunService-Launchd.plist", + ); PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - WRAPPER_EXTENSION = app; }; name = Debug; }; - D9B767C2184A8735000566D6 /* Release */ = { + D9792EF618FB58E2002F2E28 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CLANG_ENABLE_MODULES = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(DEVELOPER_FRAMEWORKS_DIR)", + CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + OTHER_LDFLAGS = ( + "-sectcreate", + __TEXT, + __info_plist, + "CBTunService/CBTunService-Info.plist", + "-sectcreate", + __TEXT, + __launchd_plist, + "CBTunService/CBTunService-Launchd.plist", ); - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "Tether/Tether-Prefix.pch"; - INFOPLIST_FILE = "Tether/Tether-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - VALIDATE_PRODUCT = YES; - WRAPPER_EXTENSION = app; }; name = Release; }; - D9B767C4184A8735000566D6 /* Debug */ = { + D9B767C1184A8735000566D6 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/TetherMac.app/Contents/MacOS/TetherMac"; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", "$(DEVELOPER_FRAMEWORKS_DIR)", ); @@ -726,34 +775,35 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = "TetherTests/TetherTests-Info.plist"; + INFOPLIST_FILE = "Tether/Tether-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 7.0; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; - TEST_HOST = "$(BUNDLE_LOADER)"; - WRAPPER_EXTENSION = xctest; + TARGETED_DEVICE_FAMILY = "1,2"; + WRAPPER_EXTENSION = app; }; name = Debug; }; - D9B767C5184A8735000566D6 /* Release */ = { + D9B767C2184A8735000566D6 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/TetherMac.app/Contents/MacOS/TetherMac"; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", "$(DEVELOPER_FRAMEWORKS_DIR)", ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Tether/Tether-Prefix.pch"; - INFOPLIST_FILE = "TetherTests/TetherTests-Info.plist"; + INFOPLIST_FILE = "Tether/Tether-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 7.0; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; - TEST_HOST = "$(BUNDLE_LOADER)"; + TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; - WRAPPER_EXTENSION = xctest; + WRAPPER_EXTENSION = app; }; name = Release; }; @@ -778,20 +828,19 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - D9B767C0184A8735000566D6 /* Build configuration list for PBXNativeTarget "Tether" */ = { + D9792EF418FB58E2002F2E28 /* Build configuration list for PBXNativeTarget "com.chrisballinger.CBTunService" */ = { isa = XCConfigurationList; buildConfigurations = ( - D9B767C1184A8735000566D6 /* Debug */, - D9B767C2184A8735000566D6 /* Release */, + D9792EF518FB58E2002F2E28 /* Debug */, + D9792EF618FB58E2002F2E28 /* Release */, ); defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; }; - D9B767C3184A8735000566D6 /* Build configuration list for PBXNativeTarget "TetherTests" */ = { + D9B767C0184A8735000566D6 /* Build configuration list for PBXNativeTarget "Tether" */ = { isa = XCConfigurationList; buildConfigurations = ( - D9B767C4184A8735000566D6 /* Debug */, - D9B767C5184A8735000566D6 /* Release */, + D9B767C1184A8735000566D6 /* Debug */, + D9B767C2184A8735000566D6 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; diff --git a/Tether/CBDeviceWindowController.m b/Tether/CBDeviceWindowController.m index bd420e0..d9fbc9c 100644 --- a/Tether/CBDeviceWindowController.m +++ b/Tether/CBDeviceWindowController.m @@ -10,7 +10,9 @@ #import "USBMuxClient.h" #import "USBMuxDevice.h" #import "CBDeviceConnection.h" -#import "CBTunDevice.h" +#import +#import +#import "Actions.h" const static uint16_t kDefaultLocalPortNumber = 8000; const static uint16_t kDefaultRemotePortNumber = 8123; @@ -95,8 +97,95 @@ - (void)windowDidLoad // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. [USBMuxClient sharedClient].delegate = self; [self performSelector:@selector(refreshButtonPressed:) withObject:nil afterDelay:0.1]; // for whatever reason + + NSString *helperLabel = @"com.chrisballinger.CBTunService"; + + NSError *error = nil; + if (![self blessHelperWithLabel:helperLabel error:&error]) { + NSLog(@"Failed to bless helper. Error: %@", error); + } + + NSXPCConnection *connection = [[NSXPCConnection alloc] initWithMachServiceName:helperLabel options:NSXPCConnectionPrivileged]; + connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(TunHandler)]; + [connection resume]; + + [[connection remoteObjectProxyWithErrorHandler:^(NSError *error) { + NSLog(@"Something bad happened, %@", [error description]); + }] openTun:^(NSFileHandle *tun, NSError *error) { + if (tun) { + NSLog(@"Got handle: %@\nfd: %d", tun, tun.fileDescriptor); + } else { + NSLog(@"Couldn't get handle: %@", error); + } + }]; } +- (BOOL)blessHelperWithLabel:(NSString *)label + error:(NSError **)error { + + BOOL result = NO; + + /* Always remove the job if we've previously submitted it. This is to help with versioning (we always install the latest tool). It also avoids conflicts where the installed tool was signed with a different key (i.e. someone building Hex Fiend while also having run the signed distribution). A potentially negative consequence is that we have to authenticate every launch, but that is actually a benefit, because it serves as a sort of notification that user's action requires elevated privileges, instead of just (potentially silently) doing it. */ + BOOL helperIsAlreadyInstalled = NO; + CFDictionaryRef existingJob = SMJobCopyDictionary(kSMDomainSystemLaunchd, (__bridge CFStringRef)(label)); + if (existingJob) { + helperIsAlreadyInstalled = YES; + CFRelease(existingJob); + } + + AuthorizationItem authItems[2] = {{ kSMRightBlessPrivilegedHelper, 0, NULL, 0 }, { kSMRightModifySystemDaemons, 0, NULL, 0 }}; + AuthorizationRights authRights = { (helperIsAlreadyInstalled ? 2 : 1), authItems }; + AuthorizationFlags flags = kAuthorizationFlagDefaults | + kAuthorizationFlagInteractionAllowed | + kAuthorizationFlagPreAuthorize | + kAuthorizationFlagExtendRights; + + AuthorizationRef authRef = NULL; + + /* Obtain the right to install privileged helper tools (kSMRightBlessPrivilegedHelper). */ + OSStatus status = AuthorizationCreate(&authRights, kAuthorizationEmptyEnvironment, flags, &authRef); + if (status != errAuthorizationSuccess) { + if (error) { + if (status == errAuthorizationCanceled) { + *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:nil]; + } else { + NSString *description = [NSString stringWithFormat:@"Failed to create AuthorizationRef (error code %ld).", (long)status]; + *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadNoPermissionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:description, NSLocalizedDescriptionKey, nil]]; + } + } + return NO; + } + + /* This does all the work of verifying the helper tool against the application + * and vice-versa. Once verification has passed, the embedded launchd.plist + * is extracted and placed in /Library/LaunchDaemons and then loaded. The + * executable is placed in /Library/PrivilegedHelperTools. + */ + + /* Remove the existing helper. If this fails it's not a fatal error (SMJobBless can handle the case when a job is already installed). */ + if (helperIsAlreadyInstalled) { + CFErrorRef localError = NULL; + SMJobRemove(kSMDomainSystemLaunchd, (__bridge CFStringRef)(label), authRef, true /* wait */, &localError); + if (localError) { + NSLog(@"SMJobRemove() failed with error %@", localError); + CFRelease(localError); + } + } + + + CFErrorRef localError = NULL; + result = SMJobBless(kSMDomainSystemLaunchd, (__bridge CFStringRef)label, authRef, (CFErrorRef *)&localError); + if (localError) { + if (error) { + *error = (__bridge NSError*)localError; + } + CFRelease(localError); + } + + return result; +} + + // The only essential/required tableview dataSource method - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { @@ -131,9 +220,6 @@ - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn } - (IBAction)refreshButtonPressed:(id)sender { - CBTunDevice *tunDevice = [[CBTunDevice alloc] init]; - [tunDevice openTun]; - if (self.listeningSocket) { NSLog(@"Disconnecting local socket"); [self.listeningSocket disconnect]; diff --git a/Tether/CBMacAppDelegate.m b/Tether/CBMacAppDelegate.m index cb214ed..072c09e 100644 --- a/Tether/CBMacAppDelegate.m +++ b/Tether/CBMacAppDelegate.m @@ -18,4 +18,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification [self.deviceWindowController.window makeKeyAndOrderFront:self]; } +- (void) applicationWillTerminate:(NSNotification *)notification { + NSLog(@"Application will terminate"); +} + @end \ No newline at end of file diff --git a/Tether/CBTunDevice.h b/Tether/CBTunDevice.h deleted file mode 100644 index af37b14..0000000 --- a/Tether/CBTunDevice.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// CBTunDevice.h -// Tether -// -// Created by Christopher Ballinger on 3/8/14. -// Copyright (c) 2014 Christopher Ballinger. All rights reserved. -// - -#import - -@interface CBTunDevice : NSObject - -- (void) openTun; -- (void) closeTun; - -@end diff --git a/Tether/CBTunDevice.m b/Tether/CBTunDevice.m deleted file mode 100644 index 23d1fb1..0000000 --- a/Tether/CBTunDevice.m +++ /dev/null @@ -1,121 +0,0 @@ -// -// CBTunDevice.m -// Tether -// -// Created by Christopher Ballinger on 3/8/14. -// Copyright (c) 2014 Christopher Ballinger. All rights reserved. -// - -#import "CBTunDevice.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -int -tun(void) -{ - struct sockaddr_ctl sc; - struct ctl_info ctlInfo; - int fd; - - - memset(&ctlInfo, 0, sizeof(ctlInfo)); - if (strlcpy(ctlInfo.ctl_name, UTUN_CONTROL_NAME, sizeof(ctlInfo.ctl_name)) >= - sizeof(ctlInfo.ctl_name)) { - fprintf(stderr,"UTUN_CONTROL_NAME too long"); - return -1; - } - fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL); - - if (fd == -1) { - perror ("socket(SYSPROTO_CONTROL)"); - return -1; - } - if (ioctl(fd, CTLIOCGINFO, &ctlInfo) == -1) { - perror ("ioctl(CTLIOCGINFO)"); - close(fd); - return -1; - } - - sc.sc_id = ctlInfo.ctl_id; - sc.sc_len = sizeof(sc); - sc.sc_family = AF_SYSTEM; - sc.ss_sysaddr = AF_SYS_CONTROL; - sc.sc_unit = 2; /* Only have one, in this example... */ - - - // If the connect is successful, a tun%d device will be created, where "%d" - // is our unit number -1 - - if (connect(fd, (struct sockaddr *)&sc, sizeof(sc)) == -1) { - perror ("connect(AF_SYS_CONTROL)"); - close(fd); - return -1; - } - return fd; -} - -@interface CBTunDevice() -@property (nonatomic) int utunFileDescriptor; -@end - - -@implementation CBTunDevice - -- (void) dealloc { - [self closeTun]; -} - -- (void) closeTun { - if (!_utunFileDescriptor) { - return; - } - close(_utunFileDescriptor); - _utunFileDescriptor = 0; -} - -- (void) openTun { - [self closeTun]; - self.utunFileDescriptor = tun (); - - if (_utunFileDescriptor == -1) - { - fprintf(stderr,"Unable to establish UTUN descriptor - aborting\n"); - [self closeTun]; - return; - } - - fprintf(stderr,"Utun interface is up.. Configure IPv4 using \"ifconfig utun1 _ipA_ _ipB_\"\n"); - fprintf(stderr," Configure IPv6 using \"ifconfig utun1 inet6 _ip6_\"\n"); - fprintf(stderr,"Then (e.g.) ping _ipB_ (IPv6 will automatically generate ND messages)\n"); - - - // PoC - Just dump the packets... - for (;;) - { - unsigned char c[1500]; - ssize_t len; - int i; - - len = read (_utunFileDescriptor,c, 1500); - - // First 4 bytes of read data are the AF: 2 for AF_INET, 1E for AF_INET6, etc.. - for (i = 4; i< len; i++) - { - printf ("%02x ", c[i]); - if ( (i-4)%16 ==15) printf("\n"); - } - printf ("\n"); - } -} - -@end diff --git a/Tether/TetherMac-Info.plist b/Tether/TetherMac-Info.plist index ebba39f..d10d763 100644 --- a/Tether/TetherMac-Info.plist +++ b/Tether/TetherMac-Info.plist @@ -28,6 +28,11 @@ Copyright © 2013 Christopher Ballinger. All rights reserved. NSMainNibFile MainMenu + SMPrivilegedExecutables + + com.chrisballinger.CBTunService + identifier com.chrisballinger.CBTunService and certificate leaf[subject.CN] = "3rd Party Mac Developer Application" + NSPrincipalClass NSApplication diff --git a/Tether/UTUN.h b/Tether/UTUN.h deleted file mode 100644 index eb9a9e4..0000000 --- a/Tether/UTUN.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// UTUN.h -// Tether -// -// Created by Christopher Ballinger on 12/8/13. -// Copyright (c) 2013 Christopher Ballinger. All rights reserved. -// - -#import - -@interface UTUN : NSObject - -@end diff --git a/Tether/UTUN.m b/Tether/UTUN.m deleted file mode 100644 index 73a09c5..0000000 --- a/Tether/UTUN.m +++ /dev/null @@ -1,868 +0,0 @@ -// -// UTUN.m -// Tether -// -// Created by Christopher Ballinger on 12/8/13. -// Copyright (c) 2013 Christopher Ballinger. All rights reserved. -// - -#import "UTUN.h" -#import -#import -#import -#import -#import -#import -#import - -/* - * Allocate a string - */ -char * -string_alloc (const char *str) -{ - if (str) - { - const long n = strlen (str) + 1; - char *ret; - - ret = calloc(1, n); - - memcpy (ret, str, n); - return ret; - } - else - return NULL; -} - -#define DEV_TYPE_TUN 2 /* point-to-point IP tunnel */ - - -struct tuntap_options { - /* --ip-win32 options */ - bool ip_win32_defined; - -# define IPW32_SET_MANUAL 0 /* "--ip-win32 manual" */ -# define IPW32_SET_NETSH 1 /* "--ip-win32 netsh" */ -# define IPW32_SET_IPAPI 2 /* "--ip-win32 ipapi" */ -# define IPW32_SET_DHCP_MASQ 3 /* "--ip-win32 dynamic" */ -# define IPW32_SET_ADAPTIVE 4 /* "--ip-win32 adaptive" */ -# define IPW32_SET_N 5 - int ip_win32_type; - - /* --ip-win32 dynamic options */ - bool dhcp_masq_custom_offset; - int dhcp_masq_offset; - int dhcp_lease_time; - - /* --tap-sleep option */ - int tap_sleep; - - /* --dhcp-option options */ - - bool dhcp_options; - - const char *domain; /* DOMAIN (15) */ - - const char *netbios_scope; /* NBS (47) */ - - int netbios_node_type; /* NBT 1,2,4,8 (46) */ - -#define N_DHCP_ADDR 4 /* Max # of addresses allowed for -DNS, WINS, etc. */ - - /* DNS (6) */ - in_addr_t dns[N_DHCP_ADDR]; - int dns_len; - - /* WINS (44) */ - in_addr_t wins[N_DHCP_ADDR]; - int wins_len; - - /* NTP (42) */ - in_addr_t ntp[N_DHCP_ADDR]; - int ntp_len; - - /* NBDD (45) */ - in_addr_t nbdd[N_DHCP_ADDR]; - int nbdd_len; - - /* DISABLE_NBT (43, Vendor option 001) */ - bool disable_nbt; - - bool dhcp_renew; - bool dhcp_pre_release; - bool dhcp_release; - - bool register_dns; -}; - -/* - * Define a TUN/TAP dev. - */ - -struct tuntap -{ -# define TUNNEL_TYPE(tt) ((tt) ? ((tt)->type) : DEV_TYPE_UNDEF) - int type; /* DEV_TYPE_x as defined in proto.h */ - -# define TUNNEL_TOPOLOGY(tt) ((tt) ? ((tt)->topology) : TOP_UNDEF) - int topology; /* one of the TOP_x values */ - - bool did_ifconfig_setup; - bool did_ifconfig_ipv6_setup; - bool did_ifconfig; - - bool ipv6; - - bool persistent_if; /* if existed before, keep on program end */ - - struct tuntap_options options; /* options set on command line */ - - char *actual_name; /* actual name of TUN/TAP dev, usually including unit number */ - - /* number of TX buffers */ - int txqueuelen; - - /* ifconfig parameters */ - in_addr_t local; - in_addr_t remote_netmask; - in_addr_t broadcast; - - struct in6_addr local_ipv6; - struct in6_addr remote_ipv6; - int netbits_ipv6; - - int fd; /* file descriptor for TUN/TAP dev */ - - bool is_utun; - /* used for printing status info only */ - unsigned int rwflags_debug; - - /* Some TUN/TAP drivers like to be ioctled for mtu - after open */ - int post_open_mtu; -}; - - -/* - * OpenBSD and Mac OS X when using utun - * have a slightly incompatible TUN device from - * the rest of the world, in that it prepends a - * uint32 to the beginning of the IP header - * to designate the protocol (why not just - * look at the version field in the IP header to - * determine v4 or v6?). - * - * We strip off this field on reads and - * put it back on writes. - * - * I have not tested TAP devices on OpenBSD, - * but I have conditionalized the special - * TUN handling code described above to - * go away for TAP devices. - */ - - -static inline long -header_modify_read_write_return (long len) -{ - if (len > 0) - return len > sizeof (u_int32_t) ? len - sizeof (u_int32_t) : 0; - else - return len; -} - -long -write_tun (struct tuntap* tt, uint8_t *buf, int len) -{ - if (tt->type == DEV_TYPE_TUN) - { - u_int32_t type; - struct iovec iv[2]; - struct ip *iph; - - iph = (struct ip *) buf; - - if (tt->ipv6 && iph->ip_v == 6) - type = htonl (AF_INET6); - else - type = htonl (AF_INET); - - iv[0].iov_base = &type; - iv[0].iov_len = sizeof (type); - iv[1].iov_base = buf; - iv[1].iov_len = len; - - return header_modify_read_write_return (writev (tt->fd, iv, 2)); - } - else - return write (tt->fd, buf, len); -} - -long -read_tun (struct tuntap* tt, uint8_t *buf, int len) -{ - if (tt->type == DEV_TYPE_TUN) - { - u_int32_t type; - struct iovec iv[2]; - - iv[0].iov_base = &type; - iv[0].iov_len = sizeof (type); - iv[1].iov_base = buf; - iv[1].iov_len = len; - - return header_modify_read_write_return (readv (tt->fd, iv, 2)); - } - else - return read (tt->fd, buf, len); -} - -/* Darwin (MacOS X) is mostly "just use the generic stuff", but there - * is always one caveat...: - * - * If IPv6 is configured, and the tun device is closed, the IPv6 address - * configured to the tun interface changes to a lingering /128 route - * pointing to lo0. Need to unconfigure... (observed on 10.5) - */ - -/* - * utun is the native Darwin tun driver present since at least 10.7 - * Thanks goes to Jonathan Levin for providing an example how to utun - * (http://newosxbook.com/src.jl?tree=listings&file=17-15-utun.c) - */ - -/* Helper functions that tries to open utun device - return -2 on early initialization failures (utun not supported - at all (old OS X) and -1 on initlization failure of utun - device (utun works but utunX is already used */ -static -int utun_open_helper (struct ctl_info ctlInfo, int utunnum) -{ - struct sockaddr_ctl sc; - int fd; - - fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL); - - if (fd < 0) - { - NSLog (@"Opening utun (%s): %s", "socket(SYSPROTO_CONTROL)", - strerror (errno)); - return -2; - } - - if (ioctl(fd, CTLIOCGINFO, &ctlInfo) == -1) - { - close (fd); - NSLog(@"Opening utun (%s): %s", "ioctl(CTLIOCGINFO)", - strerror (errno)); - return -2; - } - - - sc.sc_id = ctlInfo.ctl_id; - sc.sc_len = sizeof(sc); - sc.sc_family = AF_SYSTEM; - sc.ss_sysaddr = AF_SYS_CONTROL; - - sc.sc_unit = utunnum+1; - - - /* If the connect is successful, a utun%d device will be created, where "%d" - * is (sc.sc_unit - 1) */ - - if (connect (fd, (struct sockaddr *)&sc, sizeof(sc)) < 0) - { - NSLog (@"Opening utun (%s): %s", "connect(AF_SYS_CONTROL)", - strerror (errno)); - close(fd); - return -1; - } - - fcntl (fd, F_SETFL, O_NONBLOCK); - fcntl (fd, F_SETFD, FD_CLOEXEC); /* don't pass fd to scripts */ - - return fd; -} - -void -open_darwin_utun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt) -{ - struct ctl_info ctlInfo; - int fd; - char utunname[20]; - int utunnum =-1; - socklen_t utunname_len = sizeof(utunname); - - /* dev_node is simply utun, do the normal dynamic utun - * otherwise try to parse the utun number */ - if (dev_node && !strcmp ("utun", dev_node)==0) - { - if (!sscanf (dev_node, "utun%d", &utunnum)==1) - NSLog(@"Cannot parse 'dev-node %s' please use 'dev-node utunX'" - "to use a utun device number X", dev_node); - } - - - memset(&(ctlInfo), 0, sizeof(ctlInfo)); - if (strlcpy(ctlInfo.ctl_name, UTUN_CONTROL_NAME, sizeof(ctlInfo.ctl_name)) >= - sizeof(ctlInfo.ctl_name)) - { - NSLog(@"Opening utun: UTUN_CONTROL_NAME too long"); - } - - /* try to open first available utun device if no specific utun is requested */ - if (utunnum == -1) - { - for (utunnum=0; utunnum<255; utunnum++) - { - fd = utun_open_helper (ctlInfo, utunnum); - /* Break if the fd is valid, - * or if early initalization failed (-2) */ - if (fd !=-1) - break; - } - } - else - { - fd = utun_open_helper (ctlInfo, utunnum); - } - - /* opening an utun device failed */ - tt->fd = fd; - - if (fd < 0) - return; - - /* Retrieve the assigned interface name. */ - if (getsockopt (fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, utunname, &utunname_len)) - NSLog(@"Error retrieving utun interface name"); - - tt->actual_name = string_alloc (utunname); - - NSLog(@"Opened utun device %s", utunname); - tt->is_utun = true; -} - -void -open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt) -{ - /* Try utun first and fall back to normal tun if utun fails - and dev_node is not specified */ - open_darwin_utun(dev, dev_type, dev_node, tt); - - if (!tt->is_utun) - { - NSLog(@"Cannot open utun device"); - } -} - -static void -clear_tuntap (struct tuntap *tuntap) -{ - memset(tuntap, 0, sizeof(*tuntap)); - tuntap->fd = -1; - tuntap->ipv6 = false; -} - -static void -close_tun_generic (struct tuntap *tt) -{ - if (tt->fd >= 0) - close (tt->fd); - if (tt->actual_name) - free (tt->actual_name); - clear_tuntap (tt); -} - -bool -is_dev_type (const char *dev, const char *dev_type, const char *match_type) -{ - if (!dev) - return false; - if (dev_type) - return !strcmp (dev_type, match_type); - else - return !strncmp (dev, match_type, strlen (match_type)); -} - -int -dev_type_enum (const char *dev, const char *dev_type) -{ - if (is_dev_type (dev, dev_type, "tun")) - return DEV_TYPE_TUN; - else - return 0; -} - -const char * -dev_type_string (const char *dev, const char *dev_type) -{ - switch (dev_type_enum (dev, dev_type)) - { - case DEV_TYPE_TUN: - return "tun"; - default: - return "[unknown-dev-type]"; - } -} - -void -close_tun (struct tuntap* tt) -{ - if (tt) - { - if ( tt->ipv6 && tt->did_ifconfig_ipv6_setup ) - { - /* - const char * ifconfig_ipv6_local = - print_in6_addr (tt->local_ipv6, 0, &gc); - - argv_printf (&argv, "%s delete -inet6 %s", - ROUTE_PATH, ifconfig_ipv6_local ); - argv_msg (M_INFO, &argv); - openvpn_execve_check (&argv, NULL, 0, "MacOS X 'remove inet6 route' failed (non-critical)"); - */ - } - close_tun_generic (tt); - free (tt); - } -} - -/* - * Init tun/tap object. - * - * Set up tuntap structure for ifconfig, - * but don't execute yet. - */ -struct tuntap * -init_tun (const char *dev, /* --dev option */ - const char *dev_type, /* --dev-type option */ - int topology, /* one of the TOP_x values */ - const char *ifconfig_local_parm, /* --ifconfig parm 1 */ - const char *ifconfig_remote_netmask_parm, /* --ifconfig parm 2 */ - const char *ifconfig_ipv6_local_parm, /* --ifconfig parm 1 IPv6 */ - int ifconfig_ipv6_netbits_parm, - const char *ifconfig_ipv6_remote_parm, /* --ifconfig parm 2 IPv6 */ - in_addr_t local_public, - in_addr_t remote_public, - const bool strict_warn) -{ - struct tuntap *tt; - - tt = malloc (sizeof (struct tuntap)); - clear_tuntap (tt); - - tt->type = dev_type_enum (dev, dev_type); - tt->topology = topology; - - if (ifconfig_local_parm && ifconfig_remote_netmask_parm) - { - bool tun = false; - const char *ifconfig_local = NULL; - const char *ifconfig_remote_netmask = NULL; - const char *ifconfig_broadcast = NULL; - - /* - * We only handle TUN/TAP devices here, not --dev null devices. - */ - tun = is_tun_p2p (tt); - - /* - * Convert arguments to binary IPv4 addresses. - */ - - tt->local = getaddr ( - GETADDR_RESOLVE - | GETADDR_HOST_ORDER - | GETADDR_FATAL_ON_SIGNAL - | GETADDR_FATAL, - ifconfig_local_parm, - 0, - NULL, - NULL); - - tt->remote_netmask = getaddr ( - (tun ? GETADDR_RESOLVE : 0) - | GETADDR_HOST_ORDER - | GETADDR_FATAL_ON_SIGNAL - | GETADDR_FATAL, - ifconfig_remote_netmask_parm, - 0, - NULL, - NULL); - - /* - * Look for common errors in --ifconfig parms - */ - if (strict_warn) - { - ifconfig_sanity_check (tt->type == DEV_TYPE_TUN, tt->remote_netmask, tt->topology); - - /* - * If local_public or remote_public addresses are defined, - * make sure they do not clash with our virtual subnet. - */ - - check_addr_clash ("local", - tt->type, - local_public, - tt->local, - tt->remote_netmask); - - check_addr_clash ("remote", - tt->type, - remote_public, - tt->local, - tt->remote_netmask); - - if (tt->type == DEV_TYPE_TAP || (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)) - check_subnet_conflict (tt->local, tt->remote_netmask, "TUN/TAP adapter"); - else if (tt->type == DEV_TYPE_TUN) - check_subnet_conflict (tt->local, IPV4_NETMASK_HOST, "TUN/TAP adapter"); - } - - - - tt->did_ifconfig_setup = true; - } - - if (ifconfig_ipv6_local_parm && ifconfig_ipv6_remote_parm) - { - const char *ifconfig_ipv6_local = NULL; - const char *ifconfig_ipv6_remote = NULL; - - /* - * Convert arguments to binary IPv6 addresses. - */ - - if ( inet_pton( AF_INET6, ifconfig_ipv6_local_parm, &tt->local_ipv6 ) != 1 || - inet_pton( AF_INET6, ifconfig_ipv6_remote_parm, &tt->remote_ipv6 ) != 1 ) - { - msg( M_FATAL, "init_tun: problem converting IPv6 ifconfig addresses %s and %s to binary", ifconfig_ipv6_local_parm, ifconfig_ipv6_remote_parm ); - } - tt->netbits_ipv6 = ifconfig_ipv6_netbits_parm; - - /* - * Set ifconfig parameters - */ - ifconfig_ipv6_local = print_in6_addr (tt->local_ipv6, 0, &gc); - ifconfig_ipv6_remote = print_in6_addr (tt->remote_ipv6, 0, &gc); - - /* - * Set environmental variables with ifconfig parameters. - */ - if (es) - { - setenv_str (es, "ifconfig_ipv6_local", ifconfig_ipv6_local); - setenv_int (es, "ifconfig_ipv6_netbits", tt->netbits_ipv6); - setenv_str (es, "ifconfig_ipv6_remote", ifconfig_ipv6_remote); - } - tt->did_ifconfig_ipv6_setup = true; - } - - gc_free (&gc); - return tt; -} - -/* - * Platform specific tun initializations - */ -void -init_tun_post (struct tuntap *tt, - const struct frame *frame, - const struct tuntap_options *options) -{ - tt->options = *options; -} - -/* some of the platforms will auto-add a "network route" pointing - * to the interface on "ifconfig tunX 2001:db8::1/64", others need - * an extra call to "route add..." - * -> helper function to simplify code below - */ -void add_route_connected_v6_net(struct tuntap * tt, - const struct env_set *es) -{ - struct route_ipv6 r6; - - r6.defined = true; - r6.network = tt->local_ipv6; - r6.netbits = tt->netbits_ipv6; - r6.gateway = tt->local_ipv6; - r6.metric = 0; /* connected route */ - r6.metric_defined = true; - add_route_ipv6 (&r6, tt, 0, es); -} - -void delete_route_connected_v6_net(struct tuntap * tt, - const struct env_set *es) -{ - struct route_ipv6 r6; - - r6.defined = true; - r6.network = tt->local_ipv6; - r6.netbits = tt->netbits_ipv6; - r6.gateway = tt->local_ipv6; - r6.metric = 0; /* connected route */ - r6.metric_defined = true; - delete_route_ipv6 (&r6, tt, 0, es); -} - -/* - * Open tun/tap device, ifconfig, call up script, etc. - */ - -static bool -do_open_tun () -{ - bool ret = false; - - c->c2.ipv4_tun = (!c->options.tun_ipv6 - && is_dev_type (c->options.dev, c->options.dev_type, "tun")); - -#ifndef TARGET_ANDROID - if (!c->c1.tuntap) - { -#endif - -#ifdef TARGET_ANDROID - /* If we emulate persist-tun on android we still have to open a new tun and - then close the old */ - int oldtunfd=-1; - if (c->c1.tuntap) - oldtunfd = c->c1.tuntap->fd; -#endif - - /* initialize (but do not open) tun/tap object */ - do_init_tun (c); - - /* allocate route list structure */ - do_alloc_route_list (c); - - /* parse and resolve the route option list */ - if (c->options.routes && c->c1.route_list && c->c2.link_socket) - do_init_route_list (&c->options, c->c1.route_list, &c->c2.link_socket->info, false, c->c2.es); - if (c->options.routes_ipv6 && c->c1.route_ipv6_list ) - do_init_route_ipv6_list (&c->options, c->c1.route_ipv6_list, false, c->c2.es); - - /* do ifconfig */ - if (!c->options.ifconfig_noexec - && ifconfig_order () == IFCONFIG_BEFORE_TUN_OPEN) - { - /* guess actual tun/tap unit number that will be returned - by open_tun */ - const char *guess = guess_tuntap_dev (c->options.dev, - c->options.dev_type, - c->options.dev_node, - &gc); - do_ifconfig (c->c1.tuntap, guess, TUN_MTU_SIZE (&c->c2.frame), c->c2.es); - } - - /* possibly add routes */ - if (route_order() == ROUTE_BEFORE_TUN) { - /* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ - do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es); - } - - /* open the tun device */ - open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, - c->c1.tuntap); -#ifdef TARGET_ANDROID - if (oldtunfd>=0) - close(oldtunfd); -#endif - /* set the hardware address */ - if (c->options.lladdr) - set_lladdr(c->c1.tuntap->actual_name, c->options.lladdr, c->c2.es); - - /* do ifconfig */ - if (!c->options.ifconfig_noexec - && ifconfig_order () == IFCONFIG_AFTER_TUN_OPEN) - { - do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, TUN_MTU_SIZE (&c->c2.frame), c->c2.es); - } - - /* run the up script */ - run_up_down (c->options.up_script, - c->plugins, - OPENVPN_PLUGIN_UP, - c->c1.tuntap->actual_name, - dev_type_string (c->options.dev, c->options.dev_type), - TUN_MTU_SIZE (&c->c2.frame), - EXPANDED_SIZE (&c->c2.frame), - print_in_addr_t (c->c1.tuntap->local, IA_EMPTY_IF_UNDEF, &gc), - print_in_addr_t (c->c1.tuntap->remote_netmask, IA_EMPTY_IF_UNDEF, &gc), - "init", - NULL, - "up", - c->c2.es); - - /* possibly add routes */ - if ((route_order() == ROUTE_AFTER_TUN) && (!c->options.route_delay_defined)) - do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es); - - /* - * Did tun/tap driver give us an MTU? - */ - if (c->c1.tuntap->post_open_mtu) - frame_set_mtu_dynamic (&c->c2.frame, - c->c1.tuntap->post_open_mtu, - SET_MTU_TUN | SET_MTU_UPPER_BOUND); - - ret = true; - static_context = c; -#ifndef TARGET_ANDROID - } - else - { - msg (M_INFO, "Preserving previous TUN/TAP instance: %s", - c->c1.tuntap->actual_name); - - /* run the up script if user specified --up-restart */ - if (c->options.up_restart) - run_up_down (c->options.up_script, - c->plugins, - OPENVPN_PLUGIN_UP, - c->c1.tuntap->actual_name, - dev_type_string (c->options.dev, c->options.dev_type), - TUN_MTU_SIZE (&c->c2.frame), - EXPANDED_SIZE (&c->c2.frame), - print_in_addr_t (c->c1.tuntap->local, IA_EMPTY_IF_UNDEF, &gc), - print_in_addr_t (c->c1.tuntap->remote_netmask, IA_EMPTY_IF_UNDEF, &gc), - "restart", - NULL, - "up", - c->c2.es); - } -#endif - gc_free (&gc); - return ret; -} - -/* - * Close TUN/TAP device - */ - -static void -do_close_tun_simple (struct context *c) -{ - msg (D_CLOSE, "Closing TUN/TAP interface"); - close_tun (c->c1.tuntap); - c->c1.tuntap = NULL; - c->c1.tuntap_owned = false; -#if P2MP - save_pulled_options_digest (c, NULL); /* delete C1-saved pulled_options_digest */ -#endif -} - -static void -do_close_tun (struct context *c, bool force) -{ - struct gc_arena gc = gc_new (); - if (c->c1.tuntap && c->c1.tuntap_owned) - { - const char *tuntap_actual = string_alloc (c->c1.tuntap->actual_name, &gc); - const in_addr_t local = c->c1.tuntap->local; - const in_addr_t remote_netmask = c->c1.tuntap->remote_netmask; - - if (force || !(c->sig->signal_received == SIGUSR1 && c->options.persist_tun)) - { - static_context = NULL; - -#ifdef ENABLE_MANAGEMENT - /* tell management layer we are about to close the TUN/TAP device */ - if (management) - { - management_pre_tunnel_close (management); - management_up_down (management, "DOWN", c->c2.es); - } -#endif - - /* delete any routes we added */ - if (c->c1.route_list || c->c1.route_ipv6_list ) - { - run_up_down (c->options.route_predown_script, - c->plugins, - OPENVPN_PLUGIN_ROUTE_PREDOWN, - tuntap_actual, - NULL, - TUN_MTU_SIZE (&c->c2.frame), - EXPANDED_SIZE (&c->c2.frame), - print_in_addr_t (local, IA_EMPTY_IF_UNDEF, &gc), - print_in_addr_t (remote_netmask, IA_EMPTY_IF_UNDEF, &gc), - "init", - signal_description (c->sig->signal_received, - c->sig->signal_text), - "route-pre-down", - c->c2.es); - - delete_routes (c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, ROUTE_OPTION_FLAGS (&c->options), c->c2.es); - } - - /* actually close tun/tap device based on --down-pre flag */ - if (!c->options.down_pre) - do_close_tun_simple (c); - - /* Run the down script -- note that it will run at reduced - privilege if, for example, "--user nobody" was used. */ - run_up_down (c->options.down_script, - c->plugins, - OPENVPN_PLUGIN_DOWN, - tuntap_actual, - NULL, - TUN_MTU_SIZE (&c->c2.frame), - EXPANDED_SIZE (&c->c2.frame), - print_in_addr_t (local, IA_EMPTY_IF_UNDEF, &gc), - print_in_addr_t (remote_netmask, IA_EMPTY_IF_UNDEF, &gc), - "init", - signal_description (c->sig->signal_received, - c->sig->signal_text), - "down", - c->c2.es); - - /* actually close tun/tap device based on --down-pre flag */ - if (c->options.down_pre) - do_close_tun_simple (c); - } - else - { - /* run the down script on this restart if --up-restart was specified */ - if (c->options.up_restart) - run_up_down (c->options.down_script, - c->plugins, - OPENVPN_PLUGIN_DOWN, - tuntap_actual, - NULL, - TUN_MTU_SIZE (&c->c2.frame), - EXPANDED_SIZE (&c->c2.frame), - print_in_addr_t (local, IA_EMPTY_IF_UNDEF, &gc), - print_in_addr_t (remote_netmask, IA_EMPTY_IF_UNDEF, &gc), - "restart", - signal_description (c->sig->signal_received, - c->sig->signal_text), - "down", - c->c2.es); - } - } - gc_free (&gc); -} - -void -tun_abort() -{ - struct context *c = static_context; - if (c) - { - static_context = NULL; - do_close_tun (c, true); - } -} - -@implementation UTUN - -@end diff --git a/TetherTests/TetherTests-Info.plist b/TetherTests/TetherTests-Info.plist deleted file mode 100644 index 25450ce..0000000 --- a/TetherTests/TetherTests-Info.plist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIdentifier - com.chrisballinger.${PRODUCT_NAME:rfc1034identifier} - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - - diff --git a/TetherTests/TetherTests.m b/TetherTests/TetherTests.m deleted file mode 100644 index 32dd77e..0000000 --- a/TetherTests/TetherTests.m +++ /dev/null @@ -1,34 +0,0 @@ -// -// TetherTests.m -// TetherTests -// -// Created by Christopher Ballinger on 11/30/13. -// Copyright (c) 2013 Christopher Ballinger. All rights reserved. -// - -#import - -@interface TetherTests : XCTestCase - -@end - -@implementation TetherTests - -- (void)setUp -{ - [super setUp]; - // Put setup code here. This method is called before the invocation of each test method in the class. -} - -- (void)tearDown -{ - // Put teardown code here. This method is called after the invocation of each test method in the class. - [super tearDown]; -} - -- (void)testExample -{ - XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); -} - -@end diff --git a/TetherTests/en.lproj/InfoPlist.strings b/TetherTests/en.lproj/InfoPlist.strings deleted file mode 100644 index 477b28f..0000000 --- a/TetherTests/en.lproj/InfoPlist.strings +++ /dev/null @@ -1,2 +0,0 @@ -/* Localized versions of Info.plist keys */ -