Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NEVPNManager *manager = [NEVPNManager sharedManager];
- [manager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
- if(error) {
- NSLog(@"Load error: %@", error);
- } else {
- NEVPNProtocolIKEv2 *p = [[NEVPNProtocolIKEv2 alloc] init];
- p.username = @"Username";
- p.passwordReference = [res objectForKey:@"v_PersistentRef"];
- p.serverAddress = strAddress;
- p.authenticationMethod = NEVPNIKEAuthenticationMethodCertificate;
- p.serverCertificateIssuerCommonName = @"COMODO RSA Domain Validation Secure Server CA";
- p.serverCertificateCommonName =strAddress;
- p.identityData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"point-to-client2" ofType:@"p12"]];
- p.identityDataPassword = @"vpnuser";
- p.localIdentifier = strAddress;
- p.remoteIdentifier = strAddress;
- p.useExtendedAuthentication = YES;
- p.disconnectOnSleep = NO;
- [manager setProtocol:p];
- NSLog(@"password: %@", [manager protocol].passwordReference);
- [manager setOnDemandEnabled:YES];
- [manager setEnabled:YES];
- NEEvaluateConnectionRule * ru = [[NEEvaluateConnectionRule alloc] initWithMatchDomains:@[@"google.com"] andAction:NEEvaluateConnectionRuleActionConnectIfNeeded];
- ru.probeURL = [[NSURL alloc] initWithString:@"http://www.google.com"];
- NSArray *arr = [[NSArray alloc] initWithObjects:ru, nil];
- NEOnDemandRuleEvaluateConnection *ec =[[NEOnDemandRuleEvaluateConnection alloc] init];
- ec.interfaceTypeMatch = 2;
- [ec setConnectionRules:arr];
- NSArray *arr2 = [[NSArray alloc] initWithObjects:ec, nil];
- NSLog(@"onDemandRules: %@", arr2);
- //
- [manager setOnDemandRules:arr2];
- [manager setLocalizedDescription:@"VPN Profile"];
- [manager saveToPreferencesWithCompletionHandler:^(NSError *error) {
- if(error) {
- NSLog(@"Save error: %@", error);
- }
- else {
- NSLog(@"Saved");
- }
- NSError *startError;
- [[NEVPNManager sharedManager].connection startVPNTunnelAndReturnError:&startError];
- if(startError) {
- NSLog(@"Start error: %@", startError.localizedDescription);
- } else {
- NSLog(@"Connection established!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement