Activation HTTPS sous Apache

De EjnTricks
Révision de 25 juin 2018 à 15:42 par Etienne (discussion | contributions)

(diff) ← Version précédente | Voir la version courante (diff) | Version suivante → (diff)

Pour toutes application nécessitant une connexion et / ou des données sensibles, il est recommandé d'accéder à l'application en HTTPS. Cela peut être le cas pour des outils d'administration par exemple. Ce principe est souvent utilisé pour la publication de sources. Un accès en lecture seul est offert, avec le protocole HTTP, et un accès en modification s'effectue en HTTPS.

Cet article présente la mise en place du protocole HTTPS sur un serveur Apache pour une machine Ubuntu.


Hand-icon.png Votre avis

Current user rating: 84/100 (1 votes)

 You need to enable JavaScript to vote


Génération certificat

Afin d'activer ce protocole, il est obligatoire d'avoir un certificat. Ces certificats peuvent être délivrés par des tiers, mais très généralement payant et cher pour un usage personnel, ou créés manuellement sur la machine. Dans le cadre de cet article, il sera généré manuellement à l'aide de l'application openssl. Le certificat sera également signé avec une clé générée localement.

Attention, les certificats sont valides pour un nom de domaine en particulier, et "ne peuvent pas" s'appliquer au sous domaines par exemple.

L'emplacement des différents fichiers est inspiré de la configuration SSL par défaut fourni dans la distribution Ubuntu, à savoir:

  • /etc/ssl/certs pour le certificat.
  • /etc/ssl/private pour la clé.

Génération de la clé

Afin de signer le futur certificat, il faut générer une clé privé avec openssl. La commande suivante permet de générer une clé RSA à l'emplacement /etc/ssl/private/jouvinio.key, de longteur 2048 caractères.

#sudo openssl genrsa -out /etc/ssl/private/jouvinio.key 2048
Generating RSA private key, 2048 bit long modulus
........................+++
................................+++
e is 65537 (0x10001)

Le répertoire /etc/ssl/private contient donc la clé générée:

#sudo ll /etc/ssl/private/
total 16
drwx--x--- 2 root ssl-cert 4096 2012-04-07 09:21 ./
drwxr-xr-x 4 root root     4096 2012-02-10 20:19 ../
-rw-r--r-- 1 root root     1675 2012-04-07 09:20 jouvinio.key
-rw-r----- 1 root ssl-cert  887 2010-12-12 10:00 ssl-cert-snakeoil.key

La clé étant privé, il est nécessaire de la protéger autant que possible des accès non souhaités. Les permissions du fichier ssl-cert-snakeoil.key sont reproduite sur la clé générée.

#sudo chown root:ssl-cert /etc/ssl/private/jouvinio.key
#sudo chmod 640 /etc/ssl/private/jouvinio.key

Génération de CSR

Afin de pouvoir généré le certificat signé, il faut créer à partir de la clé privé un fichier Certificate Signing Request, placé dans le répertoire /etc/ssl/certs pour cet article. Durant cette exécution, de nombreuse question sont posées à l'utilisateur.

Une des questions posées concerne le Common Name qui doit correspondre exactement au domaine qui utilisera le certificat. Pour cet exemple d'exécution, le serveur cible répond à l'URL www.jouvinio.net, la valeur renseignée pour Common Name sera donc jouvinio.net.

Afin de générer le certification pour le site www.dev.jouvinio.net, il faut saisir dev.jouvinio.net.

Le fichier sera généré à l'emplacement /etc/ssl/certs/jouvinio.csr.

#sudo openssl req -new -key /etc/ssl/private/jouvinio.key -out /etc/ssl/certs/jouvinio.csr
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]:fr
State or Province Name (full name) [Some-State]:Val De Marne
Locality Name (eg, city) []:Vitry Sur Seine
Organization Name (eg, company) [Internet Widgits Pty Ltd]:jouvinio
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:jouvinio.net
Email Address []:ejouvin@free.fr

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

la valeur saisie pour A challenge password permettra de révoquer le ceritficat en cas de vol. Ce mot de passe ne peut pas excéder 20 caractères.

Génération Certificat signé

Une fois la clé et la demande de certificat créé, il est possible de générer le certificat signé utilisé dans la configuration Apache.

Les argument sont utilisé ainsi:

