by Rafael Coninck Teigao
|IPSec Fundamentals and Installation
last updated Fri February 4, 2000
As the Internet grows, more and more emphasis is being placed on security. One especially hot topic in security these days is IPSec and IPv6. This article is going to explain what IP Security (IPSec) is, what it is good for, why should you use it and, finally, provide and example of how to deploy it on Linux.
When you hear the word cryptography, the words that probably come to your mind are PGP, SSL, SSH, DES, and what you imagine is someone encrypting a file. This use of cryptography is at a higher level than IPSec. Basically IPSec is a way to build a secure data channel at IP level. So for a standard configuration what you have is the following:
------- ----------- ----------- ---------- |host 1 |<->| Gateway 1 |<->| External Net |<->| Gateway 2 |<->| host 2 | ------- ----------- ----------- ---------- | | |_____ Secure Communication_____|
You want "host 1" to communicate securely to "host 2", so "Gateway 1" and "Gateway 2" are set to use IPSec to communicate to each other, encrypting all data that goes from "host 1" to "host 2". IPSec is also used to authenticate the data being sent between hosts.
To understand how IPSec interacts with the network you should first understand the concept of layers. There are three important layers:
------------------- | Application Layer | ------------------- | --------------- | Network Layer | <---- IPSec works here --------------- | ---------------- | Physical Layer | ----------------
The Application Layer is where the higher protocols are (TCP, UDP, etc.) and has an interaction with the Network Layer that is transparent to software and users. If the Network Layer is secure, everything that goes on the Application Layer is secure as well. With this, attacks such as "Man in the Middle" and Eavesdropping are no longer valid.
There are several ways to use IPSec, and it is important to decide what is best for your network and your data. If you want to authenticate a client accessing the server, or you want to make sure that the data being sent has not been changed, but you do not feel the need to encrypt that data, the best thing to use is just authentication on the packets. If you want to protect the data from being monitored while it travels over the network, the best thing would be encryption and authentication. The encryption protocol is called Encapsulated Security Payload (ESP) and can also be used for authentication. The authentication portion is called the Authentication Header (AH) and can only be used for authentication. In the example below we are going to use both ESP and AH. It has been demonstrated that Encryption without Authentication can open possibilities of active attacks that may allow the breaking of the encryption.
Another important thing to know about IPSec is the Key Exchange. The two main methods of key exchange are Manual Key Exchange (MKE) and Automatic Key Exchange (AKE). When the choice is MKE, the administrator must set the keys for the communication; this method is mostly used when debugging the software that implements IPSec, but not used often on general IPSec connections. The most used method is AKE. Besides being easier for the administrator, AKE is much more secure than MKE as the key can be changed automatically every few minutes, without shutting down the connection. Manually generated keys must be exchanged between the machines using IPSEC, meaning the administrator must find a way for taking the key from one machine to another without leaving it being exposed on the network. This does not happen all the time. Some Automatic Key Exchange Protocols: IKE - the Internet Key Exchange protocol - not the best protocol, but the most used; ISAKMP - the Internet Security Association and Key Management Protocol - also used quite often, and also has some known flaws; Photuris, although still experimental, is one of the best protocols for key exchange, and is currently implemented in OpenBSD's IPSec.
IPSec can work in Tunneling Mode or Transport Mode. Both behave the same with regards to key exchange, encryption and authentication. In Tunneling Mode the end hosts do not need to have IPSec implemented, they just have to route the packets to gateways that talk to each other through IPSec interfaces. Transport Mode differs from Tunneling Mode in a way that every host has IPSec interfaces.
There are many different implementations of IPSec, with different resources. Bellow is a brief list with some of the most popular implementations.
OpenBSD comes with IPSec. For a list with 41 different IPSec implementations, go to: http://www.mit.edu/~tytso/ipsec/results9710.html
Now that the basic issues about IPSec have been covered, next comes the practical part: setting up an example. For this you are going to need at least three machines connected on the same network. If you are going to use a switch instead of a hub, you will have to use one of the machines as a gateway between the other two, like two machines, on two networks, talking to each other. These machines should be using Linux (kernel 2.0.38).
So, let's do it step by step, follow the steps below on two machines:
Let's work a little with the third machine. First of all, download and install Sniffit from: http://reptile.rug.ac.be/~coder/sniffit/sniffit.html. Learn how to use it, it is a very good tool.
Now you have three machines, two with IPSec and one with a sniffer. The final example on this article is an analysis of the traffic with and without IPSec.
With the IPSec interfaces down (ipsec auto --down left-right) and with your sniffit running on machine three, telnet from machine one to machine two. See how open is the traffic? Well, you probably could see your password going out clearly.
Now start the IPSec interfaces like you did on step #9 above. With you sniffit running on machine three, telnet from machine one to machine two. Can you see the difference? If you generated the key with ranbits 256 you are seeing your traffic encrypted with a 256 bits key.
For interoperation of FreeS/WAN with other implementations of IPSec, check out: http://www.freeswan.org/freeswan_trees/freeswan-1.3/doc/compatibility.html#intero
If you want to learn more about IPSec and other implementations, below are some resources that I found useful:
Requests For Comment: RFC-2401: Security Architecture for the Internet Protocol RFC-2411: IP Security Document Roadmap Internet Engineering Task Force Drafts: draft-ietf-ipsec-policy-schema-00: IPsec Policy Schema draft-ietf-ipsec-dhcp-04: DHCP Configuration of IPSEC Tunnel Mode
IPSec is going to be embedded in IPv6, so it is probably going to be a standard soon. An Internet that reduces the possibilities of eavesdropping and protects the privacy of the users is a promise that IPSec can partly fulfill. With this article as starting point, you can learn how to setup IPSec gateways and tunnels. I strongly recommend reading the IPSec man pages on OpenBSD, if you plan to build a secure gateway.
This article originally appeared on SecurityFocus.com -- reproduction in whole or in part is not allowed without expressed written consent.