Skip to main content

Installation

Swift Package Manager​

KapePlatformSDK is hosted on a private Cloudsmith Swift registry. Downloading from Cloudsmith requires a entitlement token, reach your contact at Kape if you have not received an entitlement token.

Download KapePlatformSDK package​

curl -u "token:<YOUR_ENTITLEMENT_TOKEN>" -1sL 'https://dl.cloudsmith.io/basic/expressvpn/kp_platform_sdks/swift/KapePlatformSDK/<VERSION>/KapePlatformSDKPackage.zip' -o "KapePlatformSDKPackage.zip"
unzip KapePlatformSDKPackage.zip

In Xcode​

  1. Open your project
  2. Go to File > Add Package Dependencies...
  3. Add local and select KapePlatformSDK folder that was just extracted
  4. Add the modules you need to your targets:
TargetAdd these products
Main AppKapeCore, KapeAuth, KapeVPN, plus KapeVPN-Lightway-Bridge / KapeVPN-OpenVPN-Bridge if you use them (see below), and KapeSubscriptions if your brand's subscriptions are on Kape's Renue platform (Subscriptions)
Network ExtensionKapeVPN, plus one KapeVPN-<Protocol>-Bridge per VPN protocol you support

Each VPN protocol is opt-in, so your app ships only the tunnel libraries it uses:

warning

Also add KapeVPN-Lightway-Bridge and KapeVPN-OpenVPN-Bridge to the main app target when you use them. Their libraries ship as dynamic frameworks, and Xcode embeds a package's frameworks only in an app target, never in an app extension — the extension loads them from the app bundle. Without this, the extension is killed at launch with Library not loaded: @rpath/Lightway.framework (or OpenSSL.framework). KapeVPN-WireGuard-Bridge links statically and needs no such step.

info

It is possible to add Cloudsmith as a remote SwiftPM registry to avoid registering KapePlatformSDK as a local package but private registries don't play nice with CI systems like Github actions or XCode cloud as the registry credentials needs to be stored in the keychain which might be difficult to manipulate on CI systems. Having a pre-build step to download the package (with credentials potentially stored in environement variables) and use that package as a local Swift package bypass this issue.

Configuration File​

Create a KapeSDK.json file and add it to both your app target and Network Extension target (if you need to connect to the VPN). It holds the Platform SDK's settings at the top level and the Kape Client SDK's configuration — the one provided to you — under client_sdk:

{
"client_id": "your-oidc-client-id",
"issuer_url": "https://auth.example.com/realms/your-tenant",
"redirect_url": "your-app-scheme://callback",
"app_group_identifier": "group.com.your.app",
"keychain_service": "com.your.app.sdk-storage",
"license": "your-license-key",
"server_address": "vpn.example.com",
"vpn_profile_name": "Your App",
"packet_tunnel_bundle_identifier": "com.your.app.PacketTunnel",
"lightway_certificate": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n",
"openvpn_ca_certificate": "-----BEGIN CERTIFICATE-----\n... OpenVPN CA chain ...\n-----END CERTIFICATE-----\n",
"openvpn_client_certificate": "-----BEGIN CERTIFICATE-----\n... client certificate ...\n-----END CERTIFICATE-----\n",
"openvpn_client_key": "-----BEGIN RSA PRIVATE KEY-----\n... matching client private key ...\n-----END RSA PRIVATE KEY-----\n",
"openvpn_tls_auth_key": "-----BEGIN OpenVPN Static key V1-----\n... TLS-Auth static key ...\n-----END OpenVPN Static key V1-----\n",
"http_call_behavior": "InternalHttpClient",
"client_sdk": {
"brand_id": "your-brand-id",
"environment": "Production",
"max_log_level": "Info",
"domains": {
"srs_api_domain": "https://api.example.com/srs/"
}
}
}

JSON has no multi-line strings: write each PEM value on one line, with \n for its line breaks.

The client_sdk object is handed to the Kape Client SDK unchanged, so any key it supports can go there. The Platform SDK reads three of them as well — brand_id, environment and max_log_level — so each is set once, in client_sdk. Keys at the top level with those names are ignored.