Paramètre Valeur
x509 Indique que l'exécution est pour un certificat X.509.
-req Gestion X.509 du fichier CSR.
-days 365 FIxe la durée de validité à 365 jours.
-in <CSR PATH> Indique l'emplacement du fichier CSR.
-signkey <KEY PATH> Indique l'emplacement de la clé à utiliser pour signer le certificat.
-out <CRT PATH> Emplacement du fichier généré.

L'argument x509 permet d'indiquer que l'exécution est pour un certificat X.509. lors de l'exécution, des informations sont reprises du fichier CSR et présentés dans la trace d'exécution.

#sudo openssl x509 -req -days 365 -in /etc/ssl/certs/jouvinio.csr -signkey /etc/ssl/private/jouvinio.key -out /etc/ssl/certs/jouvinio.crt
Signature ok
subject=/C=fr/ST=Val De Marne/L=Vitry Sur Seine/O=jouvinio/CN=jouvinio.net/emailAddress=ejouvin@free.fr
Getting Private key

Le répertoire /etc/ssl/private contient essentiellement des fichiers ou liens avec l'extension pem. Afin d'uniformiser ceci, un lien est positionné, avec cette extension, sur le certification généré.

#sudo ln -s /etc/ssl/certs/jouvinio.crt /etc/ssl/certs/jouvinio.pem

Après ces étapes, il reste à modifier la configuration Apache.

Configuration Apache

Activation module ssl

Sur une machine Ubuntu, l'activation d'un module s'effectue en mettant en place des liens dans le répertoire /etc/apache2/mods-enabled sur des fichiers se trouvant dans le répertoire /etc/apache2/mods-available. Pour l'activation du module SSL, les liens à placer sont sur les fichiers:

  • /etc/apache2/mods-available/status.conf
  • /etc/apache2/mods-available/status.load
#cd /etc/apache2/mods-enabled
#sudo ln -s ../status.conf status.conf
#sudo ln -s ../status.load status.load

Cependant, sur une distribution Ubuntu, la commande a2enmod est disponible afin d'activer des modules.

#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.
To activate the new configuration, you need to run:
  service apache2 restart

Le répertoire /etc/apache2/mods-enabled doit contenir les deux nouveaux liens.

