Configurar OpenVPN em Ubuntu

Sidner

Power Member
Boas gente. Eu peguei num pc antigo que tinha em casa do meus pais e instalei-lhe o Ubuntu Server 12.04. Queria, agora, criar uma VPN em casa, usando para isso o OpenVPN. Ora acontece que correu tudo bem do lado do servidor (acho), que está em modo bridge, mas quando tento correr no cliente, ele dá-me erro:
Código:
Mon May 28 17:32:20 2012 OpenVPN 2.1.3 x86_64-pc-linux-gnu [SSL] [LZO2] [EPOLL] [PKCS11] [MH] [PF_INET6] [eurephia] built on Mar 11 2011
Mon May 28 17:32:20 2012 NOTE: OpenVPN 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables
Mon May 28 17:32:20 2012 Cannot load certificate file HomeServer.crt: error:0906D06C:PEM routines:PEM_read_bio:no start line: error:140AD009:SSL routines:SSL_CTX_use_certificate_file:PEM lib
Mon May 28 17:32:20 2012 Exiting

O meu server.conf:
Código:
# Which local IP address should OpenVPN
# listen on? (optional)
local 192.168.1.92


# 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 tap0
;dev tun
up "/etc/openvpn/up.sh br0"
down "/etc/openvpn/down.sh br0"
ca ca.crt
cert server.crt
key server.key

dh dh1024.pem
server-bridge 192.168.1.92 255.255.255.0 192.168.1.92.100 192.168.1.92.105 //tenho aqui algumas dúvidas se é assim

client.conf:
Código:
# 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 tap0
;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 sidnerhomeserver.no-ip.org 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 nogroup


# 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 HomeServer.crt
key HomeServer.key

Só para dizer ainda que estou a tentar ligar através de wireless, não sei se isso influencia alguma coisa ou não...

Obrigado pela ajuda, é que não encontro nada na net sobre isto (excepto para por a path toda até aos ficheiro, o que já experimentei).
 
Eu desconfio que seja pelo certificado do cliente (ou seja o que tal HomeServer.crt) estar em branco... Tentei converter para ascii e continua a dar o mesmo erro.
 
O ficheiro foi criado usando ./pkitool sidnervpn

Dá-me este erro:

failed to update database
TXT_DB error number 2


A chave ele gera bem, é o .crt que parece estar sempre em branco... =\
 
Última edição:
Boas, eu escrevi um pdf sobre instalação de openvpn em linux(é muito fácil de instalar, mas está em inglês). Se quiseres posso enviar o link por pm.
 
Ponto de situação:

homeserver.conf:
Código:
port 1194
proto udp
dev tun0
ca keys/homeserver/ca.crt
cert keys/homeserver/homeserver.crt
key keys/homeserver/homeserver.key
dh keys/homeserver/dh1024.pem
server 10.8.0.0 255.255.255.0
crl-verify keys/homeserver/crl.pem
#tls-auth servers/homeserver/ta.key 0
cipher AES-256-CBC
user nobody
group nogroup
status servers/homeserver/logs/openvpn-status.log
log-append servers/homeserver/logs/openvpn.log
verb 2
mute 20
max-clients 15
management 127.0.0.1 6666
keepalive 10 120
client-config-dir /etc/openvpn/servers/homeserver/ccd
tls-server
duplicate-cn
comp-lzo
persist-key
persist-tun
ccd-exclusive
push "redirect-gateway def1"
push "dhcp-option DNS 8.8.8.8"
script-security 2
auth-user-pass-verify /etc/openvpn/verify-user.sh via-file
tmp-dir /tmp


sidnervpn.conf
Código:
client
proto udp
dev tun
ca ca.crt
dh dh1024.pem
cert sidnervpn.crt
key sidnervpn.key
remote sidnerhomeserver.no-ip.org 1194
tls-auth ta.key 1
cipher AES-256-CBC
user nobody
group nogroup
verb 2
mute 20
keepalive 10 120
comp-lzo
persist-key
persist-tun
float
resolv-retry infinite
nobind
auth-user-pass


