Added missing parameters for init and connect

This commit is contained in:
Alex Kh 2021-12-01 20:02:54 +04:00
parent 9e0fd7d51e
commit 4976dc3a4c
10 changed files with 95 additions and 113 deletions

View file

@ -217,7 +217,7 @@ enum ConnectionState : NSInteger;
SWIFT_CLASS("_TtC10AmneziaVPN18IOSVpnProtocolImpl")
@interface IOSVpnProtocolImpl : NSObject
- (nonnull instancetype)initWithBundleID:(NSString * _Nonnull)bundleID privateKey:(NSData * _Nonnull)privateKey deviceIpv4Address:(NSString * _Nonnull)deviceIpv4Address deviceIpv6Address:(NSString * _Nonnull)deviceIpv6Address closure:(void (^ _Nonnull)(enum ConnectionState, NSDate * _Nullable))closure callback:(void (^ _Nonnull)(BOOL))callback OBJC_DESIGNATED_INITIALIZER;
- (void)connectWithDnsServer:(NSString * _Nonnull)dnsServer serverIpv6Gateway:(NSString * _Nonnull)serverIpv6Gateway serverPublicKey:(NSString * _Nonnull)serverPublicKey serverIpv4AddrIn:(NSString * _Nonnull)serverIpv4AddrIn serverPort:(NSInteger)serverPort allowedIPAddressRanges:(NSArray<VPNIPAddressRange *> * _Nonnull)allowedIPAddressRanges ipv6Enabled:(Boolean)enabled reason:(NSInteger)reason failureCallback:(void (^ _Nonnull)(void))failureCallback;
- (void)connectWithDnsServer:(NSString * _Nonnull)dnsServer serverIpv6Gateway:(NSString * _Nonnull)serverIpv6Gateway serverPublicKey:(NSString * _Nonnull)serverPublicKey presharedKey:(NSString * _Nonnull)presharedKey serverIpv4AddrIn:(NSString * _Nonnull)serverIpv4AddrIn serverPort:(NSInteger)serverPort allowedIPAddressRanges:(NSArray<VPNIPAddressRange *> * _Nonnull)allowedIPAddressRanges ipv6Enabled:(Boolean)enabled reason:(NSInteger)reason failureCallback:(void (^ _Nonnull)(void))failureCallback;
- (void)disconnect;
- (void)checkStatusWithCallback:(void (^ _Nonnull)(NSString * _Nonnull, NSString * _Nonnull, NSString * _Nonnull))callback;
- (nonnull instancetype)init SWIFT_UNAVAILABLE;

View file

@ -1,14 +0,0 @@
<?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.application-groups</key>
<array/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
</dict>
</plist>

View file

