ipsec note

1. 常用的命令:

 ipsec start/stop/restart 

当修改了ipsec.conf文件后,要执行ipsec update or ipsec reload  or ipsec restart

ipsec up name

ipsec statusall

 

ipsec的配置文件: /etc/ipsec.conf

         /etc/ipsec.secrets

 strongswan的配置文件: /etc/strongswan.conf

 

日志文件: /var/log/syslog   or grep charon /var/log/*

 

参考:

 https://www.bggofurther.com/2015/02/how-to-setup-an-ipsec-tunnel-with-strongswan-with-high-availability-on-linux/

 

https://www.strongswan.org/

 

https://wiki.strongswan.org/projects/strongswan/wiki/IntroductionTostrongSwan

 

2. Authentication Methods

· Public Key Authentication: This uses RSA or ECDSA X.509 certificates to verify the authenticity of the peer. Certificates can be self-signed, in which case they have to be installed on all peers, or signed by a common Certificate Authority (CA). 

· Pre-Shared-Key (PSK): A pre-shared-key is an easy to deploy option but it requires strong secrets to be secure. This method is not recommended for large scale
deployments.

· Extensible Authentication Protocol (EAP): This covers several possible authentication methods, some are based on username/password authentication (EAP-MD5, EAP-MSCHAPv2, EAP-GTC) or on certificates (EAP-TLS),some can even tunnel other EAP methods (EAP-TTLS, EAP-PEAP).The actual authentication of users may be delegated to a RADIUS server with the eap-radius plugin.

· eXtended Authentication (XAuth): XAuth provides a flexible authentication framework within IKEv1. It is mainly used for username/password based authentication. Also, it is generally used as a second authentication method after a mutual authentication with either certificates or PSK. With IKEv1 hybrid authentication is is, however,possible to authenticate the gateway with a certificate and use only XAuth to authenticate the client.

 

3. Certificate Format

Different platforms and devices require different certificate format.

· PEM Format

The most common format, usually have extensions such as .pem,.crt,.cer .key. They are Base64 encoded ASCII files and contain "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" statements.

· DER Format

The DER format is a binary form of a certificate. It has a file extension of .der or .cer.  The only way to tell the difference between a DER .cer file and a PEM .cer file is to open it in a text editor and look for the BEGIN/END statements. 

· PKCS#7/P7B Format

Base64 ASCII format, file extention of .p7b or .p7c.  A P7B file only contains certificates and chain certificates, not the private key. Several platforms support P7B files including Microsoft Windows and Java Tomcat.

· PKCS#12/PFX Format

A binary format for storing the server certificate, any intermediate certificates, and the private key in one encryptable file. PFX files usually have extensions such as .pfx and .p12. PFX files are typically used on Windows machines AND android device to import and export certificates and private keys.

Transform: Using openssl command. Private Key DER file connot transform to PEM file, and only PEM file can transform to PKCS#12 file. 

https://www.sslshopper.com/ssl-converter.html

4. Certificate generation

Example:

echo  "Generating caKey.pem..."  

ipsec pki --gen --outform pem > caKey.pem

ipsec pki --self --in caKey.pem --dn "C=CH, O=CND, CN=CND CA" --ca --outform pem --san="192.168.6.21" > caCert.pem 

 

echo "Generating peerKey.pem..."

ipsec pki --gen --outform pem > peerKey.pem

echo "Generating peerCert.pem..."

ipsec pki --pub --in peerKey.pem | ipsec pki --issue --cacert caCert.pem --cakey caKey.pem --dn "C=CH, O=CND, CN=peer" --san="192.168.6.21" --outform pem > peerCert.pem

openssl pkcs12 -export -inkey peerKey.pem -in peerCert.pem -name "client_epdg" -certfile caCert.pem -caname "server_epdg" -out peerCert.p12

 

(1) 生成一个私钥

(2) 基于这个私钥自己签一个CA证书  

--self 表示自签证书,--in 是输入的私钥,--dn 是判别名,--ca 表示生成 CA

· C 表示国家名,同样还有 ST 州/省名,L 地区名,STREET(全大写) 街道名。

· O 表示组织名。

· CN 为通用名。

--pub  从生成的私钥里把公钥提取出来,然后用公钥去参与后面的服务器证书签发

--dn, --san--flag 是一些客户端方面的特殊要求:

Android 和 iOS 都要求服务器别名(serverAltName)就是服务器的 URL 或 IP 地址,--san。

5. Certificate Installation

Server: /etc/ipsec.d/certs/caCert.pem       /etc/ipsec.d/private/caKey.pem

Client: /etc/ipsec.d/certs/peerCert.pem   /etc/ipsec.d/private/peerKey.pem

Android:  peerCert.p12  caCert.pem     peerCert.pem

6. Configuration Files

ipsec.conf:

conn %default

ikelifetime=60m

keylife=20m

rekeymargin=3m

keyingtries=1

keyexchange=ikev2

 

conn eap

left=192.168.6.21

leftsubnet=0.0.0.0/0

leftid=@epdg.epc.mnc001.mcc001.pub.3gppnetwork.org

leftcert=caCert.pem

rightauth=pubkey

rightcert=peerCert.pem

rightsourceip=%dhcp

right=%any

auto=add

 

 

· left/right   是左右 id,它们用来识别服务器/客户端,可以是证书的判别名(DN)、IP 地址或也可以是 EAP 的用户名,还可以是魔术字 %any,  %defaultroute 表示从 default interface里取 IP。

· leftauth/rightauth  参数主要有 pubkey 表示用证书,psk 表示用密码,eap 表示用扩展验证协议。

• leftsubnet引入了魔术字 0.0.0.0/0。如果在右侧为客户端分配虚拟 IP 地址之后要做 iptables 转发,那么左边就必须是用魔术字。

• leftcert/rightcert 就是指定证书名字。

• rightsourceip 为客户端分配的虚拟 IP 段。

• auto 定义 strongswan 启动时该连接的行为。start 是启动; route 是添加路由表,有数据通过就启动; add 是添加连接类型但不启动; ignore 是当它不存在。默认是 ignore

 

leftsubnet是决定要通过tunnelip的范围,0.0.0.0/0是代表所有的IP通讯都通过VPN。 rightsourceipVPN分配的虚拟地址的范围,也就是客户端登录后得到的IP范围,例如192.168.1.0/24意味着 192.168.0.1-192.168.1.255VPN客户端可能的地址范围。

 a virtual IP via the IKEv2 configuration payload by using the leftsourceip=%config parameter。

 leftfirewall=yes   automatically inserts iptables-based firewall rules that let pass the tunneled traffic.

 

 

 

 

 







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值