User Tools

Site Tools


doc:howto:vpn.ipsec.basics

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
doc:howto:vpn.ipsec.basics [2013/01/20 20:02]
birnenschnitzel
doc:howto:vpn.ipsec.basics [2015/02/19 12:16] (current)
birnenschnitzel [Page summary]
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 strongswanThe old racoon documentation can be found [[vpn.ipsec.basics.racoon|here]].+A quick starters quide based on OpenWrt Barrier Breaker 14.07Maybe it will save you and me time if one has to setup an IPsec VPN in the futureHopefully it will ecourage other people to use Openwrt as an IPsec VPN routerWe cannot provide a graphical user interface at the moment but at least it is a solid alternative to commercial IPsec appliances
  
-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. 
  
 ===== 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
  
-  * strongswan-full: everything needed for IPsec tunnels+  * strongswan-default: 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-tools: for simpler name resolving than nslookup
  
-Altogehter those packages will eat up about MB of your router'​s flash memory. Maybe it is time for an [[extroot]] installation?​+Altogehter those packages will eat up about some MB of your router'​s flash memory. Maybe it is time for an [[extroot]] installation?​
  
  
Line 20: Line 20:
 ===== Configuration concept ===== ===== Configuration concept =====
  
-Starting ​with Strongswan 5.0 the one and only IPsec daemon is CharonThe former Pluto daemon is no longer available. For this one normally edits some files+If you already worked ​with strongSwan you should know the different files you need to configureThey include
  
   * **/​etc/​strongswan.conf**:​ Central configuration file    * **/​etc/​strongswan.conf**:​ Central configuration file 
Line 27: Line 27:
   * **/​etc/​ipsec.d**:​ Folder for certificates   * **/​etc/​ipsec.d**:​ Folder for certificates
  
-The major challenge is handling ipsec.conf ​with clean integration into the OpenWrt configuration concept. To solve this we will use a hierarchical configuration processThat involves+:!: Remark! If you you want to stay with that configuration you have reached ​the wrong place
  
-  ​* **/​etc/​config/​ipsec**:​ The OpenWrt configuration file for racoon +The major challenge is handling all of those files automatically with a clean integration into the OpenWrt configuration concept. To solve this we will use a hierarchical configuration process. That involves 
-  * **/​etc/​init.d/​ipsec**:​ The Strongswan start script. It will generate the required configuration files for racoon + 
-  * **/etc/​ipsec.conf**:​ The generated ​racoon ​config+  ​* **/​etc/​config/​ipsec**:​ The OpenWrt configuration file for strongSwan 
 +  * **/​etc/​init.d/​ipsec**:​ The Strongswan start script. It will generate the required configuration files for strongSwan 
 +  * **/var/​ipsec.conf**:​ The generated ​Strongswan ​config
   * **/​var/​ipsec.secrets** : The generated file with preshared keys   * **/​var/​ipsec.secrets** : The generated file with preshared keys
 +  * **/​var/​strongswan.conf** : The generated central configuration file
    
 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 52:
   ...   ...
  
-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 62: Line 65:
  
 <code bash> <code bash>
-#​!/​bin/​sh ​/​etc/​rc.common +#!/bin/sh 
-#/​etc/​init.d/​ipsec - version ​2+#/​etc/​init.d/​ipsec - version ​5 - 2015/02/19
  
 NAME=ipsec NAME=ipsec
Line 69: Line 72:
 STOP=60 STOP=60
  
-. /etc/​functions.sh+$IPKG_INSTROOT/lib/functions.sh 
 +. $IPKG_INSTROOT/​lib/​functions/​service.sh
  
 FileSecrets=/​var/​ipsec/​ipsec.secrets FileSecrets=/​var/​ipsec/​ipsec.secrets
Line 137: Line 141:
   echo " ​ leftsubnet=$local_subnet"​ >> $FileConn   echo " ​ leftsubnet=$local_subnet"​ >> $FileConn
   if [ "​$AuthenticationMethod"​ = "​psk"​ ]; then   if [ "​$AuthenticationMethod"​ = "​psk"​ ]; then
-    echo "  ​authby=psk" >> $FileConn+    echo "  ​leftauth=psk"​ >> $FileConn 
 +    echo " ​ rightauth=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 153:
     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 164:
   echo " ​ ike=$Phase1Proposal"​ >> $FileConn   echo " ​ ike=$Phase1Proposal"​ >> $FileConn
   echo " ​ type=tunnel"​ >> $FileConn   echo " ​ type=tunnel"​ >> $FileConn
-  echo " ​ dpdaction=restart"​ >> $FileConn 
 } }
  
Line 167: Line 171:
   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 182:
   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 201: Line 206:
  
 PrepareEnvironment() { PrepareEnvironment() {
 +  local debug
 +
   for d in cacerts aacerts ocspcerts crls acerts; do   for d in cacerts aacerts ocspcerts crls acerts; do
     mkdir -p $FolderCerts/​$d 2>/​dev/​null     mkdir -p $FolderCerts/​$d 2>/​dev/​null
Line 224: Line 231:
     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 "# generated by /​etc/​init.d/​ipsec"​ > $FileSecrets   echo "# generated by /​etc/​init.d/​ipsec"​ > $FileSecrets
 +
 +  config_get debug "​$1"​ debug 0
 +
 +  echo "# generated by /​etc/​init.d/​ipsec"​ > $FileCommon
 +  echo "​charon {" >> $FileCommon
 +  echo " ​ load = aes des sha1 sha2 md5 gmp random nonce hmac stroke kernel-netlink socket-default updown"​ >> $FileCommon
 +  echo " ​ filelog {" >> $FileCommon
 +  echo " ​   /​var/​log/​charon.log {" >> $FileCommon
 +  echo " ​     time_format = %b %e %T" >> $FileCommon
 +  echo " ​     ike_name = yes" >> $FileCommon
 +  echo " ​     append = no" >> $FileCommon
 +  echo " ​     default = " $debug >> $FileCommon
 +  echo " ​     flush_line = yes" >> $FileCommon
 +  echo " ​   }" >> $FileCommon
 +  echo " ​ }" >> $FileCommon
 +  echo "​}"​ >> $FileCommon
 +
 } }
  
