Benchmarks for Native IPsec in the 2.6 Kernel
The following listing is used to illustrate how to set up a secure connection between two computers on different LANs. Below, we provide the script file of gouda that sets a secure connection between two systems. gouda is at IP address 192.168.0.1 and reblochon is at IP address 192.168.0.2.
1: #!/usr/local/sbin/setkey -f 2: flush; 3: spdflush; 4: 5: # AH gouda to reblochon 6: add 192.168.0.1 192.168.0.2 ah 1000 7: -A hmac-md5 "1234567890123456"; 8: add 192.168.0.2 192.168.0.1 ah 2000 9: -A hmac-md5 "1234567890123456"; 10: 11: # ESP gouda to reblochon 12: add 192.168.0.1 192.168.0.2 esp 1001 13: -E 3des-cbc "123456789012345678901234" 14: -A hmac-sha1 "12345678901234567890"; 15: add 192.168.0.2 192.168.0.1 esp 2001 16: -E 3des-cbc "123456789012345678901234" 17: -A hmac-sha1 "12345678901234567890"; 18: 19: spdadd 192.168.0.1 192.168.0.2 any -P out IPsec 20: esp/transport//require 21: ah/transport//require; 22: 23: spdadd 192.168.0.2 192.168.0.1 any -P in IPsec 24: esp/transport//require 25: ah/transport//require;
For reblochon, we use the same script file with only the following differences on line 19:
19: spdadd 192.168.0.1 192.168.0.2 any -P in IPsec
and on line 23:
23: spdadd 192.168.0.2 192.168.0.1 any -P out IPsec
Note the in and out keywords are reversed.
In line 1, the setkey command is invoked. This program inserts or deletes IPsec rules in the kernel. In lines 2 and 3, we use the setkey command to clear all security associations (SA) and security policies (SP), because we want to begin from a clean state.
Before diving into more technical details, we need to become familiar with two basic concepts in IPsec protocol, security association (SA) and security policy (SP). An SA defines the security parameters, for example, the crypto algorithm to be used, to create a secure connection between two systems. An SP, on the other hand, is the security rule defining the security context to be used between the two systems. For example, an SP can specify that we need to use encryption between my desktop and a remote system on the Internet. An SA then is the effective secure connection created between my desktop and that system. Be aware that SAs are unidirectional.
In our scenario, we define two SPs between reblochon and gouda. An SP is defined as:
source | destination | on which kind of traffic to apply the policy (TCP, UDP, port, any) | the direction in/out | what to do (IPsec/discard/none) | (esp/ah) / (transport/tunnel) / (IP address of both ends of the tunnel) not required in transport mode / require.
For example, these lines:
spdadd 192.168.0.1 192.168.0.2 any -P out IPsec esp/transport//require ah/transport//require;
declare a security policy stating that any packets coming from 192.168.0.1 and going to 192.168.0.2 should use IPsec on transport mode with ESP and AH functionality.
Now that you defined the policy between your systems, you need to define SAs in order to be able to achieve that policy. You need two SAs for communication, one from gouda to reblochon and one from reblochon to gouda. The two SAs do not need to use the same algorithm. In fact, unlike this example, for better security you should not use the same key for both SAs.
You define a SA as
source | destination | ah/esp | SPI (Security Policy Index) any number but should be unique | algorithm and associated secret key.
For example, these lines:
add 192.168.0.1 192.168.0.2 esp 1001 -E 3des-cbc "123456789012123456789012" -A hmac-sha1 "12345678901234567890";
define that if you want to use ESP on a packet going from gouda to reblochon, you should use 3DES as the encryption algorithm with the quoted text as the key and SHA1 as the authentication algorithm.
Now, you finally can run the script on both nodes. You can check the status of different SAs established by using setkey -D. If you want to see existing policies on your system, you can use setkey -DP. At the end, to be sure that the traffic between two systems actually is encrypted, you can use Ethereal to monitor the traffic between two nodes. For example, in Figure 1, we show the traffic between two systems exchanging messages containing the "hello world" text. As you see, the message is encrypted between gouda and reblochon.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- The Humble Hacker?
- Server Hardening
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- EnterpriseDB's EDB Postgres Advanced Server and EDB Postgres Enterprise Manager
- The Death of RoboVM
- The US Government and Open-Source Software
- ACI Worldwide's UP Retail Payments
- Open-Source Project Secretly Funded by CIA
- Varnish Software's Hitch
- New Container Image Standard Promises More Portable Apps
In modern computer systems, privacy and security are mandatory. However, connections from the outside over public networks automatically imply risks. One easily available solution to avoid eavesdroppers’ attempts is SSH. But, its wide adoption during the past 21 years has made it a target for attackers, so hardening your system properly is a must.
Additionally, in highly regulated markets, you must comply with specific operational requirements, proving that you conform to standards and even that you have included new mandatory authentication methods, such as two-factor authentication. In this ebook, I discuss SSH and how to configure and manage it to guarantee that your network is safe, your data is secure and that you comply with relevant regulations.Get the Guide