Monday, April 30, 2007

IPsec (IP Security)

IPsec (IP security) is a suite of protocols for securing Internet Protocol (IP) communications by authenticating and/or encrypting each IP packet in a data stream. IPsec also includes protocols for cryptographic key establishment.

Summary

IPsec protocols operate at the network layer, layer 3 of the OSI model. Other Internet security protocols in widespread use, such as SSL and TLS, operate from the transport layer up (OSI layers 4 - 7). This makes IPsec more flexible, as it can be used for protecting both TCP- and UDP-based protocols, but increases its complexity and processing overhead, as it cannot rely on TCP (OSI layer 4) to manage reliability and fragmentation.

Modes

There are two modes of IPsec operation: transport mode and tunnel mode.

Transport mode

In transport mode only the payload (message) of the IP packet is encrypted. The routing is intact since the IP header is neither modified nor encrypted; however, when the Authentication Header is used, the IP addresses cannot be translated, as this will invalidate the hash value. The transport and application layers are always secured by hash so they cannot be modified in any way (for example by translating the port numbers). Transport mode is used for host-to-host communications.

A means to encapsulate IPsec messages for NAT traversal has been defined by RFC documents describing the NAT-T mechanism.

Tunnel mode

In tunnel mode, the entire IP packet is encrypted. It must then be encapsulated into a new IP packet for routing to work. Tunnel mode is used for network-to-network communications (secure tunnels between routers) or host-to-network and host-to-host communications over the Internet.

Security architecture

IPsec is implemented by a set of cryptographic protocols for (1) securing packet flows and (2) internet key exchange. Of the former, there are two.

Current status as a standard

IPsec is a mandatory part of IPv6, and is optional for use with IPv4. While the standard is designed to be indifferent to IP versions, current widespread deployment and experience concerns IPv4 implementations. IPsec protocols were originally defined by RFCs 1825–1829, published in 1995. In 1998, these documents were obsoleted by RFCs 2401–2412. 2401–2412 are not compatible with 1825–1829, although they are conceptually identical. In December 2005, third-generation documents, RFCs 4301–4309, were produced. They are largely a superset of 2401–2412, but provide a second Internet Key Exchange standard. These third-generation documents standardized the abbreviation of IPsec to uppercase “IP” and lowercase “sec”.

It is unusual to see any product that offers RFC1825–1829 support. “ESP” generally refers to 2406, while ESPbis refers to 4303.

Design intent

IPsec was intended to provide either transport mode: end-to-end security of packet traffic in which the end-point computers do the security processing, or tunnel mode: portal-to-portal communications security in which security of packet traffic is provided to several machines (even to whole LANs) by a single node.

IPsec can be used to create Virtual Private Networks (VPN) in either mode, and this is the dominant use. Note, however, that the security implications are quite different between the two operational modes.

End-to-end communication security on an Internet-wide scale has been slower to develop than many had expected. Part of the reason is that no universal, or universally trusted, Public Key Infrastructure (PKI) has emerged (DNSSEC was originally envisioned for this); part is that many users understand neither their needs nor the available options well enough to promote inclusion in vendors' products.

Since the Internet Protocol does not inherently provide any security capabilities, IPsec was introduced to provide security services such as:

  1. Encrypting traffic (so it cannot be read by parties other than those for whom it is intended)
  2. Integrity validation (ensuring traffic has not been modified along its path)
  3. Authenticating the peers (ensuring that traffic is from a trusted party)
  4. Anti-replay (protection against replay of the secure session)

Technical details

Authentication Header (AH)

The AH is intended to guarantee connectionless integrity and data origin authentication of IP datagrams. Further, it can optionally protect against replay attacks by using the sliding window technique and discarding old packets. AH protects the IP payload and all header fields of an IP datagram except for mutable fields, i.e. those that might be altered in transit. In IPv4 mutable, and therefore unauthenticated, IP header fields include TOS, Flags, Fragment Offset, TTL and Header Checksum. AH operates directly on top of IP using IP protocol number 51. The IP protocol doesn't need IPSec by itself.

An AH packet diagram:

0 - 7 bit 8 - 15 bit 16 - 23 bit 24 - 31 bit
Next Header Payload Length RESERVED
Security Parameters Index (SPI)
Sequence Number

Authentication Data (variable)

Field meanings:

Next Header
Identifies the protocol of the transferred data.
Payload Length
Size of AH packet.
RESERVED
Reserved for future use (all zero until then).
Security Parameters Index (SPI)
Identifies the security parameters in combination with IP address which then identify the Security Association implemented with this packet.
Sequence Number
A monotonically increasing number, used to prevent replay attacks.
Authentication Data
Contains the integrity check value (ICV) necessary to authenticate the packet and may contain padding.

Encapsulating Security Payload (ESP)

The Encapsulating Security Payload (ESP) extension header provides origin authenticity, integrity, and confidentiality protection of a packet. ESP also supports encryption-only and authentication-only configurations, but using encryption without authentication is strongly discouraged. Unlike the AH header, the IP packet header is not accounted for. ESP operates directly on top of IP using IP protocol number 50.

An ESP packet diagram:

0 - 7 bit 8 - 15 bit 16 - 23 bit 24 - 31 bit
Security Parameters Index (SPI)
Sequence Number


Payload Data (variable)



Padding (0-255 bytes)


Pad Length Next Header

Authentication Data (variable)


Field meanings:

Security Parameters Index (SPI)
Identifies the security parameters in combination with IP address
Sequence Number
A monotonically increasing number, used to prevent replay attacks.
Payload Data
The data to be transferred.
Padding
Used with some block ciphers to pad the data to the full length of a block.
Pad Length
Size of padding in bytes.
Next Header
Identifies the protocol of the transferred data.
Authentication Data
Contains the data used to authenticate the packet.


No comments: