Toujours sur Cheyenne, voici un billet concernant la génération de certificats SSL.

Ceux qui auront essayé Stunnel auront noté que le certificat fourni est légérement vieillot.
Je vous propose donc ici la méthodologie pour en créer un, mais sur un domaine "localhost".
A vous donc d'adapter ce tutoriel pour un autre domaine.

Pré-requis :
Avoir OpenSSL installé sur l'ordinateur, voir www.openSSL.org.

1/ Créer une clé privée

La première étape consiste à créer une clé privée.
Voici ma "passphrase" pour cet exemple : La lune luit au fond des bois
La clé RSA sur 1024 bit est cryptée en utilisant l'alogrythme Triple-DES et sera stockée dans un format PEM, c'est-à-dire un
format ASCII.

Lancez le binaire OpenSSL pour avoir la console :

openSSL>

et tapez les commandes suivantes :

genrsa -des3 -out localhost.key 1024

Puis, à l'invite de commande, saisissez deux fois la passphrase :
Loading 'screen' into random state - done
Generating RSA private key, 1024 bit long modulus
..............................................................................++++++
....++++++
e is 65537 (0x10001)
Enter pass phrase for localhost.key:
Verifying - Enter pass phrase for localhost.key:

2/ Générer un certificat CSR auto-signé :

Une fois la clé privée générée, on peut créer le certificat.
Deux options : soit le certificat est envoyé à une autorité de certification comme Verisign, soit il est "auto-signé".
C'est cette deuxième option que nous allons voir.

Toujours à l'invite de commande OpenSSL, saisir :

req -new -key localhost.key -out localhost.csr

saisir la passphrase
puis renseigner les champs tels que :

Enter pass phrase for localhost.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]:FR
State or Province Name (full name) [Some-State]:France
Locality Name (eg, city) []:Paris
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Me
Organizational Unit Name (eg, section) []:Moi
Common Name (eg, YOUR name) []:localhost
Email Address []:

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

Notez en particulier le Common Name (CN).

Dans le cas d'Apache, à chaque démarrage, la passphrase serait demandée.
Ici on retire cette passphrase par les opérations suivantes :

Copier le fichier localhost.key en localhost.key.org dans votre répertoire.

Puis dans la console OpenSSL, tapez la commande suivante :

rsa -in localhost.key.org -out localhost.key

Saisir la passphrase :
Enter pass phrase for localhost.key.org:
writing RSA key


3/ Génération du certificat auto-signé :

Dans la console OpenSSL, tapez la ligne :

x509 -req -days 365 -in localhost.csr -signkey localhost.key -out localhost.crt

qui renvoie :
Loading 'screen' into random state - done
Signature ok
subject=/C=FR/ST=France/L=Paris/O=Me/OU=Moi/CN=localhost
Getting Private key


4/ Installation dans stunnel :

Créez un fichier localhost.pem qui est la concaténation de la clé privée (localhost.key) et du certificat (localhost.crt).
Normalement vous devrez avoir quelque chose comme ceci :

