m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

iOSのVPNの構成プロファイルを検証(オンデマンド接続)

いつごろ追加されているかは知らないが

https://developer.apple.com/documentation/devicemanagement/vpn/ikev2?changes=latest_minor

まあ、オンデマンド接続自体はあっても困らないのでよい それぞれがどのような動きをするか確認

VPN.IKEv2配下

IKEv2配下のキー内で設定可能なもの

項番 キー名 説明 備考
1 OnDemandEnabled 1またはtrueの場合にオンデマンド接続を有効にする OnDemandRulesが設定されていること
2 OnDemandRules 配列形式にオンデマンドルールを設定して、オンデマンド接続を有効にする 複数の一致条件がある場合は先勝ち

※接続と切断の両方が混在する場合は正しい挙動ができないため、非推奨
3 OnDemandUserOverrideDisabled 1またはtrueの場合にオンデマンド接続時の切り替えスイッチを変更不可にする DEP化対象端末による配信処理でのみ有効

VPN.VPN.OnDemandRulesElement

オンデマンドルール条件 Actionだけでも動作はするため、一切、VPNに繋げさせない設定として指定することも可能

項番 キー名 必須 説明 備考
1 Action 必須 ルール一致時の動作
・Connect
 VPNオンデマンド接続を行う
※別のネットワークへ切り替えてもVPN接続は解除されない

・Disconnect
 VPN接続不可とする

・EvaluateConnection
 通信時に判定してオンデマンド接続の制御を行う

・Ignore
 ネットワーク切り替え時のみオンデマンド接続時、接続解除後はオンデマンド接続を無効にする
Connect中はVPN設定のオンデマンド接続トグルをOFFにしない限り、通信が始まるとVPN接続を試行する
2 ActionParameters - ActionEvaluateConnection時の判定条件を指定 ActionEvaluateConnection時は必須
3 DNSDomainMatch - DNS検索ドメインが含まれる場合は一致扱いとなる 基本、InterfaceTypeMatchCellular以外

また、*を含めることもサポートされている模様
4 DNSServerAddressMatch - DNSサーバが含まれる場合は一致扱いとなる 基本、InterfaceTypeMatchCellular以外

また、CIDR指定もサポートされている模様
5 InterfaceTypeMatch - インターフェース
Ethernet
WiFi
・Cellular
iOSで有線できないので基本、WiFiCellular
6 SSIDMatch - SSIDが含まれている場合は一致扱い 基本、InterfaceTypeMatchWiFiのみ
7 URLStringProbe - プローブURL
リクエストを送信して200OKの場合は一致扱い

DNSDomainMatchDNSServerAddressMatchは接続する端末のネットワーク情報を参照して判定するため

VPN.VPN.OnDemandRulesElement.ActionParameters

アクションパラメータ条件 特定のドメインへのアクセス時に特定のDNSサーバやプローブURLと通信できない場合にVPN接続するように制御するため、
VPN接続している場合のみ200OKが返る設定を行う

項番 キー名 必須 説明 備考
1 DomainAction 必須 ドメイン一致時の挙動を指定
・ConnectIfNeeded
・NeverConnect
2 Domains 必須 ドメイン
3 RequiredDNSServers - VPN接続時のみ通信可能なDNSサーバアドレス
到達できない場合はVPN接続を行う
DomainActionConnectIfNeeded
4 RequiredURLStringProbe - VPN接続時のみ通信可能なプローブURL DomainActionConnectIfNeeded

設定例

項番 パターン 備考
1 WiFiの場合はVPN接続する
2 Cellularの場合はVPN接続しない
3 SSIDhogehogeの場合は接続する
4 SSIDhogehogeの場合は接続、Cellularの場合はVPN接続しない
5 通信チェックしてドメインへの名前解決ができない場合に VPN接続を行う

共通設定

<?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>PayloadContent</key>
    <array>
        <dict>
            <key>DNS</key>
            <dict>
                <key>ServerAddresses</key>
                <array>
                    <string>8.8.8.8</string>
                    <string>8.8.4.4</string>
                </array>
                <key>SupplementalMatchDomainsNoSearch</key>
                <integer>0</integer>
            </dict>
            <key>IKEv2</key>
            <dict>
                <key>AuthName</key>
                <string>任意のアカウント</string>
                <key>AuthPassword</key>
                <string>任意のパスワード</string>
                <key>AuthenticationMethod</key>
                <string>None</string>
                <key>ChildSecurityAssociationParameters</key>
                <dict>
                    <key>DiffieHellmanGroup</key>
                    <integer>14</integer>
                    <key>EncryptionAlgorithm</key>
                    <string>AES-256</string>
                    <key>IntegrityAlgorithm</key>
                    <string>SHA2-256</string>
                    <key>LifeTimeInMinutes</key>
                    <integer>1440</integer>
                </dict>
                <key>DeadPeerDetectionRate</key>
                <string>Medium</string>
                <key>DisableMOBIKE</key>
                <integer>0</integer>
                <key>DisableRedirect</key>
                <integer>0</integer>
                <key>EnableCertificateRevocationCheck</key>
                <integer>0</integer>
                <key>EnableFallback</key>
                <integer>0</integer>
                <key>EnablePFS</key>
                <integer>0</integer>
                <key>ExtendedAuthEnabled</key>
                <true/>
                <key>IKESecurityAssociationParameters</key>
                <dict>
                    <key>DiffieHellmanGroup</key>
                    <integer>14</integer>
                    <key>EncryptionAlgorithm</key>
                    <string>AES-256</string>
                    <key>IntegrityAlgorithm</key>
                    <string>SHA2-256</string>
                    <key>LifeTimeInMinutes</key>
                    <integer>1440</integer>
                </dict>
                <key>LocalIdentifier</key>
                <string>多分、VPNサーバドメイン</string>
                <key>RemoteAddress</key>
                <string>多分、VPNサーバドメイン</string>
                <key>RemoteIdentifier</key>
                <string>多分、VPNサーバドメイン</string>
                <key>UseConfigurationAttributeInternalIPSubnet</key>
                <integer>0</integer>
            </dict>
            <key>PayloadDescription</key>
            <string>VPN設定を構成します</string>
            <key>PayloadDisplayName</key>
            <string>VPN</string>
            <key>PayloadIdentifier</key>
            <string>com.apple.vpn.managed.ここはなんかシステムで動的に変わる</string>
            <key>PayloadType</key>
            <string>com.apple.vpn.managed</string>
            <key>PayloadUUID</key>
            <string>ここはなんかシステムで動的に変わる</string>
            <key>PayloadVersion</key>
            <integer>1</integer>
            <key>Proxies</key>
            <dict>
                <key>HTTPEnable</key>
                <integer>0</integer>
                <key>HTTPSEnable</key>
                <integer>0</integer>
            </dict>
            <key>UserDefinedName</key>
            <string>vpn.test-ryuouen.link</string>
            <key>VPNType</key>
            <string>IKEv2</string>
        </dict>
    </array>
    <key>PayloadDisplayName</key>
    <string>vpnオンデマンドテスト</string>
    <key>PayloadIdentifier</key>
    <string>ここはなんかシステムで動的に変わる</string>
    <key>PayloadRemovalDisallowed</key>
    <false/>
    <key>PayloadType</key>
    <string>Configuration</string>
    <key>PayloadUUID</key>
    <string>ここはなんかシステムで動的に変わる</string>
    <key>PayloadVersion</key>
    <integer>1</integer>
