quinta-feira, 25 de agosto de 2011

Configurar SSL - Ubuntu - OCS Inventory NG SERVER

INTRODUÇÃO

Este tutorial permite o uso de conexão segura (https) no seu servidor Apache2 usando o módulo SSL, criando a autoridade certificadora, as chaves pública e privada e configurando o apache para usá-las.

CRIANDO UMA AUTORIDADE CERTIFICADORA (CA)

Para assinar o certificado do seu servidor temos que criar uma CA. Para isto geramos uma chave e um certificado auto-assinado.

1. Gerando chave privada

root@ocsserver:/etc/ssl1# openssl genrsa -des3 -out cacert.key 2048
Generating RSA private key, 2048 bit long modulus
.......+++
...........................................+++
e is 65537 (0x10001)
Enter pass phrase for cacert.key:
Verifying - Enter pass phrase for cacert.key:

2. Gerando seu certificado auto-assinado válido por 10 anos

root@ocsserver:/etc/ssl1# openssl req -new -x509 -days 3650 -key cacert.key -out cacert.pem
Enter pass phrase for cacert.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) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:
Email Address []:

CRIANDO A CHAVE E O CERTIFICADO DO SEU SERVIDOR

3. Criando a chave do seu servidor

root@ocsserver:/etc/ssl1# openssl genrsa -des3 -out server.dominio.br.key 1024
Generating RSA private key, 1024 bit long modulus
...................................++++++
.............................................++++++
e is 65537 (0x10001)
Enter pass phrase for server.dominio.br.key:
Verifying - Enter pass phrase for server.dominio.br.key:

4. Gerando certificado do seu servidor

Importante: o Common Name deve ser igual ao nome do seu servidor virtual

root@ocsserver:/etc/ssl1# openssl req -new -key server.dominio.br.key -out server.dominio.br.csr
Enter pass phrase for server.dominio.br.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) [AU]:BR
State or Province Name (full name) [Some-State]:Minas Gerais
Locality Name (eg, city) []:Belo Horizonte
Organization Name (eg, company) [Internet Widgits Pty Ltd]:UFMG
Organizational Unit Name (eg, section) []:STI
Common Name (eg, YOUR name) []:server.dominio.br
Email Address []:slassis@ufmg.br

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

ASSINATURA DO CERTIFICADO SERVIDOR PELA CA

5. Assinando o certificado do seu servidor pela CA pelo período de 10 anos

root@ocsserver:/etc/ssl1# openssl x509 -req -in server.dominio.br.csr -out server.dominio.br.crt -sha1 -CA cacert.pem -CAkey cacert.key -CAcreateserial -days 3650
Signature ok
subject=/C=BR/ST=Minas Gerais/L=Belo Horizonte/O=UFMG/OU=STI/CN=server.dominio.br/emailAddress=slassis@ufmg.br
Getting CA Private Key
Enter pass phrase for cacert.key:

CRIANDO CHAVE INSEGURA DO SERVIDOR

6. A criação da chave insegura do seu servidor é utilizada para iniciar o Apache, permitindo que não seja exigido uma senha a cada reinicialização do servidor.

root@ocsserver:/etc/ssl1# openssl rsa -in server.dominio.br.key -out server.dominio.br.key.insecure
Enter pass phrase for server.dominio.br.key:
writing RSA key

CONFIGURAÇÃO DO APACHE

7. Crie o diretório ssl

root@ocsserver:/etc/ssl1# cd /etc/apache2
root@ocsserver:/etc/apache2# mkdir ssl

8. Altere o proprietário da pasta e a permissão

root@ocsserver:/etc/apache2#sudo chown root.root ssl
root@ocsserver:/etc/apache2#chmod 400 ssl

9. Copie os arquivos para o diretório /etc/apache2/ssl

root@ocsserver:/etc/ssl1# sudo cp cacert.key /etc/apache2/ssl
root@ocsserver:/etc/ssl1# sudo cp cacert.pem /etc/apache2/ssl
root@ocsserver:/etc/ssl1# sudo cp cacert.srl /etc/apache2/ssl/
root@ocsserver:/etc/ssl1# sudo cp server.dominio.br.crt /etc/apache2/ssl/
root@ocsserver:/etc/ssl1# sudo cp server.dominio.br.key.insecure /etc/apache2/ssl/

10. Acrescente no arquivo /etc/apache2/sites-available/default-ssl as seguintes linhas:

SSLCertificateFile /etc/apache2/ssl/server.dominio.br.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.dominio.br.key.insecure
SSLCACertificateFile /etc/apache2/ssl/cacert.pem

Exemplo de arquivo default-ssl:

<VirtualHost *:443>
ServerAdmin webmaster@localhost

SSLEngine On
SSLCertificateFile /etc/apache2/ssl/ocsserver.demec.ufmg.br.crt
SSLCertificateKeyFile /etc/apache2/ssl/ocsserver.demec.ufmg.br.key.insecure
SSLCACertificateFile /etc/apache2/ssl/cacert.pem

DocumentRoot /var/www/snmp
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/snmp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<directory>
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>


COPIANDO ARQUIVO DE CERTIFICADO NO DIRETÓRIO DO AGENTE

11. Faça uma cópia dos arquivos cacert.pem e server.dominio.br.crt tendo por base seu o diretório de configuração do seu servidor e o diretório basevardir especificado no arquivo /etc/ocsinventory-agent/ocsinventory-agent.cfg

Exemplo: Caso o endereço do servidor seja http://server.dominio.br/ocsinventory e o seu basevardir esteja configurado como /var/lib/ocsinventory-agent:

root@ocsserver:/etc/ssl1# sudo cp cacert.pem /var/lib/ocsinventory-agent/http:__server.dominio.br_ocsinventory
root@ocsserver:/etc/ssl1# sudo cp server.dominio.br.crt /var/lib/ocsinventory-agent/http:__server.dominio.br_ocsinventory

12. Finalmente não esqueça de reiniciar o Apache para que as modificações surtam efeito

root@ocsserver:/etc/ssl1# sudo /etc/init.d/apache2 restart
* Restarting web server apache2 ... waiting [ OK ]






4 comentários:

  1. Sergio muito bom seu tutorial, mas será que vc poderia me ajudar mais um pouco?

    Já fiz todos os procedimentos com exito, rodei o agente no proprio servidor e já fiz de tudo só que quando vou no OCS Redes SNMP não me mostra nada. (Inclusive já estou navegando com OCS em HTTPS).

    Aguardo sua ajuda!

    ResponderExcluir
  2. Ola Sergio, tenho uma dúvida quanto a utilização de SSL. Para que utilizar SSL no OCS ?

    Por exemplo se eu hospedar meu servidor OCS NG em um computador na nuvem e fizer inventario de varias empresas, deveria usar SSL ? ele ira criptografar toda a comunicação entre agente e servidor ?

    ResponderExcluir
  3. Ola Sergio, tenho uma dúvida quanto a utilização de SSL. Para que utilizar SSL no OCS ?

    Por exemplo se eu hospedar meu servidor OCS NG em um computador na nuvem e fizer inventario de varias empresas, deveria usar SSL ? ele ira criptografar toda a comunicação entre agente e servidor ?

    ResponderExcluir
  4. Ola Sergio, tenho uma dúvida quanto a utilização de SSL. Para que utilizar SSL no OCS ?

    Por exemplo se eu hospedar meu servidor OCS NG em um computador na nuvem e fizer inventario de varias empresas, deveria usar SSL ? ele ira criptografar toda a comunicação entre agente e servidor ?

    ResponderExcluir