OpenVPN в Windows

Материал из Xgu.ru

Перейти к: навигация, поиск
stub.png
Данная страница находится в разработке.
Эта страница ещё не закончена. Информация, представленная здесь, может оказаться неполной или неверной.

Если вы считаете, что её стоило бы доработать как можно быстрее, пожалуйста, скажите об этом.

Автор: Сергей Черепенин

Короткий URL: openvpn/windows


Содержание

[править] Организация соединения с использованием статических ключей

В данной главе рассматривается подготовка и организация vpn соединения с использованием статического ключа. В качестве сервера используется компьютер с операционной системой Debian GNU/Linux Etch на ядре 2.6.18-4-686, а в качестве клиента - Windows 2003 SP2.

Настройки сетевых интерфейсов сервера и клиента:

  • сервер
$ /sbin/ifconfig

eth0      Link encap:Ethernet  HWaddr 00:04:76:A1:EF:BB  
          inet addr:10.0.17.1  Bcast:10.255.255.255  Mask:255.0.0.0
          inet6 addr: fe80::204:76ff:fea1:efbb/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5663951 errors:0 dropped:0 overruns:1 frame:0
          TX packets:2928925 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1850432381 (1.7 GiB)  TX bytes:330532572 (315.2 MiB)
          Interrupt:169 

eth1      Link encap:Ethernet  HWaddr 00:60:08:20:7B:0B  
          inet addr:192.168.16.15  Bcast:192.168.16.255  Mask:255.255.255.0
          inet6 addr: fe80::260:8ff:fe20:7b0b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:104476 errors:0 dropped:0 overruns:0 frame:0
          TX packets:120582 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:19294593 (18.4 MiB)  TX bytes:48250297 (46.0 MiB)
          Interrupt:185 Base address:0xc400 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:64752 errors:0 dropped:0 overruns:0 frame:0
          TX packets:64752 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:43343011 (41.3 MiB)  TX bytes:43343011 (41.3 MiB)
  • клиент
C:\Documents and Settings\Administrator>ipconfig /all

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix  . : net.nt
Description . . . . . . . . . . . : 3Com EtherLink XL 10/100 PCI For Complete
PC Management NIC (3C905C-TX)
Physical Address. . . . . . . . . : 00-04-75-75-46-C1
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 192.168.16.197
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.16.15
DHCP Server . . . . . . . . . . . : 192.168.16.15
DNS Servers . . . . . . . . . . . : 192.168.16.15
Lease Obtained. . . . . . . . . . : 12 июля 2011 г. 11:49:13
Lease Expires . . . . . . . . . . : 12 июля 2011 г. 11:59:13

Теперь необходимо проинсталлировать необходимое программное обеспечение принятым, для каждой операционной системы, способом.

На сервере под управлением ОС Debian GNU/Linux достаточно выполнить команду:

$ sudo apt-get install openvpn -y

Список файлов, входящих в состав пакета openvpn_2.0.9-4_i386.deb можно просмотреть с помощью команды:

$ sudo dpkg -L openvpn

Кроме этого, проверьте имеет ли Ваше ядро поддержку TUN/TAP устройств. Сделать это можно выполнив следующую команду:

$ grep CONFIG_TUN /boot/config-`uname -r`
CONFIG_TUN=m

Если Ваше ядро не поддерживает эти устройства:

$ grep CONFIG_TUN /boot/config-`uname -r`
# CONFIG_TUN is not set

то для продолжения Вам необходимо скомпилировать этот модуль.

На клиенте, под управлением ОС Windows 2003 SP2, необходимо в первую очередь получить инсталляционный файл. Скачать его можно с помощью ссылки. На момент написания статьи текущая версия OpenVPN - 2.0.9. Затем необходимо проинсталлировать полученное программное обеспечение обычным вызовом .exe файла. Во время инсталляции оставьте все значения по умолчанию.

После установки необходимо сгенерировать статический ключ на любом компьютере - сервере или клиенте, скопировать его на другой компьютер и отредактировать конфигурационные файлы сервера и клиента.

  • Для генерации статического ключа в ОС Debian необходимо выполнить следующую команду:
 
