Diferencia entre revisiones de «Módulo SSL en Apache 2.4»
| (No se muestran 3 ediciones intermedias del mismo usuario) | |||
| Línea 18: | Línea 18: | ||
apache2 -M | grep ssl | apache2 -M | grep ssl | ||
| − | = | + | = Xenerar certificado autoasinado = |
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt | sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt | ||
| + | |||
| + | ; openssl | ||
| + | : This is the command line tool for creating and managing OpenSSL certificates, keys, and other files. | ||
| + | ; req -x509 | ||
| + | : This specifies that we want to use X.509 certificate signing request (CSR) management. X.509 is a public key infrastructure standard that TLS adheres to for key and certificate management. | ||
| + | ; -nodes | ||
| + | : This tells OpenSSL to skip the option to secure our certificate with a passphrase. We need Apache to be able to read the file, without user intervention, when the server starts up. A passphrase would prevent this from happening, since we would have to enter it after every restart. | ||
| + | ; -days 365 | ||
| + | : This option sets the length of time that the certificate will be considered valid. We set it for one year here. Many modern browsers will reject any certificates that are valid for longer than one year. | ||
| + | ; -newkey rsa:2048 | ||
| + | : This specifies that we want to generate a new certificate and a new key at the same time. We did not create the key that is required to sign the certificate in a previous step, so we need to create it along with the certificate. The rsa:2048 portion tells it to make an RSA key that is 2048 bits long. | ||
| + | ; -keyout: | ||
| + | This line tells OpenSSL where to place the generated private key file that we are creating. | ||
| + | ; -out | ||
| + | : This tells OpenSSL where to place the certificate that we are creating. | ||
= Configurar virtual host para acceso seguro = | = Configurar virtual host para acceso seguro = | ||
| + | |||
| + | Hai que declarar o certificado e a clave privada no ficheiro de configuración do servidor HTTP Apache, usando as directivas: | ||
| + | * SSLEngine on | ||
| + | * SSLCertificateFile ArchivoCert | ||
| + | * SSLCertificateKeyFile ArchivoClave | ||
| + | |||
| + | ; ArchivoCert | ||
| + | : Camiño de acceso ao ficheiro que contén o certificado. | ||
| + | ; ArchivoClave | ||
| + | : Camiño de acceso ao ficheiro que contén a clave privada. | ||
<pre> /etc/apache2/sites-available/default-ssl.conf | <pre> /etc/apache2/sites-available/default-ssl.conf | ||
| Línea 53: | Línea 78: | ||
Podemos desactivar as versións 2 e 3 de SSL por estar obsoletas: | Podemos desactivar as versións 2 e 3 de SSL por estar obsoletas: | ||
SSLProtocol all -SSLv2 -SSLv3 | SSLProtocol all -SSLv2 -SSLv3 | ||
| + | |||
| + | Un servidor Apache pode presentar elementos de risco que poidan comprometer a súa seguridade incluso en modo HTTPS. | ||
| + | |||
| + | Aconséllase desactivar as antiguas versións dos protocolos SSL/TLS e dos protocolos de cifrado. | ||
| + | |||
| + | También é aconsellable: | ||
| + | * limitar a información ofrecida polo servidor, en particular a súa versión | ||
| + | * personalizar as respostas do servidor, para utilizarlas na autenticación. | ||
| + | |||
| + | Distintas directivas permiten controlar estes elementos de seguridade: | ||
| + | ; SSLProtocol | ||
| + | : Versións del protocolo SSL/TLS autorizadas. | ||
| + | ; SSLCipherSuite | ||
| + | : Algoritmos de cifrado autorizados. | ||
| + | ; ServerTokens | ||
| + | : Campos do encabezado Server enviados ao cliente. | ||
| + | ; ServerSignature | ||
| + | : Pe de páxina para os documentos xenerados plo servidor. | ||
| + | ; TraceEnable | ||
| + | : Autoriza ou non as solicitudes de rexistro enviadas polo cliente. | ||
= Reiniciar servicio = | = Reiniciar servicio = | ||
| Línea 65: | Línea 110: | ||
* [https://httpd.apache.org/docs/trunk/es/mod/mod_ssl.html Información oficial de Apache do módulo SSL] | * [https://httpd.apache.org/docs/trunk/es/mod/mod_ssl.html Información oficial de Apache do módulo SSL] | ||
* [https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-22-04 How To Create a Self-Signed SSL Certificate for Apache in Ubuntu 22.04 - Digital Ocean] | * [https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-22-04 How To Create a Self-Signed SSL Certificate for Apache in Ubuntu 22.04 - Digital Ocean] | ||
| + | * [https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwic77Ohv-CIAxWdafEDHbp-HPEQFnoECBYQAQ&url=https%3A%2F%2Fwww.rehurtado.com%2Fver_documento.php%3Fid%3D29&usg=AOvVaw2XN89eivWlPoqI18Pdmnj5&opi=89978449 Guia Inteco] | ||
Revisión actual del 11:30 26 sep 2024
Sumario
Introdución
Podemos usar o 'protocolo HTTPS (HyperText Transfer Protocol Secure) para aumentar a seguridade; basesase nunha capa de software protexida, SSL (Secure Socket Layer) ou TLS (Transport Layer Secure, sucesor de SSL), para a comunicación entre o cliente e o servidor Apache.
O protocolo de seguridade toma en conta a autenticación dos participantes a través dos certificados, o cifrado e o control da integridade dos datos intercambiados.
Emprega o well-known port 443, a diferencia de http que emprega o 80.
Habilitar módulo SSL
sudo a2enmod ssl sudo a2enmod headers
O módulo que xestiona o protocolo SSL é mod_ssl. Ten que estar configurado para ser cargado no ficheiro de configuración do servidor HTTP Apache.
NOTA. Comprobar que o módulo está instalado: apache2 -M | grep ssl
Xenerar certificado autoasinado
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt
- openssl
- This is the command line tool for creating and managing OpenSSL certificates, keys, and other files.
- req -x509
- This specifies that we want to use X.509 certificate signing request (CSR) management. X.509 is a public key infrastructure standard that TLS adheres to for key and certificate management.
- -nodes
- This tells OpenSSL to skip the option to secure our certificate with a passphrase. We need Apache to be able to read the file, without user intervention, when the server starts up. A passphrase would prevent this from happening, since we would have to enter it after every restart.
- -days 365
- This option sets the length of time that the certificate will be considered valid. We set it for one year here. Many modern browsers will reject any certificates that are valid for longer than one year.
- -newkey rsa
- 2048
- This specifies that we want to generate a new certificate and a new key at the same time. We did not create the key that is required to sign the certificate in a previous step, so we need to create it along with the certificate. The rsa:2048 portion tells it to make an RSA key that is 2048 bits long.
- -keyout
This line tells OpenSSL where to place the generated private key file that we are creating.
- -out
- This tells OpenSSL where to place the certificate that we are creating.
Configurar virtual host para acceso seguro
Hai que declarar o certificado e a clave privada no ficheiro de configuración do servidor HTTP Apache, usando as directivas:
- SSLEngine on
- SSLCertificateFile ArchivoCert
- SSLCertificateKeyFile ArchivoClave
- ArchivoCert
- Camiño de acceso ao ficheiro que contén o certificado.
- ArchivoClave
- Camiño de acceso ao ficheiro que contén a clave privada.
/etc/apache2/sites-available/default-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin your_email@example.com
ServerName server_domain_or_IP
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>
Desactivar SSLv2 e SSLv3 (opcional)
Podemos desactivar as versións 2 e 3 de SSL por estar obsoletas:
SSLProtocol all -SSLv2 -SSLv3
Un servidor Apache pode presentar elementos de risco que poidan comprometer a súa seguridade incluso en modo HTTPS.
Aconséllase desactivar as antiguas versións dos protocolos SSL/TLS e dos protocolos de cifrado.
También é aconsellable:
- limitar a información ofrecida polo servidor, en particular a súa versión
- personalizar as respostas do servidor, para utilizarlas na autenticación.
Distintas directivas permiten controlar estes elementos de seguridade:
- SSLProtocol
- Versións del protocolo SSL/TLS autorizadas.
- SSLCipherSuite
- Algoritmos de cifrado autorizados.
- ServerTokens
- Campos do encabezado Server enviados ao cliente.
- ServerSignature
- Pe de páxina para os documentos xenerados plo servidor.
- TraceEnable
- Autoriza ou non as solicitudes de rexistro enviadas polo cliente.
Reiniciar servicio
sudo systemctl restart apache2
Uso
Acceder por https: https://server_domain_or_IP