【初めてのiPhone】プロキシサーバを使うAPNの設定方法
iPhoneの4G接続でプロキシサーバを使用する方法を記載しています。
今回は通常時にプロキシサーバを使わず、VPN接続した時だけプロキシサーバを使う方法です。
VPNのプロファイルの中には、プロキシ使用の有無を設定する箇所があり、これを使用すると、若干条件はありますがVPN接続時にプロキシサーバを経由するようになります。
この記事では、既にプロキシサーバとVPN接続環境を整えている前提での話となります。
iPhoneがVPN接続状態でプロキシを使用する条件
iPhoneでVPN経由のプロキシサーバを使うには、以下の設定を行う必要があります。- VPNサーバ側でスプリットトンネリングを行わない設定にする(インターネットへの通信を全てVPN経由にする)
- iPhoneのVPNプロファイル内でプロキシサーバを指定する(proxy.pacも可)
VPN接続時に全ての通信をVPN側に流したくない事があるかもしれないためです。(であればVPNを切断すれば良いかもしれませんが…)
strongSwanの設定
strongSwanでは、以下の接続設定を作成します。(設定ファイル上は、conn ~の部分)- インターネットへの通信に対して、VPNを経由する接続設定
- インターネットへの通信にはVPNを経由せず、ローカルネットワークのみVPNを通る接続設定(スプリットトンネリング)
このようにするのは、MS-CHAPv2を2種類作成しても、ユーザ認証が始まる前にconnが決まってしまうため、インターネットへの通信に対してVPN経由する/しないの設定(leftsubnet:トラフィックセレクタ)を任意に選ぶことが出来きないためです。
以下では、プロキシを使わない設定をleftsubnet=192.168.0.0/24、プロキシを使う設定をleftsubnet=0.0.0.0/0としています。
/etc/ipsec.conf
conn %default
left=%defaultroute
leftcert=server.pem
leftid=vpn.example.com
leftsendcert=always
right=%any
rightsourceip=192.168.255.0/24
keyexchange=ikev2
auto=add
dpdaction=clear
dpddelay=300s
rekey=no
ike=aes256-sha256-modp2048!
esp=aes256-sha256!
conn certificate-for-non-proxy
leftsubnet=192.168.0.0/24
rightid="username2"
conn mschapv2-for-proxy
leftsubnet=0.0.0.0/0
leftauth=pubkey
rightauth=eap-mschapv2
eap_identity="username"
/etc/ipsec.secrets
: RSA server-private.key username: EAP "password"
iPhoneのプロファイル
iPhoneのプロファイルでは、com.example.vpn.conf1とcom.example.vpn.conf2の2種類の接続設定を作成し、認証方式とプロキシ使用有無を書き分けています。<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadDisplayName</key>
<string>Strongswan</string>
<key>PayloadIdentifier</key>
<string>com.example.vpn</string>
<key>PayloadUUID</key>
<string>9f93912b-5fd2-4455-99fd-13b9a47b4581</string>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadIdentifier</key>
<string>com.example.vpn.conf1</string>
<key>PayloadUUID</key>
<string>29e4456d-3f03-4f15-b46f-4225d89465b7</string>
<key>PayloadType</key>
<string>com.apple.vpn.managed</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>UserDefinedName</key>
<string>Machine Ceritificate no proxy</string>
<key>VPNType</key>
<string>IKEv2</string>
<key>IKEv2</key>
<dict>
<key>RemoteAddress</key>
<string>vpn.example.com</string>
<key>RemoteIdentifier</key>
<string>vpn.example.com</string>
<key>LocalIdentifier</key>
<string>username2</string>
<key>ServerCertificateIssuerCommonName</key>
<string>vpn.example.com</string>
<key>ServerCertificateCommonName</key>
<string>vpn.example.com</string>
<key>AuthenticationMethod</key>
<string>Certificate</string>
<key>ExtendedAuthEnabled</key>
<integer>0</integer>
<key>PayloadCertificateUUID</key>
<string>d60488c6-328e-4944-9c8d-61db8095c864</string>
<key>IKESecurityAssociationParameters</key>
<dict>
<key>EncryptionAlgorithm</key>
<string>AES-256</string>
<key>IntegrityAlgorithm</key>
<string>SHA2-256</string>
<key>DiffieHellmanGroup</key>
<integer>14</integer>
</dict>
<key>ChildSecurityAssociationParameters</key>
<dict>
<key>EncryptionAlgorithm</key>
<string>AES-256</string>
<key>IntegrityAlgorithm</key>
<string>SHA2-256</string>
<key>DiffieHellmanGroup</key>
<integer>14</integer>
</dict>
</dict>
</dict>
<dict>
<key>PayloadIdentifier</key>
<string>com.example.vpn.conf2</string>
<key>PayloadUUID</key>
<string>29e4456d-3f03-4f15-b46f-4225d89465b8</string>
<key>PayloadType</key>
<string>com.apple.vpn.managed</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>Proxies</key>
<dict>
<key>HTTPEnable</key>
<integer>1</integer>
<key>HTTPSEnable</key>
<integer>1</integer>
<key>HTTPProxy</key>
<string>vpn.example.com</string>
<key>HTTPPort</key>
<integer>8080</integer>
<key>HTTPSProxy</key>
<string>vpn.example.com</string>
<key>HTTPSPort</key>
<integer>8080</integer>
</dict>
<key>UserDefinedName</key>
<string>EAP-MSCHAPv2 with Proxy</string>
<key>VPNType</key>
<string>IKEv2</string>
<key>IKEv2</key>
<dict>
<key>RemoteAddress</key>
<string>vpn.example.com</string>
<key>RemoteIdentifier</key>
<string>vpn.example.com</string>
<key>LocalIdentifier</key>
<string></string>
<key>ServerCertificateIssuerCommonName</key>
<string>vpn.example.com</string>
<key>ServerCertificateCommonName</key>
<string>vpn.example.com</string>
<key>AuthenticationMethod</key>
<string>None</string>
<key>ExtendedAuthEnabled</key>
<integer>1</integer>
<key>AuthName</key>
<string>username</string>
<key>AuthPassword</key>
<string>password</string>
<key>IKESecurityAssociationParameters</key>
<dict>
<key>EncryptionAlgorithm</key>
<string>AES-256</string>
<key>IntegrityAlgorithm</key>
<string>SHA2-256</string>
<key>DiffieHellmanGroup</key>
<integer>14</integer>
</dict>
<key>ChildSecurityAssociationParameters</key>
<dict>
<key>EncryptionAlgorithm</key>
<string>AES-256</string>
<key>IntegrityAlgorithm</key>
<string>SHA2-256</string>
<key>DiffieHellmanGroup</key>
<integer>14</integer>
</dict>
</dict>
</dict>
<dict>
<key>PayloadIdentifier</key>
<string>com.example.vpn.username2</string>
<key>PayloadUUID</key>
<string>d60488c6-328e-4944-9c8d-61db8095c864</string>
<key>PayloadType</key>
<string>com.apple.security.pkcs12</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadContent</key>
<data>
MII*************************************************************
(省略)
****************************************
</data>
</dict>
<dict>
<key>PayloadIdentifier</key>
<string>com.example.vpn</string>
<key>PayloadUUID</key>
<string>64988b2c-33e0-4adf-a432-6fbcae543408</string>
<key>PayloadType</key>
<string>com.apple.security.pem</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadContent</key>
<data>
MII*************************************************************
(省略)
****************************************
</data>
</dict>
</array>
</dict>
</plist>
証明書の書き方はこちらで書いています。 iPhoneで strongSwan (IPsec VPN) に接続する (Machine Certificates)
iPhoneでstrongSwanに証明書で接続する設定を記載しています。
<key>Proxies</key>
<dict>
<key>HTTPEnable</key>
<integer>0</integer>
<key>HTTPSEnable</key>
<integer>0</integer>
<key>ProxyAutoConfigEnable</key>
<true/>
<key>ProxyAutoConfigURLString</key>
<string>http://vpn.example.com/local/proxy.pac</string>
</dict>
このプロファイルをインストールすると以下のように表示が変わり、どちらのVPN接続設定を使うか選べるようになります。