@ -299,50 +299,46 @@ ios {
Q_ENABLE_BITCODE.name = ENABLE_BITCODE
QMAKE_MAC_XCODE_SETTINGS += Q_ENABLE_BITCODE
CONFIG(iphoneos, iphoneos|iphonesimulator) {
message("Building for iPhone OS")
QMAKE_TARGET_BUNDLE_PREFIX = org.amnezia
QMAKE_BUNDLE = AmneziaVPN
QMAKE_IOS_DEPLOYMENT_TARGET = 12.0
QMAKE_APPLE_TARGETED_DEVICE_FAMILY = 1
QMAKE_DEVELOPMENT_TEAM = X7UJ388FXK
QMAKE_PROVISIONING_PROFILE = f2fefb59-14aa-4aa9-ac14-1d5531b06dcc
QMAKE_XCODE_CODE_SIGN_IDENTITY = "Apple Distribution"
XCODEBUILD_FLAGS += -allowProvisioningUpdates
DEFINES += iphoneos
contains(QT_ARCH, arm64) {
message("Building for iOS/ARM v8 64-bit architecture")
ARCH_TAG = "ios_armv8_64"
LIBS += $$PWD/3rd/OpenSSL/lib/ios/iphone/libcrypto.a
LIBS += $$PWD/3rd/OpenSSL/lib/ios/iphone/libssl.a
} else {
message("Building for iOS/ARM v7 (32-bit) architecture")
ARCH_TAG = "ios_armv7"
}
}
CONFIG(iphonesimulator, iphoneos|iphonesimulator) {
message("Building for iPhone Simulator")
ARCH_TAG = "ios_x86_64"
# CONFIG(iphoneos, iphoneos|iphonesimulator) {
iphoneos {
message("Building for iPhone OS")
QMAKE_TARGET_BUNDLE_PREFIX = org.amnezia
QMAKE_BUNDLE = AmneziaVPN
QMAKE_IOS_DEPLOYMENT_TARGET = 12.0
QMAKE_APPLE_TARGETED_DEVICE_FAMILY = 1
QMAKE_DEVELOPMENT_TEAM = X7UJ388FXK
QMAKE_PROVISIONING_PROFILE = f2fefb59-14aa-4aa9-ac14-1d5531b06dcc
QMAKE_XCODE_CODE_SIGN_IDENTITY = "Apple Distribution"
QMAKE_INFO_PLIST= $$PWD/ios/app/Info.plist
DEFINES += iphoneos
XCODEBUILD_FLAGS += -allowProvisioningUpdates
DEFINES += iphoneos
contains(QT_ARCH, arm64) {
message("Building for iOS/ARM v8 64-bit architecture")
ARCH_TAG = "ios_armv8_64"
LIBS += $$PWD/3rd/OpenSSL/lib/ios/iphone/libcrypto.a
LIBS += $$PWD/3rd/OpenSSL/lib/ios/iphone/libssl.a
} else {
message("Building for iOS/ARM v7 (32-bit) architecture")
ARCH_TAG = "ios_armv7"
}
}
# }
# CONFIG(iphonesimulator, iphoneos|iphonesimulator) {
# message("Building for iPhone Simulator")
# ARCH_TAG = "ios_x86_64"
#
# DEFINES += iphonesimulator
#
# LIBS += $$PWD/3rd/OpenSSL/lib/ios/simulator/libcrypto.a
# LIBS += $$PWD/3rd/OpenSSL/lib/ios/simulator/libssl.a
# iphonesimulator {
# message("Building for iPhone Simulator")
# ARCH_TAG = "ios_x86_64"
#
# DEFINES += iphonesimulator
#
# LIBS += $$PWD/3rd/OpenSSL/lib/ios/simulator/libcrypto.a
# LIBS += $$PWD/3rd/OpenSSL/lib/ios/simulator/libssl.a
# }
# }
NETWORKEXTENSION=1

View file

@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ADJUST_SDK_TOKEN</key>
<string>$(ADJUST_SDK_TOKEN)</string>
<key>CFBundleAllowMixedLocalizations</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
@ -36,8 +34,6 @@
<false/>
<key>UILaunchStoryboardName</key>
<string>AmneziaVPNLaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array/>
<key>UIRequiresFullScreen</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
@ -49,7 +45,5 @@
<array/>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>com.wireguard.ios.app_group_id</key>
<string>group.org.mozilla.ios.Guardian</string>
</dict>
</plist>

View file

@ -8,9 +8,13 @@
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>$(GROUP_ID_IOS)</string>
<string>group.ru.kotit.AmneziaVPN.udev</string>
</array>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)group.ru.kotit.AmneziaVPN.udev</string>
</array>
</dict>
</plist>

View file

@ -8,7 +8,11 @@
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>$(GROUP_ID_IOS)</string>
<string>group.ru.kotit.AmneziaVPN.udev</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)group.ru.kotit.AmneziaVPN.udev</string>
</array>
</dict>
</plist>

View file

@ -2,39 +2,28 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>AmneziaVPNNetworkExtension</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
@ -42,11 +31,5 @@
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).PacketTunnelProvider</string>
</dict>
<key>com.wireguard.ios.app_group_id</key>
<string>group.$(APP_ID_IOS)</string>
<key>com.wireguard.macos.app_group_id</key>
<string>$(DEVELOPMENT_TEAM).group.$(APP_ID_MACOS)</string>
</dict>
</plist>

View file

