Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Building And Integrating Virtual Private Networks With Openswan (2006).pdf
Скачиваний:
73
Добавлен:
17.08.2013
Размер:
4.74 Mб
Скачать

2

Practical Overview of the IPsec Protocol

The focus of this chapter is on the cryptographic theories and IPsec protocols you need to know about as a system administrator. We will not look at detailed mathematical formulas but instead will explain the basics of cryptography so that you can understand the key management and packet processing performed by the IPsec protocols. References to all the appropriate RFCs and drafts are in the appendix, so those who want to dive deep into the mathematical core of cryptography can do so.

A Very Brief Overview of Cryptography

Normal IP packets consist of the IP header and the IP data, or payload. The IP header contains information about where the packet came from, where it should be going to, what kind of (sub-) protocol the packet has, the size of the packet, the time-to-live (TTL, sometimes called hopcount), some option bits that tweak little things, and finally an extra verification number, called the checksum. The checksum is a simple addition of all numbers in the IP packet. If one number gets accidentally changed during transmission, the checksum will be different, allowing the packet to be recognized as 'broken'.

Practical Overview of the IPsec Protocol

For instance, this packet could be a UDP packet, in which case the protocol field in the IP header would have the value 17. It has a source and destination IP address, and a source port and destination port, since the UDP protocol uses ports. Within the header, there is a checksum that can be used by routers to see if the packet has been mangled. If so, the packet is dropped. Even though the checksum detects mangling that happens by accident, it is not sufficient to protect against the packet being altered, since if someone wants to change a packet, they can simply calculate what the new checksum needs to be and alter that as well. To protect against malicious packet tampering, one needs to have a stronger method for verifying the packet than a simple checksum. This is where cryptographic functions come into play. Instead of a simple checksum that everyone can generate, we need to add some kind of cryptographic checksum that only the sender and receiver know how to make and verify.

Valid Packet Rewriting

There is, however, a catch with this idea of a checksum that can only be made and checked by sender and receiver. As transmitted packets travel across the network, they are not immutable and some items in the IP header can change quite legitimately.

Probably the most important is the time-to-live (TTL). When a packet is passed along by a router, it must decrease its TTL value by 1. If that value would become 0, the packet has traveled over too many hops and is dropped. A special control packet, using the ICMP protocol, is sent back to the sender notifying it of the lost packet. The whole idea of TTL is to ensure packets don't travel in loops on the Internet for ever.

Other parts that may be changed are those that handle quality-of-service issues. Some networks may treat certain types of packets as less important, by giving such packets a lower priority. They can set QoS bits in the header to indicate these policies to their devices.

Ciphers

Ciphers and algorithms are the two main types of cryptographic functions used with IPsec. A cipher is nothing more than a deterministic scrambling scheme. If you have an unencrypted value X (the plaintext) and you push it through a cypher box, you get a scrambled text Y (the ciphertext). The sizes of the plaintext and the ciphertext are the same.

An often-used toy cipher is called ROT13. The ROT13 cipher works like this: Replace all letters with the letter 13 spaces further in the alphabet. If you get to Z, continue counting at A. If we put 'ABC' through this cipher, we could get 'NOP. If we put 'NOP' through our ROT13 cipher, we would get 'ABC'.

The problem is that the security of our cipher lies in the secrecy of it. Anyone who knows, or works out, how our secret cipher works, is able to decipher all our messages. It is very dangerous to rely on the secrecy of a cipher. You cannot ask a lot of people (mathematicians or cryptanalysts) whether your cipher is good without betraying your secret. And cryptography is deemed too difficult for a single person to securely invent in their basement.

A more common type of cipher is one where the cipher method is not a secret, and is known to everyone, but the cipher takes two inputs instead of one. One input is the plaintext, and the other

28

Chapter 2

input is a secret only known by the two parties involved. This secret is called a key, in this case a secret key. The cipher mangles the plaintext with the key and the result is the ciphertext. The receiver uses the same key and the ciphertext as input to the cipher to recreate the plaintext. This is called a symmetric cipher. Because of the use of a secret key, we do not need to keep the cipher secret. We only need to keep our key secret. And if someone steals our key, we can just decide on another key to use; we do not have to throw away the cipher.

DES, 3DES, and AES

