Salta al contenuto
Note per Studenti VPN and IPsec Report

VPN and IPsec

In questa pagina 8

See also: IPv4 Datagram and FragmentationIPv4 is a connectionless, unreliable best-effort service; the header is 20 to 60 bytes (HLen counts 4-byte words), TTL limits hops, Protocol identifies the payload (1 ICMP, 6 TCP, 17 UDP) and the checksum covers only the header; a datagram larger than the link MTU is fragmented (only the payload is split, offsets are in units of 8 bytes, MF is 1 in all fragments but the last) and reassembled only at the destination.IPv4 Datagram and Fragmentation →, Forwarding and Routing TablesForwarding moves each packet one hop at a time toward its destination; it is direct when the destination is on a local network (ARP gives its MAC) and indirect otherwise (the packet goes to the next hop or default gateway given by the routing table). With netmasks, delivery is direct on interface x if the destination AND the mask equals the interface address AND the mask; otherwise the table is scanned from the longest mask (longest prefix match) and the default route 0.0.0.0/0 always matches; route aggregation shortens tables.Forwarding and Routing Tables →.

What a VPN is

Definition. A Virtual Private Network is a private network built over a public network (e.g. the Internet). Its nodes communicate securely over the public network as if they were in a private network.

Use. Employees reach the company intranet securely while travelling; companies extend their private network worldwide.

A private network gives authentication (guards and firewalls: users inside are identified), privacy (content cannot be seen from outside), integrity (nobody outside can forge or insert data). A VPN aims to get these properties without being physically inside: machines that are virtually private.

Architecture

A designated host, the VPN server, is authorised by the FirewallsA firewall blocks unauthorised traffic between networks using header information of layers 2-4: stateless packet filters apply ordered rules per packet, stateful firewalls track connections (NEW, ESTABLISHED, RELATED, INVALID), application firewalls act as proxies; in Linux netfilter provides five hooks and iptables organises rules in tables and chains.Firewalls → to send and receive traffic. It is exposed to the outside, while all other hosts stay protected; outside nodes must pass through it and authenticate. Direct connections to an internal node VV are blocked by the firewall, so all packets go through the VPN server.

Encapsulation (IP tunnelling)

Problem. How to send an IP packet from AA to BB securely if they belong to the same VPN but not to the same physical private network? Encrypting even the IP header would be safer, but routers cannot read an encrypted header and must change TTL and checksum.

Solution. Put the encrypted IP packet inside another IP packet as payload. At the destination the outer header is discarded, the payload is decrypted and treated as an ordinary IP packet.

Definition (IP tunnel). The real packet between the two tunnel endpoints carries another IP packet as payload; the tunnel crosses a public network and the traffic inside is protected.

Example. UU (network 10.0.7.0/24) sends to VV (10.0.8.0/24). On the public network travels 198.51.100.7 →\to 203.0.113.1, whose encrypted payload contains 10.0.7.5 →\to 10.0.8.9. UU gives the packet to the VPN client because 10.0.8.9 AND 255.255.255.0 == 10.0.8.0 differs from its own network: it goes to the default gateway.

Numeric example (size). With a 20-byte outer IPv4 header, an inner packet of 1500 bytes becomes 15201520 bytes, more than the MTU of 1500: it is fragmented into 14801480 and 2020 bytes of payload. Inner packets must stay smaller than the MTU minus the encapsulation overhead.

Numeric example (ESP in tunnel mode). Block cipher of 16 bytes and a 12-byte integrity code. Overhead: new IP header 2020; ESP header 88 (SPI 44 + sequence number 44); initialisation vector 1616; ESP trailer 22; integrity code 1212; plus padding to a multiple of 1616. Fixed overhead 20+8+16+2+12=5820+8+16+2+12=58 bytes. Inner packet of 14001400 bytes: 1400+2=14021400+2=1402, padding 66 to reach 1408=88⋅161408=88\cdot16, outer packet 20+8+16+1400+6+2+12=146420+8+16+1400+6+2+12=1464 bytes, within the MTU. For no fragmentation L+p+2≤1444L+p+2\le1444, hence (multiple of 1616) L+p+2≤1440L+p+2\le1440, Lmax=1438L_{max}=1438 bytes. Efficiency η=LL+58+p\eta=\frac{L}{L+58+p}: for L=1400L=1400, 95.6%95.6\%; for a 60-byte voice packet 60/120=50%60/120=50\% (with p=2p=2).

