:: Setting up VPN using PPP using FreeSwan IpSec :: | |||
HOME |
#> mkdir ipsec; cd ipsec #> wget ftp://ftp.xs4all.nl/pub/crypto/freeswan/binaries/RedHat-RPMs/`uname -r | tr -d 'a-wy-z'`/\* #> rpm --import freeswan-rpmsign.asc #> rpm --checksig freeswan*.rpm freeswan-module-2.01_2.4.20_8-0.i386.rpm: sha1 (md5) pgp md5 OK freeswan-userland-2.01_2.4.20_8-0.i386.rpm: sha1 (md5) pgp md5 OKYou can then install the RPM's using the following commands:
#> rpm -ivh freeswan-module-2.01_2.4.20_8-0.i386.rpm #> rpm -ivh freeswan-userland-2.01_2.4.20_8-0.i386.rpm
#> wget ftp://ftp.xs4all.nl/pub/crypto/freeswan/freeswan-\*I decided to untar it in /usr/src. Use the following commands [manual]:
#> mv ./freeswan-2.01.tar.gz /usr/src #> cd /usr/src #> tar -xvzf freeswan-2.01.tar.gz #> cd freeswan-2.01 #> make oldmod #> make minstall
[shashank@mia /etc]# /usr/local/sbin/ipsec newhostkey --output /etc/ipsec.secrets [shashank@mia /etc]# cat /etc/ipsec.secrets 1. : RSA { 2. # RSA 2192 bits mia.ece.uic.edu Fri Aug 8 16:54:03 2003 3. # for signatures only, UNSAFE FOR ENCRYPTION 4. #pubkey=0sAQN+0ObyTUPxn2r/m3URW7uVq/S+C3dJenU..... 5. Modulus: 0x7ed0e6f24d43f19f6aff9b75115bbb95ab..... 6. PublicExponent: 0x03 7. # everything after this point is secret 8. PrivateExponent: 0x1522d1286235fd9a91d5449382..... 9. Prime1: 0xf08b954672e0d5b1d89455e5f2ff72b02cb..... 10. Prime2: 0x86f6bc07f4c5f58ebd139b1fc51fc4fa65e..... 11. Exponent1: 0xa05d0e2ef7408e769062e3eea1ffa1ca..... 12. Exponent2: 0x59f9d2aff883f909d362676a836a8351..... 13. Coefficient: 0x230fe4391d79b13b5b631032020021..... 14. }NOTE the first line of the key. A name (or identity) can be assigned to this key before the ":". This enable's pluto to select a particular RSA key for a particular connection. If such a name is not provided, this key will acts as a default for all connections (Use man ipsec.secrets to find out more about how to specify the name for a key).
[shashank@mia /etc]# /usr/local/sbin/ipsec rsasigkey 1024 >> /etc/ipsec.secrets [shashank@mia /etc]# pico /etc/ipsec.secrets [shashank@mia /etc]# cat ipsec.secrets : RSA { # RSA 2192 bits mia.ece.uic.edu Mon Aug 11 09:55:05 2003 # for signatures only, UNSAFE FOR ENCRYPTION #pubkey=0sAQNgZVw+MZpwjtjSDYobZJOuil3/h2FcG3h --SNIP-- } @mia: RSA { # RSA 1024 bits mia.ece.uic.edu Mon Aug 11 10:07:10 2003 # for signatures only, UNSAFE FOR ENCRYPTION #pubkey=0sAQO8jbw1RZ82kOXxij5kKclmvfMhNqcRFmp --SNIP-- }NOTE: You will have to manually enter @mia: RSA and the opening and closing braces, as ipsec rsasigkey does not do that.
[shashank@mia /etc]# ipsec ranbits 192 0xe8e627e9_a9880d77_88e6ef39_916e5dac_f0493cd6_ddbd2aa4 [shashank@mia /etc]# pico ipsec.secrets (to paste the above key) [shashank@mia /etc]# cat ipsec.secrets : PSK "e8e627e9_a9880d77_88e6ef39_916e5dac_f0493cd6_ddbd2aa4" : RSA { # RSA 2192 bits mia.ece.uic.edu Fri Aug 8 16:54:03 2003 --SNIP--
#> cat /etc/ipsec.conf 1 version 2.0 # conforms to second version of ipsec.conf specification 2 3 config setup 4 interfaces="ipsec0=eth0" 5 klipsdebug=none 6 plutodebug=none 7 uniqueids=yes 8 #manualstart="mia-spiff-h2h-manual" 9 10 conn %default 11 keyingtries=0 12 authby=rsasig 13 14 conn block 15 auto=ignore 16 17 conn private 18 auto=ignore 19 20 conn private-or-clear 21 auto=ignore 22 23 conn clear-or-private 24 auto=ignore 25 26 conn clear 27 auto=ignore 28 29 conn packetdefault 30 auto=ignore 31 32 conn mia-spiff-h2h 33 left=131.193.50.165 34 # leftsubnet=131.193.50.165/32 35 leftnexthop=131.193.50.1 36 leftid=@mia 37 leftrsasigkey=0sAQOAS9+zP7L5pHZG8JgdBP... 38 right=131.193.50.187 39 # rightsubnet=131.193.50.187/32 40 rightnexthop=131.193.50.1 41 rightid=@spiff 42 rightrsasigkey=0sAQNaO9TGUfxQOjTQJc9Lzq... 43 auto=ignore 44 rekey=no 45 failureshunt=passthrough 46 pfs=no 47 compress=no 48 # auth=esp #(esp|ah) 49 authby=rsasig #(rsasig|secret) 50 type=tunnel #(tunnel|transport|passthrough|drop|reject)Explanation for most options can be obtained by using man ipsec.conf and but some not-so-apparent options are explained below:
shashank@mia #> ipsec showhostkey --left --id @mia # RSA 1024 bits mia.ece.uic.edu Wed Aug 13 10:24:08 2003 leftrsasigkey=0sAQOAS9+zP7L5pHZG8.... --SNIP-- shashank@spiff #> ipsec showhostkey --right --id @spiff # RSA 1024 bits spiff.ece.uic.edu Wed Aug 13 10:26:47 2003 rightrsasigkey=0sAQNaO9TGUfxQOjTQJc9Lzq...
-------------------------------------------------------------------------------------------- mia spiff -------------------------------------------------------------------------------------------- ipsec setup start ipsec setup start ipsec setup verify (***) ipsec setup verify (***) ipsec auto --show --add mia-spiff-h2h ipsec auto --show --add mia-spiff-h2h ipsec auto --show --up mia-spiff-h2h 104 "mia-spiff-h2h" #4: STATE_MAIN_I1: initiate 106 "mia-spiff-h2h" #4: STATE_MAIN_I2: sent MI2, expecting MR2 108 "mia-spiff-h2h" #4: STATE_MAIN_I3: sent MI3, expecting MR3 004 "mia-spiff-h2h" #4: STATE_MAIN_I4: ISAKMP SA established 112 "mia-spiff-h2h" #5: STATE_QUICK_I1: initiate 004 "mia-spiff-h2h" #5: STATE_QUICK_I2: sent QI2, IPsec SA established ---------------------------------------------------------------------------------------------
[shashank@mia /etc]# tcpdump -i eth0 host spiff tcpdump: listening on eth0 17:26:39.803815 spiff > mia: ESP(spi=0x4389906e,seq=0x11e) 17:26:39.803953 mia > spiff: ESP(spi=0x7a1f85e0,seq=0x120)You can see ESP(spi=0x4389906e,seq=0x11e) which means that the packets are indeed encrypted using ESP.
[shashank@mia /etc]# netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 131.193.50.187 131.193.50.1 255.255.255.255 UGH 40 0 0 ipsec0 131.193.50.0 0.0.0.0 255.255.255.0 U 40 0 0 eth0 131.193.50.0 0.0.0.0 255.255.255.0 U 40 0 0 ipsec0 *** 192.168.0.0 0.0.0.0 255.255.255.0 U 40 0 0 eth1 127.0.0.0 0.0.0.0 255.0.0.0 U 40 0 0 lo 0.0.0.0 131.193.50.1 0.0.0.0 UG 40 0 0 eth0 --------------------------------------------------------------------------------- shashank@spiff:~# netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 131.193.50.165 131.193.50.1 255.255.255.255 UGH 0 0 0 ipsec0 192.168.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 131.193.50.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 131.193.50.0 0.0.0.0 255.255.255.0 U 0 0 0 ipsec0 *** 127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo 0.0.0.0 131.193.50.1 0.0.0.0 UG 0 0 0 eth0One can see that if a packet is sent from spiff to mia, the Ipstack will use the interface ipsec0. For all other packets eth0 is used. I am a bit confused about why the lines with "***" are there in the kernel routing table.
mia# ipsec look mia.ece.uic.edu Fri Aug 22 11:42:47 CDT 2003 131.193.50.165/32 -> 131.193.50.187/32 => [email protected] [email protected] (210) ipsec0->eth0 mtu=16260(1443)->1500 [email protected] ESP_3DES_HMAC_MD5: dir=out src=131.193.50.165 iv_bits=64bits iv=0xda32b05b84e9bc71 ooowin=64 seq=105 alen=128 aklen=128 eklen=192 life(c,s,h)=bytes(14816,0,0)addtime(147,0,0)usetime(83,0,0)packets(105,0,0) idle=73 refcount=4 ref=12 [email protected] ESP_3DES_HMAC_MD5: dir=in src=131.193.50.187 iv_bits=64bits iv=0xcd481addfa20735c ooowin=64 seq=69 bit=0xffffffffffffffff alen=128 aklen=128 eklen=192 life(c,s,h)=bytes(10351,0,0)addtime(147,0,0)usetime(83,0,0)packets(69,0,0) idle=73 refcount=73 ref=7 [email protected] IPIP: dir=in src=131.193.50.187 policy=131.193.50.187/32->131.193.50.165/32 flags=0x8<> life(c,s,h)=bytes(10351,0,0)addtime(147,0,0)usetime(83,0,0)packets(69,0,0) idle=73 refcount=4 ref=8 [email protected] IPIP: dir=out src=131.193.50.165 life(c,s,h)=bytes(11454,0,0)addtime(147,0,0)usetime(83,0,0)packets(105,0,0) idle=73 refcount=4 ref=13 Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 131.193.50.1 0.0.0.0 UG 40 0 0 eth0 131.193.50.0 0.0.0.0 255.255.255.0 U 40 0 0 eth0 131.193.50.0 0.0.0.0 255.255.255.0 U 40 0 0 ipsec0 131.193.50.187 131.193.50.1 255.255.255.255 UGH 40 0 0 ipsec0AND
mia# ipsec auto --status 000 interface ipsec0/eth0 131.193.50.165 000 000 debug none 000 000 "mia-spiff-h2h": 131.193.50.165[@mia]---131.193.50.1...131.193.50.1---131.193.50.187[@spiff] 000 "mia-spiff-h2h": ike_life: 3600s; ipsec_life: 28800s; rekey_margin: 540s; rekey_fuzz: 100%; keyingtries: 0 000 "mia-spiff-h2h": policy: RSASIG+ENCRYPT+TUNNEL+DONTREKEY+UP+failurePASS; interface: eth0; erouted 000 "mia-spiff-h2h": newest ISAKMP SA: #1; newest IPsec SA: #2; eroute owner: #2 000 000 #2: "mia-spiff-h2h" STATE_QUICK_I2 (sent QI2, IPsec SA established); EVENT_SA_EXPIRE in 28555s; newest IPSEC; eroute owner 000 #2: "mia-spiff-h2h" [email protected] [email protected] [email protected] [email protected] 000 #1: "mia-spiff-h2h" STATE_MAIN_I4 (ISAKMP SA established); EVENT_SA_EXPIRE in 3355s; newest ISAKMP 000Note: In the above output you can make out that RSA public key was used (RSASIG+ENCRYPT+TUNNEL+DONTREKEY+UP+failurePASS). However if you are using a secret key this output would be (PSK+ENCRYPT+TUNNEL+DONTREKEY+UP+failurePASS).
-------------------------------------------------------------------------------------------- mia spiff -------------------------------------------------------------------------------------------- ipsec auto --show --down mia-spiff-h2h ipsec auto --show --down mia-spiff-h2h ipsec auto --show --delete mia-spiff-h2h (***) ipsec auto --show --delete mia-spiff-h2h (***) ipsec setup stop ipsec setup stop ---------------------------------------------------------------------------------------------
1 - 50 --SNIP-- 51 conn mia-spiff-h2h-manual 52 left=131.193.50.165 53 # leftsubnet=131.193.50.165/32 54 leftnexthop=131.193.50.1 55 right=131.193.50.187 56 # rightsubnet=131.193.50.187/32 57 rightnexthop=131.193.50.1 58 spi=0x300 59 esp=3des-md5-96 60 espenckey=0x7ae54bc2_c5f885ae_e21f6d4b_e118b1b2_4a877dee_c3ee713d 61 espauthkey=0x1cc467d1_8931fea2_d2c6d607_b09b482d 62 # esp=3des 63 # espenckey=0x7ae54bc2_c5f885ae_e21f6d4b_e118b1b2_4a877dee_c3ee713d 64 ###(manual) authentication algorithm and parameters to it 65 # ah=hmac-md5-96 66 # ahkey=0x1cc467d1_8931fea2_d2c6d607_b09b482d 67 # (auto) authentication control 68 # auth=ah 69Most of the options were explained earlier in Automatic Host-to-host IPSec Tunnels.
------------------------------------------------------------------------- mia spiff ------------------------------------------------------------------------- ipsec setup start ipsec setup start ipsec setup verify (***) ipsec setup verify (***) ipsec manual --show --up mia-spiff-h2h-manual ipsec manual --show --up mia-spiff-h2h-manual ---------------------------------------------------------------------------If you uncomment the manualstart="mia-spiff-h2h-manual" option you don't have to execute the --up commands.
------------------------------------------------------------------------- mia spiff ------------------------------------------------------------------------- ipsec setup stop ipsec setup stop ---------------------------------------------------------------------------You can even use the ipsec manual --down and --unroute commands. But once --down is executed, the connection to the peer is broken and your terminal will hang up. You will have to establish a seperate connection to the peer from somewhere else to execute the --unroute command.
Lines (1 to 50) and (51 to 69) --SNIP-- 70 conn mia-spiff-n2n 71 left=131.193.50.165 72 leftsubnet=192.168.0.0/24 73 leftnexthop=131.193.50.1 74 leftid=@mia 75 leftrsasigkey=0sAQOAS9+zP7L5pHZG8JgdBPf97IP4T... 76 right=131.193.50.187 77 rightsubnet=192.168.3.0/24 78 rightnexthop=131.193.50.1 79 rightid=@spiff 80 rightrsasigkey=0sAQNaO9TGUfxQOjTQJc9LzqWzrZkF... 81 auto=ignore 82 rekey=no 83 failureshunt=passthrough 84 pfs=no 85 compress=no 86 auth=esp 87 authby=rsasig 88Everything is the same as Automatic Host-to-host IPSec Tunnels, except leftsubnet and rightsubnet, which are replaced by leftsubnet=192.168.0.0/24 and rightsubnet=192.168.2.0/24.
#!/bin/sh echo -e "Disabling\n" IPTABLES=/sbin/iptables EXTIF="eth0" INTIF="eth1" echo "1" > /proc/sys/net/ipv4/ip_forward echo "1" > /proc/sys/net/ipv4/ip_dynaddr $IPTABLES -P INPUT ACCEPT $IPTABLES -F INPUT $IPTABLES -P OUTPUT ACCEPT $IPTABLES -F OUTPUT $IPTABLES -P FORWARD ACCEPT $IPTABLES -F FORWARD $IPTABLES -t nat -F echo -e "done.\n"
shashank@hulk# route add -net 192.168.0.0/24 gw 192.168.3.1 ------------------------------------------------------------ shashank@zidler# route add -net 192.168.3.0/24 gw 192.168.0.1
Lines 1 - 88 --SNIP-- 89 conn mia-spiff-n2n-manual 90 left=131.193.50.165 91 leftsubnet=192.168.0.0/24 92 leftnexthop=131.193.50.1 93 right=131.193.50.187 94 rightsubnet=192.168.3.0/24 95 rightnexthop=131.193.50.1 96 spi=0x500 97 esp=3des-md5-96 98 espenckey=0x7ae54bc2_c5f885ae_e21f6d4b_e118b1b2_4a877dee_c3ee713d 99 espauthkey=0x1cc467d1_8931fea2_d2c6d607_b09b482d 100 # esp=3des 101 # espenckey=0x7ae54bc2_c5f885ae_e21f6d4b_e118b1b2_4a877dee_c3ee713d 102 ###(manual) authentication algorithm and parameters to it 103 # ah=hmac-md5-96 104 # ahkey=0x1cc467d1_8931fea2_d2c6d607_b09b482d 105 # (auto) authentication control 106 # auth=ahMost of the options were explained earlier in Automatic Host-to-host IPSec Tunnels.
#!/bin/sh echo -e "Disabling\n" IPTABLES=/sbin/iptables EXTIF="eth0" INTIF="eth1" echo "1" > /proc/sys/net/ipv4/ip_forward echo "1" > /proc/sys/net/ipv4/ip_dynaddr $IPTABLES -P INPUT ACCEPT $IPTABLES -F INPUT $IPTABLES -P OUTPUT ACCEPT $IPTABLES -F OUTPUT $IPTABLES -P FORWARD ACCEPT $IPTABLES -F FORWARD $IPTABLES -t nat -F echo -e "done.\n"
------------------------------------------------------------------------- mia spiff ------------------------------------------------------------------------- ipsec setup start ipsec setup start ipsec setup verify (***) ipsec setup verify (***) ipsec manual --show --up mia-spiff-n2n-manual ipsec manual --show --up mia-spiff--n2n-manual ---------------------------------------------------------------------------If you add manualstart="mia-spiff-n2n-manual" option to the config section of /etc/ipsec.conf, you don't have to execute the --up commands.
shashank@hulk# route add -net 192.168.0.0/24 gw 192.168.3.1 ------------------------------------------------------------ shashank@zidler# route add -net 192.168.3.0/24 gw 192.168.0.1
------------------------------------------------------------------------- mia spiff ------------------------------------------------------------------------- ipsec setup stop ipsec setup stop ---------------------------------------------------------------------------You can even use the ipsec manual --down and --unroute commands. But once --down is executed, the connection to the peer is broken and your terminal will hang up. You will have to establish a seperate connection to the peer from somewhere else to execute the --unroute command.