VPN(8)                  OpenBSD System Manager's Manual                 VPN(8)

NAME
     vpn - configuring the system for virtual private networks

DESCRIPTION
     A virtual private network is used to securely connect two or more subnets
     over the internet. For each subnet there is a security gateway which is
     linked via a cryptographically secured tunnel to the security gateway of
     the other subnet.  ipsec(4) is used to provide the necessary network-lay-
     er cryptographic services.  This document describes the configuration
     process for setting up a VPN.

     Briefly, creating a VPN consists of the following steps:

     1.   Choose a key exchange method: manual keyed or photurisd(8).
     2.   Create a Security Association (SA) for each endpoint.
     3.   Create the appropriate IPSec flows.
     4.   Configure your firewall rules appropriately.

   Choosing a key exchange method
     There are currently two key exchange methods available:

     o   manual (symmetric shared secret)
     o   photurisd(8)

     At present VPNs between private (RFC 1918) networks must use manual key-
     ing, as photurisd(8) can only be used if the IP address of the security
     gateway actually falls within the range of addresses being tunnelled to.
     This can clearly never occur if the addresses being tunnelled to are non-
     routable private networks.

   Generating Manual Keys
     The shared secret symmetric keys used to create a VPN can be any hexadec-
     imal value, so long as both sides of the connection use the same values.
     Since the security of the VPN is based on these keys being unguessable,
     it is very important that the keys be chosen using a strong random
     source. One practical method of generating them is by using the random(4)
     device. To produce 160 bits of randomness, for example, do a:

        dd if=/dev/urandom bs=1024 count=1 | sha1

     Different cipher types may require different sized keys.

     Cipher    Key Length
     DES       56 bits
     3DES      168 bits
     BLF       Variable (160 bits recommended)
     CAST      Variable (160 bits recommended)
     SKIPJACK  80 bits

     Use of DES or SKIPJACK as an encryption algorithm is not recommended (ex-
     cept for backwards compatibility) due to their short key length.  Fur-
     thermore, recent attacks on SKIPJACK have shown severe weaknesses in its
     structure.

     Note that DES requires 8 bytes to form a 56-bit key and 3DES requires 24
     bytes to form its 168-bit key. This is because the most significant bit
     of each byte is ignored by both algorithms.

   Enabling the Appropriate Kernel Operations
     ipsec(4) operations must be first enabled using sysctl(8).  Before creat-
     ing security associations, or performing encryption (ESP) or authentica-
     tion (AH) operation, ensure the appropriate kernel operation has been en-
     abled:

     sysctl -w net.inet.esp.enable=1
     sysctl -w net.inet.ah.enable=1

     For more permanent operation, these options should be enabled in your
     sysctl.conf(5).

   Creating Security Associations
     Before the IPSec flows can be defined, two Security Associations (SAs)
     must be defined on each end of the VPN, e.g.:

     ipsecadm new esp -spi SPI_OUT -src A_EXTERNAL_IP
              -dst B_EXTERNAL_IP -forcetunnel
              -enc 3des -auth sha1
              -key ENCRYPTION_KEY -authkey AUTHENTICATION_KEY

     ipsecadm new esp -spi SPI_IN -src B_EXTERNAL_IP
              -dst A_EXTERNAL_IP -forcetunnel
              -enc 3des -auth sha1
              -key ENCRYPTION_KEY -authkey AUTHENTICATION_KEY

   Creating IPSec Flows
     Both IPsec gateways need to configure ipsec(4) routes with the
     ipsecadm(8) tool:

     On the security gateway of subnet A:

     ipsecadm flow -dst B_EXTERNAL_IP -spi SPI_OUT -proto esp
              -addr A_EXTERNAL_IP 255.255.255.255
                    B_EXTERNAL_IP 255.255.255.255 -local
     ipsecadm flow -dst B_EXTERNAL_IP -spi SPI_OUT -proto esp
              -addr A_INTERNAL_NETWORK A_INTERNAL_NETMASK
                    B_INTERNAL_NETWORK B_INTERNAL_NETMASK
     ipsecadm flow -dst B_EXTERNAL_IP -spi SPI_OUT -proto esp
              -addr A_EXTERNAL_IP 255.255.255.255
                    B_INTERNAL_NETWORK B_INTERNAL_NETMASK -local
     ipsecadm flow -dst B_EXTERNAL_IP -spi SPI_OUT -proto esp
              -addr A_INTERNAL_NETWORK A_INTERNAL_NETMASK
                    B_EXTERNAL_IP 255.255.255.255

     and on the security gateway of subnet B:

     ipsecadm flow -dst A_EXTERNAL_IP -spi SPI_IN -proto esp
              -addr B_EXTERNAL_IP 255.255.255.255
                    A_EXTERNAL_IP 255.255.255.255 -local
     ipsecadm flow -dst A_EXTERNAL_IP -spi SPI_IN -proto esp
              -addr B_INTERNAL_NETWORK B_INTERNAL_NETMASK
                    A_INTERNAL_NETWORK A_INTERNAL_NETMASK
     ipsecadm flow -dst A_EXTERNAL_IP -spi SPI_OUT -proto esp
              -addr B_EXTERNAL_IP 255.255.255.255
                    A_INTERNAL_NETWORK A_INTERNAL_NETMASK -local
     ipsecadm flow -dst A_EXTERNAL_IP -spi SPI_OUT -proto esp
              -addr B_INTERNAL_NETWORK B_INTERNAL_NETMASK
                    A_EXTERNAL_IP 255.255.255.255

     Furthermore, unless manual keying is used, both security gateways need to
     start the photurisd(8) key management daemon with the -v flag and make
     sure it is configured properly on both sides to provide the required se-
     curity services (typically, encryption and authentication).

   Configuring Firewall Rules
     ipf(8) needs to be configured such that all packets from the outside are
     blocked by default. Only successfully IPSec-processed packets (from the
     enc0(4) interface), or key management packets (for photurisd(8),  UDP
     packets with source and destination ports of 468) should be allowed to
     pass.
     The ipf(5) rules for a tunnel which uses encryption (the ESP IPsec proto-
     col) and photurisd(8) on security gateway A might look like this:

     # ne0 is the only interface going to the outside.
     block in log on ne0 from any to any
     block out log on ne0 from any to any
     block in log on enc0 from any to any

     # Passing in encrypted traffic from security gateways
     pass in proto esp from gatewB/32 to gatewA/32
     pass out proto esp from gatewA/32 to gatewB/32

     # Passing in traffic from the designated subnets.
     pass in on enc0 from netB/netBmask to netA/netAmask

     # Passing in Photuris traffic from the security gateways
     pass in on ne0 proto udp from gatewB/32 port = 468 to gatewA/32 port = 468
     pass out on ne0 proto udp from gatewA/32 port = 468 to gatewB/32 port = 468

     If there are no other ipf(5) rules, the "quick" clause can be added to
     the last three rules.

