Implementing VPN with L2TP protocol in iOS app


Implementing VPN with L2TP protocol in iOS app using Routing and Remote Access (RRA) SDK


This article aims to demonstrate how to implement VPN with L2TP protocol in iOS app using Routing and Remote Access (RRA) SDK.


This article demonstrates how to implement a basic L2TP VPN server with RRA SDK on macOS. The steps are illustrated in the following sections:


In this article, we will be implementing VPN with L2TP protocol in iOS app using Routing and Remote Access (RRA) SDK.


Routing and Remote Access (RRA) SDK is an open source networking framework that provides secure connectivity between iOS devices and remote access gateways (RAGs) through various tunneling protocols including L2TP/IPsec and PPTP. It supports both wired and wireless networks.


This tutorial assumes that you have already installed RRA SDK on your macOS machine.


This tutorial assumes that you have already installed RRA SDK on your macOS machine.


Step 1: Create a New Project in Xcode


To begin, you need to create a new Xcode project. We will use RRA SDK to create a VPN server app and use the server to connect to an app running on iOS device.


Step 2: Create a New VPN Server App


The first step in this tutorial is to create a new project for our VPN server app.


Open the Xcode project for the tutorial. Click on the File menu, and then choose New > Project… to open a new project window.


In the New Project dialog, select the iOS App (Command Line) option.


In the iOS App (Command Line) section, provide the following information:


Enter the project name in the Project Name field.


In the Product Name field, enter the name of the project.


In the Language field, select the language you wish to use for the app.


In the Scheme dropdown, select the option that suits your needs.


The following screenshot shows the dialog box that we will be using for our project.


Step 3: Create a New RRA Client App


Next, we will create a new project for our iOS client app.


Open the Xcode project for the tutorial. Click on the File menu, and then choose New > Project… to open a new project window.


In the New Project dialog, select the iOS App (Single View) option.


In the iOS App (Single View) section, provide the following information:


Enter the project name in the Project Name field.


In the Product Name field, enter the name of the project.


In the Language field, select the language you wish to use for the app.


In the Scheme dropdown, select the option that suits your needs.


The following screenshot shows the dialog box that we will be using for our project.


Step 4: Create a New VPN Server


In this tutorial, we will be using the L2TP protocol to establish VPN connection between our iOS client and our VPN server.


To start, we will create a new project for our VPN server.


Open the Xcode project for the tutorial. Click on the File menu, and then choose New > Project… to open a new project window.


In the New Project dialog, select the iOS App (Command Line) option.


In the iOS App (Command Line) section, provide the following information:


Enter the project name in the Project Name field.


In the Product Name field, enter the name of the project.


In the Language field, select the language you wish to use for the app.


In the Scheme dropdown, select the option that suits your needs.


Step 5: Add RRA SDK to Your Project


After creating a new project, we need to add RRA SDK to the project.


Open the RRA project file located at the location ~/Library/Application\ Support/RRA/RRA.xcodeproj/project.xcworkspace/xcuserdata/<username>/<app_name>/<project_name>.xcuserdatad/xcschemes/<scheme_name>.xcscheme.


Double-click on the RRA.xcodeproj file.


Add RRA SDK to your project by clicking on the + button.


You will be presented with the following dialog box.


Enter the following information:


Scheme name: <project_name>


Scheme Group Name: <project_name>


Scheme Class: RRA.L2TPServer.RRA.L2TPServer


Scheme Name: <project_name>


Scheme Group Name: <project_name>


Scheme Class: RRA.L2TPServer.RRA.L2TPServer


Step 6: Create the Client App


Now, we will create a new project for our iOS client app.


Open the Xcode project for the tutorial. Click on the File menu, and then choose New > Project… to open a new project window.


In the New Project dialog, select the iOS App (Single View) option.


In the iOS App (Single View) section, provide the following information:


Enter the project name in the Project Name field.


In the Product Name field, enter the name of the project.


In the Language field, select the language you wish to use for the app.


In the Scheme dropdown, select the option that suits your needs.


The following screenshot shows the dialog box that we will be using for our project.


Step 7: Create a New VPN Server


To connect to a VPN server, we need to provide the following information:


The host name or IP address of the VPN server.


The port number of the VPN server.


The name of the service provider.


The username and password of the VPN server.


The protocol of the VPN connection.


In this tutorial, we will use the L2TP protocol to establish a VPN connection between our iOS client and our VPN server.


Open the RRA project file located at the location ~/Library/Application\ Support/RRA/RRA.xcodeproj/project.xcworkspace/xcuserdata/<username>/<app_name>/<project_name>.xcuserdatad/xcschemes/<scheme_name>.xcscheme.


Double-click on the RRA.xcodeproj file.


Add RRA SDK to your project by clicking on the + button.


You will be presented with the following dialog box.


Enter the following information:


Scheme name: <project_name>


Scheme Group Name: <project_name>


Scheme Class: RRA.L2TPServer.RRA.L2TPServer


Scheme Name: <project_name>


Scheme Group Name: <project_name>


Scheme Class: RRA.L2TPServer.RRA.L2TPServer


Step 8: Create the Client App


Now, we will create a new project for our iOS client app.


Open the Xcode project for the tutorial. Click on the File menu, and then choose New > Project… to open a new project window.


In the New Project dialog, select the iOS App (Single View) option.


In the iOS App (Single View) section, provide the following information:


Enter the project name in the Project Name field.


In the Product Name field, enter the name of the project.


In the Language field, select the language you wish to use for the app.


In the Scheme dropdown, select the option that suits your needs.


Step 9: Build the Client App


Now, we will build the iOS app.


Open the iOS client app by double-clicking on the <project_name>-Info.plist file.


Find the key called CFBundleIdentifier.


Step 10: Run the iOS Client App


Now, we will run the iOS client app.


Open the iOS client app by double-clicking on the <project_name>-AppDelegate.m file.


Find the -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method.


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self applicationDidFinishLaunching]; return YES; }


Add the following code in the -application:didFinishLaunchingWithOptions: method.


Add the following code in the -application:didFinishLaunchingWithOptions: method.


Add the following code in the -application:didFinishLaunchingWithOptions: method.


Run the iOS client app by clicking on the Run button.


You will see the following dialog box.


If you are prompted for an SSL certificate, select the option that suits your needs.


If you are prompted for an SSL certificate, select the option that suits your needs.


Step 11: Test the iOS Client App


Now, we will test the iOS client app.


Open the iOS client app by double-clicking on the <project_name>-ViewController.xib file.


You will see the a dialog box.


Click on the Add button.



Previous
Next Post »