Texto de documentación para la creación de certificados de seguridad SSL con OpenSSL y el uso de conexiones web seguras. El texto incluye la configuración necesaria para poner a funcionar un servidor virtual HTTPS en Apache2.



© 2011 Manuel Méndez - Manuko
Documento bajo Licencia de Documentación Libre GNU/FDL

Última revisión: 20110212-15:18

Certificados SSL

Para poder establecer comunicaciones web seguras por HTTPS, o realizar conexiones seguras de correo con SSL o TLS por IMAP, utilizaremos certificados de seguridad con OpenSSL.

En este texto explicaremos como crear certificados de seguridad con OpenSSL y, además, configurar Apache2 para poner a funcionar un servidor virtual que responda a conexiones HTTPS.

Indice

Instalar OpenSSL

Debian/Ubuntu

Será necesario instalar el paquete openssl con apt-get:

root@localhost:~# apt-get install openssl

Con eso, si todo va bien, ya tendremos instalado OpenSSL.

Red Hat/CentOS

En Red Hat será necesario utilizar yum para instalar el paquete openssl:

[root@localhost ~]# yum install openssl

Con eso debería bastar.

Volver al indice

Cómo crear certificados auto-firmados

Los comandos necesarios para generar certificados autofirmados son los siguientes:
Ahí va...

root@localhost:~/certs# openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
.................++++++
.....................++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:
root@localhost:~/certs# cp server.key server.key.passphrase
root@localhost:~/certs# openssl rsa -in server.key.passphrase -out server.key
Enter pass phrase for server.key.passphrase:
writing RSA key
root@localhost:~/certs# openssl req -new -x509 -nodes -sha1 -days 365
/-key server.key -out server.crt
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]:ES
State or Province Name (full name) [Some-State]:Barcelona
Locality Name (eg, city) []:Barcelona
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Yomismo
Organizational Unit Name (eg, section) []:Yomismo2
Common Name (eg, YOUR name) []:Manuko
Email Address []:manuko@222.lll

Y ya está, ya tenemos un certificado autofirmado. Si quisieramos utilizar la clave para enviar el certificado a firmar a una entidad certificadora, deberíamos sustituir el último paso por lo siguiente:

root@localhost:~/certs# openssl req -new -key server.key -out server.csr

Y con ese csr ya podríamos solicitar la certificación para nuestro dominio.

Volver al indice

Configurar HTTPS en Apache2

Instalar y habilitar mod_ssl

Hay que habilitar el modulo SSL de Apache2, instalandolo en primer lugar. En Red Hat/CentOS, lo haremos con yum:

[root@localhost ~]# yum install mod_ssl

En Debian/Ubuntu, el mod_ssl viene incluido en Apache2. Simplemente tendremos que habilitarlo. Para habilitar el módulo ssl, podemos utilizar el comando a2enmod ssl o bien modificando la configuración de Apache2 para añadir la directiva LoadModule oportuna.

Por último, tendremos que incluir estas directivas dentro del código del servidor virtual de Apache que se encargue de HTTPS:

SSLEngine on
    SSLCertificateFile    /etc/apache2/ssl.crt/server.crt
    SSLCertificateKeyFile /etc/apache2/ssl.crt/server.key

Volver al indice

Ejemplo de servidor virtual HTTPS

Listen 80 443

NameVirtualHost aqui-mi-ip-publica:443
 
 <VirtualHost aqui-mi-ip-publica:443>
    ServerAdmin webmaster@https.ejemplo.org
    DocumentRoot /var/www/virtuals/https.ejemplo.org
    ServerName https.ejemplo.org
    <Directory /var/www/virtuals/https.ejemplo.org>
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from All
    </Directory>

    SSLEngine on
    SSLCertificateFile    cert/server.crt
    SSLCertificateKeyFile cert/server.key
    ErrorLog logs/https.ejemplo.org_ssl-error_log
    CustomLog logs/https.ejemplo.org_ssl-access_log common
</VirtualHost>

Volver al indice



© 2011 Manuel Méndez - Manuko
Documento bajo Licencia de Documentación Libre GNU/FDL

Última revisión: 20110212-15:18