$ sudo openvpn --genkey --secret /etc/openvpn/static.key
  • Для генерации статического ключа в ОС Windows необходимо запустить следующую команду: Пуск -> Программы -> OpenVPN -> Generate a static OpenVPN key. В результате будет создан файл C:\Program Files\OpenVPN\config\key.txt. Затем необходимо скопировать этот ключ на другого участника соединения.

Далее отредактируйте конфигурационные файлы сервера и клиента:

  • конфигурационный файл сервера /etc/openvpn/sample.conf:
cat  /etc/openvpn/sample.conf 
dev tap
ifconfig 172.16.0.1 255.255.255.0
secret key.txt
comp-lzo
  • конфигурационный файл клиента C:\Program Files\OpenVPN\config\sample.ovpn:
remote 192.168.16.15
dev tap
ifconfig 172.16.0.2 255.255.255.0
secret key.txt
comp-lzo

Из указанных выше конфигурационных файлов видно, что различие серверного и клиентского конфигов очень мало, и сервером будет тот компьютер, у которого не указан параметр remote

Выполним команду на сервере:

sudo openvpn --config /etc/openvpn/sample.conf
Tue Jul  12 11:54:44 2011 OpenVPN 2.0.9 i486-pc-linux-gnu [SSL] [LZO] [EPOLL] built on Jan 21 2007
Tue Jul  12 11:54:44 2011 IMPORTANT: OpenVPN's default port number is now 1194, based on an official port number assignment by IANA.  OpenVPN 2.0-beta16 and earlier used 5000 as the default port.
Tue Jul  12 11:54:44 2011 WARNING: file 'key.txt' is group or others accessible
Tue Jul  12 11:54:44 2011 TUN/TAP device tap0 opened
Tue Jul  12 11:54:44 2011 /sbin/ifconfig tap0 172.16.0.1 netmask 255.255.255.0 mtu 1500 broadcast 172.16.0.255
Tue Jul  12 11:54:44 2011 UDPv4 link local (bound): [undef]:1194
Tue Jul  12 11:54:44 2011 UDPv4 link remote: [undef]
Tue Jul  12 11:54:57 2011 Peer Connection Initiated with 192.168.16.197:1194
Tue Jul  12 11:54:58 2011 Initialization Sequence Completed

Затем на windows:

Ovpn1.png

Запустить сервис OpenVPN под Windows можно и из cmd:

C:\Documents and Settings\Administrator>cd "c:\Program Files\OpenVPN\config"
C:\Program Files\OpenVPN\config>openvpn --config sample.ovpn
Tue Jul 12 12:52:24 2011 us=640078 Current Parameter Settings:
Tue Jul 12 12:52:24 2011 us=640364   config = 'sample.ovpn'
Tue Jul 12 12:52:24 2011 us=640535   mode = 0
Tue Jul 12 12:52:24 2011 us=640688   show_ciphers = DISABLED
Tue Jul 12 12:52:24 2011 us=640852   show_digests = DISABLED
Tue Jul 12 12:52:24 2011 us=641022   show_engines = DISABLED
Tue Jul 12 12:52:24 2011 us=641192   genkey = DISABLED
Tue Jul 12 12:52:24 2011 us=641358   key_pass_file = '[UNDEF]'
Tue Jul 12 12:52:24 2011 us=641529   show_tls_ciphers = DISABLED
Tue Jul 12 12:52:24 2011 us=641706   proto = 0
Tue Jul 12 12:52:24 2011 us=641863 NOTE: --mute triggered...
Tue Jul 112 12:52:24 2011 us=642076 178 variation(s) on previous 10 message(s) su
ppressed by --mute
Tue Jul 12 12:52:24 2011 us=642346 OpenVPN 2.0.9 Win32-MinGW [SSL] [LZO] built o
n Oct  1 2006
Tue Jul 12 12:52:24 2011 us=643308 IMPORTANT: OpenVPN's default port number is n
ow 1194, based on an official port number assignment by IANA.  OpenVPN 2.0-beta1
6 and earlier used 5000 as the default port.
Tue Jul 12 12:52:24 2011 us=643684 WARNING: --ping should normally be used with
--ping-restart or --ping-exit
Tue Jul 12 12:52:24 2011 us=644588 Static Encrypt: Cipher 'BF-CBC' initialized w
ith 128 bit key
Tue Jul 12 12:52:24 2011 us=644902 Static Encrypt: Using 160 bit message hash 'S
HA1' for HMAC authentication
Tue Jul 12 12:52:24 2011 us=645257 Static Decrypt: Cipher 'BF-CBC' initialized w
ith 128 bit key
Tue Jul 12 12:52:24 2011 us=645528 Static Decrypt: Using 160 bit message hash 'S
HA1' for HMAC authentication
Tue Jul 12 12:52:24 2011 us=645839 LZO compression initialized
Tue Jul 12 12:52:24 2011 us=650456 TAP-WIN32 device [Local Area Connection 2] op
ened: \\.\Global\{59380ED2-2769-41B0-97F6-C4BC571471CA}.tap
Tue Jul 12 12:52:24 2011 us=650817 TAP-Win32 Driver Version 8.4
Tue Jul 12 12:52:24 2011 us=651030 TAP-Win32 MTU=1500
Tue Jul 12 12:52:24 2011 us=651244 Notified TAP-Win32 driver to set a DHCP IP/ne
tmask of 172.16.0.2/255.255.255.0 on interface {59380ED2-2769-41B0-97F6-C4BC5714
71CA} [DHCP-serv: 172.16.0.0, lease-time: 31536000]
Tue Jul 12 12:52:24 2011 us=687896 Successful ARP Flush on interface [65540] {59
380ED2-2769-41B0-97F6-C4BC571471CA}
Tue Jul 12 12:52:24 2011 us=694501 Data Channel MTU parms [ L:1577 D:1450 EF:45
EB:135 ET:32 EL:0 AF:3/1 ]
Tue Jul 12 12:52:24 2011 us=698395 Local Options String: 'V4,dev-type tap,link-m
tu 1577,tun-mtu 1532,proto UDPv4,ifconfig 172.16.0.0 255.255.255.0,comp-lzo,ciph
er BF-CBC,auth SHA1,keysize 128,secret'
Tue Jul 12 12:52:24 2011 us=704162 Expected Remote Options String: 'V4,dev-type
tap,link-mtu 1577,tun-mtu 1532,proto UDPv4,ifconfig 172.16.0.0 255.255.255.0,com
p-lzo,cipher BF-CBC,auth SHA1,keysize 128,secret'
Tue Jul 12 12:52:24 2011 us=710006 Local Options hash (VER=V4): '94889dd0'
Tue Jul 12 12:52:24 2011 us=712199 Expected Remote Options hash (VER=V4): '94889
dd0'
Tue Jul 12 12:52:24 2011 us=716063 Socket Buffers: R=[8192->8192] S=[8192->8192]
Tue Jul 12 12:52:24 2011 us=720016 UDPv4 link local (bound): [undef]:1194
Tue Jul 12 12:52:24 2011 us=722180 UDPv4 link remote: 192.168.16.15:1194
Tue Jul 12 12:52:30 2011 us=303168 Peer Connection Initiated with 192.168.16.15:
1194
Tue Jul 12 12:52:31 2011 us=54350 TEST ROUTES: 0/0 succeeded len=-1 ret=1 a=0 u/
d=up
Tue Jul 12 12:52:31 2011 us=58342 Initialization Sequence Completed

Теперь проверьте состояние интерфейсов при помощи команды /sbin/ifconfig на сервере:

/sbin/ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:04:76:A1:EF:BB  
          inet addr:10.0.17.1  Bcast:10.255.255.255  Mask:255.0.0.0
          inet6 addr: fe80::204:76ff:fea1:efbb/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5663951 errors:0 dropped:0 overruns:1 frame:0
          TX packets:2928925 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1850432381 (1.7 GiB)  TX bytes:330532572 (315.2 MiB)
          Interrupt:169 

