- Con este minimo podemos instalar apache para un servidor LAMP: # apt-get install libapache2-mod-php5 openssl Inicializacion de la CA Respaldar el archivo de configuracion de openssl: # cd /etc/ssl # cp openssl.conf openssl.conf.orig Editar algunos parametros basicos: Ya que todos los comandos y certificados los manejaremos bajo el directorio /etc/ssl/TuxjmCA entonces editaremos estos parametros: dir = ./demoCA # Where everything is kept Cambiarlo por: dir = /etc/ssl/TuxjmCA # Where everything is kept Si se quieren poner algunos valores a la hora de crear los certificados hacerlos en la seccion de: [ req_distinguished_name ], para mas opciones, ver: man 5 config, guardar el archivo y entocnes empezaremos a crear los certificados. El archivo openssl.conf hace referencia a algunos archivos y directorios que normalmente existen en /etc/ssl, pero nosotros estaremos en otro por lo que los crearemos en nuestro directorio /etc/ssl/TuxjmCA # cd /etc/ssl/TuxjmCA # mkdir certs csr newcerts private Crear el archivo index.txt # touch index.txt Crear e inicializar el archivo serial # echo "01" > serial - Crear la el certificado raiz y la llave privada de nuestra CA: # cd /etc/ssl/TuxjmCA # openssl req -new -x509 -keyout private/cakey.pem -out cacert.pem -days 3650 Generating a 1024 bit RSA private key ...++++++ ..........................++++++ writing new private key to 'private/cakey.pem' Enter PEM pass phrase: SUPER_MEGA_CONTRASEÑA Verifying - Enter PEM pass phrase: SUPER_MEGA_CONTRASEÑA ----- 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]:MX State or Province Name (full name) [Some-State]:Baja California Locality Name (eg, city) []:Tijuana Organization Name (eg, company) [Internet Widgits Pty Ltd]:Tuxjm Inc. Organizational Unit Name (eg, section) []:SIT Common Name (eg, YOUR name) []:ca.tuxjm.net Email Address []:jmedina@tuxjm.net Esto creara dos archivos, uno de el certificado raiz, el cual puede ser publicado a los que vayan a usar nuestra infraestructura de llave publica, y el archivo de la llave privada, el cual se usara para firmar las Certificados de Requerimiento de Certificados (CSR), este archivo se debe de tener en un lugar seguro. # ls -l cacert.pem private/cakey.pem -rw-r--r-- 1 root root 1330 2006-12-16 17:26 cacert.pem -rw-r--r-- 1 root root 963 2006-12-16 17:26 private/cakey.pem Bien, aunque el certificado raiz no sera usado para algun servicio, podemos comprobar su funcionamiento, asi: # openssl s_server -cert cacert.pem -key private/cakey.pem -www Enter pass phrase for private/cakey.pem: SUPER_MEGA_CONTRASEÑA Using default temp DH parameters Using default temp ECDH parameters ACCEPT Si el comando se ejecuta sin problemas, significa que los certificados estan bien hechos, este comando anterior levanto un servidor web en modo seguro es decir con soporte HTTPS, puedes apuntar tu navegador a la direccion: https://localhost:4433 y veras que te pide verificar el certificado, ahi mismo puedes ver su informacion. Bien ahora tendremos que crear el CSR y el certificado para nuestro servidor web. Primero creamos el CSR: # openssl req -nodes -new -keyout private/jamedina.tuxjm.net.key -out csr/jamedina.tuxjm.net.csr Generating a 1024 bit RSA private key .........++++++ ......................................++++++ writing new private key to 'private/jamedina.tuxjm.net.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]:MX State or Province Name (full name) [Some-State]:Baja California Locality Name (eg, city) []:Tijuana Organization Name (eg, company) [Internet Widgits Pty Ltd]:Tuxjm Inc. Organizational Unit Name (eg, section) []:Hosting Common Name (eg, YOUR name) []:jamedina.tuxjm.net Email Address []:jmedina@tuxjm.net Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: (SOLO_DAR_ENTER) An optional company name []: (SOLO_DAR_ENTER) En la parte de los atributos EXTRA ahi solo daremos enter y no tendra contraseña ya que si se llega a reiniciar el servidor web, se tendra que meter la contraseña para que inicie el servidor web. Esto nos creara los siguientes archivos: # ls -l csr/jamedina.tuxjm.net.csr private/jamedina.tuxjm.net.key -rw-r--r-- 1 root root 729 2006-12-16 17:46 csr/jamedina.tuxjm.net.csr -rw-r--r-- 1 root root 891 2006-12-16 17:46 private/jamedina.tuxjm.net.key BIen ahora firmaremos el CSR con la llave privada raiz de nuestra CA, lo haremos con el siguiente comando: # openssl ca -out certs/jamedina.tuxjm.net.crt -in csr/jamedina.tuxjm.net.csr -policy policy_anything Using configuration from /usr/lib/ssl/openssl.cnf Enter pass phrase for ./private/cakey.pem: SUPER_MEGA_CONTRASEÑA Check that the request matches the signature Signature ok Certificate Details: Serial Number: 1 (0x1) Validity Not Before: Dec 17 01:56:06 2006 GMT Not After : Dec 17 01:56:06 2007 GMT Subject: countryName = MX stateOrProvinceName = Baja California localityName = Tijuana organizationName = Tuxjm Inc. organizationalUnitName = Hosting commonName = jamedina.tuxjm.net emailAddress = jmedina@tuxjm.net X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: EB:7D:B2:C7:BD:50:E9:E7:F0:AD:E4:C0:5B:5B:69:72:7B:FC:FE:1D X509v3 Authority Key Identifier: keyid:CF:DE:56:69:CB:59:33:31:3A:56:64:31:FC:67:7C:DF:26:D9:FD:BB Certificate is to be certified until Dec 17 01:56:06 2007 GMT (365 days) Sign the certificate? [y/n]:y 1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries Data Base Updated Esto nos crea el archivo certs/jamedina.tuxjm.net.crt Ahora copiaremos el archivo de la llave de nuestro certificado jamedina.tuxjm.net.key y el certificado jamedina.tuxjm.net.crt a el directorio ssl de la configuracion de Apache2: # cp -v private/jamedina.tuxjm.net.key certs/jamedina.tuxjm.net.crt /etc/apache2/ssl/ `private/jamedina.tuxjm.net.key' -> `/etc/apache2/ssl/jamedina.tuxjm.net.key' `certs/jamedina.tuxjm.net.crt' -> `/etc/apache2/ssl/jamedina.tuxjm.net.crt' Ahora configurar apache2 para usar nuestro certificado recien creado. - Crear /etc/apache2/sites-enables/ssl # cp /etc/apache2/sites-available/default /etc/apache2/sites-available/ssl # ln -s /etc/apache2/sites-available/ssl /etc/apache2/sites-enabled/ssl - Editar el nuevo archivo /etc/apache2/sites-available/ssl Modificarlo para que sea un host virtual con soporte para HTTPS: Buscar las siguientes dos lineas: NameVirtualHost * Y cambiarlas por: NameVirtualHost *:443 Enseguida esta la linea que tiene: DocumentRoot /var/www Y seguido agregar estas lineas: ServerName jamedina.tuxjm.net SSLEngine On SSLCertificateFile /etc/apache2/ssl/jamedina.tuxjm.net.crt SSLCertificateKeyFile /etc/apache2/ssl/jamedina.tuxjm.net.key NOTA: No olvidar poner el en el "ServerName" lo mismo que se puso en el campo Common Name (eg, YOUR name) []: cuando se creo el Certificado. - Agregar el puerto 443 para que apache tambien escuche peticiones en este puerto y tenga soporte para HTTPS, abrir el archivo /etc/apache2/ports.conf Agregar esta linea: Listen 443 - Ejecutar el siguiente comando para agregar los modulos y configuracion para que apache2 use SSL # a2enmod ssl - Reiniciar apache2. /etc/init.d/apache2 force-reload Checar la validez de un certificado: Usando check_expire de http://sial.org/howto/openssl/check-expire/ instalar: # apt-get install libconfig-general-perl # apt-get install libtimedate-perl # wget http://sial.org/code/perl/scripts/check-expire PARA SELF-SIGNED CERTS. Si se desea crear un certificado firmado por uno mismo (self-signed) podemos usar el siguiente comando que viene incluido en el paquete apache2-common, ejecutar esto: # /usr/sbin/apache2-ssl-certificate # # # Referencias: OpenSSL Command-Line HOWTO: http://www.madboa.com/geek/openssl/ OpenSSL Documentation: http://sial.org/howto/openssl/ OpenSSL Self-signed Test Certificates: http://sial.org/howto/openssl/self-signed/ OpenSSL Certificate Authority Setup: http://sial.org/howto/openssl/ca/ Generating Certificate Signing Requests (CSR): http://sial.org/howto/openssl/csr/ Example TLS Certificate Configuration: http://sial.org/howto/openssl/examples/ Exporting OpenSSL Certificates: http://sial.org/howto/openssl/exporting/ OpenSSL S/MIME: http://sial.org/howto/openssl/smime/ Monitoring for certificate expiration: http://sial.org/howto/openssl/check-expire/