Log enquanto não me estou a ligar, aparentemente uma vez a cada minuto:
Código:
Thu May 31 15:31:21 2012 193.136.33.133:55721 Re-using SSL/TLS context
Thu May 31 15:31:21 2012 193.136.33.133:55721 LZO compression initialized
Thu May 31 15:31:21 2012 193.136.33.133:55721 Control Channel MTU parms [ L:1558 D:166 EF:66 EB:0 ET:0 EL:0 ]
Thu May 31 15:31:21 2012 193.136.33.133:55721 Data Channel MTU parms [ L:1558 D:1450 EF:58 EB:135 ET:0 EL:0 AF:3/1 ]
Thu May 31 15:31:21 2012 193.136.33.133:55721 Local Options hash (VER=V4): '162b04de'
Thu May 31 15:31:21 2012 193.136.33.133:55721 Expected Remote Options hash (VER=V4): '9e7066d2'
Thu May 31 15:31:24 2012 193.136.33.133:55721 CRL CHECK OK: /C=PT/ST=DL/L=Porto/O=Sidner_Home_Server/[email protected]
Thu May 31 15:31:24 2012 193.136.33.133:55721 VERIFY OK: depth=1, /C=PT/ST=DL/L=Porto/O=Sidner_Home_Server/[email protected]
Thu May 31 15:31:24 2012 193.136.33.133:55721 CRL CHECK OK: /C=PT/ST=DL/L=Porto/O=Sidner_Home_Server/OU=Office/CN=sidnervpn/[email protected]
Thu May 31 15:31:24 2012 193.136.33.133:55721 VERIFY OK: depth=0, /C=PT/ST=DL/L=Porto/O=Sidner_Home_Server/OU=Office/CN=sidnervpn/[email protected]
Thu May 31 15:31:25 2012 193.136.33.133:55721 TLS Error: Auth Username/Password was not provided by peer
Thu May 31 15:31:25 2012 193.136.33.133:55721 TLS Error: TLS handshake failed

Log quando me tento ligar:
Código:
Thu May 31 15:33:02 2012 Authenticate/Decrypt packet error: packet HMAC authentication failedThu May 31 15:33:02 2012 TLS Error: incoming packet authentication failed from [AF_INET]193.136.33.133:54114
Thu May 31 15:33:04 2012 Authenticate/Decrypt packet error: packet HMAC authentication failed
Thu May 31 15:33:04 2012 TLS Error: incoming packet authentication failed from [AF_INET]193.136.33.133:54114
Thu May 31 15:33:08 2012 Authenticate/Decrypt packet error: packet HMAC authentication failed
Thu May 31 15:33:08 2012 TLS Error: incoming packet authentication failed from [AF_INET]193.136.33.133:54114
Thu May 31 15:33:16 2012 Authenticate/Decrypt packet error: packet HMAC authentication failed
Thu May 31 15:33:16 2012 TLS Error: incoming packet authentication failed from [AF_INET]193.136.33.133:54114

Depois de tentar, dá falha por timeout. Estou a usar o pluggin openvpn para o network-manager e a usar este guia, do barricas (obrigado again!): http://dl.dropbox.com/u/20393685/OpenVPN-PDF/CreatePersonalOpenVPNServer.pdf
 
Eu nunca instalei um servidor de VPN, mas já tive problemas a ligar-me com o network-manager. Experimenta na linha de comandos e vê os logs também do lado do cliente.
 
Novidades! E das boas! Após algumas chatices e de procurar mais alguns bugs, consegui!

