Wireguard Transport

Wireguard is a modern, fast, and secure VPN protocol. It aims to be simpler, leaner, and more performant than other VPN protocols like IPSec and OpenVPN. WireguardSDK allows developers to easily integrate WireGuard VPN functionality into their iOS applications. With WireguardSDK, you can establish secure VPN connections, manage configurations, and control the VPN lifecycle directly from your app's code.

Initializing WireguardSDK

To get started, you'll need to import the VPNApplicationSDK and create a WireguardConfiguration object with your specific settings:

import VPNApplicationSDK
// ...

let wireguardConfig = WireguardConfiguration(
    carrierID: "YOUR_CARRIER_ID",
    extensionBundleID: "com.yourcompany.demo-test.app.wireguard-extension",
    groupData: VPNGroupData(groupID: "group.com.yourcompany.vpnsdk-demo", usesSystemExtension: false)
)

let wireguardSDK = WireguardSDK(configuration: wireguardConfig)

Be sure to replace YOUR_CARRIER_ID with your actual carrier ID and update the extensionBundleID and groupID to match your app's settings.

Establishing a Connection

Once the SDK is initialized and the user is logged in, you can start a VPN connection with a single function call:

// ...
wireguardSDK.start(location: .optimal(), proxy: nil, completion: { error, credential in
    if let error = error {
        print("Failed to start Wireguard connection: \(error)")
    } else {
        print("Wireguard connection established successfully")
    }
})

This will establish a connection using the optimal location and no proxy. You can customize these settings as needed.

Updating Configuration

If you need to update the Wireguard configuration without creating a new SDK instance, you can use the updateConfiguration method:

// ...
let newWireguardConfig = WireguardConfiguration(
    carrierId: "NEW_CARRIER_ID",
    extensionBundleId: "com.yourcompany.demo-test.app.wireguard-extension",
    groupData: VPNGroupData(groupID: "new.group.com.yourcompany.vpnsdk-demo", usesSystemExtension: false)
)

do {
    try wireguardSDK.updateConfiguration(configuration: newWireguardConfig)
    print("Configuration updated successfully")
} catch {
    print("Failed to update configuration: \(error)")

You can't update the configuration if a connection is active. You'll need to call stopVPN first. Also, if you change the main configuration parameters (hostURL, carrierID, extensionBundleID, groupData), you'll need to create a new WireguardSDK instance instead of updating.

Disconnecting

To stop the VPN connection:

// ...
wireguardSDK.stop(completion: { error in
    if let error = error {
        print("Failed to stop VPN: \(error)")
    } else {
        print("VPN stopped successfully")
    }
})

Last updated