#sudo ll /etc/apache2/mods-enabled
total 8
drwxr-xr-x 2 root root 4096 2012-04-06 21:55 ./
drwxr-xr-x 7 root root 4096 2012-02-27 23:59 ../
lrwxrwxrwx 1 root root   40 2011-07-24 21:42 actions.load -> /etc/apache2/mods-available/actions.load
lrwxrwxrwx 1 root root   28 2010-12-12 10:21 alias.conf -> ../mods-available/alias.conf
lrwxrwxrwx 1 root root   28 2010-12-12 10:21 alias.load -> ../mods-available/alias.load
lrwxrwxrwx 1 root root   33 2010-12-12 10:21 auth_basic.load -> ../mods-available/auth_basic.load
lrwxrwxrwx 1 root root   33 2010-12-12 10:21 authn_file.load -> ../mods-available/authn_file.load
lrwxrwxrwx 1 root root   34 2011-11-05 19:37 authnz_ldap.load -> ../mods-available/authnz_ldap.load
lrwxrwxrwx 1 root root   36 2010-12-12 10:21 authz_default.load -> ../mods-available/authz_default.load
lrwxrwxrwx 1 root root   38 2010-12-12 10:21 authz_groupfile.load -> ../mods-available/authz_groupfile.load
lrwxrwxrwx 1 root root   33 2010-12-12 10:21 authz_host.load -> ../mods-available/authz_host.load
lrwxrwxrwx 1 root root   33 2010-12-12 10:21 authz_user.load -> ../mods-available/authz_user.load
lrwxrwxrwx 1 root root   32 2010-12-12 10:21 autoindex.conf -> ../mods-available/autoindex.conf
lrwxrwxrwx 1 root root   32 2010-12-12 10:21 autoindex.load -> ../mods-available/autoindex.load
lrwxrwxrwx 1 root root   26 2010-12-14 20:48 cgi.load -> ../mods-available/cgi.load
lrwxrwxrwx 1 root root   26 2010-12-12 12:48 dav.load -> ../mods-available/dav.load
lrwxrwxrwx 1 root root   30 2010-12-12 12:48 dav_svn.conf -> ../mods-available/dav_svn.conf
lrwxrwxrwx 1 root root   30 2010-12-12 12:48 dav_svn.load -> ../mods-available/dav_svn.load
lrwxrwxrwx 1 root root   30 2010-12-12 10:21 deflate.conf -> ../mods-available/deflate.conf
lrwxrwxrwx 1 root root   30 2010-12-12 10:21 deflate.load -> ../mods-available/deflate.load
lrwxrwxrwx 1 root root   26 2010-12-12 10:21 dir.conf -> ../mods-available/dir.conf
lrwxrwxrwx 1 root root   26 2010-12-12 10:21 dir.load -> ../mods-available/dir.load
lrwxrwxrwx 1 root root   26 2010-12-12 10:21 env.load -> ../mods-available/env.load
lrwxrwxrwx 1 root root   27 2011-11-05 19:43 ldap.load -> ../mods-available/ldap.load
lrwxrwxrwx 1 root root   27 2010-12-12 10:21 mime.conf -> ../mods-available/mime.conf
lrwxrwxrwx 1 root root   27 2010-12-12 10:21 mime.load -> ../mods-available/mime.load
lrwxrwxrwx 1 root root   34 2010-12-12 10:21 negotiation.conf -> ../mods-available/negotiation.conf
lrwxrwxrwx 1 root root   34 2010-12-12 10:21 negotiation.load -> ../mods-available/negotiation.load
lrwxrwxrwx 1 root root   27 2010-12-14 20:48 php5.conf -> ../mods-available/php5.conf
lrwxrwxrwx 1 root root   27 2010-12-14 20:48 php5.load -> ../mods-available/php5.load
lrwxrwxrwx 1 root root   28 2010-12-12 12:18 proxy.conf -> ../mods-available/proxy.conf
lrwxrwxrwx 1 root root   33 2010-12-12 12:19 proxy_http.load -> ../mods-available/proxy_http.load
lrwxrwxrwx 1 root root   28 2010-12-12 12:19 proxy.load -> ../mods-available/proxy.load
lrwxrwxrwx 1 root root   33 2010-12-12 10:21 reqtimeout.conf -> ../mods-available/reqtimeout.conf
lrwxrwxrwx 1 root root   33 2010-12-12 10:21 reqtimeout.load -> ../mods-available/reqtimeout.load
lrwxrwxrwx 1 root root   31 2010-12-12 10:21 setenvif.conf -> ../mods-available/setenvif.conf
lrwxrwxrwx 1 root root   31 2010-12-12 10:21 setenvif.load -> ../mods-available/setenvif.load
lrwxrwxrwx 1 root root   26 2012-04-06 21:55 ssl.conf -> ../mods-available/ssl.conf
lrwxrwxrwx 1 root root   26 2012-04-06 21:55 ssl.load -> ../mods-available/ssl.load
lrwxrwxrwx 1 root root   29 2010-12-12 10:21 status.conf -> ../mods-available/status.conf
lrwxrwxrwx 1 root root   29 2010-12-12 10:21 status.load -> ../mods-available/status.load

Ecoute du port 443

Par défaut, les sites HTTPS sont sur le port 443. Il faut donc indiquer à Apache d'écouter ce port, à travers le fichier ports.conf. Sous Ubuntu, ce fichier se trouve à l'emplacement /etc/apache2/ports.conf et contient déjà le paramétrage adéquat, même si un peu plus complexe.

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
    # If you add NameVirtualHost *:443 here, you will also have to change
    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
    # to <VirtualHost *:443>
    # Server Name Indication for SSL named virtual hosts is currently not
    # supported by MSIE on Windows XP.
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>


Sans modification, un warning sera affiché lors du rechargement des configurations Apache.

#sudo apache2ctl graceful
[Sun Apr 08 14:50:13 2012] [warn] _default_ VirtualHost overlap on port 443, the first has precedence

Il faut rajouter une directive NameVirtualHost sur le port 443.

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
    # If you add NameVirtualHost *:443 here, you will also have to change
    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
    # to <VirtualHost *:443>
    # Server Name Indication for SSL named virtual hosts is currently not
    # supported by MSIE on Windows XP.
    NameVirtualHost *:443
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

Configuration host

La dernière étape consiste à référencer la clé et le certificat au niveau de la configuration des Hosts avec les paramètres:

  • SSLCertificateFile pour le certificat.
  • SSLCertificateKeyFile pour la clé.

