Sei sulla pagina 1di 31

Una (mica tanto) breve

introduzione a
OpenVPNTM
Un piccolo tutorial in italiano per OpenVPNTM 2.0
www.openvpn.net
GUI WinXP www.openvpn.se

Ing. Fulvio Capone


Version 0.1, 25 gennaio 2006
www.fulcap.dyndns.org
Copyright 2005
c Fulvio Capone and all the Contributors to OpenVPNTM guide. All
rights reserved.
Traduzione di parte della documentazione di OpenVPNTM e piccole aggiunte dettate
dall’esperienza.

Questo documento è libero; è lecito ridistribuirlo e/o modificarlo secondo i termini


della Licenza Pubblica Generica GNU come pubblicata dalla Free Software Foundation;
o la versione 2 della licenza o (a scelta) una versione successiva.
Questo documento è distribuito nella speranza che sia utile, ma SENZA ALCU-
NA GARANZIA; senza neppure la garanzia implicita di COMMERCIABILITÀ o di
APPLICABILITÀ PER UN PARTICOLARE SCOPO. Si veda la Licenza Pubblica
Generica GNU per avere maggiori dettagli.
Ognuno dovrebbe avere ricevuto una copia della Licenza Pubblica Generica GNU
insieme a questo documento; in caso contrario, la si può ottenere dalla Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, Stati Uniti.

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.

OpenVPNTM è un progetto Open Source ed è licenziato sotto la licenza GPL.


Licenze commerciali sono anche disponibili per ridistribuire OpenVPNTM con
le proprie applicazioni proprietarie.
Per maggiori informazioni contatta info@openvpn.net.

O.S. supportati
OpenVPNTM funziona sui seguenti sistemi operativi: Linux, Windows 2000/XP
e successivi, OpenBSD, FreeBSD, NetBSD, Mac OS X, e Solaris.

Cosa permette di fare OpenVPN


• inserire nel tunnel qualunque sottorete IP o adattatore virtuale ethernet
su una singola porta UDP o TCP
• configurare una batteria di server VPN scalabile, con carico bilanciato tra
essi, usando una o più macchine che possano gestire migliaia di connessioni
dinamiche entranti da client della VPN
• usare tutte le opzioni di cifratura, autenticazione e certificazione della li-
breria OpenSSL per proteggere tutto il tuo traffico privato mentre transita
attraverso Internet
• usare qualunque cifrario, chiave, o firma HMAC (per la verifica dell’inte-
grità del datagramma) supportata da OpenSSL
• scegliere tra una chiave statica basata sulla cifratura convenzionale o
cifratura a chiave pubblica basata sui certificati
• usare una chiave statica preventivamente distribuita oppure sullo scambio
di chiavi dinamico basato su TLS
• usare una compressione sul link adattativa e temporeale e un profilo di
traffico per gestire l’occupazione di banda sul link

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

Implementazione della VPN


Creare la Certificate Authority e generare certificati e chia-
vi per un sever multiclient OpenVPN
Il primo passo nella costruzione di una configurazione OpenVPNTM è stabilire
la PKI (Infrastruttura a Chiave Pubblica).
La PKI consiste in:
• un certificato separato (anche conosciuto come chiave pubblica) e una
chiave privata per il server e per ogni client
• un certificato e una chiave principali della CA usati per firmare ogni
certificato e chiave del server e dei client.
OpenVPNTM supporta l’autenticazione bidirezionale basata sui certificati, ciò
significa che il client deve autenticare il certificato del server e il server quello
del client prima che la mutua connessione fidata sia stabilita.
Entrambi, il server e il client, dovranno autenticare l’altro per verificare che il
presente certificato sia stato firmato dal certificato della CA e per testare le
informazioni appena autenticate (tipo: server o client, nome . . . ).
Questo modello di sicurezza ha delle funzionalità molto interessanti per la OpenVPNTM
:
• Il server deve conoscere solo il proprio certificato/chiave senza dover co-
noscere tutti i certificati dei client
• Il server accetterà solo client i quali certificati sono firmati dal certificato
della CA (che genereremo dopo). Dato che il server può verificare questa
firma senza dover conoscere la chiave privata della CA, quest’ultima può
risiedere su una macchina fisica separata, addirittura su una macchina non
connessa a nessuna rete
• Se la chiave privata è compromessa, può venir revocata, inserendo il certi-
ficato nella CRL (Lista dei Certificati Revocati). CRL permette di re-
spingere i singoli certificati revocati senza dover ricostruire una nuova
PKI
• Il server può dare diritti differenti a seconda del certificato.

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]".

Generare certificato e chiavi per vari client


La procedure è del tutto simile a prima:
buil-key nome_client_1
buil-key nome_client_2
...
Se vuoi chiavi protette da password usa lo script build-key-pass.
Ricorda di inserire il Common name per ogni client e assicurati che sia UNICO!

Generare i parametri Diffie Hellman


I parametri Diffie Hellman devono essere generati per il server OpenVPNTM .
build-dh

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.

Revoca dei certificati


Un certificato può venire revocato in maniera tale da non dover riimplementare
da capo tutta la PKI ogni qualvolta:
• una chiave privata associata ad un certificato è stata compromessa o persa
• un utente di una chiave privata cifrata perde la password della chiave

• vuoi escludere un utente dalla VPN


Per revocare un certificato/chiave bisogna quindi utilizzare i seguenti comandi
vars
revoke-full nome_client
dovresti visualizzare un output simile

Using configuration from /root/openvpn/20/openvpn/tmp/easy-rsa/openssl.cnf


DEBUG[load_index]: unique_subject = "yes"
Revoking Certificate 04.
Data Base Updated
Using configuration from /root/openvpn/20/openvpn/tmp/easy-rsa/openssl.cnf
DEBUG[load_index]: unique_subject = "yes"
client2.crt: /C=KG/ST=NA/O=OpenVPN-TEST/CN=client2/emailAddress=me@myhost.mydomain
error 23 at 0 depth lookup:certificate revoked
Nota l’errore 23 nell’ultima riga: questo avvisa che la verifica della revoca del
certificato è fallita.
Il comando revoke-full crea un file CRL (Lista dei Certificati Revocati) chia-
mato crl.pem nella sottodirectory in cui sono contenute le chiavi.
Bisogna quindi ora aggiungere una riga nel file di configurazione del server che
indichi a quest’ultimo di leggere questa lista.
Il comando da aggiungere è
crl-verify crl.pem
Ricordarsi di settare il percorso corretto del file CRL.
Se questa riga non viene aggiunta il server non legge la lista e per lui è come
se non fosse stato revocato nessun certificato. La lista è cumulativa quindi non
viene generato un file per ogni certificato revocato ma un solo unico file che
include tutti i certificati revocati!
Ora quando un client tenta di collegarsi a OpenVPNTM il server controlla la li-
sta come prima cosa e se viene riscontrato un certificato revocato la connessione
viene immediatamente uccisa.

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.

Editare il file di esempio di configurazione del client


• come per il server per prima cosa edita i percorsi dei certificati e delle
chiavi
• ogni client deve avere il suo certificato/chiave
• edita la direttiva remote in maniera che punti all’indirizzo ip (o nome)
del server OpenVPNTM ed alla sua porta udp/tcp
• infine assicurati che il client sia compatibile con le opzioni scelte nel server
OpenVPNTM , come la compressione, la cifratura e tutte le altre opzioni.

Vedi i file di esempio funzionanti a pagina 26, 28.

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:

• DoS1 attack o port flooding2


• port scanning
• Buffer overflow
• handshake TLS/SSL iniziato da una macchina non autorizzata
Per poter usare l’autenticazione TLS bisogna creare una chiave statica segreta
che si usa in aggiunta alle chiavi/certificati RSA.
Questa viene chiamata trust authority.
Per generare la chiave usiamo il comando:
openvpn --genkey --secret ta.key
Questa chiave deve venire ora copiata a tutti i client e i server della OpenVPNTM
tramite un canale sicuro, in quanto deve rimanere segreta, e messa nella stessa
directory dove già si trovano chiavi e certificati.
Nel file di configurazione del server aggiungere:
tls-auth ta.key 0
con il relativo percorso.
Nel file di configurazione del client aggiungere:
tls-auth ta.key 1
con il relativo percorso.

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:

• broadcast nella VPN


• nessuna rete da impostare staticamente da inviare ai client
• lavora con qualunque protocollo che funzioni su ethernet
• relativamente facile da configurare
1 Denial of Service
2 intasamento della porta dovuto a pacchetti falsi

9
Svantaggi:

• minore efficienza e scalabilità dalle versione routed


Come creare il bridge di rete (in winXP):

• Apri connessioni di rete


• clicca col tasto destro sulla connessione alla rete locale e scegli proprietà
• nelle impostazioni TCP/IP metti l’indirizzo IP in manuale e anche quello
del default gateway
• fai la stessa cosa con la connessione della OpenVPNTM dell’adattatore
win-TAP32 ricordandoti di mettere l’indirizzo IP che si è già specificato
nel file di configurazione del server
• seleziona le due connessioni e clicca col tasto destro
• scegli crea bridge di rete
• clicca col tasto sul bridge di rete e scegli proprietà
• nelle proprietà TCP/IP metti manualmente l’indirizzo IP della rete locale
e non quello del gateway della OpenVPNTM

• fatto e finito il server è pronto.

Visualizzare l’intera rete locale dietro al server bridged


Se vogliamo che un client esterno alla rete locale veda tutta la rete che sta
dietro al server con questa modalità è quasi gratis. Bisogna dare come indirizzo
ip al server bridged lo stesso del nostro DHCP. C’è un poblema: se si usa il
server bridged su Windows XP conviene installarsi un server DHCP diverso
da quello di win altrimenti fatica a funzionare. Installiamo e configuriamo un
server DHCP gratuito come DHCP Static Server ruttkamp.gmxhome.de. Il
range dei client della OpenVPNTM deve essere esterno al range dei client del
DHCP, tutti devono essere nella stessa rete fisica: se il server DHCP e quello
OpenVPNTM hanno lo stesso indirizzo (ad esempio 10.8.0.1) i client del DHCP
li possiamo configurare da 10.8.0.5 a 10.8.0.128 e quelli della OpenVPNTM da
10.8.0.129 a 10.8.0.253. Benissimo il gioco è fatto, tutti i client sia DHCP che
OpenVPNTM si vedono senza problemi e vedono ovviamente il server(sia DHCP
che OpenVPNTM in quanto sono lo stesso computer).

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.

Far partire la nostra OpenVPN


Per far partire la nostra OpenVPNTM abbiamo 2 metodi:
• riga di comando
• GUI3 per WinXP
Per farla partire da riga di comando basta eseguire il comando
openvpn [server config file]
dalla cartella di OpenVPNTM .
Stessa cosa per il client.
Se abbiamo scaricato la GUI da www.openvpn.se, nella tray bar, quella in basso
a destra, troveremo la sua iconcina: ci permetterà di gestire e far partire e
terminare tutti i file di configurazione che si trovano nella sottodirectory ./config
di OpenVPNTM separatamente. Molto comoda e ben fatta!
Benissimo ora che sia server che client sono partiti possiamo, tramite console,
vedere se i client vede il server e viceversa. Per fare ciò si usa il comando
ping [indirizzo IP]. Abbiamo due casi:
• server routed: dal client possiamo pingare direttamente l’indirizzo ip del
server, ad esempio ping 10.8.0.1, e viceversa
3 Graphical User Interface

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.

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)
Se la chiave è di lunghezza variabile e non viene specificata OpenVPNTM uti-
lizzerà quella di default.
Dire quale sia il migliore è difficile. . . Sicuramente un algoritmo molto sicuro e
molto veloce nel cifrare è il Blowfish BF-CBC con chiave fino a 448 bit!

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 ’;’ #
#################################################

# Which local IP address should OpenVPN


# listen on? (optional)
;local a.b.c.d

# Which TCP/UDP port should OpenVPN listen on?


# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one. You will need to
# open up this port on your firewall.
port 1194

# TCP or UDP server?


proto tcp
;proto udp

# "dev tun" will create a routed IP tunnel,


# "dev tap" will create an ethernet tunnel.
# Use "dev tap" if you are ethernet bridging.
# If you want to control access policies
# over the VPN, you must create firewall

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

# Windows needs the TAP-Win32 adapter name


# from the Network Connections panel if you
# have more than one. On XP SP2 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don’t need this.
;dev-node tap

# 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

# Diffie hellman parameters.


# Generate your own with:
# openssl dhparam -out dh1024.pem 1024
# Substitute 2048 for 1024 if you are using
# 2048 bit keys.
dh C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\dh1024.pem