eth1      Link encap:Ethernet  HWaddr 00:60:08:20:7B:0B  
          inet addr:192.168.16.15  Bcast:192.168.16.255  Mask:255.255.255.0
          inet6 addr: fe80::260:8ff:fe20:7b0b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:104476 errors:0 dropped:0 overruns:0 frame:0
          TX packets:120582 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:19294593 (18.4 MiB)  TX bytes:48250297 (46.0 MiB)
          Interrupt:185 Base address:0xc400 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:64752 errors:0 dropped:0 overruns:0 frame:0
          TX packets:64752 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:43343011 (41.3 MiB)  TX bytes:43343011 (41.3 MiB)

tap0      Link encap:Ethernet  HWaddr 86:FA:EC:53:C3:84  
          inet addr:172.16.0.1  Bcast:172.16.0.255  Mask:255.255.255.0
          inet6 addr: fe80::84fa:ecff:fe53:c384/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:83 errors:0 dropped:0 overruns:0 frame:0
          TX packets:63 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:10893 (10.6 KiB)  TX bytes:9344 (9.1 KiB)

И на windows-клиенте при помощи команды ipconfig /all:

C:\Documents and Settings\Administrator>ipconfig /all

Windows IP Configuration

Host Name . . . . . . . . . . . . : win0
Primary Dns Suffix  . . . . . . . :
Node Type . . . . . . . . . . . . : Unknown
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : net.nt
Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix  . : net.nt
Description . . . . . . . . . . . : 3Com EtherLink XL 10/100 PCI For Complete
PC Management NIC (3C905C-TX)
Physical Address. . . . . . . . . : 00-04-75-75-46-C1
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 192.168.16.197
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.16.15
DHCP Server . . . . . . . . . . . : 192.168.16.15
DNS Servers . . . . . . . . . . . : 192.168.16.15
Lease Obtained. . . . . . . . . . : 12 июля 2011 г. 12:14:14
Lease Expires . . . . . . . . . . : 12 июля 2011 г. 12:24:14

Ethernet adapter Local Area Connection 2:
Connection-specific DNS Suffix  . :
Description . . . . . . . . . . . : TAP-Win32 Adapter V8
Physical Address. . . . . . . . . : 00-FF-59-38-0E-D2
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 172.16.0.2
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
DHCP Server . . . . . . . . . . . : 172.16.0.0
Lease Obtained. . . . . . . . . . : 12 июля 2011 г. 12:15:23
Lease Expires . . . . . . . . . . : 12 июля 2011 г. 12:15:23

И проверьте только что установленный туннель :

ping 172.16.0.2 -c 4
PING 172.16.0.2 (172.16.0.2) 56(84) bytes of data.
64 bytes from 172.16.0.2: icmp_seq=1 ttl=128 time=4.57 ms
64 bytes from 172.16.0.2: icmp_seq=2 ttl=128 time=0.813 ms
64 bytes from 172.16.0.2: icmp_seq=3 ttl=128 time=0.950 ms
64 bytes from 172.16.0.2: icmp_seq=4 ttl=128 time=1.11 ms

--- 172.16.0.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 0.813/1.863/4.578/1.571 ms

На этом организация vpn соединения с использованием статических ключей завершена.

[править] Создание сертификатов на Windows с использованием easy-rsa

В первую очередь необходимо создать каталог c:\Progam Files\OpenVPN\easy-rsa\keys и скопировать в него файлы serial.start и index.txt.start без суффикса .start. Сделать это можно при помощи следующей команды запущенной в cmd:

C:\Documents and Settings\Administrator>cd "c:\Program Files\OpenVPN\easy-rsa" && mkdir keys && copy serial.start keys\serial && copy index.txt.start keys\index.txt
        1 file(s) copied.
        1 file(s) copied.

Затем необходимо скопировать файлы vars.bat.sample и openssl.cnf.sample в vars.bat и openssl.cnf соответственно. Сделать это можно, выполнив batch файл C:\Program Files\OpenVPN\easy-rsa\init-config.bat при помощи следующей команды:

C:\Documents and Settings\Administrator>cd "c:\Program Files\OpenVPN\easy-rsa" && init-config.bat
C:\Program Files\OpenVPN\easy-rsa>copy vars.bat.sample vars.bat
        1 file(s) copied.
