diff --git a/PacketTunnel/Header.h b/PacketTunnel/Header.h new file mode 100644 index 0000000..3f72052 --- /dev/null +++ b/PacketTunnel/Header.h @@ -0,0 +1,13 @@ +// +// Header.h +// PacketTunnel +// +// Created by HossinAsaadi on 7/23/23. +// + + +#ifndef Header_h +#define Header_h +#import + +#endif /* Header_h */ diff --git a/PacketTunnel/Info.plist b/PacketTunnel/Info.plist new file mode 100644 index 0000000..3059459 --- /dev/null +++ b/PacketTunnel/Info.plist @@ -0,0 +1,13 @@ + + + + + NSExtension + + NSExtensionPointIdentifier + com.apple.networkextension.packet-tunnel + NSExtensionPrincipalClass + $(PRODUCT_MODULE_NAME).PacketTunnelProvider + + + diff --git a/PacketTunnel/PacketTunnel.entitlements b/PacketTunnel/PacketTunnel.entitlements new file mode 100644 index 0000000..ad152a5 --- /dev/null +++ b/PacketTunnel/PacketTunnel.entitlements @@ -0,0 +1,20 @@ + + + + + com.apple.developer.networking.networkextension + + packet-tunnel-provider + + com.apple.security.app-sandbox + + com.apple.security.application-groups + + group.hossin.asaadi.sshTunnel + + com.apple.security.network.client + + com.apple.security.network.server + + + diff --git a/PacketTunnel/PacketTunnelProvider.swift b/PacketTunnel/PacketTunnelProvider.swift new file mode 100644 index 0000000..783e5d6 --- /dev/null +++ b/PacketTunnel/PacketTunnelProvider.swift @@ -0,0 +1,96 @@ +// +// PacketTunnelProvider.swift +// PacketTunnel +// +// Created by HossinAsaadi on 7/23/23. +// + +import NetworkExtension +import SshLib +class PacketTunnelProvider: NEPacketTunnelProvider { + var tunnelFd: Int32? { + var buf = [CChar](repeating: 0, count: Int(IFNAMSIZ)) + + for fd: Int32 in 0 ... 1024 { + var len = socklen_t(buf.count) + + if getsockopt(fd, 2 /* IGMP */, 2, &buf, &len) == 0 && String(cString: buf).hasPrefix("utun") { + return fd + } + } + + return packetFlow.value(forKey: "socket.fileDescriptor") as? Int32 + } + + override func startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void) { + let tunnelNetworkSettings = createTunnelSettings() + self.setTunnelNetworkSettings(tunnelNetworkSettings) + + let localSocks = "127.0.0.1:10801" + let sshAddress = "1.1.1.1:22" + let sshUser = "root" + let sshPass = "1234" + + let udpGwRemote = "1.1.1.1:7300" + + + DispatchQueue.global(qos: .userInitiated).async { + + NSLog("run ssh : \(SshlibInitSSH(sshAddress,localSocks,sshUser,sshPass))") + + } + DispatchQueue.global(qos: .userInitiated).async { + + let argv = ["tun2socks", + "--netif-ipaddr", + "240.0.0.4", + "--netif-netmask", + "255.255.255.0", + "--loglevel", + "debug", + "--socks-server-addr", + localSocks, + "--udpgw-remote-server-addr", + udpGwRemote, + ] + var cargs = argv.map { strdup($0) } + + NSLog("run tun2socks_main: \(tun2socks_main(Int32(argv.count),&cargs,self.tunnelFd!,Int32(1500)))") + + + } + + completionHandler(nil) + + } + + override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) { + completionHandler() + } + + override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)?) { + // Add code here to handle the message. + if let handler = completionHandler { + handler(messageData) + } + } + + override func sleep(completionHandler: @escaping () -> Void) { + // Add code here to get ready to sleep. + completionHandler() + } + + override func wake() { + // Add code here to wake up. + } + func createTunnelSettings() -> NEPacketTunnelNetworkSettings { + let newSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "240.0.0.10") + newSettings.ipv4Settings = NEIPv4Settings(addresses: ["240.0.0.2"], subnetMasks: ["255.255.255.0"]) + newSettings.ipv4Settings?.includedRoutes = [NEIPv4Route.`default`()] + newSettings.proxySettings = nil + newSettings.dnsSettings = NEDNSSettings(servers: ["8.8.8.8"]) + newSettings.mtu = (1500) as NSNumber + + return newSettings + } +} diff --git a/SshLib.xcframework/Info.plist b/SshLib.xcframework/Info.plist new file mode 100644 index 0000000..aa6f703 --- /dev/null +++ b/SshLib.xcframework/Info.plist @@ -0,0 +1,53 @@ + + + + + AvailableLibraries + + + LibraryIdentifier + ios-arm64_x86_64-simulator + LibraryPath + SshLib.framework + SupportedArchitectures + + arm64 + x86_64 + + SupportedPlatform + ios + SupportedPlatformVariant + simulator + + + LibraryIdentifier + macos-arm64_x86_64 + LibraryPath + SshLib.framework + SupportedArchitectures + + arm64 + x86_64 + + SupportedPlatform + macos + + + LibraryIdentifier + ios-arm64 + LibraryPath + SshLib.framework + SupportedArchitectures + + arm64 + + SupportedPlatform + ios + + + CFBundlePackageType + XFWK + XCFrameworkFormatVersion + 1.0 + + diff --git a/SshLib.xcframework/ios-arm64/SshLib.framework/Headers b/SshLib.xcframework/ios-arm64/SshLib.framework/Headers new file mode 120000 index 0000000..a177d2a --- /dev/null +++ b/SshLib.xcframework/ios-arm64/SshLib.framework/Headers @@ -0,0 +1 @@ +Versions/Current/Headers \ No newline at end of file diff --git a/SshLib.xcframework/ios-arm64/SshLib.framework/Modules b/SshLib.xcframework/ios-arm64/SshLib.framework/Modules new file mode 120000 index 0000000..5736f31 --- /dev/null +++ b/SshLib.xcframework/ios-arm64/SshLib.framework/Modules @@ -0,0 +1 @@ +Versions/Current/Modules \ No newline at end of file diff --git a/SshLib.xcframework/ios-arm64/SshLib.framework/Resources b/SshLib.xcframework/ios-arm64/SshLib.framework/Resources new file mode 120000 index 0000000..953ee36 --- /dev/null +++ b/SshLib.xcframework/ios-arm64/SshLib.framework/Resources @@ -0,0 +1 @@ +Versions/Current/Resources \ No newline at end of file diff --git a/SshLib.xcframework/ios-arm64/SshLib.framework/SshLib b/SshLib.xcframework/ios-arm64/SshLib.framework/SshLib new file mode 120000 index 0000000..2d1a76f --- /dev/null +++ b/SshLib.xcframework/ios-arm64/SshLib.framework/SshLib @@ -0,0 +1 @@ +Versions/Current/SshLib \ No newline at end of file diff --git a/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/SshLib.h b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/SshLib.h new file mode 100644 index 0000000..5fbcc6b --- /dev/null +++ b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/SshLib.h @@ -0,0 +1,13 @@ + +// Objective-C API for talking to the following Go packages +// +// sshlib +// +// File is generated by gomobile bind. Do not edit. +#ifndef __SshLib_FRAMEWORK_H__ +#define __SshLib_FRAMEWORK_H__ + +#include "Sshlib.objc.h" +#include "Universe.objc.h" + +#endif diff --git a/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/Sshlib.objc.h b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/Sshlib.objc.h new file mode 100644 index 0000000..2aa6b3f --- /dev/null +++ b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/Sshlib.objc.h @@ -0,0 +1,16 @@ +// Objective-C API for talking to sshlib Go package. +// gobind -lang=objc sshlib +// +// File is generated by gobind. Do not edit. + +#ifndef __Sshlib_H__ +#define __Sshlib_H__ + +@import Foundation; +#include "ref.h" +#include "Universe.objc.h" + + +FOUNDATION_EXPORT void SshlibInitSSH(NSString* _Nullable sshAddress, NSString* _Nullable socks5Address, NSString* _Nullable sshUser, NSString* _Nullable sshPass); + +#endif diff --git a/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/Universe.objc.h b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/Universe.objc.h new file mode 100644 index 0000000..019e750 --- /dev/null +++ b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/Universe.objc.h @@ -0,0 +1,29 @@ +// Objective-C API for talking to Go package. +// gobind -lang=objc +// +// File is generated by gobind. Do not edit. + +#ifndef __Universe_H__ +#define __Universe_H__ + +@import Foundation; +#include "ref.h" + +@protocol Universeerror; +@class Universeerror; + +@protocol Universeerror +- (NSString* _Nonnull)error; +@end + +@class Universeerror; + +@interface Universeerror : NSError { +} +@property(strong, readonly) _Nonnull id _ref; + +- (nonnull instancetype)initWithRef:(_Nonnull id)ref; +- (NSString* _Nonnull)error; +@end + +#endif diff --git a/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/ref.h b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/ref.h new file mode 100644 index 0000000..b8036a4 --- /dev/null +++ b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/ref.h @@ -0,0 +1,35 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#ifndef __GO_REF_HDR__ +#define __GO_REF_HDR__ + +#include + +// GoSeqRef is an object tagged with an integer for passing back and +// forth across the language boundary. A GoSeqRef may represent either +// an instance of a Go object, or an Objective-C object passed to Go. +// The explicit allocation of a GoSeqRef is used to pin a Go object +// when it is passed to Objective-C. The Go seq package maintains a +// reference to the Go object in a map keyed by the refnum along with +// a reference count. When the reference count reaches zero, the Go +// seq package will clear the corresponding entry in the map. +@interface GoSeqRef : NSObject { +} +@property(readonly) int32_t refnum; +@property(strong) id obj; // NULL when representing a Go object. + +// new GoSeqRef object to proxy a Go object. The refnum must be +// provided from Go side. +- (instancetype)initWithRefnum:(int32_t)refnum obj:(id)obj; + +- (int32_t)incNum; + +@end + +@protocol goSeqRefInterface +-(GoSeqRef*) _ref; +@end + +#endif diff --git a/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Modules/module.modulemap b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Modules/module.modulemap new file mode 100644 index 0000000..796a693 --- /dev/null +++ b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Modules/module.modulemap @@ -0,0 +1,8 @@ +framework module "SshLib" { + header "ref.h" + header "Sshlib.objc.h" + header "Universe.objc.h" + header "SshLib.h" + + export * +} \ No newline at end of file diff --git a/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Resources/Info.plist b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Resources/Info.plist new file mode 100644 index 0000000..0d1a4b8 --- /dev/null +++ b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Resources/Info.plist @@ -0,0 +1,6 @@ + + + + + + diff --git a/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/SshLib b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/SshLib new file mode 100644 index 0000000..fcb06f8 Binary files /dev/null and b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/SshLib differ diff --git a/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/Current b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/Current new file mode 120000 index 0000000..8c7e5a6 --- /dev/null +++ b/SshLib.xcframework/ios-arm64/SshLib.framework/Versions/Current @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Headers b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Headers new file mode 120000 index 0000000..a177d2a --- /dev/null +++ b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Headers @@ -0,0 +1 @@ +Versions/Current/Headers \ No newline at end of file diff --git a/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Modules b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Modules new file mode 120000 index 0000000..5736f31 --- /dev/null +++ b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Modules @@ -0,0 +1 @@ +Versions/Current/Modules \ No newline at end of file diff --git a/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Resources b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Resources new file mode 120000 index 0000000..953ee36 --- /dev/null +++ b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Resources @@ -0,0 +1 @@ +Versions/Current/Resources \ No newline at end of file diff --git a/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/SshLib b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/SshLib new file mode 120000 index 0000000..2d1a76f --- /dev/null +++ b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/SshLib @@ -0,0 +1 @@ +Versions/Current/SshLib \ No newline at end of file diff --git a/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/SshLib.h b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/SshLib.h new file mode 100644 index 0000000..5fbcc6b --- /dev/null +++ b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/SshLib.h @@ -0,0 +1,13 @@ + +// Objective-C API for talking to the following Go packages +// +// sshlib +// +// File is generated by gomobile bind. Do not edit. +#ifndef __SshLib_FRAMEWORK_H__ +#define __SshLib_FRAMEWORK_H__ + +#include "Sshlib.objc.h" +#include "Universe.objc.h" + +#endif diff --git a/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/Sshlib.objc.h b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/Sshlib.objc.h new file mode 100644 index 0000000..2aa6b3f --- /dev/null +++ b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/Sshlib.objc.h @@ -0,0 +1,16 @@ +// Objective-C API for talking to sshlib Go package. +// gobind -lang=objc sshlib +// +// File is generated by gobind. Do not edit. + +#ifndef __Sshlib_H__ +#define __Sshlib_H__ + +@import Foundation; +#include "ref.h" +#include "Universe.objc.h" + + +FOUNDATION_EXPORT void SshlibInitSSH(NSString* _Nullable sshAddress, NSString* _Nullable socks5Address, NSString* _Nullable sshUser, NSString* _Nullable sshPass); + +#endif diff --git a/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/Universe.objc.h b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/Universe.objc.h new file mode 100644 index 0000000..019e750 --- /dev/null +++ b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/Universe.objc.h @@ -0,0 +1,29 @@ +// Objective-C API for talking to Go package. +// gobind -lang=objc +// +// File is generated by gobind. Do not edit. + +#ifndef __Universe_H__ +#define __Universe_H__ + +@import Foundation; +#include "ref.h" + +@protocol Universeerror; +@class Universeerror; + +@protocol Universeerror +- (NSString* _Nonnull)error; +@end + +@class Universeerror; + +@interface Universeerror : NSError { +} +@property(strong, readonly) _Nonnull id _ref; + +- (nonnull instancetype)initWithRef:(_Nonnull id)ref; +- (NSString* _Nonnull)error; +@end + +#endif diff --git a/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/ref.h b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/ref.h new file mode 100644 index 0000000..b8036a4 --- /dev/null +++ b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/ref.h @@ -0,0 +1,35 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#ifndef __GO_REF_HDR__ +#define __GO_REF_HDR__ + +#include + +// GoSeqRef is an object tagged with an integer for passing back and +// forth across the language boundary. A GoSeqRef may represent either +// an instance of a Go object, or an Objective-C object passed to Go. +// The explicit allocation of a GoSeqRef is used to pin a Go object +// when it is passed to Objective-C. The Go seq package maintains a +// reference to the Go object in a map keyed by the refnum along with +// a reference count. When the reference count reaches zero, the Go +// seq package will clear the corresponding entry in the map. +@interface GoSeqRef : NSObject { +} +@property(readonly) int32_t refnum; +@property(strong) id obj; // NULL when representing a Go object. + +// new GoSeqRef object to proxy a Go object. The refnum must be +// provided from Go side. +- (instancetype)initWithRefnum:(int32_t)refnum obj:(id)obj; + +- (int32_t)incNum; + +@end + +@protocol goSeqRefInterface +-(GoSeqRef*) _ref; +@end + +#endif diff --git a/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Modules/module.modulemap b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Modules/module.modulemap new file mode 100644 index 0000000..796a693 --- /dev/null +++ b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Modules/module.modulemap @@ -0,0 +1,8 @@ +framework module "SshLib" { + header "ref.h" + header "Sshlib.objc.h" + header "Universe.objc.h" + header "SshLib.h" + + export * +} \ No newline at end of file diff --git a/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Resources/Info.plist b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Resources/Info.plist new file mode 100644 index 0000000..0d1a4b8 --- /dev/null +++ b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Resources/Info.plist @@ -0,0 +1,6 @@ + + + + + + diff --git a/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/SshLib b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/SshLib new file mode 100644 index 0000000..712ef0b Binary files /dev/null and b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/SshLib differ diff --git a/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/Current b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/Current new file mode 120000 index 0000000..8c7e5a6 --- /dev/null +++ b/SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/Current @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Headers b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Headers new file mode 120000 index 0000000..a177d2a --- /dev/null +++ b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Headers @@ -0,0 +1 @@ +Versions/Current/Headers \ No newline at end of file diff --git a/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Modules b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Modules new file mode 120000 index 0000000..5736f31 --- /dev/null +++ b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Modules @@ -0,0 +1 @@ +Versions/Current/Modules \ No newline at end of file diff --git a/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Resources b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Resources new file mode 120000 index 0000000..953ee36 --- /dev/null +++ b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Resources @@ -0,0 +1 @@ +Versions/Current/Resources \ No newline at end of file diff --git a/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/SshLib b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/SshLib new file mode 120000 index 0000000..2d1a76f --- /dev/null +++ b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/SshLib @@ -0,0 +1 @@ +Versions/Current/SshLib \ No newline at end of file diff --git a/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Headers/SshLib.h b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Headers/SshLib.h new file mode 100644 index 0000000..5fbcc6b --- /dev/null +++ b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Headers/SshLib.h @@ -0,0 +1,13 @@ + +// Objective-C API for talking to the following Go packages +// +// sshlib +// +// File is generated by gomobile bind. Do not edit. +#ifndef __SshLib_FRAMEWORK_H__ +#define __SshLib_FRAMEWORK_H__ + +#include "Sshlib.objc.h" +#include "Universe.objc.h" + +#endif diff --git a/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Headers/Sshlib.objc.h b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Headers/Sshlib.objc.h new file mode 100644 index 0000000..2aa6b3f --- /dev/null +++ b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Headers/Sshlib.objc.h @@ -0,0 +1,16 @@ +// Objective-C API for talking to sshlib Go package. +// gobind -lang=objc sshlib +// +// File is generated by gobind. Do not edit. + +#ifndef __Sshlib_H__ +#define __Sshlib_H__ + +@import Foundation; +#include "ref.h" +#include "Universe.objc.h" + + +FOUNDATION_EXPORT void SshlibInitSSH(NSString* _Nullable sshAddress, NSString* _Nullable socks5Address, NSString* _Nullable sshUser, NSString* _Nullable sshPass); + +#endif diff --git a/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Headers/Universe.objc.h b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Headers/Universe.objc.h new file mode 100644 index 0000000..019e750 --- /dev/null +++ b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Headers/Universe.objc.h @@ -0,0 +1,29 @@ +// Objective-C API for talking to Go package. +// gobind -lang=objc +// +// File is generated by gobind. Do not edit. + +#ifndef __Universe_H__ +#define __Universe_H__ + +@import Foundation; +#include "ref.h" + +@protocol Universeerror; +@class Universeerror; + +@protocol Universeerror +- (NSString* _Nonnull)error; +@end + +@class Universeerror; + +@interface Universeerror : NSError { +} +@property(strong, readonly) _Nonnull id _ref; + +- (nonnull instancetype)initWithRef:(_Nonnull id)ref; +- (NSString* _Nonnull)error; +@end + +#endif diff --git a/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Headers/ref.h b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Headers/ref.h new file mode 100644 index 0000000..b8036a4 --- /dev/null +++ b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Headers/ref.h @@ -0,0 +1,35 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#ifndef __GO_REF_HDR__ +#define __GO_REF_HDR__ + +#include + +// GoSeqRef is an object tagged with an integer for passing back and +// forth across the language boundary. A GoSeqRef may represent either +// an instance of a Go object, or an Objective-C object passed to Go. +// The explicit allocation of a GoSeqRef is used to pin a Go object +// when it is passed to Objective-C. The Go seq package maintains a +// reference to the Go object in a map keyed by the refnum along with +// a reference count. When the reference count reaches zero, the Go +// seq package will clear the corresponding entry in the map. +@interface GoSeqRef : NSObject { +} +@property(readonly) int32_t refnum; +@property(strong) id obj; // NULL when representing a Go object. + +// new GoSeqRef object to proxy a Go object. The refnum must be +// provided from Go side. +- (instancetype)initWithRefnum:(int32_t)refnum obj:(id)obj; + +- (int32_t)incNum; + +@end + +@protocol goSeqRefInterface +-(GoSeqRef*) _ref; +@end + +#endif diff --git a/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Modules/module.modulemap b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Modules/module.modulemap new file mode 100644 index 0000000..796a693 --- /dev/null +++ b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Modules/module.modulemap @@ -0,0 +1,8 @@ +framework module "SshLib" { + header "ref.h" + header "Sshlib.objc.h" + header "Universe.objc.h" + header "SshLib.h" + + export * +} \ No newline at end of file diff --git a/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Resources/Info.plist b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Resources/Info.plist new file mode 100644 index 0000000..0d1a4b8 --- /dev/null +++ b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/Resources/Info.plist @@ -0,0 +1,6 @@ + + + + + + diff --git a/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/SshLib b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/SshLib new file mode 100644 index 0000000..ba85377 Binary files /dev/null and b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/A/SshLib differ diff --git a/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/Current b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/Current new file mode 120000 index 0000000..8c7e5a6 --- /dev/null +++ b/SshLib.xcframework/macos-arm64_x86_64/SshLib.framework/Versions/Current @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/sshTunnel.xcodeproj/project.pbxproj b/sshTunnel.xcodeproj/project.pbxproj index 930b5b6..ddc6f2f 100644 --- a/sshTunnel.xcodeproj/project.pbxproj +++ b/sshTunnel.xcodeproj/project.pbxproj @@ -7,13 +7,66 @@ objects = { /* Begin PBXBuildFile section */ + 853BDC6E2A6D7B2E000D0B5F /* liblibtun2socks.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 853BDC6D2A6D7B2E000D0B5F /* liblibtun2socks.a */; }; + 853BDC712A6D7D8B000D0B5F /* VPNManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 853BDC702A6D7D8B000D0B5F /* VPNManager.swift */; }; + 853BDC732A6D7E7E000D0B5F /* VPN.swift in Sources */ = {isa = PBXBuildFile; fileRef = 853BDC722A6D7E7E000D0B5F /* VPN.swift */; }; + 85D84CEA2A6D744A0059791C /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 85D84CD72A6D73DE0059791C /* NetworkExtension.framework */; }; + 85D84CED2A6D744A0059791C /* PacketTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85D84CEC2A6D744A0059791C /* PacketTunnelProvider.swift */; }; + 85D84CF22A6D744A0059791C /* PacketTunnel.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 85D84CE92A6D744A0059791C /* PacketTunnel.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 85D84CF72A6D756D0059791C /* SshLib.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 85D84CF62A6D756C0059791C /* SshLib.xcframework */; }; + 85D84CF82A6D756D0059791C /* SshLib.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 85D84CF62A6D756C0059791C /* SshLib.xcframework */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 85F618E92A6D4AA800E9C03C /* sshTunnelApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85F618E82A6D4AA800E9C03C /* sshTunnelApp.swift */; }; 85F618EB2A6D4AA800E9C03C /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85F618EA2A6D4AA800E9C03C /* ContentView.swift */; }; 85F618ED2A6D4AA900E9C03C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 85F618EC2A6D4AA900E9C03C /* Assets.xcassets */; }; 85F618F12A6D4AA900E9C03C /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 85F618F02A6D4AA900E9C03C /* Preview Assets.xcassets */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 85D84CF02A6D744A0059791C /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 85F618DD2A6D4AA800E9C03C /* Project object */; + proxyType = 1; + remoteGlobalIDString = 85D84CE82A6D744A0059791C; + remoteInfo = PacketTunnel; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 85D84CE42A6D73DE0059791C /* Embed Foundation Extensions */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 13; + files = ( + 85D84CF22A6D744A0059791C /* PacketTunnel.appex in Embed Foundation Extensions */, + ); + name = "Embed Foundation Extensions"; + runOnlyForDeploymentPostprocessing = 0; + }; + 85D84CF92A6D756D0059791C /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 85D84CF82A6D756D0059791C /* SshLib.xcframework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ + 853BDC6D2A6D7B2E000D0B5F /* liblibtun2socks.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = liblibtun2socks.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 853BDC6F2A6D7B4E000D0B5F /* Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Header.h; sourceTree = ""; }; + 853BDC702A6D7D8B000D0B5F /* VPNManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNManager.swift; sourceTree = ""; }; + 853BDC722A6D7E7E000D0B5F /* VPN.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPN.swift; sourceTree = ""; }; + 85D84CD72A6D73DE0059791C /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; }; + 85D84CE92A6D744A0059791C /* PacketTunnel.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = PacketTunnel.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + 85D84CEC2A6D744A0059791C /* PacketTunnelProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PacketTunnelProvider.swift; sourceTree = ""; }; + 85D84CEE2A6D744A0059791C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 85D84CEF2A6D744A0059791C /* PacketTunnel.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = PacketTunnel.entitlements; sourceTree = ""; }; + 85D84CF62A6D756C0059791C /* SshLib.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = SshLib.xcframework; sourceTree = ""; }; 85F618E52A6D4AA800E9C03C /* sshTunnel.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = sshTunnel.app; sourceTree = BUILT_PRODUCTS_DIR; }; 85F618E82A6D4AA800E9C03C /* sshTunnelApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = sshTunnelApp.swift; sourceTree = ""; }; 85F618EA2A6D4AA800E9C03C /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -23,6 +76,16 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 85D84CE62A6D744A0059791C /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 853BDC6E2A6D7B2E000D0B5F /* liblibtun2socks.a in Frameworks */, + 85D84CF72A6D756D0059791C /* SshLib.xcframework in Frameworks */, + 85D84CEA2A6D744A0059791C /* NetworkExtension.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 85F618E22A6D4AA800E9C03C /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -33,11 +96,24 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 85D84CEB2A6D744A0059791C /* PacketTunnel */ = { + isa = PBXGroup; + children = ( + 85D84CEC2A6D744A0059791C /* PacketTunnelProvider.swift */, + 85D84CEE2A6D744A0059791C /* Info.plist */, + 85D84CEF2A6D744A0059791C /* PacketTunnel.entitlements */, + 853BDC6F2A6D7B4E000D0B5F /* Header.h */, + ); + path = PacketTunnel; + sourceTree = ""; + }; 85F618DC2A6D4AA800E9C03C = { isa = PBXGroup; children = ( 85F618E72A6D4AA800E9C03C /* sshTunnel */, + 85D84CEB2A6D744A0059791C /* PacketTunnel */, 85F618E62A6D4AA800E9C03C /* Products */, + 85F618FB2A6D4D8000E9C03C /* Frameworks */, ); sourceTree = ""; }; @@ -45,6 +121,7 @@ isa = PBXGroup; children = ( 85F618E52A6D4AA800E9C03C /* sshTunnel.app */, + 85D84CE92A6D744A0059791C /* PacketTunnel.appex */, ); name = Products; sourceTree = ""; @@ -57,6 +134,8 @@ 85F618EC2A6D4AA900E9C03C /* Assets.xcassets */, 85F618EE2A6D4AA900E9C03C /* sshTunnel.entitlements */, 85F618EF2A6D4AA900E9C03C /* Preview Content */, + 853BDC702A6D7D8B000D0B5F /* VPNManager.swift */, + 853BDC722A6D7E7E000D0B5F /* VPN.swift */, ); path = sshTunnel; sourceTree = ""; @@ -69,9 +148,37 @@ path = "Preview Content"; sourceTree = ""; }; + 85F618FB2A6D4D8000E9C03C /* Frameworks */ = { + isa = PBXGroup; + children = ( + 853BDC6D2A6D7B2E000D0B5F /* liblibtun2socks.a */, + 85D84CF62A6D756C0059791C /* SshLib.xcframework */, + 85D84CD72A6D73DE0059791C /* NetworkExtension.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + 85D84CE82A6D744A0059791C /* PacketTunnel */ = { + isa = PBXNativeTarget; + buildConfigurationList = 85D84CF32A6D744A0059791C /* Build configuration list for PBXNativeTarget "PacketTunnel" */; + buildPhases = ( + 85D84CE52A6D744A0059791C /* Sources */, + 85D84CE62A6D744A0059791C /* Frameworks */, + 85D84CE72A6D744A0059791C /* Resources */, + 85D84CF92A6D756D0059791C /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = PacketTunnel; + productName = PacketTunnel; + productReference = 85D84CE92A6D744A0059791C /* PacketTunnel.appex */; + productType = "com.apple.product-type.app-extension"; + }; 85F618E42A6D4AA800E9C03C /* sshTunnel */ = { isa = PBXNativeTarget; buildConfigurationList = 85F618F42A6D4AA900E9C03C /* Build configuration list for PBXNativeTarget "sshTunnel" */; @@ -79,12 +186,16 @@ 85F618E12A6D4AA800E9C03C /* Sources */, 85F618E22A6D4AA800E9C03C /* Frameworks */, 85F618E32A6D4AA800E9C03C /* Resources */, + 85D84CE42A6D73DE0059791C /* Embed Foundation Extensions */, ); buildRules = ( ); dependencies = ( + 85D84CF12A6D744A0059791C /* PBXTargetDependency */, ); name = sshTunnel; + packageProductDependencies = ( + ); productName = sshTunnel; productReference = 85F618E52A6D4AA800E9C03C /* sshTunnel.app */; productType = "com.apple.product-type.application"; @@ -99,6 +210,9 @@ LastSwiftUpdateCheck = 1430; LastUpgradeCheck = 1430; TargetAttributes = { + 85D84CE82A6D744A0059791C = { + CreatedOnToolsVersion = 14.3; + }; 85F618E42A6D4AA800E9C03C = { CreatedOnToolsVersion = 14.3; }; @@ -118,11 +232,19 @@ projectRoot = ""; targets = ( 85F618E42A6D4AA800E9C03C /* sshTunnel */, + 85D84CE82A6D744A0059791C /* PacketTunnel */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 85D84CE72A6D744A0059791C /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 85F618E32A6D4AA800E9C03C /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -135,18 +257,105 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 85D84CE52A6D744A0059791C /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 85D84CED2A6D744A0059791C /* PacketTunnelProvider.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 85F618E12A6D4AA800E9C03C /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 853BDC732A6D7E7E000D0B5F /* VPN.swift in Sources */, 85F618EB2A6D4AA800E9C03C /* ContentView.swift in Sources */, + 853BDC712A6D7D8B000D0B5F /* VPNManager.swift in Sources */, 85F618E92A6D4AA800E9C03C /* sshTunnelApp.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 85D84CF12A6D744A0059791C /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 85D84CE82A6D744A0059791C /* PacketTunnel */; + targetProxy = 85D84CF02A6D744A0059791C /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin XCBuildConfiguration section */ + 85D84CF42A6D744A0059791C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = PacketTunnel/PacketTunnel.entitlements; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 5AC5438XDR; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = PacketTunnel/Info.plist; + INFOPLIST_KEY_CFBundleDisplayName = PacketTunnel; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path/../../Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = hossin.asaadi.sshProxy.PacketTunnel; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + SUPPORTS_MACCATALYST = YES; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 85D84CF52A6D744A0059791C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = PacketTunnel/PacketTunnel.entitlements; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 5AC5438XDR; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = PacketTunnel/Info.plist; + INFOPLIST_KEY_CFBundleDisplayName = PacketTunnel; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path/../../Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = hossin.asaadi.sshProxy.PacketTunnel; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + SUPPORTS_MACCATALYST = YES; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; 85F618F22A6D4AA900E9C03C /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -154,7 +363,7 @@ CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; - CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_MODULES = NO; CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; @@ -188,8 +397,8 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", + "BADVPN_LIBTSOCKS=1", + "BADVPN_THREAD_SAFE=1", ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; @@ -197,10 +406,12 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ""; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OBJC_BRIDGING_HEADER = PacketTunnel/Header.h; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; @@ -212,7 +423,7 @@ CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; - CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_MODULES = NO; CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; @@ -243,15 +454,21 @@ ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; + GCC_PREPROCESSOR_DEFINITIONS = ( + "BADVPN_LIBTSOCKS=1", + "BADVPN_THREAD_SAFE=1", + ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ""; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OBJC_BRIDGING_HEADER = PacketTunnel/Header.h; SWIFT_OPTIMIZATION_LEVEL = "-O"; }; name = Release; @@ -259,9 +476,11 @@ 85F618F52A6D4AA900E9C03C /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = sshTunnel/sshTunnel.entitlements; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"sshTunnel/Preview Content\""; @@ -284,10 +503,12 @@ "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13.3; MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = hossin.asaadi.V2Box.sshTunnel; + PRODUCT_BUNDLE_IDENTIFIER = hossin.asaadi.sshProxy; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = auto; - SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -297,9 +518,11 @@ 85F618F62A6D4AA900E9C03C /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = sshTunnel/sshTunnel.entitlements; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"sshTunnel/Preview Content\""; @@ -322,10 +545,12 @@ "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13.3; MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = hossin.asaadi.V2Box.sshTunnel; + PRODUCT_BUNDLE_IDENTIFIER = hossin.asaadi.sshProxy; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = auto; - SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -335,6 +560,15 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 85D84CF32A6D744A0059791C /* Build configuration list for PBXNativeTarget "PacketTunnel" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 85D84CF42A6D744A0059791C /* Debug */, + 85D84CF52A6D744A0059791C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 85F618E02A6D4AA800E9C03C /* Build configuration list for PBXProject "sshTunnel" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/sshTunnel/ContentView.swift b/sshTunnel/ContentView.swift index dae472c..707d9fb 100644 --- a/sshTunnel/ContentView.swift +++ b/sshTunnel/ContentView.swift @@ -8,14 +8,23 @@ import SwiftUI struct ContentView: View { + @ObservedObject var vpn: VPN = VPN() + var body: some View { - VStack { - Image(systemName: "globe") - .imageScale(.large) - .foregroundColor(.accentColor) - Text("Hello, world!") + Text("SSH Tunnel").font(.headline) + List { + Toggle(isOn: $vpn.toggle) { + Text("Connect SSH") + + } + .onChange(of: vpn.toggle) { value in + vpn.onToggle() + } } .padding() + .onAppear(){ + vpn.viewDidLoad() + } } } diff --git a/sshTunnel/VPN.swift b/sshTunnel/VPN.swift new file mode 100644 index 0000000..7021d1e --- /dev/null +++ b/sshTunnel/VPN.swift @@ -0,0 +1,56 @@ +// +// VPN.swift +// sshTunnel +// +// Created by HossinAsaadi on 7/23/23. +// + +import Foundation +class VPN: ObservableObject { + @Published var toggle = false + + var manager = VPNManager.shared() + func getVpnStatus() -> Bool{ + return (manager.manager.connection.status != .disconnected && + manager.manager.connection.status != .disconnecting && + manager.manager.connection.status != .invalid + ) + } + @objc func updateStatus() { + toggle = (manager.manager.connection.status != .disconnected && + manager.manager.connection.status != .disconnecting && + manager.manager.connection.status != .invalid + ) + + } + func viewDidLoad() { +#if !targetEnvironment(simulator) + + manager.loadVPNPreference() { error in + guard error == nil else { + print("load VPN preference failed: \(error.debugDescription)") + return + } + self.updateStatus() + NotificationCenter.default.addObserver(self, selector: #selector(self.updateStatus), name: NSNotification.Name.NEVPNStatusDidChange, object: self.manager.manager.connection) + } +#endif + } + func onToggle(){ + manager.enableVPNManager() { error in + guard error == nil else { + print("enable VPN failed: \(error.debugDescription)") + return + } + self.manager.toggleVPNConnection() { error in + guard error == nil else { + + fatalError("toggle VPN connection failed: \(error.debugDescription)") + } + } + + } + + } + +} diff --git a/sshTunnel/VPNManager.swift b/sshTunnel/VPNManager.swift new file mode 100644 index 0000000..ad1431a --- /dev/null +++ b/sshTunnel/VPNManager.swift @@ -0,0 +1,95 @@ +// +// VPNManager.swift +// sshTunnel +// +// Created by HossinAsaadi on 7/23/23. +// + +import Foundation +import NetworkExtension + +extension NEVPNStatus: CustomStringConvertible { + public var description: String { + switch self { + case .disconnected: return "Disconnected" + case .invalid: return "Invalid" + case .connected: return "Connected" + case .connecting: return "Connecting" + case .disconnecting: return "Disconnecting" + case .reasserting: return "Reasserting" + } + } +} + +public class VPNManager { + public var manager = NEVPNManager.shared() + + private static var sharedVPNManager: VPNManager = { + return VPNManager() + }() + + public class func shared() -> VPNManager { + return sharedVPNManager + } + + public init() {} + public func removeVPN(){ + manager.removeFromPreferences { error in + if let error = error { + print("NETunnelProviderManager removeFromPreferences error: \(error)") + } + } + } + public func loadVPNPreference(completion: @escaping (Error?) -> Void) { + NETunnelProviderManager.loadAllFromPreferences() { managers, error in + guard let managers = managers, error == nil else { + completion(error) + return + } + + if managers.count == 0 { + let newManager = NETunnelProviderManager() + newManager.protocolConfiguration = NETunnelProviderProtocol() + newManager.localizedDescription = "SSHTunnel" + newManager.protocolConfiguration?.serverAddress = "localhost" + newManager.saveToPreferences { error in + guard error == nil else { + completion(error) + return + } + newManager.loadFromPreferences { error in + self.manager = newManager + completion(nil) + } + } + } else { + self.manager = managers[0] + completion(nil) + } + } + } + public func enableVPNManager(completion: @escaping (Error?) -> Void) { + manager.isEnabled = true + manager.saveToPreferences { error in + guard error == nil else { + completion(error) + return + } + self.manager.loadFromPreferences { error in + completion(error) + } + } + } + + public func toggleVPNConnection(completion: @escaping (Error?) -> Void) { + if self.manager.connection.status == .disconnected || self.manager.connection.status == .invalid { + do { + try self.manager.connection.startVPNTunnel() + } catch { + completion(error) + } + } else { + self.manager.connection.stopVPNTunnel() + } + } +} diff --git a/sshTunnel/sshTunnel.entitlements b/sshTunnel/sshTunnel.entitlements index f2ef3ae..90b496c 100644 --- a/sshTunnel/sshTunnel.entitlements +++ b/sshTunnel/sshTunnel.entitlements @@ -2,9 +2,13 @@ - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - + com.apple.developer.networking.networkextension + + packet-tunnel-provider + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + diff --git a/sshTunnel/sshTunnelApp.swift b/sshTunnel/sshTunnelApp.swift index 63b1e89..b415fff 100644 --- a/sshTunnel/sshTunnelApp.swift +++ b/sshTunnel/sshTunnelApp.swift @@ -6,12 +6,13 @@ // import SwiftUI - @main struct sshTunnelApp: App { var body: some Scene { WindowGroup { - ContentView() + ContentView().onAppear(){ + + } } } }