Hack 71 Opportunistic Encryption with FreeS/WANUse FreeS/WAN and DNS TXT records to automatically create encrypted connections between machines. One particularly cool feature [Hack #67] is opportunistic encryption with other hosts running FreeS/WAN. This allows FreeS/WAN to transparently encrypt traffic between all hosts that also support opportunistic encryption. To do this, each host must have a public key generated to use with FreeS/WAN. This key can then be stored in a DNS TXT record for that host. When a host that is set up for opportunistic encryption wishes to initiate an encrypted connection with another host, it will look up the host's public key through DNS and use it to initiate the connection. To begin, you'll need to generate a key for each host that you want to use this feature with. You can do that by running this command: # ipsec newhostkey --output /tmp/`hostname`.key Now you'll need to add the contents of the file that was created by that command to /etc/ipsec.secrets: # cat /tmp/`hostname`.key >> /etc/ipsec.secrets Next, you'll need to generate a TXT record to put into your DNS zone. You can do this by running a command similar to this one: # ipsec showhostkey --txt @colossus.nnc Now add this record to your zone and reload it. You can verify that DNS is working correctly by running this command: # ipsec verify Now just restart FreeS/WAN by running a command similar to this: # /etc/init.d/ipsec restart You should now be able to connect to any other host that supports opportunistic encryption. But what if other hosts want to connect to you? To allow this, you'll need to create a TXT record for your machine in your reverse DNS zone. You can generate the record by running a command similar to this: # ipsec showhostkey --txt 192.168.0.64 Add this record to the reverse zone for your subnet, and other machines will be able to initiate opportunistic encryption with your machine. With opportunistic encryption in use, all traffic between the hosts will be automatically encrypted, protecting all services simultaneously. Pretty neat, huh? |