domingo, 5 de agosto de 2007

SSl-Apache Certificate Authority

HOW TO SSl-apache mas su entidad certificadora(Certificate Authority).

Para crear tu propia Entidad Certificadora ó CA (Certificate Authority) Para que trabaje (SSL/TLS cifrado) en servidores https, tienes que generar una key private y un certificado para el servidor.
Para un sitio Web comercial, desearas probablemente comprar un certificado raiz firmado por una bien conocida CA.
Para el Intranet o las aplicaciones especiales, tu puedes ser tu propio CA. Esto se hace con las herramientas de OpenSSL.

Step 1:

Pasos para una llave privada del CA y un certificado privado del CA X.509.

Tambien haremos un directorio para los certificados y las llaves:

[root]# mkdir /root/ssl/jair.com.co
[root]# chmod 0770 /root/ssl/jair.com.co
[root]# cd /root/jair.com.co

[root]# openssl genrsa -des3 -out my-ca.key 2048 >>> hace la llave.

[root]# openssl req -new -x509 -days 3650 -key my-ca.key -out my-ca.crt >>>hace el certificado X.509 con un curso de la vida de 10 años.

[root]# openssl x509 -in my-ca.crt -text -noout >>> te deja ver el certificado terminado. Cerciorarte de que tu contraseña esta en un lugar seguro, necesitarás todo esto en el futuro!

Step 2:

Hacer una llave y un certificado para el web server:
* tenemos que hacer un certificado X.509 y una llave privada correspondiente para el web server.

[root]# openssl genrsa -des3 -out mars-server.key 1024
[root]# openssl req -new -key mars-server.key -out mars-server.csr

* crearemos una llave y una petición del certificado, entonces firmara la petición del certificado con la llave del CA que hicimos en el paso 1.

[root]# openssl x509 -req -in mars-server.csr -out mars-server.crt -sha1 -CA my-ca.crt -CAkey my-ca.key -CAcreateserial -days 3650

* las llaves privadas de SSL/TLS para los servidores necesitan ser 512 o 1024 bits.
Cualquier otro tamaño puede ser incompatible con ciertos browsers.

[root]# openssl x509 -in mars-server.crt -text -noout

Cerciorarte de que tu nombre del servidor sea igual que el FQDN que tus clientes utilizarán al conectar con tu sitio.

[root]# chmod 0400 *.key

Ahora, necesitamos copiar ó mover las llaves y los certificados a los directorios apropiados en la jerarquia /etc/httpd:

[root]# cp mars-server.crt /etc/httpd/conf/ssl.crt
[root]# cp mars-server.key /etc/httpd/conf/ssl.key
[root]# cp my-ca.crt /etc/httpd/conf/ssl.crt

necesitamos mover las nuevas llaves y certs en los directorios apropiados /etc/apache2/ssl/

[root]# cp mars-server.crt /etc/apache2/ssl/ssl.crt
[root]# cp mars-server.key /etc/apache2/ssl/ssl.key
[root]# cp my-ca.crt /etc/apache2/ssl/myssl.crt


step 3:

Crear los directorios y los archivos para el servicio seguro
No quisiera que el directorio seguro de mi fuera parte de mi rama inseguro

Mi directorio de rai­z normal es /var/www/html.
La raiz del documento para el server web seguro sera situada en /var/www/jair.

[root]# mkdir /var/www/jair
[root]# chmod 0775 /var/www/jair
[root]# cd /var/www/jair
[root]# mkdir Passneeded
[root]# mkdir Certneeded
[root]# mkdir PassAndCert

agrega este archivo muy simple del i­ndice del SSL de la prueba en /var/www/jair.
se crea un index.html, archivos del JPEG y archivos de texto en cada directorio, de modo que haya algo mirar en cada directorio.

Step 4:

Configurar el web server de Apache por defecto,
dos archivos de los configuracion: apache2.conf y ssl.conf.
Todos nuestros cambios serán realizados en el archivo de /etc/apache2/mods-available/ssl.conf.
No es necesario modificar el archivo de apache2.conf para lograr nuestras metas en un servidor.

DocumentRoot "/var/www/SSL"

# observa que el FQDN y el hostname del servidor deben ir aqui -
los clientes no podrian conectar si no es asi! :-)

ServerName mars.jair.com.co:443
ServerAdmin webmaster@jair.com.co

# aqui­, estoy permitiendo solamente high y seguridad medium".
SSLCipherSuite HIGH:MEDIUM

# aqui­ estoy permitiendo SSLv3 y TLSv1, no estoy permitiendo la version vieja SSLv2.
SSLProtocol all -SSLv2

# Server Certificate:
SSLCertificateFile /etc/httpd/conf/ssl.crt/mars-server.crt

# Server Private Key:
SSLCertificateKeyFile /etc/httpd/conf/ssl.key/mars-server.key

# Server Certificate Chain:
SSLCertificateChainFile /etc/httpd/conf/ssl.crt/my-ca.crt

# Certificate Authority (CA):
SSLCACertificateFile /etc/httpd/conf/ssl.crt/my-ca.crt

