IP Security
You cannot talk about VPNs without saying something about IP Security (IPSec). IPSec is a framework of open standards. It is not bound to any specific encryption or authentication algorithm keying technology. IPSec acts on the network layer, where it protects and authenticates IP packets between participating peers such as firewalls, routers, or concentrators. IPSec security provides four major functions:
- Confidentiality
The sender can encrypt the packets before transmitting them across the network. If such a communication is intercepted, it cannot be read by anybody. - Data integrity
The receiver can verify whether the data was changed while traveling the Internet. - Origin authentication
The receiver can authenticate the source of the packet. - Antireplay protection
The receiver can verify that each packet is unique and is not duplicated.
Encryption
When packets are traveling on the Internet, they are vulnerable to eavesdropping. Clear-text messages can be intercepted and read by anybody. Therefore, to keep the data secure, it can be encrypted. For encryption to work, both the sender and the receiver need to know the rules that were used to encrypt the original message. This is explained in more detail in Chapter 4, "Cryptography." There are two types of encryption:
- Symmetric
- Asymmetric
With symmetric key encryption, each peer uses the same key to encrypt and decrypt data. With asymmetric key encryption, each peer uses a different key to encrypt and decrypt the message. Both the Data Encryption Standard (DES) and Triple DES (3DES) require a symmetric shared secret key. The problem is then to give those keys to both users. The keys can be sent by mail, courier, or public key exchange. The easiest method to exchange the key is Diffie-Hellman public key exchange. This key exchange provides a way for the users to establish a shared secret key, which only they know, although they are sending it over an insecure channel.Public key cryptosystems rely on a two-key system:
- A public key, which is exchanged between the users
- A private key, which is kept secret by the owners
The Diffie-Hellman public key algorithm states that if user A and user B exchange public keys and combine them with their private keys, the end result should be the same. This is shown in Figure 12-5.
Figure 12-5. Diffie-Hellman Key Exchange
[View full size image]

Data Integrity
Data integrity is also a critical function of VPN because data is sent over a public network and can be intercepted and modified. To guard against this interception, every message has an attached hash. This hash guarantees the integrity of the message. The receiver checks this by comparing the received hash with the hash it calculates from the message itself. If both values are equal, the message has not been tampered with. However, if there is no match, the receiver knows that the message was altered.IPSec uses the Hashed Message Authentication Codes (HMAC) protocol to calculate the hash. At the sender's end, the message and the shared key are sent through a hash algorithm, which produces a hash value. Basically, this hash algorithm is a formula used to convert a variable-length message into a fixed-length hash. It is also important to understand that this is a one-way function. A message can produce a hash, but a hash cannot produce the original message. After the hash is calculated, it is sent over the network together with the message. At the other end, the receiver performs the same action. It sends the message and the shared key through the hash algorithm and then compares the two hashes to verify whether they match.Two HMAC algorithms are commonly used:
- HMAC-MD5
This protocol uses a 128-bit shared key. The key and the message are combined to a 128-bit hash. - HMAC-SHA-1
This protocol uses a 160-bit shared key. The length of the hash is 160 bits. This protocol is considered stronger because of the longer key.
Origin Authentication
Another important function is origin authentication. Before the electronic era, a seal or a signature on a letter guaranteed its origin. In the electronic era, a document is signed with the sender's private encryption key. This is also called a digital signature . This signature can be authenticated by decrypting it with the sender's public key. When doing business over a long distance, it is important to know who is at the other side of the phone, fax, and so on. The same is true for VPNs. The devices at the other end of the tunnel must be authenticated before the path is considered secure. There are three peer authentication methods:
- Preshared keys
A secret key is entered into each peer manually. - RSA signatures
The exchange of digital certificates authenticates the peers. - RSA encryption nonces
Nonces (a random number generated by the peers) are encrypted and then exchanged between peers. The two nonces are used during the peer authentication process.
Preshared Keys
If preshared keys are used, the same key is configured on each IPSec peer. At each end, the preshared keys are combined with other information (device-specific information) to form the authentication key. They are both sent through a hash algorithm to form a hash. Then the hash is sent to the other site, as you can see in Figure 12-6.
Figure 12-6. Preshared Keys

RSA Signatures
With RSA signatures, both hashes are not only authenticated but also digitally signed. Digital certification is discussed in Chapter 13, "Public Key Infrastructure." At the local end, the authentication key and identity information are sent through the hash algorithm to form the hash, a process similar to that used with preshared keys. But with RSA signatures, the hash is then encrypted using the local peer's private key. The result of this procedure is a digital signature, as you can see in Figure 12-7. The digital signature and a digital certificate are both forwarded to the other site. The public encryption key that is also used to decrypt the signature is included in the digital certificate.
Figure 12-7. RSA Signatures
[View full size image]

RSA-Encrypted Nonces
RSA-encrypted nonces require that each site generate a nonce. As stated previously, a nonce is a pseudorandom number. The generated nonces are then encrypted and exchanged. When the other side receives the nonces, it makes an authentication key from both nonces and some other information. That nonce-based key is then combined with device-specific information and run though the hash algorithm, as shown in Figure 12-8. After this, the process is similar to that used for RSA signatures.
Figure 12-8. RSA-Encrypted Nonces

Antireplay Protection
Antireplay protection verifies that each packet is unique and not duplicated. IPSec packets are protected by comparing the sequence number of the received packets and a sliding window on the destination host. Packets in which the sequence number is before the sliding window are considered late, or duplicate. These packets are dropped.
Protocol Framework
The previous sections discussed encryption, integrity, and authentication. Now let's apply these three concepts to the IPSec protocol suite. IPSec is a framework of open standards. IPSec relies on existing technology, such as DES and 3DES, to secure the communication between two entities. There are two main IPSec framework protocols available:
- Authentication header (AH)
- Encapsulating security payload (ESP)
AH
AH is the protocol to use when confidentiality is not required. It provides data authentication and integrity for IP packets between two systems. It verifies that the origin of the packet is correct and that the packet is not modified during transport. It does not encrypt the data packet, so the text is transported in clear text.Authentication is achieved by using a one-way hash function to create a message digest. The hash is then combined with the text and transmitted to the other site. When the packet reaches its destination, the receiver performs the same one-way hash function and compares the result with the message digest that the sender has supplied. Because the one-way hash uses a symmetric key between the two systems, the authenticity of the packet is guaranteed. The AH function is applied to the entire datagram, except for some header fields that change in transit, such as the Time-To-Live field. The workings of AH are shown in Figure 12-9 and are spelled out in the following steps:
Step 1. | The IP header and data payload are hashed. |
Step 2. | The hash is used to build the AH, which is inserted into the original packet. |
Step 3. | The modified packet is send to the peer router. |
Step 4. | The peer router hashes the IP header and data payload. |
Step 5. | The router extracts the transmitted hash from the AH. |
Step 6. | The peer router compares the two hashes. The hashes have to match exactly to prove that the packet was not modified during transport. |
Figure 12-9. AH
[View full size image]

ESP
ESP can be used to provide encryption and authentication. It provides confidentiality by performing encryption at the IP packet layer. ESP provides authentication for the IP packet payload and the ESP header. As with AH, ESP verifies the following: that the packet originated from where it declares it did, that it is what it declares it is, and that the packet was not modified during transport.ESP provides confidentiality by encrypting the payload. It supports several symmetric encryption algorithms. The default for IPSec is 56-bit DES, but Cisco products also support 3DES and AES for stronger encryption. ESP can be used alone or in combination with AH. Between two security gateways, the original data is well protected because the entire IP packet is encrypted. An ESP header and trailer are added to the encrypted payload, as shown in Figure 12-10.
Figure 12-10. ESP
[View full size image]

Tunnel or Transport Mode
Both ESP and AH can be applied to IP packets in two different ways:
- Transport mode
- Tunnel mode
These two different modes provide a further level of authentication or encryption support to IPSec. The sections that follow discuss these two IPSec modes in more detail.
Transport Mode
This mode is primarily used for end-to-end connections between hosts or devices acting as hosts. Transport mode protects the payload of the packet but leaves the original IP address readable. This address is used to route a packet through the Internet. Transport mode provides security to the higher layer protocols only. Figure 12-11 shows how transport mode affects AH IPSec connections.
Figure 12-11. AH Transport Mode

Figure 12-12. ESP Transport Mode

Tunnel Mode
IPSec tunnel mode is used between gateways such as routers, PIX firewalls, or VPN concentrators. Tunnel mode is used when the final destination is not a host but a VPN gateway. In this mode, instead of shifting the original IP header to the left and then inserting the IPSec header, the original header is copied and shifted to the left to form a new IP header. The IPSec header is then placed between the new and the original IP headers. The original datagram is left intact. Figure 12-13 shows AH tunnel mode.
Figure 12-13. AH Tunnel Mode

Figure 12-14. ESP Tunnel Mode
[View full size image]

Transform Sets
The protocol that brings all the previously mentioned protocols together is the Internet Key Exchange (IKE) protocol. IKE operates in two separate phases when establishing IPSec VPNs.IKE Phase 1 is responsible for
- Authenticating the IPSec peers
- Negotiating an IKE security association among the peers
- Initiating a secure tunnel for IPSec using the Internet Security Association and Key Management Protocol (ISAKMP)
IKE Phase 2 is responsible for
- Negotiating the set of security parameters for the tunnel
- Creating the IPSec tunnel
Configuring IPSec on a Cisco router is fairly simple. You need to identify some parameters for IKE Phase 1, such as:
- Encryption algorithm
56-bit DES or the stronger 168-bit 3DES - Hash algorithm
MD5 or SHA-1 - Authentication method
Preshared keys, RSA digital signatures, or RSA encrypted nonces - Key exchange method
768-bit Diffie-Hellman group 1 or 1024-bit Diffie-Hellman group 2 - IKE SA lifetime
86,400 seconds or 1 day
These parameters need to be identical on both sides, or the connection will not be established. Once these are configured, the only other values you need to supply to establish the IPSec tunnel in IKE Phase 2 mode are as follows:
NOTEBesides DES and 3DES, a new encryption algorithm is now available, Advanced Encryption Standard (AES). AES comes in three varieties:
- AES
Specifies 128-bit AES as the encryption algorithm - AES192
Specifies 192-bit AES as the encryption algorithm - AES256
Specifies 256-bit AES as the encryption algorithm