IPsec

IPsec gives security at the network layer: confidentiality, integrity, data origin authentication, protection from replay. Two protocols:

  • AH (Authentication Header, IP protocol 51): source authentication and data integrity;
  • ESP (Encapsulating Security Payload, IP protocol 50): also confidentiality (encryption).

Definition (tunnel mode). The whole original IP packet is encapsulated and becomes the payload of a new IP packet with a new IP header. Protects the entire packet; intermediate routers see nothing of the original; useful between networks; simplifies key exchange.

Definition (transport mode). Keeps the original IP header: the header is not protected, so traffic analysis is possible. Used for end-to-end communication between two hosts; no new header.

Example. Site A (10.1.0.0/16) and site B (10.2.0.0/16) have an ESP tunnel between border routers 203.0.113.1 and 203.0.113.2. A packet 10.1.0.5 →\to 10.2.0.9 leaves with the new header 203.0.113.1 →\to 203.0.113.2, protocol 50: only traffic between the gateways is visible.

Security Association (SA). Before sending IPsec datagrams, source and destination create a logical connection, an SA. It is one-way: bidirectional traffic needs two SAs (each with its SPI, keys and sequence counter; the sequence number allows discarding repeated packets, i.e. replay). SA state: an SPI (Security Parameter Index) identifying it; source and destination IP addresses; the security protocol (AH or ESP); the encryption type; the integrity-check type. IPsec is implemented in the IP layer of the kernel; a VPN uses tunnel mode.

SSL/TLS tunnel

Implemented outside the kernel, in an application that uses TCP or UDP (Public-Key Cryptography, RSA and TLSPublic-key cryptography uses a public key to encrypt and a private key to decrypt; certificates issued by a Certificate Authority bind identities to public keys; digital signatures give authenticity, integrity and non-repudiation; RSA relies on the difficulty of factoring; TLS combines certificates, a symmetric session key (derived with Diffie-Hellman since TLS 1.3) and MACs.Public-Key Cryptography, RSA and TLS →): each IP packet for the VPN is passed to a dedicated application, sent as TCP/UDP to the other end, where the encrypted IP packet is extracted and delivered. It is more popular than IPsec because it does not depend on the kernel.

The VPN service step by step

A VPN client (satellite site) and a VPN server (main site) must: 1) establish a secure tunnel; 2) forward into the tunnel the IP packets for the other side; 3) after receiving an IP packet from the tunnel, release it into the private network.

1. TLS tunnel. Mutual authentication: the client authenticates the server with a public-key certificate; the server authenticates the client with a shared key (e.g. the user's password). Data are encrypted and protected with MACs.

2. Virtual network interfaces (TUN/TAP) connect the kernel to a user-space program:

interface layer use
TUN IP (layer 3) packets, including the IP header, are delivered to the user-space program; layer 3 VPNs
TAP link (layer 2), behaves as a network card carries any layer 3 protocol; layer 2 VPNs

3. Forwarding. The tunnel application is a virtual host connected through the TUN/TAP card; it encrypts and encapsulates the IP packet in TCP/UDP with a new IP header (client VPN as source, server VPN as destination, port 443).

4. Release. The VPN server removes the outer header, the application decrypts the packet and checks its integrity, and returns it to the kernel.

Example. UU (10.0.7.0/24) sends to VV (10.0.8.0/24): 1) to the gateway (VPN client), routed to the TUN interface; 2) encrypted and encapsulated in TCP to the VPN server, port 443; 3) the server extracts, decrypts, verifies, passes to its kernel; 4) the kernel routes it to VV.

Bypassing geo-restrictions

Geo-restriction filters by the geographic location of the IP address. With a VPN the visible IP is the VPN server's: connecting to a server in another region gives access as if there. More generally a VPN hides the real IP of the sender (within limits).

Common mistakes

  • Believing a VPN makes traffic anonymous: the VPN operator sees it.
  • Forgetting that in transport mode the IP header stays in clear.
  • Counting one SA for bidirectional traffic: two are needed.
  • Confusing AH (integrity and authentication only) with ESP (also encryption).
  • Forgetting encapsulation overhead and fragmentation.
  • Confusing TUN (layer 3, packets) with TAP (layer 2, frames).

Versione ripasso

Teoria collegata