# This is needed so that you can use auto-indexing for some directories in the
# /var/www/SSL directory branch. This can be handy if you would like to have
# a list of sensitive files for people to download.

# necesario para que puedas utilizar auto-index para algunos directorios #de /var/www/jair


Options Indexes
AllowOverride None
Allow from from all
Order allow,deny


en tambien en otras vesiones de apache2 editamos el fichero /etc/apache2/sites-availables/default y creamos el virtual host adecuado para el puerto 443 :

NameVirtualHost *:443

ServerAdmin webmaster@localhost
DocumentRoot /var/local/mipagina
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/servidor-cert.pem
SSLCertificateKeyFile /etc/apache2/ssl/serv-priv.pem
ServerName mipagina.midominio.com

Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all


modifica el fichero /etc/apache2/ports.conf para que ponga:
Listen 80
Listen 443

Step 6:

Require simple username/password auth for one of the directories:
We want to require a valid username and password for the /var/www/SSL/Passneeded directory. The username and password will be encrypted in transit as part of the TCP stream. We will need to setup the access control directives, as well as use the htpasswd command to add the username/password pairs.

Requerir username/password para uno de los directorios:
Deseamos requerir username y contraseña para el directorio de /var/www/jair/Passneeded.
El username, contraseña serán cifrados en tránsito como parte de la corriente del TCP.
Necesitaremos directivas de control de acceso. utilizamos el comando htpasswd username/password.

[root]# htpasswd -c -m /etc/apache2/.htpasswd jair
New password:
Re-type new password:
Adding password for user jair
[root]# htpasswd -m /etc/apache2/.htpasswd jair2
New password:
Re-type new password:
Adding password for user jair2

[root]# chown apache.root /etc/apache2/.htpasswd
[root]# chmod 0460 /etc/apache2/.htpasswd

Now, we need to tell Apache to require a username/password to access the Passneeded directory. Here is what we will add to /etc/httpd/conf.d/ssl.conf file:

Ahora, necesitamos decir a Apache requerir username/password tener acceso al directorio de Passneeded. Aquí es lo que agregaremos al archivo de /etc/apache/conf.d/ssl.conf:


AuthType Basic
AuthName "Username and Password Required"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user


creating Client Certificates for Authentication

Now, let's say that we want a stronger method of authenticating clients, one that is not as susceptible to password guessing and shoulder-surfing. What can we do? We can create an SSL/TLS client certificate. The certificate has to be digitally signed by a CA that the server trusts, the user has to have the client loaded in his browser, and the user has to know a pass phrase to use it. The certificate itself uses strong, public-key cryptography. We can make such a certificate with our OpenSSL toolkit.

A note on certificate formats: The server and CA certs that we have been using up to now are encoded in PEM format, which uses ASCII characters. For some reason, the industry-standard client certs used in web browsers are encoded in the PKCS#12 format, which cannot be viewed as simple text. It is a binary file. We will now create a client cert by following these steps:

* Create a new private key and certificate request
* Sign the certificate request, thereby creating the client certificate
* Generate the PKCS#12 cert file
* View information about the PKCS#12 cert
* Import the PKCS#12 client cert into your browser
* Test!

[root]# cd /root/CA
[root]# openssl genrsa -des3 -out van-c.key 1024
Generating RSA private key, 1024 bit long modulus
..++++++
.............................................................++++++
e is 65537 (0x10001)
Enter PEM pass phrase:
Verifying password - Enter PEM pass phrase:

[root]# openssl req -new -key van-c.key -out van-c.csr
Using configuration from /usr/share/ssl/openssl.cnf
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) [GB]:TW
State or Province Name (full name) [Berkshire]:Taipei County
Locality Name (eg, city) [Newbury]:Nankang
Organization Name (eg, company) [My Company Ltd]:VanEmery.Com
Organizational Unit Name (eg, section) []:Sales
Common Name (eg, your name or your server's hostname) []:Van Emery
Email Address []:ve@vanemery.com

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

# openssl x509 -req -in van-c.csr -out van-c.crt -sha1 -CA my-ca.crt -CAkey my-ca.key -CAcreateserial -days 3650

[root]# openssl pkcs12 -export -in van-c.crt -inkey van-c.key -name "Van Emery Cert" -out van-c.p12

[root]# openssl pkcs12 -in van-c.p12 -clcerts -nokeys -info

Note: The "export password" is all the end-user needs to know. This is what you will be asked for when installing the certificate in a browser.

Now move the van-c.p12 file to your client machine and import it into your web browser. This is usually done your browser's "Preferences" section under "Privacy and Security", "Certificates", "Manage Certificates". You may be asked to input a Software Security Device Master Password. DO NOT FORGET this password! You will also be asked for the client certificate's export password.

Configure Apache to require client certificates for a specific directory:

In order to require client certificates for the /var/www/SSL/Certneeded directory, you will need to add the following lines to the /etc/httpd/conf.d/ssl.conf configuration file:


SSLVerifyClient require
SSLVerifyDepth 1


Que pena pero falta traducir algo (espero terminar Pronto) :-)

No hay comentarios: