Yves-Gwenael Bourhis <[email protected]>, Mandriva SA, Paris
(C) 2006 Yves-Gwenael Bourhis -- Distribute freely without change -- leave Copyright Note intact
urpmi openvpn cd /etc/openvpn/ cp -r /usr/share/openvpn/easy-rsa/ /etc/openvpn/in case of self build rpm, replace the last command from above by:
cp -r /usr/share/doc/openvpn-2.x.x/easy-rsa/ /etc/openvpn/Then:
cp /usr/share/openvpn/sample-config-files/server.conf /etc/openvpn/or, in case of self build rpm, replace the last command from above by:
cp /usr/share/doc/openvpn-2.x.x/sample-config-files/server.conf /etc/openvpn/
cd /etc/openvpn/easy-rsaor, if openvpn version is >= 2.1.x:
cd /etc/openvpn/easy-rsa/1.0/Now edit the /etc/openvpn/easy-rsa/vars file and set the
KEY_COUNTRY
, KEY_PROVINCE
, KEY_CITY, KEY_ORG
, and KEY_EMAIL
parameters. Don't leave any of these parameters blank.source vars ./clean-all ./build-caEach time you need to create new keys using easy-rsa, launch the
source vars
command first../clean-all
command is to be used only the first time, because it deletes the ca and all keys.yes
when prompted to auto sign the certificate../build-key-server $SERVERreplace
$SERVER
with the name you want to give to the server certificate../build-key-server server
./build-key client1
( or any name other than "client1" )./build-key revokekey
( or any name other than "revokekey" )./revoke-full revokekeyThis builds a /etc/openvpn/easy-rsa/keys/crl.pem file.
ln keys/crl.pem /etc/openvpn/Beware, create a hardlink as shown above (
ln
without the -s
option)../build-dh
ca ca.crt
-->> ca /etc/openvpn/easy-rsa/keys/ca.crt
cert server.crt
-->> cert /etc/openvpn/easy-rsa/keys/server.crt
key server.key
-->> key /etc/openvpn/easy-rsa/keys/server.key
dh dhxxx.pem
-->> dh /etc/openvpn/easy-rsa/keys/dhxxx.pem
# CRL (certificate revocation list) verification crl-verify /etc/openvpn/crl.pem
;user nobody
-->> user nobody
;group nobody
-->> group nogroup
:
and to change nobody
to nogroup
in the lines just above._________ | OpenVPN | WAN(IP=81.82.83.84)---| Server |---LAN(192.168.0.X/255.255.255.0) |_________|you will configure /etc/openvpn/server.conf as follows:
# Push routes to the client to allow it # to reach other private subnets behind # the server. Remember that these # private subnets will also need # to know to route the OpenVPN client # address pool (10.8.0.0/255.255.255.0) # back to the OpenVPN server. push "route 192.168.0.0 255.255.255.0"If you wish to redirect the gateway threw the vpn uncomment the following line:
push "redirect-gateway"and you may also wish to push DNS and WINS servers:
# Certain Windows-specific network settings # can be pushed to clients, such as DNS # or WINS server addresses. CAVEAT: # http://openvpn.net/faq.html#dhcpcaveats push "dhcp-option DNS 10.8.0.1" push "dhcp-option WINS 10.8.0.1"
client-to-client
cipher BF-CBC
(Blowfish 128 bits)# Select a cryptographic cipher. # This config item must be copied to # the client config file as well. ;cipher BF-CBC # Blowfish (default) ;cipher AES-128-CBC # AES ;cipher DES-EDE3-CBC # Triple-DESLeaving everything commented (as is), is identical as uncommenting the following line:
cipher BF-CBC # Blowfish (default)The result is the same.
cipher AES-256-CBCWith the above line, you will the have 256-bit version of AES (Advanced Encryption Standard).
cipher BF-CBC
, you will need to set the same on the client side.openvpn --show-ciphersThe displayed result will look like this:
The following ciphers and cipher modes are available for use with OpenVPN. Each cipher shown below may be used as a parameter to the --cipher option. The default key size is shown as well as whether or not it can be changed with the --keysize directive. Using a CBC mode is recommended. DES-CBC 64 bit default key (fixed) IDEA-CBC 128 bit default key (fixed) RC2-CBC 128 bit default key (variable) DES-EDE-CBC 128 bit default key (fixed) DES-EDE3-CBC 192 bit default key (fixed) DESX-CBC 192 bit default key (fixed) BF-CBC 128 bit default key (variable) RC2-40-CBC 40 bit default key (variable) CAST5-CBC 128 bit default key (variable) RC5-CBC 128 bit default key (variable) RC2-64-CBC 64 bit default key (variable) AES-128-CBC 128 bit default key (fixed) AES-192-CBC 192 bit default key (fixed) AES-256-CBC 256 bit default key (fixed)
cipher BF-CBC keysize 512But don't forget to set the same in the client configuration file.
service openvpn startRun :
ifconfig
urpmi opensc engine_pkcs11 openct openvpn-2.1_beta14-1.i586.rpm service openct start
cp -r /usr/share/doc/openvpn-2.1_beta14/easy-rsa/ /etc/openvpn/ cd /etc/openvpn/easy-rsa/2.0/In /etc/openvpn/easy-rsa/2.0/ edit openssl.cnf and modify this section:
[ engine_section ] # # If you are using PKCS#11 # Install engine_pkcs11 of opensc (www.opensc.org) # And uncomment the following # verify that dynamic_path points to the correct location # #pkcs11 = pkcs11_section [ pkcs11_section ] engine_id = pkcs11 dynamic_path = /usr/lib/engines/engine_pkcs11.so MODULE_PATH = $ENV::PKCS11_MODULE_PATH PIN = $ENV::PKCS11_PIN init = 0to make it like this:
[ engine_section ] # # If you are using PKCS#11 # Install engine_pkcs11 of opensc (www.opensc.org) # And uncomment the following # verify that dynamic_path points to the correct location # pkcs11 = pkcs11_section [ pkcs11_section ] engine_id = pkcs11 #dynamic_path = /usr/lib/engines/engine_pkcs11.so dynamic_path = /usr/lib/openssl/engines/engine_pkcs11.so #MODULE_PATH = $ENV::PKCS11_MODULE_PATH MODULE_PATH = /usr/lib/opensc-pkcs11.so #PIN = $ENV::PKCS11_PIN init = 0Do not forget to comment out
pkcs11 = pkcs11_section
as shown above.--pkcs11
option to the easy-rsa scripts.pkcs15-init --erase-card -T pkcs15-init --create-pkcs15 -T pkcs15-init --store-pin --auth-id 0 --label "YourLabelToTheKey"
pkcs15-init --store-certificate keys/ca.crt --authority --label "Mandriva CA" --id "D1:FB:AF:27:EB:B7:34:99:52:20:D2:33:19:C0:E8:69:51:7A:ED:B6" --auth-id 0In the above example, I decided to use the key's fingerprint as an id, but you can use omit this and automatic default id's will be set (i.e. id "46" is a standard).
--auth-id 0
is compulsary parameter.openssl x509 -noout -text -in keys/ca.crt | lessDo the same the read the other certificates ids.
pkcs15-init --store-certificate keys/client1.crt --label "Client1" --id "DC:EF:ED:19:74:73:DA:44:B6:A4:EE:F5:8B:1F:C5:43:33:2D:1F:A0" --auth-id 0
pkcs15-init --store-private-key keys/client1.key --public-key-label "Client1" --label "Client1 Private Key" --id "DC:EF:ED:19:74:73:DA:44:B6:A4:EE:F5:8B:1F:C5:43:33:2D:1F:A0" --auth-id 0Important : the
--id
has to be the exact same as the one you used to store the client1.crt (here:DC:EF:ED:19:74:73:DA:44:B6:A4:EE:F5:8B:1F:C5:43:33:2D:1F:A0
)openvpn --show-pkcs11-slots /usr/lib/opensc-pkcs11.so openvpn --show-pkcs11-objects /usr/lib/opensc-pkcs11.so 0Note this part of the output (example from my test key):
You can access this token using --pkcs11-slot-type "label" --pkcs11-slot "OpenSC Card (PKyves)" options.And note also the subject for the client1 keyring. which in my example is:
Object Type: Certificate CKA_ID: dc ef ed 19 74 73 da 44 b6 a4 ee f5 8b 1f c5 43 33 2d 1f a0 CKA_LABEL: Client1 subject: /C=FR/ST=Ile-de-France/L=Paris/O=Mandriva/CN=client1/[email protected] serialNumber: 03 notBefore: 060621144856Zafter having noted these down, I will modifie the client's configuratin file (/etc/openvpn.client.conf) by removing the
cert
and key
lines, and I'll replace them with what follows:pkcs11-providers /usr/lib/opensc-pkcs11.so pkcs11-slot-type "label" pkcs11-slot "OpenSC Card (PKyves)" pkcs11-id-type subject pkcs11-id "/C=FR/ST=Ile-de-France/L=Paris/O=Mandriva/CN=client1/[email protected]"Now, each time the client is started, the PIN key will be asked before connection.
urpmi openvpn cd /etc/openvpn/ cp -r /usr/share/openvpn/sample-config-files/client.conf /etc/openvpn/in case of self build rpm, replace the last command from above by:
cp -r /usr/share/doc/openvpn-2.x.x/sample-config-files/client.conf /etc/openvpn/
scp /etc/openvpn/easy-rsa/keys/ca.crt user@ip:/etc/openvpn/ scp /etc/openvpn/easy-rsa/keys/client1.crt root@PC2ip:/etc/openvpn/ scp /etc/openvpn/easy-rsa/keys/client1.key root@PC2ip:/etc/openvpn/Where
PC2ip
is the client's IP.remote server
-->> remote "server ip" port
( ex: remote 192.168.1.100 1194
):user nobody
-->> user nobody
:group nobody
-->> group nogroup
ca ca.crt
-->> ca /etc/openvpn/ca.crt
cert client1.crt
-->> cert /etc/openvpn/client1.crt
key client1.key
-->> key /etc/openvpn/client1.key
:ns-cert-type server
-->> ns-cert-type server
cipher BF-CBC
Blowfish 128 bits encryption, add the same as on the server side.cipher AES-256-CBCor like this:
cipher BF-CBC keysize 512
Service openvpn startRun :
ifconfig
#ZONE DISPLAY COMMENTS vpn VPN Remote subnetOr as follows in /etc/shorewall/zones if you have shorewall 3.x.x:
#ZONE TYPE OPTIONS IN OUT # OPTIONS OPTIONS vpn ipv4
#ZONE INTERFACE BROADCAST OPTIONS vpn tun0
# TYPE ZONE GATEWAY GATEWAY # ZONE generic:udp:1194 net 0.0.0.0/0 vpnYou can also do the following:
# TYPE ZONE GATEWAY GATEWAY # ZONE openvpn net 0.0.0.0/0 vpnBut I prefer the
generic:udp:1194
syntax because as you can see in /etc/openvpn/server.conf or /etc/openvpn/client.conf, you can easily define any port and protocol (udp or tcp).generic:udp:1194
syntax you easily reflect the server configuration. the openvpn
syntax is only for the standard openvpn protocol on udp port 1194.#SOURCE DEST POLICY LOG LEVEL loc vpn ACCEPT vpn loc ACCEPTWhere
loc
is the interface to the local network.#SOURCE DEST POLICY LOG LEVEL fw vpn ACCEPT vpn fw ACCEPT
#INTERFACE SUBNET ADDRESS PROTO PORT(S) IPSEC eth0 10.8.0.0/24This above example is supposing eth0 is on your LAN.
service shorewall restart
# tell the OpenVPN server to validate the username/password # entered by clients using the login PAM module plugin /usr/lib/openvpn/openvpn-auth-pam.so /etc/pam.d/login
useradd client1 -M -s /bin/false passwd client1 Changing password for user client1. New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.The
-M
option of useradd
is to create no /home/client1 directory. The -s /bin/false
is to give no shell to the user on the server for security reasons because we only want to have PAM checking the login and password, and that is all.service openvpn restart
# This will direct the OpenVPN client to query the user for a username/password, # passing it on to the server over the secure TLS channel: auth-user-passRestart the Client:
service openvpn restartType your login and password when prompted to do so.
chkconfig --list openvpnIf you see this :
openvpn 0:off 1:off 2:on 3:on 4:on 5:on 6:offrun :
chkconfig openvpn offIf you see this:
openvpn 0:off 1:off 2:off 3:off 4:off 5:off 6:offYou have nothing to do.
service openvpn startand stop it with:
service openvpn stop
chkconfig openvpn onAnd change the
.conf
extension to something else such as .config
..conf
and which is in /etc/openvpn.openvpn --daemon --config /etc/openvpn/clientconf.configWhere /etc/openvpn/clientconf.config is the name you gave to the client file but it can be something else.
ps ax 25305 ? S<s 0:00 openvpn --daemon --config /etc/openvpn/clientconf.configAnd kill it:
kill 25305
client-cert-not-requiredSuch configurations should usually also set:
username-as-common-namewhich will tell the server to use the username for indexing purposes as it would use the Common Name of a client which was authenticating via a client certificate.
client-cert-not-required
will not obviate the need for a server certificate, so a client connecting to a server which uses client-cert-not-required
may remove the cert
and key
directives from the client configuration file, but not the ca
directive, because it is necessary for the client to verify the server certificate.urpmi rpm-build libpam0-devel liblzo2_2-develThen, as a normal user and at the root of your home directory (i.e.:/home/$USER/ where $USER is your username on the machine), create a file (i.e. call it Rpmsetup.sh) and paste this script in it : RPM Setup Script (for i586 arch).
chmod a+x Rpmsetup.shAnd launch it:
./Rpmsetup.sh
gpg --recv-keys 1FBF51F3Verify the package:
gpg --verify openvpn-2.1_beta14.tar.gz.asc(replace openvpn-2.1_beta14.tar.gz.asc by the version you are testing)
tar -xvzf openvpn-2.1_beta14.tar.gzmodify the openvpn-2.1_beta14/openvpn.spec file and when you see:
%if "%{_vendor}" == "MandrakeSoft" %{!?without_lzo:BuildRequires: liblzo1-devel >= 1.07} %{!?without_lzo:Requires: liblzo1 >= 1.07} %else %{!?without_lzo:BuildRequires: lzo-devel >= 1.07} %{!?without_lzo:Requires: lzo >= 1.07}add requires for the
Mandriva
distribution this way:
%if "%{_vendor}" == "MandakeSoft" %{!?without_lzo:BuildRequires: liblzo1-devel >= 1.07} %{!?without_lzo:Requires: liblzo1 >= 1.07} %else %if "%{_vendor}" == "Mandriva" %{!?without_lzo:BuildRequires: liblzo2_2-devel >= 2.01} %{!?without_lzo:Requires: liblzo2_2 >= 2.01} %else %{!?without_lzo:BuildRequires: lzo-devel >= 1.07} %{!?without_lzo:Requires: lzo >= 1.07}create a new tarball with the modifications:
mv openvpn-2.1_beta14.tar.gz openvpn-2.1_beta14.tar.gz.orig tar -cvzf openvpn-2.1_beta14.tar.gz openvpn-2.1_beta14and finally build your rpm (as a user):
rpmbuild -tb openvpn-2.1_beta14.tar.gzEventually install (as root) the missing dependencies and relaunch (as a user) the rpmbuild.
edit-urpm-sources.pl
in a terminal as root, add the distribution sources, and activate the "contrib/testing" repository to get newer versions of OpenVPN.gpg --recv-keys 1FBF51F3Sources and Windows Installer: