- •Table of Contents
- •Preface
- •What This Book Covers
- •What You Need for This Book
- •Conventions
- •Reader Feedback
- •Customer Support
- •Errata
- •Questions
- •The Need for Cryptography
- •Privacy
- •Security
- •A History of the Internet
- •Holding the Internet Together
- •The Creation of ICANN
- •ICANN Bypassed
- •The Root Name Servers
- •Running the Top-Level Domains
- •History of Internet Engineering
- •The Internet Engineering Task Force (IETF)
- •RFCs—Requests For Comments
- •IETF and Crypto
- •The War on Crypto
- •Dual Use
- •Public Cryptography
- •The Escrowed Encryption Standard
- •Export Laws
- •The Summer of '97
- •The EFF DES Cracker
- •Echelon
- •The End of the Export Restrictions
- •Free Software
- •Free as in Verifiable
- •The Open Source Movement
- •The History of Openswan
- •IETF Troubles over DNS
- •Super FreeS/WAN
- •The Arrival of Openswan
- •NETKEY
- •Further Reading
- •Using Openswan
- •Copyright and License Conditions
- •Writing and Contributing Code
- •Legality of Using Openswan
- •International Agreements
- •International Law and Hosting Openswan
- •Unrecognized International Claims
- •Patent Law
- •Expired and Bogus Patents
- •Useful Legal Links
- •Summary
- •A Very Brief Overview of Cryptography
- •Valid Packet Rewriting
- •Ciphers
- •Algorithms
- •Uniqueness
- •Public-Key Algorithms
- •Exchanging Public Keys
- •Digital Signatures
- •Diffie-Hellman Key Exchange
- •Avoiding the Man in the Middle
- •Session Keys
- •Crypto Requirements for IPsec
- •IPsec: A Suite of Protocols
- •Kernel Mode: Packet Handling
- •Authentication Header (AH)
- •Encapsulated Security Payload (ESP)
- •Transport and Tunnel Mode
- •Choosing the IPsec Mode and Type
- •The Kernel State
- •Encryption Details
- •Manual Keying
- •Final Note on Protocols and Ports
- •Usermode: Handling the Trust Relationships
- •The IKE Protocol
- •Phase 1: Creating the ISAKMP SA
- •Phase 2: Quick Mode
- •The NAT Problem
- •Summary
- •Linux Distributions
- •Debian
- •SuSE
- •Slackware
- •Gentoo
- •Linux 'Router' Distributions
- •Deciding on the Userland
- •Pluto
- •Racoon
- •Isakmpd
- •More Reasons to Pick Pluto
- •Choosing the Kernel IPsec Stack
- •KLIPS, the Openswan Stack
- •ipsecX Interfaces
- •First Packet Caching
- •Path MTU Discovery
- •KLIPS' Downside
- •NETKEY, the 2.6 IPsec Stack
- •The USAGI / SuSE IPsec Stack
- •Making the Choice
- •GPL Compliance and KLIPS
- •Binary Installation of the Openswan Userland
- •Checking for Old Versions
- •Installing the Binary Package for Openswan
- •Building from Source
- •Using RPM-based Distributions
- •Rebuilding the Openswan Userland
- •Building src.rpm from Scratch
- •Openswan Options
- •Building the Openswan Userland from Source
- •Downloading the Source Code
- •Configuring the Userland Tools
- •Optional Features
- •Compile Flags
- •File Path Options
- •Obscure Pluto Options
- •Compiling and Installing
- •Binary Installation of KLIPS
- •Building KLIPS from Source
- •Kernel Prerequisites
- •Identifying your Kernel's Abilities
- •Using Both KLIPS and NETKEY
- •The Kernel Build Options
- •Required Kernel Options
- •Desired Options
- •NETKEY Stack Options
- •KLIPS Stack Options
- •L2TP Options
- •Patching the Kernel
- •NAT-Traversal Patch
- •KLIPS Compile Shortcut
- •Activating KLIPS
- •Determining the Stack in Use
- •Building KLIPS into the Linux Kernel Source Tree
- •Building a Standard Kernel
- •NAT Traversal
- •Patching KLIPS into the Linux Kernel
- •Verifying the Installation
- •Summary
- •Manual versus Automatic
- •PSK versus RSA
- •Pitfalls of Debugging IPsec
- •Pre-Flight Check
- •The ipsec verify Command
- •NAT and Masquerading
- •Checking External Commands
- •Opportunistic Encryption
- •The ipsec livetest Command
- •Configuration of Openswan
- •The ipsec.conf File
- •Host-to-Host Tunnel
- •Left and Right
- •The type Options
- •The auto Option
- •The rsasigkey Options
- •Bringing Up the IPsec Tunnels
- •Listing IPsec Connections
- •Testing the IPsec Tunnel
- •Connecting Subnets Through an IPsec Connection
- •Testing Subnet Connections
- •Testing Properly
- •Encrypting the Host and the Network Behind It
- •Employing Advanced Routing
- •Creating More Tunnels
- •Avoiding Duplication
- •The Also Keyword
- •KLIPS and the ipsecX Interfaces
- •Pre-Shared Keys (PSKs)
- •Proper Secrets
- •Dynamic IP Addresses
- •Hostnames
- •Roadwarriors
- •Multiple Roadwarrior Connections
- •Dynamic IP and PSKs
- •Mixing PSK and RSA
- •Connection Management
- •Subnet Extrusion
- •NAT Traversal
- •Deprecated Syntax
- •Confirming a Functional NAT-T
- •Dead Peer Detection
- •DPD Works Both Ways
- •Configuring DPD
- •Buggy Cisco Routers
- •Ciphers and Algorithms
- •Using ike= to Specify Phase 1 Parameters
- •Using esp= to Specify Phase 2 Parameters
- •Defaults and Strictness
- •Unsupported Ciphers and Algorithms
- •Aggressive Mode
- •XAUTH
- •XAUTH Gateway (Server Side)
- •XAUTH Client (Supplicant Side)
- •Fine Tuning
- •Perfect Forward Secrecy
- •Rekeying
- •Key Rollover
- •Summary
- •X.509 Certificates Explained
- •X.509 Objects
- •X.509 Packing
- •Types of Certificates
- •Passphrases, PIN Codes, and Interactivity
- •IKE and Certificates
- •Using the Certificate DN as ID for Openswan
- •Generating Certificates with OpenSSL
- •Setting the Time
- •Configuring OpenSSL
- •Be Consistent with All Certificates
- •OpenSSL Commands for Common Certificate Actions
- •Configuring Apache for IPsec X.509 Files
- •Creating X.509-based Connections
- •Using a Certificate Authority
- •Using Multiple CAs
- •Sending and Receiving Certificate Information
- •Creating your own CA using OpenSSL
- •Creating Host Certificates with Your Own CA
- •Host Certificates for Microsoft Windows (PKCS#12)
- •Certificate Revocation
- •Dynamic CRL Fetching
- •Configuring CRL
- •Online Certificate Status Protocol (OCSP)
- •Summary
- •History of Opportunistic Encryption
- •Trusting Third Parties
- •Trusting the DNS?
- •OE in a Nutshell
- •An OE Security Gateway
- •DNS Key Records
- •Forward and Reverse Zones
- •The OE DNS Records
- •Different Types of OE
- •Policy Groups
- •Internal States
- •Configuring OE
- •Configuring Policies
- •Full OE or Initiate-Only
- •Generating Correct DNS Records
- •Name Server Updates
- •Verifying Your OE Setup
- •Testing Your OE Setup
- •The trap eroute
- •The pass eroute
- •The hold eroute
- •Manipulating OE Connections Manually
- •Advanced OE Setups
- •Caveats
- •Summary
- •Where to Firewall?
- •Allowing IPsec Traffic
- •NAT and IPsec Passthrough
- •Configuring the Firewall on the Openswan Host
- •Firewalling and KLIPS
- •Firewalling and NETKEY
- •Packet Size
- •Summary
- •Microsoft Windows
- •Layer 2 Tunneling Protocol (L2TP)
- •Assigning an IP for VPN Access
- •L2TP Properties
- •Pure IPsec versus L2TP/IPsec
- •Client and Server Configurations for L2TP/IPsec
- •The L2TP Openswan Server
- •Configuring Openswan for L2TP/IPsec
- •Linux Kernel Runtime Parameters for L2TP/IPsec
- •Protecting the L2TP Daemon with IPsec using iptables
- •Choosing an L2TP Daemon
- •Configuring L2TPD
- •Configuring User Authentication for pppd
- •Microsoft Windows XP L2TP Configuration
- •Microsoft Windows 2000 L2TP Configuration
- •Apple Mac OS X L2TP Configuration
- •Server Configuration for X.509 IPsec without L2TP
- •Openswan Configuration for X.509 without L2TP
- •Client Configuration for X.509 IPsec without L2TP
- •Microsoft's IKE Daemon
- •Microsoft's Certificate Store
- •Clients using Microsoft Native IPsec Implementation
- •The ipsec.exe Wrapper
- •The Linsys IPsec Tool (lsipsectool)
- •Securepoint IPsec Client
- •TauVPN (iVPN)
- •The WaveSEC Client
- •Third-Party Replacement Clients for Windows
- •The GreenBow VPN Client
- •Astaro Secure Client
- •Mac OS X IPSecuritas
- •VPNtracker
- •Manual Racoon Configuration
- •Importing X.509 Certificates into Windows
- •Importing X.509 Certificates on Mac OS X (Tiger)
- •Summary
- •Openswan as a Client to an Appliance
- •Preparing the Interop
- •The Human Factor
- •Terminology
- •Preparation
- •IPsec Passthrough
- •Tunnel Limitations
- •Anticipate Known Problems
- •Update the Firmware
- •GUI Issues
- •Keepalives
- •ISP Filtering
- •Frequently used VPN Gateways
- •Webmin with Openswan
- •Cisco VPN 3000
- •Cisco PIX Concentrator
- •Nortel Contivity
- •Checkpoint
- •WatchGuard Firebox
- •Symantec
- •Frequently used VPN Client Appliances
- •ZyXEL
- •DrayTek Vigor
- •The Vigor Web Interface
- •Windows Logon Issues
- •Other Vigorisms
- •Unresolved Issues
- •NetScreen
- •Known Issues
- •SonicWALL
- •BinTec
- •LANCOM
- •Linksys
- •Lucent Brick
- •NETGEAR
- •KAME/Racoon
- •Aftercare
- •Summary
- •Methods of Encryption
- •Host-to-Host Mesh
- •Host-to-Gateway Setup
- •Single IP Extrusiautomation or L2TP
- •Opportunistic Encryption in the LAN
- •Non-OE-Capable Machines
- •Designing a Solution for Encrypting the LAN
- •Design Goals
- •Separation of WiFi and Crypto
- •Link Layer Protection
- •The Logical Choice: IPsec
- •Hotspot
- •WaveSEC
- •Full WaveSEC
- •Catch 22 Traffic
- •Building a WaveSEC Server
- •DHCP Server Setup
- •DNS Server Setup
- •Openswan Server Setup
- •Catch 22 Traffic Setup
- •Building a WaveSEC Client
- •DH Client Setup
- •Openswan Setup
- •Testing the WaveSEC
- •Starting the WaveSEC Connection
- •Known Issues with WaveSEC
- •WaveSEC for Windows
- •Design Limitations
- •Building a WaveSEC for Windows Server
- •Obtaining the Certificate and Client Software
- •Our Prototype Experiences
- •Openswan Issues
- •Windows Kernel Issues
- •Summary
- •Cipher Performance
- •Handling Thousands of Tunnels
- •Managing Large Configuration Files
- •Standard Naming Convention
- •The also= Parameter
- •The include Parameter
- •Openswan Startup Time
- •Limitations of the Random Device
- •Other Performance-Enhancing Factors
- •Logging to Disk
- •Disable Dead Peer Detection
- •Reducing the Number of Tunnels
- •OSPF Setup
- •BGPv4 Setup
- •High Availability
- •Heartbeat
- •Xen Migration
- •Using Anycast
- •Summary
- •Do Not Lock Yourself Out!
- •Narrowing Down the Problem
- •Host Issues
- •Configuration Problems
- •Connection Names
- •Interoperability
- •Hunting Ghosts
- •Rekey Problems (After an Hour)
- •Openswan Error Messages
- •IKE: Unknown VendorIDs
- •Network Issues
- •Firewalls
- •MTU and Fragmentation Issues
- •Debugging IPsec on Apple Mac OS X
- •Debugging IPsec on Microsoft Windows
- •Oakley Debugging
- •Debugging ipsec.exe
- •Microsoft L2TP Errors
- •You Suddenly Cannot Log in Anymore over the VPN
- •Software Bugs
- •Userland Issues: Assertion Failed or Segmentation Faults
- •Kernel Issues: Crashes and Oopses
- •Memory Issues
- •Common IKE Error Messages
- •Common Kernel-Related Error Messages
- •Common Errors when Upgrading
- •Using tcpdump to Debug IPsec
- •Situation A: No Communication on Port 500
- •Situation B: Failure at Third Exchange
- •Situation C: QUICK Mode Initiates, but Never Completes
- •Situation D: All IKE Messages Occur, but no Traffic Flows
- •A Final tcpdump Example
- •User Mode Linux Testing
- •Preparing the Openswan for the UML Build Process
- •Running the UMLs
- •Writing a UML Test Case
- •Debugging the Kernel with GDB
- •Asking the Openswan Community for Help
- •Internet Relay Chat (IRC)
- •The Openswan Mailing Lists
- •Posting to the Lists
- •Research First, Ask Later
- •Free, as in Beer
- •Do not Anonymize
- •Summary
- •Linux Kernel Developments
- •Kernel API Changes between 2.6.12 and 2.6.14
- •Red Hat Kernel Developments
- •Fedora Kernel Source/Headers Packaging Change
- •MD5 Insecurities
- •Discontinuation of Openswan 1 by the End of 2005
- •Update on UML Testing Suite Installation
- •Openswan GIT Repositories
- •Openswan on Windows and Mac OS X Updates
- •Known Outstanding Bugs
- •Vulnerability Fixes in Openswan 2.4.4
- •The OSI Model and the IP Model
- •No Layers, Just Packets
- •The Protocol
- •IP Network Overview
- •IP Address Management
- •The Old IP Classes
- •Classless IP Networks
- •The Definition of a Subnet
- •Calculating with Subnets: The Subnet Mask
- •The Rest of the Network
- •Linux Networking Commands
- •Routing
- •Routing Decisions
- •Peering
- •Network Address Translation
- •Port Forwarding
- •Openswan Links
- •Community Documentation
- •Generic Linux Distributions Containing Openswan
- •Specialized Linux Distributions Containing Openswan
- •Overview RFCs
- •Basic Protocols
- •Key Management
- •Procedural and Operational RFCs
- •Detailed RFCs on Specific Cryptographic Algorithms and Ciphers
- •Dead Peer Detection RFCs
- •NAT-Traversal and UDP Encapsulation RFCs
- •RFCs for Secure DNS Service, which IPSEC May Use
- •RFCs Related to L2TP, Often Used in Combination with IPsec
- •RFCs on IPsec in Relation to Other Protocols
- •RFCs Not in Use or Implemented across Multiple Vendors
- •Index
Dealing with Firewalls
Vendors tend to promote 'IPsec Passthrough' as an important feature of their device. However, it really means that their device does not actually have an IPsec stack, and instead will mangle IPsec traffic that passes through the device, that should have been left untouched to properly work. If you can't disable this feature, avoid the device entirely!
You can not use IPsec passthrough and NAT-T between two peers at the same time. If you attempt this, you will see a message similar to the following in your log files:
Mar 18 18:29:42 gateway pluto[5096]: "nat_demo"[17] 192.168.89.10 #31: Warning: peer is NATed but source port is still udp/500. Ipsec-passthrough NAT device suspected -- NAT-T may not work.
Mar 18 18:30:47 gateway pluto[5096]: "nat_demo"[17] 192.168.89.10 #32: Warning: peer is NATed but source port is still udp/500. Ipsec-passthrough NAT device suspected -- NAT-T may not work.
If NAT-T is enabled on your IPsec peers, you must disable IPsec passthrough on any NAT device between them.
Configuring the Firewall on the Openswan Host
No matter which kernel stack is used, you still need to permit IPsec traffic in and out of the Openswan host. This portion of the firewall configuration is the same for KLIPS and NETKEY. Note that it is slightly different from the table listed earlier, and now uses the INPUT/OUTPUT tables instead of the FORWARD table:
#Firewall Configuration to allow IPsec traffic to be
#sent and received by this server.
iptables -I INPUT -s 193.111.228.1 -d 205.150.200.209 -p udp --dport 500 -j ACCEPT
iptables -I OUTPUT -s 205.150.200.209 -d 193.111.228.1 -p udp --dport 500 -j ACCEPT
iptables -I INPUT -s 193.111.228.1 -d 205.150.200.209 -p udp --dport 4500 -j ACCEPT
iptables -I OUTPUT -s 205.150.200.209 -d 193.111.228.1 -p udp --dport 4500 -j ACCEPT
iptables -I INPUT -s 193.111.228.1 -d 205.150.200.209 -p 50 -j ACCEPT iptables -I OUTPUT -s 205.150.200.209 -d 193.111.228.1 -p 50 -j ACCEPT
These iptables commands are basic—you can further narrow down traffic by adding additional filtering commands, such as -i eth0, to specify that the packet must come in via your external interface eth0. The rules for ESP packets appear last, using an insert (-I) command. This causes them to appear at the top of the list, which is useful, since there will be many more ESP packets than IKE packets. They will be matched immediately, instead of traveling down the ruleset before getting accepted.
Although NATed IKE packets are sent out with a source port of 500 or 4500, these source ports might be changed by a NAT router in transit that needs to map many machines onto its own ports. Therefore you should not only allow port 500 to 500 and 4500 to 4500 packets, but all packets to and from port 500 and 4500, as in our example above.
150
Chapter 7
One last reminder about firewall rules on your IPSec peer. If your peer is doing NAT itself (as is common in many Linux installations), you will need to exclude traffic for your IPsec tunnels from being NATed. We covered this in Chapter 4, but here it is again. This example assumes that your local network is 192.168.0.0/24, and that the remote side is 192.168.1.0/24—so you need to exclude the traffic destined for 192.168.1.0/24 from being NATed before it becomes encrypted:
iptables -t nat -I POSTROUTING -s 192.168.0.0/24 -d \! 192.168.1.0/24 -o eth0 -j MASQUERADE
Firewalling and KLIPS
When using KLIPS, there is an ipsecX device for each IPsec tunnel, which greatly simplifies the writing of firewall rulesets. When dealing with ipsecX devices, any traffic coming in from the virtual device has already been decrypted and checked by the KLIPS policies, so you can assume it is genuine traffic from the remote peer. Whether it is safe to forward to your network might also depend on the trust you have in that peer. Note that traffic flow with KLIPS is:
Where * denotes where the packet passes through the iptables FORWARD chain. So you can permit all traffic that comes in over the VPN with a single iptables rule:
iptables -I FORWARD -i ipsec0 -j ACCEPT
Another example shows how to only allow POP3 traffic (on TCP port 110) that comes in from a trusted VPN connection, but not from the Internet:
iptables -I FORWARD -i ipsec0 -p tcp --dport 110 -j ACCEPT iptables -I FORWARD -i eth0 -p tcp --dport 110 -j DROP
If your default policy for eth0 is to drop unmatched packets, you can even leave out the last rule.
Firewalling and NETKEY
IP firewalling when using NETKEY is quite different, as there are no ipsecX devices to easily identify IPsec traffic. Furthermore, this part of the networking code is under heavy development at the moment. At the time of writing (Linux 2.6.15), IPsec packets still appear to iptables in strange inconsistent ways. We see incoming encrypted packets and incoming plaintext packets, but there is no relationship between the two that we can observe. Some encrypted packets will cause plaintext packets to appear, others might not. And some plaintext packets might have arrived in plaintext to begin with.
Some packets might get killed by the built-in rp_filter anti-spoof protection if that is not disabled in /etc/sysctl.conf. You would expect a strict separation for encrypted packets to appear in the INPUT/OUTPUT tables, and the decrypted packets to go through the FORWARD table, but it is not that easy. There are patches by Patrick McHardy in the netfilter patch-o-matic to make the packets hit the iptables before and after encryption, but they have not been merged into the mainstream kernel yet. The patches can be found at http://www.netfilter.org/patch- o-matic/pom-extra.html. To accomplish the same as the secure POP rules above for KLIPS, you have to use the FWMARK facility of iptables. You can have the kernel mark IPsec packets.
151
Dealing with Firewalls
This mark stays on the packet even after it has been decrypted. And since only the kernel, meaning you, can mark packets—it is not a state for packets on the network—you can distinguish plaintext traffic from decrypted traffic if you mark the encrypted traffic first:
iptables -t mangle -A PREROUTING -i eth0 |
-p esp |
-j MARK -- |
set-mark |
1 |
||||||||
iptables -I INPUT -i eth0 -m mark -- |
mark |
1 |
-p tcp -- |
dport |
110 -j ACCEPT |
|||||||
iptables -I |
FORWARD |
-i |
eth0 |
-m |
mark |
--mark |
1 -p |
tcp |
--dport 110 -j |
ACCEPT |
||
iptables -A |
FORWARD |
-i |
eth0 |
-p |
tcp -- |
dport |
110 -j DROP |
|
|
Alternatively you can split firewalling up for the two ethernet cards. On the external interface you drop port TCP 110, but accept IPsec traffic, and on the internal interface, you allow TCP port 110.
Packet Size
The MTU (Maximum Transmission Unit) size of packets can become a problem, as larger packets may be fragmented when being put into the IPsec tunnel. Also, a device somewhere between the IPsec peers might be silently fragmenting the packets, which, coupled with devices that cannot or will not reassemble the fragmented packets, leads to loss of communication.
Symptoms of this manifest themselves most commonly when loading a single web page is OK, but following any link on the website fails, or when you can log in via SSH, but issuing ls -al in a large directory seems to hang. Any situation where the initial connection works, but all subsequent data gets stuck, is usually an indicator of a packet size problem.
The issue is packet fragmentation—a device somewhere between the two peers is breaking the packets into two or more fragments. While a difficult problem to diagnose, it is not too hard to fix. If you are using KLIPS, simply add the following line to the config setup section of your
ipsec.conf:
overridemtu=1419
This changes the MTU setting on the ipsecX interface. You can also do this manually by issuing the command:
ifconfig ipsec0 mtu 1419
We suggest starting with 1419, as IPsec encapsulated inside UDP using AES adds about 70-80 bytes of overhead to the packet, so by limiting packets to 1419 bytes, we stay inside the 1500 byte limit.
Note: the MTU of the ipsecX interfaces defaults to 16260 bytes. This is so that the ipsecX device can accept packets from any phyiscal media (Ethernet, Token Ring, ATM, etc.) and fragment properly.
Using NETKEY, you must either adjust the MTU of the outer interface:
ifconfig eth0 mtu 1440
or add in specific routes and specify the MTU for the route:
ip route replace 192.112.90.50 via 193.111.228.1 dev eth0 mtu 1440
152