作者zxvc (眾生都是未來佛)
看板WindowsPhone
標題Re: [分享] CentOS架IKEv2 VPN Server
時間Fri Apr 18 14:31:43 2014
今天又跟WP 8.1 DP的VPN奮戰一個早上,終於搞定如何只用憑證連VPN。
但我覺得好像不太實用XD
今天找到一個關鍵的資訊
Try It Out: Windows Phone 8.1 VPN:
http://technet.microsoft.com/en-us/windows/dn673608
該網頁截圖顯示WP 8.1應該能讀取client憑證。
又WP 8.1支援兩種認證方法(我前一篇用的是方法1.):
1. user name+password: PEAP-MSCHAPv2
2. certificate: EAP-TLS
所以我就修改strongSwan ipsec.conf加入以下兩行:
conn win-eap-tls
rightauth=eap-tls
那8.1 DP讀不到憑證的問題要怎麼解決?
我從該網頁截圖看到他的certificate details的Intended purposes
有Encrypting File System, Secure Email, Client Authentication。
這讓我想起我前一篇用openssl產生server certificate有用extendedKeyUsage
去限制key的用途(預設是任何用途),這是微軟VPN的特色。
所以我猜測client certificate也應該要用extendedKeyUsage去限制。
所以在產生client certificate前,修改openssl.cnf的這兩行:
[ usr_cert ]
extendedKeyUsage = clientAuth,emailProtection,msEFS
subjectAltName=IP:your.vpn.client.ip
clientAuth,emailProtection,msEFS就是我照TechNet那網頁截圖中
client certificate所有的key usages去設定的。其實只設extendedKeyUsage,
你就會發現匯入WP的憑證終於顯示在VPN設定頁面!
但直接連VPN會發現連不上。
後來查到這一篇:
http://comments.gmane.org/gmane.network.vpn.strongswan.user/2484
大意是說,Windows(WP應該也是)會以IP作為identity。
又subjectAltName要跟identity一致,所以要用這行範例去設定:
subjectAltName=IP:your.vpn.client.ip
其中your.vpn.client.ip就是手機的IP!
問題是手機的IP是固定的嗎?手機連到WiFi常用DHCP配IP,
所以即使連到同一WiFi,也不見得每次都用相同IP囧
(3G上網我就不清楚。)不同IP就要不同憑證囧囧
我滿懷疑是我搞錯了。要不然Win/WP的EAP-TLS就只有固定IP的情形比較有用,
動態IP幾乎不能用!?
最後我驗證過WP 8.1 DP確實可以用EAP-TLS的VPN。
※ 引述《zxvc (眾生都是未來佛)》之銘言:
: ※ [本文轉錄自 Linux 看板 #1JJ_PQVc ]
: 作者: zxvc (眾生都是未來佛) 看板: Linux
: 標題: [分享] CentOS架IKEv2 VPN Server
: 時間: Thu Apr 17 23:42:08 2014
: 最近我的手機Windows Phone 8.1 DP支援了IKEv2協定的VPN,
: 所以我就想在CentOS 6.5上架IKEv2的VPN server,使得手機也能連上。
: 我用的VPN server軟體是strongswan。
: 我試了一天才試出來。網路上有些資料,但有的沒講很清楚,只能try and error。
: 以下我就把設定IKEv2 VPN server的指令步驟寫出來,也有寫一些註解(英文),
: 有問題再問我,我有空再回應。
: yum install strongswan openssl
: # Create CA
: ## See:
: http://www.topdog.za.net/2012/08/23/iphone-ipad-mac-osx-ipsec-vpn-with-strongswan-5-on-centos-rhel-6/
: cd /etc/pki/tls/misc
: ## Common Name is arbitray, e.g. My CA.
: ./CA -newca
: echo 00 > /etc/pki/CA/crlnumber
: openssl ca -gencrl -out /etc/pki/CA/crl.pem
: ln -s /etc/pki/CA/cacert.pem /etc/strongswan/ipsec.d/cacerts/
: ln -s /etc/pki/CA/crl.pem /etc/strongswan/ipsec.d/crls/
: # Create the server certificate
: ## Add extendedKeyUsage and subjectAltName lines under [ usr_cert ] in
: openssl.cnf.
: ## See: http://wiki.strongswan.org/projects/strongswan/wiki/Win7CertReq
: ## E.g:
: ## extendedKeyUsage = serverAuth
: ## subjectAltName=IP:your.vpn.server.ip
: ## or subjectAltName=DNS:your.vpn.server.dns
: vim ../openssl.cnf
: ## Common Name must be equal to the IP or the DNS set in subjectAltName!
: ## E.g Common Name is your.vpn.server.ip
: ## Please remeber the password. You will use it later in ipsec.secrets.
: ./CA -newreq
: ./CA -sign
: mv newcert.pem /etc/strongswan/ipsec.d/certs/your.vpn.server.ip.pem
: mv newkey.pem /etc/strongswan/ipsec.d/private/your.vpn.server.ip.key
: ## Add this line to ipsec.secrets:
: ## : RSA your.vpn.server.ip.key "password of your.vpn.server.ip.key"
: vim /etc/strongswan/ipsec.secrets
: ## If you want to use EAP-MSCHAPV2 for a client "jack" and his password
: "passwd",
: ## add this line to ipsec.secrets:
: ## jack : EAP "passwd"
: # Create the client certificate
: ## Uncomment extendedKeyUsage and subjectAltName in openssl.cnf!
: ## Common Name is arbitray, e.g. Client Test.
: ./CA -newreq
: ./CA -sign
: ## Export for Windows.
: openssl pkcs12 -export -in newcert.pem -inkey newkey.pem -certfile /etc/pki/CA/cacert.pem -out client.p12
: # Import the certificate to Windows 7 tutorial:
: ## http://wiki.strongswan.org/projects/strongswan/wiki/Win7Certs
: # NAT
: echo "1" > /proc/sys/net/ipv4/ip_forward
: /sbin/iptables -t nat -A POSTROUTING -s 10.71.132.0/24 -o eth0 -j MASQUERADE
: # Import client.p12 to Windows Phone 8.1 DP.
: ## Import through IE or OneDrive.
: ## Then: go to Windows Phone/Settings/VPN/On/add/Connect using/user
: name+password/fill "jack" and "passwd"/...
: # Example setting files
: --------------------------- ipsec.conf -------------------------
: # basic configuration
: config setup
: # Add connections here.
: conn %default
: keyexchange=ikev2
: ike=aes256-sha1-modp1024!
: esp=aes256-sha1!
: dpdaction=clear
: dpddelay=300s
: rekey=no
: leftfirewall=yes
: left=%any
: leftsubnet=0.0.0.0/0
: leftauth=pubkey
: leftcert=your.vpn.server.ip.pem
: leftid=@your.vpn.server.ip
: right=%any
: rightsourceip=10.71.132.1/24
: auto=add
: conn win-pubkey
: rightauth=pubkey
: eap_identity=%any
: conn win-eap-mschapv2
: rightauth=eap-mschapv2
: rightsendcert=never
: eap_identity=%any
: --------------------------- ipsec.secrets -------------------------
: : RSA your.vpn.server.ip.key "password of your.vpn.server.ip.key"
: jack : EAP "passwd"
: --------------------------- strongswan.conf -------------------------
: charon {
: load_modular = yes
: plugins {
: include strongswan.d/charon/*.conf
: }
: # Set the DNS server.
: dns1 = 8.8.8.8
: #dns2 = x.x.x.x
: }
: include strongswan.d/*.conf
--
楞嚴咒(附注音):
http://sdrv.ms/130iapv
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.115.71.32
※ 文章網址: http://www.ptt.cc/bbs/WindowsPhone/M.1397802708.A.9C7.html
※ 編輯: zxvc (140.115.71.32), 04/18/2014 14:33:06
推 felaray:這文越來越歪了XDDD 04/18 14:34
→ zxvc:我覺得還好啊,主要目的就是研究要讓WP 8.1 VPN能使用的方法 04/18 14:37
→ felaray:我知道呀 :) 不過linux的東西看不懂 (遮臉 04/18 14:53
推 KOBER81:沒有像安卓那種方便連各國VPN的APP可以用嗎? 04/18 15:08
推 BenShiuan:VPN > 新增 > 有「從市集下載SSL VPN app」的連結 04/18 15:11
→ BenShiuan:或許以後可以開發相關的app (?) 04/18 15:11
推 joe7254445:還沒出的樣子 04/18 15:40
→ zxvc:EAP-TLS for WP 8.1 DP的動態IP問題解決了! 04/18 16:40
→ zxvc:strongSwan ipsec.conf如果沒有使用eap-identity參數,WP的確 04/18 16:41
→ zxvc:是以IP為identity。若在我這篇的win-eap-tls加上 04/18 16:42
→ zxvc:eap_identity=%identity 04/18 16:43
→ zxvc:strongSwan就會問WP,它的identity是什麼。從我實驗結果WP應該 04/18 16:44
→ zxvc:是回certificate的subjectAltName,而不再是IP。這時 04/18 16:46
→ zxvc:strongSwan再跟WP要該identity的對應certificate。 04/18 16:50
→ zxvc:...總之WP手機若用EAP-TLS的憑證式驗證,不須要固定IP。 04/18 16:52
→ zxvc:補充一點,strongSwan的ipsec.conf可以設定多個"conn"。但要 04/19 21:45
→ zxvc:注意,strongSwan可能會選錯,它好像無法直接區別WP VPN要用 04/19 21:48
→ zxvc:EAP-TLS還是EAP-MSCHAPv2認證。避免麻煩的話,ipsec.conf不要 04/19 21:53
→ zxvc:有多種認證協定。 04/19 21:54