C:\Program Files\OpenVPN\easy-rsa>copy openssl.cnf.sample openssl.cnf
        1 file(s) copied.

Файл openssl.cnf --- >>>>
Файл vars.bat ----->>>

Затем необходимо отредактировать файл vars.bat:

@echo off
set HOME=%ProgramFiles%\OpenVPN\easy-rsa\
set KEY_CONFIG=openssl.cnf
set KEY_DIR=keys
set KEY_SIZE=1024
set KEY_COUNTRY=UA
set KEY_PROVINCE=Kiev
set KEY_CITY=Kiev
set KEY_ORG=TechExpert
set KEY_EMAIL=otradnyi@mail.ru

Затем необходимо внести изменения в среду окружения согласно файла vars.bat. Сделать это можно из cmd при помощи следующей команды:

C:\Documents and Settings\Administrator>cd "c:\Program Files\OpenVPN\easy-rsa" && vars.bat
  • Затем необходимо создать Diffie-Hellman key:
C:\Program Files\OpenVPN\easy-rsa>vars.bat
C:\Program Files\OpenVPN\easy-rsa>build-dh.bat
Loading 'screen' into random state - done
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
..................+...............................................................................+..........+.......................
.....+.....+.............+........................................................+.........+........................................
+.........+...................................................................................+......................................
.................................................................+...................................................+...............
.........+............................................................................+........+............................+........
....................+........................................+.........+............................+................................
.......................+...........+.................................................................+..........+....................
............................................+......+.........................+.......................+.....................+.........
........................................................+....+.......................................................................
.............................+..........................................+............................................................
..................................+...........+....................................................+.................................
.............................................................+......................................+.............................+..
.................................................................................................................+...................
.....++*++*++*

В результате в каталоге C:\Program Files\OpenVPN\easy-rsa\keys появится файл dh1024.pem:

C:\Program Files\OpenVPN\easy-rsa>dir keys
Volume in drive C has no label.
Volume Serial Number is 508A-A105
Directory of C:\Program Files\OpenVPN\easy-rsa\keys
13.07.2011  13:22    <DIR>          .
13.07.2011  13:22    <DIR>          ..
13.07.2011  13:22               245 dh1024.pem
13.07.2011  13:06                 0 index.txt
13.07.2011  13:06                 3 serial
               3 File(s)            248 bytes
               2 Dir(s)   7 517 777 920 bytes free
  • Теперь необходимо создать Certificate Authority. Создается он путем выполнения файла build-ca.bat:
C:\Program Files\OpenVPN\easy-rsa>vars.bat



C:\Program Files\OpenVPN\easy-rsa>build-ca.bat
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
.......++++++
...................++++++
writing new private key to 'keys\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) [UA]:UA
State or Province Name (full name) [Kiev]:Kiev
Locality Name (eg, city) [Kiev]:Kiev
Organization Name (eg, company) [TechExpert]:TechExpert
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:win0
Email Address [otradnyi@mail.ru]:otradnyi@mail.ru

В результате выполнения этой команды в каталоге keys было создано два файла ca.crt и ca.key:

C:\Program Files\OpenVPN\easy-rsa>dir keys
Volume in drive C has no label.
Volume Serial Number is 508A-A105
Directory of C:\Program Files\OpenVPN\easy-rsa\keys
13.07.2011  13:38    <DIR>          .
13.07.2011  13:38    <DIR>          ..
13.07.2011  13:38             1 224 ca.crt
13.07.2011  13:38               887 ca.key
13.07.2011  13:22               245 dh1024.pem
13.07.2011  13:06                 0 index.txt
13.07.2011  13:06                 3 serial
               5 File(s)          2 359 bytes
               2 Dir(s)   7 517 769 728 bytes free

ca.crt --->>>
ca.key ---->>>

  • Далее необходимо создать ключи сервера и клиента.

Для этого необходимо выполнить файл build-key-server.bat с параметром имени сервера, в нашем случае это win0:

