Because IPsec is implemented at the IP layer, it can provide protection to any IP protocol including TCP and UDP. The security services that IPsec provides are:
IPsec is made up of three protocols, each of which is defined as a framework that defines packet layouts and field sizes and is suitable for use by multiple cryptographic algorithms. The protocols themselves do not define specific cryptographic algorithms to use, although every implementation is required to support a specified set of algorithms. The protocols that make up IPsec are:
The Internet Security Association Key Management Protocol (ISAKMP)
The Encapsulating Security Payload (ESP) protocol provides confidentiality (encryption) and limited protection against traffic flow analysis. ESP also includes some of the services normally provided by AH. Both AH and ESP rely on the availability of shared keys, and neither one has a way to move them from one machine to another. Generating these keys is handled by the third IPsec protocol, the ISAKMP.
ISAKMP is also a framework protocol; it doesn't by itself define the algorithms that are used to generate the keys for AH and ESP. The Internet Key Exchange (IKE) protocol uses the ISAKMP framework with specific key exchange algorithms to set up cryptographic keys for AH and ESP. This layering may seem confusing and overly complicated, but the separation of ISAKMP from IKE means that the same basic IPsec framework can be used with multiple different key exchange algorithms (including plain old manual key exchange). The standardization of IKE allows different people to implement the same key exchange algorithms and be guaranteed interoperability. The Linux FreeS/WAN project has an implementation of IKE called Pluto.
In IPv6 the AH and ESP protocols can be used simultaneously, with an IPv6 feature called header chaining, to provide authentication modes that ESP alone cannot provide. When they are used in this way it is recommended that ESP be wrapped by the additional AH header. In IPv4, it's not possible to use them both at once (you can have only one header at a time).
IPsec provides two operating modes for AH and ESP, transport and tunnel. In transport mode, AH or ESP occur immediately after the IP header and encapsulate the remainder of the original IP packet. Transport mode works only between individual hosts; the packet must be interpreted by the host that receives it. Transport is used to protect host-to-host communications. Hosts can use it to protect all of their traffic to other cooperating hosts, or they can use it much the way TLS is used, as a protection layer around specific protocols.
In tunnel mode, the entire original packet is encapsulated in a new packet, and a new IP header is generated. IPsec uses the term security gateway for any device that can operate in tunnel mode. This term applies to all devices that can take IP packets and convert them to and from the IPsec protocols, whether they are hosts or dedicated routers. Because the whole IP packet is included, the recipient can forward packets to a final destination after processing. Tunnel mode is used when two security gateways or a gateway and a host communicate, and it is what allows you to build a virtual private network using IPsec.
The AH and ESP protocols each contain a 32-bit value that is called the Security Parameter Index (SPI). This is an identifier that is used to distinguish between different conversations going to the same destination. Every IPsec implementation is required to be able to independently track security parameters for the combination of SPI, destination IP address, and the security protocol that is being used (either AH or ESP). This combination of parameters is called a Security Association (SA). It is the responsibility of the specific ISAKMP key management protocol to negotiate and set the cryptographic parameters, including the SPI, for each Security Association.
An SA is effectively the collection of the cryptographic keys and parameters for use by either AH or ESP:
Direction | Source Addr. | Dest. Addr. | Protocol | Source Port | Dest. Port | Notes |
---|---|---|---|---|---|---|
In | Ext | Int | AH |
[36]
|
Incoming AH, client to server | |
Out | Int | Ext | AH | Incoming AH, server to client | ||
In | Ext | Int | ESP | Incoming ESP, client to server | ||
Out | Int | Ext | ESP | Incoming ESP, server to client | ||
In | Ext | Int | UDP | 500 | 500 | Incoming ISAKMP request |
Out | Int | Ext | UDP | 500 | 500 | ISAKMP response |
Out | Int | Ext | AH | Outgoing AH, client to server | ||
In | Ext | Int | AH | Outgoing AH, server to client | ||
Out | Int | Ext | ESP | Outgoing ESP, client to server | ||
In | Ext | Int | ESP | Outgoing ESP, server to client | ||
Out | Int | Ext | UDP | 500 | 500 | Outgoing ISAKMP request |
In | Ext | Int | UDP | 500 | 500 | ISAKMP response |
[36]AH and ESP do not have source or destination ports.You may note that the table does not include information about the setting for the ACK bit. UDP has no equivalent of the TCP ACK bit. When TCP packets are incorporated into AH packets, their flags will still be present; it would be theoretically possible for a firewall that understood AH to use those ACK bits to determine the direction of the TCP connections and to filter using this information. Similarly, TCP and UDP packets in AH will have their original source and destination ports available for filtering.
It is, however, possible to use regular IP to the proxy system and have it speak IPsec to the destination. In addition, IPsec could be used with SOCKS. In this configuration, the client would set up communications with the SOCKS server via IPsec, and the SOCKS server would set up a separate IPsec communications channel to the final destination. However, this double use of IPsec may require significant CPU resources to implement.
Therefore, you can combine network address translation and IPsec tunneling, as long as you do the network address translation first and then set up the IPsec tunnel. (Using IPsec parlance, it would be possible to implement network address translation behind or on a security gateway.)