# emerge -av openswan
# yum install openswan nss-tools ## Red Hat preferuje NSS, protože splňuje FIPS 140-2
# ipsecctl -f /etc/ipsec.conf # ipsecctl -sf ## "show flows"Místo ipsec.conf(5) můžete pořád použít mocnější a složitější INI isakmpd.conf(5).
# ip xfrm policy ipsec.conf(5), ipsec.secrets(5), /etc/ipsec.d/
flow esp from 172.16.258.12 to 192.0.2.24 type bypass
# ip xfrm policy add src 172.16.258.12 dst 192.0.2.24 dir out action allow # ip xfrm policy add src 172.16.258.12 dst 192.0.2.24 dir in action allow
# ipsecctl -ss ## "show SAs" # netstat -rnf encap
# ip xfrm state
# tohle bude samozřejmě "aktivní" pořád # nedělejte to esp from 172.16.258.12 to 192.0.2.24 spi ... auth ... enc ... authkey ... enckey ...
# ip xfrm policy help
"...but Vint could never sell the CATENET name, just had too many... letters in it.
Uh, the military likes three-letter acronyms, so it became TCP/IP, and, y'know, it won."(Van Jacobson)
ike [passive] esp from vic0 to 172.16.259.2 psk "potazmitasdigoat"
# isakmpd -Kdv # ipsecctl -f /etc/ipsec.conf
# vi /etc/ipsec.conf ... odkomentovat include ipsec.d/*.conf # vi /etc/ipsec.d/pripojeni.conf conn pripojeni authby=secret auto=start left=192.0.2.14 right=172.16.259.2 # vi /etc/ipsec.d/my.precious.secrets 192.0.2.14 172.16.259.2: PSK "potazmitasdigoat" # ipsec setup start # ipsec auto --add pripojeni # ipsec auto --up pripojeni
# cd /etc/isakmpd # openssl genrsa -out private/local.key -pubout local.pub 2048 # scp local.pub <druhá.strana>:/etc/isakmpd/pubkeys/ipv4/<moje.ip.v4.adresa>
ike [passive] esp from 172.16.258.1 to 172.16.259.2
# isakmpd -Kdv # ipsecctl -f /etc/ipsec.conf
# ipsec newhostkey --configdir /etc/pki/nssdb --verbose --output newkey ## --- tak, aby byl ten ": RSA { }" na začátku souboru (zase nějaký funky parser) # ipsec showhostkey --left ## nebo --right # ipsec showhostkey --left >> /etc/ipsec.d/pripojeni.conf
conn koneksna authby=rsasig auto=start left=192.0.2.2 leftrsasigkey=0sBORDELKTERYNECHAPUPROCNEMUZEBYTVEZVLASTNIMSOUBORU right=192.0.2.5 rightrsasigkey=0sNEBOVNORMALNIMPEMFORMATUTAKJAKOVNORMALNICHIMPLEMENTACICH
ike [passive] esp from 172.16.258.1 to 172.16.259.2 \ srcid stroj-i.doména.swi dstid stroj-j.doména.swi
leftid=@stroj-i.doména.swi
# pkg_add -iv ikeman
ike from em0 to 10.0.0.0/8 peer 42.42.42.42 dstid brána.doména.swi
# vi /etc/ipsec.d/virtlab.conf conn pripojeni authby=secret auto=start left=192.168.NN.YY right=42.42.42.42 rightid=@brána.doména.swi conn dalsi-flow also=pripojeni rightsubnet=10.0.0.0/8 # ipsec setup start # ipsec auto --add pripojeni # ipsec auto --add dalsi-flow # ipsec auto --up pripojeni # ipsec auto --up dalsi-flow
ike passive from vic0 to any srcid brána.doména.swi ike passive from 10.0.0.0/8 to any srcid brána.doména.swi
remote_filter != "000.000.000.000-255.255.255.255"
iked in /etc/iked/private, strongSwan in /etc/ipsec.d/private.
iked: # openssl genrsa -out local.key 2048 strongSwan: # ipsec pki --gen > local.key.der
iked: # openssl rsa -out ../local.pub -in local.key -pubout strongSwan: # ipsec pki --pub --in local.key.der > local.pub.der
(convert it to a proper format)
openssl rsa -pubin -in local.pub.der -inform DER -outform PEM -out local.pub
iked: # openssl req -new -key /etc/iked/private/local.key -out potazmo.csr strongSwan:
iked: ikeman(1) or otherwise strongSwan: # cat local.pub | ipsec pki --issue --cacert ca.crt --cakey ca.key --dn "C=CZ,O=virtlab,CN=potazmo.virtlab.swi" --san potazmo.virtlab.swi > potazmo.csr
K zamyšlení: Které proměnné ovládá klient? Jak do nich dostane řetězec "; rm -rf /; echo"?
# cat > /etc/ipsec.d/updown.sh #!/bin/sh POLICY_ADD="/usr/bin/sudo /bin/ip xfrm policy add" case "${PLUTO_VERB}" in "up-client-v6") if [ "${PLUTO_CONNECTION}" = "vpn-mynetwork" ]; then logger $PLUTO_VERB adding xfrm allow policies for $PLUTO_CONNECTION at $PLUTO_PEER ${POLICY_ADD} src "${PLUTO_MY_CLIENT}" dst "${PLUTO_MY_CLIENT}" dir in action allow ${POLICY_ADD} src "${PLUTO_MY_CLIENT}" dst "${PLUTO_MY_CLIENT}" dir out action allow fi ;; esac # vi /etc/ipsec.conf [...] conn vpn-mynetwork # inspirace z /usr/libexec/ipsec/_updown leftupdown=/etc/ipsec.d/updown.sh [...] # visudo ipsec ALL=(root) NOPASSWD: /bin/ip
# vi /etc/ipsec.conf
[...]
flow esp from MUJ_ROZSAH to MUJ_ROZSAH type bypass
[...]