# Configure server mode and supply a VPN subnet


# for OpenVPN to draw client addresses from.

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

# Maintain a record of client <-> virtual IP address


# associations in this file. If OpenVPN goes down or
# is restarted, reconnecting clients can be assigned
# the same virtual IP address from the pool that was
# previously assigned.
ifconfig-pool-persist ipp.txt

# Configure server mode for ethernet bridging.


# You must first use your OS’s bridging capability
# to bridge the TAP interface with the ethernet
# NIC interface. Then you must manually set the
# 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

# 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.10.0 255.255.255.0"
;push "route 192.168.20.0 255.255.255.0"

# To assign specific IP addresses to specific


# clients or if a connecting client has a private
# subnet behind it that should also have VPN access,
# use the subdirectory "ccd" for client-specific
# configuration files (see man page for more info).

# EXAMPLE: Suppose the client


# having the certificate common name "Thelonious"
# also has a small subnet behind his connecting
# machine, such as 192.168.40.128/255.255.255.248.

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.

# EXAMPLE: Suppose you want to give


# Thelonious a fixed VPN IP address of 10.9.0.1.
# First uncomment out these lines:
;client-config-dir ccd
;route 10.9.0.0 255.255.255.252
# Then add this line to ccd/Thelonious:
# ifconfig-push 10.9.0.1 10.9.0.2

# 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

# If enabled, this directive will configure


# all clients to redirect their default
# network gateway through the VPN, causing
# all IP traffic such as web browsing and
# and DNS lookups to go through the VPN
# (The OpenVPN server machine may need to NAT
# the TUN/TAP interface to the internet in
# order for this to work properly).
# CAVEAT: May break client’s network config if
# client’s local DHCP server packets get routed
# through the tunnel. Solution: make sure
# client’s local DHCP server is reachable via
# a more specific route than the default route
# of 0.0.0.0/0.0.0.0.
;push "redirect-gateway"

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"

# Uncomment this directive to allow different


# clients to be able to "see" each other.
# By default, clients will only see the server.
# To force clients to only see the server, you
# will also need to appropriately firewall the
# server’s TUN/TAP interface.
client-to-client

# Uncomment this directive if multiple clients


# might connect with the same certificate/key
# files or common names. This is recommended
# 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

# The keepalive directive causes ping-like


# messages to be sent back and forth over
# the link so that each side knows when
# the other side has gone down.
# Ping every 10 seconds, assume that remote
# peer is down if no ping received during
# a 120 second time period.
keepalive 10 120

# For extra security beyond that provided


# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
#
# Generate with:
# openvpn --genkey --secret ta.key
#
# The server and each client must have
# a copy of this key.

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

# 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-DES
keysize 448

# Enable compression on the VPN link.


# If you enable it here, you must also
# enable it in the client config file.
comp-lzo

# The maximum number of concurrently connected


# clients we want to allow.
;max-clients 100

# It’s a good idea to reduce the OpenVPN


# daemon’s privileges after initialization.
#
# You can uncomment this out on
# non-Windows systems.
;user nobody
;group nobody

# The persist options will try to avoid


# accessing certain resources on restart
# that may no longer be accessible because
# of the privilege downgrade.
persist-key
persist-tun

# Output a short status file showing


# current connections, truncated
# and rewritten every minute.
status openvpn-status.log

# By default, log messages will go to the syslog (or


# on Windows, if running as a service, they will go to
# the "\Program Files\OpenVPN\log" directory).
# Use log or log-append to override this default.
# "log" will truncate the log file on OpenVPN startup,

18
# while "log-append" will append to it. Use one
# or the other (but not both).
;log openvpn.log
;log-append openvpn.log

# Set the appropriate level of log


# file verbosity.
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 3

# Silence repeating messages. At most 20


# sequential messages of the same message
# category will be output to the log.
;mute 20

#Serve per escludere dall’autenticazione i certificati


#revocati in maniera tale da non permettergli di autenticarsi
#e quindi di connettersi alla vpn
crl-verify G:\\Programmi\\OpenVPN\\easy-rsa\\keys\\crl.pem

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
#################################################

# Which local IP address should OpenVPN


# listen on? (optional)
;local a.b.c.d

# Which TCP/UDP port should OpenVPN listen on?


# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one. You will need to
# open up this port on your firewall.
port 1194

# TCP or UDP server?


proto tcp
;proto udp

# "dev tun" will create a routed IP tunnel,


# "dev tap" will create an ethernet tunnel.
# Use "dev tap" if you are ethernet bridging.
# If you want to control access policies
# over the VPN, you must create firewall
# 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

# Windows needs the TAP-Win32 adapter name


# from the Network Connections panel if you
# have more than one. On XP SP2 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don’t need this.
dev-node tap
#tap è il nome che ho dato alla connessione
#LAN dell’adattatore TAP-Win32. Bisogna
#quindi rinominare la connessione con un
#nome che vogliamo e questo nome va riportato
#esattamente in questo parametro

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

# Diffie hellman parameters.


# Generate your own with:
# openssl dhparam -out dh1024.pem 1024
# Substitute 2048 for 1024 if you are using
# 2048 bit keys.
dh C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\dh1024.pem

# Configure server mode and supply a VPN subnet


# for OpenVPN to draw client addresses from.
# 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

# Maintain a record of client <-> virtual IP address


# associations in this file. If OpenVPN goes down or
# is restarted, reconnecting clients can be assigned
# the same virtual IP address from the pool that was
# previously assigned.
ifconfig-pool-persist ipp.txt

# Configure server mode for ethernet bridging.


# You must first use your OS’s bridging capability
# to bridge the TAP interface with the ethernet
# NIC interface. Then you must manually set the

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

# 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.10.0 255.255.255.0"
;push "route 192.168.20.0 255.255.255.0"

# To assign specific IP addresses to specific


# clients or if a connecting client has a private
# subnet behind it that should also have VPN access,
# use the subdirectory "ccd" for client-specific
# configuration files (see man page for more info).

# EXAMPLE: Suppose the client


# having the certificate common name "Thelonious"
# also has a small subnet behind his connecting
# machine, such as 192.168.40.128/255.255.255.248.
# 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.

# EXAMPLE: Suppose you want to give


# Thelonious a fixed VPN IP address of 10.9.0.1.
# First uncomment out these lines:
;client-config-dir ccd
;route 10.9.0.0 255.255.255.252
# Then add this line to ccd/Thelonious:
# ifconfig-push 10.9.0.1 10.9.0.2

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

# If enabled, this directive will configure


# all clients to redirect their default
# network gateway through the VPN, causing
# all IP traffic such as web browsing and
# and DNS lookups to go through the VPN
# (The OpenVPN server machine may need to NAT
# the TUN/TAP interface to the internet in
# order for this to work properly).
# CAVEAT: May break client’s network config if
# client’s local DHCP server packets get routed
# through the tunnel. Solution: make sure
# client’s local DHCP server is reachable via
# a more specific route than the default route
# of 0.0.0.0/0.0.0.0.
;push "redirect-gateway"

# 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"

# Uncomment this directive to allow different


# clients to be able to "see" each other.
# By default, clients will only see the server.
# To force clients to only see the server, you
# will also need to appropriately firewall the
# server’s TUN/TAP interface.
client-to-client

# Uncomment this directive if multiple clients


# might connect with the same certificate/key
# files or common names. This is recommended

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

# The keepalive directive causes ping-like


# messages to be sent back and forth over
# the link so that each side knows when
# the other side has gone down.
# Ping every 10 seconds, assume that remote
# peer is down if no ping received during
# a 120 second time period.
keepalive 10 120

# For extra security beyond that provided


# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
#
# Generate with:
# openvpn --genkey --secret ta.key
#
# The server and each client must have
# a copy of this key.
# 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

# 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-DES
keysize 448

# Enable compression on the VPN link.


# If you enable it here, you must also
# enable it in the client config file.
comp-lzo

# The maximum number of concurrently connected

24
# clients we want to allow.
;max-clients 100

# It’s a good idea to reduce the OpenVPN


# daemon’s privileges after initialization.
#
# You can uncomment this out on
# non-Windows systems.
;user nobody
;group nobody

# The persist options will try to avoid


# accessing certain resources on restart
# that may no longer be accessible because
# of the privilege downgrade.
persist-key
persist-tun

# Output a short status file showing


# current connections, truncated
# and rewritten every minute.
status openvpn-status.log

