Gerar um perfil OpenVPN para o usuário cliente importar

33

Existe alguma documentação ou recurso descrevendo como gerar e hospedar um perfil para um cliente OpenVPN para importar? O ideal seria que meus usuários não precisassem buscar separadamente um arquivo .zip do .ovpn + certs, extraí-lo para o diretório correto, ajustar seus .ovpn, etc.

    
por Yang 01.03.2013 / 23:03

4 respostas

35

Aparentemente desde o OpenVPN 2.1, uma configuração em linha foi suportada. Permitindo que você localize seus certificados e todas as chaves em um único arquivo de configuração. Mas a documentação sobre como criar este arquivo de configuração não foi adicionada até a versão recente do 2.3.

Veja a seção INLINE FILE SUPPORT de a página de manual do OpenVPN para mais informações.

client
proto udp
remote openvpnserver.example.com
port 1194
dev tun
nobind

key-direction 1

<ca>
-----BEGIN CERTIFICATE-----
# insert base64 blob from ca.crt
-----END CERTIFICATE-----
</ca>

<cert>
-----BEGIN CERTIFICATE-----
# insert base64 blob from client1.crt
-----END CERTIFICATE-----
</cert>

<key>
-----BEGIN PRIVATE KEY-----
# insert base64 blob from client1.key
-----END PRIVATE KEY-----
</key>

<tls-auth>
-----BEGIN OpenVPN Static key V1-----
# insert ta.key
-----END OpenVPN Static key V1-----
</tls-auth>

Os documentos para o arquivo de configuração são os mesmos que os documentos para as opções de linha de comando:

OpenVPN allows any option to be placed either on the command line or in a configuration file. Though all command line options are preceded by a double-leading-dash ("--"), this prefix can be removed when an option is placed in a configuration file.

    
por 02.03.2013 / 01:13
6

Do OpenVPN 2.3 página man (É suportado desde 2.1rc-alguma coisa):

OpenVPN allows including files in the main configuration for the --ca, --cert, --dh, --extra-certs, --key, --pkcs12, --secret and --tls-auth options.

Each inline file started by the line <option> and ended by the line </option>.

Here is an example of an inline file usage

<cert>
-----BEGIN CERTIFICATE-----
[...]
-----END CERTIFICATE-----
</cert>

When using the inline file feature with --pkcs12 the inline file has to be base64 encoded. Encoding of a .p12 file into base64 can be done for example with OpenSSL by running openssl base64 -in input.p12

Observe também a opção key-direction :

--key-direction
Alternative way of specifying the optional direction parameter for the --tls-auth and --secret options. Useful when using inline files (See section on inline files).

    
por 01.10.2013 / 17:22
1

Isso foi testado com o OpenVPN 2.3.4 Debian 8.9 Server com clientes Win7.

Passo 1. Crie um arquivo contendo seus padrões (eu o chamo de inline_client.conf) todas as configurações devem corresponder aos seus valores server.conf

client
dev tun
proto udp
remote yourserver.xyz 1194
resolv-retry infinite
nobind
persist-key
persist-tun
mute-replay-warnings
remote-cert-tls server
cipher AES-256-CBC
comp-lzo
verb 3
;mute 20

ca [inline]
cert [inline]
key [inline]
tls-auth [inline] 1

Etapa 2. Crie o seguinte script, ajuste os caminhos conforme necessário e chmod ug+x MakeInline.sh

#!/bin/bash

# Default Variable Declarations

DEFAULT="inline_client.conf"
FILEEXT=".ovpn"
CRT=".crt"
KEY=".key"
CA="ca.crt"
TA="ta.key"
kPath="./keys/"


#Ask for a Client name
echo "Please enter an existing Client Name:"
read NAME

echo "Please enter an Name for the output file"
read ovpnName

#1st Verify that client's Public Key Exists
if [ ! -f $kPath$NAME$CRT ]; then
   echo "[ERROR]: Client Public Key Certificate not found: $kPath$NAME$CRT"
   exit
fi
echo "Client's cert found: $kPath$NAME$CRT"

#Then, verify that there is a private key for that client
if [ ! -f $kPath$NAME$KEY ]; then
   echo "[ERROR]: Client 3des Private Key not found: $kPath$NAME$KEY"
   exit
fi
echo "Client's Private Key found: $kPath$NAME$KEY"

#Confirm the CA public key exists
if [ ! -f $kPath$CA ]; then
   echo "[ERROR]: CA Public Key not found: $kPath$CA"
   exit
fi
echo "CA public Key found: $kPath$CA"

#Confirm the tls-auth ta key file exists
if [ ! -f $kPath$TA ]; then
   echo "[ERROR]: tls-auth Key not found: $kPath$TA"
   exit
fi
echo "tls-auth Private Key found: $kPath$TA"

#Ready to make a new .opvn file - Start by populating with the

cat $DEFAULT > $ovpnName$FILEEXT

#Now, append the CA Public Cert
echo "<ca>" >> $ovpnName$FILEEXT
cat $kPath$CA | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' >> $ovpnName$FILEEXT
echo "</ca>" >> $ovpnName$FILEEXT

#Next append the client Public Cert
echo "<cert>" >> $ovpnName$FILEEXT
cat $kPath$NAME$CRT | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' >> $ovpnName$FILEEXT
echo "</cert>" >> $ovpnName$FILEEXT

#Then, append the client Private Key
echo "<key>" >> $ovpnName$FILEEXT
cat $kPath$NAME$KEY >> $ovpnName$FILEEXT
echo "</key>" >> $ovpnName$FILEEXT

#Finally, append the TA Private Key
echo "<tls-auth>" >> $ovpnName$FILEEXT
cat $kPath$TA >> $ovpnName$FILEEXT
echo "</tls-auth>" >> $ovpnName$FILEEXT

echo "Done! $ovpnName$FILEEXT Successfully Created."

#Script written by Eric Jodoin
#Update by Eric Maasdorp 2017-12-16

Etapa 3. Execute MakeInline.sh para solicitar o nome de um cliente que você precisava ter criado com build-key or build-key-pass . Ele pedirá um nome para o arquivo ovpn. Meu padrão é ServerToConnectTo.ClientName que irá produzir ServerToConnectTo.ClientName.ovpn

Observação: se você usou build-key em vez de build-key-pass , qualquer um que obtiver o *.ovpn terá acesso ao seu servidor sem uma senha!

    
por 16.12.2017 / 11:55
0

Este script Python pode ser executado no servidor para gerar as chaves do cliente e um perfil. Eu o inlinei, mas não é minha criação e é longa e pode ser atualizada periodicamente, e há garfos que são tão possíveis de serem pesquisados na web para futuros viajantes na web. Se o link não funcionar, tente pesquisar "openvpn_gen.py".

link

    
por 31.05.2017 / 22:54