OpenVPN (deutsch): Difference between revisions

From
Jump to navigation Jump to search
 
(47 intermediate revisions by 11 users not shown)
Line 1: Line 1:
'''Einleitung''': OpenVPN ist eine leicht zu implementierende und zu wartende VPN-Applikation,
OpenVPN ist eine leicht aufzusetzende und zu wartende
[[VPN | Virtual Private Network]]-Applikation, die bis auf die notwendige virtuelle
die bis auf das notwendige TUN- bzw. TAP-Device komplett im Userspace arbeitet.
Netzwerkschnittstelle komplett im Userspace arbeitet. Der gesamte Netzwerkverkehr wird auf Grundlage von [[OpenSSL]] verschlüsselt.
Dieses Dokument beschreibt die Installation sowohl des Servers ([[VPN]]-Gateway)
als auch der Clients unter den verbreiteten Betriebssystemen Windows, Linux, Mac OS X und OpenBSD.




==Funktionsweise==
=Was wird gebraucht?=
* OpenVPN-Programm
* TUN/TAP-Schnittstelle
* Konfigurationsdatei für OpenVPN (optional, aber empfohlen)
* [[PKI]] = Public-Key-Infrastruktur (optional, für größere Installationen empfohlen)


OpenVPN legt nach dem Start sowohl auf der Client- als auch auf der Serverseite
eine virtuelle Netzwerkschnittstelle an (wenn nicht schon vorhanden), welche
jeweils ein Ende des Tunnelsdarstellt. Der OpenVPN-Server muss vom Client durch
eine feste IP-Addresse oder festen Host-Namen erreichbar sein und verbindet
sich mit ihm auf einem beliebigen UDP- oder TCP-Port. Mit den zwei
Verbindungsarten Routing und Bridging stehen nun je nach Auswahl fast alle oder
jegliche Dienste des lokalen Netzes für den Client zur Verfügung.


Der gesamte Datenverkehr durch den Tunnel wird mittels OpenSSL-Bibliotheken verschlüsselt. Die LZO-Bibliotheken bieten die Option zur Kompression dieser Information.
=Funktionsweise=
Grundlage des OpenVPN-Tunnels ist das openvpn-Programm,
welches sowohl auf Server als auch auf Clientseite auf einem UDP-Port läuft und
mit Hilfe des [[tun]]/[[tap]]-Treibers eine virtuelle Netzwerkschnittstelle anlegt,
welche jeweils ein Ende des Tunnels darstellt.
Im Gegensatz zum PPP, welches ähnlich arbeitet, kann der gesamte Netzwerkverkehr
auf Grundlage von [[OpenSSL]] verschlüsselt werden.


=== Benötigte Komponenten ===
Zur Authentifizierung von Server und Client können zwei Verfahren verwendet werden:
* Shared-Secret-Authentifizierung (auch Static-Key-Authentifizierung)
* Zertifikatbasierte Authentifizierung


