Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Tutorial Openvpn
Tutorial Openvpn
introduzione a
OpenVPNTM
Un piccolo tutorial in italiano per OpenVPNTM 2.0
www.openvpn.net
GUI WinXP www.openvpn.se
This document is free; you can redistribute it and/or modify it under the terms of
the GNU General Public License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This document is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along with
this document; if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA.
2
OpenVPN
OpenVPNTM è una soluzione VPN totalmente basata su SSL che può funziona-
re con larghissimo range di configurazioni, come accessi remoti, sicurezza WI-FI
e tanti altri.
OpenVPNTM fornisce una sicurezza a livello Applicazione della pila OSI grazie
all’infrastruttura protocollare industriale standard SSL/TLS sulla quale si ap-
poggia. È in grado inoltre di lavorare sia a livello 2, in configurazione bridged,
che a livello 3 OSI, in modalità routed. La scelta tra queste due configura-
zioni è legata alle specifiche esigenze. Supporta metodi di autenticazione dei
client flessibili basati su certificati, smart card e/o autenticazione a due livelli,
permettendo politiche di utenti di gruppo usando regole di firewall applicate
all’interfaccia virtuale della VPN. OpenVPNTM non è un proxy web e non fun-
ziona tramite un web browser.
O.S. supportati
OpenVPNTM funziona sui seguenti sistemi operativi: Linux, Windows 2000/XP
e successivi, OpenBSD, FreeBSD, NetBSD, Mac OS X, e Solaris.
3
• inserire nel tunnel reti i cui terminali pubblici sono dinamici come DHCP
o dial-up
• inserire nel tunnel reti orientate alla connessione con accessi regolati senza
dover ricorrere a regole di firewall esplicite
• inserire nel tunnel reti che utilizzano NAT
• creare un bridge ethernet sicuro tramite un dispositivo tap virtuale
• utilizzare una GUI su WinXP o Mac OS X per controllare OpenVPNTM
4
Generare certificato e chiave della CA
In questa serie di paragrafi genereremo il certificato e la chiave della CA, del
server e di alcuni client.
Per la gestione della PKI useremo degli script già inclusi in OpenVPNTM .
In una console o prompt dei comandi entra nella sottodirectory ./easy-rsa e fai
partire
init-config
Ora editiamo il file vars e soprattutto non lasciare vuoti i seguenti parametri
KEY_COUNTRY, KEY_PROVINCE,KEY_CITY, KEY_ORG, e KEY_EMAIL.
Poi inizializziamo la PKI:
vars
clean-all
build-ca
Il comando finale build-ca creerà certificato e chiave della CA invocando il
comando interattivo openssl:
ai:easy-rsa # ./build-ca
Generating a 1024 bit RSA private key
............++++++
...........++++++
writing new private key to ’ca.key’
-----
You are about to be asked to enter information that will be
incorporated into your certificate request. What you are about to
enter is what is called a Distinguished Name or a DN. There are
quite a few fields but you can leave some blank For some fields
there will be a default value, If you enter ’.’, the field will be
left blank.
-----
Country Name (2 letter code) [KG]:
State or Province Name(fullname)[NA]:
Locality Name (eg, city) [BISHKEK]:
Organization Name (eg, company) [OpenVPN-TEST]:
Organizational Unit Name (eg,section) []:
Common Name (eg, your name or your server’s hostname)[]:OpenVPN-CA
Email Address [me@myhost.mydomain]:
Da notare che la maggior parte dei parametri è già stata settata in vars e quindi
bisogna settare esplicitamente solo il parametro Common Name.
Nell’esempio è stato usato OpenVPN-CA.
5
Generare certificato e chiave del server
Il comando è:
build-key-server server
Come prima molti parametri sono già settati di default e l’unico da inserire è
Common Name. Mettiamo server.
Vengono poste due domande e dobbiamo dare risposta positiva:
"Sign the certificate? [y/n]" and "1 out of 1 certificate requests
certified, commit? [y/n]".
ai:easy-rsa # ./build-dh
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
.................+...........................................
...................+.............+.................+.........
......................................
File di chiavi
Ora troveremo i certificati e le chiavi appena generati nella sottodirectory keys.
Filename Needed By Purpose Secret
ca.crt server + all clients Root CA certificate NO
ca.key key signing machine only Root CA key YES
dhn.pem server only Diffie Hellman parameters NO
server.crt server only Server Certificate NO
server.key server only Server Key YES
client1.crt client1 only Client1 Certificate NO
client1.key client1 only Client1 Key YES
client2.crt client2 only Client2 Certificate NO
client2.key client2 only Client2 Key YES
client3.crt client3 only Client3 Certificate NO
client3.key client3 only Client3 Key YES
6
Il passo finale nel processo di generazione delle chiavi è il copiare tutti i file ne-
cessari nelle varie macchine, avendo cura di usare un canale sicuro per i file da
mantenere segreti.
7
Creare file di configurazione per server e client
Editare il file di esempio di configurazione del server
I file di esempio sono il punto di partenza per la configurazione di un server
OpenVPNTM
Quelli inclusi nei sorgenti OpenVPNTM vanno poi adattati alle proprie esigenze.
Se vuoi utilizzare istanze multiple di OpenVPNTM sulla stessa macchina è bene
utilizzare differenti file di configurazione per ogni istanza:
• edita i percorsi dei certificati e delle chiavi come prima cosa
• scegli se vuoi routed o bridge e quindi scegli tun o tap
• server tcp o udp
• togli il commento a client-to-client se vuoi che i client si vedano tra loro
e non vedano solo il server
• usa una porta differente per ogni istanza
• se usi Windows ogni connessione deve avere il suo adattatore TAP-Win32.
Puoi aggiungere adattatori virtuali con Start Menu → All Programs
→ OpenVPNTM → Add a new TAP-Win32 virtual ethernet
adapter.
• se stai usando istanze multiple di OpenVPNTM nella stessa directory, ri-
cordati di editare i percorsi dei file di log in maniera tale da non sovra-
scrivere quelli di un’istanza con quelli dell’altra.
Vedi i file di esempio funzionanti a pagina 13, 19.
Nota: sotto linux i file di configurazione sono chiamati server.conf e client.conf
mentre sotto windows client.ovpn e server.ovpn.
8
Incrementare il livello di sicurezza
L’autenticazione TLS aggiunge un’ulteriore firma HMAC a tutti i pacchetti del-
l’handshake SSL/TLS per la verifica dell’integrità. Se il pacchetto non ha la
firma giusta viene scartato direttamente senza processarlo.
Protegge contro:
Server bridged
Per avere un server bridged e quindi avere i seguenti vantaggi bisogna, oltre al
file di configurazione creare il bridge di rete ed è possibile farlo solo su linux o
winXP/2003.
Vantaggi:
9
Svantaggi:
10
Configurare OpenVPN per partire automaticamente all’av-
vio dell’O.S.
In windows l’installer imposta già il servizio ma è disabilitato per default. Per
attivarlo vai in Control Panel / Administrative Tools / Services cerca nell’elenco
OpenVPNTM , clicca col tasto destro e scegli proprietà. Dopo di che setta il
tipo di avvio in: Automatico. Dal prossimo riavvio OpenVPNTM partirà in
automatico.
NB: Quando partirà in automatico OpenVPNTM farà partire ogni file .ovpn
contenuto nella cartella ./config in una istanza separata, quindi assicurati di
avere un adattatore virtuale per ogni istanza che verrà fatta partire!
Server su IP dinamico
Se la macchina sulla quale risiede il server possiede un IP pubblico dinamico si
può aggirare l’ostacolo iscrivendosi gratuitamente ad un servizio di DNS il quale
associa un nome scelto da noi all’IP che gli viene dinamicamente comunicato
da un piccolissimo programmino client che continuamente legge e comunica il
nostro IP dinamico al server DNS internet. In pratica come IP del server utiliz-
zeremo un nome pippo.dns.org invece del classico IP in formato decimale. Ha
il vantaggio di essere gratuito e più semplice da ricordare dato che è un nome e
non una serie di numeri.
Un esempio di sito che fornisce questo servizio gratuitamente è www.dyndns.org.
11
• sever bridged: dal client non possiamo pingare direttamente il server in
quanto è solo un gateway e non compare tra le macchine in rete, a meno che
il client non possa vedere la rete lan che sta dietro il server OpenVPNTM
, ma possiamo pingare un altro client connesso al nostro server
Ricordarsi ovviamente di permettere su tutti i computer collegati alla VPN a
OpenVPNTM di passare indisturbato tramite i firewall!
Se il ping funziona l’intera VPN funziona. Congratulazioni!
Tunnel cifrato
Il tunnel della VPN può venire cifrato per aggiungere un ulteriore grado di
sicurezza. Per fare ciò basta aggiungere una riga nel file di configurazione del
server e di tutti i client.
Il comando è
cipher algoritmo
seguito dalla dimensione della chiave in bit se questa può essere variabile
keysize dimensione
OpenVPNTM supporta i seguenti algoritmi di cifratura
C:\Programmi\OpenVPN>openvpn --show-ciphers
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.
12
Esempi di server e client
Server routed
#################################################
# Sample OpenVPN 2.0 config file for #
# multi-client server. #
# #
# This file is for the server side #
# of a many-clients <-> one-server #
# OpenVPN configuration. #
# #
# OpenVPN also supports #
# single-machine <-> single-machine #
# configurations (See the Examples page #
# on the web site for more info). #
# #
# This config should work on Windows #
# or Linux/BSD systems. Remember on #
# Windows to quote pathnames and use #
# double backslashes, e.g.: #
# "C:\\Program Files\\OpenVPN\\config\\foo.key" #
# #
# Comments are preceded with ’#’ or ’;’ #
#################################################
13
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# an explicit unit number, such as tun0.
# On Windows, use "dev-node" for this.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun
14
# The server will take 10.8.0.1 for itself,
# the rest will be made available to clients.
# Each client will be able to reach the server
# on 10.8.0.1. Comment this line out if you are
# ethernet bridging. See the man page for more info.
server 10.8.0.0 255.255.255.0
15
# First, uncomment out these lines:
;client-config-dir ccd
;route 192.168.40.128 255.255.255.248
# Then create a file ccd/Thelonious with this line:
# iroute 192.168.40.128 255.255.255.248
# This will allow Thelonious’ private subnet to
# access the VPN. This example will only work
# if you are routing, not bridging, i.e. you are
# using "dev tun" and "server" directives.
16
# 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"
17
# The second parameter should be ’0’
# on the server and ’1’ on the clients.
tls-auth C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\ta.key 0 # This file is secret
18
# while "log-append" will append to it. Use one
# or the other (but not both).
;log openvpn.log
;log-append openvpn.log
Server bridged
#################################################
# Sample OpenVPN 2.0 config file for #
# multi-client server. #
# #
# This file is for the server side #
# of a many-clients <-> one-server #
# OpenVPN configuration. #
# #
# OpenVPN also supports #
# single-machine <-> single-machine #
# configurations (See the Examples page #
# on the web site for more info). #
# #
# This config should work on Windows #
# or Linux/BSD systems. Remember on #
# Windows to quote pathnames and use #
# double backslashes, e.g.: #
# "C:\\Program Files\\OpenVPN\\config\\foo.key" #
# #
# Comments are preceded with ’#’ or ’;’ #
19
#################################################
20
# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key). Each client
# and the server must have their own cert and
# key file. The server and all clients will
# use the same ca file.
#
# See the "easy-rsa" directory for a series
# of scripts for generating RSA certificates
# and private keys. Remember to use
# a unique Common Name for the server
# and each of the client certificates.
#
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
ca C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\ca.crt
cert C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\server.crt
key C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\server.key # This file should be kept secret
21
# IP/netmask on the bridge interface, here we
# assume 10.8.0.4/255.255.255.0. Finally we
# must set aside an IP range in this subnet
# (start=10.8.0.50 end=10.8.0.100) to allocate
# to connecting clients. Leave this line commented
# out unless you are ethernet bridging.
server-bridge 10.8.0.1 255.255.255.0 10.8.0.50 10.8.0.100
22
# Suppose that you want to enable different
# firewall access policies for different groups
# of clients. There are two methods:
# (1) Run multiple OpenVPN daemons, one for each
# group, and firewall the TUN/TAP interface
# for each group/daemon appropriately.
# (2) (Advanced) Create a script to dynamically
# modify the firewall in response to access
# from different clients. See man
# page for more info on learn-address script.
;learn-address ./script
23
# only for testing purposes. For production use,
# each client should have its own certificate/key
# pair.
#
# IF YOU HAVE NOT GENERATED INDIVIDUAL
# CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
# EACH HAVING ITS OWN UNIQUE "COMMON NAME",
# UNCOMMENT THIS LINE OUT.
;duplicate-cn
24
# clients we want to allow.
;max-clients 100
25
;crl-verify G:\\Programmi\\OpenVPN\\easy-rsa\\keys\\crl.pem
#serve per escludere dall’autenticazione i certificati revocati
26
# to load balance between the servers.
remote IP_ADDRESS_SERVER 1194
;remote my-server-2 1194
# SSL/TLS parms.
# See the server config file for more
# description. It’s best to use
# a separate .crt/.key file pair
# for each client. A single ca
27
# file can be used for all clients.
ca C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\ca.crt
cert C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\client.crt
key C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\client.key
28
# #
# This configuration can be used by multiple #
# clients, however each client should have #
# its own cert and key files. #
# #
# On Windows, you might want to rename this #
# file so it has a .ovpn extension #
##############################################
29
# Keep trying indefinitely to resolve the
# host name of the OpenVPN server. Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite
# SSL/TLS parms.
# See the server config file for more
# description. It’s best to use
# a separate .crt/.key file pair
# for each client. A single ca
# file can be used for all clients.
ca C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\ca.crt
cert C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\client.crt
key C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\client.key
30
# a potential attack discussed here:
# http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the nsCertType
# field set to "server". The build-key-server
# script in the easy-rsa folder will do this.
ns-cert-type server
31