ss-abramchuk / openvpnadapter Goto Github PK
View Code? Open in Web Editor NEWObjective-C wrapper for OpenVPN library. Compatible with iOS and macOS.
License: GNU Affero General Public License v3.0
Objective-C wrapper for OpenVPN library. Compatible with iOS and macOS.
License: GNU Affero General Public License v3.0
Dear @ss-abramchuk
You are doing great framework. I got it work perfectly with latest OpenVPN library. The application side is very clean to understand how to work via application extension.
Now my next mission is once install VPN settings (App Extension or VPN profile ...whatever) VPN should be always-ON.
I read some articles about Always-ON VPN:
Apple Doc:
https://help.apple.com/deployment/ios/#/iore8b083096
(This is main principle from Apple. But not even OpenVPN)
About OpenVPN FAQ:
https://docs.openvpn.net/connecting/connecting-to-access-server-with-apple-ios/faq-regarding-openvpn-connect-ios/#Can_I_import_an_OpenVPN_profile_via_an_iOS_mobileconfig_file
(I could not get it work. Many configurations )
Tool to generate .mobileconfig file for OpenVPN:
https://github.com/iphoting/ovpnmcgen.rb
(I think this is very useful. but I have no idea about --p12file PKCS#12 file)
Do you have any experience about Always-On VPN ?
If yes, please share your knowledge.
Thank you.
I am using OpenVPNAdapter on my iOS project.
When i use ovpn file on my project, i can get this error.
This is client side source code.
vpnAdapter = [[OpenVPNAdapter alloc] init];
vpnAdapter.delegate = self;
vpnReachability = [[OpenVPNReachability alloc] init];
NSData *fileContent = /****.ovpn file data****/;
OpenVPNConfiguration *vpnConfiguration = [[OpenVPNConfiguration alloc] init];
[vpnConfiguration setFileContent:fileContent];
NSError *error = nil;
OpenVPNProperties *properties = [vpnAdapter applyConfiguration:vpnConfiguration error:&error];
/I can get errors on this part/
if (error != nil) {
NSLog(@"properties Error");
return;
}
And this is content of .ovpn file.
persist-key
persist-tun
client
dev tun
proto tcp
remote 185.186.78.157 8181
auth-user-pass
resolv-retry infinite
nobind
pull
comp-lzo
verb 3
-----BEGIN CERTIFICATE-----
//////////////////////////////////////
-----END CERTIFICATE-----
dhcp-option DNS xx.sss.xxx.xx
Looking forward to see reply.
Thanks
Sasha
Hello
I tried to use this adapter for my personal purpose.
Btw, this adapter has limitation in network speed.
When i use openvpn client app, speed was up to 30mbps.
but, if i use this adapter, speed was up to 1mbps.
I think that there is some limitation in buffer size.
I tried to add following settings into vpn profile.
sndbuf 65536
rcvbuff 65536
but, when i connect to vpn, if i debug, sometimes i get this error.
Tun write error: write_some: No buffer space available
Despite enabling keychain sharing group and adding to entitlement file, we are still getting below mentioned error:
OSStatus error:[-34018] Internal error when a required entitlement isn't present, client has neither application-identifier nor keychain-access-groups entitlements.
Internal error when a required entitlement isn't present, client has neither application-identifier nor keychain-access-groups entitlements.
The operation couldn’t be completed. (NEVPNErrorDomain error 1.)
Hi,
When i connect to VPN (Wi-Fi), then close Wi-Fi, and the VPN is closed.
This is my code in startTunnelWithOptions
method:
__weak typeof(self) weakSelf = self;
[self.reachability startTrackingWithCallback:^(OpenVPNReachabilityStatus status) {
[weakSelf.adapter reconnectAfterTimeInterval:3];
}];
But the log is :
'-----Transport Error: EADDRNOTAVAIL: Can't assign requested address'
Client terminated, restarting in 5000 ms...
-----Client terminated, restarting in 5000 ms...
,
No other logs.
Thank you..
Hi
I'm developing OpenVPN in iOS. I follow your instruction. But I have one question.
I can't know how to use PacketTunnelProvider. Please let me know how can I use. If possible, please share your IM or Email.
Regards.
I would like to use this project to implement OpenVPN on IOS, but is this project yet to be completed?
Condition: Turn on WIFI and cellular data
When i connected openvpn, it works fine
But then I closed the WIFI, the network can not automatically switch to the cellular data,
I tried using the "reconnect" feature, but it did not work.
What can I do to solve this problem?
Hi @ss-abramchuk!
I too am experiencing speed issues as noted in #5, I noticed you mentioned something about a proper workaround instead of paired sockets but didn’t have the time to implement this.
Could we perhaps have a discussion about how to achieve this as I would be delighted to contribute to this and speed up the developement process. :)
The one used ikEv2?IPSec?L2TP? ss?
I am sorry to trouble you, i write a very simple client with your adapter, which code is very similar as your test code, the status told me "Connected via tun", but when i open the website, it can not visit google, so how i fix that? Thank you.
i need your help !!!!
i try to run your branch's feature/test-client ,but when it is connecting the iphone's logs tell me SIOCGIFMTU failed: Device not configured and interface_get_mtu failed (6), defaulting to max mtu.
it makes me so sad. i don't understand what's happend.
Hello,
Build the OpenVPNAdapter project and use in iOS, But this framework don't support ECC. what's should i do?
thank you.
Issue when archiving, already reinstalled the framework and changed the configurations
When I try to build project under Xcode8.2, errors occurs like
ld: warning: ignoring file /Users/a-a-dev/dev/openvpn-ios-client-master/OpenVPN Tunnel Provider/Vendors/polarssl/lib/libmbedtls.a, missing required architecture x86_64 in file /Users/a-a-dev/dev/openvpn-ios-client-master/OpenVPN Tunnel Provider/Vendors/polarssl/lib/libmbedtls.a (3 slices)
ld: warning: ignoring file /Users/a-a-dev/dev/openvpn-ios-client-master/OpenVPN Tunnel Provider/Vendors/lz4/lib/liblz4.a, missing required architecture x86_64 in file /Users/a-a-dev/dev/openvpn-ios-client-master/OpenVPN Tunnel Provider/Vendors/lz4/lib/liblz4.a (3 slices)
Undefined symbols for architecture x86_64:
"_LZ4_decompress_safe", referenced from:
openvpn::CompressLZ4Base::do_decompress(openvpn::BufferAllocatedType<unsigned char, openvpn::thread_unsafe_refcount>&) in ovpncli.o
"_LZ4_compress", referenced from:
openvpn::CompressLZ4Base::do_compress(openvpn::BufferAllocatedType<unsigned char, openvpn::thread_unsafe_refcount>&) in ovpncli.o
"_gcm_init", referenced from:
openvpn::PolarSSLCrypto::CipherContextGCM::init(openvpn::CryptoAlgs::Type, unsigned char const*, unsigned int, int) in ovpncli.o
......
3X!
i use this code to connect with my vpn server. log says that vpn is connected. But no confirmation shows here to connect vpn server.
Connected via tun
Another problem is when i check my ip is not showing my vpn ip.
Help me out to make this possible ?
Hi @ss-abramchuk ,
The configureTunnelWithSettings:callback:
method of OpenVPNAdapterDelegate
, I added the following code :
__weak typeof(self) weakself = self; [self setTunnelNetworkSettings:settings completionHandler:^(NSError * _Nullable error) { callback(error == nil ? weakself.flow : nil); }];
, but when run, get an error, @"NSLocalizedFailureReason" : @"Error creating TUN/TAP interface."
, Why the mistake?
Thank you.
halo, I develop an app based on OpenVPNAdapter,and I can connect VPN successfully, but when I switch to other network, OpenVPNReachabilityStatus change to OpenVPNReachabilityStatusNotReachable,and vpnadaptor will lost connect,then,even if I restart app,it dose not work any more, i don't know how to deal with it, can you tell me why? and how to do it? thx~
i am using OpenVPN iOS Client and getting error in "PacketTunnelProvider.swift" file that username, password and configure are not members of vpnAdapter. Also OpenVPNEvent is undeclared type.
After looking into adapters code, i have some questions:
1-OpenVPNEvent is now OpenVPNAdapterEvent. right?
2-To set username and password i have to pass OpenVPNCredentials to vpnAdapter.provide(). right?
3-To configure it. i have to make OpenVPNConfiguration var and pass it to vpnAdapter.apply(). right ?
On the example
branch what else is missing so we can run the example successfully?
The main viewController
seems to be empty
Thanks!
:1:9: note: in file included from :1:
#import "Headers/Umbrella-Header.h"
^
/Users/midnight/Downloads/openvpn-adapter-feature-test-client 2/OpenVPN Adapter/Umbrella-Header.h:19:9: error: 'OpenVPNAdapter/OpenVPNError.h' file not found
#import <OpenVPNAdapter/OpenVPNError.h>
^
/Users/midnight/Downloads/openvpn-adapter-feature-test-client 2/OpenVPN iOS Tunnel Provider/NEPacketTunnelFlow+OpenVPN.swift:11:8: error: could not build Objective-C module 'OpenVPNAdapter'
import OpenVPNAdapter
^
Hey there!
I'd love to use this project in an app I'm working on, but I have noticed there's currently no license for the project.
Have you got any plans to add a license?
According to this website https://choosealicense.com/no-license my options right now are:
Ask the maintainers nicely to add a license
Unless the software includes strong indications to the contrary, lack of a license is probably an oversight. If the software is hosted on a site like GitHub, open an issue requesting a license and include a link to this site, or if you’re bold and it’s fairly obvious what license is most appropriate, open a pull request to add a license.
Don’t use the software
Find or create an alternative that is under an open source license.
(Obviously this option isn't ideal)
Negotiate a private license
Bring your lawyer.
🤔
Thanks!
Do you have a list of stuff that you think you need to complete? Just curious about this project and how far along you might be. Looks very promising!
Dear @ss-abramchuk ,
I have integrated your great framework to iOS client successfully. Now I am trying to integrate to MAC OS client.
My MAC OS PacketTunnelProvider's code is completely same as iOS' code. But it is not working.
Is there any special thing to give an attention ?
Thank you so much.
Hello,
Are there any plans to implement the XOR obfuscation patch to avoid detection of the protocol...? Ie, this one https://github.com/clayface/openvpn_xorpatch
Many thanks,
J
I've tried to add cocoapods support to this library but due to inexperience with the system, have thus far been unable to do so.
So I'm asking for help off anyone more experienced in the matter to lend a hand!
Dear Abramchuk,
We are using OpenVPN server 2.3.10.
I got an error while running "testRemoteConnection" as below:
Test Case '-[OpenVPNAdapterTests.OpenVPNAdapterTests testRemoteConnection]' started.
Fatal error: Failed to retrieve OpenVPN profile: file /Users/james/Documents/OpenVPNAdapter-master/OpenVPN Adapter Tests/ProfileLoader.swift, line 26
2018-03-28 15:37:20.977974+0800 xctest[13082:4203154] Fatal error: Failed to retrieve OpenVPN profile: file /Users/james/Documents/OpenVPNAdapter-master/OpenVPN Adapter Tests/ProfileLoader.swift, line 26
Have you had any experience about this issue ?
Thanks.
It shows reconnected every time when i debug extension i use "feature/test-client" branch
Hi,
Is this OpenVPNAdapter.framework
part of an app extension?
Shouldn't put it in the container app?
thank you.
Hi,
I try to connect to openvpn server(v. 2.4.4) with username/password.
I've used master branch, disabled client cert, and defined ca.crt.
var caCert: String
do {
if let caFileURL = Bundle.main.url(forResource: "ca", withExtension: "crt") {
let caData = try Data(contentsOf: caFileURL)
let cert = try OpenVPNCertificate(pem: caData)
let pemData = try cert.pemData()
guard let result = String(data: pemData, encoding: .utf8)?.replacingOccurrences(of: "\n", with: "\\n") else {
fatalError()
}
caCert = result
} else {
fatalError("There is no CA certificate")
}
} catch {
fatalError(error.localizedDescription)
}
///////
and
let vpnConfiguration = OpenVPNConfiguration().then {
$0.forceCiphersuitesAESCBC = true
$0.proto = .TCP
$0.autologinSessions = true
$0.sslDebugLevel = 0
$0.disableClientCert = true
$0.settings = [
"remote": remote,
"ca": caCert
]
}
adapter tries to connect and then it fails with an error: "mbed TLS: SSL read error : X509 - Certificate verification failed, e.g. CRL, CA or signature check failed".
Then i tried to switch to branch support/openssl because i found out that server was build wtih openssl
in that branch there are no OpenVPNCertificate files, so i tried:
`var caCert: String
do {
if let caFileURL = Bundle.main.url(forResource: "ca", withExtension: "crt") {
let caData = try Data(contentsOf: caFileURL)
guard let result = String(data: caData, encoding: .utf8)?.replacingOccurrences(of: "\n", with: "\\n") else {
fatalError()
}
caCert = result
} else {
fatalError("There is no CA certificate")
}
} catch {
fatalError(error.localizedDescription)
}
`
Now. it's stuck on connecting -> reconnecting -> resolve -> wait loop.
There is serever log:
Fri Dec 8 09:55:48 2017 us=722720 I/O WAIT status=0x0001
Fri Dec 8 09:55:48 2017 us=722738 MULTI: REAP range 16 -> 32
Fri Dec 8 09:55:48 2017 us=722766 UDPv4 read returned 252
Fri Dec 8 09:55:48 2017 us=722802 TLS State Error: No TLS state for client [AF_INET]109.202.21.168:54211, opcode=4
Fri Dec 8 09:55:48 2017 us=722837 GET INST BY REAL: 109.202.21.168:54211 [failed]
Fri Dec 8 09:55:48 2017 us=722862 SCHEDULE: schedule_find_least NULL
Fri Dec 8 09:55:48 2017 us=722900 PO_CTL rwflags=0x0001 ev=5 arg=0x080fc824
Fri Dec 8 09:55:48 2017 us=722931 PO_CTL rwflags=0x0001 ev=4 arg=0x080fc768
Fri Dec 8 09:55:48 2017 us=722964 I/O WAIT TR|Tw|SR|Sw [10/0]
Fri Dec 8 09:55:49 2017 us=721043 PO_WAIT[0,0] fd=5 rev=0x00000001 rwflags=0x0001 arg=0x080fc824
Fri Dec 8 09:55:49 2017 us=721146 event_wait returned 1
What can cause this connection problems? What should i look into to find solution?
Thanks
Dear Abramchuk,
I am developing an iOS client app using openvpn3. Our application is for DNS queries via VPN tunnel.
DNS query is working when I test our .ovpn file on their commercial "OpenVPN Connect" application.
And I never get it work when we use your great library. DNS filtering is not working this case.
So, I did try to compile latest version from https://github.com/OpenVPN/openvpn3 with your project.
But no luck, I added 3 lines of below code in ovpncli.hpp :
#ifndef OVPNCLI_HPP
#define OVPNCLI_HPP
......
#endif
I got a compiler error when I build the framework:
duplicate symbol __ZN7openvpn6string10first_lineERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE in:
/Users/tugsjargal/Library/Developer/Xcode/DerivedData/OpenVPN_Adapter-arroqxkzbhsyofcygngubggktzfi/Build/Intermediates.noindex/OpenVPN Adapter.build/Debug-iphoneos/OpenVPN Adapter iOS.build/Objects-normal/armv7/OpenVPNProperties.o
/Users/tugsjargal/Library/Developer/Xcode/DerivedData/OpenVPN_Adapter-arroqxkzbhsyofcygngubggktzfi/Build/Intermediates.noindex/OpenVPN Adapter.build/Debug-iphoneos/OpenVPN Adapter iOS.build/Objects-normal/armv7/OpenVPNClient.o
duplicate symbol __ZN7openvpn17render_hex_numberEhb in:
/Users/tugsjargal/Library/Developer/Xcode/DerivedData/OpenVPN_Adapter-arroqxkzbhsyofcygngubggktzfi/Build/Intermediates.noindex/OpenVPN Adapter.build/Debug-iphoneos/OpenVPN Adapter iOS.build/Objects-normal/armv7/OpenVPNClient.o
/Users/tugsjargal/Library/Developer/Xcode/DerivedData/OpenVPN_Adapter-arroqxkzbhsyofcygngubggktzfi/Build/Intermediates.noindex/OpenVPN Adapter.build/Debug-iphoneos/OpenVPN Adapter iOS.build/Objects-normal/armv7/ovpncli.o
duplicate symbol __ZN7openvpn6string10first_lineERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE in:
/Users/tugsjargal/Library/Developer/Xcode/DerivedData/OpenVPN_Adapter-arroqxkzbhsyofcygngubggktzfi/Build/Intermediates.noindex/OpenVPN Adapter.build/Debug-iphoneos/OpenVPN Adapter iOS.build/Objects-normal/armv7/OpenVPNProperties.o
/Users/tugsjargal/Library/Developer/Xcode/DerivedData/OpenVPN_Adapter-arroqxkzbhsyofcygngubggktzfi/Build/Intermediates.noindex/OpenVPN Adapter.build/Debug-iphoneos/OpenVPN Adapter iOS.build/Objects-normal/armv7/ovpncli.o
ld: 3 duplicate symbols for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Do you have any idea ?
Thanks for your help.
Hi Sergey,
Would you be interested in doing an integration into the base of an app I have created? I have tried and tried but cannot get this to work. I would be happy to pay for your time. If you are interested please email me at [email protected].
Thanks,
Mike
Hi,
We are trying to connect the VPN using .ovpn file which is working with openVPN Cli on Mac and windows. We have changed the username, password and serverAddress.
It's disconnecting after some time from connecting state on Settings application of iPhone. Please help us to resolve this issue.
Regards,
Rishu
lz4/lib/liblz4.a(lz4.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm utterly confused by an issue I've been experiencing for some time now, so I was hoping to pick your brains @ss-abramchuk on the off-chance you have also experienced this problem.
Sometimes, in certain circumstances such as changing from cellular to WiFi, the VPN connection will enter what appears to be a connecting loop which never finishes.
OpenVPNAdapter
logs the following:
RESOLVE
“Server poll timeout, trying next remote entry..”
RECONNECTING
RESOLVE
“Server poll timeout, trying next remote entry..”
RECONNECTING
...
This might have something to do with initiating a reconnect as a result of a reachability change, but having the functionality to reconnect when going from cellular -> Wi-Fi is desirable.
Have you experienced this? Or have you any ideas what could be causing this?
I ask this partly to help myself but also to hopefully prevent others from experiencing the same.
Thanks for reading.
J
when i run the OpenVPNAdapterTests,the result show Transport Error: mbed TLS: SSL read error : X509 - Certificate verification failed, e.g. CRL, CA or signature check failed .
I don't know if it was a configuration file or something else.
Please tell how to resolve . Thanks
I'm getting 'connect error: Missing External PKI alias' when i try to call TestConnection method.
Using 'auth-user-pass' and i'm sure i have filled in my credentials
master or the stable branch: feature/example
Hey! I've been monitoring your great work on the feature/cleanup
branch.
Something you may or may not be aware of, the OpenVPNAdapterPacketFlow protocol doesn't match the NEPacketTunnelFlow methods because of missing nullability annotations (at least that's what I think the issue is!).
I think all that's needed is NS_ASSUME_NONNULL_BEGIN/END
to be added to this file.
Cheers!
OpenVPNAdapter/OpenVPN Adapter/OpenVPNAdapterPacketFlow.h
Lines 20 to 33 in 96d2ab1
Dear Abramchuk,
You are doing great things. I like your lib.
I am extending NEPacketTunnelProvider on Objective C.
My big problem is DNS settings are not setting to the tunnel. So, seems that all packets are not passing via tunnel.
Here is my code:
//--------------PacketTunnelProvider.h--------------
@import NetworkExtension;
@import OpenVPNAdapter;
@interface PacketTunnelProvider : NEPacketTunnelProvider <OpenVPNAdapterDelegate, OpenVPNAdapterPacketFlow>
@property (nonatomic, strong) OpenVPNAdapter *vpnAdapter;
@property (nonatomic, strong) OpenVPNReachability *vpnReachability;
@end
//--------------PacketTunnelProvider.m--------------
#import "PacketTunnelProvider.h"
#import "CustomFlow.h"
#import "OpenVPNAdapterPacketFlow.h"
@import OpenVPNAdapter;
@implementation PacketTunnelProvider {
void (^startHandler)(NSError *);
void (^stopHandler)(void);
NSMutableArray *logArray;
}
@synthesize vpnAdapter;
@synthesize vpnReachability;
- (void)startTunnelWithOptions:(NSDictionary *)options
completionHandler:(void (^)(NSError *))completionHandler
{
// Add code here to start the process of connecting the tunnel.
vpnReachability = [OpenVPNReachability new];
vpnAdapter = [OpenVPNAdapter new];
vpnAdapter.delegate = self;
OpenVPNConfiguration *configuration = [OpenVPNConfiguration new];
NSError *error;
@try {
NETunnelProviderProtocol *protocolConf = (NETunnelProviderProtocol *)self.protocolConfiguration;
configuration.fileContent = [protocolConf.providerConfiguration objectForKey:@"ovpn"];
[vpnAdapter applyConfiguration:configuration error:&error];
} @catch (NSException *exception) {
completionHandler(error);
return;
}
//[vpnReachability startTrackingWithCallback];
startHandler = completionHandler;
[vpnAdapter connect];
}
- (void)stopTunnelWithReason:(NEProviderStopReason)reason completionHandler:(void (^)(void))completionHandler {
// Add code here to start the process of stopping the tunnel.
stopHandler = completionHandler;
[vpnAdapter disconnect];
completionHandler();
}
- (void)handleAppMessage:(NSData *)messageData completionHandler:(void (^)(NSData *))completionHandler {
// Add code here to handle the message.
if(completionHandler != nil) {
completionHandler(messageData);
}
}
- (void)sleepWithCompletionHandler:(void (^)(void))completionHandler {
// Add code here to get ready to sleep.
completionHandler();
}
- (void)wake {
// Add code here to wake up.
NSLog(@"Wake is called.");
}
/**
This method is called once the network settings to be used have been established.
The receiver should call the completion handler once these settings have been set, returning a NEPacketTunnelFlow object for
the TUN interface, or nil if an error occurred.
@param openVPNAdapter The OpenVPNAdapter instance requesting this information.
@param networkSettings The NEPacketTunnelNetworkSettings to be used for the tunnel.
@param completionHandler The completion handler to be called with a NEPacketTunnelFlow object, or nil if an error occurred.
*/
- (void)openVPNAdapter:(OpenVPNAdapter *)openVPNAdapter
configureTunnelWithNetworkSettings:(NEPacketTunnelNetworkSettings *)networkSettings
completionHandler:(void (^)(id<OpenVPNAdapterPacketFlow> packetFlow))completionHandler
{
__weak typeof(self) weakSelf = self;
[self setTunnelNetworkSettings:networkSettings completionHandler:^(NSError *error) {
completionHandler((error == nil) ? weakSelf.packetFlow : nil);
}];
NSLog(@"configureTunnelWithNetworkSettings...");
}
/**
Informs the receiver that an OpenVPN error has occurred.
Some errors are fatal and should trigger the diconnection of the tunnel, check for fatal errors with the
OpenVPNAdapterErrorFatalKey.
@param openVPNAdapter The OpenVPNAdapter instance which encountered the error.
@param error The error which has occurred.
*/
- (void)openVPNAdapter:(OpenVPNAdapter *)openVPNAdapter handleError:(NSError *)error
{
NSLog(@"OpenVPNAdapter Error: %@", [error description]);
if(startHandler != nil) {
startHandler(error);
startHandler = nil;
} else {
[self cancelTunnelWithError:error];
}
}
/**
Informs the receiver that an OpenVPN event has occurred.
@param openVPNAdapter The OpenVPNAdapter instance which encountered the event.
@param event The event which has occurred.
@param message An accompanying message, may be nil.
*/
- (void)openVPNAdapter:(OpenVPNAdapter *)openVPNAdapter
handleEvent:(OpenVPNAdapterEvent)event
message:(nullable NSString *)message {
switch(event) {
case OpenVPNAdapterEventConnected:
if(startHandler == nil) {
NSLog(@"startHandler is nil.");
return;
}
//startHandler(dummyError);
startHandler(nil);
NSLog(@"start handler worked.");
startHandler = nil;
break;
case OpenVPNAdapterEventDisconnected:
if(stopHandler == nil) {
return;
}
//vpnReachability.stopTracking()
stopHandler();
stopHandler = nil;
break;
default:
break;
}
}
/**
Informs the receiver that an OpenVPN message has been logged.
@param openVPNAdapter The OpenVPNAdapter instance which encountered the log message.
@param logMessage The log message.
*/
- (void)openVPNAdapter:(OpenVPNAdapter *)openVPNAdapter
handleLogMessage:(NSString *)logMessage
{
NSLog(@"%@", logMessage);
}
/**
Informs the receiver that a clock tick has occurred.
Clock ticks can be configured with an OpenVPNConfiguration object.
@param openVPNAdapter The OpenVPNAdapter instance which encountered the clock tick.
*/
- (void)openVPNAdapterDidReceiveClockTick:(OpenVPNAdapter *)openVPNAdapter
{
}
@end
I am not sure how to extend your Swift as below:
extension NEPacketTunnelFlow: OpenVPNAdapterPacketFlow { }
Do you have any idea ?
Thank you so much.
My PacketTunnelProvider is like this.
guard
let fileContent = providerConfiguration[ProviderConfigurationKey.fileContent] as? Data,
let caRef = providerConfiguration[ProviderConfigurationKey.caRef] as? Data,
let userCertificateRef = providerConfiguration[ProviderConfigurationKey.userCertificateRef] as? Data,
let userKeyRef = providerConfiguration[ProviderConfigurationKey.userKeyRef] as? Data
else {
preconditionFailure("fileContent, certificates and a key should be provided to the tunnel provider")
}
guard
let ca = String(data: caRef, encoding: .utf8)?.replacingOccurrences(of: "\n", with: "\n"),
let userCertificate = String(data: userCertificateRef, encoding: .utf8)?.replacingOccurrences(of: "\n", with: "\n"),
let userKey = String(data: userKeyRef, encoding: .utf8)?.replacingOccurrences(of: "\n", with: "\n")
else {
fatalError("Failed to retrieve certificates and a user key from keychain")
}
// Create representation of the OpenVPN configuration. Other properties such as connection timeout or
// private key password aslo may be provided there.
let vpnConfiguration = OpenVPNConfiguration().then {
$0.fileContent = fileContent
$0.settings = [
"ca" : ca,
"cert" : userCertificate,
"key" : userKey
]
}
// Apply OpenVPN configuration
let properties: OpenVPNProperties
do {
properties = try vpnAdapter.apply(configuration: vpnConfiguration)
} catch {
completionHandler(error)
return
}
Then I go this error. Please let me know why this error happened.
Please add a "dummy" openvpn file in the example. I am able to get the VPN into settings but I don't get any logs or can't connect.
Thanks
This is my code on PacketTunnelProvider.m file.
vpnAdapter = [[OpenVPNAdapter alloc] init];
vpnAdapter.delegate = self;
vpnReachability = [[OpenVPNReachability alloc] init];
NETunnelProviderProtocol *protocol = (NETunnelProviderProtocol *)self.protocolConfiguration;
NSDictionary *dict = protocol.providerConfiguration;
NSData* fileContent = [configContentString dataUsingEncoding:NSUTF8StringEncoding];
OpenVPNConfiguration *vpnConfiguration = [[OpenVPNConfiguration alloc] init];
[vpnConfiguration setFileContent:fileContent];
[vpnConfiguration setDisableClientCert:YES];
NSData *dt = vpnConfiguration.fileContent;
NSError *error = nil;
OpenVPNProperties *properties = [vpnAdapter applyConfiguration:vpnConfiguration error:&error];
if (error != nil) {
NSLog(@"properties Error");
return;
}
if (![properties autologin]) {
OpenVPNCredentials *credentials = [[OpenVPNCredentials alloc] init];
credentials.username = userName;
credentials.password = password;
NSError *err = nil;
[vpnAdapter provideCredentials:credentials error:&err];
if (err != nil) {
NSLog(@"Provider Credentials Error");
return;
}
}
[vpnReachability startTrackingWithCallback:^(OpenVPNReachabilityStatus status) {
if (status != OpenVPNReachabilityStatusNotReachable) {
[vpnAdapter reconnectAfterTimeInterval:5];
}
}];
[vpnAdapter connect];
i can see error as like this.
Transport error on 'xx.xx.xxx.xxx: NETWORK_RECV_ERROR
What is missing on my side?
Looking forward to see any reply.
I have the VPNs able to connect some of the times - this vpn works in openVPN but not in the custom app.
I have checked and other VPNs do work
Only profiles with a ca, cert and key can be connected to. In openvpn connect all 3 aren't needed. How can I connect using a ca and tls-auth?
Hi,
Here is log.......
2017-12-21 09:54:18.643298+0800 VPN[2477:1291865] Failed to establish tunnel in a reasonable time
2017-12-21 09:54:18.643395+0800 VPN[2477:1291807] =====>TUN Error: cannot acquire tun interface socket
2017-12-21 09:54:18.643561+0800 VPN[2477:1291807] error Error Domain=com.data.rcy.error-domain Code=20 "OpenVPN error occurred." UserInfo={NSLocalizedFailureReason=Error creating TUN/TAP interface., com.data.rcy.error-key.message=cannot acquire tun interface socket, com.data.rcy.error-key.fatal=true, NSLocalizedDescription=OpenVPN error occurred.}
2017-12-21 09:54:18.643589+0800 VPN[2477:1291807] ----->event, 0,(null)
2017-12-21 09:54:18.653427+0800 VPN[2477:1291807] =====>Client exception in transport_recv: tun_exception: not connected
How can I fix this?
Thanks.
I managed to get the vpn to connect. I was wondering if I need to reinstall the profile everytime the password of the VPN changes? I have tried using keychain, manually changing the password and then app groups.
Thanks
Hi, @ss-abramchuk ,
I'm sorry to ask you again.
Xcode log is VPN status is Connected, but 'vpn' tag is not show on the iphone, and can't surf the Internet.
Have you finished tunnel provider yet?Can you provide me with demo?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.