Line 239: Line 260:
     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 251: Line 280:
 start() { start() {
   CheckInstallation   CheckInstallation
-  ​PrepareEnvironment+ 
 +  config_load ipsec 
 +  config_foreach ​PrepareEnvironment ​ipsec 
 +  config_foreach ConfigRemote remote
  
   config_load users   config_load users
   config_foreach ConfigUser user   config_foreach ConfigUser user
- 
-  config_load ipsec 
-  config_foreach ConfigRemote remote 
  
   /​usr/​sbin/​ipsec start   /​usr/​sbin/​ipsec start
Line 271: Line 300:
 {{:​doc:​howto:​ipsec_daemon.png|}} {{:​doc:​howto:​ipsec_daemon.png|}}
  
-===== 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 
  
-  * 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. 
  
-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 
  
-  * Logon to a fast Linux machine ​ 
-  * Use a direct LAN connection to the router 
-  * Ensure the router is idle 
-  * Transfer 100 MB of data using ssh 
-  * Calculate the speed from the elapsed time. Throughput = 800 / SecondsElapsed 
- 
-<​code>​ 
-ssh -2 -c aes128-cbc root@<​router>​ time dd if=/​dev/​zero bs=500000 count=200 > /dev/null 
-ssh -2 -c aes256-cbc root@<​router>​ time dd if=/​dev/​zero bs=500000 count=200 > /dev/null 
-</​code>​ 
- 
-You can have a look at the realtime traffic graph in a dry run afterwards to verify the speed. But do not open it during your test because it invalidates the results. 
- 
-^ CPU ^ MHz ^ tested device ^AES128 (s)^AES128 (MBit/​s)^AES256 (s)^AES256 (MBit/​s)^ ​ 
-| MIPS 24k | 680 | [[toh:​d-link:​dir-825|D-Link DIR-825]] [[toh:​netgear:​wndr3700|Netgear WNDR3700]] |  28.2 |  28.5 |  32.4 |  24.6 | 
-| MIPS 24k | 400 | [[toh:​tp-link:​tl-wr703n|TP-Link TL-WR703N]] |  47.7 |  16.5 |  56.1 |  14.2 | 
-| MIPS R3000 | 125 | [[toh:​asus:​wl500g|Asus WL-500g]] |  164.8 |  4.8 |  183.5 |  4.3 |  
- 
- 
-===== IPsec Tuning ===== 
- 
-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:​ 
- 
-  * SHA1 calculation works on registers only 
-  * A lot of memcpy operations have been removed from MD5 and AES. 
-  * AES memory footprint is lowered from 16K to 8,2K 
-  * Avoid little endian byte swapping in AES 
-  * 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: 
- 
-^ OpenWrt ^ Device ^ AES256/SHA1 (MBit/s) ^ AES128/SHA1 (MBit/s)^ AES128/MD5 (MBit/​s)^ ​ 
-| trunk + mcespi.ko | MIPS 24K @ 680 MHz (AR7161) |  37.5 |  42.4 |  47.6 | 
-| 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. 
- 
-  * create a buildroot environment 
-  * compile an image for your router once 
-  * put the mcespi.c into the the folder build_dir/​linux-<​arch>/​linux-<​X.Y.Z>/​crypto 
-  * Include the line **obj-$(CONFIG_CRYPTO_MD5) += mcespi.o** into build_dir/​linux-<​arch>/​linux-<​X.Y.Z>/​crypto/​Makefile 
-  * compile the image once again. 
-  * Afterwards you will find build_dir/​linux-<​arch>/​linux-<​X.Y.Z>/​crypto/​mcespi.ko 
-  * Put mcespi.ko to your router into /​lib/​modules/<​X.Y.Z>​ 
-  * Load the module with insmod ​ 
-  * For automatic loading create a new /​etc/​modules.d/​09-crypto-mcespi with corresponding content. 
- 
-If you are not on MIPS big endian but you have at least kernel 2.6.39 you can head for SHA1 performance optimization. Download [[http://​wiki.openwrt.org/​_media/​doc/​howto/​sha1-optimized.c|sha_optimized.c]] and build it as a module. FIXME Ticket [[https://​dev.openwrt.org/​ticket/​10637|#​10637]] tries to implement that patch into trunk. At least on Atheros AR7161 platform and current trunk this leads to an oops. If you can help and find out why just put your feedback here or over there. ​ Note: On current trunk the default kernel is 3.3 and sha_optimized.c does not have to be backported anymore. 
- 
-<code bash> 
-mv 259-crypto_SHA1_3.2_backport.patch target/​linux/​generic/​patches-XXX 
-make target/​linux/​clean 
-make world 
-</​code>​ 
  
 ===== What's next ===== ===== What's next =====
  
-After the basic setup you should ​continue with the [[vpn.ipsec.firewall|firewall modifications]].+After the basic setup you should ​make sure you understand ​the [[vpn.ipsec.performance|expected performance]] of low budget routers.
  
 ===== Tag ===== ===== Tag =====
  
 {{tag>​crypto}} {{tag>​crypto}}
 +
  
doc/howto/vpn.ipsec.basics.1358708543.txt.bz2 · Last modified: 2013/01/20 20:02 by birnenschnitzel