L'exemple présenté est une modification de la configuration fournie sous Ubuntu.

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined

        Alias /doc/ "/usr/share/doc/"
        <Directory "/usr/share/doc/">
                Options Indexes MultiViews FollowSymLinks
                AllowOverride None
                Order deny,allow
                Deny from all
                Allow from 127.0.0.0/255.0.0.0 ::1/128
        </Directory>

        #   SSL Engine Switch:
        #   Enable/Disable SSL for this virtual host.
        SSLEngine on

        #   A self-signed (snakeoil) certificate can be created by installing
        #   the ssl-cert package. See
        #   /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
        #   If both key and certificate are stored in the same file, only the
        #   SSLCertificateFile directive is needed.
        # SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
        SSLCertificateFile    /etc/ssl/certs/jouvinio.pem
        # SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
        SSLCertificateKeyFile /etc/ssl/private/jouvinio.key

        #   Server Certificate Chain:
        #   Point SSLCertificateChainFile at a file containing the
        #   concatenation of PEM encoded CA certificates which form the
        #   certificate chain for the server certificate. Alternatively
        #   the referenced file can be the same as SSLCertificateFile
        #   when the CA certificates are directly appended to the server
        #   certificate for convinience.
        #SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt

        #   Certificate Authority (CA):
        #   Set the CA certificate verification path where to find CA
        #   certificates for client authentication or alternatively one
        #   huge file containing all of them (file must be PEM encoded)
        #   Note: Inside SSLCACertificatePath you need hash symlinks
        #         to point to the certificate files. Use the provided
        #         Makefile to update the hash symlinks after changes.
        #SSLCACertificatePath /etc/ssl/certs/
        #SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt

        #   Certificate Revocation Lists (CRL):
        #   Set the CA revocation path where to find CA CRLs for client
        #   authentication or alternatively one huge file containing all
        #   of them (file must be PEM encoded)
        #   Note: Inside SSLCARevocationPath you need hash symlinks
        #         to point to the certificate files. Use the provided
        #         Makefile to update the hash symlinks after changes.
        #SSLCARevocationPath /etc/apache2/ssl.crl/
        #SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl

        #   Client Authentication (Type):
        #   Client certificate verification type and depth.  Types are
        #   none, optional, require and optional_no_ca.  Depth is a
        #   number which specifies how deeply to verify the certificate
        #   issuer chain before deciding the certificate is not valid.
        #SSLVerifyClient require
        #SSLVerifyDepth  10

        #   Access Control:
        #   With SSLRequire you can do per-directory access control based
        #   on arbitrary complex boolean expressions containing server
        #   variable checks and other lookup directives.  The syntax is a
        #   mixture between C and Perl.  See the mod_ssl documentation
        #   for more details.
        #<Location />
        #SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
        #            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
        #            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
        #            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
        #            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
        #           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
        #</Location>

        #   SSL Engine Options:
        #   Set various options for the SSL engine.
        #   o FakeBasicAuth:
        #     Translate the client X.509 into a Basic Authorisation.  This means that
        #     the standard Auth/DBMAuth methods can be used for access control.  The
        #     user name is the `one line' version of the client's X.509 certificate.
        #     Note that no password is obtained from the user. Every entry in the user
        #     file needs this password: `xxj31ZMTZzkVA'.
        #   o ExportCertData:
        #     This exports two additional environment variables: SSL_CLIENT_CERT and
        #     SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
        #     server (always existing) and the client (only existing when client
        #     authentication is used). This can be used to import the certificates
        #     into CGI scripts.
        #   o StdEnvVars:
        #     This exports the standard SSL/TLS related `SSL_*' environment variables.
        #     Per default this exportation is switched off for performance reasons,
        #     because the extraction step is an expensive operation and is usually
        #     useless for serving static content. So one usually enables the
        #     exportation for CGI and SSI requests only.
        #   o StrictRequire:
        #     This denies access when "SSLRequireSSL" or "SSLRequire" applied even
        #     under a "Satisfy any" situation, i.e. when it applies access is denied
        #     and no other module can change it.
        #   o OptRenegotiate:
        #     This enables optimized SSL connection renegotiation handling when SSL
        #     directives are used in per-directory context.
        #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
        </Directory>

        #   SSL Protocol Adjustments:
        #   The safe and default but still SSL/TLS standard compliant shutdown
        #   approach is that mod_ssl sends the close notify alert but doesn't wait for
        #   the close notify alert from client. When you need a different shutdown
        #   approach you can use one of the following variables:
        #   o ssl-unclean-shutdown:
        #     This forces an unclean shutdown when the connection is closed, i.e. no
        #     SSL close notify alert is send or allowed to received.  This violates
        #     the SSL/TLS standard but is needed for some brain-dead browsers. Use
        #     this when you receive I/O errors because of the standard approach where
        #     mod_ssl sends the close notify alert.
        #   o ssl-accurate-shutdown:
        #     This forces an accurate shutdown when the connection is closed, i.e. a
        #     SSL close notify alert is send and mod_ssl waits for the close notify
        #     alert of the client. This is 100% SSL/TLS standard compliant, but in
        #     practice often causes hanging connections with brain-dead browsers. Use
        #     this only for browsers where you know that their SSL implementation
        #     works correctly.
        #   Notice: Most problems of broken clients are also related to the HTTP
        #   keep-alive facility, so you usually additionally want to disable
        #   keep-alive for those clients, too. Use variable "nokeepalive" for this.
        #   Similarly, one has to force some clients to use HTTP/1.0 to workaround
        #   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
        #   "force-response-1.0" for this.
        BrowserMatch "MSIE [2-6]" \
                nokeepalive ssl-unclean-shutdown \
                downgrade-1.0 force-response-1.0
        # MSIE 7 and newer should be able to use keepalive
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

