Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. NEVPNManager *manager = [NEVPNManager sharedManager];
  2. [manager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
  3. if(error) {
  4. NSLog(@"Load error: %@", error);
  5. } else {
  6.  
  7.  
  8. NEVPNProtocolIKEv2 *p = [[NEVPNProtocolIKEv2 alloc] init];
  9. p.username = @"Username";
  10. p.passwordReference = [res objectForKey:@"v_PersistentRef"];
  11. p.serverAddress = strAddress;
  12. p.authenticationMethod = NEVPNIKEAuthenticationMethodCertificate;
  13. p.serverCertificateIssuerCommonName = @"COMODO RSA Domain Validation Secure Server CA";
  14. p.serverCertificateCommonName =strAddress;
  15. p.identityData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"point-to-client2" ofType:@"p12"]];
  16. p.identityDataPassword = @"vpnuser";
  17. p.localIdentifier = strAddress;
  18. p.remoteIdentifier = strAddress;
  19. p.useExtendedAuthentication = YES;
  20. p.disconnectOnSleep = NO;
  21. [manager setProtocol:p];
  22.  
  23. NSLog(@"password: %@", [manager protocol].passwordReference);
  24. [manager setOnDemandEnabled:YES];
  25. [manager setEnabled:YES];
  26.  
  27. NEEvaluateConnectionRule * ru = [[NEEvaluateConnectionRule alloc] initWithMatchDomains:@[@"google.com"] andAction:NEEvaluateConnectionRuleActionConnectIfNeeded];
  28.  
  29.  
  30. ru.probeURL = [[NSURL alloc] initWithString:@"http://www.google.com"];
  31.  
  32.  
  33. NSArray *arr = [[NSArray alloc] initWithObjects:ru, nil];
  34. NEOnDemandRuleEvaluateConnection *ec =[[NEOnDemandRuleEvaluateConnection alloc] init];
  35. ec.interfaceTypeMatch = 2;
  36. [ec setConnectionRules:arr];
  37. NSArray *arr2 = [[NSArray alloc] initWithObjects:ec, nil];
  38. NSLog(@"onDemandRules: %@", arr2);
  39. //
  40. [manager setOnDemandRules:arr2];
  41. [manager setLocalizedDescription:@"VPN Profile"];
  42. [manager saveToPreferencesWithCompletionHandler:^(NSError *error) {
  43. if(error) {
  44. NSLog(@"Save error: %@", error);
  45. }
  46. else {
  47. NSLog(@"Saved");
  48. }
  49.  
  50. NSError *startError;
  51. [[NEVPNManager sharedManager].connection startVPNTunnelAndReturnError:&startError];
  52. if(startError) {
  53. NSLog(@"Start error: %@", startError.localizedDescription);
  54. } else {
  55. NSLog(@"Connection established!");
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement