Professional Documents
Culture Documents
Aunque hay soluciones parciales, la solución definitiva, como siempre, pasa por usar
HTTPS o, lo que es lo mismo, HTTP sobre SSL. Desde la versión 2.6, WordPress
permite usar SSL fácilmente para el panel de administrador. Así que me puse
a hacer pruebas para configurar SSL en mi servidor web.
Sin embargo, ocurre una cosa muy interesante con el protocolo SSL cuando se usa
con HTTP: que no se pueden servir fácilmente múltiples sitios virtuales encriptados
con SSL desde una misma IP.
Sin embargo, cuando se usa SSL, la negociación entre los extremos y la encriptación
ocurre en una capa inferior, antes de que éstos comiencen a usar el protocolo HTTP.
Por ello, no es trivial configurar diferentes certificados para diferentes sitios web
virtuales. En la configuración típica, sólo podremos usar un certificado compartido
para todas las páginas que se sirvan por HTTPS desde un único servidor web, a
menos que usemos una IP diferente para cada sitio.
Para este inconveniente hay workarounds (TLS Support for name-based virtual
servers) y soluciones definitivas con el Server Name Indication (SNI). Apache 2.2 no
soporta SNI, pero el módulo de Apache mod_gnutls (incluido en Debian Lenny:
libapache2-mod-gnutls) nos permitiría usarlo. Desafortunadamente, aunque
Firefox (>=2), Safari, Chrome y Opera soportan esta extensión del protocolo, Internet
Explorer 6 e Internet Explorer 7 para Windows XP no soportan SNI, por lo que no
podemos usarla de momento por motivos obvios.
Por todos estos motivos, descubrí que con los hostings profesionales no resulta fácil
o, mejor dicho, barato, tener un servidor SSL. Es lo que me va a impedir a mí poder
configurar SSL para el panel de administración de LHYLE.
Sin embargo, podemos seguir estudiando cómo podríamos hacerlo si lo que tenemos
es un Hosting Casero o si le hemos contratado un servidor dedicado a nuestro
proveedor de hosting.
NameVirtualHost *
<VirtualHost *>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/
...
</VirtualHost>
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
# SSL name based virtual hosts are not yet supported, therefore no
# NameVirtualHost statement here
Listen 443
</IfModule>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/
...
</VirtualHost>
De modo que ahora hay una nueva configuración de sitio disponible, en la ruta
/etc/apache2/sites-available/default-ssl:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/
...
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
BrowserMatch ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
</VirtualHost>
</IfModule>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
Aunque recién instalado, el Apache 2.2 de Debian Lenny está preparado para servir
contenido HTTPS, aún hay que habilitar el sitio y el módulo de SSL.
# a2enmod ssl
Enabling module ssl.
See /usr/share/doc/apache2.2-common/README.Debian.gz on how to configure SSL
and create self-signed certificates.
Run '/etc/init.d/apache2 restart' to activate new configuration!
# a2ensite default-ssl
Enabling site default-ssl.
Run '/etc/init.d/apache2 reload' to activate new configuration!
# /etc/init.d/apache2 restart
Ahora ya podríamos conectarnos por HTTPS a https://subdominio.dominio.tld. Sin
embargo, al estar usando el certificado “de aceite de serpiente”, lo que nos
encontraremos será con que el navegador nos da una o dos advertencias sobre el
dominio. Una segura porque el certificado no está firmado por una autoridad de
confianza y tal vez otra porque el dominio, hostname o IP que estamos usando para
acceder al sitio no coincida con el que indica el certificado.
SSLCertificateFile /etc/ssl/certs/desarrollo.vicente-navarro.com_self.crt
SSLCertificateKeyFile /etc/ssl/private/desarrollo.vicente-
navarro.com_self.key
Veamos cómo hacerlo con el script CA.pl de OpenSSL, que en Debian está bajo
/usr/lib/ssl/misc/
# ./CA.pl -newca
CA certificate filename (or enter to create)
¡¡Ya somos Autoridad Certificadora!! Ahora vamos a generar una clave privada y
una petición de certificado para el sitio web desarrollo.vicente-navarro.com
#./CA.pl -newreq
Generating a 1024 bit RSA private key
.................++++++
.........................++++++
writing new private key to 'newkey.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
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]:Spain
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Desarrollo de Lo hice
y lo entendi
Organizational Unit Name (eg, section) []:El blog de Vicente Navarro
Common Name (eg, YOUR name) []:desarrollo.vicente-navarro.com
Email Address []:correodesarrollo@vicente-navarro.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Request is in newreq.pem, private key is in newkey.pem
Ahora, con la clave privada del certificado raíz, firmamos la petición de certificado,
para que éste ya esté completo:
# ./CA.pl -sign
Using configuration from /usr/lib/ssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number:
bf:8a:98:f2:48:c0:84:69
Validity
Not Before: Feb 18 19:06:09 2009 GMT
Not After : Feb 18 19:06:09 2010 GMT
Subject:
countryName = ES
stateOrProvinceName = Spain
organizationName = Desarrollo de Lo hice y lo entendi
organizationalUnitName = El blog de Vicente Navarro
commonName = desarrollo.vicente-navarro.com
emailAddress = correodesarrollo@vicente-navarro.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
20:7C:02:85:3D:52:2B:88:57:1E:A9:1B:F1:92:CF:70:74:78:00:48
X509v3 Authority Key Identifier:
keyid:BD:85:EB:33:B0:0B:06:74:9A:F3:AB:18:95:D5:4B:CB:76:B8:EA:83
Los nuevos ficheros y directorios que encontraremos en este directorio tras estos tres
comandos (“CA.pl -newca“, “CA.pl -newreq” y “CA.pl -sign“) son:
# ls -la
total 52
drwxr-xr-x 3 root root 4096 2009-02-18 20:06 ./
drwxr-xr-x 4 root root 4096 2009-01-13 18:25 ../
-rwxr-xr-x 1 root root 5875 2009-01-07 19:04 CA.pl*
-rwxr-xr-x 1 root root 3784 2009-01-07 19:04 CA.sh*
-rwxr-xr-x 1 root root 119 2009-01-07 19:04 c_hash*
-rwxr-xr-x 1 root root 152 2009-01-07 19:04 c_info*
-rwxr-xr-x 1 root root 112 2009-01-07 19:04 c_issuer*
-rwxr-xr-x 1 root root 110 2009-01-07 19:04 c_name*
drwxr-xr-x 6 root root 4096 2009-02-18 20:06 demoCA/ ← Directorio que contiene el
certificado raíz y su clave privada (demoCA/cacert.pem es el certificado y
demoCA/private/cakey.pem es la clave privada)
-rw-r--r-- 1 root root 3532 2009-02-18 20:06 newcert.pem ← Certificado de
desarrollo.vicente-navarro.com firmado por la autoridad certificadora
-rw-r--r-- 1 root root 963 2009-02-18 20:05 newkey.pem ← Clave privada del
certificado
-rw-r--r-- 1 root root 781 2009-02-18 20:05 newreq.pem ← Petición de certificado
para firmar
# mv newkey.pem /etc/ssl/private/desarrollo.vicente-navarro.com.key
# mv newcert.pem /etc/ssl/certs/desarrollo.vicente-navarro.com.crt
SSLCertificateFile /etc/ssl/certs/desarrollo.vicente-navarro.com.crt
SSLCertificateKeyFile /etc/ssl/private/desarrollo.vicente-navarro.com.key
Ahora me gustaría hacer un comentario sobre la contraseña que nos pide OpenSSL
para ponerle a la clave privada del certificado (no a la del certificado raíz). En los
ejemplos anteriores nos la ha pedido y le hemos puesto una. En principio, podría ser
buena idea ponérsela, pero tenemos que tener en cuenta que si lo hacemos,
tendremos que introducirla cada vez que reiniciemos el servidor, incluso en
el arranque de la máquina, algo que puede ser muy inconveniente:
# apache2ctl stop
# apache2ctl start
Apache/2.2.9 mod_ssl/2.2.9 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.
# CA.pl -newreq-nodes
#./CA.pl -newreq-nodes
Generating a 1024 bit RSA private key
.............++++++
..................................++++++
writing new private key to 'newkey.pem'
-----
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]:Spain
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Desarrollo de Lo hice
y lo entendi
Organizational Unit Name (eg, section) []:El blog de Vicente Navarro
Common Name (eg, YOUR name) []:desarrollo.vicente-navarro.com
Email Address []:correodesarrollo@vicente-navarro.com
# cp -p /usr/lib/ssl/misc/demoCA/cacert.pem
/etc/ssl/certs/supercocoauthority.pem
# cd /etc/ssl/certs/
# openssl x509 -in supercocoauthority.pem -noout -hash
628f4309
… y crear un enlace al certificado cuyo nombre sea el hash con extensión .0:
# ln -s supercocoauthority.pem 628f4309.0
Con el comando openssl s_client podemos probar que la conexión funciona. Sin
embargo, curiosamente, a diferencia de cómo funciona openssl verify, el openssl
s_client no encuentra los certificados si no le especificamos el directorio donde
buscarlos explícitamente con la opción -CApath:
# wget https://desarrollo.vicente-navarro.com/blog/wp/wp-login.php
--2009-02-22 08:41:25-- https://desarrollo.vicente-navarro.com/blog/wp/wp-login.php
Resolving desarrollo.vicente-navarro.com... 127.0.0.1
Connecting to desarrollo.vicente-navarro.com|127.0.0.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3111 (3.0K) [text/html]
Saving to: `wp-login.php'
100%[======================================>] 3,111
--.-K/s in 0.001s
$ wget https://desarrollo.vicente-navarro.com/blog/wp/wp-login.php
--2009-02-22 07:59:01-- https://desarrollo.vicente-navarro.com/blog/wp/wp-login.php
Resolving desarrollo.vicente-navarro.com... 192.168.4.35
Connecting to desarrollo.vicente-navarro.com|192.168.4.35|:443... connected.
ERROR: cannot verify desarrollo.vicente-navarro.com's certificate, issued by
`/C=ES/ST=Spain/O=Super Coco Inc./OU=Barrio Sesamo/CN=Super Coco
Certification Authority/emailAddress=supercoco@barriosesamo.com':
Unable to locally verify the issuer's authority.
To connect to desarrollo.vicente-navarro.com insecurely, use `--no-check-certificate'.
Unable to establish SSL connection.
100%[======================================>] 3,111
--.-K/s in 0s