strongswan openswan freeradius討論QQ羣:892427461mysql
Strongswan+freeradius+daloradius+ad認證明現ikev2接入服務
linux
第一部分 Centos7 strongswan安裝配置支持 Windows7 ikev2 eap-machapv2模式、計算機證書模式web
實驗時間:2018年8月6日-2018年8月6日sql
拓撲圖:vim
環境:bash
防火牆1:FW1 USG2200服務器
IP地址外網:10.99.101.170 域名:strongswan.test.com
網絡
IP地址內網:192.168.20.3
app
防火牆2:FW2 USG2200ide
IP地址外網:10.99.101.129 域名:mystrongswan.test.com
IP地址內網:192.168.20.2
防火牆5:FW5 USG2200
IP地址外網:10.99.101.167
IP地址內網:131.107.0.1
服務器:
域控服務器:
Windows Server2016
IP地址:192.168.20.10 域名:dc.test.com
strongswan服務器:
Centos7
IP地址:192.168.20.29
Strongswan-5.6.3
freeradius服務器:
Centos7
IP地址:192.168.20.27
freeradius-4.0.0
客戶端:Windows7
自帶客戶端 epa-mschapv2模式 、 計算機證書模式
第一部分 Centos7 strongswan安裝配置支持 Windows7 ikev2 eap-machapv2模式、計算機證書模式
實驗時間:2018年8月6日-2018年8月6日
一、 CentOS 7 最小安裝,隨意,其餘也能夠。
設置IP地址
cd /etc/sysconfig/network-scripts
vi ifcfg-ens32
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.20.29
NETMASK=255.255.255.0
GATEWAY=192.168.20.2
DNS1=192.168.20.10
reboot
二、 安裝vim,可選步驟,不安裝也能夠。
yum install -y vim
三、 安裝完後升級系統,可選步驟,不升級也能夠。
yum -y upgrade
升級全部包,不改變軟件設置和系統設置,系統版本升級,內核不改變
yum -y update
升級全部包,改變軟件設置和系統設置,系統版本內核都升級
四、 關閉selinux
vim /etc/sysconfig/selinux
SELINUX=disabled
reboot sestatus
SELinux status: disabled
五、 安裝strongswan
yum -y install epel-release yum -y install strongswan
strongswan的配置文件在/etc/strongswan/
查看版本
strongswan version
Linux strongSwan U5.6.3/K3.10.0-862.9.1.el7.x86_64
Institute for Internet Technologies and Applications
University of Applied Sciences Rapperswil, Switzerland
See 'strongswan --copyright' for copyright information.
六、 製做證書
(1)strongswan官方對Windows 7 客戶端對證書的要求的說明:
連接:https://wiki.strongswan.org/projects/strongswan/wiki/Win7CertReq
關於strongswan pki 的官方說明看下面的連接:
https://wiki.strongswan.org/projects/strongswan/wiki/IpsecPKI
(2)建一個目錄保存要生成的證書,在哪建都行:
mkdir /etc/strongswan/ca cd /etc/strongswan/ca
(3)生成一個私鑰用做CA根證書的私鑰,文件名爲YIMIDECA.key.pem,文件名能夠本身隨便改。
strongswan pki --gen -- outform pem > YIMIDECA.key.pem
(4)自簽名形式生成CA根證書
strongswan pki --self --in YIMIDECA.key.pem --dn "C=CN, O=YIMIDEZUZHI, CN=YIMIDE CA" --ca --lifetime 3650 --outform pem > YIMIDECA.cert.pem
C=CN 國家代碼,填CN 跟其餘證書的C要一致
O=YIMIDEZUZHI 組織代碼,本身隨便填的,1米的組織 跟其餘證書的O要一致
CN=YIMIDE CA 本身隨便填。
(5)生成一個私鑰用做strongswan服務器的私鑰,文件名爲YIMIDESERVER.key.pem
strongswan pki --gen -- outform pem > YIMIDESERVER.key.pem
從這個私鑰文件YIMIDESERVER.key.pem中提取公鑰,文件名爲YIMIDESERVER.pub.pem
strongswan pki --pub --in YIMIDESERVER.key.pem --outform pem > YIMIDESERVER.pub.pem
用提取的公鑰文件YIMIDESERVER.pub.pem和剛纔生成的CA證書YIMIDECA.cert.pem簽發一個服務器證書,文件名爲YIMIDESERVER.cert.pem
strongswan pki --issue --lifetime 1200 --cacert YIMIDECA.cert.pem --cakey YIMIDECA.key.pem --in YIMIDESERVER.pub.pem --dn "C=CN, O=YIMIDEZUZHI, CN= strongswan.test.com" --san "dns:192.168.20.29" --san "dns:10.99.101.170" --san "dns:10.99.101.129" --san "strongswan.test.com" --san "mystrongswan.test.com" --flag serverAuth --flag ikeIntermediate --outform pem > YIMIDESERVER.cert.pem
C=CN 國家代碼,我沒試亂填會怎樣,老實填CN 跟其餘證書的C要一致
O=YIMIDEZUZHI 組織代碼,本身隨便填的,一米的組織 跟其餘證書的O要一致
CN=strongswan.test.com 這個填strongswan服務器的域名
--san "dns:192.168.20.29" --san "dns:10.99.101.170" --san "dns:10.99.101.129" --san "strongswan.test.com" --san "mystrongswan.test.com"這個填strongswan服務器的ip和域名。
--san --flag 的設置仍是看這個:
strongswan官方對Windows 7 客戶端對證書的要求的說明:
連接:https://wiki.strongswan.org/projects/strongswan/wiki/Win7CertReq
(6)生成一個私鑰用做客戶端的私鑰,文件名爲YIMIDECLIENT.key.pem
strongswan pki --gen --outform pem > YIMIDECLIENT.key.pem
從這個私鑰文件YIMIDECLIENT.key.pem中提取公鑰,文件名爲YIMIDECLIENT.pub.pem
strongswan pki --pub --in YIMIDECLIENT.key.pem --outform pem > YIMIDECLIENT.pub.pem
用提取的公鑰文件YIMIDECLIENT.pub.pem和剛纔生成的CA證書YIMIDECA.cert.pem簽發一個服務器證書,文件名爲YIMIDECLIENT.cert.pem
strongswan pki --issue --lifetime 1200 --cacert YIMIDECA.cert.pem --cakey YIMIDECA.key.pem --in YIMIDECLIENT.pub.pem --dn "C=CN, O=YIMIDEZUZHI, CN=YIMIDECLIENT" --outform pem > YIMIDECLIENT.cert.pem
C=CN 國家代碼,填CN 跟其餘證書的C要一致
O=YIMIDEZUZHI 組織代碼,本身隨便填的,一米的組織 跟其餘證書的O要一致
CN=YIMIDECLIENT 這個本身起名。
生成一個pkcs12格式的證書,把證書導入到客戶端時使用。
openssl pkcs12 -export -inkey YIMIDECLIENT.key.pem -in YIMIDECLIENT.cert.pem -name "YIMIDECLIENT" -certfile YIMIDECA.cert.pem -caname "YIMIDE CA" -out YIMIDECLIENT.cert.p12
這條命令會要求輸入兩次證書密碼,用於導入計算機時填入。
證書製做完畢!!!!!!!!!!
如今這個文件夾有9個文件:
YIMIDECA.key.pem
YIMIDECA.cert.pem
YIMIDESERVER.key.pem
YIMIDESERVER.pub.pem
YIMIDESERVER.cert.pem
YIMIDECLIENT.key.pem
YIMIDECLIENT.pub.pem
YIMIDECLIENT.cert.pem
YIMIDECLIENT.cert.p12
爲strongswan服務器安裝證書,就是將證書複製到規定的目錄
cp -r YIMIDECA.cert.pem /etc/strongswan/ipsec.d/cacerts/ cp -r YIMIDESERVER.cert.pem /etc/strongswan/ipsec.d/certs/ cp -r YIMIDECLIENT.cert.pem /etc/strongswan/ipsec.d/certs/ cp -r YIMIDECA.key.pem /etc/strongswan/ipsec.d/private/ cp -r YIMIDESERVER.key.pem /etc/strongswan/ipsec.d/private/ cp -r YIMIDECLIENT.key.pem /etc/strongswan/ipsec.d/private/
七、 編輯strongswan配置文件,共三個/etc/strongswan/ipsec.conf、/etc/strongswan/strongswan.conf、/etc/strongswan/ipsec.secrets
vim /etc/strongswan/ipsec.conf
config setup
uniqueids=never #關閉ID惟一性,即容許多個客戶端使用同一個證書,多設備同時在線
conn %default #默認配置項,其餘conn配置項都會調用此默認項
left=%any #left表示local,即本地端(服務器端)IP地址;%any是魔數字,表示任意地址
leftsubnet=0.0.0.0/0 #本地端網絡,0.0.0.0/0爲通配,表示全部IP網段
right=%any #right表示remote,即遠程端(客戶端)IP地址可爲任意地址
rightsourceip=192.168.20.0/24 #分配給遠程端的虛擬IP地址段,儘可能避免使用經常使用私網地址段以避免衝突
dpdaction=clear #dpd表示Dead Peer Detection,對端失效檢測,clear表示對端失效時關閉鏈接
ike=aes128-sha1-modp1024,aes128-sha1-modp1536,aes128-sha1-modp2048,aes128-sha256-ecp256,aes128-sha256-modp1024,aes128-sha256-modp1536,aes128-sha256-modp2048,aes256-aes128-sha256-sha1-modp2048-modp4096-modp1024,aes256-sha1-modp1024,aes256-sha256-modp1024,aes256-sha256-modp1536,aes256-sha256-modp2048,aes256-sha256-modp4096,aes256-sha384-ecp384,aes256-sha384-modp1024,aes256-sha384-modp1536,aes256-sha384-modp2048,aes256-sha384-modp4096,aes256gcm16-aes256gcm12-aes128gcm16-aes128gcm12-sha256-sha1-modp2048-modp4096-modp1024,3des-sha1-modp1024!
esp=aes128-aes256-sha1-sha256-modp2048-modp4096-modp1024,aes128-sha1,aes128-sha1-modp1024,aes128-sha1-modp1536,aes128-sha1-modp2048,aes128-sha256,aes128-sha256-ecp256,aes128-sha256-modp1024,aes128-sha256-modp1536,aes128-sha256-modp2048,aes128gcm12-aes128gcm16-aes256gcm12-aes256gcm16-modp2048-modp4096-modp1024,aes128gcm16,aes128gcm16-ecp256,aes256-sha1,aes256-sha256,aes256-sha256-modp1024,aes256-sha256-modp1536,aes256-sha256-modp2048,aes256-sha256-modp4096,aes256-sha384,aes256-sha384-ecp384,aes256-sha384-modp1024,aes256-sha384-modp1536,aes256-sha384-modp2048,aes256-sha384-modp4096,aes256gcm16,aes256gcm16-ecp384,3des-sha1!
conn IKEv1-CERT-XAUTH #供老版本IOS使用。IKEv1,使用證書和XAUTH驗證
keyexchange=ikev1 #密鑰交換使用IKEv1
fragmentation=yes #容許分片
leftauth=pubkey #本地端使用公鑰驗證
leftcert= YIMIDESERVER.cert.pem #指定本地端證書
rightauth=pubkey #遠程端使用公鑰驗證
rightauth2=xauth #遠程端使用用戶帳號驗證
rightcert=YIMIDECLIENT.cert.pem #指定遠程端證書
auto=add #auto定義strongSwan服務啓動時該鏈接的行爲,add是添加鏈接類型但不啓動
conn IKEv1-PSK-XAUTH #供IOS, Android使用。IKEv1,使用預共享密鑰和XAUTH驗證
keyexchange=ikev1 #密鑰交換使用IKEv1
leftauth=psk #本地端使用預共享密鑰驗證
rightauth=psk #遠程端使用預共享密鑰驗證
rightauth2=xauth #遠程端使用用戶帳號驗證
auto=add #strongSwan啓動時添加鏈接類型但不啓動
conn IKEv2-CERT #供Windows 7+, Linux使用。IKEv2,使用證書驗證
keyexchange=ikev2 #密鑰交換使用IKEv2
leftauth=pubkey #本地端使用公鑰驗證
leftcert= YIMIDESERVER.cert.pem #指定本地端證書
leftfirewall=yes #添加防火牆規則
rightauth=pubkey #遠程端使用公鑰驗證
rightcert= YIMIDECLIENT.cert.pem #指定遠程端證書
auto=add #strongSwan啓動時添加鏈接類型但不啓動
conn IKEv2-EAP #供Windows 7+, IOS9+使用。IKEv2,EAP驗證
keyexchange=ikev2 #密鑰交換使用IKEv2
ike=aes256-sha256-modp1024,3des-sha1-modp1024,aes256-sha1-modp1024! #第一階段加密方式
esp=aes256-sha256,3des-sha1,aes256-sha1! #ESP的順序與IKE一致
rekey=no #本地端對Windows遠程端發出rekey請求會斷開鏈接,因此需配置爲no
leftfirewall=yes #添加防火牆規則
leftauth=pubkey #本地端使用公鑰驗證
leftcert=YIMIDESERVER.cert.pem #指定本地端證書
leftsendcert=always #本地端老是發送證書
leftid=@strongswan.test.com #本地端標識,使用本地端公網IP地址做爲標識,和生成服務器證書時的--san參數對應
rightauth=eap-mschapv2 #遠程端使用eap-mschapv2驗證
rightsendcert=never #不要求遠程端發送證書
rightsourceip=%dhcp #使用dhcp獲取ip
eap_identity=%any #指定EAP驗證身份,任意帳戶
fragmentation=yes #容許分片
auto=add #strongSwan啓動時添加鏈接類型但不啓動
vim /etc/strongswan/strongswan.conf
charon{
filelog {
/var/log/strongswan.charon.log {
time_format = %b %e %T
default = 2
append = no
flush_line = yes
}
}
load_modular = yes
duplicheck.enble = no
compress = yes
plugins {
include strongswan.d/charon/*.conf
}
dns1 = 192.168.20.10
nbns1 = 192.168.20.10
nbns2 = 192.168.20.100
}
include strongswan.d/*.conf
vim /etc/strongswan/ipsec.secrets
: RSA YIMIDESERVER.key.pem
: PSK "psk123456"
: XAUTH "xauth123456"
eapuser : EAP "eap123456"
八、 firewalld防火牆配置
打開防火牆端口
firewall-cmd --permanent --add-port=500/udp firewall-cmd --permanent --add-port=4500/udp firewall-cmd --reload
容許esp ah 協議
firewall-cmd --permanent --add-rich-rule='rule protocol value="esp" accept' firewall-cmd --permanent --add-rich-rule='rule protocol value="ah" accept' firewall-cmd --reload
開啓內核轉發
編輯 /etc/systcl.conf
vim /etc/sysctl.conf
net.ipv6.conf.all.forwarding=1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects=0
九、 啓動服務
systemctl enable strongswan systemctl start strongswan systemctl status strongswan
查看加載的CA證書
strongswan listcacerts
顯示:
List of X.509 CA Certificates
subject: "C=CN, O=YIMIDEZUZHI, CN=YIMIDE CA"
issuer: "C=CN, O=YIMIDEZUZHI, CN=YIMIDE CA"
validity: not before Jul 24 16:05:12 2018, ok
not after Jul 21 16:05:12 2028, ok (expires in 3649 days)
serial: 07:f8:c4:ad:18:64:7d:4c
flags: CA CRLSign self-signed
subjkeyId: ff:e1:cb:fc:c0:91:37:c7:cd:6e:66:f6:40:f0:77:a1:5d:d2:fa:a4
pubkey: RSA 2048 bits
keyid: 78:93:01:ae:43:76:f1:b3:ed:6a:58:1e:73:23:ae:b1:09:ce:52:b5
subjkey: ff:e1:cb:fc:c0:91:37:c7:cd:6e:66:f6:40:f0:77:a1:5d:d2:fa:a4
十、 設置USG2200端口映射
添加轉發策略:
untrust > truse any 192.168.20.29/32 udp permit
添加目的NAT
udp 500 4500
添加源NAT untrust > trust any 192.168.20.29/32 NAT轉換 內網接口地址
十一、爲Windows 7安裝客戶端證書
想辦法把客戶端證書文件YIMIDECLIENT.cert.p12複製到Windows 7 客戶端計算機
運行mmc 文件-->添加/刪除管理單元-->證書-->計算機帳戶
證書安裝完畢!!!!!!!!!!!!!!!!!!!
十一、 第一種連接--創建使用證書驗證的鏈接:
目的地址使用創建YIMIDESERVER.cert.pem 時使用的 --san 參數 strongswan.test.com mystrongswan.test.com 10.99.101.129 10.99.101.170 各創建一個,進行測試
鏈接成功後狀態:
十二、 第二種連接--創建使用證書+密碼驗證的鏈接EAP-MSCHAP v2 :
用戶密碼使用ipsec.secret 中的 eapuser 密碼 eap123456
鏈接成功後狀態:
Strongswan+freeradius+daloradius+ad認證明現ikev2接入服務
第一部分 Centos7 strongswan安裝配置支持 Windows7 ikev2 eap-machapv2模式、計算機證書模式
配置結束
第一部分 Centos7 strongswan安裝配置支持 Windows7 ikev2 eap-machapv2模式、計算機證書模式
第二部分 安裝配置freeradius-4.0.0 samba 使用winbind 集成Windiows Active Directory 域帳戶認證並實現用戶組認證
第三部分 集成Strongswan+freeradius實現使用域用戶組認證ikev2接入