</dict>
</plist>

以下、差分を記載

WiFiの場合はVPN接続する

         <key>IKEv2</key>
            <dict>
                <key>OnDemandEnabled</key>
                <integer>1</integer>
                <key>OnDemandUserOverrideDisabled</key>
                <integer>1</integer>
                <key>OnDemandRules</key>
                <array>
                    <dict>
                        <key>Action</key>
                        <string>Connect</string>
                        <key>InterfaceTypeMatch</key>
                        <string>WiFi</string>
                    </dict>
                </array>

Cellularの場合はVPN接続しない

         <key>IKEv2</key>
            <dict>
                <key>OnDemandEnabled</key>
                <integer>1</integer>
                <key>OnDemandUserOverrideDisabled</key>
                <integer>1</integer>
                <key>OnDemandRules</key>
                <array>
                    <dict>
                        <key>Action</key>
                        <string>Disconnect</string>
                        <key>InterfaceTypeMatch</key>
                        <string>Cellular</string>
                    </dict>
                </array>

SSIDhogehogeの場合は接続する

         <key>IKEv2</key>
            <dict>
                <key>OnDemandEnabled</key>
                <integer>1</integer>
                <key>OnDemandUserOverrideDisabled</key>
                <integer>1</integer>
                <key>OnDemandRules</key>
                <array>
                    <dict>
                        <key>Action</key>
                        <string>Connect</string>
                        <key>InterfaceTypeMatch</key>
                        <string>WiFi</string>
                        <key>SSIDMatch</key>
                        <array>
                            <string>hogehoge</string>
                        </array>
                    </dict>
                </array>

SSIDhogehogeの場合は接続、Cellularの場合はVPN接続しない

         <key>IKEv2</key>
            <dict>
                <key>OnDemandEnabled</key>
                <integer>1</integer>
                <key>OnDemandUserOverrideDisabled</key>
                <integer>1</integer>
                <key>OnDemandRules</key>
                <array>
                    <dict>
                        <key>Action</key>
                        <string>Connect</string>
                        <key>InterfaceTypeMatch</key>
                        <string>WiFi</string>
                        <key>SSIDMatch</key>
                        <array>
                            <string>ryuouennet_mk2_A</string>
                        </array>
                    </dict>
                    <dict>
                        <key>Action</key>
                        <string>Disconnect</string>
                        <key>InterfaceTypeMatch</key>
                        <string>Cellular</string>
                    </dict>
                </array>

通信チェックしてドメインへの名前解決ができない場合に VPN接続を行う

         <key>IKEv2</key>
            <dict>
                <key>OnDemandEnabled</key>
                <integer>1</integer>
                <key>OnDemandUserOverrideDisabled</key>
                <integer>1</integer>
                <key>OnDemandRules</key>
                <array>
                    <dict>
                        <key>Action</key>
                        <string>EvaluateConnection</string>
                        <key>ActionParameters</key>
                        <array>
                            <dict>
                                <key>DomainAction</key>
                                <string>ConnectIfNeeded</string>
                                <key>Domains</key>
                                <array>
                                    <string>.hogehoge.com</string>
                                    <string>.hoeghoge.co.jp</string>
                                </array>
                                <key>RequiredDNSServers</key>
                                <array>
                                    <string>10.1.1.2</string>
                                    <string>10.1.1.3</string>
                                </array>
                            </dict>    
                        </array>
                        <key>InterfaceTypeMatch</key>
                        <string>WiFi</string>
                    </dict>
                </array>

所感

基本、Wi-FiSSIDで絞るのが楽な感じ EvaluateConnectionとか使用すると設定考えるのめんどーになるし、DNSサーバの準備とか必要

参考

VPN.IKEv2 | Apple Developer Documentation

IKEv2 VPNサーバーにiPhone (iOS)でオンデマンド接続させる方法 - Qiita