Ipsec Basics: Sorin M. Schwartz Seminars
Ipsec Basics: Sorin M. Schwartz Seminars
schwartz
seminars
IP Sec Basics
page 1 of 11
IPsec basics
by Sorin M. SCHWARTZ
IPSec is a bundle of protocols and algorithms defining a flexible framework in which it is the user who
selects the actual parameters of the algorithms and methods to be used.
As a result, one should assume that two IPSec implementation instances are not necessarily identical.
IPsec is defined in RFC 2401 to 2411 and 2451.
In a communications network, security has a few different aspects, the most important being:
Authentication
Integrity
Confidentiality
Making sure that the data received is indeed coming from the expected
partner
(avoiding unauthorized sources to transmit data to a station)
Making sure that the data received is indeed what was transmitted by
the source
(avoiding modifications to the data by unknown parties, executed while
the data traveled from source to destination)
Making sure that receivers identify and discard packets that have been
already received
(avoiding multiple executions of same command, generated by
unknown parties)
Making sure that nobody listens and understands the data on its way
from source to destination
IPsec addresses all the above services and defines the necessary tools for their provision.
The basic idea of IPsec is to mark packets before being injected into the communications network, and
use this mark at the receiving side in order to decide whether the packet arrived from the correct source
(authentication), whether the packet content is exactly the one generated by the source, without any
modifications (integrity) and whether the packet is not a replay of one of the previous packets, already
received (rejection of replayed data).
In addition, IPsec also defines a framework for data encryption ensuring that potential listeners in the
network would not be able to understand the information carried in the packet (confidentiality).
The marking process results in new fields being added to the packet to be protected.
sorin m. schwartz
seminars
IP Sec Basics
page 2 of 11
The "marking" of the packets before their transmission may be executed by:
- the user computer (client), or by
- the ingress edge router (the first router met by the transmitted packet, the router connecting the user to the
communications network)
When the user computer is the one marking the transmitted packets, it is said that IPsec is used in
transport mode.
When the ingress router is doing the job on behalf of the user (acting as a proxy IPsec entity), it is said that
IPsec is used in tunnel mode.
R1
user A
R
R
ingress
router for
user A
user B
R2
sorin m. schwartz
seminars
IP Sec Basics
page 3 of 11
Definitions
- Hash function - a function that takes variable length input data and produces fixed length output data (=
the hash value of the original input data) that can be regarded as the fingerprint of the input
data.
Hash functions should be collision resistant, i.e. it should be hard to find two different inputs
generating the same hash value.
variable length
input data
hash
function
fixed length
output data
Hash function
variable length
input data
hash
function
fixed length
output data
encryption
function
fixed length
output data
encryption key
MAC function
sorin m. schwartz
seminars
IP Sec Basics
page 4 of 11
packet
(IP header +
payload)
packet
variable
length
input data
hash
function
fixed
length
output
data
(128 or
160
bits)
encryption
key
encryption
function
HMAC-SHA-196
MAC
sorin m. schwartz
seminars
IP Sec Basics
page 5 of 11
Received packet
packet
variable
length
input data
hash
function
YES
accep
t
fixed length
output data
(128 or 160 bits)
same
value?
decryption key
(associated with
the encryption
key used by
transmitter)
NO
reject
decryption
function
The receiving party calculates the hash value of the received packet. If the packet has not been tampered
with, the hash value calculated at the reception should be the SAME as the hash value calculated by the
transmitter.
The hash value as calculated by the transmitter is not available in the packet . . . but its encrypted value is
there (the ICV).
Applying the decryption key (that has been agreed between the parties as being the one to be used for
decoding messages arriving from that specific user) to the ICV, should result in the SAME hash value as the
one calculated at transmitter!
If the values are indeed equal, the decoding process is considered to be successful, and the packet is
accepted.
Packets for which the two values are different are considered as being corrupted, and are therefore
rejected.
sorin m. schwartz
seminars
IP Sec Basics
page 6 of 11
Confidentiality principles
Confidentiality is obtained by encrypting the packet to be protected. Receiving party, and only it, should be
able to decrypt the packet. Some identifiers, should however remain unencrypted, allowing the receiving
party to identify the packet and to decode it with the correct algorithm, key, etc.
sorin m. schwartz
seminars
IP Sec Basics
page 7 of 11
IP Sec new
IP header
DA = R2
SA = R1
IP Sec
marking
original
IP header
DA = B
SA = A
original
IP header
DA = B
SA = A
original
payload
IP Sec
marking
authentication
protected
original
IP header
DA = B
SA = A
authentication
protected
confidentiality
protected
(encryption)
original
payload
confidentiality
protected
(encryption)
original
payload
IP Sec
marking
IP Sec
marking
Original packet to be
protected
TRANSPORT mode
(protection available
end-to-end)
TUNNEL mode
(protection available
router-to-router)
Depending on the specific IP Sec protocol used, and the selected mode (transport or tunnel), IP Sec
marking appears in different locations in the protected packet.
When authentication is used, the marking protects the whole packet.
When confidentiality marking is used, the transport and tunnel mode provide different types of services.
In transport mode the encryption process is executed by the end station, and routers in the network are
expected to route the encrypted packet toward its destination.
As a result, the encrypting station CAN NOT encrypt the IP header, as it includes the vital information
needed by routers for correct operation. The only part that can be protected in this case is the payload itself
(the upper layers).
In tunnel mode the encryption process is executed by the ingress router, and the resulting packet is sent
via the network to another router (the other end of the tunnel) as indicated in a NEW IP header, added by
the ingress router.
As a result, the ingress router CAN encrypt the WHOLE original packet (payload AND original IP
addresses).
sorin m. schwartz
seminars
IP Sec Basics
page 8 of 11
Both authentication and confidentiality services are based on packet marking executed at transmission site,
followed by decoding executed at the receiving site.
R1
user A
R
R
user B
R2
- Authentication Header protocol (RFC 2402) - provides marking for authentication, integrity
and replay protection
2.- ESP - Encapsulating Security Payload (RFC 2406) - provides marking for authentication, integrity and
replay protection
as well as for confidentiality.
As both authentication and encryption algorithms imply the use of encryption keys, one more element is
needed: a protocol to handle the encryption key selection and other administrative issues related to the
creation and maintenance of a Security Association between nodes.
3.- IKE - Internet Key Exchange (RFC 2409) - establishes and maintains Security Associations.
sorin m. schwartz
seminars
IP Sec Basics
page 9 of 11
AH packet format
IPv4 packet after AH processing
in TUNNEL mode
original IP header
(protocol field = TCP)
original IP header
(protocol field = 51)
new IP header
(protocol field = 51)
Next header = IP
data
Payload length
Payload length
Reserved
Reserved
authenticated
AH authentication data
(Integrity Check Value ICV)
AH authentication data
(Integrity Check Value ICV)
original IP header
(protocol field = TCP)
data
sorin m. schwartz
seminars
IP Sec Basics
page 10 of 11
original IP header
(protocol field = TCP)
original IP header
(protocol field = 50)
new IP header
(protocol field = 50)
data
authenticated
Sequence number
encrypted
Sequence number
original IP header
(protocol field = TCP)
data
Pad length
Next header = TCP
encrypted
pad
data
pad
Pad length
Next header = IP
ESP authentication data
(Integrity Check Value ICV)
(optional)
- SPI - Arbitrary value that, together with the IP DA of the packet, identifies the actual Security Association (SA) to
which the packet belongs.
- Stations identify the SA to be used for the processing of an incoming packet, based on:
- IP DA
- SPI
- security service (as indicated by the protocol value in the field preceding the security header - AH or ESP)
- Sequence number - avoids replay of the packet
- Pad length
- Next header - type of payload in the packet
- Authentication data - includes Integrity Check Value (ICV), used to authenticate the packet
sorin m. schwartz
seminars
IP Sec Basics
page 11 of 11
Protocol
Operation mode
Encryption
Integrity
Life time
Party #1
Party #2
21
xxxx
yyyy
75
zzzz
www
w