# By default, log messages will go to the syslog (or


# on Windows, if running as a service, they will go to
# the "\Program Files\OpenVPN\log" directory).
# Use log or log-append to override this default.
# "log" will truncate the log file on OpenVPN startup,
# while "log-append" will append to it. Use one
# or the other (but not both).
;log openvpn.log
;log-append openvpn.log

# Set the appropriate level of log


# file verbosity.
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 3

# Silence repeating messages. At most 20


# sequential messages of the same message
# category will be output to the log.
;mute 20

25
;crl-verify G:\\Programmi\\OpenVPN\\easy-rsa\\keys\\crl.pem
#serve per escludere dall’autenticazione i certificati revocati

Client per server routed


##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server. #
# #
# 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 #
##############################################

# Specify that we are a client and that we


# will be pulling certain config file directives
# from the server.
client

# Use the same setting as you are using on


# the server.
# 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

# Windows needs the TAP-Win32 adapter name


# from the Network Connections panel
# if you have more than one. On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap

# Are we connecting to a TCP or


# UDP server? Use the same setting as
# on the server.
proto tcp
;proto udp

# The hostname/IP and port of the server.


# You can have multiple remote entries

26
# to load balance between the servers.
remote IP_ADDRESS_SERVER 1194
;remote my-server-2 1194

# Choose a random host from the remote


# list for load-balancing. Otherwise
# try hosts in the order specified.
;remote-random

# 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

# Most clients don’t need to bind to


# a specific local port number.
nobind

# Downgrade privileges after initialization (non-Windows only)


;user nobody
;group nobody

# Try to preserve some state across restarts.


persist-key
persist-tun

# If you are connecting through an


# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here. See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]

# Wireless networks often produce a lot


# of duplicate packets. Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings

# 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

# Verify server certificate by checking


# that the certicate has the nsCertType
# field set to "server". This is an
# important precaution to protect against
# 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

# If a tls-auth key is used on the server


# then every client must also have the key.
tls-auth C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\ta.key 1

# Select a cryptographic cipher.


# If the cipher option is used on the server
# then you must also specify it here.
cipher BF-CBC #cifratura blowfish;per vedere tutti i cifrari usare openvpn --show-cipher
keysize 448 #dimensione della chiave

# Enable compression on the VPN link.


# Don’t enable this unless it is also
# enabled in the server config file.
comp-lzo

# Set log file verbosity.


verb 3

# Silence repeating messages


;mute 20

Client per server bridged


Client
##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server. #

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 #
##############################################

# Specify that we are a client and that we


# will be pulling certain config file directives
# from the server.
client

# Use the same setting as you are using on


# the server.
# 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

# Windows needs the TAP-Win32 adapter name


# from the Network Connections panel
# if you have more than one. On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap

# Are we connecting to a TCP or


# UDP server? Use the same setting as
# on the server.
proto tcp
;proto udp

# The hostname/IP and port of the server.


# You can have multiple remote entries
# to load balance between the servers.
remote IP_ADDRESS_SERVER 1194
;remote my-server-2 1194

# Choose a random host from the remote


# list for load-balancing. Otherwise
# try hosts in the order specified.
;remote-random

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

# Most clients don’t need to bind to


# a specific local port number.
nobind

# Downgrade privileges after initialization (non-Windows only)


;user nobody
;group nobody

# Try to preserve some state across restarts.


persist-key
persist-tun

# If you are connecting through an


# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here. See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]

# Wireless networks often produce a lot


# of duplicate packets. Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings

# 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

# Verify server certificate by checking


# that the certicate has the nsCertType
# field set to "server". This is an
# important precaution to protect against

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

# If a tls-auth key is used on the server


# then every client must also have the key.
tls-auth C:\\Programmi\\OpenVPN\\easy-rsa\\keys\\ta.key 1

# Select a cryptographic cipher.


# If the cipher option is used on the server
# then you must also specify it here.
cipher BF-CBC #cifratura blowfish;per vedere tutti i cifrari usare openvpn --show-cipher
keysize 448 #dimensione della chiave

# Enable compression on the VPN link.


# Don’t enable this unless it is also
# enabled in the server config file.
comp-lzo

# Set log file verbosity.


verb 3

# Silence repeating messages


;mute 20

31

Potrebbero piacerti anche