当前位置:文档之家› ipsec原理介绍

ipsec原理介绍

Ipsec VPN调研总结一、Ipsec原理Ipsec vpn指采用IPSec协议来实现远程接入的一种VPN技术,IPSec全称为Internet Protocol Security,是由Internet Engineering Task Force (IETF) 定义的安全标准框架,用以提供公用和专用网络的端对端加密和验证服务。

Ipsec是一个协议集,包括AH协议、ESP协议、密钥管理协议(IKE协议)和用于网络验证及加密的一些算法。

1、IPSec支持的两种封装模式传输(transport)模式:只是传输层数据被用来计算AH或ESP头,AH或ESP头以及ESP加密的用户数据被放置在原IP包头后面。

隧道(tunnel)模式:用户的整个IP数据包被用来计算AH或ESP头,AH或ESP头以及ESP加密的用户数据被封装在一个新的IP数据包中。

2、数据包结构◆传输模式:不改变原有的IP包头,通常用于主机与主机之间。

◆隧道模式:增加新的IP头,通常用于私网与私网之间通过公网进行通信。

3、场景应用图4、网关到网关交互图5、Ipsec体系结构:6、ipsec中安全算法●源认证用于对对等体的身份确认,具体方法包含:PSK(pre-share key);PK3(public key infrustructure公钥基础设施)数字证书,RSA等,后两种为非对称加密算法。

●数据加密对传输的数据进行加密,确保数据私密性,具体对称加密算法包含:des(data encrypt standard)共有2种密钥长度40bits,56bits,3des密钥长度为56bits的3倍;aes(advanced encrypted standard)AES 加密共有三种形式,分为AES 128(128-bit 长度加密),AES 192(192-bit 长度加密)以及AES 256(256-bit 长度加密)。

●完整性校验对接收的数据进行检查,确保数据没有被篡改,主要使用hash算法(HMAC hashed message authentication code),包含MD5(message digest输出128bit校验结果);SHA-1(secure hash algorithm 1)输出160bits校验结果。

●密钥交换算法安全交换加密数据时使用的密钥,采用DH(Diffie-Hellman)算法,是一种确保共享KEY 安全穿越不安全网络的方法,它是OAKLEY的一个组成部分,分为group1(768位),group2(1024位),group5(1536)等。

二、Ipsec工具编译及使用针对Ipsec-tools、openswan、strongswan三个ipsec工具做编译和实例测试。

1、AR9344原厂SDK编译ipsec-tools和openswan都编译不通、出错,出错原因分析是工具包与内核以相关依赖库都有版本匹配问题。

2、openwrt最新版本编译代码配置菜单中没有ipsec-tools\openswan\strongswan三个VPN的配置选项,还未调查如何添加这三个工具包。

3、openwrt旧版本编译Openwrt固件版本:BARRIER BREAKER (Bleeding Edge, r39028)内核版本:linux-3.10.21●编译结果ipsec-tool 编译通过openswan 编译出错(相关使用的结构体与内核版本不匹配)strongswan 编译通过●内核配置无论使用哪种ipsec工具都需要内核模块ipsec的支持:●Ipsec-tools工具配置选上network->vpn->ipsec-tools配置选项。

●Strongswan 工具配置network->vpn->strongwan相关配置,选上strongswan和strongswan-default两项,其它相关依赖选项会自动选上。

4、测试环境搭建●网络拓扑结构图●网络环境将两台路由GW1和GW2的WAN口直连、LAN口分别直连A和B两台PC。

GW1添加对端子网路由:route add –net 192.168.0.0/24 gw 172.16.113.163GW2添加对端子网路由:route add –net 192.168.1.0/24 gw 172.16.113.173GW1和GW2打开路由转发功能:echo "1" > /proc/sys/net/ipv4/ip_forwardGW1和GW2关闭防火墙和NAT:iptables –F iptables –t nat -F在此环境下A机可以ping通B机。

5、openwrt旧版本测试ipsec功能●Ipsec-tools工具(1)点对点测试:使用传输模式, PC机(linux系统里安装ipsec-tools)与路由器直连测试,配置文件修改后分别在两端主动发起ping包请求。

PC主动发起ping包可以ping通,路由器主动发起ping包不通。

原因:路由端ipsec-tools发协商包时认定网络环境为nat-t,导致使用4500端口用nat-t的功能发送协商包给PC端的500端口、PC端收到无法协商导致不能进行数据传数,查看日志路由端始终一直多次发协商包、而PC端一直多次回应是否是协商包。

将/feeds/packages/net/ipsec-tools/Makefile中configure配置时默认添加了nat-t 功能,注释掉--enable-natt关闭即可,重新编译再测试。

测试结果:去掉nat-t功能后,PC与路由器双方均可主动ping通。

(2)网关到网关测试:使用隧道模式。

A机配置文件:(1)/etc/raccoon/psk.txt内容:172.16.113.163 0x123456(2)/etc/setkey.conf内容:flush;spdflush;spdadd 192.168.0.0/24 192.168.1.0/24 any -P in ipsec esp/tunnel/172.16.113.163-172.16.113.173/require;spdadd 192.168.1.0/24 192.168.0.0/24 any -P out ipsec esp/tunnel/172.16.113.173-172.16.113.163/require;(3)/etc/racoon/racoon内容:path include "/etc/racoon";path pre_shared_key "/etc/racoon/psk.txt";path certificate "/etc/cert";padding {maximum_length 20;randomize off;strict_check off;exclusive_tail off;}timer {counter 5;interval 20 sec;persend 1;phase1 30 sec;phase2 15 sec;}remote anonymous {exchange_mode main;proposal {encryption_algorithm aes 128;hash_algorithm sha1;authentication_method pre_shared_key;dh_group 2;lifetime time 24 hour;}}sainfo anonymous {pfs_group 2;lifetime time 3600 sec;encryption_algorithm aes 128;authentication_algorithm hmac_sha1;compression_algorithm deflate;}B机配置文件:(1)/etc/raccoon/psk.txt内容:172.16.113.173 0x123456(2)/etc/setkey.conf内容:flush;spdflush;spdadd 192.168.1.0/24 192.168.0.0/24 any -P in ipsec esp/tunnel/172.16.113.173-172.16.113.163/require;spdadd 192.168.0.0/24 192.168.1.0/24 any -P out ipsec esp/tunnel/172.16.113.163-172.16.113.173/require;(3)/etc/racoon/racoon内容:同A机。

启动ipsec-tools工具:setkey -FPsetkey -Fkillall racoonsetkey -f /etc/setkey.confracoon -d -f /etc/racoon/racoon.conf -l /tmp/ipsec-log.txt -v可查看/tmp/ipsec-log.txt文件内容分析交互过程。

测试过程:B主机ping A主机地址,ping不通,在GW1路由的WAN口上使用tcpdump抓数据包、收到esp包和解析出的icmp包;LAN口上抓数据包没有收到ICMP包。

结论:Ipsec-tools解密数据包后没将数据包转发给子网,目前不清楚为什么不转发。

Strongswan工具A机配置:(1)/etc/ipsec.conf配置文件:config setupuniqueids=neverconn %defaultauthby=psktype=tunnelconn net-netkeyexchange=ikev1left=172.16.113.173leftsubnet=192.168.1.0/24leftid=172.16.113.173right=172.16.113.163rightsubnet=192.168.0.0/24rightid=172.16.113.163auto=routeike=aes-sha1-modp1024ikelifetime=86400sesp=aes-sha1-modp1024lifetime=86400stype=tunnel(2)/etc/ipsec.secrets文件内容:172.16.113.173 172.16.113.163 : PSK "123456"(3)/etc/strongswan.conf文件# strongswan.conf - strongSwan configuration filecharon {# number of worker threads in charonthreads = 16# send strongswan vendor ID?# send_vendor_id = yesplugins {sql {# loglevel to log into sql databaseloglevel = -1# URI to the database# database = sqlite:///path/to/file.db# database = mysql://user:password@localhost/database }}filelog {/tmp/strongswan.log {time_format = %b %e %Tappend = nodefault = 4flush_line = yes}}}pluto {}libstrongswan {# set to no, the DH exponent size is optimized# dh_exponent_ansi_x9_42 = no}B机配置:(1)/etc/ipsec.conf配置文件:config setupuniqueids=neverconn %defaultauthby=psktype=tunnelconn net-netkeyexchange=ikev1left=172.16.113.163leftsubnet=192.168.0.0/24leftid=172.16.113.163right=172.16.113.173rightsubnet=192.168.1.0/24rightid=172.16.113.173auto=routeike=aes-sha1-modp1024ikelifetime=86400sesp=aes-sha1-modp1024lifetime=86400stype=tunnel(2)/etc/ipsec.secrets文件内容:172.16.113.163 172.16.113.173 : PSK "123456"(3)/etc/strongswan.conf文件同A机。

相关主题