KeyRequiredDescription
client_sdkYesKape Client SDK configuration provided to you (a JSON object)
client_sdk.brand_idYesBrand identifier provided to you
client_sdk.environmentYesProduction or Staging
client_sdk.max_log_levelNoOff, Error, Warn, Info, Debug, Trace (default: Info)
client_idOIDC onlyOIDC client ID
issuer_urlOIDC onlyOIDC issuer URL for discovery
redirect_urlOIDC onlyOIDC redirect URI (must match your URL scheme). Unused on tvOS
app_group_identifierNoShared App Group for app + extension IPC. Required when using KapeVPN. Omit it if you use only KapeCore + KapeAuth — see below
keychain_serviceYesKeychain service name for token storage
licenseYesSDK license key provided to you. Which features it grants gates parts of the SDK — see Licensed features below
server_addressNoDisplay address in iOS VPN settings
vpn_profile_nameNoName iOS shows for the VPN configuration in Settings → General → VPN (default: your app's CFBundleDisplayName, then CFBundleName)
packet_tunnel_bundle_identifierNoBundle ID of your Network Extension
lightway_certificateNoCA certificate for verifying Lightway server connections. Required when using the Lightway protocol.
openvpn_ca_certificateNoCA chain PEM for OpenVPN. Required when using the OpenVPN protocol.
openvpn_client_certificateNoClient certificate PEM for OpenVPN. Required when using the OpenVPN protocol.
openvpn_client_keyNoRSA private key matching openvpn_client_certificate. Required when using the OpenVPN protocol.
openvpn_tls_auth_keyNoOpenVPN TLS-Auth static key (V1). Required when using the OpenVPN protocol.
file_logging_enabledNotrue writes the SDK's logs to disk, so they survive the process and can be uploaded or exported with KapeLogsCollector (default: false). Needs max_log_level Info or more verbose. See Logs Collector
logs_collectorNoObject of size and retention limits for the Low Level SDK's log files. See Logs Collector
http_call_behaviorNoInitial HTTP call behavior. Case name matched case-insensitively, e.g. DssAutoDiscover. Leave unset to get InternalHttpClient, or — on a license with CategoryAntiCensorship — automatic anti-censorship detection. See HTTP Call Behavior below.
warning

The same KapeSDK.json must be included in both your app target and Network Extension target. The extension reads it to initialize the SDK with identical settings.

To read a differently named file — one per environment, for example — pass its name, without the extension: KapeSDKSettings(jsonName: "KapeSDK-staging"). The extension then needs to read the same one; see Switching Environment. For settings that do not ship in the bundle, KapeSDKSettings(jsonData:) reads the same format from Data.

A missing file throws KapeSDKSettingsError.jsonNotFound(name:); a file that is not a JSON object, or whose client_sdk is not one, throws KapeSDKSettingsError.invalidJSON(reason:); a missing required key throws KapeSDKSettingsError.missingKey(_:) naming it (e.g. client_sdk.brand_id).

"OIDC only" keys may be omitted if you sign users in only as guests or with an opaque token. An OIDC login without issuer_url (or, in the browser, without redirect_url) throws a KapeError in the Configuration domain naming the key. A value that is present but not a URL still throws KapeSDKSettingsError.invalidURL(key:value:).

Migrating from KapeSDK.plist and a YAML file​

Earlier versions read a KapeSDK.plist plus a separate YAML file it named through YAMLConfigName. That format is still read: KapeSDKSettings() falls back to KapeSDK.plist when the bundle has no KapeSDK.json, and KapeSDKSettings(plistName:) reads a named plist. To migrate, put the YAML file's contents under client_sdk (YAML keys and JSON keys are the same), then move each plist key:

KapeSDK.plist keyKapeSDK.json key
BrandIdclient_sdk.brand_id
Environmentclient_sdk.environment
MaxLogLevelclient_sdk.max_log_level
YAMLConfigName— (the YAML content is client_sdk)
ClientIdclient_id
IssuerURLissuer_url
RedirectURLredirect_url
AppGroupIdentifierapp_group_identifier
KeychainServicekeychain_service
Licenselicense
ServerAddressserver_address
VPNProfileNamevpn_profile_name
PacketTunnelBundleIdentifierpacket_tunnel_bundle_identifier
LightwayCertificatelightway_certificate
OpenVPNCertificateopenvpn_ca_certificate
OpenVPNClientCertopenvpn_client_certificate
OpenVPNClientKeyopenvpn_client_key
OpenVPNTlsAuthKeyopenvpn_tls_auth_key
FileLoggingEnabledfile_logging_enabled
LogsCollectorlogs_collector

If your plist and YAML both set the log level, the plist's MaxLogLevel was the one in effect — carry that value into client_sdk.max_log_level.

Integrations without an App Group​

app_group_identifier exists so the app and its Network Extension can share state. If you use only KapeCore + KapeAuth — no VPN, no extension — omit the key. KapeSDKSettings then reports appGroupIdentifier and keychainAccessGroup as nil, and the SDK uses app-private storage:

With an App GroupWithout
Keychainshared access group (kSecAttrAccessGroup)app's default access group
Auth stateUserDefaults(suiteName:)UserDefaults.standard
File logsApp Group container (its Library/Caches on tvOS)app's own Application Support directory (Caches on tvOS, where Application Support is not writable)

Your app then needs no App Group registration and no com.apple.security.application-groups entitlement. Examples/AuthDemo ships this way, with no entitlements file at all.

Calling a KapeVPN API without an App Group throws a KapeError naming app_group_identifier.

danger

Removing an app_group_identifier you have already shipped is a one-way door. Existing keychain items stay in the old access group and become unreadable — signed-in users are signed out. Decide before your first release.

Entitlements​

If you need to be able to connect to the VPN, both your app and Network Extension require these entitlements:


<key>com.apple.developer.networking.networkextension</key>
<array>
<string>packet-tunnel-provider</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.your.app</string>
</array>

So that Smart Location results are stored per Wi-Fi network, the app (not the extension) also needs com.apple.developer.networking.wifi-info on iOS. See Wi-Fi identity prerequisites.

Network Extension Target​

If you need to be able to connect to the VPN, create a Network Extension target (Packet Tunnel Provider) in your Xcode project with a minimal subclass:

import KapeVPN
import KapeVPN_Lightway_Bridge
import KapeVPN_WireGuard_Bridge

class PacketTunnelProvider: KapePacketTunnelProvider {
override var vpnProtocols: [KapeVPNProtocolSupport] { [.lightway, .wireGuard] }
}

List every protocol whose KapeVPN-<Protocol>-Bridge product you linked: .wireGuard, .lightway, .openVPN. The base class handles everything else: SDK initialization, endpoint discovery, tunnel management, and connection lifecycle. See VPN Protocol for what happens when the selected protocol is not listed.

Licensed features​

Your SDK license carries the set of features it grants. These gate SDK behaviour:

FeatureGates
CategoryDedicatedIpDedicated IP. Without it every fetchDip* call reports the same thing an account with no Dedicated IP licenses reports — KapeDipSetupStage.notEntitled, empty location lists — and connect(to:) with a Dedicated IP location throws KapeVPNError.dipNotEntitled. Nothing to handle beyond what you already handle for an unentitled account
CategorySimpleDedicatedIpSimple Dedicated IPs in fetchDedicatedIPs(), and reserving one. Without it they are left out of the list, with no error, and reserveSimpleDedicatedIP(at:) throws .notEntitled
CategoryAntiCensorshipThe gated HttpCallBehavior cases — see HTTP Call Behavior below
VpnProtocolLightway, VpnProtocolWireGuard, VpnProtocolOpenVpnWhich protocols selectVpnProtocol(_:) accepts, and which endpoints .automatic attempts
VpnProtocolObfuscationObfuscated endpoints. Unlike the rest, this one filters instead of failing
VpnLightwayBitripplesetBitrippleEnabled(_:)
VpnLightwaySnisetLightwaySNI(_:)
VpnHttpsProxysetProxyConfig(_:mode:)
VpnKillSwitchAdvancedsetKillSwitchMode(.advanced). .standard is always available
VpnSplitTunnelsetSplitTunnel(_:)
VpnCustomDnssetCustomDnsServers(_:)
VpnAutoConnectRulessetConnectOnDemand(_:) and setOnDemandRules(_:)
VpnAdvancedProtectionsetAdvancedProtectionCategories(_:)
VpnLightwayHeartbeatsetHeartbeatEnabled(_:)
VpnLightwayExpresslanesetExpresslaneEnabled(_:)
VpnSessionPauseResumepause(for:). resume() is never gated

The fifteen Vpn* features are covered in full — including what each setter throws and what the tunnel does with a value it is not licensed for — in Licensed VPN features.

KapeSdkHandle.hasLicensedFeature(_:) reports what your license grants, so you can hide UI for a feature you are not licensed for. KapeSdkHandle.licenseProblems reports anything wrong with the license itself — expired, revoked, unsigned — and a license carrying any problem grants nothing. Both are resolved from the Low Level SDK's verified view before construction returns; see Licensed VPN features. The Low Level SDK enforces licensing itself, per request, and remains the authority.

HTTP Call Behavior​

HttpCallBehavior controls how the SDK routes its own API requests. .default, .callback, and .internalHttpClient (the default) work on any license. Every other case — DSS, NT, and geo-unblock anti-censorship request routing — requires the CategoryAntiCensorship entitlement on your SDK license.

Automatic anti-censorship detection​

If you leave the http_call_behavior key unset and your license grants CategoryAntiCensorship, the SDK picks an initial behavior for you — you don't need to detect censorship yourself to get anti-censorship routing on a licensed client. At launch, before the SDK manager is constructed (so it's already in effect for your very first SDK call), it reads the device's App Store storefront country to apply the HTTP behavior that is more likely to work in that country.

Licenses without CategoryAntiCensorship are unaffected by this — they always start on .internalHttpClient, same as before.

This only ever applies the initial behavior. Setting the http_call_behavior key always takes precedence — set it explicitly if you want a specific mode (e.g. DssEnforce) pinned from launch rather than the auto-detected one.

Manual control​

Read the current behavior, or switch it live at runtime (e.g. in response to your own censorship detection, or to turn anti-censorship routing off again), via KapeSdkHandle:

// Read the current behavior
let current = handle.httpCallBehavior

// Switch on DSS auto-discovery for licensed clients
handle.setHttpCallBehavior(.dssAutoDiscover)
warning

Setting a gated behavior without the CategoryAntiCensorship entitlement does not fail immediately — but every subsequent SDK call (login, endpoint discovery, subscriptions, ...) throws KapeError (FeatureNotLicensed) until you set the behavior back to .default, .callback, or .internalHttpClient.

info

Calling setHttpCallBehavior(_:) right after constructing KapeSdkHandle — rather than in response to some later event — can race the automatic detection above if the http_call_behavior key is unset: whichever of the two finishes last wins. Set the key instead if you need a specific behavior guaranteed from the very start.