</VirtualHost>
</IfModule>

Configuration Headers

Comme décrit dans l'installation de l'application OwnCloud, la configuration du host peut être complété afin d'augmenter la sécurité. Cela nécessite la disponibilité du module mod_headers. Pour une installation sous Ubuntu, ce module peut être présent. il suffit de vérifier sa présence dans le répertoire /etc/apache2/mods-available.

#ll /etc/apache2/mods-available/headers.load
-rw-r--r-- 1 root root 66 nov.  18  2010 /etc/apache2/mods-available/headers.load

Dans ce cas, le module est installé et il faut s'assurer qu'il est activé, en vérifiant la présence du lien dans /etc/apache2/mods-enabled.

#ll /etc/apache2/mods-enabled/headers.load
lrwxrwxrwx 1 root root 30 oct.  10 01:22 /etc/apache2/mods-enabled/headers.load -> ../mods-available/headers.load

Si tel n'est pas le cas, il faut l'activer avec la commande a2enmod, et redémarrer l'instance Apache.

#sudo a2enmod headers
#sudo apache2 -k graceful

Une fois activer, il faut modifier la configuration du site, fichier .conf dans le répertoire /etc/apache2/sites-enabled, en ajoutant le ces instructions suivantes.

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
        ServerAdmin webmaster@localhost

        <IfModule mod_headers.c>
                Header always set Strict-Transport-Security "max-age=15768000;"
        </IfModule>

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined

        Alias /doc/ "/usr/share/doc/"
        <Directory "/usr/share/doc/">
                Options Indexes MultiViews FollowSymLinks
                AllowOverride None
                Order deny,allow
                Deny from all
                Allow from 127.0.0.0/255.0.0.0 ::1/128
        </Directory>

        #   SSL Engine Switch:
        #   Enable/Disable SSL for this virtual host.
        SSLEngine on

        #   A self-signed (snakeoil) certificate can be created by installing
        #   the ssl-cert package. See
        #   /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
        #   If both key and certificate are stored in the same file, only the
        #   SSLCertificateFile directive is needed.
        # SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
        SSLCertificateFile    /etc/ssl/certs/jouvinio.pem
        # SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
        SSLCertificateKeyFile /etc/ssl/private/jouvinio.key

        #   Server Certificate Chain:
        #   Point SSLCertificateChainFile at a file containing the
        #   concatenation of PEM encoded CA certificates which form the
        #   certificate chain for the server certificate. Alternatively
        #   the referenced file can be the same as SSLCertificateFile
        #   when the CA certificates are directly appended to the server
        #   certificate for convinience.
        #SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt

        #   Certificate Authority (CA):
        #   Set the CA certificate verification path where to find CA
        #   certificates for client authentication or alternatively one
        #   huge file containing all of them (file must be PEM encoded)
        #   Note: Inside SSLCACertificatePath you need hash symlinks
        #         to point to the certificate files. Use the provided
        #         Makefile to update the hash symlinks after changes.
        #SSLCACertificatePath /etc/ssl/certs/
        #SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt

        #   Certificate Revocation Lists (CRL):
        #   Set the CA revocation path where to find CA CRLs for client
        #   authentication or alternatively one huge file containing all
        #   of them (file must be PEM encoded)
        #   Note: Inside SSLCARevocationPath you need hash symlinks
        #         to point to the certificate files. Use the provided
        #         Makefile to update the hash symlinks after changes.
        #SSLCARevocationPath /etc/apache2/ssl.crl/
        #SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl

        #   Client Authentication (Type):
        #   Client certificate verification type and depth.  Types are
        #   none, optional, require and optional_no_ca.  Depth is a
        #   number which specifies how deeply to verify the certificate
        #   issuer chain before deciding the certificate is not valid.
        #SSLVerifyClient require
        #SSLVerifyDepth  10

        #   Access Control:
        #   With SSLRequire you can do per-directory access control based
        #   on arbitrary complex boolean expressions containing server
        #   variable checks and other lookup directives.  The syntax is a
        #   mixture between C and Perl.  See the mod_ssl documentation
        #   for more details.
        #<Location />
        #SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
        #            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
        #            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
        #            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
        #            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
        #           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
        #</Location>

        #   SSL Engine Options:
        #   Set various options for the SSL engine.
        #   o FakeBasicAuth:
        #     Translate the client X.509 into a Basic Authorisation.  This means that
        #     the standard Auth/DBMAuth methods can be used for access control.  The
        #     user name is the `one line' version of the client's X.509 certificate.
        #     Note that no password is obtained from the user. Every entry in the user
        #     file needs this password: `xxj31ZMTZzkVA'.
        #   o ExportCertData:
        #     This exports two additional environment variables: SSL_CLIENT_CERT and
        #     SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
        #     server (always existing) and the client (only existing when client
        #     authentication is used). This can be used to import the certificates
        #     into CGI scripts.
        #   o StdEnvVars:
        #     This exports the standard SSL/TLS related `SSL_*' environment variables.
        #     Per default this exportation is switched off for performance reasons,
        #     because the extraction step is an expensive operation and is usually
        #     useless for serving static content. So one usually enables the
        #     exportation for CGI and SSI requests only.
        #   o StrictRequire:
        #     This denies access when "SSLRequireSSL" or "SSLRequire" applied even
        #     under a "Satisfy any" situation, i.e. when it applies access is denied
        #     and no other module can change it.
        #   o OptRenegotiate:
        #     This enables optimized SSL connection renegotiation handling when SSL
        #     directives are used in per-directory context.
        #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
        </Directory>

        #   SSL Protocol Adjustments:
        #   The safe and default but still SSL/TLS standard compliant shutdown
        #   approach is that mod_ssl sends the close notify alert but doesn't wait for
        #   the close notify alert from client. When you need a different shutdown
        #   approach you can use one of the following variables:
        #   o ssl-unclean-shutdown:
        #     This forces an unclean shutdown when the connection is closed, i.e. no
        #     SSL close notify alert is send or allowed to received.  This violates
        #     the SSL/TLS standard but is needed for some brain-dead browsers. Use
        #     this when you receive I/O errors because of the standard approach where
        #     mod_ssl sends the close notify alert.
        #   o ssl-accurate-shutdown:
        #     This forces an accurate shutdown when the connection is closed, i.e. a
        #     SSL close notify alert is send and mod_ssl waits for the close notify
        #     alert of the client. This is 100% SSL/TLS standard compliant, but in
        #     practice often causes hanging connections with brain-dead browsers. Use
        #     this only for browsers where you know that their SSL implementation
        #     works correctly.
        #   Notice: Most problems of broken clients are also related to the HTTP
        #   keep-alive facility, so you usually additionally want to disable
        #   keep-alive for those clients, too. Use variable "nokeepalive" for this.
        #   Similarly, one has to force some clients to use HTTP/1.0 to workaround
        #   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
        #   "force-response-1.0" for this.
        BrowserMatch "MSIE [2-6]" \
                nokeepalive ssl-unclean-shutdown \
                downgrade-1.0 force-response-1.0
        # MSIE 7 and newer should be able to use keepalive
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

</VirtualHost>
</IfModule>


Viewer icon.png Voir aussi

Documentation Ubuntu: http://doc.ubuntu-fr.org/tutoriel/securiser_apache2_avec_ssl

Dans cet article, un certificat est généré par domaine / sous-domaine. Il peut donc être contraignant d'utiliser cette méthode lors de l'utilisation d'un grand nombre de sous domaine. Il est cependant possible de générer un certificat pour tous les sous domaines, en indiquant *.jouvinio.net par exemple, lors du renseignement du paramètre Common Name au moment de la génération du certificat. Ce certificat "global" pourra alors être utilisé dans une configuration commune des Hosts, après activation du module vhost_alias.

Ce type de configuration est détaillé à l'URL http://phaseshiftllc.com/articles/2008/10/27/multiple-secure-subdomains-with-a-wildcard-ssl-certificate.html