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") SWIFT_CLASS("_TtC10AmneziaVPN18IOSVpnProtocolImpl")
@interface IOSVpnProtocolImpl : NSObject @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; - (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)disconnect;
- (void)checkStatusWithCallback:(void (^ _Nonnull)(NSString * _Nonnull, NSString * _Nonnull, NSString * _Nonnull))callback; - (void)checkStatusWithCallback:(void (^ _Nonnull)(NSString * _Nonnull, NSString * _Nonnull, NSString * _Nonnull))callback;
- (nonnull instancetype)init SWIFT_UNAVAILABLE; - (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,7 +299,8 @@ ios {
Q_ENABLE_BITCODE.name = ENABLE_BITCODE Q_ENABLE_BITCODE.name = ENABLE_BITCODE
QMAKE_MAC_XCODE_SETTINGS += Q_ENABLE_BITCODE QMAKE_MAC_XCODE_SETTINGS += Q_ENABLE_BITCODE
CONFIG(iphoneos, iphoneos|iphonesimulator) { # CONFIG(iphoneos, iphoneos|iphonesimulator) {
iphoneos {
message("Building for iPhone OS") message("Building for iPhone OS")
QMAKE_TARGET_BUNDLE_PREFIX = org.amnezia QMAKE_TARGET_BUNDLE_PREFIX = org.amnezia
QMAKE_BUNDLE = AmneziaVPN QMAKE_BUNDLE = AmneziaVPN
@ -308,6 +309,7 @@ ios {
QMAKE_DEVELOPMENT_TEAM = X7UJ388FXK QMAKE_DEVELOPMENT_TEAM = X7UJ388FXK
QMAKE_PROVISIONING_PROFILE = f2fefb59-14aa-4aa9-ac14-1d5531b06dcc QMAKE_PROVISIONING_PROFILE = f2fefb59-14aa-4aa9-ac14-1d5531b06dcc
QMAKE_XCODE_CODE_SIGN_IDENTITY = "Apple Distribution" QMAKE_XCODE_CODE_SIGN_IDENTITY = "Apple Distribution"
QMAKE_INFO_PLIST= $$PWD/ios/app/Info.plist
XCODEBUILD_FLAGS += -allowProvisioningUpdates XCODEBUILD_FLAGS += -allowProvisioningUpdates
@ -324,18 +326,11 @@ ios {
ARCH_TAG = "ios_armv7" ARCH_TAG = "ios_armv7"
} }
} }
# }
CONFIG(iphonesimulator, iphoneos|iphonesimulator) {
message("Building for iPhone Simulator")
ARCH_TAG = "ios_x86_64"
DEFINES += iphoneos
LIBS += $$PWD/3rd/OpenSSL/lib/ios/iphone/libcrypto.a
LIBS += $$PWD/3rd/OpenSSL/lib/ios/iphone/libssl.a
}
# CONFIG(iphonesimulator, iphoneos|iphonesimulator) { # CONFIG(iphonesimulator, iphoneos|iphonesimulator) {
# iphonesimulator {
# message("Building for iPhone Simulator") # message("Building for iPhone Simulator")
# ARCH_TAG = "ios_x86_64" # ARCH_TAG = "ios_x86_64"
# #
@ -343,6 +338,7 @@ ios {
# #
# LIBS += $$PWD/3rd/OpenSSL/lib/ios/simulator/libcrypto.a # LIBS += $$PWD/3rd/OpenSSL/lib/ios/simulator/libcrypto.a
# LIBS += $$PWD/3rd/OpenSSL/lib/ios/simulator/libssl.a # LIBS += $$PWD/3rd/OpenSSL/lib/ios/simulator/libssl.a
# }
# } # }
NETWORKEXTENSION=1 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"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>ADJUST_SDK_TOKEN</key>
<string>$(ADJUST_SDK_TOKEN)</string>
<key>CFBundleAllowMixedLocalizations</key> <key>CFBundleAllowMixedLocalizations</key>
<true/> <true/>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
@ -36,8 +34,6 @@
<false/> <false/>
<key>UILaunchStoryboardName</key> <key>UILaunchStoryboardName</key>
<string>AmneziaVPNLaunchScreen</string> <string>AmneziaVPNLaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array/>
<key>UIRequiresFullScreen</key> <key>UIRequiresFullScreen</key>
<true/> <true/>
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
@ -49,7 +45,5 @@
<array/> <array/>
<key>UIUserInterfaceStyle</key> <key>UIUserInterfaceStyle</key>
<string>Light</string> <string>Light</string>
<key>com.wireguard.ios.app_group_id</key>
<string>group.org.mozilla.ios.Guardian</string>
</dict> </dict>
</plist> </plist>

View file

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

View file

@ -8,7 +8,11 @@
</array> </array>
<key>com.apple.security.application-groups</key> <key>com.apple.security.application-groups</key>
<array> <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> </array>
</dict> </dict>
</plist> </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"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <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> <key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string> <string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>
<string>AmneziaVPNNetworkExtension</string> <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> <key>NSExtension</key>
<dict> <dict>
<key>NSExtensionPointIdentifier</key> <key>NSExtensionPointIdentifier</key>
@ -42,11 +31,5 @@
<key>NSExtensionPrincipalClass</key> <key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).PacketTunnelProvider</string> <string>$(PRODUCT_MODULE_NAME).PacketTunnelProvider</string>
</dict> </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> </dict>
</plist> </plist>

View file

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

View file

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

View file

@ -159,15 +159,14 @@ IOS_FLAGS="
Q_OS_IOS=1 Q_OS_IOS=1
" "
#printn Y "Mode: " printn Y "Mode: "
#if [[ "$RELEASE" ]]; then if [[ "$RELEASE" ]]; then
# print G "release" 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" 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 OSRUBY=$OS
printn Y "OS: " printn Y "OS: "