If your organization already runs an MDM service, you need nothing from the server half of this guide: check the first list of prerequisites, read the two sections after them, then skip to Step 4. Any MDM that can send a custom configuration profile and a Managed App Configuration can deploy Xlarva, and the profiles are the same whichever server sends them.
Prerequisites
For any deployment
- Xlarva 3.11 or later on each device. Delivering a Multi-Tunnel or Multi-Hop in a profile needs 3.13 or later. On iPhone and iPad your MDM can take over a copy people installed themselves from the App Store; Step 6 shows how.
- Xlarva Pro on each device. A profile-installed tunnel connects only with Pro, exactly like one added in the app. Organizations can buy subscription seats through Apple Business and assign them with their device management.
- A VPN server, with one identity per device. Xlarva connects to a server you already run: WireGuard, AmneziaWG or CONNECT-IP. A WireGuard configuration is a key pair, and when two devices use the same one at the same time, each connection knocks the other off. Add a peer for every device and send each device its own profile.
For your own MDM server
- A server that stays online, with a public IP address and SSH access with
sudo. This guide uses Debian with systemd. NanoMDM and Caddy need very little, so the smallest plan of most VPS providers is enough for a small fleet. Devices connect to it whenever it wakes them, so it has to be reachable at all times. - A registered domain name whose DNS you can edit. You will add one record, such as
mdm.example.com, pointing straight at the server: an A record, plus AAAA if the server has IPv6. Choose a name you will keep. Every enrollment profile carries it, and moving to another name means enrolling every device again. - TCP port 443 open to the internet. Port 80 can stay closed: Caddy gets its certificate through the TLS-ALPN challenge on 443.
- An Apple Account the organization keeps, rather than an employee's own, for the Apple Push Certificates Portal. Renewing the push certificate every year needs the same account.
- An email address at your organization's own domain, for mdmcert.download in Step 1. It does not accept addresses from free mail providers.
- A Mac to prepare profiles and send them to iPhones by AirDrop. It needs
mdmctlfrom the MicroMDM releases for Step 1;openssl,curl,ssh,uuidgenandplutilcome with macOS.
On the MDM side, only the server and the domain cost money: mdmcert.download, Let's Encrypt, NanoMDM and Caddy are free, and so is the push certificate.
How Apple device management works
Mobile device management (MDM) is a protocol Apple builds into iPhone, iPad, Mac, Apple TV and Apple Vision Pro. Nothing extra is installed on the device. Once it is enrolled, it takes commands from one MDM server, and only from that server: install this profile, report the installed apps, manage this app.
Enrollment
A device enrolls by installing an enrollment profile. The profile names the server's address and carries an identity certificate, with which the device proves who it is every time it talks to the server. There are three ways in:
- Device enrollment. Someone installs the enrollment profile by hand and approves it. This is the route this guide takes, and it works on any device. People can also remove the profile again, which unenrolls the device.
- Automated Device Enrollment. Devices your organization bought from Apple or an authorized reseller are assigned to your server in Apple Business or Apple School Manager, and enroll during Setup Assistant. They are supervised, and the enrollment can be made impossible to remove.
- User Enrollment. For personal devices: the organization gets a separate work space on the device and fewer rights over it.
A device has one MDM enrollment at a time.
The push and the check-in
The server never connects to a device. When it has something to say, it queues a command and asks the Apple Push Notification service (APNs) to wake the device. The push carries nothing but the wake-up. The device then connects to the server over HTTPS, takes the next command, carries it out, reports the result, and asks again until the queue is empty.
Two things follow from this design. An MDM server needs a push certificate from Apple, which lets it address pushes to the devices enrolled with it under a topic of its own. And everything confidential, including the VPN profiles in this guide with their private keys, crosses the HTTPS connection between the device and your server, so whoever terminates that connection can read it.
Configuration profiles
Settings travel in configuration profiles: property lists, usually saved with a .mobileconfig extension, that hold one or more payloads such as a Wi-Fi network, a certificate, a VPN or a set of restrictions. People cannot edit what a profile installs. A profile installed by MDM can be removed only by the MDM, or by removing the enrollment, which takes every MDM profile with it. The same profile can also be installed by hand, which is a handy way to try one before sending it.
Managed apps and their configuration
An MDM can also take an app under management. A managed app can receive a Managed App Configuration, a dictionary the app reads from its own preferences under com.apple.configuration.managed, and attributes such as the per-app VPN its traffic should use. The system delivers the configuration and the app enforces it. This is how Xlarva learns what your organization allows.
Supervision and declarative management
Supervised devices, which come from Automated Device Enrollment or are prepared with Apple Configurator, accept more restrictions, among them one that stops people from creating VPN configurations of their own. Apple's newer Declarative Device Management lets devices apply settings and report changes on their own initiative. This guide uses the classic command protocol, which every MDM server supports; the profiles in it can be delivered either way.
What Xlarva takes from MDM
Xlarva takes two independent channels from your device management. Use either one or both.
| You want to | Send | Needs |
|---|---|---|
| Install a tunnel that people cannot edit, export or delete | A com.apple.vpn.managed payload in a configuration profile |
Any enrollment. Can also be installed by hand. |
| Send only chosen apps, and chosen websites in Safari, through a tunnel | A com.apple.vpn.managed.applayer payload, plus the same VPNUUID in each app's attributes |
MDM. The app assignment cannot be installed by hand. |
| Turn off features of the app and show who manages it | A Managed App Configuration for app.xlarva.apple |
MDM. On a Mac without VPP, a managed preferences profile. |
The Managed deployment chapter of the user guide lists every key Xlarva reads. This article is the walkthrough; that chapter is the reference.
Step 1: Get a push certificate
Apple issues MDM push certificates only for a request signed by an MDM vendor. Commercial MDM services sign it for you. A self-hosted server can use mdmcert.download, a free service for open-source MDM projects, which signs your request and mails it back encrypted to you. You then upload it to Apple yourself, so the certificate is issued to your organization's Apple Account.
The request is made with mdmctl, the command-line tool that ships with MicroMDM. Work in a folder you will keep, because it is about to hold the push certificate's private key:
mkdir -p ~/mdm/push && cd ~/mdm/push
mdmctl mdmcert.download -new -email=it@example.com
This writes the push certificate's private key, mdmcert.download.push.key, and a second key pair that decrypts mdmcert.download's reply, then sends the request. A few minutes later an email arrives with a .p7 file attached. Save it into the same folder and decrypt it:
mdmctl mdmcert.download -decrypt=mdm_signed_request.20261204_101500_1234.plist.b64.p7
The result is mdmcert.download.push.req. Sign in to the Apple Push Certificates Portal with the organization's Apple Account, choose Create a Certificate, upload the .req file and download the certificate. Save it as push.pem beside the key, and read its topic, which every enrollment profile names:
openssl x509 -in push.pem -noout -subject
# subject=UID=com.apple.mgmt.External.4b5c…, CN=APSP:4b5c…, C=US
The topic is the UID value, starting with com.apple.mgmt.External..
Renew it, never replace it
The certificate is valid for a year. Before it expires, make a new request the same way and use Renew next to the existing certificate in the portal, signed in with the same Apple Account. Renewing keeps the topic, so enrolled devices carry on. A new certificate has a new topic, and every device would have to enroll again.
Step 2: Set up the server
NanoMDM is a small open-source MDM server from the MicroMDM project. It speaks the MDM protocol, keeps track of enrollments, queues commands and sends pushes, and leaves the rest, such as which profile goes to which device, to you. It is a single binary. The layout below keeps NanoMDM on the loopback interface, puts Caddy in front of it for TLS, and exposes only the one path devices use. Its API is reached through an SSH tunnel.
A certificate authority for devices
Each device needs its own identity certificate. Create a small certificate authority on your Mac to sign them; NanoMDM accepts only identities it signed. The CA's private key never leaves your Mac: the server needs the certificate alone.
mkdir -p ~/mdm/pki && cd ~/mdm/pki
openssl req -x509 -new -newkey rsa:2048 -nodes -sha256 -days 3650 \
-subj "/O=Example Company/CN=Example MDM Device CA" \
-addext "basicConstraints=critical,CA:TRUE" \
-addext "keyUsage=critical,keyCertSign,cRLSign" \
-keyout ca.key -out ca.crt
For more than a few dozen devices, a SCEP server that issues each device its certificate during enrollment saves this per-device work. The rest of this guide stays with the hand-made identities.
NanoMDM
Download the Linux build from the NanoMDM releases, then on the server install it with the CA certificate and an API key:
sudo install -m 755 nanomdm-linux-amd64 /usr/local/bin/nanomdm
sudo useradd --system --home-dir /var/lib/nanomdm --shell /usr/sbin/nologin nanomdm
sudo install -d -m 755 /etc/nanomdm
sudo install -m 644 ca.crt /etc/nanomdm/ca.pem
echo "NANOMDM_API_KEY=$(openssl rand -hex 32)" | sudo tee /etc/nanomdm/env >/dev/null
sudo chmod 600 /etc/nanomdm/env
Run it as a systemd service, listening on the loopback interface only:
/etc/systemd/system/nanomdm.service
[Unit]
Description=NanoMDM
After=network-online.target
Wants=network-online.target
[Service]
User=nanomdm
Group=nanomdm
EnvironmentFile=/etc/nanomdm/env
ExecStart=/usr/local/bin/nanomdm \
-listen 127.0.0.1:9000 \
-storage filekv -storage-dsn /var/lib/nanomdm/db \
-ca /etc/nanomdm/ca.pem \
-api ${NANOMDM_API_KEY}
StateDirectory=nanomdm
StateDirectoryMode=0700
Restart=on-failure
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
ReadWritePaths=/var/lib/nanomdm
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now nanomdm
The file store suits a small fleet. NanoMDM can keep its data in MySQL or PostgreSQL instead.
Caddy in front
Caddy gets a certificate from Let's Encrypt by itself and forwards only /mdm, the path both check-ins and commands use. Install it (sudo apt install caddy on Debian) and replace /etc/caddy/Caddyfile:
/etc/caddy/Caddyfile
{
# Certificates come through the TLS-ALPN challenge on port 443,
# so port 80 can stay closed.
auto_https disable_redirects
}
mdm.example.com {
tls {
issuer acme {
disable_http_challenge
}
}
# Devices only. The /v1 API stays on the loopback interface.
handle /mdm {
reverse_proxy 127.0.0.1:9000
}
handle {
respond 404
}
}
sudo systemctl restart caddy
If another service on the server needs UDP port 443, such as a QUIC-based VPN relay, add servers { protocols h1 h2 } to the global block at the top, and Caddy leaves UDP alone.
Keep the MDM off TLS-terminating proxies
Point the DNS record straight at the server. A CDN in proxy mode decrypts every command on its way to the device, and the VPN profiles in Step 4 carry the tunnels' private keys. No client-certificate setup is needed at the proxy either: the enrollment profile in Step 3 has devices sign every message, and NanoMDM checks the signature itself.
Upload the push certificate
From your Mac, open an SSH tunnel to the API and upload the certificate with its key. Keep a copy of the API key from /etc/nanomdm/env on your Mac as NANOMDM_API_KEY:
ssh -f -N -L 9000:127.0.0.1:9000 admin@mdm.example.com
export NANOMDM_API_KEY=… # the value from /etc/nanomdm/env
cd ~/mdm/push
cat push.pem mdmcert.download.push.key |
curl -sS -u "nanomdm:$NANOMDM_API_KEY" -T - http://127.0.0.1:9000/v1/pushcert
NanoMDM answers with the topic and the certificate's expiry date. Upload the renewed certificate the same way each year.
Step 3: Enroll a device
Make its identity
On your Mac, sign an identity for the device and pack it with its key into a PKCS #12 file. The legacy 3DES and SHA-1 options make a file every iOS and macOS version imports from a profile; OpenSSL 3 and later default to AES, which not every version does.
cd ~/mdm/pki
printf 'basicConstraints=critical,CA:FALSE\nkeyUsage=critical,digitalSignature,keyEncipherment\nextendedKeyUsage=clientAuth\n' > device.ext
openssl req -new -newkey rsa:2048 -nodes -subj "/O=Example Company/CN=MDM alice-iphone" \
-keyout alice-iphone.key -out alice-iphone.csr
openssl x509 -req -in alice-iphone.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
-days 1825 -sha256 -extfile device.ext -out alice-iphone.crt
openssl pkcs12 -export -inkey alice-iphone.key -in alice-iphone.crt -name "MDM alice-iphone" \
-keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -macalg sha1 \
-passout pass:CHOOSE-A-PASSWORD -out alice-iphone.p12
Give every device its own identity: NanoMDM refuses an identity another enrollment already uses.
Write the enrollment profile
The profile holds two payloads: the identity, and the MDM payload that points at your server and names that identity. Save it as alice-iphone.mobileconfig:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadType</key> <string>Configuration</string>
<key>PayloadIdentifier</key> <string>com.example.mdm</string>
<key>PayloadUUID</key> <string>REPLACE-WITH-UUIDGEN</string>
<key>PayloadVersion</key> <integer>1</integer>
<key>PayloadDisplayName</key> <string>Example Company MDM</string>
<key>PayloadOrganization</key> <string>Example Company</string>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadType</key> <string>com.apple.security.pkcs12</string>
<key>PayloadIdentifier</key> <string>com.example.mdm.identity</string>
<key>PayloadUUID</key> <string>IDENTITY-UUID</string>
<key>PayloadVersion</key> <integer>1</integer>
<key>Password</key> <string>CHOOSE-A-PASSWORD</string>
<key>PayloadContent</key> <data>BASE64_OF_THE_P12</data>
</dict>
<dict>
<key>PayloadType</key> <string>com.apple.mdm</string>
<key>PayloadIdentifier</key> <string>com.example.mdm.enrollment</string>
<key>PayloadUUID</key> <string>REPLACE-WITH-UUIDGEN</string>
<key>PayloadVersion</key> <integer>1</integer>
<key>ServerURL</key> <string>https://mdm.example.com/mdm</string>
<key>CheckInURL</key> <string>https://mdm.example.com/mdm</string>
<key>Topic</key> <string>com.apple.mgmt.External.YOUR-TOPIC</string>
<key>IdentityCertificateUUID</key> <string>IDENTITY-UUID</string>
<key>SignMessage</key> <true/>
<key>AccessRights</key> <integer>8179</integer>
<key>CheckOutWhenRemoved</key> <true/>
<key>ServerCapabilities</key>
<array>
<string>com.apple.mdm.per-user-connections</string>
</array>
</dict>
</array>
</dict>
</plist>
- Paste the output of
base64 -i alice-iphone.p12overBASE64_OF_THE_P12, and the password you chose overCHOOSE-A-PASSWORD. - Run
uuidgenonce and put the result in both places that sayIDENTITY-UUID: the MDM payload finds its identity by this UUID. Run it again for eachREPLACE-WITH-UUIDGEN. - Set
ServerURLandCheckInURLto your server, andTopicto the topic from Step 1. - Check the file with
plutil -lint alice-iphone.mobileconfig.
A few of the keys deserve a word. SignMessage has the device sign each request with its identity, which is how NanoMDM knows who is calling without TLS client authentication. AccessRights is a bit mask of what the server may do; 8179 grants everything except erasing the device, locking it and clearing its passcode, none of which a VPN deployment needs. com.apple.mdm.per-user-connections lets a Mac enroll its logged-in user as a second channel beside the device.
Treat the profile like a key
It contains the device's private key and the password that opens it. Hand it over directly, by AirDrop or on the device itself, not by email or a shared link.
Install it
- iPhone or iPad: on your Mac, Control-click the file and choose Share → AirDrop; double-clicking would install it on the Mac instead. On the device, open Settings, tap Profile Downloaded, then Install, and trust the remote management when asked.
- Mac: double-click the file, then approve it in System Settings → General → Device Management (Privacy & Security → Profiles on macOS 14). An enrollment approved by the user this way is user approved, which Step 4 needs for the system extension policy.
Watch the server while the device enrolls. Its first check-ins carry its enrollment id, which every command needs: the UDID on an iPhone or iPad. A Mac also enrolls its logged-in user, as <device id>:<user id>; send device-wide profiles to the device id.
ssh admin@mdm.example.com sudo journalctl -u nanomdm -f
# msg=Authenticate id=00008140-000A1B2C3D4E5F6G type=Device serial_number=…
Send it a first command
A command is a property list with a CommandUUID and a Command dictionary. NanoMDM's /v1/enqueue/<id> queues it and pushes the device in one call. Each command needs a UUID of its own, and a device ignores one it has answered before, so this small helper fills in a fresh one on every send. Add it to your shell:
# Queue a command for a device and push it. The COMMAND_UUID placeholder
# in the file gets a new UUID on every send.
mdm_send() { # mdm_send <enrollment-id> <command.plist>
sed "s/COMMAND_UUID/$(uuidgen)/" "$2" |
curl -sS -u "nanomdm:$NANOMDM_API_KEY" -X PUT --data-binary @- \
"http://127.0.0.1:9000/v1/enqueue/$1"
echo
}
DEVICE=00008140-000A1B2C3D4E5F6G # the enrollment id from the log
Then ask the device for its installed profiles:
profile-list.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CommandUUID</key> <string>COMMAND_UUID</string>
<key>Command</key>
<dict>
<key>RequestType</key> <string>ProfileList</string>
</dict>
</dict>
</plist>
mdm_send "$DEVICE" profile-list.plist
# {"status":{"00008140-…":{"push_result":"…"}},"command_uuid":"…","request_type":"ProfileList"}
Within a few seconds the server's log shows the device's answer as status=Acknowledged with the same command_uuid. The statuses you will see:
| Status | Meaning |
|---|---|
Acknowledged | Done. A query's answer comes with it. |
Error | Failed. The answer's ErrorChain says why. |
NotNow | The device is locked or busy. It fetches the command again by itself, for example once it is unlocked. |
CommandFormatError | The command itself is malformed. |
NanoMDM keeps each full answer in its store. To read answers as they arrive, start it with -webhook-url pointing at a service of yours, which then receives every check-in and result. For a quick look, -dump prints every request and response to the log; turn it off again afterwards, because it logs the VPN profiles you send as well.
Step 4: Install a tunnel
A tunnel travels in a com.apple.vpn.managed payload whose VPNSubType is app.xlarva.apple. The tunnel itself sits in the payload's VendorConfig dictionary, under exactly one of these keys:
| Key | Holds |
|---|---|
WgQuickConfigBase64 | A WireGuard .conf file, Base64-encoded on one line. AmneziaWG and CONNECT-IP files work too. WgQuickConfig takes the same file as plain text, for consoles that keep line breaks. |
XlarvaConfigBase64 | A configuration exported from Xlarva, for settings a .conf file cannot express, such as obfuscation or DDNS. A Multi-Tunnel or Multi-Hop goes with the configurations it runs, exactly as Xlarva exports it (3.13 or later). XlarvaConfig takes it unencoded. |
The keys for a .conf file are the ones WireGuard's own app reads, so an existing WireGuard profile needs only its VPNSubType and provider changed. Base64 is a transport encoding, not encryption: the finished profile holds the tunnel's private key.
Example.mobileconfig — an iPhone and iPad profile with one tunnel that connects on demand
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadType</key> <string>Configuration</string>
<key>PayloadIdentifier</key> <string>com.example.vpn</string>
<key>PayloadUUID</key> <string>REPLACE-WITH-UUIDGEN</string>
<key>PayloadVersion</key> <integer>1</integer>
<key>PayloadDisplayName</key> <string>Example VPN</string>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadType</key> <string>com.apple.vpn.managed</string>
<key>PayloadIdentifier</key> <string>com.example.vpn.tunnel</string>
<key>PayloadUUID</key> <string>REPLACE-WITH-UUIDGEN</string>
<key>PayloadVersion</key> <integer>1</integer>
<key>UserDefinedName</key> <string>Corporate VPN</string>
<key>VPNType</key> <string>VPN</string>
<key>VPNSubType</key> <string>app.xlarva.apple</string>
<key>VendorConfig</key>
<dict>
<key>WgQuickConfigBase64</key>
<string>BASE64_OF_THE_WIREGUARD_CONF</string>
</dict>
<key>VPN</key>
<dict>
<key>RemoteAddress</key> <string>vpn.example.com</string>
<key>ProviderBundleIdentifier</key> <string>app.xlarva.apple.tunnel</string>
<key>ProviderType</key> <string>packet-tunnel</string>
<key>AuthenticationMethod</key> <string>Password</string>
<key>AuthName</key> <string>unused</string>
<key>AuthPassword</key> <string>unused</string>
<key>OnDemandEnabled</key> <integer>1</integer>
<key>OnDemandRules</key>
<array>
<dict><key>Action</key><string>Connect</string></dict>
</array>
</dict>
</dict>
</array>
</dict>
</plist>
- Encode the device's tunnel with
base64 -i alice-iphone.conf | tr -d '\n'and paste the output overBASE64_OF_THE_WIREGUARD_CONF. - Give each
REPLACE-WITH-UUIDGENits ownuuidgen, and replacecom.example.vpnin both identifiers with a name of your own. Sending a profile with the same identifier again replaces the installed one, which is how you update a tunnel. - Set
RemoteAddressto the host in the file'sEndpointline andUserDefinedNameto the name people should see. LeaveAuthNameandAuthPasswordin place: WireGuard does not use them, but recent iOS versions refuse the payload without them and report only that the VPN service could not be installed. - Automatic connection and blocking traffic outside the tunnel come from Apple's standard keys in the
VPNdictionary,OnDemandEnabled,OnDemandRulesandIncludeAllNetworks. Xlarva runs what the profile sets. - Check the file with
plutil -lint Example.mobileconfig. To try it before involving the server, AirDrop it to a test device and install it by hand: Xlarva treats a hand-installed profile exactly like one from MDM. Remove that copy before sending the same profile from MDM, because a device refuses an MDM profile whose identifier belongs to one installed by hand.
An InstallProfile command carries the whole profile as data:
cat > install-vpn.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CommandUUID</key> <string>COMMAND_UUID</string>
<key>Command</key>
<dict>
<key>RequestType</key> <string>InstallProfile</string>
<key>Payload</key> <data>$(base64 -i Example.mobileconfig)</data>
</dict>
</dict>
</plist>
EOF
mdm_send "$DEVICE" install-vpn.plist
To take the tunnel away, send RemoveProfile with the profile's identifier, <key>Identifier</key> <string>com.example.vpn</string>, in place of the payload.
On a Mac
On a Mac the tunnel runs as a system extension, and the profile says so. Install it with PayloadScope System, use the Mac provider, and name the extension's code signature:
<!-- At the top level, beside PayloadType Configuration -->
<key>PayloadScope</key> <string>System</string>
<!-- In the VPN dictionary -->
<key>ProviderBundleIdentifier</key> <string>app.xlarva.apple.tunnelextension</string>
<key>ProviderDesignatedRequirement</key> <string>THE_REQUIREMENT_CODESIGN_PRINTS</string>
Read the requirement from the installed app on a Mac that runs the build people will use. A TestFlight build is signed with a different certificate from the App Store one, and its requirement names that certificate:
codesign -d -r- /Applications/Xlarva.app/Contents/Library/SystemExtensions/app.xlarva.apple.tunnelextension.systemextension
# designated => anchor apple generic and …
Everything after designated => is the value. So that people are not asked to allow the extension the first time it starts, pre-approve it in the same profile or another one:
<dict>
<key>PayloadType</key> <string>com.apple.system-extension-policy</string>
<key>PayloadIdentifier</key> <string>com.example.vpn.extension</string>
<key>PayloadUUID</key> <string>REPLACE-WITH-UUIDGEN</string>
<key>PayloadVersion</key> <integer>1</integer>
<key>AllowedSystemExtensions</key>
<dict>
<key>NBQ74QRWC2</key>
<array>
<string>app.xlarva.apple.tunnelextension</string>
</array>
</dict>
</dict>
NBQ74QRWC2 is Xlarva's team identifier. Send Mac profiles to the device id, not to the user channel. Xlarva reads a new profile when it next comes to the front.
What people see
- A building icon on Xlarva's home screen whenever a profile has installed a tunnel. It opens the list of tunnels your organization manages.
- Each tunnel's status, routing, on-demand state and whether it blocks connections without the VPN. Keys, peers and endpoints are not shown, and there is nothing to edit, export or delete.
- People connect and disconnect it in Settings → VPN on iPhone and iPad, or System Settings → VPN on a Mac, unless on-demand rules do it for them. Shortcuts cannot control it.
Step 5: Send chosen apps through the tunnel
A per-app VPN carries only the traffic of the apps assigned to it, and the system picks that traffic by the app it comes from. The VPN server needs no change. It takes two pieces: a com.apple.vpn.managed.applayer payload with a VPNUUID, and that same VPNUUID in each assigned app's attributes.
A per-app payload: one entry of the profile's PayloadContent, in place of the whole-device one
<dict>
<key>PayloadType</key> <string>com.apple.vpn.managed.applayer</string>
<key>PayloadIdentifier</key> <string>com.example.perapp.tunnel</string>
<key>PayloadUUID</key> <string>REPLACE-WITH-UUIDGEN</string>
<key>PayloadVersion</key> <integer>1</integer>
<key>UserDefinedName</key> <string>Work Apps</string>
<key>VPNUUID</key> <string>REPLACE-WITH-UUIDGEN</string>
<key>OnDemandMatchAppEnabled</key> <true/>
<key>SafariDomains</key>
<array>
<string>intranet.example.com</string>
</array>
<key>VPNType</key> <string>VPN</string>
<key>VPNSubType</key> <string>app.xlarva.apple</string>
<key>VendorConfig</key>
<dict>
<key>WgQuickConfigBase64</key> <string>BASE64_OF_THE_WIREGUARD_CONF</string>
</dict>
<key>VPN</key>
<dict>
<key>RemoteAddress</key> <string>vpn.example.com</string>
<key>ProviderBundleIdentifier</key> <string>app.xlarva.apple.tunnel</string>
<key>ProviderType</key> <string>packet-tunnel</string>
<key>AuthenticationMethod</key> <string>Password</string>
<key>AuthName</key> <string>unused</string>
<key>AuthPassword</key> <string>unused</string>
<key>OnDemandEnabled</key> <integer>1</integer>
<key>OnDemandRules</key>
<array>
<dict>
<key>Action</key> <string>Disconnect</string>
<key>InterfaceTypeMatch</key> <string>WiFi</string>
<key>SSIDMatch</key>
<array>
<string>Office</string>
</array>
</dict>
</array>
</dict>
</dict>
- Both on-demand keys are needed. An assigned app's traffic starts the tunnel only with
OnDemandMatchAppEnabledbeside the payload's type andOnDemandEnabledset to1in itsVPNdictionary. With the first alone, iOS stores the tunnel with on-demand off, and the apps' connections never start it. SafariDomainssends those websites in Safari through the tunnel, subdomains included. Safari needs no assignment and does not have to be managed. Their DNS queries go through the tunnel as well, so the tunnel's DNS server must answer through it.- A
Disconnectrule lets the assigned apps connect directly on the networks it matches, here the Wi-Fi named Office. A per-app tunnel uses onlyDisconnectrules; leave the rules out if the apps should use the tunnel everywhere.
Send the profile with InstallProfile as in Step 4. Then assign apps. An App Store app that is not managed yet is taken over with InstallApplication; on iPhone and iPad this needs no VPP license, and the device asks the person to allow it:
<key>Command</key>
<dict>
<key>RequestType</key> <string>InstallApplication</string>
<key>Identifier</key> <string>com.example.crm</string>
<key>ChangeManagementState</key> <string>Managed</string>
<key>ManagementFlags</key> <integer>0</integer>
<key>Attributes</key>
<dict>
<key>VPNUUID</key> <string>THE_PER_APP_PAYLOAD_VPNUUID</string>
</dict>
</dict>
An app that is already managed is reassigned without asking, with a Settings command:
<key>Command</key>
<dict>
<key>RequestType</key> <string>Settings</string>
<key>Settings</key>
<array>
<dict>
<key>Item</key> <string>ApplicationAttributes</string>
<key>Identifier</key> <string>com.example.crm</string>
<key>Attributes</key>
<dict>
<key>VPNUUID</key> <string>THE_PER_APP_PAYLOAD_VPNUUID</string>
</dict>
</dict>
</array>
</dict>
A ManagedApplicationAttributes command lists the VPNUUID each managed app is assigned to. On iPhone and iPad, Mail, Calendar and Contacts use the tunnel for an account a profile installs, when the account payload carries the same VPNUUID.
Expected on iPhone, not faults
- While the tunnel is not running, an assigned app has no network at all; it does not fall back to a direct connection. When the tunnel cannot start, because the server is unreachable or the device has no Xlarva Pro, the assigned apps are offline.
- The VPN icon in the status bar shows only while an assigned app is in the foreground. The tunnel keeps running when you switch away.
- Changing the rules of a per-app profile already on the device takes a remove and a reinstall: an update in place keeps the rules the device already took. Keep the same
VPNUUID, and the apps stay assigned.
On a Mac
A Mac has no managed apps to carry a VPNUUID, so the assignment goes into the profile itself, as a com.apple.vpn.managed.appmapping payload beside the per-app payload. The per-app payload takes the Mac keys from Step 4.
<dict>
<key>PayloadType</key> <string>com.apple.vpn.managed.appmapping</string>
<key>PayloadIdentifier</key> <string>com.example.perapp.apps</string>
<key>PayloadUUID</key> <string>REPLACE-WITH-UUIDGEN</string>
<key>PayloadVersion</key> <integer>1</integer>
<key>AppLayerVPNMapping</key>
<array>
<dict>
<key>Identifier</key> <string>com.example.crm</string>
<key>SigningIdentifier</key> <string>com.example.crm</string>
<key>DesignatedRequirement</key> <string>THE_REQUIREMENT_CODESIGN_PRINTS</string>
<key>VPNUUID</key> <string>THE_PER_APP_PAYLOAD_VPNUUID</string>
</dict>
</array>
</dict>
codesign -dv -r- /Applications/Example.app prints both the signing identifier (Identifier=) and the designated requirement of each app.
Step 6: Restrict and brand Xlarva
The Managed App Configuration decides what people may do in Xlarva and tells them who manages it. Every key is optional and every restriction defaults to allowed, so send only what you want to change:
| Key | When false |
|---|---|
allowManualTunnels | People cannot add, import, edit, delete or connect tunnels of their own. Profile-installed tunnels are unaffected. |
allowSelfHostedDeploy | Deploying a server over SSH is unavailable. |
allowExport | Exporting and sharing configurations, and sending them to an Apple TV, are unavailable. |
allowCloudSync | Xlarva stops syncing through iCloud from its next launch. |
allowLANGateway | The SOCKS5 server that shares a tunnel with the local network stays off. |
companyName, contactEmail, contactPhone, contactAddress, companyLogo | Not restrictions: shown in Xlarva so people know whom to ask. |
On iPhone and iPad, InstallApplication takes over the copy of Xlarva already installed and hands it the configuration in one command. The device asks the person to allow it; the installed build stays as it is.
<key>Command</key>
<dict>
<key>RequestType</key> <string>InstallApplication</string>
<key>Identifier</key> <string>app.xlarva.apple</string>
<key>ChangeManagementState</key> <string>Managed</string>
<key>ManagementFlags</key> <integer>0</integer>
<key>Configuration</key>
<dict>
<key>allowManualTunnels</key> <false/>
<key>allowExport</key> <false/>
<key>companyName</key> <string>Example Company</string>
<key>contactEmail</key> <string>it@example.com</string>
</dict>
</dict>
To change the configuration later, send a Settings command with an ApplicationConfiguration item: Item, Identifier app.xlarva.apple, and the new Configuration dictionary. It replaces the old one whole.
A Mac accepts InstallApplication only with a VPP license. Without one, send the same dictionary as managed preferences: a profile with PayloadScope System holding a com.apple.ManagedClient.preferences payload. Relaunch Xlarva once it has arrived.
<dict>
<key>PayloadType</key> <string>com.apple.ManagedClient.preferences</string>
<key>PayloadIdentifier</key> <string>com.example.xlarva.policy</string>
<key>PayloadUUID</key> <string>REPLACE-WITH-UUIDGEN</string>
<key>PayloadVersion</key> <integer>1</integer>
<key>PayloadContent</key>
<dict>
<key>app.xlarva.apple</key>
<dict>
<key>Forced</key>
<array>
<dict>
<key>mcx_preference_settings</key>
<dict>
<key>com.apple.configuration.managed</key>
<dict>
<key>allowManualTunnels</key> <false/>
<key>companyName</key> <string>Example Company</string>
</dict>
</dict>
</dict>
</array>
</dict>
</dict>
</dict>
The company details appear under Settings → Organization in Xlarva, and companyLogo, a PNG or JPEG of at most 512 KB, at the top of each profile-installed tunnel's page.
Restrictions are enforced by the app
Xlarva follows the configuration, but it is only as strong as the management that keeps people from removing it. On supervised devices, also set the allowVPNCreation restriction to false: the system then refuses any VPN configuration people create, in Xlarva or elsewhere, while profile-installed ones keep working.
Troubleshooting
- A command never gets an answer, and the device never checks in. The enrollment profile may have been removed on the device. APNs still accepts pushes for a device that has left, so the server cannot tell. Enroll it again with its own enrollment profile; that also clears its command queue. A device that cannot resolve the server's name reports
NSURLErrorDomain -1003: if you looked the name up before its DNS record existed, a resolver on the way may still be caching the negative answer. NotNow. The device is locked. It fetches the command again once unlocked.- The profile "is not managed by MDM". A profile with the same
PayloadIdentifierwas installed by hand. Remove it on the device, or give the MDM profile another identifier. - A command sent again does nothing. It still has the old
CommandUUID. The server accepts it, but the device does not run it again, and the answer on record is the old one.mdm_sendfills in a new UUID each time for this reason. - "The VPN service could not be installed." Check
AuthNameandAuthPassword, and thatProviderBundleIdentifiermatches the platform. - The tunnel is installed but never connects. The device needs Xlarva Pro.
- Two devices keep dropping each other's connection. They share one WireGuard key. Give each device its own configuration.
- A Mac stops answering while its tunnel is up. In our testing, a Mac whose whole-device tunnel routed all traffic, without Include All Networks, received no pushes until the tunnel disconnected; with Include All Networks the Exclude APNs setting keeps pushes outside the tunnel. To reach such a Mac, send commands while it is off the tunnel, or narrow the tunnel's routes.
Keeping it running
Back these up somewhere safe, and keep them out of the web root and out of any repository:
| File | Without it |
|---|---|
mdmcert.download.push.key and push.pem | No pushes. The key is needed to renew under the same topic. |
ca.key and ca.crt | No identities for new devices. A new CA means every device enrolls again. |
/var/lib/nanomdm/db on the server | The server forgets its enrollments, and every device enrolls again. |
| The API key | Generate a new one and restart NanoMDM; nothing is lost. |
Put the push certificate's renewal date in a calendar a few weeks early. Device profiles hold private keys too, both the MDM identity and the tunnel: delete the copies you no longer need once they are installed.
That is the whole path: a push certificate, a small server, one enrollment per device, and three kinds of payload. The Managed deployment chapter of the guide covers every key in more detail, and if something here does not behave as described, tell us.