C:\Program Files\OpenVPN\easy-rsa>vars.bat
C:\Program Files\OpenVPN\easy-rsa>build-key-server.bat win0
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
............................................++++++
....................++++++
writing new private key to 'keys\win0.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) [UA]:
State or Province Name (full name) [Kiev]:
Locality Name (eg, city) [Kiev]:
Organization Name (eg, company) [TechExpert]:
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:win0
Email Address [otradnyi@mail.ru]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from openssl.cnf
Loading 'screen' into random state - done
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'UA'
stateOrProvinceName   :PRINTABLE:'Kiev'
localityName          :PRINTABLE:'Kiev'
organizationName      :PRINTABLE:'TechExpert'
organizationalUnitName:PRINTABLE:'IT'
commonName            :PRINTABLE:'win0'
emailAddress          :IA5STRING:'otradnyi@mail.ru'
Certificate is to be certified until Jul  13 11:25:57 2017 GMT (3650 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

В результате в каталоге:

C:\Program Files\OpenVPN\easy-rsa>dir keys
Volume in drive C has no label.
Volume Serial Number is 508A-A105
Directory of C:\Program Files\OpenVPN\easy-rsa\keys
13.07.2011  14:26    <DIR>          .
13.07.2011  14:26    <DIR>          ..
13.07.2011  14:26             3 629 01.pem
13.07.2011  13:38             1 224 ca.crt
13.07.2011  13:38               887 ca.key
13.07.2011  13:22               245 dh1024.pem
13.07.2011  14:26                99 index.txt
13.07.2011  14:26                21 index.txt.attr
13.07.2011  14:26                 3 serial
13.07.2011  14:26             3 629 win0.crt
13.07.2011  14:25               680 win0.csr
13.07.2011  14:25               887 win0.key
               10 File(s)         11 304 bytes
               2 Dir(s)   7 517 663 232 bytes free
  • Теперь создадим ключ клиента:
C:\Program Files\OpenVPN\easy-rsa>build-key.bat roman
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
........++++++
........++++++
writing new private key to 'keys\roman.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) [UA]:
State or Province Name (full name) [Kiev]:
Locality Name (eg, city) [Kiev]:
Organization Name (eg, company) [TechExpert]:
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:roman
Email Address [otradnyi@mail.ru]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from openssl.cnf
Loading 'screen' into random state - done
DEBUG[load_index]: unique_subject = "yes"
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'UA'
stateOrProvinceName   :PRINTABLE:'Kiev'
localityName          :PRINTABLE:'Kiev'
organizationName      :PRINTABLE:'TechExpert'
organizationalUnitName:PRINTABLE:'IT'
commonName            :PRINTABLE:'roman'
emailAddress          :IA5STRING:'otradnyi@mail.ru'
Certificate is to be certified until Jul  13 11:37:01 2017 GMT (3650 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

В результате в каталоге:

C:\Program Files\OpenVPN\easy-rsa>dir keys
Volume in drive C has no label.
Volume Serial Number is 508A-A105
Directory of C:\Program Files\OpenVPN\easy-rsa\keys
13.07.2011  14:37    <DIR>          .
13.07.2011  14:37    <DIR>          ..
13.07.2011  14:26             3 629 01.pem
13.07.2011  14:37             3 531 02.pem
13.07.2011  13:38             1 224 ca.crt
13.07.2011  13:38               887 ca.key
13.07.2011  13:22               245 dh1024.pem
13.07.2011  14:37               199 index.txt
13.07.2011  14:37                21 index.txt.attr
13.07.2011  14:37                 3 serial
13.07.2011  14:37             3 531 roman.crt
13.07.2011  14:37               680 roman.csr
13.07.2011  14:37               887 roman.key
13.07.2011  14:26             3 629 win0.crt
13.07.2011  14:25               680 win0.csr
13.07.2011  14:25               887 win0.key
              14 File(s)         20 033 bytes
               2 Dir(s)   7 517 650 944 bytes free
  • Теперь необходимо скопировать roman.crt, roman.key и ca.crt в каталог /etc/openvpn.
  • mkdir /etc/openvpn/keys
  • Теперь необходимо поправить конфиги:

--Винда:

###remote 192.168.16.15
###secret key.txt

dev tap

ifconfig 172.16.0.2 255.255.255.0

###comp-lzo
tls-server
dh keys/dh1024.pem
ca keys/ca.crt
cert keys/win0.crt
key keys/win0.key

-- Linux

remote 192.168.16.197
dev tap
tls-client
ifconfig 172.168.0.1 255.255.255.0
dh dh1024.pem
ca ca.crt
cert roman.crt
key roman.key

Если при старте сервера на Windows возникнет ошибка:

system library:fopen:No such file or directory

Необходимо переместить каталог c:\Progam Files\OpenVPN\easy-rsa\keys в с:\keys и после этого модифицировать конфиг:

dev tap
ifconfig 172.16.0.2 255.255.255.0
tls-server
dh c:\\keys\\dh1024.pem
ca c:\\keys\\ca.crt
cert c:\\keys\\win0.crt
key c:\\keys\\win0.key

Теперь запустим сервер vpn из cmd под Windows с помощью следующей команды:

C:\Documents and Settings\Administrator>openvpn --config "c:\Program Files\OpenVPN\config\sample.ovpn"
Tue Jul 12 17:02:23 2011 us=612115 Current Parameter Settings:
Tue Jul 12 17:02:23 2011 us=612409   config = 'c:\Program Files\OpenVPN\config\sample.ovpn'
Tue Jul 12 17:02:23 2011 us=612634   mode = 0
Tue Jul 12 17:02:23 2011 us=612791   show_ciphers = DISABLED
Tue Jul 12 17:02:23 2011 us=612953   show_digests = DISABLED
Tue Jul 12 17:02:23 2011 us=613112   show_engines = DISABLED
Tue Jul 12 17:02:23 2011 us=613270   genkey = DISABLED
Tue Jul 12 17:02:23 2011 us=613427   key_pass_file = '[UNDEF]'
Tue Jul 12 17:02:23 2011 us=613591   show_tls_ciphers = DISABLED
Tue Jul 12 17:02:23 2011 us=613753   proto = 0
Tue Jul 12 17:02:23 2011 us=613910 NOTE: --mute triggered...
Tue Jul 12 17:02:23 2011 us=614111 178 variation(s) on previous 10 message(s) suppressed by --mute
Tue Jul 12 17:02:23 2011 us=614331 OpenVPN 2.0.9 Win32-MinGW [SSL] [LZO] built on Oct  1 2006
Tue Jul 12 17:02:23 2011 us=615260 IMPORTANT: OpenVPN's default port number is now 1194, based on an official port number assignment
.  OpenVPN 2.0-beta16 and earlier used 5000 as the default port.
Tue Jul 12 17:02:23 2011 us=615596 WARNING: --ping should normally be used with --ping-restart or --ping-exit
Tue Jul 12 17:02:23 2011 us=671943 Diffie-Hellman initialized with 1024 bit key
Tue Jul 12 17:02:23 2011 us=675391 Control Channel MTU parms [ L:1573 D:138 EF:38 EB:0 ET:0 EL:0 ]
Tue Jul 12 17:02:23 2011 us=680475 TAP-WIN32 device [Local Area Connection 4] opened: \\.\Global\{DDA59CFF-B7AE-4F0E-91DA-C111AF5139B
Tue Jul 12 17:02:23 2011 us=680823 TAP-Win32 Driver Version 8.4
Tue Jul 12 17:02:23 2011 us=681026 TAP-Win32 MTU=1500
Tue Jul 12 17:02:23 2011 us=681234 Notified TAP-Win32 driver to set a DHCP IP/netmask of 172.16.0.2/255.255.255.0 on interface {DDA59
E-4F0E-91DA-C111AF5139B5} [DHCP-serv: 172.16.0.0, lease-time: 31536000]
Tue Jul 12 17:02:23 2011 us=716919 Successful ARP Flush on interface [196612] {DDA59CFF-B7AE-4F0E-91DA-C111AF5139B5}
Tue Jul 12 17:02:23 2011 us=725976 Data Channel MTU parms [ L:1573 D:1450 EF:41 EB:4 ET:32 EL:0 ]
Tue Jul 12 17:02:23 2011 us=726302 Local Options String: 'V4,dev-type tap,link-mtu 1573,tun-mtu 1532,proto UDPv4,ifconfig 172.16.0.0
.255.0,cipher BF-CBC,auth SHA1,keysize 128,key-method 2,tls-server'
Tue Jul 12 17:02:23 2011 us=726626 Expected Remote Options String: 'V4,dev-type tap,link-mtu 1573,tun-mtu 1532,proto UDPv4,ifconfig 1
.0 255.255.255.0,cipher BF-CBC,auth SHA1,keysize 128,key-method 2,tls-client'
Tue Jul 12 17:02:23 2011 us=726987 Local Options hash (VER=V4): '79e31c21'
Tue Jul 12 17:02:23 2011 us=727192 Expected Remote Options hash (VER=V4): '5a258ee1'
Tue Jul 12 17:02:23 2011 us=727475 Socket Buffers: R=[8192->8192] S=[8192->8192]
Tue Jul 12 17:02:23 2011 us=727723 UDPv4 link local (bound): [undef]:1194
Tue Jul 12 17:02:23 2011 us=727898 UDPv4 link remote: [undef]

Затем на клиенте дадим команду:

sudo openvpn --config /etc/openvpn/sample.conf

И смотрим на продолжение вывода на сервере:

Tue Jul 12 17:05:23 2011 us=993139 TLS: Initial packet from 192.168.16.15:1194, sid=76cd5180 622a0d09
Tue Jul 12 17:05:24 2011 us=505011 VERIFY OK: depth=1, /C=UA/ST=Kiev/L=Kiev/O=TechExpert/OU=IT/CN=win0/emailAddress=otradnyi@mail.ru
Tue Jul 12 17:05:24 2011 us=506441 VERIFY OK: depth=0, /C=UA/ST=Kiev/O=TechExpert/OU=IT/CN=roman/emailAddress=otradnyi@mail.ru
Tue Jul 12 17:05:24 2011 us=567168 Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
Tue Jul 12 17:05:24 2011 us=567435 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Tue Jul 12 17:05:24 2011 us=567739 Data Channel Decrypt: Cipher 'BF-CBC' initialized with 128 bit key
Tue Jul 12 17:05:24 2011 us=567977 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Tue Jul 12 17:05:24 2011 us=569802 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 1024 bit RSA
Tue Jul 12 17:05:24 2011 us=570075 [roman] Peer Connection Initiated with 192.168.16.15:1194
Tue Jul 12 17:05:26 2011 us=153485 TEST ROUTES: 0/0 succeeded len=-1 ret=1 a=0 u/d=up
Tue Jul 12 17:05:26 2011 us=153796 Initialization Sequence Completed

И проверяем

ping 172.16.0.2 -c 4
PING 172.16.0.2 (172.16.0.2) 56(84) bytes of data.
64 bytes from 172.16.0.2: icmp_seq=1 ttl=128 time=8.91 ms
64 bytes from 172.16.0.2: icmp_seq=2 ttl=128 time=1.00 ms
64 bytes from 172.16.0.2: icmp_seq=3 ttl=128 time=1.23 ms
64 bytes from 172.16.0.2: icmp_seq=4 ttl=128 time=1.34 ms

[править] Создание сертификатов на Debian с использованием easy-rsa

ls -l /usr/share/doc/openvpn/examples/easy-rsa/
итого 80
drwxr-xr-x 2 root root 4096 2011-07-13 00:18 2.0
-rwxr-xr-x 1 root root  242 2011-07-13 13:06 build-ca
-rwxr-xr-x 1 root root  228 2011-07-13 13:06 build-dh
-rwxr-xr-x 1 root root  529 2011-07-13 13:06 build-inter
-rwxr-xr-x 1 root root  516 2011-07-13 13:06 build-key
-rwxr-xr-x 1 root root  424 2011-07-13 13:06 build-key-pass
-rwxr-xr-x 1 root root  695 2011-07-13 13:06 build-key-pkcs12
-rwxr-xr-x 1 root root  662 2011-07-13 13:06 build-key-server
-rwxr-xr-x 1 root root  466 2011-07-13 13:06 build-req
-rwxr-xr-x 1 root root  402 2011-07-13