LogoLogo
  • Platform Overview
  • πŸ—ΊοΈGuides
    • Getting Started
    • Users
      • Integrate the User SDK
      • Registration
      • Authentication
      • SDK Releases
      • API Reference
    • Entitlements
      • Administrative API
        • Integrating the Administrative API
        • Entitlement Definitions
        • Managing Entitlements Sets
        • Managing Entitlements Sequences
        • Managing User Entitlements
        • API Schema
      • End-user API
        • Integrate the Entitlements SDK
        • Redeeming Entitlements
        • Retrieving Entitlements
        • SDK Releases
        • API Reference
    • Sudos
      • Integrate the Sudo Profiles SDK
      • Sudo Entitlements
      • Manage Sudos
      • SDK Releases
      • API Reference
    • Telephony
      • Integrate the Telephony SDK
      • Manage Phone Numbers
      • Text Messaging
      • Voice Calling
      • Telephony Simulator
      • SDK Releases
      • API Reference
    • Email
      • Integrate the Email SDK
      • Email Entitlements
      • Manage Email Addresses
      • Sending & Receiving Email
      • Manage Email Folders
      • Draft Email Messages
      • Manage Email Address Blocklists
      • Email Address Public Information
      • Pagination
      • Caching
      • Configuration Data
      • Email Notifications
      • SDK Releases
      • API Reference
    • Decentralized Identity
      • Edge Agent
        • Relay SDK
          • Integrate the Relay SDK
          • Relay Entitlements
          • Manage Relay Postboxes
          • Manage Relay Messages
          • Receiving Messages
          • SDK Releases
        • Edge Agent SDK
          • Integrate the Edge Agent SDK
          • Agent Management
          • Manage Wallets
          • Establishing Connections
          • Manage Connections
          • Messaging
          • Manage DIDs
          • Accepting New Credentials
          • Manage Credentials
          • Present Credentials for Verification
          • Utilize Alternative Cryptography Providers
          • SDK Releases
          • Standards and Protocols
      • Cloud Agent
        • Cloud Agent Admin API
          • Integrate the Cloud Agent Admin API
          • Aries Interop Profile (AIP)
            • Connection Exchanges
            • Credential Exchanges
            • Proof Exchanges
          • Connections
          • Basic Messages
          • Credentials
            • Anoncreds Credentials
              • Schemas
              • Credential Definitions
            • W3C Credentials
          • Audit Logs
          • API Schema
          • Error Codes
          • Standards and Protocols
    • Virtual Cards
      • Integrate the Virtual Cards SDK
      • Virtual Cards Entitlements
      • Virtual Cards Transaction Velocity Constraints
      • Key Management
      • Manage Funding Sources
      • Manage Virtual Cards
      • Manage Transactions
      • Configuration Data
      • Pagination
      • Caching
      • SDK Releases
      • API Reference
    • Virtual Cards Simulator
      • Integrate the Virtual Cards Simulator SDK
      • Simulate Authorizations
      • Simulate Debits
      • Simulate Refunds
      • Simulate Reversals
      • Merchants and Currencies
      • SDK Releases
      • API Reference
    • Virtual Private Network
      • Integrate the VPN SDK
      • VPN Entitlements
      • Manage Servers
      • Manage Connection
      • Observe VPN Related Events
      • SDK Releases
      • API Reference
      • Frequently Asked Questions
    • Secure ID Verification
      • Integrate the Secure ID Verification SDK
      • List Supported Countries
      • Verify an Identity
      • Check Secure ID Verification Status
      • Use the Secure ID Verification Simulator
      • SDK Releases
      • API Reference
    • Password Manager
      • Integrate the Password Manager SDK
      • Accessing the Password Manager
      • Managing Password Vaults
      • Managing Password Vault Items
      • Vault Import and Export
      • Password Utilities
      • Password Manager Entitlements
      • Password Vault Security
      • SDK Releases
      • API Reference
    • Ad/Tracker Blocker
      • Integrate the Ad/Tracker Blocker SDK
      • Manage Rulesets
      • Blocking Ads and Trackers
      • Manage Exceptions
      • SDK Releases
      • API Reference
    • Site Reputation
      • Integrate the Site Reputation SDK
      • Use the Site Reputation SDK
      • SDK Releases
      • API Reference
  • πŸ’‘Concepts
    • Sudo Digital Identities
  • 🧱Development
    • Versioning
  • 🏒Administration
    • Admin Console Roles
  • ❓Get Help
    • Request a Demo
    • Report an Issue
Powered by GitBook
On this page
  • Establish a Connection
  • Connection Configuration
  • Connect to the VPN
  • Disconnect from an Established Connection
  1. Guides
  2. Virtual Private Network

Manage Connection

Provides the essentials to allow your users to connect and disconnect from a server and view their connection status.

PreviousManage ServersNextObserve VPN Related Events

Last updated 3 years ago

The VPN SDK provides a set of APIs to allow your users to establish and teardown a VPN connection with a server.

Establish a Connection

A connection to a server is established by calling the connect to server API using a server selected from the list servers API call.

In order to establish a connection, a is required.

Connection Configuration

Connection configuration is decided at the time of calling the connect API. It is up to you to build up a SudoVPNConfiguration object.

SudoVPNConfiguration

Property
Description

server

protocolType

When the disconnect API is called, the configured server will be set back to undefined.

Both server and protocolType can be left as undefined. In the case that server is left undefined, the best server will be attempted to connect to, using the user's current geographical location. If protocolType is left undefined, the default protocol (IPSec (IKEv2) on mobile) will be used.

Protocol Types

When connecting to a VPN, a couple of different Protocol types are available. Depending on the platform, only a subset of these types may be supported.

In a scenario where network is lost whilst connected to an IPSec (IKEv2) or UDP protocol, the VPN tunnel will remain open. This allows the connection to stay open if there are changes in the network (i.e. moving from Wi-Fi to Mobile Data).

Protocol
Description
iOS
Android

L2TP

PPTP

IPSec

IPSec (IKEv2)

OpenVPN UDP

OpenVPN TCP

WireGuard

In order to see which protocols are currently available via the client, use the supportedProtocols() method. This method returns the list of supported protocols mentioned above currently available to the device calling the method.

An example implementation is:

let supportedProtocols = vpnClient.supportedProtocols()
/// `supportedProtocols` contains an array of the protocols that can be used.

The listSupportedProtocols method is used to return a list of of supported protocols used as part of configuring a connection that are currently available to the client calling the method.

An example implementation of this is:

val supportedProtocols = vpnClient.listSupportedProtocols()
// [supportedProtocols] contains a list of protocols that can be used to configure a connection.

Connect to the VPN

To connect to the VPN, use the connect(withConfiguration:completion:) method. The completion will be called either when the connection process has successfully begun, or an error occurred while attempting to do so.

If configuration is nil, the best server, and default protocol type will be used.

An example implementation of calling the connect method is:

vpnClient.connect { result in
    switch result {
    case let .failure(cause):
        /// Handle/notify user of error.
    case .success:
        /// Successfully begun connection. 
}

The connect(notification, revokedNotification) method is used to establish a connection to the VPN network. The notification parameter allows you to attach a persistent notification once a connection is established whereas the revokedNotification parameter allows you to emit a notification when the VPN is revoked.

Before establishing a connection, the configurationclient property must be set. If configuration is null, the best server, and default protocol type will be used.

Android requires that the application request permission from the user the first time that the application attempts to create a connection with a VPN network.

Before attempting to connect to a VPN network. The prepare(fragment: Fragment) / prepare(activity: Activity) method must be called. This method will launch an intent containing a VPN connection permission dialogue requiring user action with the result coming back via the fragment or activity onActivityForResult method which can be overridden. If the result is RESULT_OK, the application is considered prepared. The isPrepared method is used to indicate whether the user has previously given permission to connect to VPN networks.

The execution of the prepare method is required in order to perform any VPN connection operations.

An example implementation of connecting to a selected server is:

class ConnectionFragment : Fragment(), CoroutineScope {

    companion object {
        private const val VPN_PREPARE = 1000
        private const val NOTIFICATION_ID_VPN_STATUS = 1
        private const val NOTIFICATION_ID_VPN_REVOKED = 2
    }

    // val server: SudoVPNServer // Retrieved via the list servers API
    private fun connect() {
        try {
            if (sudoVPNClient.isPrepared()) {

                // Set the configuration client property with selected [server].
                sudoVPNClient.configuration = SudoVPNConfiguration(server, SudoVPNProtocol.IKEV2, false)

                // Build SudoVPNNotification objects.
                val vpnConnectionNotification = NotificationCompat.Builder(
                    requireContext(),
                    "vpnNotificationChannel"
                )
                    .setSmallIcon(R.drawable.vpn_logo)
                    .build()
                val vpnRevokedNotification = NotificationCompat.Builder(
                    requireContext(),
                    "vpnNotificationChannel"
                )
                    .setSmallIcon(R.drawable.vpn_logo)
                    .build()
                val sudoNotification = SudoVPNNotification(NOTIFICATION_ID_VPN_STATUS, vpnConnectionNotification)
                val sudoRevokedNotification = SudoVPNNotification(NOTIFICATION_ID_VPN_REVOKED, vpnRevokedNotification)

                launch {
                    try {
                        withContext(Dispatchers.IO) {
                            sudoVPNClient.connect(sudoNotification, sudoRevokedNotification)
                        }
                    } catch (e: SudoVPNException) {
                        // Handle/notify user of exception
                    }
                }
            } else {
                sudoVPNClient.prepare(this)
            }
        } catch (e: ActivityNotFoundException) {
            // Handle/notify user if prepare method could not be executed.
        }
    }

    // Handle result from calling [sudoVPNClient.prepare] method.
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == RESULT_OK && requestCode == VPN_PREPARE) {
            connect()
        }
    }
}

Disconnect from an Established Connection

Once already connected, a user may want to deliberately disconnect, or close the connection as part of a process.

To disconnect from an already established connection, use the disconnect(completion:) method.

An example implementation of calling the disconnect method is:

vpnClient.disconnect { result in
    switch result {
    case let .failure(cause):
        /// Handle/notify user of error.
    case .success:
        /// Successfully disconnected. 
}

Disconnecting from an already established connection is performed by calling the disconnect method.

An example implementation of performing a disconnection is:

 launch {
     try {
         withContext(Dispatchers.IO) {
            sudoVPNClient.disconnect()
        }
        // The disconnection process has begun.
     } catch (e: SudoVPNException) {
         // Handle/notify user of exception
     }
 }

The that the client will/is connected to.

The that the client will/is using to connect to the VPN.

To watch for connection state events to see when the client has successfully connected (or failed to connect), see .

To watch for connection state events to see when the client has successfully connected (or failed to connect), see Setting up a Subscription in the Android section of the page.

To watch for connection state events to see when the client has successfully disconnected (or failed to disconnect), see .

To watch for connection state events to see when the client has successfully disconnected (or failed to disconnect), see Setting up a Subscription in the Android section of the page.

πŸ—ΊοΈ
Observe VPN Related Events
Observe VPN Related Events
SudoVPNServer
Layer 2 Tunnel Protocol
❌
❌
Point-To-Point Tunnelling Protocol
❌
❌
Internet Protocol Security
βœ…
❌
Internet Key Exchange V2
βœ…
βœ…
Open VPN over UDP
❌
βœ…
Open VPN over TCP
❌
βœ…
Wire Guard
❌
βœ…
SudoVPNProtocol
Connection Events
Connection Events
SudoVPNServer