我正在嘗試運行一個 Strongswan VPN 伺服器,以便使用其內建 VPN 功能與 Windows-10 用戶端一起使用(以方便客戶端用戶使用)
每當嘗試連線時,Windows 都會顯示使用者/密碼已被接受,然後“連接”,然後失敗。伺服器日誌顯示錯誤「逾時後正在刪除半開啟的 IDE_SA ...」。
“sudo systemctl status Strongswan.service”的輸出,最後 10 行日誌:
strongswan.service - strongSwan IPsec IKEv1/IKEv2 daemon using ipsec.conf
Loaded: loaded (/lib/systemd/system/strongswan.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-12-04 13:15:05 GMT; 1min 38s ago
Main PID: 1859 (starter)
Tasks: 18 (limit: 4915)
CGroup: /system.slice/strongswan.service
ââ1859 /usr/lib/ipsec/starter --daemon charon --nofork
ââ1873 /usr/lib/ipsec/charon
Dec 04 13:15:34 raspberrypi ipsec[1859]: 09[IKE] authentication of 'CN=vpn.example.com' (myself) with RSA signature successful
Dec 04 13:15:34 raspberrypi ipsec[1859]: 09[IKE] sending end entity cert "CN=vpn.example.com"
Dec 04 13:15:34 raspberrypi ipsec[1859]: 09[ENC] generating IKE_AUTH response 1 [ IDr CERT AUTH EAP/REQ/ID ]
Dec 04 13:15:34 raspberrypi ipsec[1859]: 09[ENC] splitting IKE message (1948 bytes) into 2 fragments
Dec 04 13:15:34 raspberrypi ipsec[1859]: 09[ENC] generating IKE_AUTH response 1 [ EF(1/2) ]
Dec 04 13:15:34 raspberrypi ipsec[1859]: 09[ENC] generating IKE_AUTH response 1 [ EF(2/2) ]
Dec 04 13:15:34 raspberrypi ipsec[1859]: 09[NET] sending packet: from 192.168.2.9[4500] to 109.41.64.240[6977] (1248 bytes)
Dec 04 13:15:34 raspberrypi ipsec[1859]: 09[NET] sending packet: from 192.168.2.9[4500] to 109.41.64.240[6977] (768 bytes)
Dec 04 13:15:34 raspberrypi charon[1873]: 14[IKE] sending keep alive to 109.41.64.240[6977]
Dec 04 13:15:43 raspberrypi charon[1873]: 15[JOB] deleting half open IKE_SA with 109.41.64.240 after timeout
在一些關於 Strongswan 和 Windows 的帖子中來回擺弄,我找不到任何錯誤。現在重新處理這個問題,因為 systemctl restart 似乎沒有再解析配置?無論我改變什麼,我都會得到相同的輸出。停止和啟動似乎有幫助。
(目前正在本地網路中嘗試此操作,因此所有 IP 都在 192.168.* 中。VPN 範圍應該是 172.17.0.0/16
/etc/ipsec.conf 是這樣的:
# ipsec.conf - strongSwan IPsec configuration file
config setup
strictcrlpolicy=no
uniqueids=never
# Add connections here.
# Sample VPN connections
conn %default
keyexchange=ikev2
ike=aes256-sha1-modp1024!
esp=aes256-sha1!
dpdaction=clear
rekey=no
dpddelay=300s
fragmentation=yes
conn win7
compress=no
type=tunnel
left=%any
# leftid=192.168.2.9
leftcert=server.cert.pem
leftsendcert=always
leftsubnet=0.0.0.0/0
leftsendcert=always
right=%any
rightip=%any
rightauth=eap-mschapv2
rightsourceip=172.17.0.128/25
rightdns=192.168.2.1
rightsendcert=never
# eap_identity=%identity
eap_identity=%any
auto=add
include /var/lib/strongswan/ipsec.conf.inc
在Windows 10(家庭)中,我選擇連線名稱“測試”,伺服器位址192.168.2.9,VPN類型“自動”,登入類型“使用者名稱和密碼”。
檔案 /etc/ipsec.secrets 有一個名為 'user' 的使用者: # 該檔案保存共用機密或用於驗證的 RSA 私鑰。
# RSA private key for this host, authenticating it to any other host
# which knows the public part.
# this file is managed with debconf and will contain the automatically created private key
#include /var/lib/strongswan/ipsec.secrets.inc
: RSA "server.key.pem"
user : EAP "testpassword_preliminary"
我使用以下命令列在伺服器上產生了證書:
ipsec pki --gen --size 4096 --type rsa --outform pem > ca.key.pem
ipsec pki --self --in ca.key.pem --type rsa --dn "CN=VPN Server CA" --ca --lifetime 3650 --outform pem > ca.cert.pem
ipsec pki --gen --size 4096 --type rsa --outform pem > server.key.pem
ipsec pki --pub --in server.key.pem --type rsa | ipsec pki --issue --lifetime 2750 --cacert ca.cert.pem --cakey ca.key.pem --dn "CN=vpn.example.com" --san="vpn.example.com" --flag serverAuth --flag ikeIntermediate --outform pem > server.cert.pem