Código:
root@sidner-N53Jq:/etc/openvpn# openvpn sidnervpn.ovpn
Fri Jun  1 19:48:29 2012 OpenVPN 2.1.3 x86_64-pc-linux-gnu [SSL] [LZO2] [EPOLL] [PKCS11] [MH] [PF_INET6] [eurephia] built on Mar 11 2011
Fri Jun  1 19:48:29 2012 WARNING: No server certificate verification method has been enabled.  See http://openvpn.net/howto.html#mitm for more info.
Fri Jun  1 19:48:29 2012 NOTE: OpenVPN 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables
Fri Jun  1 19:48:29 2012 WARNING: file 'sidnervpn.key' is group or others accessible
Fri Jun  1 19:48:29 2012 /usr/bin/openssl-vulnkey -q -b 2048 -m <modulus omitted>
Fri Jun  1 19:48:29 2012 WARNING: file 'ta.key' is group or others accessible
Fri Jun  1 19:48:29 2012 Control Channel Authentication: using 'ta.key' as a OpenVPN static key file
Fri Jun  1 19:48:29 2012 Outgoing Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri Jun  1 19:48:29 2012 Incoming Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri Jun  1 19:48:29 2012 LZO compression initialized
Fri Jun  1 19:48:29 2012 Control Channel MTU parms [ L:1558 D:166 EF:66 EB:0 ET:0 EL:0 ]
Fri Jun  1 19:48:29 2012 Data Channel MTU parms [ L:1558 D:1450 EF:58 EB:135 ET:0 EL:0 AF:3/1 ]
Fri Jun  1 19:48:29 2012 Local Options hash (VER=V4): '9e7066d2'
Fri Jun  1 19:48:29 2012 Expected Remote Options hash (VER=V4): '162b04de'
Fri Jun  1 19:48:29 2012 UDPv4 link local: [undef]
Fri Jun  1 19:48:29 2012 UDPv4 link remote: [AF_INET]144.64.6.113:1194
Fri Jun  1 19:48:29 2012 VERIFY OK: depth=1, /C=PT/ST=DL/L=Porto/O=Sidner_Home_Server/[email protected]
Fri Jun  1 19:48:29 2012 VERIFY OK: depth=0, /C=PT/ST=DL/L=Porto/O=Sidner_Home_Server/OU=Office/CN=homeserver/[email protected]
Fri Jun  1 19:48:29 2012 Data Channel Encrypt: Cipher 'AES-256-CBC' initialized with 256 bit key
Fri Jun  1 19:48:29 2012 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri Jun  1 19:48:29 2012 Data Channel Decrypt: Cipher 'AES-256-CBC' initialized with 256 bit key
Fri Jun  1 19:48:29 2012 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri Jun  1 19:48:29 2012 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 2048 bit RSA
Fri Jun  1 19:48:29 2012 [homeserver] Peer Connection Initiated with [AF_INET]144.64.6.113:1194
Fri Jun  1 19:48:31 2012 TUN/TAP device tun0 opened
Fri Jun  1 19:48:31 2012 /sbin/ifconfig tun0 10.8.0.6 pointopoint 10.8.0.5 mtu 1500
Fri Jun  1 19:48:31 2012 WARNING: potential route subnet conflict between local LAN [10.8.0.0/255.255.255.0] and remote VPN [10.8.0.1/255.255.255.255]
Fri Jun  1 19:48:31 2012 Initialization Sequence Completed



Segui este guia: http://www.frontiernet.net/~beakmyn/vpn%20howto/Complete%20Home%20VPN%20Howto%20Guide.html#sdfootnote1sym

V
ou agora tentar com o pluggin do network-manager.
 
Cool. Eu nunca percebi por que conseguia ligar-me na linha de comandos e não com o network manager, mas imaginei que fosse alguma coisa na configuração que o network manager não estava a fazer da mesma maneira. Como funcionava não cheguei a investigar.
 
Cool. Eu nunca percebi por que conseguia ligar-me na linha de comandos e não com o network manager, mas imaginei que fosse alguma coisa na configuração que o network manager não estava a fazer da mesma maneira. Como funcionava não cheguei a investigar.

Sabes como posso automatizar isto? Sem ser um simples bash script que me obrigue a ter um terminal aberto...
 
Do lado do cliente? Eu apenas instalei o pacote openvpn, copiei o ficheiro xxx.conf que me deram no emprego, com a configuração específica deles, para /etc/openvpn e para me ligar corro /etc/init.d/openvpn start

Também tive de desativar o openvpn no runlevel 2, para não tentar ligar cada vez que faço boot, e uso o resolvconf para atualizar automaticamente as definições de DNS. Não sei como te estás a ligar, mas podes tentar configurar de maneira a poderes usar o init script do openvpn, e se isso não resultar podes experimentar correr o comando que estás a usar com um & no fim para correr em background.
 
Do lado do cliente? Eu apenas instalei o pacote openvpn, copiei o ficheiro xxx.conf que me deram no emprego, com a configuração específica deles, para /etc/openvpn e para me ligar corro /etc/init.d/openvpn start

Também tive de desativar o openvpn no runlevel 2, para não tentar ligar cada vez que faço boot, e uso o resolvconf para atualizar automaticamente as definições de DNS. Não sei como te estás a ligar, mas podes tentar configurar de maneira a poderes usar o init script do openvpn, e se isso não resultar podes experimentar correr o comando que estás a usar com um & no fim para correr em background.

O comando que eu uso é openvpn sidnervpn.ovpn como root...mais nada. :P
 
Experimenta:

Código:
openvpn sidnervpn.ovpn --daemon

Não sei se esse sidnervpn.ovpn é equivalente ao meu ficheiro de configuração. Para testar isso podes copiar o ficheiro para /etc/openvpn (talvez tenhas de mudar a extensão para .conf) e correr o /etc/init.d/openvpn start. Mas se o modo daemon que sugeri em cima funcionar vai dar quase ao mesmo.
 
Ora bem, testei a openvpn aqui na FEUP e ele liga bem, mas parece estar com problemas de DNS, visto que não consegue resolver nomes, só ips... Ou seja faço ping a 8.8.8.8 e dá, mas ping a www.google.com não dá.

Como posso resolver isto? Alguém sabe?
 
Back
Topo