EXAMPLES
     To create a manual keyed VPN between two class C networks using 3DES en-
     cryption and the following IP addresses:

      A_INTERNAL_IP = 10.0.50.1
      A_EXTERNAL_IP = 192.168.1.254
      B_EXTERNAL_IP = 192.168.2.1
      B_INTERNAL_IP = 10.0.99.1

     1.   Choose the shared secrets using a suitably random method:

          # dd if=/dev/urandom bs=1024 count=1 | sha1
          cd28c327c7fd0943596a96cc7bf9108cd896f33c

          # dd if=/dev/urandom bs=1024 count=1 | sha1
          44aedc8aa8acf0b8c74acd626cd1b1057fb12c76

          # dd if=/dev/urandom bs=1024 count=1 | sha1
          c9fff55b501206a6607fb45c392c5e1568db2aaf

     2.   Create the Security Associations (on both endpoints):

          # /sbin/ipsecadm new esp -src 192.168.2.1 -dst 192.168.1.254 \
             -forcetunnel -spi 1000 -enc 3des -auth sha1 \
             -key 596a96cc7bf9108cd896f33c44aedc8aa8acf0b8c74acd62 \
             -authkey c9fff55b501206a6607fb45c392c5e1568db2aaf

          # /sbin/ipsecadm new esp -src 192.168.1.254 -dst 192.168.2.1  \
             -forcetunnel -spi 1001 -enc 3des -auth sha1 \
             -key 596a96cc7bf9108cd896f33c44aedc8aa8acf0b8c74acd62 \
             -authkey c9fff55b501206a6607fb45c392c5e1568db2aaf

     3.   Create the ipsec route on machine A:

          # /sbin/ipsecadm flow -dst 192.168.2.1 -spi 1001 -proto esp \
              -addr 192.168.1.254 255.255.255.255 \
                    192.168.2.1 255.255.255.255 -local

          # /sbin/ipsecadm flow -dst 192.168.2.1 -spi 1001 -proto esp \
              -addr 10.0.50.0 255.255.255.0 10.0.99.0 255.255.255.0

          # /sbin/ipsecadm flow -dst 192.168.2.1 -spi 1001 -proto esp \
              -addr 192.168.1.254 255.255.255.255 \
                    10.0.99.0 255.255.255.0 -local

          # /sbin/ipsecadm flow -dst 192.168.2.1 -spi 1001 -proto esp \
              -addr 10.0.50.0 255.255.255.0 192.168.2.1 255.255.255.255

     4.   Create the ipsec flow on machine B:

          # /sbin/ipsecadm flow -dst 192.168.1.254 -spi 1000 -proto esp \
              -addr 192.168.2.1 255.255.255.255 \
                    192.168.1.254 255.255.255.255 -local

          # /sbin/ipsecadm flow -dst 192.168.1.254 -spi 1000 -proto esp \
              -addr 10.0.99.0 255.255.255.0 10.0.50.0 255.255.255.0

          # /sbin/ipsecadm flow -dst 192.168.1.254 -spi 1000 -proto esp \
               -addr 192.168.2.1 255.255.255.255 \
                     10.0.50.0 255.255.255.0 -local

          # /sbin/ipsecadm flow -dst 192.168.1.254 -spi 1000 -proto esp \
               -addr 10.0.99.0 255.255.255.0 192.168.1.254 255.255.255.255

     5.   Configure the firewall rules on machine A:

          # ne0 is the only interface going to the outside.
          block in log on ne0 from any to any
          block out log on ne0 from any to any
          block in log on enc0 from any to any

          # Passing in encrypted traffic from security gateways
          pass in proto esp from 192.168.2.1/32 to 192.168.1.254/32
          pass out proto esp from 192.168.1.254/32 to 192.168.2.1/32

          # Passing in traffic from the designated subnets.
          pass in quick on enc0 from 10.0.99.0/24 to 10.0.50.0/24

     6.   Configure the firewall rules on machine B:

          # ne0 is the only interface going to the outside.
          block in log on ne0 from any to any
          block out log on ne0 from any to any
          block in log on enc0 from any to any

          # Passing in encrypted traffic from security gateways
          pass in proto esp from 192.168.1.254/32 to 192.168.2.1/32
          pass out proto esp from 192.168.2.1/32 to 192.168.1.254/32

          # Passing in traffic from the designated subnets.
          pass in quick on enc0 from 10.0.50.0/24 to 10.0.99.0/24

FILES
     /usr/share/ipsec/rc.vpn      Sample VPN configuration file
     /etc/photuris/photuris.conf  Photuris configuration file
     /etc/ipf.rules               Firewall configuration file

BUGS
     photurisd(8) can not be used in VPN mode unless both of the security
     gateway IP addresses lie within the network ranges being tunnelled to.
     In situations where the gateway IP is outside the desired netrange, such
     as with private (RFC 1918) networks, manual keying must be used.  This
     should be fixed in the next release.

SEE ALSO
     enc(4),  ipsec(4),  options(4),  ipf(5),  ipf(8),  ipsecadm(8),
     isakmpd(8),  photurisd(8)

OpenBSD 2.6                    February 9, 1999                              4