* [http://openvpn.net/download.html OpenVPN]
==Shared-Secret-Authentifizierung==
* OpenSSL [http://www.openssl.org/source/ für Unix] bzw. [http://gnuwin32.sourceforge.net/packages/openssl.htm für Windows]
Die Shared-Secret-Authentifizierung basiert auf einem [[symmetrische Verschlüsselung|symmetrischen Verschlüsselungsverfahren]].
* [http://vtun.sourceforge.net/tun/ Virtuelle Punkt-zu-Punkt und Ethernet Schnittstelle] (ist ab Linuxkernel 2.4 integriert und der Windows-Installation von OpenVPN beigelegt)
Dabei müssen die Kommunikationspartner den gemeinsamen Schlüssel (''shared key'') zuvor über einen [[sicherer Kanal|sicheren Kanal]]
* [[Public Key Infrastructure (PKI)]] (optional)
austauschen. Der gesamte Tunnel-Netzwerkverkehr wird dann mit diesem Schlüssel verschlüsselt und kann von jedem,
der ebenfalls den Schlüssel besitzt entschlüsselt werden.
Daher muss der Schlüssel bei Kompromittierung auf allen beteiligten Systemen ausgetauscht werden.


==Installation==
==Zertifikatbasierte Authentifizierung==
Die Zertifikatbasierte Authentifizierung basiert auf einem [[asymmetrische Verschlüsselung|asymmetrischen Verschlüsselungsverfahren]],
über welches ein sicherer Kanal ''erzeugt'' wird. Da die [[asymmetrische Verschlüsselung]] erheblich langsamer im Vergleich zur
[[symmetrische Verschlüsselung|symmetrischen Verschlüsselung]] ist,
wird ein temporärer symmetrischer Zufallsschlüssel von einem Kommunikationspartner erzeugt
und über den sicheren Kanal an sein Gegenüber geschickt.
Bei Kompromittierung brauch dann nur noch das entsprechende Zertifikat gesperrt werden (''siehe '').
Allerdings ist für das Aufsetzen der [[Public-Key-Infrastruktur]] ein größerer Konfigurationsaufwand erforderlich.


===Windows===
Siehe auch:
* [http://de.wikipedia.org/wiki/Asymmetrisches_Kryptosystem Wikipedia: Asymmetrisches Kryptosystem]
* [http://de.wikipedia.org/wiki/Public-Key-Infrastruktur Wikipedia: Public-Key-Infrastruktur]


Die Installation erfolgt - wie unter Windows üblich - durch Starten der EXE-Datei
und wiederholtem Klicken auf ''Next''. Danach findet sich das openvpn-Programm
unter ''\Programme\OpenVPN\bin'', die Konfigurationsdateien unter
''\Programme\OpenVPN\config''.


====Als unprivilegierter Benutzer starten====
===Zertifizierungsstelle (CA) und Public-Key-Infrastruktur (PKI)===


Um den Tunnel als normaler Benutzer aufzubauen müssen die Zugriffskontrolllisten
====Certificate Revocation List (CRL) - Schwarze Liste mit ungültigen Zertifikaten====
für den OpenVPN-Dienst angepasst werden. z.B. mit
[http://setacl.sourceforge.net/ SetACL] oder
[http://www.microsoft.com/downloads/details.aspx?FamilyId=E8BA3E56-D8FE-4A91-93CF-ED6985E3927B&displaylang=en Subinacl.exe].


Anzeigen der Zugriffsrechte:<br />
=Installation=
<code>
Zur Installation von Server und Client wird das openvpn-Programm und ein paar Bibliotheken benötigt. Da diese auf Server- und Clientseite die gleichen sind, reicht es eine Seite zu beschreiben. Auf der anderen Seite - also dem anderen Tunnelende - wird dann entsprechend nur die conf-Datei sowie der Schlüssel und die Zertifikate ausgetauscht.
setacl -on openvpnservice -ot srv -actn list
</code>


Setzen der ACLs für den OpenVPN-Service, so daß Benutzer den Dienst starten und beenden können:<br />
Die Installationshinweise sind teilweise http://openvpn.sourceforge.net/install.html entnommen.
<code>
setacl -on openvpnservice -ot srv -actn ace -ace "n:Benutzer;p:start_stop"
</code>


Starten des Dienstes via Kommandozeile:<br />
==Windows==
<code>
Zuerst wird das Installationspaket für OpenVPN und den TUN/TAP-Treiber von:
sc start OpenVPNService
* http://openvpn.sourceforge.net/beta/openvpn-2.0_beta*-install.exe
</code>
geholt.


Stoppen des Dienstes via Kommandozeile:<br />
<code>sc stop OpenVPNService</code>


Die obigen Maßnahmen erlauben aber noch nicht das Setzen von Routen.
==Linux==
Um einem unprivilegiertem Nutzer das Setzen von Routen zu ermöglichen, muss
Die Installation wird am Beispiel von SuSE-Linux beschrieben, sollte aber vom fähigen Systemadministrator auch auf andere Distributionen übertragen werden können.
er zur Gruppe der '''Netzwerkkonfigurations-Operatoren''' hinzugefügt werden.
Wer nach dem Anmelden seine Lieblingsverbindung automatisch starten möchte, muss in der Registry
unter ''HKLM\SOFTWARE/Microsoft\Windows\CurrentVersion\Run'' den openvpn-gui Eintrag ändern.<br />
<code>openvpn-gui REG_SZ c:\programme\openvpn\bin\openvpn-gui.exe --connect config.ovpn</code> <br />
Dann wird man beim Anmelden, je nach Art der Verbindung, sofort nach Username und Passwort (z.B. für Base1) gefragt.


=== Unix ===
===SuSE-Distributionspaket (alt, unterstützt nur pre-shared Keys)===
Alle handelsüblichen Distributionen bieten mehr oder weniger aktuelle Pakete von OpenVPN an, die i.d.R. die hier angesprochenen Funktionalitäten aufweisen.
yast -i lzo openssl openvpn
Eventuell müssen analog empfohlene Zusatzpakete installiert werden (z.B. OpenSSL oder LZO).


<table>
===OpenVPN 2.0 aus den Quellen installieren (besser, notwendig für PKI-Auth)===
<tr>
* lzo-Bibliothek (für die Kompression) http://www.oberhumer.com/opensource/lzo/download/lzo-1.08.tar.gz
<th>Distribution</th>
* OpenSSL-Bibliothek
<th>Version(en)</th>
* http://openvpn.sourceforge.net/beta/openvpn-2.0_beta*.tar.gz
<th>Installationskommando (als root)</th>
</tr>
<tr>
<td>[http://www.opensuse.org/ suse/opensuse]</td>
<td>&gt;=9.3</td>
<td>yast -i openvpn</td>
</tr>
<tr>
<td>[http://www.gentoo.org/ gentoo]</td>
<td>n/a</td>
<td>emerge openvpn</td>
</tr>
<tr>
<td>[http://www.freebsd.org/ FreeBSD]</td>
<td>6.0</td>
<td>pkg_add -r openvpn</td>
</tr>
<tr>
<td>[http://www.debian.org/ debian]</td>
<td>&gt;=3.1</td>
<td>apt-get install openvpn</td>
</tr>
<tr>
<td>[http://www.ubuntulinux.org/ ubuntu]</td>
<td>&gt;=5.10</td>
<td>apt-get install openvpn</td>
</tr>
<tr>
<td>[http://fedora.redhat.com/ Fedora Core]</td>
<td>&gt;=4</td>
<td>yum install openvpn</td>
</tr>
</table>


Sofern keine Paketverwaltungssoftware benutzt werden kann, bleibt noch der Weg über die Quelltexte um an eine aktuelle Version des Programms zu kommen.
====SuSE Linux====
Das bekannte Drei-Gespann:
yast -i openssl-devel
<code>
yast -i lzo-devel (ab SuSE 9.0)

(vor SuSE 9.0 - keine lzo-Bibliothek)
wget http://www.oberhumer.com/opensource/lzo/download/lzo-1.08.tar.gz
tar xzf lzo-1.08.tar.gz
cd lzo-1.08
./configure
./configure
make
make
make install
make install
</code>
sollte bis auf die Angabe der Pfade für ''Header-'' und ''Bibliotheks-Dateien'' zum Erfolg führen, sofern Compiler und SSL-Bibliotheken (in der Entwicklerversion) installiert sind.
Für eine Konfiguration mit lzo unterhalb von ''/usr/local'' hilft folgender Aufruf von ''configure'':
<code>
./configure --with-lzo-headers=/usr/local/include/ --with-lzo-lib=/usr/local/lib/
</code>


# Die Version von OpenVPN ist evtl. anzupassen
# (mit Browser unter http://openvpn.sourceforge.net/beta/ herausfinden)
wget http://openvpn.sourceforge.net/beta/openvpn-2.0_beta15.tar.gz
tar xzf openvpn-2.0_beta15.tar.gz
cd openvpn-2.0_beta15
# Bei selbstübersetzter lzo-Bibliothek müssen die beiden Pfade angegeben werden:
#./configure --with-lzo-headers=/usr/local/include --with-lzo-lib=/usr/local/lib
./configure
make
make install


====Als unprivilegierter Benutzer starten====
=====Als unprivilegierter Benutzer starten=====
Da OpenVPN Änderungen an den Netzwerkeinstellungen vornimmt ''(ifconfig/route)'',
Da OpenVPN Änderungen an den Netzwerkeinstellungen vornimmt,
muss das Programm mit root-Rechten ausgeführt werden.
muss das Programm mit root-Rechten ausgeführt werden.
Um den ''normalen'' Benutzern nicht das root-Passwort geben zu müssen,
Um den ''normalen'' Benutzern nicht das root-Passwort geben zu müssen,
Line 105: Line 129:


# Komma-separierte Liste der VPN-Nutzer
# Komma-separierte Liste der VPN-Nutzer
User_Alias VPNUSER=vpnuser1, vpnuser2
User_Alias VPNUSER=vpnuser1, vpnuser2

# Zum testen des VPN sollte man das --daemon weglassen,
# Zum testen des VPN sollte man das --daemon weglassen,
# um evtl. Fehler auf stdout zu erhalten.
# um evtl. Fehler auf stdout zu erhalten.
Cmnd_Alias OPENVPN=/usr/local/sbin/openvpn --config /etc/openvpn/SAR-VPN.ovpn --daemon
Cmnd_Alias OPENVPN=/usr/local/sbin/openvpn --config /etc/openvpn/SAR-VPN.ovpn --daemon
Cmnd_Alias KILLOPENVPN=/usr/bin/killall openvpn
Cmnd_Alias KILLOPENVPN=/usr/bin/killall openvpn

# NOPASSWD ist optional.
# NOPASSWD ist optional.
# Soll der Nutzer sein Passwort eingeben muessen lautet der Eintrag wie folgt:
# Soll der Nutzer sein Passwort eingeben muessen lautet der Eintrag wie folgt:
Line 128: Line 152:
beendet werden.
beendet werden.


==Mac OS X==
== Konfiguration ==


=== Grundeinstellung ===
Die Installation erfolgt analog zu Linux (bei fehlender lzo-Bobliothek). Die Developer-Tools müssen installiert sein! (C-Compiler, make, openssl-devel, etc.)
Da Mac OS X (aka Darwin) kein TUN-Device zur Verfügung stellt, muss es nachinstalliert werden. Hier findet man eine detailierte Installationsbeschreibung und ein vorkompiliertes kext-file: http://chrisp.de/en/projects/tunnel.html


Ausführlich beschrieben im [http://openvpn.net/howto.html#config offiziellen Handbuch]; im Wesentlichen läuft es darauf hinaus bei Client und Server
wget http://www.oberhumer.com/opensource/lzo/download/lzo-1.08.tar.gz
zueinander passende Einstellungen zu wählen.
# (oder mit Safari holen, falls wget nicht verfügbar)
tar xzf lzo-1.08.tar.gz
cd lzo-1.08
./configure
make
make install


OpenVPN-Client und -Server können sich sowohl über UDP als auch TCP unterhalten.
# Die Version von OpenVPN ist evtl. anzupassen
Bei der richtigen Wahl ist zu Bedenken, dass das tap-Device (siehe unten) auf
# (mit Browser unter http://openvpn.sourceforge.net/beta/ herausfinden)
Layer 2 Ebene tunnelt und somit innerhalb des Kanals TCP-Pakete sendet. Da TCP
wget http://openvpn.sourceforge.net/beta/openvpn-2.0_beta15.tar.gz
ein Verbindungsorientiertes Protokoll ist, besitz es eine sich selbst anpassende
# (oder mit Safari holen, falls wget nicht verfügbar)
Zeitspanne, nach der ein erneuter Request auf ein nicht angekommenes Paket
gesendet wird. Liegt also ein TCP-Layer über einem anderen, beide ausgestattet
tar xzf openvpn-2.0_beta15.tar.gz
mit Timer und Resend-Request. Diese Kontrollflusspakete werden zusätzlich zu den
cd openvpn-2.0_beta15
eigentlichen Daten gesendet und sind für sie redundant. Wenn die Verbindung im
./configure --with-lzo-headers=/usr/local/include --with-lzo-lib=/usr/local/lib
Kanal einen kurzen Timer besitz, werden Resend-Requests über den ''TCP''-Tunnel
make
gesendet und erhöhen so auch das Datenaufkommen außerhalb des Tunnels (die
make install
TCP-Pakete der Verbindung, die den Tunnel bildet kann ebenfalls verloren gehen
was zu neuen Resend-Requests führt). Durch sich kumulierende
Kontrollflusnachrichten erhöht sich der Geschwindigkeitsverlust durch redundante
Daten (mehr dazu siehe [http://sites.inka.de/sites/bigred/devel/tcp-tcp.html hier]).


=== Authentifikation ===


==== Preshared Key ====
==OpenBSD==


Die Preshared-Secret-Authentifizierung basiert auf einem symmetrischen
Verschlüsselungsverfahren.
Mittels <code>openvpn --genkey --secret static.key</code> wird ein gemeinsamer
Schlüssel erzeugt, den die beiden Kommunikationspartner
zuvor über einen sicheren Kanal erhalten müssen. Der
gesamte Tunnel-Netzwerkverkehr wird dann mit diesem Schlüssel verschlüsselt und
kann von jedem, der ebenfalls den Schlüssel besitzt entschlüsselt werden. Daher
eignet sich jeder Schlüssel für nur genau eine Punkt-zu-Punkt verbindung und
muss bei Kompromittierung ausgetauscht werden.


Mittels der beiden folgenden Konfigurationsdateien sollte bereits eine
==Andere UNIX-Systeme (ohne TUN-Device)==
Verbindung zwischen Client und Server möglich sein:


''server.conf'':
<code>
dev tun
ifconfig 10.8.0.1 10.8.0.2
secret static.key
</code>
client.conf'':
<code>
remote myremote.mydomain
dev tun
ifconfig 10.8.0.2 10.8.0.1
secret static.key
</code>


Dabei sollte myremote.mydomain in den Hostnamen oder die statische IP des
==Frontends==
Servers geändert werden. In diesem Beispiel erhalten die virtuellen
* OpenVPN GUI für Windows http://www.nilings.se/openvpn/
tun-Schnittstellen die Addressen 10.8.0.1 (Server) und 10.8.0.2 (Client).
* OpenVPN-GUI für Mac OS X http://rechenknecht.net/OpenVPN-GUI/


=Konfiguration=
Grundsätzlich können alle Konfigurations-Parameter dem openvpn-Programm an der Kommandozeile in der Form ''--parameter=wert'' mitgegeben werden.
Alternativ kann man die Konfigurations-Parameter in eine Datei zeilenweise in der Form ''parameter wert'' schreiben und den Dateinamen mit dem Parameter ''--config Dateiname'' an der Kommandozeile mitgeben, z.B.:


==== Zertifikatbasierte Authentifizierung ====
openvpn --config openvpn.conf


Die Zertifikatbasierte Authentifizierung nutzt eine [[Public Key
==Der erste Test==
Infrastructure]] (PKI) und basiert auf einem asymmetrischen
Zum Testen der OpenVPN-Installation sollte man zunächst eine Shared-Secret-Authentifizierung wählen, da diese einfach zu konfigurieren ist. Mit:
Verschlüsselungsverfahren, über welches ein sicherer Kanal erzeugt wird. Dabei
kommen signierte Zertifikate zum Einsatz, die bei Kompromittierung lediglich
gesperrt und gegebenenfalls auf der entsprechenden Maschine durch ein neues
ersetzt werden müssen. Ohne ein von der [[Certificate Authority]] (CA)
signiertes Zertifikat seines Gegenübers akzeptiert kein Kommunikationspartner
die Verbindung.


===== Erstellen einer PKI mit OpenVPN =====
openvpn --genkey --secret static.key


OpenSSL bringt bereits alle Werkzeuge mit, um eine CA aufzusetzen, um damit
erstellt man einen gemeinsamen Schlüssel (''static.key''), den man auf die beiden OpenVPN-Rechner mit den späteren Tunnelenden kopiert.
Server- und Clientzertifikate sowie die dazugehörigen privaten Schlüssel zu
erstellen. OpenVPN besitzt im Unterverzeichnis ''easy-rsa'' weitere Skripte, mit
denen diese Tools bedient und deren Handhabung noch weiter vereinfacht. Die
Bedienung von easy-rsa entnehmen Sie bitte dem
[http://openvpn.net/howto.html#pki OpenVPN-howto].


Die folgende, dem Howto entnommene Tabelle ordnet jeder generierten Datei einen
Besitzer zu. Besonders zu beachten ist, dass die als ''Secret'' markierten
Dateien nur an die dafür vorgesehenen Parteien gegeben werden.
<table>
<tr>
<td><b>Filename</b></td>
<td><b>Needed By</b></td>
<td><b>Purpose</b></td>
<td><b>Secret</b></td>


</tr>
Angenommen, der Server hat die reale IP-Adresse ''192.168.0.1'' und der Client die IP-Adresse ''192.168.0.2'' kann man folgendermaßer eine erste Testverbindung aufbauen:


<tr>
'''auf dem Server'''
<td>ca.crt</td>
openvpn --dev tun0 --remote 192.168.0.2 --ifconfig 192.168.10.1 192.168.10.2 --secret static.key
<td>server + all clients</td>
<td>Root CA certificate</td>
<td>NO</td>
</tr>


<tr>
<td>ca.key</td>
<td>key signing machine only</td>


<td>Root CA key</td>
'''auf dem Client'''
<td>YES</td>
openvpn --dev tun0 --remote 192.168.0.1 --ifconfig 192.168.10.2 192.168.10.1 --secret static.key
</tr>


<tr>
<td>dh{n}.pem</td>
<td>server only</td>
<td>Diffie Hellman parameters</td>
<td>NO</td>
</tr>


<tr>
Der Server sollte dann durch den Tunnel vom Client aus über die virtuelle IP-Adresse ''192.168.10.1'' ansprechbar sein:
<td>server.crt</td>
ping 192.168.10.1
<td>server only</td>
<td>Server Certificate</td>
<td>NO</td>
</tr>


<tr>
analog ist der Client über die virtuelle IP-Adresse ''192.168.10.2'' erreichbar.
<td>server.key</td>
<td>server only</td>
<td>Server Key</td>


<td>YES</td>
==Szenarien==
</tr>
===Außendienst-Mitarbeiter (Netz-zu-Host)===
Eine häufiger Anwendungsfall für [[VPN]]s beschreibt folgendes Szenario:
Ein Außendienst-Mitarbeiter (auch ''Roadwarrior''), Tele-Arbeiter oder
einfach jemand der zu Hause noch ein Dokument braucht,
möchte Zugriff auf die Ressourcen seines Firmen-Netzes erlangen,
welches aus Sicherheitsgründen zum Internet aber durch eine Firewall abgeschottet ist.


<tr>
In der folgenden Betrachtung wird davon ausgegangen, dass das Firmen-Netzwerk im [[Subnetz]] 192.168.0.0/24 liegt.
<td>client1.crt</td>
Diese Angaben sind bei der Konfiguration natürlich an die lokalen Gegebenheiten anzupassen.
<td>client1 only</td>
Weiterhin soll für als Subnetz, in welchem sich die VPN-Clients befinden, 192.168.10.0/24 angenommen werden.
<td>Client1 Certificate</td>
<td>NO</td>
</tr>


<tr>
Für kleine Netzwerke kann für dieses Szenario auch der Peer-to-Peer-Modus (mit Shared-Secret-Authentifizierung)
<td>client1.key</td>
von OpenVPN verwendet werden. Der Administrationsaufwand steigt bei dieser Realisierung mit der Größe des VPN-Netzes -
also mit der Anzahl der VPN-Clients. Außerdem muss pro Client auf der Serverseite ein expliziter Daemon-Prozess mit separatem UDP-Port laufen, was zudem die [[Firewall]]-Konfiguration aufwändiger gestaltet.
Im folgenden wird daher der Server-Client-Modus von OpenVPN (ab Version 2) mit Hilfe von zertifikatbasierter Authentifizierung beschrieben.


<td>client1 only</td>
====CA aufsetzen====
<td>Client1 Key</td>
Zur Signierung des Server- und der Client-Zertifikate sollte man eine eigene CA aufsetzen.
<td>YES</td>
Das [[OpenSSL]]-Paket bringt schon die nötigen Werkzeuge dafür mit.
</tr>
Zur Vereinfach existiert das Skript ''CA.pl''. Das Skript ist wie folgt zu finden:


<tr>
* /usr/share/ssl/misc/CA.pl (SuSE)
<td>client2.crt</td>
* /usr/lib/ssl/misc/CA.pl (Debian)
<td>client2 only</td>
<td>Client2 Certificate</td>
<td>NO</td>


</tr>
CA.pl -newca


<tr>
erstellt im aktuellen Verzeichnis das CA-Verzeichnis ''demoCA''. Nach der Eingabe von:
<td>client2.key</td>
* Passwort für privaten Schlüssel (''Enter PEM pass phrase'')
<td>client2 only</td>
* Eigenschaften des Zertifikates:
<td>Client2 Key</td>
** Land (''Country Name (2 letter code)'')
<td>YES</td>
** Staat (''Country Name (State or Province Name (full name)'')
</tr>
** Stadt (''Locality Name (eg, city)'')
** Firma (''Organization Name (eg, company)'')
** Abteilung (''Organizational Unit Name (eg, section)'')
** Name (des Nutzers bzw. des Rechners) (''Common Name (eg, YOUR name)'')
** E-Mail-Adresse (''Email Address'')


<tr>
Also beispielsweise:
<td>client3.crt</td>
<td>client3 only</td>


<td>Client3 Certificate</td>
tux@linux:~> /usr/share/ssl/misc/CA.pl -newca
<td>NO</td>
CA certificate filename (or enter to create)
</tr>
Making CA certificate ...
Generating a 1024 bit RSA private key
.......++++++
.++++++
writing new private key to './demoCA/private/cakey.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
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) [AU]:'''DE'''
State or Province Name (full name) [Some-State]:'''Berlin'''
Locality Name (eg, city) []:'''Berlin'''
Organization Name (eg, company) [Internet Widgits Pty Ltd]:'''Humboldt-Universitaet zu Berlin'''
Organizational Unit Name (eg, section) []:'''Informatik'''
Common Name (eg, YOUR name) []:'''Tux-CA'''
Email Address []:


<tr>
Das CA-Zertitifikat ist anschließend unter ''demoCA/cacert.pem'' zu finden.
<td>client3.key</td>
<td>client3 only</td>
<td>Client3 Key</td>
<td>YES</td>
</tr>


</table>
====Zertifikate erstellen ====


===== Anpassung der ''.conf'' bzw. ''.ovpn'' Dateien =====
Jetzt werden noch Schlüssel und Zertifikate für den Server und die Clients benötigt:
(Die Erstellung verläuft für Server und Clients gleich!)


Sowohl beim Server als auch beim Client ist darauf zu achten, dass die folgenden
1. Der private Schlüssel und eine Zertifikat-Anforderung:
Zeilen der unten gegebenen Beispielkonfigurationen
tux@linux:~> /usr/share/ssl/misc/CA.pl -newreq
<code>
Using configuration from /etc/ssl/openssl.cnf
ca ca.crt
Generating a 1024 bit RSA private key
cert server.crt
..++++++
key server.key
..............................................................................................++++++
</code> bzw.
writing new private key to 'newreq.pem'
<code>
Enter PEM pass phrase:
ca ca.crt
Verifying password - Enter PEM pass phrase:
cert client.crt
-----
key client.key
You are about to be asked to enter information that will be incorporated
</code>
into your certificate request.
auf die für den Server/Client erstellten Dateien zeigen. Sollten Sie nicht mit
What you are about to enter is what is called a Distinguished Name or a DN.
der unten gegebenen Konfiguration starten, müssen Sie die
There are quite a few fields but you can leave some blank
Preshared-Key-Authentifizierung evtl. deaktivieren.
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:'''DE'''
State or Province Name (full name) [Some-State]:'''Berlin'''
Locality Name (eg, city) []:'''Berlin'''
Organization Name (eg, company) [Internet Widgits Pty Ltd]:'''Humboldt-Universitaet zu Berlin'''
Organizational Unit Name (eg, section) []:'''Informatik'''
Common Name (eg, YOUR name) []:'''TestClient'''
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Request (and private key) is in newreq.pem


====Benutzername/Passwort====
erstellt eine Zertifikat-Anfrage inklusive dem privaten Schlüssel in der Datei ''newreq.pem''.


=== Wahl des virtuellen Device ===
2. Unterschreiben der Zertifikat-Anforderung mit CA-Key:
tux@linux:~> /usr/share/ssl/misc/CA.pl -signreq
Using configuration from /etc/ssl/openssl.cnf
7974:error:0E06D06C:configuration file routines:NCONF_get_string:no value:conf_lib.c:329:group=CA_default name=unique_subject
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Nov 29 13:43:20 2004 GMT
Not After : Nov 29 13:43:20 2005 GMT
Subject:
countryName = DE
stateOrProvinceName = Berlin
localityName = Berlin
organizationName = Humboldt-Universitaet zu Berlin
organizationalUnitName = Informatik
commonName = TestClient
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
49:88:2F:9A:D6:E3:90:7F:5C:DE:56:F2:20:26:F9:74:2B:46:D4:7E
X509v3 Authority Key Identifier:
keyid:C6:AF:33:7D:F2:8F:22:1C:42:D9:F1:AD:7B:73:FE:4C:A2:C1:C8:94
DirName:/C=DE/ST=Berlin/L=Berlin/O=Humboldt-Universitaet zu Berlin/OU=Informatik/CN=Tux-CA
serial:00
Certificate is to be certified until Nov 29 13:43:20 2005 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
Signed certificate is in newcert.pem


Auf den OpenVPN-Gateways muss in jedem Fall das IP-Forwarding (Routing)
3. Erzeugen einer PKCS#12-Datei (mit CA- und Client-Zertifikat sowie privatem Schlüssel):
eingestellt sein. Auf Debian-Systemen muss hierzu in der
tux@linux:~> /usr/share/ssl/misc/CA.pl -pkcs12 "Test Client"
''/etc/network/options'' die Option ''ip_forward'' auf ''yes'' geändert werden.
Enter pass phrase for newreq.pem:
Suse bietet mittels yast an, dies via Häkchen bei den Netzwerkeinstellungen zu
Enter Export Password:
machen. Bei anderen Systemen sollte ein
Verifying - Enter Export Password:
<code>echo 1 > /proc/sys/net/ipv4/ip_forward</code> zum Erfolg führen (muss nach jedem Neustart
ausgeführt werden).


==== tun-Devices ====
Die resultierende Datei ''newcert.p12'' kann anschließend mit OpenVPN zur Authentifizierung verwendet werden.
(''newreq.pem'' und ''newcert.pem'' können gelöscht werden.)


Durch den Tunnel können mit einem dieser Schnittstelle alle gängigen
Für 1 Server-Zertifikat und n Client-Zertifikate würde man also folgendes aufrufen:
Netzwerkprotokolle auf IP-Basis (Layer 3) transportiert werden. So können Daten
vom Fileserver sowie Datenbankinfos abgerufen, ebenso können E-Mails bei einem
Mailserver abgeholt werden. Das alles funktioniert, als ob man sich vor Ort
befände, weil alle Anfragen zu beliebigen Rechnern im lokalen Netz durchgereicht
werden. Interessant ist die Technik auch für Außendienstler (Roadwarrior), die sich von
unterwegs in der Zentrale einloggen wollen, um ihre Daten abzugleichen.


Die Kommunikation von drinnen nach draußen funktioniert über mehrere Routen auf Client und Serverseite, daher wird das Verfahren auch Routing genannt. Die Konfigurationsvorlagen sind bereits für den Einsatz des tun-Device
# CA erstellen
ausgelegt.
/usr/share/ssl/misc/CA.pl -newca

==== tap-Devices ====
# Server-Zertifikat

/usr/share/ssl/misc/CA.pl -newreq
Im Gegensatz zu OpenVPN mit einem tun-Device beherrscht die Konfiguration mit
/usr/share/ssl/misc/CA.pl -signreq
einem tap-Device ein vollständiges Tunneln von Ethernet-Frames (Layer 2) und
/usr/share/ssl/misc/CA.pl -pkcs12 "Server-Zertifikat"
erlaubt somit beispielsweise auch den Einsatz von IPX über einem Tunnel. Ist
mv newcert.p12 server.p12
OpenVPN 2.0 für tap-Devices konfiguriert, bekommen Clients IP-Adressen aus dem
rm newreq.pem newcert.pem
Adresspool des Servernetzes. Dies setzt voraus, dass dort bereits ein
DHCP-Server seinen Dienst verrichtet. Alternativ kann OpenVPN einen DHCP-Server
# Client-1-Zertifikat
simulieren und selbst IP-Adressen verteilen.
/usr/share/ssl/misc/CA.pl -newreq

/usr/share/ssl/misc/CA.pl -signreq
In den Konfigurationsvorlagen muss dazu die Wahl der Netzwerkschnittstelle
/usr/share/ssl/misc/CA.pl -pkcs12 "Client-1-Zertifikat"
geändert werden:
mv newcert.p12 client-1.p12
<code>
rm newreq.pem newcert.pem
dev tap
.
;dev tun
.
</code>
.

# Client-n-Zertifikat
Zwei Netze, das virtuelle VPN-Netz und das lokale Netzwerk, werden über eine Brücke miteinander verbunden und unter ein und derselben Subdomain vereint. Das Verfahren nennt man daher auch Bridging.
/usr/share/ssl/misc/CA.pl -newreq

/usr/share/ssl/misc/CA.pl -signreq
===Szenarien===
/usr/share/ssl/misc/CA.pl -pkcs12 "Client-n-Zertifikat"

mv newcert.p12 client-n.p12
====Außendienst-Mitarbeiter (Netz-zu-Host)====
rm newreq.pem newcert.pem

Eine häufiger Anwendungsfall für [[VPN]]s beschreibt folgendes Szenario:
Ein Außendienst-Mitarbeiter (auch ''Roadwarrior''), Tele-Arbeiter oder
einfach jemand der zu Hause noch ein Dokument braucht,
möchte Zugriff auf die Ressourcen seines Firmen-Netzes erlangen,
welches aus Sicherheitsgründen zum Internet aber durch eine Firewall abgeschottet ist.

In der folgenden Betrachtung wird davon ausgegangen, dass das Firmen-Netzwerk im [[Subnetz]] 192.168.0.0/24 liegt.
Diese Angaben sind bei der Konfiguration natürlich an die lokalen Gegebenheiten anzupassen.
Weiterhin soll für als Subnetz, in welchem sich die VPN-Clients befinden, 192.168.10.0/24 angenommen werden.

Für kleine Netzwerke kann für dieses Szenario auch der Peer-to-Peer-Modus (mit Shared-Secret-Authentifizierung)
von OpenVPN verwendet werden. Der Administrationsaufwand steigt bei dieser Realisierung mit der Größe des VPN-Netzes -
also mit der Anzahl der VPN-Clients. Außerdem muss pro Client auf der Serverseite ein expliziter Daemon-Prozess mit separatem UDP-Port laufen, was zudem die [[Firewall]]-Konfiguration aufwändiger gestaltet.
Im folgenden wird daher der Server-Client-Modus von OpenVPN (ab Version 2) mit Hilfe von zertifikatbasierter Authentifizierung beschrieben.


====Transparente Fillialanbindung (Netz-zu-Netz)====
Für dieses Szenario kann die Konfiguration aus dem ersten Test verwendet werden.
Es wird dann kein expliziter Server ausgewiesen und
es braucht keine [[PKI]] aufgesetzt werden.
Man muss nur den gemeinsamen Schlüssel über einen sicheren Kanal übertragen,
z.B. eine verschlüsselte E-Mail.


Sinnvollerweise kann man die Optionen wie im o.g. Szenario in eine Datei schreiben
====Server-Konfiguration====
und ein paar zusätzliche Optionen, wie das automatische Setzen von Routen angeben.
Im folgenden wird eine Bespiel-Konfiguration für dieses Szenario angegeben.
Kommentare werden mit einem # vorangestellt, auskommentierten Optionen folgen einem Semikolon.


Eine Beispiel-Konfiguration wäre also:
Der Server kann anschließend mit:
openvpn --config ''Konfigurationsdatei''
gestartet werden.


<code>
##############################################################################
##############################################################################
# /etc/openvpn/openvpn-server.ovpn
# /etc/openvpn/openvpn-gateway.ovpn
#
#
# Diese Konfiguartionsdatei beinhaltet Einstellungen
# Diese Konfiguartionsdatei beinhaltet Einstellungen
# fuer einen OpenVPN-Server.
# fuer einen OpenVPN-Gateway.
#
#
# Mit
# Mit
# openvpn --config /etc/openvpn/openvpn-server.ovpn
# openvpn --config /etc/openvpn/openvpn-gateway.ovpn
# kann der Server gestartet werden.
# kann das Gateway gestartet werden.

'''remote 192.168.10.2'''
;remote 192.168.10.1 # auf der anderen Tunnelseite

'''ifconfig 192.168.10.1 192.168.10.2'''
;ifconfig 192.168.10.2 192.168.10.1 # auf der anderen Tunnelseite
# OpenVPN laeuft als Server und verwendet 192.168.10.0/24
# als VPN-Subnetz.
'''server 192.168.10.0 255.255.255.0'''
# Auf welcher IP-Adresse soll OpenVPN lauschen? (optional)
;local 192.168.0.1
# Welcher Port soll verwendet werden? (Standard: UDP/5000)
'''proto udp'''
'''proto udp'''
'''port 5000'''
'''port 5000'''

# Wir verwenden IP-Tunnel - also das tun-Device.
# Fuer Ethernet-Tunnel ist das tap-Device zu verwenden und ausserdem
# die ''server-bridge''-Option statt der o.g. ''server''-Option.
;dev tap
'''dev tun'''
'''dev tun'''

# Welche Schluessel/Zertifikate sollen verwendet werden?
# In welchem Verzeichnis liegen die Dateien?
# Es wird /etc/openvpn angenommen
'''cd /etc/openvpn'''
'''cd /etc/openvpn'''

'''secret preshared.key'''
# CA-Zertifikat

;ca sample-keys/tmp-ca.crt
# Eigenes Zertifikat
;cert sample-keys/server.crt
# Eigener privater Schluessel
;key sample-keys/server.key # Diese Datei sollte geheim bleiben
# Wir verwenden lieber alles in einer Datei!
'''pkcs12 server.p12'''
# Diffie-Hellman-Parameter.
# Diese Datei kann wie folgt erstellt werden:
# openssl dhparam -out /etc/openvpn/dh1024.pem 1024
'''dh dh1024.pem'''
# Ein gemeinsamer Schluessel kann ausserdem verwendet.
# So koennen nur die Clients eine Verbindung aufbauen,
# die auch das Geheimnis kennen.
# (Ein kleiner Schutz gegen DoS-Attacken)
'''tls-auth preshared.key 0'''
# Welche CRL-Datei wird verwendet?
# Die CRL ist eine von der CA unterschriebene Liste
# mit den Zertifikaten, die sich nicht anmelden dürfen.
'''crl-verify crl.pem'''
# Pruefe, ob noch eine Verbindung mit dem Client besteht.
# Jede 10 Sekunden einen Ping, falls nach 60 Sekunden
# keine Antwort ankommt, wird ein Verbindungsabbruch angenommen.
'''keepalive 10 60'''
'''keepalive 10 60'''

# Erhalte Verbindung falls Client-IP-Adressen
# waehrend der Verbindung sich aendern sollten.
# (z.B. bei Dial-Up-Reconnect)
'''float '''
# Kompression fuer den Tunnel
'''comp-lzo'''
'''comp-lzo'''

# Ermoeglich mehrere gleichzeitige Verbindungen mit
# dem gleichen Zertifikat. (nicht empfohlen)
;duplicate-cn
# Abgeben der Prozess-Rechte nach dem Start:
# * ''user'' Nutzer nach Rechteabgabe (mit moeglichst wenig Rechten)
# * ''group'' Gruppe analog
# * ''persist-key'' Lese die Schluessel nicht beim Neustart durch
# ''SIGUSR1'' bzw. ''--ping-restart'' ein
# * ''persist-tun'' Analog fuer den Zugriff auf das TUN/TAP-Device
'''user nobody'''
'''user nobody'''
'''group nobody'''
'''group nobody'''
'''persist-key'''
'''persist-key'''
'''persist-tun'''
'''persist-tun'''

# Log-Level:
#
# 0 keine Ausgabe bis auf kritische Fehler
# 4 empfohlen fuer Standardbetrieb
# 5 und 6 zum Debuggen
# 9 maximal
'''verb 4'''
'''verb 4'''
# Daemon-Mode: keine Ausgabe auf das Terminal (stdout) sondern ins Syslog
;daemon # Sollte erst nach fertiger Konfiguration aktiviert werden


Weitere Informationen zur Syntax und Semantik der Konfiguration gibt es hier:
;daemon # Sollte erst nach fertiger Konfiguration aktiviert werden
</code>
* http://openvpn.sourceforge.net/man.html


Will man mehrere Fillialen an eine Zentrale anbinden,
Beispiele unter:
wird man eher zum oben genannten Netz-zu-Host-Szenario greifen.
* http://openvpn.sourceforge.net/examples.html
Hierbei spielt das Gateway in der Zentrale die Rolle des Servers und
das Gateway der Filliale die Rolle des Clients.
Eventuell muss auf Server-Seite noch ein clientspezifisches Skript mit
entsprechenden Routing-Eintragungen eingesetzt werden,
falls in der Zentrale ein Rechner aus dem Netz der Filliale erreicht werden soll.


====Client-Konfiguration====
=== Extra-Sicherheit ===
Analog zum Server (siehe oben) wird der Client gestartet.
Es folgt ein Bespiel fuer eine Client-Konfigurationsdatei.


Nachdem die Virtuellen Netzwerkkarten kreiert und die Routen gelegt sind, bietet
##############################################################################
OpenVPN unter Unix die Option seine Rechte zu reduzieren. Der Kommentar vor den folgenden
# /etc/openvpn/openvpn-client.ovpn
Zeilen sollte bei den Konfigurationsvorlagen entfernt werden.

<code>
;user nobody
;group nobody
</code>

Falls also je eine
Sicherheitslücke entdeckt werden sollte, kann der OpenVPN-Prozess nicht
missbraucht werden. Zusätzlich kann man ihn mit Einfügen der folgenden Zeile an
ein bestimmtes Verzeichnis binden:

<code>
chroot /usr/local/openvpn
</code>

== Konfigurationsvorlagen ==

Die folgenden Beispielkonfigurationsdateien wurden dem OpenVPN-Paket
entnommen.

=== server.conf ===

<code>
#################################################
# 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 tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# 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 MyTap

# 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
# Diese Konfiguartionsdatei beinhaltet Einstellungen
# of scripts for generating RSA certificates
# fuer einen OpenVPN-Client.
# 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.
# Mit
# OpenVPN can also use a PKCS #12 formatted key file
# openvpn --config /etc/openvpn/openvpn-client.ovpn
# (see "pkcs12" directive in man page).
# kann der Client gestartet werden.
ca ca.crt
cert server.crt
# OpenVPN laeuft als Client.
key server.key # This file should be kept secret
'''client'''

# Diffie hellman parameters.
# Wir verwenden IP-Tunnel - also das tun-Device.
# Generate your own with:
'''dev tun'''
# openssl dhparam -out dh1024.pem 1024
# Substitute 2048 for 1024 if you are using
# Angabe des Server-Daten.
# 2048 bit keys.
# Bei mehreren ''remote''-Eintraegen wird ein Load-Balancing versucht.
dh dh1024.pem
;remote my.server.local 5000 # Namen sind moeglich

'''remote 192.168.0.1 5000''' # IP-Adressen auch
# Configure server mode and supply a VPN subnet
# for OpenVPN to draw client addresses from.
# Welche Schluessel/Zertifikate sollen verwendet werden?
# The server will take 10.8.0.1 for itself,
# the rest will be made available to clients.
# In welchem Verzeichnis liegen die Dateien?
# Each client will be able to reach the server
# Es wird /etc/openvpn angenommen
# on 10.8.0.1. Comment this line out if you are
'''cd /etc/openvpn'''
# ethernet bridging. See the man page for more info.
server 10.8.0.0 255.255.255.0
# CA-Zertifikat

;ca sample-keys/tmp-ca.crt
# Maintain a record of client <-> virtual IP address
# associations in this file. If OpenVPN goes down or
# Eigenes Zertifikat
# is restarted, reconnecting clients can be assigned
;cert sample-keys/client1.crt
# the same virtual IP address from the pool that was
# previously assigned.
# Eigener privater Schluessel
ifconfig-pool-persist ipp.txt
;key sample-keys/client1.key # Diese Datei sollte geheim bleiben

# Configure server mode for ethernet bridging.
# Wir verwenden lieber alles in einer Datei!
# You must first use your OS's bridging capability
'''pkcs12 client1.p12'''
# to bridge the TAP interface with the ethernet
# NIC interface. Then you must manually set the
# Diffie-Hellman-Parameter.
# IP/netmask on the bridge interface, here we
# Diese Datei kann wie folgt erstellt werden:
# assume 10.8.0.4/255.255.255.0. Finally we
# openssl dhparam -out /etc/openvpn/dh1024.pem 1024
# must set aside an IP range in this subnet
'''dh dh1024.pem'''
# (start=10.8.0.50 end=10.8.0.100) to allocate
# to connecting clients. Leave this line commented
# Ein gemeinsamer Schluessel kann ausserdem verwendet.
# out unless you are ethernet bridging.
# So koennen nur die Clients eine Verbindung aufbauen,
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
# die auch das Geheimnis kennen.

# (Ein kleiner Schutz gegen DoS-Attacken)
# Push routes to the client to allow it
# '''ACHTUNG:''' Letzter Parameter muss auf Client-Seite == 1 sein!
# to reach other private subnets behind
'''tls-auth preshared.key 1'''
# the server. Remember that these
# private subnets will also need
# Versuche den Hostnamen des Servers aufzuloesen auch nachdem
# to know to route the OpenVPN client
# keine Verbindung zum Internet bestand.
# address pool (10.8.0.0/255.255.255.0)
# Sinnvoll bei Clients, die keine permanente Internet-Anbindung haben.
# back to the OpenVPN server.
'''resolv-retry infinite'''
;push "route 192.168.10.0 255.255.255.0"
;push "route 192.168.20.0 255.255.255.0"
# Clienten brauchen keinen Port binden.

'''nobind'''
# To assign specific IP addresses to specific
# clients or if a connecting client has a private
# Pruefe, ob noch eine Verbindung mit dem Server besteht.
# subnet behind it that should also have VPN access,
# Jede 10 Sekunden einen Ping, falls nach 60 Sekunden
# use the subdirectory "ccd" for client-specific
# keine Antwort ankommt, wird ein Verbindungsabbruch angenommen.
# configuration files (see man page for more info).
'''keepalive 10 60'''

# EXAMPLE: Suppose the client
# Kompression fuer den Tunnel
# having the certificate common name "Thelonious"
'''comp-lzo'''
# also has a small subnet behind his connecting
# machine, such as 192.168.40.128/255.255.255.248.
# Abgeben der Prozess-Rechte nach dem Start:
# First, uncomment out these lines:
# * ''user'' Nutzer nach Rechteabgabe (mit moeglichst wenig Rechten)
;client-config-dir ccd
# * ''group'' Gruppe analog
;route 192.168.40.128 255.255.255.248
# * ''persist-key'' Lese die Schluessel nicht beim Neustart durch
# Then create a file ccd/Thelonious with this line:
# ''SIGUSR1'' bzw. ''--ping-restart'' ein
# iroute 192.168.40.128 255.255.255.248
# * ''persist-tun'' Analog fuer den Zugriff auf das TUN/TAP-Device
# This will allow Thelonious' private subnet to
'''user nobody'''
# access the VPN. This example will only work
'''group nobody'''
# if you are routing, not bridging, i.e. you are
'''persist-key'''
# using "dev tun" and "server" directives.
'''persist-tun'''

# EXAMPLE: Suppose you want to give
# Log-Level:
# 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"

# 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
# 0 keine Ausgabe bis auf kritische Fehler
# CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
# 4 empfohlen fuer Standardbetrieb
# EACH HAVING ITS OWN UNIQUE "COMMON NAME",
# 5 und 6 zum Debuggen
# UNCOMMENT THIS LINE OUT.
# 9 maximal
;duplicate-cn
'''verb 4'''

# The keepalive directive causes ping-like
# Daemon-Mode: keine Ausgabe auf das Terminal (stdout) sondern ins Syslog
# messages to be sent back and forth over
;daemon # Sollte erst nach fertiger Konfiguration aktiviert werden
# the link so that each side knows when
# the other side has gone down.
# Lege nach dem Verbindungsaufbau automatisch eine Route zum lokalen Netz
# Ping every 10 seconds, assume that remote
# hinter dem Server durch den Tunnel an.
# peer is down if no ping received during
# Beispiel: ''Subnetz 192.168.2.0/24''
# a 120 second time period.
;route 192.168.2.0 255.255.255.0
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 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

# 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,
# 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
</code>


=== client.conf ===

<code>
##############################################
# 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
# to load balance between the servers.
remote my-server-1 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
# file can be used for all clients.
ca ca.crt
cert client.crt
key 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 ta.key 1

# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
;cipher x

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

=== firewall.sh ===

Das folgende Skript nutzt die Linux-Kernel-Erweiterung netfilter, um eine
Firewall zu errichten. Lediglich UDP-Verbindungen auf dem Port 1194 werden
nicht geblockt. Auf diesem Port sollte der OpenVPN-Server horchen, um eine
Verbindung des Clients mit der virtuellen tun/tap-Schnittstelle des Servers zu
ermöglichen. Jene Schnittstelle besitzt im Gegensatz zu anderen Netzwerkkarten
alle Rechte zum FORWARD, INPUT und OUTPUT.

<code>
#!/bin/bash

# A Sample OpenVPN-aware firewall.

# eth0 is connected to the internet.
# eth1 is connected to a private subnet.

# Change this subnet to correspond to your private
# ethernet subnet. Home will use HOME_NET/24 and
# Office will use OFFICE_NET/24.
PRIVATE=10.0.0.0/24

# Loopback address
LOOP=127.0.0.1

# Delete old iptables rules
# and temporarily block all traffic.
iptables -P OUTPUT DROP
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -F

# Set default policies
iptables -P OUTPUT ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP

# Prevent external packets from using loopback addr
iptables -A INPUT -i eth0 -s $LOOP -j DROP
iptables -A FORWARD -i eth0 -s $LOOP -j DROP
iptables -A INPUT -i eth0 -d $LOOP -j DROP
iptables -A FORWARD -i eth0 -d $LOOP -j DROP

# Anything coming from the Internet should have a real Internet address
iptables -A FORWARD -i eth0 -s 192.168.0.0/16 -j DROP
iptables -A FORWARD -i eth0 -s 172.16.0.0/12 -j DROP
iptables -A FORWARD -i eth0 -s 10.0.0.0/8 -j DROP
iptables -A INPUT -i eth0 -s 192.168.0.0/16 -j DROP
iptables -A INPUT -i eth0 -s 172.16.0.0/12 -j DROP
iptables -A INPUT -i eth0 -s 10.0.0.0/8 -j DROP

# Block outgoing NetBios (if you have windows machines running
# on the private subnet). This will not affect any NetBios
# traffic that flows over the VPN tunnel, but it will stop
# local windows machines from broadcasting themselves to
# the internet.
iptables -A FORWARD -p tcp --sport 137:139 -o eth0 -j DROP
iptables -A FORWARD -p udp --sport 137:139 -o eth0 -j DROP
iptables -A OUTPUT -p tcp --sport 137:139 -o eth0 -j DROP
iptables -A OUTPUT -p udp --sport 137:139 -o eth0 -j DROP

# Check source address validity on packets going out to internet
iptables -A FORWARD -s ! $PRIVATE -i eth1 -j DROP

# Allow local loopback
iptables -A INPUT -s $LOOP -j ACCEPT
iptables -A INPUT -d $LOOP -j ACCEPT

# Allow incoming pings (can be disabled)
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT

# Allow services such as www and ssh (can be disabled)
iptables -A INPUT -p tcp --dport http -j ACCEPT
iptables -A INPUT -p tcp --dport ssh -j ACCEPT

# Allow incoming OpenVPN packets
# Duplicate the line below for each
# OpenVPN tunnel, changing --dport n
# to match the OpenVPN UDP port.
#
# In OpenVPN, the port number is
# controlled by the --port n option.
# If you put this option in the config
# file, you can remove the leading '--'
#
# If you taking the stateful firewall
# approach (see the OpenVPN HOWTO),
# then comment out the line below.

iptables -A INPUT -p udp --dport 1194 -j ACCEPT

# Allow packets from TUN/TAP devices.
# When OpenVPN is run in a secure mode,
# it will authenticate packets prior
# to their arriving on a tun or tap
# interface. Therefore, it is not
# necessary to add any filters here,
# unless you want to restrict the
# type of packets which can flow over
# the tunnel.

iptables -A INPUT -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A INPUT -i tap+ -j ACCEPT
iptables -A FORWARD -i tap+ -j ACCEPT

# Allow packets from private subnets
iptables -A INPUT -i eth1 -j ACCEPT
iptables -A FORWARD -i eth1 -j ACCEPT

# Keep state of connections from local machine and private subnets
iptables -A OUTPUT -m state --state NEW -o eth0 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state NEW -o eth0 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

# Masquerade local subnet
iptables -t nat -A POSTROUTING -s $PRIVATE -o eth0 -j MASQUERADE
</code>



==Literatur==
===Transparente Fillialanbindung (Netz-zu-Netz)===


* [http://openvpn.sourceforge.net/ OpenVPN-Homepage]
=Literatur=
* [http://openvpn.net/howto.html OpenVPN-Howto]
* [http://www.online-tutorials.net/security/openvpn-tutorial/tutorials-t-69-209.html OpenVPN-Tutorial (deutsch)]
* [http://www.lugah.de.bart.blserver.de/Data/OpenVPN-Howto/OpenVPN_Mini_HowTo.html OpenVPN-Mini-Howto (deutsch)]
* [http://www.sans.org/reading_room/whitepapers/vpns/ OpenVPN and the SSL VPN Revolution]
* c't 9/05 Open-Source-Projekt Open VPN , Seite 194
* Linux Magazin, Oktober 2003: VPN im Userspace mit OpenVPN

Latest revision as of 09:23, 15 June 2012

OpenVPN ist eine leicht aufzusetzende und zu wartende Virtual Private Network-Applikation, die bis auf die notwendige virtuelle Netzwerkschnittstelle komplett im Userspace arbeitet. Der gesamte Netzwerkverkehr wird auf Grundlage von OpenSSL verschlüsselt.


Funktionsweise

OpenVPN legt nach dem Start sowohl auf der Client- als auch auf der Serverseite eine virtuelle Netzwerkschnittstelle an (wenn nicht schon vorhanden), welche jeweils ein Ende des Tunnelsdarstellt. Der OpenVPN-Server muss vom Client durch eine feste IP-Addresse oder festen Host-Namen erreichbar sein und verbindet sich mit ihm auf einem beliebigen UDP- oder TCP-Port. Mit den zwei Verbindungsarten Routing und Bridging stehen nun je nach Auswahl fast alle oder jegliche Dienste des lokalen Netzes für den Client zur Verfügung.

Der gesamte Datenverkehr durch den Tunnel wird mittels OpenSSL-Bibliotheken verschlüsselt. Die LZO-Bibliotheken bieten die Option zur Kompression dieser Information.

Benötigte Komponenten

Installation

Windows

Die Installation erfolgt - wie unter Windows üblich - durch Starten der EXE-Datei und wiederholtem Klicken auf Next. Danach findet sich das openvpn-Programm unter \Programme\OpenVPN\bin, die Konfigurationsdateien unter \Programme\OpenVPN\config.

Als unprivilegierter Benutzer starten

Um den Tunnel als normaler Benutzer aufzubauen müssen die Zugriffskontrolllisten für den OpenVPN-Dienst angepasst werden. z.B. mit SetACL oder Subinacl.exe.

Anzeigen der Zugriffsrechte:
setacl -on openvpnservice -ot srv -actn list

Setzen der ACLs für den OpenVPN-Service, so daß Benutzer den Dienst starten und beenden können:
setacl -on openvpnservice -ot srv -actn ace -ace "n:Benutzer;p:start_stop"

Starten des Dienstes via Kommandozeile:
sc start OpenVPNService

Stoppen des Dienstes via Kommandozeile:
sc stop OpenVPNService

Die obigen Maßnahmen erlauben aber noch nicht das Setzen von Routen. Um einem unprivilegiertem Nutzer das Setzen von Routen zu ermöglichen, muss er zur Gruppe der Netzwerkkonfigurations-Operatoren hinzugefügt werden. Wer nach dem Anmelden seine Lieblingsverbindung automatisch starten möchte, muss in der Registry unter HKLM\SOFTWARE/Microsoft\Windows\CurrentVersion\Run den openvpn-gui Eintrag ändern.
openvpn-gui REG_SZ c:\programme\openvpn\bin\openvpn-gui.exe --connect config.ovpn
Dann wird man beim Anmelden, je nach Art der Verbindung, sofort nach Username und Passwort (z.B. für Base1) gefragt.

Unix

Alle handelsüblichen Distributionen bieten mehr oder weniger aktuelle Pakete von OpenVPN an, die i.d.R. die hier angesprochenen Funktionalitäten aufweisen. Eventuell müssen analog empfohlene Zusatzpakete installiert werden (z.B. OpenSSL oder LZO).

Distribution Version(en) Installationskommando (als root)
suse/opensuse >=9.3 yast -i openvpn
gentoo n/a emerge openvpn
FreeBSD 6.0 pkg_add -r openvpn
debian >=3.1 apt-get install openvpn
ubuntu >=5.10 apt-get install openvpn
Fedora Core >=4 yum install openvpn

Sofern keine Paketverwaltungssoftware benutzt werden kann, bleibt noch der Weg über die Quelltexte um an eine aktuelle Version des Programms zu kommen. Das bekannte Drei-Gespann:

./configure
make
make install

sollte bis auf die Angabe der Pfade für Header- und Bibliotheks-Dateien zum Erfolg führen, sofern Compiler und SSL-Bibliotheken (in der Entwicklerversion) installiert sind. Für eine Konfiguration mit lzo unterhalb von /usr/local hilft folgender Aufruf von configure:

./configure --with-lzo-headers=/usr/local/include/ --with-lzo-lib=/usr/local/lib/


Als unprivilegierter Benutzer starten

Da OpenVPN Änderungen an den Netzwerkeinstellungen vornimmt, muss das Programm mit root-Rechten ausgeführt werden. Um den normalen Benutzern nicht das root-Passwort geben zu müssen, kann man statt dessen sudo verwenden. Als root nimmt man mit visudo folgenden Eintrag vor:

# Komma-separierte Liste der VPN-Nutzer
User_Alias VPNUSER=vpnuser1, vpnuser2
# Zum testen des VPN sollte man das --daemon weglassen,
# um evtl. Fehler auf stdout zu erhalten.
Cmnd_Alias OPENVPN=/usr/local/sbin/openvpn --config /etc/openvpn/SAR-VPN.ovpn --daemon
Cmnd_Alias KILLOPENVPN=/usr/bin/killall openvpn
# NOPASSWD ist optional.
# Soll der Nutzer sein Passwort eingeben muessen lautet der Eintrag wie folgt:
#VPNUSER ALL=OPENVPN
#VPNUSER ALL=KILLOPENVPN
VPNUSER ALL=NOPASSWD:OPENVPN
VPNUSER ALL=NOPASSWD:KILLOPENVPN

In diesem Beispiel wird angenommen, dass die Konfigurationsdatei unter /etc/openvpn/SAR-VPN.ovpn und das openvpn-Programm unter /usr/local/sbin/openvpn zu finden ist.

Der Tunnel kann dann mit

sudo /usr/local/sbin/openvpn --config /etc/openvpn/SAR-VPN.ovpn --daemon

gestartet und mit

sudo killall openvpn

beendet werden.

Konfiguration

Grundeinstellung

Ausführlich beschrieben im offiziellen Handbuch; im Wesentlichen läuft es darauf hinaus bei Client und Server zueinander passende Einstellungen zu wählen.

OpenVPN-Client und -Server können sich sowohl über UDP als auch TCP unterhalten. Bei der richtigen Wahl ist zu Bedenken, dass das tap-Device (siehe unten) auf Layer 2 Ebene tunnelt und somit innerhalb des Kanals TCP-Pakete sendet. Da TCP ein Verbindungsorientiertes Protokoll ist, besitz es eine sich selbst anpassende Zeitspanne, nach der ein erneuter Request auf ein nicht angekommenes Paket gesendet wird. Liegt also ein TCP-Layer über einem anderen, beide ausgestattet mit Timer und Resend-Request. Diese Kontrollflusspakete werden zusätzlich zu den eigentlichen Daten gesendet und sind für sie redundant. Wenn die Verbindung im Kanal einen kurzen Timer besitz, werden Resend-Requests über den TCP-Tunnel gesendet und erhöhen so auch das Datenaufkommen außerhalb des Tunnels (die TCP-Pakete der Verbindung, die den Tunnel bildet kann ebenfalls verloren gehen was zu neuen Resend-Requests führt). Durch sich kumulierende Kontrollflusnachrichten erhöht sich der Geschwindigkeitsverlust durch redundante Daten (mehr dazu siehe hier).

Authentifikation

Preshared Key

Die Preshared-Secret-Authentifizierung basiert auf einem symmetrischen Verschlüsselungsverfahren. Mittels openvpn --genkey --secret static.key wird ein gemeinsamer Schlüssel erzeugt, den die beiden Kommunikationspartner zuvor über einen sicheren Kanal erhalten müssen. Der gesamte Tunnel-Netzwerkverkehr wird dann mit diesem Schlüssel verschlüsselt und kann von jedem, der ebenfalls den Schlüssel besitzt entschlüsselt werden. Daher eignet sich jeder Schlüssel für nur genau eine Punkt-zu-Punkt verbindung und muss bei Kompromittierung ausgetauscht werden.

Mittels der beiden folgenden Konfigurationsdateien sollte bereits eine Verbindung zwischen Client und Server möglich sein:

server.conf:

dev tun
ifconfig 10.8.0.1 10.8.0.2
secret static.key

client.conf:

remote myremote.mydomain
dev tun
ifconfig 10.8.0.2 10.8.0.1
secret static.key

Dabei sollte myremote.mydomain in den Hostnamen oder die statische IP des Servers geändert werden. In diesem Beispiel erhalten die virtuellen tun-Schnittstellen die Addressen 10.8.0.1 (Server) und 10.8.0.2 (Client).


Zertifikatbasierte Authentifizierung

Die Zertifikatbasierte Authentifizierung nutzt eine [[Public Key Infrastructure]] (PKI) und basiert auf einem asymmetrischen Verschlüsselungsverfahren, über welches ein sicherer Kanal erzeugt wird. Dabei kommen signierte Zertifikate zum Einsatz, die bei Kompromittierung lediglich gesperrt und gegebenenfalls auf der entsprechenden Maschine durch ein neues ersetzt werden müssen. Ohne ein von der Certificate Authority (CA) signiertes Zertifikat seines Gegenübers akzeptiert kein Kommunikationspartner die Verbindung.

Erstellen einer PKI mit OpenVPN

OpenSSL bringt bereits alle Werkzeuge mit, um eine CA aufzusetzen, um damit Server- und Clientzertifikate sowie die dazugehörigen privaten Schlüssel zu erstellen. OpenVPN besitzt im Unterverzeichnis easy-rsa weitere Skripte, mit denen diese Tools bedient und deren Handhabung noch weiter vereinfacht. Die Bedienung von easy-rsa entnehmen Sie bitte dem OpenVPN-howto.

Die folgende, dem Howto entnommene Tabelle ordnet jeder generierten Datei einen Besitzer zu. Besonders zu beachten ist, dass die als Secret markierten Dateien nur an die dafür vorgesehenen Parteien gegeben werden.

Filename Needed By Purpose Secret
ca.crt server + all clients Root CA certificate NO
ca.key key signing machine only Root CA key YES
dh{n}.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
Anpassung der .conf bzw. .ovpn Dateien

Sowohl beim Server als auch beim Client ist darauf zu achten, dass die folgenden Zeilen der unten gegebenen Beispielkonfigurationen

ca ca.crt
cert server.crt
key server.key

bzw.

ca ca.crt
cert client.crt
key client.key

auf die für den Server/Client erstellten Dateien zeigen. Sollten Sie nicht mit der unten gegebenen Konfiguration starten, müssen Sie die Preshared-Key-Authentifizierung evtl. deaktivieren.

Benutzername/Passwort

Wahl des virtuellen Device

Auf den OpenVPN-Gateways muss in jedem Fall das IP-Forwarding (Routing) eingestellt sein. Auf Debian-Systemen muss hierzu in der /etc/network/options die Option ip_forward auf yes geändert werden. Suse bietet mittels yast an, dies via Häkchen bei den Netzwerkeinstellungen zu machen. Bei anderen Systemen sollte ein echo 1 > /proc/sys/net/ipv4/ip_forward zum Erfolg führen (muss nach jedem Neustart ausgeführt werden).

tun-Devices

Durch den Tunnel können mit einem dieser Schnittstelle alle gängigen Netzwerkprotokolle auf IP-Basis (Layer 3) transportiert werden. So können Daten vom Fileserver sowie Datenbankinfos abgerufen, ebenso können E-Mails bei einem Mailserver abgeholt werden. Das alles funktioniert, als ob man sich vor Ort befände, weil alle Anfragen zu beliebigen Rechnern im lokalen Netz durchgereicht werden. Interessant ist die Technik auch für Außendienstler (Roadwarrior), die sich von unterwegs in der Zentrale einloggen wollen, um ihre Daten abzugleichen.

Die Kommunikation von drinnen nach draußen funktioniert über mehrere Routen auf Client und Serverseite, daher wird das Verfahren auch Routing genannt. Die Konfigurationsvorlagen sind bereits für den Einsatz des tun-Device ausgelegt.

tap-Devices

Im Gegensatz zu OpenVPN mit einem tun-Device beherrscht die Konfiguration mit einem tap-Device ein vollständiges Tunneln von Ethernet-Frames (Layer 2) und erlaubt somit beispielsweise auch den Einsatz von IPX über einem Tunnel. Ist OpenVPN 2.0 für tap-Devices konfiguriert, bekommen Clients IP-Adressen aus dem Adresspool des Servernetzes. Dies setzt voraus, dass dort bereits ein DHCP-Server seinen Dienst verrichtet. Alternativ kann OpenVPN einen DHCP-Server simulieren und selbst IP-Adressen verteilen.

In den Konfigurationsvorlagen muss dazu die Wahl der Netzwerkschnittstelle geändert werden:

dev tap
;dev tun

Zwei Netze, das virtuelle VPN-Netz und das lokale Netzwerk, werden über eine Brücke miteinander verbunden und unter ein und derselben Subdomain vereint. Das Verfahren nennt man daher auch Bridging.

Szenarien

Außendienst-Mitarbeiter (Netz-zu-Host)

Eine häufiger Anwendungsfall für VPNs beschreibt folgendes Szenario: Ein Außendienst-Mitarbeiter (auch Roadwarrior), Tele-Arbeiter oder einfach jemand der zu Hause noch ein Dokument braucht, möchte Zugriff auf die Ressourcen seines Firmen-Netzes erlangen, welches aus Sicherheitsgründen zum Internet aber durch eine Firewall abgeschottet ist.

In der folgenden Betrachtung wird davon ausgegangen, dass das Firmen-Netzwerk im Subnetz 192.168.0.0/24 liegt. Diese Angaben sind bei der Konfiguration natürlich an die lokalen Gegebenheiten anzupassen. Weiterhin soll für als Subnetz, in welchem sich die VPN-Clients befinden, 192.168.10.0/24 angenommen werden.

Für kleine Netzwerke kann für dieses Szenario auch der Peer-to-Peer-Modus (mit Shared-Secret-Authentifizierung) von OpenVPN verwendet werden. Der Administrationsaufwand steigt bei dieser Realisierung mit der Größe des VPN-Netzes - also mit der Anzahl der VPN-Clients. Außerdem muss pro Client auf der Serverseite ein expliziter Daemon-Prozess mit separatem UDP-Port laufen, was zudem die Firewall-Konfiguration aufwändiger gestaltet. Im folgenden wird daher der Server-Client-Modus von OpenVPN (ab Version 2) mit Hilfe von zertifikatbasierter Authentifizierung beschrieben.


Transparente Fillialanbindung (Netz-zu-Netz)

Für dieses Szenario kann die Konfiguration aus dem ersten Test verwendet werden. Es wird dann kein expliziter Server ausgewiesen und es braucht keine PKI aufgesetzt werden. Man muss nur den gemeinsamen Schlüssel über einen sicheren Kanal übertragen, z.B. eine verschlüsselte E-Mail.

Sinnvollerweise kann man die Optionen wie im o.g. Szenario in eine Datei schreiben und ein paar zusätzliche Optionen, wie das automatische Setzen von Routen angeben.

Eine Beispiel-Konfiguration wäre also:

##############################################################################
# /etc/openvpn/openvpn-gateway.ovpn
#
# Diese Konfiguartionsdatei beinhaltet Einstellungen
# fuer einen OpenVPN-Gateway.
#
# Mit
#   openvpn --config /etc/openvpn/openvpn-gateway.ovpn
# kann das Gateway gestartet werden.
remote 192.168.10.2
;remote 192.168.10.1  # auf der anderen Tunnelseite
ifconfig 192.168.10.1 192.168.10.2
;ifconfig 192.168.10.2 192.168.10.1  # auf der anderen Tunnelseite

proto udp
port 5000
dev tun
cd /etc/openvpn
secret preshared.key
keepalive 10 60
comp-lzo
user nobody
group nobody
persist-key
persist-tun
verb 4
;daemon # Sollte erst nach fertiger Konfiguration aktiviert werden

Will man mehrere Fillialen an eine Zentrale anbinden, wird man eher zum oben genannten Netz-zu-Host-Szenario greifen. Hierbei spielt das Gateway in der Zentrale die Rolle des Servers und das Gateway der Filliale die Rolle des Clients. Eventuell muss auf Server-Seite noch ein clientspezifisches Skript mit entsprechenden Routing-Eintragungen eingesetzt werden, falls in der Zentrale ein Rechner aus dem Netz der Filliale erreicht werden soll.

Extra-Sicherheit

Nachdem die Virtuellen Netzwerkkarten kreiert und die Routen gelegt sind, bietet OpenVPN unter Unix die Option seine Rechte zu reduzieren. Der Kommentar vor den folgenden Zeilen sollte bei den Konfigurationsvorlagen entfernt werden.

;user nobody
;group nobody

Falls also je eine Sicherheitslücke entdeckt werden sollte, kann der OpenVPN-Prozess nicht missbraucht werden. Zusätzlich kann man ihn mit Einfügen der folgenden Zeile an ein bestimmtes Verzeichnis binden:

chroot /usr/local/openvpn

Konfigurationsvorlagen

Die folgenden Beispielkonfigurationsdateien wurden dem OpenVPN-Paket entnommen.

server.conf

#################################################
# 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 tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# 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 MyTap
# 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 ca.crt
cert server.crt
key 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 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
# 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.4 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
# 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
# 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 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
# 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,
# 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


client.conf

##############################################
# 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
# to load balance between the servers.
remote my-server-1 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
# file can be used for all clients.
ca ca.crt
cert client.crt
key 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 ta.key 1
# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
;cipher x
# 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

firewall.sh

Das folgende Skript nutzt die Linux-Kernel-Erweiterung netfilter, um eine Firewall zu errichten. Lediglich UDP-Verbindungen auf dem Port 1194 werden nicht geblockt. Auf diesem Port sollte der OpenVPN-Server horchen, um eine Verbindung des Clients mit der virtuellen tun/tap-Schnittstelle des Servers zu ermöglichen. Jene Schnittstelle besitzt im Gegensatz zu anderen Netzwerkkarten alle Rechte zum FORWARD, INPUT und OUTPUT.

#!/bin/bash
# A Sample OpenVPN-aware firewall.
# eth0 is connected to the internet.
# eth1 is connected to a private subnet.
# Change this subnet to correspond to your private
# ethernet subnet.  Home will use HOME_NET/24 and
# Office will use OFFICE_NET/24.
PRIVATE=10.0.0.0/24
# Loopback address
LOOP=127.0.0.1
# Delete old iptables rules
# and temporarily block all traffic.
iptables -P OUTPUT DROP
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -F
# Set default policies
iptables -P OUTPUT ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP
# Prevent external packets from using loopback addr
iptables -A INPUT -i eth0 -s $LOOP -j DROP
iptables -A FORWARD -i eth0 -s $LOOP -j DROP
iptables -A INPUT -i eth0 -d $LOOP -j DROP
iptables -A FORWARD -i eth0 -d $LOOP -j DROP
# Anything coming from the Internet should have a real Internet address
iptables -A FORWARD -i eth0 -s 192.168.0.0/16 -j DROP
iptables -A FORWARD -i eth0 -s 172.16.0.0/12 -j DROP
iptables -A FORWARD -i eth0 -s 10.0.0.0/8 -j DROP
iptables -A INPUT -i eth0 -s 192.168.0.0/16 -j DROP
iptables -A INPUT -i eth0 -s 172.16.0.0/12 -j DROP
iptables -A INPUT -i eth0 -s 10.0.0.0/8 -j DROP
# Block outgoing NetBios (if you have windows machines running
# on the private subnet).  This will not affect any NetBios
# traffic that flows over the VPN tunnel, but it will stop
# local windows machines from broadcasting themselves to
# the internet.
iptables -A FORWARD -p tcp --sport 137:139 -o eth0 -j DROP
iptables -A FORWARD -p udp --sport 137:139 -o eth0 -j DROP
iptables -A OUTPUT -p tcp --sport 137:139 -o eth0 -j DROP
iptables -A OUTPUT -p udp --sport 137:139 -o eth0 -j DROP
# Check source address validity on packets going out to internet
iptables -A FORWARD -s ! $PRIVATE -i eth1 -j DROP
# Allow local loopback
iptables -A INPUT -s $LOOP -j ACCEPT
iptables -A INPUT -d $LOOP -j ACCEPT
# Allow incoming pings (can be disabled)
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
# Allow services such as www and ssh (can be disabled)
iptables -A INPUT -p tcp --dport http -j ACCEPT
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
# Allow incoming OpenVPN packets
# Duplicate the line below for each
# OpenVPN tunnel, changing --dport n
# to match the OpenVPN UDP port.
#
# In OpenVPN, the port number is
# controlled by the --port n option.
# If you put this option in the config
# file, you can remove the leading '--'
#
# If you taking the stateful firewall
# approach (see the OpenVPN HOWTO),
# then comment out the line below.
iptables -A INPUT -p udp --dport 1194 -j ACCEPT
# Allow packets from TUN/TAP devices.
# When OpenVPN is run in a secure mode,
# it will authenticate packets prior
# to their arriving on a tun or tap
# interface.  Therefore, it is not
# necessary to add any filters here,
# unless you want to restrict the
# type of packets which can flow over
# the tunnel.
iptables -A INPUT -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A INPUT -i tap+ -j ACCEPT
iptables -A FORWARD -i tap+ -j ACCEPT
# Allow packets from private subnets
iptables -A INPUT -i eth1 -j ACCEPT
iptables -A FORWARD -i eth1 -j ACCEPT
# Keep state of connections from local machine and private subnets
iptables -A OUTPUT -m state --state NEW -o eth0 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state NEW -o eth0 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
# Masquerade local subnet
iptables -t nat -A POSTROUTING -s $PRIVATE -o eth0 -j MASQUERADE


Literatur