-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
288f98c
commit 53da43d
Showing
47 changed files
with
949 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Header.h | ||
// PacketTunnel | ||
// | ||
// Created by HossinAsaadi on 7/23/23. | ||
// | ||
|
||
|
||
#ifndef Header_h | ||
#define Header_h | ||
#import <libtun2socks/tun2socks.h> | ||
|
||
#endif /* Header_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.networkextension.packet-tunnel</string> | ||
<key>NSExtensionPrincipalClass</key> | ||
<string>$(PRODUCT_MODULE_NAME).PacketTunnelProvider</string> | ||
</dict> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.developer.networking.networkextension</key> | ||
<array> | ||
<string>packet-tunnel-provider</string> | ||
</array> | ||
<key>com.apple.security.app-sandbox</key> | ||
<true/> | ||
<key>com.apple.security.application-groups</key> | ||
<array> | ||
<string>group.hossin.asaadi.sshTunnel</string> | ||
</array> | ||
<key>com.apple.security.network.client</key> | ||
<true/> | ||
<key>com.apple.security.network.server</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>AvailableLibraries</key> | ||
<array> | ||
<dict> | ||
<key>LibraryIdentifier</key> | ||
<string>ios-arm64_x86_64-simulator</string> | ||
<key>LibraryPath</key> | ||
<string>SshLib.framework</string> | ||
<key>SupportedArchitectures</key> | ||
<array> | ||
<string>arm64</string> | ||
<string>x86_64</string> | ||
</array> | ||
<key>SupportedPlatform</key> | ||
<string>ios</string> | ||
<key>SupportedPlatformVariant</key> | ||
<string>simulator</string> | ||
</dict> | ||
<dict> | ||
<key>LibraryIdentifier</key> | ||
<string>macos-arm64_x86_64</string> | ||
<key>LibraryPath</key> | ||
<string>SshLib.framework</string> | ||
<key>SupportedArchitectures</key> | ||
<array> | ||
<string>arm64</string> | ||
<string>x86_64</string> | ||
</array> | ||
<key>SupportedPlatform</key> | ||
<string>macos</string> | ||
</dict> | ||
<dict> | ||
<key>LibraryIdentifier</key> | ||
<string>ios-arm64</string> | ||
<key>LibraryPath</key> | ||
<string>SshLib.framework</string> | ||
<key>SupportedArchitectures</key> | ||
<array> | ||
<string>arm64</string> | ||
</array> | ||
<key>SupportedPlatform</key> | ||
<string>ios</string> | ||
</dict> | ||
</array> | ||
<key>CFBundlePackageType</key> | ||
<string>XFWK</string> | ||
<key>XCFrameworkFormatVersion</key> | ||
<string>1.0</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Versions/Current/Headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Versions/Current/Modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Versions/Current/Resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Versions/Current/SshLib |
13 changes: 13 additions & 0 deletions
13
SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/SshLib.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
16 changes: 16 additions & 0 deletions
16
SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/Sshlib.objc.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
29 changes: 29 additions & 0 deletions
29
SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/Universe.objc.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <NSObject> | ||
- (NSString* _Nonnull)error; | ||
@end | ||
|
||
@class Universeerror; | ||
|
||
@interface Universeerror : NSError <goSeqRefInterface, Universeerror> { | ||
} | ||
@property(strong, readonly) _Nonnull id _ref; | ||
|
||
- (nonnull instancetype)initWithRef:(_Nonnull id)ref; | ||
- (NSString* _Nonnull)error; | ||
@end | ||
|
||
#endif |
35 changes: 35 additions & 0 deletions
35
SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Headers/ref.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <Foundation/Foundation.h> | ||
|
||
// 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 |
8 changes: 8 additions & 0 deletions
8
SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Modules/module.modulemap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
framework module "SshLib" { | ||
header "ref.h" | ||
header "Sshlib.objc.h" | ||
header "Universe.objc.h" | ||
header "SshLib.h" | ||
|
||
export * | ||
} |
6 changes: 6 additions & 0 deletions
6
SshLib.xcframework/ios-arm64/SshLib.framework/Versions/A/Resources/Info.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
</dict> | ||
</plist> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A |
1 change: 1 addition & 0 deletions
1
SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Versions/Current/Headers |
1 change: 1 addition & 0 deletions
1
SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Versions/Current/Modules |
1 change: 1 addition & 0 deletions
1
SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Versions/Current/Resources |
1 change: 1 addition & 0 deletions
1
SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/SshLib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Versions/Current/SshLib |
13 changes: 13 additions & 0 deletions
13
SshLib.xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/SshLib.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
16 changes: 16 additions & 0 deletions
16
....xcframework/ios-arm64_x86_64-simulator/SshLib.framework/Versions/A/Headers/Sshlib.objc.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.