Differences

This shows you the differences between two versions of the page.

doc:howto:vpn.ipsec.basics [2013/01/20 20:02]
birnenschnitzel
doc:howto:vpn.ipsec.basics [2014/11/09 05:09] (current)
ahimoth Script was bad for strongswan.conf on reboot. Removed the offending lines
Line 1: Line 1:
====== IPsec Basics ====== ====== IPsec Basics ======
 +| For an overview over all existing Virtual private network (VPN)-related articles in the OpenWrt wiki, please visit [[doc/howto/vpn.overview]] |
-:!: This page is about strongswan. The old racoon documentation can be found [[vpn.ipsec.basics.racoon|here]].+:!: This page is about strongSwan. The old racoon documentation can be found [[vpn.ipsec.basics.racoon|here]].
-A quick starters quide based on Backfire 12.09. Maybe it will save you and me time if one has to setup an IPsec VPN in the future. Hopefully it will ecourage other people to use Openwrt as an IPsec VPN router. We cannot provide a graphical user interface at the moment but at least it is a solid alternative to commercial IPsec appliances. If you came here for informations about [[http://www.openswan.org|Openswan]] on OpenWrt you may be disappointed. This guide is only about strongswan.+A quick starters guide based on OpenWrt Attitude Adjustment 12.09. Maybe it will save you and me time if one has to setup an IPsec VPN in the future. Hopefully it will encourage other people to use Openwrt as an IPsec VPN router. We cannot provide a graphical user interface at the moment but at least it is a solid alternative to commercial IPsec appliances. If you came here for information about [[http://www.openswan.org|Openswan]] on OpenWrt you may be disappointed. This guide is only about strongSwan.
===== Packages ===== ===== Packages =====
-If not already installed on your router you need the at least those packages+If not already installed on your router you need the at least those packages. **Ensure that you use strongSwan 5.0.0 or higher**. Older versions will not work due to differences in configuration handling.
-  * strongswan-full: everything needed for IPsec tunnels+  * strongswan-full 5.0.0: everything needed for IPsec tunnels
  * ip: Required to make scripting easier   * ip: Required to make scripting easier
  * iptables-mod-nat-extra: For VPN networks with [[vpn.ipsec.overlappingsubnets|overlapping IP addresses]]   * iptables-mod-nat-extra: For VPN networks with [[vpn.ipsec.overlappingsubnets|overlapping IP addresses]]
  * djbdns-utils: for simpler name resolving than old "nslookup | awk" thing (may also be named djbdns-tools)   * djbdns-utils: for simpler name resolving than old "nslookup | awk" thing (may also be named djbdns-tools)
-Altogehter those packages will eat up about 2 MB of your router's flash memory. Maybe it is time for an [[extroot]] installation?+Altogether those packages will eat up about 4 MB of your router's flash memory. Maybe it is time for an [[extroot]] installation?
Line 20: Line 21:
===== Configuration concept ===== ===== Configuration concept =====
-Starting with Strongswan 5.0 the one and only IPsec daemon is Charon. The former Pluto daemon is no longer available. For this one normally edits some files+Starting with strongSwan 5.0 the one and only IPsec daemon is Charon. The former Pluto daemon is no longer available. For this, one normally edits some files
  * **/etc/strongswan.conf**: Central configuration file   * **/etc/strongswan.conf**: Central configuration file
Line 29: Line 30:
The major challenge is handling ipsec.conf with clean integration into the OpenWrt configuration concept. To solve this we will use a hierarchical configuration process. That involves The major challenge is handling ipsec.conf with clean integration into the OpenWrt configuration concept. To solve this we will use a hierarchical configuration process. That involves
-  * **/etc/config/ipsec**: The OpenWrt configuration file for racoon +  * **/etc/strongswan.conf**: The central strongSwan configuration file. 
-  * **/etc/init.d/ipsec**: The Strongswan start script. It will generate the required configuration files for racoon +  * **/etc/config/ipsec**: The OpenWrt UCI compatible IPsec configuration file. 
-  * **/etc/ipsec.conf**: The generated racoon config +  * **/etc/init.d/ipsec**: The strongSwan start [[vpn.ipsec.basics#ike.daemon|script]]. It will generate the required configuration files. 
-  * **/var/ipsec.secrets** : The generated file with preshared keys +  * **/var/ipsec/ipsec.conf**: The generated IPsec config file, automatically symlinked into /etc. 
- +  * **/var/ipsec/ipsec.secrets** : The generated IPsec preshared keys file, automatically symlinked into /etc. 
Here a short example of the configuration methodology when having two VPN tunnels to ACME and Yabadoo networks Here a short example of the configuration methodology when having two VPN tunnels to ACME and Yabadoo networks
<code> <code>
-#/etc/config/racoon +#/etc/config/ipsec 
-config 'remove' 'ACME'+config 'remote' 'ACME'
  option 'enabled' '1'   option 'enabled' '1'
  option 'gateway' '1.2.3.4'   option 'gateway' '1.2.3.4'
Line 49: Line 51:
  ...   ...
-config 'tunnel' 'Yabadoo'+config 'remote' 'Yabadoo'
  option 'enabled' '1'   option 'enabled' '1'
  option 'gateway' '5.6.7.8'   option 'gateway' '5.6.7.8'
Line 59: Line 61:
===== IKE Daemon ===== ===== IKE Daemon =====
-To let Charon run as a background daemon we can place a hook in the init environment. Therefore create the file **/etc/init.d/ipsec** and set the executable bit. Remark: This script is in an early alpha state. It currently works for site to site tunnels with preshared keys. Feel free to enhance it.+To let Charon run as a background daemon we can place a hook in the init environment. Therefore create the file **/etc/init.d/ipsec** and set the executable bit. This script will read configuration from **/etc/config/ipsec** and then generate the actual IPsec system configuration files (**/var/ipsec/ipsec.conf** and **/var/ipsec/ipsec.secrets**) before starting IPsec.  
 +Remark: This script is in an early alpha state. It currently works for site to site tunnels with preshared keys. Feel free to enhance it.
<code bash> <code bash>
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
-#/etc/init.d/ipsec - version 2+#/etc/init.d/ipsec - version 4
NAME=ipsec NAME=ipsec
Line 69: Line 72:
STOP=60 STOP=60
-. /etc/functions.sh+. /lib/functions.sh
FileSecrets=/var/ipsec/ipsec.secrets FileSecrets=/var/ipsec/ipsec.secrets
FileConn=/var/ipsec/ipsec.conf FileConn=/var/ipsec/ipsec.conf
-FileCommon=/var/ipsec/strongswan.conf 
FolderCerts=/var/ipsec/ipsec.d FolderCerts=/var/ipsec/ipsec.d
Line 139: Line 141:
    echo "  authby=psk" >> $FileConn     echo "  authby=psk" >> $FileConn
    echo "  rightsubnet=$remote_subnet" >> $FileConn     echo "  rightsubnet=$remote_subnet" >> $FileConn
-    echo "  auto=route" >> $FileConn+# should be auto=route when going to 5.0.1 
 +    echo "  auto=start" >> $FileConn
  elif [ "$AuthenticationMethod" = "xauth_psk_server" ]; then   elif [ "$AuthenticationMethod" = "xauth_psk_server" ]; then
    echo "  authby=xauthpsk" >> $FileConn     echo "  authby=xauthpsk" >> $FileConn
Line 147: Line 150:
    echo "  auto=add" >> $FileConn     echo "  auto=add" >> $FileConn
  fi   fi
-  echo $ExchangeMode +  if [ "$LocalIdentifier" != "" ]; then 
-  if [ "$ExchangeMode" = "main" ]; then +    echo "  leftid=$LocalIdentifier" >> $FileConn 
-    echo "  aggressive = no" >> $FileConn +  fi 
-  else +  if [ "$RemoteIdentifier" != "" ]; then 
-    echo "  aggressive = yes" >> $FileConn+    echo "  rightid=$RemoteIdentifier" >> $FileConn
  fi   fi
-  [[ "$MyIdentifier" != "" ]] && echo "  leftid=$MyIdentifier" >> $FileConn 
#  echo "  auth=esp" >> $FileConn #  echo "  auth=esp" >> $FileConn
Line 159: Line 161:
  echo "  ike=$Phase1Proposal" >> $FileConn   echo "  ike=$Phase1Proposal" >> $FileConn
  echo "  type=tunnel" >> $FileConn   echo "  type=tunnel" >> $FileConn
-  echo "  dpdaction=restart" >> $FileConn 
} }
Line 167: Line 168:
  local pre_shared_key   local pre_shared_key
  local authentication_method   local authentication_method
-  local my_identifier+  local local_identifier 
 +  local remote_identifier
  ConfigName=$1   ConfigName=$1
Line 177: Line 179:
  config_get pre_shared_key        "$1" pre_shared_key   config_get pre_shared_key        "$1" pre_shared_key
  config_get authentication_method "$1" authentication_method   config_get authentication_method "$1" authentication_method
-  config_get exchange_mode        "$1" exchange_mode "main" +  config_get local_identifier      "$1" local_identifier 
-  config_get my_identifier        "$1" my_identifier ""+  config_get remote_identifier    "$1" remote_identifier
  AuthenticationMethod=$authentication_method   AuthenticationMethod=$authentication_method
-  ExchangeMode=$exchange_mode +  LocalIdentifier=$local_identifier 
-  MyIdentifier=$my_identifier+  RemoteIdentifier=$remote_identifier
  RemoteGateway=$gateway   RemoteGateway=$gateway
Line 213: Line 215:
    rm /etc/ipsec.secrets 2>/dev/null     rm /etc/ipsec.secrets 2>/dev/null
    ln -s $FileSecrets /etc/ipsec.secrets     ln -s $FileSecrets /etc/ipsec.secrets
-  fi 
- 
-  if [ ! -L /etc/strongswan.conf ]; then 
-    rm /etc/strongswan.conf 2>/dev/null 
-    ln -s $FileCommon /etc/strongswan.conf 
  fi   fi
Line 224: Line 221:
    ln -s $FileConn /etc/ipsec.conf     ln -s $FileConn /etc/ipsec.conf
  fi   fi
- 
  echo "# generated by /etc/init.d/ipsec" > $FileConn   echo "# generated by /etc/init.d/ipsec" > $FileConn
  echo "version 2" > $FileConn   echo "version 2" > $FileConn
  echo "config setup" >> $FileConn   echo "config setup" >> $FileConn
 +  echo "  charondebug = \"ike 2,knl 2\"" >> $FileConn
  echo "# generated by /etc/init.d/ipsec" > $FileSecrets   echo "# generated by /etc/init.d/ipsec" > $FileSecrets
Line 239: Line 236:
    exit     exit
  fi   fi
 +
 +  for f in aes authenc cbc hmac md5 sha1; do
 +    if [ `opkg list kmod-crypto-$f | wc -l` -eq 0 ]; then
 +      echo kmod-crypto-$f missing
 +      echo install with  \"opkg install kmod-crypto-$f --nodeps\"
 +      exit
 +    fi
 +  done
  for f in aes gmp hmac kernel-netlink md5 random sha1 updown attr resolve; do   for f in aes gmp hmac kernel-netlink md5 random sha1 updown attr resolve; do
    if [ ! -f /usr/lib/ipsec/plugins/libstrongswan-${f}.so ]; then     if [ ! -f /usr/lib/ipsec/plugins/libstrongswan-${f}.so ]; then
      echo /usr/lib/ipsec/plugins/$f missing       echo /usr/lib/ipsec/plugins/$f missing
-      echo install with \"opkg install strongswan4-mod-$f --nodeps\"+      echo install with \"opkg install strongswan-mod-$f --nodeps\"
      exit       exit
    fi     fi
Line 273: Line 278:
===== Hardware performance ===== ===== Hardware performance =====
-In the times of broadband internet connections encryption and decryption speed of routers can limit throughput of VPN tunnels. CPU utilization maxes out at 100 percent and impacts other services of the device like a web server. If you really want to go with a self made IPsec VPN on a cheap router you should consider some facts+In the times of broadband internet connections encryption and decryption speed of SOME low-end routers can limit throughput of VPN tunnels. CPU utilization can max out at 100 percent and impacts other services of the device like a web server. FOR REFERENCE: strongSwan will run just FINE on a WNDR3700 (MIPS 680 Mhz, 64 Mb RAM). If your router is underpowered, here are some other options:
  * Older firewall devices with hardware accelerated VPN are sold for a few bucks on Ebay. Juniper Netscreen 5GT for example can easily reach a VPN throughput of 20 MBit/sec. Downside is that firmware updates are only possible with a Juniper support contract. So check twice for a bargain.   * Older firewall devices with hardware accelerated VPN are sold for a few bucks on Ebay. Juniper Netscreen 5GT for example can easily reach a VPN throughput of 20 MBit/sec. Downside is that firmware updates are only possible with a Juniper support contract. So check twice for a bargain.
  * Firewall devices are build to support IPsec out of the box. A convenient web interface helps the administrator to build a tunnel in a few seconds. OpenWrt still lacks a standard LuCI config panel. If you only go with 1-5 VPN tunnels this should be no concern to you.   * Firewall devices are build to support IPsec out of the box. A convenient web interface helps the administrator to build a tunnel in a few seconds. OpenWrt still lacks a standard LuCI config panel. If you only go with 1-5 VPN tunnels this should be no concern to you.
-To find the right OpenWrt hardware for your VPN you should have a look at the following benchmark table. It is build on a simple test without any claim of perfection. Nevertheless the numbers are quite close to what you can expect from an AES 128/256 bit encrypted IPsec Tunnel connection with standard kernel modules. You may notice that those numbers differ from what is written on the [[inbox:benchmark.openssl|OpenSSL wiki page]]. But simply remember: **The tests over there do not include network traffic**. If you want to add a new device onto the list check the encrpytion throughput using the following prerequisites+To find the right OpenWrt hardware for your VPN you should have a look at the following benchmark table. It is build on a simple test without any claim of perfection. Nevertheless the numbers are quite close to what you can expect from an AES 128/256 bit encrypted IPsec Tunnel connection with standard kernel modules. You may notice that those numbers differ from what is written on the [[inbox:benchmark.openssl|OpenSSL wiki page]]. But simply remember: **The tests over there do not include network traffic**. If you want to add a new device onto the list check the encryption throughput using the following prerequisites
  * Logon to a fast Linux machine   * Logon to a fast Linux machine
Line 303: Line 308:
If you use a default OpenWrt installation you will discover that using the SHA1 hashing function will hit VPN performance. If you go for raw throughput MD5 can be a helpful alternative. One may remark that MD5 is [[http://en.wikipedia.org/wiki/Md5#Security|not very secure]] but for IPsec connections it should be enough as we are talking about hash values of encrypted data with a key that is changed [[doc:uci:racoon#p2_proposal|every hour]] according to phase 2 proposals. A good tradeoff could be to choose AES256/SHA1 for phase 1 and AES128/MD5 for phase 2.  If you use a default OpenWrt installation you will discover that using the SHA1 hashing function will hit VPN performance. If you go for raw throughput MD5 can be a helpful alternative. One may remark that MD5 is [[http://en.wikipedia.org/wiki/Md5#Security|not very secure]] but for IPsec connections it should be enough as we are talking about hash values of encrypted data with a key that is changed [[doc:uci:racoon#p2_proposal|every hour]] according to phase 2 proposals. A good tradeoff could be to choose AES256/SHA1 for phase 1 and AES128/MD5 for phase 2. 
-Read on if you have some time and want to enhance your VPN speed. The kernel IPsec architecture relies on different crypto providers. E.g. if you build a tunnel with SHA1 checksums you must hava a module that can calculate those values. A look at /proc/crypto will reveal what modules are loaded and which algorithms they provide. The standard Linux Kernel modules are far from being optimized. At least with kernel 3.2 someone has taken care of [[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=1eb19a12bd2214cdcad5273d472b062a4ba97fa1|SHA1]]. Those of you that are on **MIPS big endian** machines can replace the default aes_generic.ko, sha_generic.ko, cbc.ko and md5.ko modules with a single assembler optimized [[https://sourceforge.net/projects/mcespi/files/|mcespi.ko]]. Besides of being faster it has some nice characteristcs:+Read on if you have some time and want to enhance your VPN speed. The kernel IPsec architecture relies on different crypto providers. E.g. if you build a tunnel with SHA1 checksums you must have a module that can calculate those values. A look at /proc/crypto will reveal what modules are loaded and which algorithms they provide. The standard Linux Kernel modules are far from being optimized. At least with kernel 3.2 someone has taken care of [[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=1eb19a12bd2214cdcad5273d472b062a4ba97fa1|SHA1]]. Those of you that are on **MIPS big endian** machines can replace the default aes_generic.ko, sha_generic.ko, cbc.ko and md5.ko modules with a single assembler optimized [[https://sourceforge.net/projects/mcespi/files/|mcespi.ko]]. Besides of being faster it has some nice characteristics:
  * SHA1 calculation works on registers only   * SHA1 calculation works on registers only
Line 311: Line 316:
  * 21K module size in contrast to 4 modules with 45K   * 21K module size in contrast to 4 modules with 45K
-If you are on AR7161 you should ensure that you already have [[https://dev.openwrt.org/browser/trunk/target/linux/ar71xx/patches-2.6.39/910-unaligned_access_hacks.patch|unaligned access patch 1]] from trunk and the not yet implemented [[http://patchwork.openwrt.org/patch/1721/|unaligned access patch 2]]. It will free CPU from handling unaligned access expections so that you can reach these results:+If you are on AR7161 you should ensure that you already have [[https://dev.openwrt.org/browser/trunk/target/linux/ar71xx/patches-2.6.39/910-unaligned_access_hacks.patch|unaligned access patch 1]] from trunk and the not yet implemented [[http://patchwork.openwrt.org/patch/1721/|unaligned access patch 2]]. It will free CPU from handling unaligned access exceptions so that you can reach these results:
^ OpenWrt ^ Device ^ AES256/SHA1 (MBit/s) ^ AES128/SHA1 (MBit/s)^ AES128/MD5 (MBit/s)^ ^ OpenWrt ^ Device ^ AES256/SHA1 (MBit/s) ^ AES128/SHA1 (MBit/s)^ AES128/MD5 (MBit/s)^
Line 317: Line 322:
| 10.03.1-rc6 | MIPS 24K @ 680 MHz (AR7161) |  18.0 |  19.6 |  30.3 | | 10.03.1-rc6 | MIPS 24K @ 680 MHz (AR7161) |  18.0 |  19.6 |  30.3 |
-The module is in early alpha development an the easyiest way to install it includes a few steps.+The module is in early alpha development an the easiest way to install it includes a few steps.
  * create a buildroot environment   * create a buildroot environment
Line 340: Line 345:
After the basic setup you should continue with the [[vpn.ipsec.firewall|firewall modifications]]. After the basic setup you should continue with the [[vpn.ipsec.firewall|firewall modifications]].
 +
 +===== Current Issues =====
 +The latest trunk includes strongSwan 5.1.1-1. It will compile if you remove curl, but will not run due to a module loading issue.
 +One workaround is to configure the charon.load string in strongswan.conf, which explicitly loads the modules you want/need.
 +
 +Example:
 +<code>
 +Charon {
 +  load = aes des sha1 sha2 md5 pem pkcs1 gmp random nonce x509 revocation hmac stroke kernel-netlink socket-default updown attr farp dhcp
 +....
 +</code>
===== Tag ===== ===== Tag =====
{{tag>crypto}} {{tag>crypto}}
 +

Back to top

doc/howto/vpn.ipsec.basics.1358708543.txt.bz2 · Last modified: 2013/01/20 20:02 by birnenschnitzel