-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDU1t99yrXv3eV+RDU2z69ATCnMU8uFhZ7YGyfaEi2pbvtRfG9o
eG5c5cToT7CMCAJQ4Ruerr7La13r7fsEWzW7iSk0RsMWpn1aCY82dEScIuVOu3S1
NLerFfBtxE0eJ6ZOelh5doe/0y56NEa12DzCfGk3ZDwAHJO3TsS2E+sf7QIDAQAB
AoGBALhBzPl5pEgkMak+I1NwOKfRR948LNVK+FjeKYIAesdT7P5+W3R1zhVeVTlI
w+52gIrEVsTpQwOXz5eQTt9WlwxOKp/bNALvs1Eln/PpfrcCOjGt5Tr1U1VVVu7t
tLiui8WQktqzuJCs7nFHT0dod2QfwQ0f0RnGmh8OoS5a05wBAkEA/HWKp5pYa1sn
dWtNWpNFrwjktr+0fd7d22HmLYblyeZKqcexzt2gMWJ0yYVsH7PGCXvFbmcvHQcI
L3Gej+iruQJBANfTE26OHKTensHViXkMlrN1YCnbFM8KImDom8hIbetf5/bc0k9b
RJIQCTejnzxd5tSnpcqq1BFdJ6WauNCrt9UCQGjJWO3MMJsO0Mf567eGnUvTgysf
UwlTsf5XGjUXYtV0ktT5oCHe95jH5vWmPYTDF5XkG8SBa5q+ynT20fuldXECQBO/
x95s+KgJiwN3s8203jFrwzHxTzUm20B86IxqPEy2iPZo/IGwe1TWTNGfklmmyhGZ
ia1C9obkPFWGE/VcUUUCQElxarhciOYId7i+JcLsjjKJAY8q3hLB5/hZmvo7844M
CkweIk+nI6CDIpG6GN7mOeTFwpZClTQcULSm7ZsVVRw=
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
MIICMTCCAZoCCQCsx5t0VgDuQDANBgkqhkiG9w0BAQUFADBdMQswCQYDVQQGEwJG
UjEPMA0GA1UECBMGRnJhbmNlMQ4wDAYDVQQHEwVQYXJpczELMAkGA1UEChMCTWUx
DDAKBgNVBAsTA01vaTESMBAGA1UEAxMJbG9jYWxob3N0MB4XDTA3MDcxMjIyMDMx
MVoXDTA4MDcxMTIyMDMxMVowXTELMAkGA1UEBhMCRlIxDzANBgNVBAgTBkZyYW5j
ZTEOMAwGA1UEBxMFUGFyaXMxCzAJBgNVBAoTAk1lMQwwCgYDVQQLEwNNb2kxEjAQ
BgNVBAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA1Nbf
fcq1793lfkQ1Ns+vQEwpzFPLhYWe2Bsn2hItqW77UXxvaHhuXOXE6E+wjAgCUOEb
nq6+y2td6+37BFs1u4kpNEbDFqZ9WgmPNnREnCLlTrt0tTS3qxXwbcRNHiemTnpY
eXaHv9MuejRGtdg8wnxpN2Q8AByTt07EthPrH+0CAwEAATANBgkqhkiG9w0BAQUF
AAOBgQCCoFNCJtOmFS+8s01N0rFmzor4KvmHdMZrHnXacSt9b0YAmAdq9mrCwf5Q
bCf4rPMyerbPXjokf2/gjpcYvpqfZxQpCtdtbKDJcZyqNifoZ0mm8a3fq5SEjlrm
wQLm6UNSBnJeVEgoLpB1tlVzBQTqPcZnCbY9ycbtL5q1j2H4oQ==
-----END CERTIFICATE-----


Puis, copiez ce fichier dans le répertoire de Stunnel.

Enfin, dans le fichier de configuration de Stunnel (stunnel.conf), modifiez les lignes faisant référence au certificat et à la clé,
en mettant les lignes ainsi :

cert = localhost.pem
key = localhost.pem

Puis, arrétez et relancez Stunnel (stop/start) pour que les modifications soient prises en compte.


5/ Test de la configuration

Après avoir lancé Cheyenne, ouvrez votre navigateur et appelez l'URL : https://localhost/

le dialogue d'information pour le certificat devrait ressembler à ceci :



et le détail à ceci :




6 / Bonus avec Apache/mod-ssl :

Dans le cas où on utilise Apache avec mod_ssl au lieu de stunnel+Cheyenne, il est possible d'utiliser le fichier de certificat et celui de la clé privée ainsi :
Lorsque mod_ssl est installé, Apache crée plusieurs sous-dossiers dans son répertoire de configuration (conf).
Leur position peut varier, ce qui suit est donc à adapter.
Copier vos fichiers (certificats et clé) vers le répertoire conf d'Apache :
cp localhost.crt /usr/local/apache/conf/ssl.crt
cp localhost.key /usr/local/apache/conf/ssl.key


Il faut également configurer dans le fichier httpd.conf les infos suivantes :

SSLEngine on
SSLCertificateFile /usr/local/apache/conf/ssl.crt/localhost.crt
SSLCertificateKeyFile /usr/local/apache/conf/ssl.key/localhost.key
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

Puis relancez Apache et testez :

/etc/init.d/httpd stop
/etc/init.d/httpd start

Et dans un navigateur :

https://localhost/


===Philippe