@ -61,16 +61,19 @@ public class IOSVpnProtocolImpl : NSObject {
let nsManagers = managers ?? []
Logger.global?.log(message: "We have received \(nsManagers.count) managers.")
print("We have received \(nsManagers.count) managers.")
let tunnel = nsManagers.first(where: IOSVpnProtocolImpl.isOurManager(_:))
if tunnel == nil {
Logger.global?.log(message: "Creating the tunnel")
print("Creating the tunnel")
self!.tunnel = NETunnelProviderManager()
closure(IOSConnectionState.Disconnected, nil)
return
}
Logger.global?.log(message: "Tunnel already exists")
print("Tunnel already exists")
self!.tunnel = tunnel
if tunnel?.connection.status == .connected {
@ -87,18 +90,25 @@ public class IOSVpnProtocolImpl : NSObject {
switch session.status {
case .connected:
Logger.global?.log(message: "STATE CHANGED: connected")
print("STATE CHANGED: connected")
case .connecting:
Logger.global?.log(message: "STATE CHANGED: connecting")
print("STATE CHANGED: connecting")
case .disconnected:
Logger.global?.log(message: "STATE CHANGED: disconnected")
print("STATE CHANGED: disconnected")
case .disconnecting:
Logger.global?.log(message: "STATE CHANGED: disconnecting")
print("STATE CHANGED: disconnecting")
case .invalid:
Logger.global?.log(message: "STATE CHANGED: invalid")
print("STATE CHANGED: invalid")
case .reasserting:
Logger.global?.log(message: "STATE CHANGED: reasserting")
print("STATE CHANGED: reasserting")
default:
Logger.global?.log(message: "STATE CHANGED: unknown status")
print("STATE CHANGED: unknown status")
}
// We care about "unknown" state changes.
@ -129,10 +139,11 @@ public class IOSVpnProtocolImpl : NSObject {
}
Logger.global?.log(message: "Found the manager with the correct bundle identifier: \(tunnelProto.providerBundleIdentifier!)")
print("Found the manager with the correct bundle identifier: \(tunnelProto.providerBundleIdentifier!)")
return true
}
@objc func connect(dnsServer: String, serverIpv6Gateway: String, serverPublicKey: String, serverIpv4AddrIn: String, serverPort: Int, allowedIPAddressRanges: Array<VPNIPAddressRange>, ipv6Enabled: Bool, reason: Int, failureCallback: @escaping () -> Void) {
@objc func connect(dnsServer: String, serverIpv6Gateway: String, serverPublicKey: String, presharedKey: String, serverIpv4AddrIn: String, serverPort: Int, allowedIPAddressRanges: Array<VPNIPAddressRange>, ipv6Enabled: Bool, reason: Int, failureCallback: @escaping () -> Void) {
Logger.global?.log(message: "Connecting")
assert(tunnel != nil)
@ -144,6 +155,7 @@ public class IOSVpnProtocolImpl : NSObject {
let ipv6GatewayIP = IPv6Address(serverIpv6Gateway)
var peerConfiguration = PeerConfiguration(publicKey: keyData)
peerConfiguration.preSharedKey = PreSharedKey(base64Key: presharedKey)
peerConfiguration.endpoint = Endpoint(from: serverIpv4AddrIn + ":\(serverPort )")
peerConfiguration.allowedIPs = []
@ -168,6 +180,7 @@ public class IOSVpnProtocolImpl : NSObject {
}
}
interface.dns = [ DNSServer(address: dnsServerIP!)]
interface.mtu = 1412 // 1280
if (ipv6Enabled) {
interface.dns.append(DNSServer(address: ipv6GatewayIP!))
@ -206,6 +219,7 @@ public class IOSVpnProtocolImpl : NSObject {
}
Logger.global?.log(message: "Loading the tunnel succeeded")
print("Loading the tunnel succeeded")
do {
if (reason == 1 /* ReasonSwitching */) {
@ -219,8 +233,10 @@ public class IOSVpnProtocolImpl : NSObject {
Logger.global?.log(message: "Failed to convert response to string")
return
}
print("Config sent to NE: \(configString)")
}
} else {
print("starting tunnel")
try (self.tunnel!.connection as? NETunnelProviderSession)?.startTunnel()
}
} catch let error {

View file

@ -96,30 +96,29 @@ bool IOSVpnProtocol::initialize()
case ConnectionStateError: {
[m_controller dealloc];
m_controller = nullptr;
emit initialized(false, false, QDateTime());
emit connectionStateChanged(VpnConnectionState::Error);
return;
}
case ConnectionStateConnected: {
Q_ASSERT(date);
QDateTime qtDate(QDateTime::fromNSDate(date));
emit initialized(true, true, qtDate);
emit connectionStateChanged(VpnConnectionState::Connected);
return;
}
case ConnectionStateDisconnected:
// Just in case we are connecting, let's call disconnect.
[m_controller disconnect];
emit initialized(true, false, QDateTime());
emit connectionStateChanged(VpnConnectionState::Disconnected);
return;
}
}
callback:^(BOOL a_connected) {
qDebug() << "State changed: " << a_connected;
if (a_connected) {
emit isConnected();
emit connectionStateChanged(Connected);
return;
}
emit isDisconnected();
// emit connectionStateChanged(Disconnected);
}];
}
return true;
@ -176,6 +175,7 @@ ErrorCode IOSVpnProtocol::start()
[m_controller connectWithDnsServer:dnsServersList.takeFirst().toNSString()
serverIpv6Gateway:@"FE80::1"
serverPublicKey:serverPubKey.toNSString()
presharedKey:pskKey.toNSString()
serverIpv4AddrIn:serverAddr.toNSString()
serverPort:port.toInt()
allowedIPAddressRanges:allowedIPAddressRangesNS
@ -183,7 +183,7 @@ ErrorCode IOSVpnProtocol::start()
reason:0
failureCallback:^() {
qDebug() << "IOSVPNProtocol - connection failed";
emit isDisconnected();
emit connectionStateChanged(Disconnected);
}];
return NoError;
}
@ -192,7 +192,7 @@ void IOSVpnProtocol::stop()
{
if (!m_controller) {
qDebug() << "Not correctly initialized";
emit isDisconnected();
emit connectionStateChanged(Disconnected);
return;
}

View file

@ -159,15 +159,14 @@ IOS_FLAGS="
Q_OS_IOS=1
"
#printn Y "Mode: "
#if [[ "$RELEASE" ]]; then
# print G "release"
# MODE="CONFIG-=debug CONFIG+=release CONFIG-=debug_and_release"
#else
# print G "debug"
# MODE="CONFIG+=debug CONFIG-=release CONFIG-=debug_and_release"
#fi
MODE="CONFIG-=debug CONFIG+=release CONFIG-=debug_and_release"
printn Y "Mode: "
if [[ "$RELEASE" ]]; then
print G "release"
MODE="CONFIG-=debug CONFIG+=release CONFIG-=debug_and_release"
else
print G "debug"
MODE="CONFIG+=debug CONFIG-=release CONFIG-=debug_and_release"
fi
OSRUBY=$OS
printn Y "OS: "