First off, the scenario I deployed is on a Linux machine sitting behind a home router (NAT box). The machine we're doing the setup will be called tux.
Clients ---- Internet ---- ISP ---- Router(NAT) ---- tux(Strongswan)
For this to work port 500 and 4500 on your Router(NAT) should be forwarded to tux.
If you don't have a static IP with yout provider, you should consider a dynamic DNS service that will update the DNS address every day, when the address changes.
NOTE: I preferred to build strongswan from source to get the newest algorithms and Ed25519 curve support instead of standard EC curves. Safecurves
- build tools and libraries (
1_install_prerequisites.sh)- build-essential - for building from source
- libgmp-dev - for EC algorithms
- libssl-dev - for openssl support and pubkey authentication
- syslog-ng - for easier debugging
- strongswan source (used version 5.6.0) (
2_get_and_build_ss.sh)- for the enabled options see Strongswan plugins
- openssl is enabled for handling certificates
- chapoly, sha3, gcm, ccm and ctr for support of modern ciphers and AEAD support
- dhcp and farp for forwarding DHCP requests to the DHCP server, and farp to enable
tuxto represent the node on the network - eap plugins for various authentication modes
- disabled unsecure algorithms: des, rc2 sha1, fips-prf
apt-get install strongswan libstrongswan-extra-plugins libcharon-extra-pluginsAfter installing prerequisites and building strongswan we need to configure strongswan and start the daemon.
Configuration is done in the following files:
- /etc/ipsec.conf (
3_ipsec.conf) - /etc/ipsec.d/ (
4_gen_certs.sh)- cacerts/
- private/
- certs/
- /etc/ipsec.secrets (
5_ipsec.secrets) - configure other usernames and passwords - /etc/sysctl.conf - enable IP forwarding and other stuff:
net.ipv4.ip_forward = 1
net.ipv4.ip_no_pmtu_disc = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
After all this is configured, store the caKey somewhere safe and make the caCert.pem and CA.crt available to clients.
Now clients can connect using the defined credentials in ipsec.secrets conf.
For this we could use the pregenarated CA key, BUT it is definately safer to generate a new CA key and deploy the caClientCert.pem in the cacerts folder on the tux.
Generation of the clientCa.key and cert is done as follows:
ipsec pki --gen --type ed25519 --outform pem > caClientKey.pem
ipsec pki --self --in caClientKey.pem --dn "C=US, O=place, CN=strongSwan Client CA" --ca --outform pem > caClientCert.pem
To generate the client certificates use the 6_gen_user_certs.sh on the where caClientKey.pem and caClientCert.pem is aavaliable.
I have tested the Android strongswan client and Linux (arch, ubuntu, debian) with charon-cmd.
Android setup is straightforward after you transfer the caCert and put it into the application.
charon-cmd examples (need to be executed as root):
# EAP mschapv2 example - asks for password
charon-cmd --host some.place.net --identity alice --cert caCert.pem
# Pubkey example
charon-cmd --host some.place.net --identity alice --cert caCert.pem --p12 carol.p12