Various fixes for iOS (#126)

* Readme update, solution for wireguard make in M1 machines,
* import file and restore enabled.
* xcode_patcher.rb fixed, Now no need to add openVPN framewrok in Embed frameworks manually.
* Now xcode_patcher.rb will add OpenVPN Framework to Embed Frameworks in main target, instead of Network extension.
* Update iosvpnprotocol.swift
* Protocol wasn't detected because it is working on localized description of tunnel, fixed cases.
* Code cleanup
* Speed issue fixed for wireguard.
* GetDeviceIp and bytes(speed of OpenVPN) fixed.
*Device IP method wasn't working as expected, so I replaced. and for speed in OpenVPN we need to handle message seperately for bytes.
*QR progress added with progressbar and text.
This commit is contained in:
dartsyms 2022-12-12 16:16:12 +04:00 committed by GitHub
parent a9217810e7
commit 814b66c04a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 189 additions and 323 deletions

View file

@ -2,7 +2,9 @@
#include <QFile>
@implementation QtAppDelegate
@implementation QtAppDelegate {
UIView *_screen;
}
+(QtAppDelegate *)sharedQtAppDelegate {
static dispatch_once_t pred;
@ -26,6 +28,13 @@
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
_screen = [UIScreen.mainScreen snapshotViewAfterScreenUpdates: false];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle: UIBlurEffectStyleDark];
UIVisualEffectView *blurBackround = [[UIVisualEffectView alloc] initWithEffect: blurEffect];
[_screen addSubview: blurBackround];
blurBackround.frame = _screen.frame;
UIWindow *_window = UIApplication.sharedApplication.keyWindow;
[_window addSubview: _screen];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
@ -44,6 +53,7 @@
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
[_screen removeFromSuperview];
}
- (void)applicationWillTerminate:(UIApplication *)application

View file

@ -125,7 +125,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
case .wireguard:
handleWireguardAppMessage(messageData, completionHandler: completionHandler)
case .openvpn:
handleWireguardAppMessage(messageData, completionHandler: completionHandler)
handleOpenVPNAppMessage(messageData, completionHandler: completionHandler)
case .shadowsocks:
break
// handleShadowSocksAppMessage(messageData, completionHandler: completionHandler)
@ -297,6 +297,21 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
}
}
private func handleOpenVPNAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)? = nil) {
guard let completionHandler = completionHandler else { return }
if messageData.count == 1 && messageData[0] == 0 {
let bytesin = ovpnAdapter.transportStatistics.bytesIn
let strBytesin = "rx_bytes=" + String(bytesin);
let bytesout = ovpnAdapter.transportStatistics.bytesOut
let strBytesout = "tx_bytes=" + String(bytesout);
let strData = strBytesin + "\n" + strBytesout;
let data = Data(strData.utf8)
completionHandler(data)
}
}
/*
private func handleShadowSocksAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)? = nil) {
guard let completionHandler = completionHandler else { return }

View file

@ -388,7 +388,7 @@ public class IOSVpnProtocolImpl : NSObject {
proto.providerBundleIdentifier = vpnBundleID
tunnel!.protocolConfiguration = proto
tunnel!.localizedDescription = vpnName
tunnel!.localizedDescription = "Amnezia Wireguard"
tunnel!.isEnabled = true
tunnel!.saveToPreferences { [unowned self] saveError in
@ -527,8 +527,9 @@ public class IOSVpnProtocolImpl : NSObject {
@objc func checkStatus(callback: @escaping (String, String, String) -> Void) {
Logger.global?.log(message: "Check status")
// assert(tunnel != nil)
print("check status")
let protoType = (tunnel!.localizedDescription ?? "").toTunnelType
print(protoType);
switch protoType {
case .wireguard:
@ -559,7 +560,7 @@ public class IOSVpnProtocolImpl : NSObject {
print("server IP: \(serverIpv4Gateway)")
let deviceIpv4Address = getTunIPAddress()
let deviceIpv4Address = getWiFiAddress()
print("device IP: \(serverIpv4Gateway)")
if deviceIpv4Address == nil {
callback("", "", "")
@ -610,8 +611,9 @@ public class IOSVpnProtocolImpl : NSObject {
print("server IP: \(serverIpv4Gateway)")
let deviceIpv4Address = getTunIPAddress()
print("device IP: \(serverIpv4Gateway)")
let deviceIpv4Address = getWiFiAddress()
print("device IP: \(deviceIpv4Address)")
if deviceIpv4Address == nil {
callback("", "", "")
return
@ -690,38 +692,45 @@ public class IOSVpnProtocolImpl : NSObject {
}
}
private func getTunIPAddress() -> String? {
var address: String? = nil
var interfaces: UnsafeMutablePointer<ifaddrs>? = nil
var temp_addr: UnsafeMutablePointer<ifaddrs>? = nil
var success: Int = 0
// retrieve the current interfaces - returns 0 on success
success = Int(getifaddrs(&interfaces))
if success == 0 {
// Loop through linked list of interfaces
temp_addr = interfaces
while temp_addr != nil {
if temp_addr?.pointee.ifa_addr == nil {
continue
func getWiFiAddress() -> String? {
var address : String?
// Get list of all interfaces on the local machine:
var ifaddr : UnsafeMutablePointer<ifaddrs>?
guard getifaddrs(&ifaddr) == 0 else { return nil }
guard let firstAddr = ifaddr else { return nil }
// For each interface ...
for ifptr in sequence(first: firstAddr, next: { $0.pointee.ifa_next }) {
let interface = ifptr.pointee
// Check for IPv4 or IPv6 interface:
let addrFamily = interface.ifa_addr.pointee.sa_family
//if addrFamily == UInt8(AF_INET) || addrFamily == UInt8(AF_INET6) { // **ipv6 committed
if addrFamily == UInt8(AF_INET){
// Check interface name:
let name = String(cString: interface.ifa_name)
if name == "en0" {
// Convert interface address to a human readable string:
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
getnameinfo(interface.ifa_addr, socklen_t(interface.ifa_addr.pointee.sa_len),
&hostname, socklen_t(hostname.count),
nil, socklen_t(0), NI_NUMERICHOST)
address = String(cString: hostname)
}
if temp_addr?.pointee.ifa_addr.pointee.sa_family == UInt8(AF_INET) {
// Check if interface is en0 which is the wifi connection on the iPhone
if let name = temp_addr?.pointee.ifa_name, ((String(utf8String: name)?.contains("tun")) != nil) {
// Get NSString from C String
if let value = temp_addr?.pointee.ifa_addr as? sockaddr_in {
address = String(utf8String: inet_ntoa(value.sin_addr))
}
}
}
temp_addr = temp_addr?.pointee.ifa_next
}
}
freeifaddrs(interfaces)
freeifaddrs(ifaddr)
return address
}
}
enum TunnelType: String {
case wireguard, openvpn, shadowsocks, empty
}
@ -729,9 +738,9 @@ enum TunnelType: String {
extension String {
var toTunnelType: TunnelType {
switch self {
case "wireguard": return .wireguard
case "openvpn": return .openvpn
case "shadowsocks": return .shadowsocks
case "Amnezia Wireguard": return .wireguard
case "Amnezia OpenVPN": return .openvpn
case "Amnezia ShadowSocks": return .shadowsocks
default:
return .empty
}