26
Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

Embed Size (px)

Citation preview

Page 1: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

Network Security: IPsec

Tuomas AuraT-110.5241 Network security

Aalto University, Nov-Dec 2014

Page 2: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

IPsec:Architecture and protocols

2

Page 3: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

3

Internet protocol security (IPsec)Network-layer security protocol

Protects IP packets between two hosts or gatewaysTransparent to transport layer and applications; security policy defined and enforced on network levelIP addresses used to as host identifiers

Two steps:1. IKE authenticated key exchange creates security associations2. ESP session protocol protects data

Specified by Internet Engineering Task Force (IETF)Original goal: encryption and authentication layer that will replace all othersSecurity (IPsec) was a sales point for IPv6, but it now works just as well for IPv4

Page 4: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

4

PAD PAD

Security associations (SA) created by IKE, used by IPsec ESPSecurity policy guides SA creation and selection for useIPsec is part of the IP layer in the OS kernel; IKE is a user-space service (daemon)

IPSec IPSec

Node A Node B

1. Key exchange

2. ESP protects data

SPD

Security Policy

Database

Untrusted network

SAD

Security Association Database

Security Policy

Database

SPD

SADSecurity

Association Database

IPsec SA Pair

Session Key Session KeyIKE(v2)IKE(v2)IKE SA

IPsec architecture [RFC4301]

Page 5: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

Internet Key Exchange (IKEv2)Initial exchanges (using the notation from the IPsec RFC):

1. I → R: HDR(A,0), SAi1, KEi, Ni 2. R → I: HDR(A,B), SAr1, KEr, Nr, [CERTREQ]3. I → R: HDR(A,B), SK { IDi, [CERT,] [CERTREQ,] [IDr,] AUTHi, SAi2, TSi, TSr }4. R → I: HDR(A,B), SK { IDr, [CERT,] AUTHr, SAr2, TSi, TSr }

A, B = SPI values that identity the protocol run and the created IKE SANx = noncesSAx1 = offered and chosen algorithms, DH group (p and g)KEx = Diffie-Hellman public key (gx or gy)CERTREQ = accepted root CAs (or other trust roots)IDx, CERT = identity, certificateAUTHi = SignI (Message 1, Nr, h(SK, IDi))

AUTHr = SignR (Message 2, Ni, h(SK, IDr))

SK = h(Ni, Nr, gxy) — actually, 6 different keys are derived from thisSK { … } = ESK( …, MACSK(…)) — MAC and encrypt with session key

SAx2, TSx = parameters for the first IPsec SA (algorithms, SPIs, traffic selectors)

Page 6: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

Internet Key Exchange (IKEv2)Initial exchanges:

1. I → R: HDR(A,0), SAi1, KEi, Ni 2. R → I: HDR(A,B), SAr1, KEr, Nr, [CERTREQ]3. I → R: HDR(A,B), SK { IDi, [CERT,] [CERTREQ,] [IDr,] AUTHi, SAi2, TSi, TSr }4. R → I: HDR(A,B), SK { IDr, [CERT,] AUTHr, SAr2, TSi, TSr }

A, B = SPI values that identity the protocol run and the created IKE SANx = noncesSAx1 = offered and chosen algorithms, DH group (p and g)KEx = Diffie-Hellman public key (gx or gy)CERTREQ = accepted root CAs (or other trust roots)IDx, CERT = identity, certificateAUTHi = SignI (Message 1, Nr, h(SK, IDi))

AUTHr = SignR (Message 2, Ni, h(SK, IDr))

SK = h(Ni, Nr, gxy) — actually, 6 different keys are derived from thisSK { … } = ESK( …, MACSK(…)) — MAC and encrypt with session key

SAx2, TSx = parameters for the first IPsec SA (algorithms, SPIs, traffic selectors)

Secret, fresh session key?Mutual authentication?Entity authentication andkey confirmation?Contributory?Perfect forward secrecy?Integrity check for initial negotiation?Non-repudiation or plausible deniability?Identity protection?

Page 7: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

IKEv2 with a cookie exchangeIn the second message, responder may send a cookie (a nonce)Goal: prevent DOS attacks from a spoofed IP address

1. I → R: HDR(A,0), SAi1, KEi, Ni 2. R → I: HDR(A,0), N(COOKIE) // R stores no state3. I → R: HDR(A,0), N(COOKIE), SAi1, KEi, Ni 4. R → I: HDR(A,B), SAr1, KEr, Nr, [CERTREQ] // R creates a state5. I → R: HDR(A,B), SK{ IDi, [CERT,] [CERTREQ,] [IDr,]

AUTH, SAi2, TSi, TSr }6. R → I: HDR(A,B), ESK (IDr, [CERT,] AUTH, SAr2, TSi, TSr)

How to bake a good cookie? For example: COOKIE = h(NR-periodic, IP addr of I, IP addr of R) where NR-periodic is a periodically changing secret random value know only by the responder R

Page 8: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

10

Security Associations (SA)One IKE SA for each pair of nodes

Stores the master key SK = h(Ni, Nr, gxy) for creating IPsec SAs

At least one IPsec SA pair for each pair of nodes Stores the negotiated session protocol, encryption and authentication algorithms, keys and other session parametersStores the encryption algorithm stateIPsec SAs always come in pairs, one in each direction

IPsec SAs are identified by a 32-bit security parameter index (SPI) [RFC4301]

The destination node selects the SPI value

Node stores IPsec SAs in a security association database (SAD)

Page 9: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

11

Session protocol Encapsulated Security Payload (ESP) [RFC 4303]

Encryption and/or MAC for each packet Optional replay prevention with sequence numbers Protects the IP payload (= transport-layer PDU) only

ESP with encryption only is insecure!

Old protocol: Authentication Header (AH) Do not use for new applications Authentication only, no encryption Protects payload and some IP header fields

Page 10: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

13

Session protocol modesTransport modeEncryption and/or authentication from end host to end host

Encrypted

Tunnel modeEncryption and/or authentication between two gateways (VPN)

Encrypted

IPsec gateway IPsec gateway

IntranetIntranet

Internet

Network

Page 11: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

14

Using tunnel mode with hostsTunnel mode - between end hosts (security equivalent to transport mode)

Network

Tunnel mode - between a host and a gateway (typical VPN connection)

IntranetInternet

Untrustedaccess network

IPsec gateway

Page 12: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

16

ESP packet format

IP header ESP header IP header

Original

Encrypted

OriginalOriginal

IP header IP Payload

ESP in transport mode:

ESP in tunnel mode:

Auth trailerESP trailer

Authenticated

Encrypted

Authenticated

ESP header and trailer =SPI + Sequence number + Padding

ESP authentication trailer =message authentication code (MAC)

Original packet:

IP header ESP header Auth trailerESP trailerIP Payload

IP Payload

!

Page 13: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

18

IPsec databasesSecurity association database (SAD)

Contains the IPsec SAs i.e.t the dynamic protection state

Security policy database (SPD)Contains the static security policyUsually set by system administrators (e.g. Windows group policy), although some protocols and applications make dynamic changes

Peer authorization database (PAD)Needed in IKE for mapping between authenticated names and IP addressesConceptual; not implemented as an actual database

Additionally, the IKE service/daemon stores IKE SAs:Master secret created with Diffie-Hellman key exchangeUsed for instantiating new IPsec Sas

(Note: our description of SPD differs somewhat from RFC4301 and is probably closer to most implementations)

Page 14: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

19

Gateway SPD/SAD exampleProtocol Local IP Port Remote IP Port Action Comment

UDP 2.3.4.5 500 4.5.6.7 500 BYPASS IKE* 1.2.3.0/24 * 5.6.7.0/24 * ESP tunnel to 4.5.6.7 Protect VPN traffic* * * * * BYPASS All other peers

SPI SPD selector values

Protocol Algorithms, keys, algorithm state

spi1 TCP, 1.2.3.0/24, 5.6.7.0/24 ESP tunnel from 4.5.6.7 …spi2 — ESP tunnel to 4.5.6.7 …

Intranet 1.2.3.0/24

2.3.4.51.2.3.1

interface1

5.6.7.14.5.6.7

Intranet 5.6.7.0/24

IPsec gateway A

Internet

interface2 interface1 interface2

IPsec gateway B

SPD of gateway A, interface 2

SAD of gateway A

Pointers to created associations

Page 15: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

20

Security policy database (SPD)Specifies the static security policyMulti-homed nodes have a separate SPD for each network interface

(in practice, they can be stored on one database)(multihomed = node with multiple network interfaces)

Policy maps inbound and outbound packets to actionsSPD = linearly ordered list of policiesPolicy = selectors + actionThe first policy with matching selectors applies to each packet

Policy selector is a 5-tuple: Local and remote IP addressTransport protocol (TCP, UDP, ICMP)Source and destination ports

Actions: BYPASS (allow), DISCARD (block), or PROTECT PROTECT specifies also the session protocol and algorithmsPacket is mapped to a suitable IPsec security association (SA)If the SA does not exist, IKE is triggered to create themSPD stores pointers to previously created SAs

Policies at peer nodes must match if they are to communicate

Page 16: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

Some problems with IPsec

Page 17: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

27

IPsec and NATProblems:

NAT cannot multiplex IPsec: impossible to modify SPI or port number because they are authenticated

→ Host behind a NAT could not use IPsec NAT traversal (NAT-T):

UDP-encapsulated ESP (port 4500)NAT detection: extension of IKEv1 and IKEv2 for sending the original source address in initial packets

→ Enables host behind a NAT to use IPsec

Page 18: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

28

IPsec and mobilityProblem: IPsec policies and SAs are bound to IP addresses. Mobile nodes change their IP addressMobile IPv6:

Home address (HoA) in Mobile IP v6 is stable. But Mobile IPv6 itself depends on IPsec for the tunnel between HA and MN. → chicken-and-egg situation

Solutions: IPsec was changed to look up inbound SAs by SPI onlyIPsec-based VPNs from mobile hosts do not use the IP address as selector. Instead, proprietary solutionsProposed MOBIKE and HIP mobility protocols intergrate IPsec and mobility

Page 19: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

30

IPsec and name resolution

Typical TCP socket API use: resolve name into an IP address; then connect to the addressTCP SYN to the address triggers IKE (if the ESP SA does not exist yet)

2. Key Exchange (IKE)

IP Network

PC-A

Name service

Server-B1.2.3.4

Application Data

Query: “server-b”

Response: “1.2.3.4”

1. Name resolution

3. IPsec ProtectionOS

Application

IPsec Policy:

1.2.*.* ESP* BYPASS

Page 20: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

31

Classic IPsec/DNS Vulnerability

IPsec policy selection depends on secure name resolutionAttacker spoofs DNS response to circumvent the IPsec policy

2. Key Exchange (IKE)

Honest host

Attackerpc-c.example.org

3.4.5.6

Application Data

Query: “server-b.example.org”

Spoofed Response: “3.4.5.6”

1. Name resolution

3. IPsec ProtectionOS

Application

IPsec Policy

1.2.*.* ESP * BYPASS

Page 21: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

32

IPsec and Certificates

Let’s assume DNS is secureAnother problem: IKE knows the peer IP address, not the peer name; the certificate only contains the name How does IPsec decide whether the certificate is ok?

2. Key Exchange (IKE)

Honest host

Name service

Query: “server-b.

example.org”

Response: “1.2.3.4”

OS

Application

“1.2.3.4” = “server-b” ?

“1.2.3.4”

Certificate: {“server-b.example.org”, PublicKeyC}CA

“server-b.example.org”

Connect(“1.2.3.4”)

1. Name resolution

Page 22: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

33

What can go wrong?

2. Key Exchange (IKE)Certificate: {“server-b”, PublicKeyB}CA

PC-A

Name service

Application Data

Query: “server-b”

Response: “1.2.3.4”

1. Name resolution

3. IPsec ProtectionOS

Application

IPsec Policy:

* ESP

Server-B1.2.3.4

Page 23: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

34

IPsec and Certificates - Attack

IPsec cannot detect whether the certificate contains the correct nameSecure DNS (forward lookup) does not help — why?Result: group authentication of those certified by the same CA → maybe ok for protecting an intranet where the goal is to keep outsiders out

2. Key Exchange (IKE)Certificate: {“pc-c”, PublicKeyC}CA

PC-A

Name service

Application Data

Query: “server-b”

Response: “1.2.3.4”

1. Name resolution

3. IPsec ProtectionOS

Application

IPsec Policy:

* ESP

AttackerPC-C(using

1.2.3.4)

Page 24: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

35

Peer authorization database (PAD)IPsec spec [RFC4301] defines a database that maps authenticated names to the IP addresses which they are allowed to represent

How implemented? Secure reverse DNS would be the best solution — but it does not exist

Other solutions: Secure DNS — both secure forward and reverse lookup needed, which is unrealisticGive up IPsec transparency — extend the socket API so that applications can query for the authenticated name and other security stateConnect by name — change the socket API so that the connect() call specifies the host name, not the IP address

Currents situation: IPsec is only used for VPN where the gateway names and IP addresses are preconfigured

Page 25: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

36

Related readingWilliam Stallings. Network security essentials: applications and standards, 3rd ed. chapter 6; 4th ed. chapters 8, 11William Stallings. Cryptography and Network Security, 4th ed.: chapter 16 Kaufmann, Perlman, Speciner. Network security, 2nd ed.: chapter 17 (ignore AH)

Note: chapter 18 on the older IKEv1 is historical

Dieter Gollmann. Computer Security, 2nd ed. chapter 13.3; 3rd ed. chapters 16.1–16.3, 17.3

Page 26: Network Security: IPsec Tuomas Aura T-110.5241 Network security Aalto University, Nov-Dec 2014

37

ExercisesWhy is IPsec used mainly for VPN implementations? Does IPsec VPN suffer from any of the problems mentioned in the lecture?For the IPsec policy examples of this lecture, define the IPsec policy for the peer nodes i.e. the other ends of the connections.Try to configure the IPsec policy between two computers. What difficulties did you meet? Use ping and TCP to test connectivity. Use a network sniffer to observe the key exchange and to check that packets on the wire are encrypted.What administrative problems arise from the fact that IPsec security policies in two communicating nodes must match? How is this solved in Windows?RFC 4301 requires that the SPD is decorrelated, i.e. that the selectors of policy entries not to overlap, i.e. that any IP packet will match at most one rule (excluding the default rule which matches all packet). Yet, the policies created by system administrators almost always have overlapping entries. Device an algorithm for transforming any IPsec policy to an equivalent decorrelated policy. (Real protocol stacks do not implement decorrelation. Why?)Each SAD entry stores (caches) policy selector values from the policy that was used when creating it. Inbound packets are compared against these selectors to check that the packet arrives on the correct SA.

What security problem would arise without this check?What security weakness does the caching have (compared to a lookup through the SPD)? Does policy decorrelation solve the problem?