The first cipher to enter widespread use throughout the world was DES, the Digital Encryption Standard. It was designed by IBM in the seventies, and slightly (but crucially!) modified by the NSA. Since then, computers have become much more powerful and DES is no longer secure against a brute force attack. This is an attack where all possible keys are tried on the ciphertext until the attacker stumbles upon the plaintext when they happen to use the right key.

Most installations using DES switched to triple-DES (3DES) years ago. Recently, the Rijndael cipher was chosen as the successor for DES, also called the Advanced Encryption Standard (AES) by the National Institute of Standards and Technology (NIST) in the US.

Algorithms

The cryptographic algorithms used with IPsec are mathematical one-way functions. A one-way function, like a cipher, takes an input and produces an output, but unlike a cipher, you cannot use the output and any other function to obtain the input. Hence the name 'one-way'. In IPsec terminology, these are often called the algorithms.

These types of algorithms are frequently used to make secure checksums for data. Again, the security of the algorithm does not lie with its secrecy, but in the fact that it is next to impossible to modify the input in such a way that it produces the same output. Algorithms that create a much shorter output than input are called hash functions. The two most commonly used hash algorithms are Message Digest 5 (MD5) and Secure Hashing Algorithm 1 (SHA1).

Recently a lot of media attention has focused on how MD5 and SHA1 have been hacked or broken. The truth is slightly less worrying. Researchers have found 'collisions' in these functions, which means that someone could find another plaintext that has the same MD5 or SHA1 hash as the original plaintext. However this does not mean it's possible to swap the plaintext with any other arbitrary plaintext at will. The implementation in IPsec uses a sequence number scheme called HMAC, which makes it even harder to find the proper alternative plaintext that would pass the MD5 or SHA1 algorithm.

MD5 and SHA1 are still safe algorithms to use for IPsec, but if a newer algorithm becomes available and you can use it, it is recommended to switch. A likely candidate for inclusion in the near future is SHA-256 or SHA-512.

29

Practical Overview of the IPsec Protocol

Uniqueness

One way eavesdroppers could still manipulate a secure communication would be to capture valid communication, and even though they cannot read this captured communication, to resend it. Since these resent packets are valid, digitally encrypted packets, they will pass the checks for proper authentication. This might disrupt the secure communication, or trigger other responses. This is called a replay attack. One way to avoid it is to add a counter to all the packets before running them through the cipher. Every time the counter is used, it is increased. This way, a replayed packet can be correctly identified as an old packet, and can be discarded.

Public-Key Algorithms

Of course, using a secret key is a Catch 22 situation. If you could communicate the secret key securely, you would not need a new form of encrypted communication to begin with. The solution to this problem was invented by Diffie and Hellman around the time DES was introduced. Without going into too much mathematical detail, the idea is to generate two very large numbers and use a one-way function in such a way that using one of the numbers as input to the function gives a ciphertext, but if you have the second large number, you can actually reverse the one-way function. This second number is a so-called 'trap door'.

The first large number you can give away to everyone, and is called the public key. The second number is your private key, and no one but you should know it. People can use the public key to encrypt a message that only you can decrypt with the private key.

Exchanging Public Keys

If two parties (by convention known as Alice and Bob) have never securely exchanged each other's public key, then they have a problem to solve before they can communicate. How do they know that they are talking to the person that they think they are talking to? How can each be sure that they are not talking to a 'man in the middle'? A man in the middle (often called Mallory) is someone who pretends he is Bob to Alice, and pretends he is Alice to Bob.

Digital Signatures

This public key encryption scheme can even be extended. Using a more complex algorithm, such as RSA or DSA, the private key can also be used to create a digital signature. The principle of a digital signature is similar to that of a handwritten signature. The assumption is that only the person represented by the signature is able to produce a correct signature. If your signature appears on a piece of paper, and it matches the reference signature that is on file that you have made in the past in the presence of a notary or bank employee, then it is assumed that only you could have written that signature, so therefore you signed that piece of paper. For a digital signature, the same assumption is used. Anyone with the public key can verify a digital signature, but only the person with the private key can make it.

Diffie-Hellman Key Exchange

The Diffie-Hellman (DH) key exchange allows you to exchange a secret key over a public channel, and thereby gain privacy no matter who listens in on this DH key exchange.

30