Obtaining a certificate *directly* from a server / Obtenir un certificat *directement* depuis le serveur

I posted this tip on the Entourage newsgroup and I’m reposting it here to allow suggestions before I submit it as a new item in the Entourage FAQ. I’ll also ask the OmniGroup people if they don’t mind… :

Some servers use self signed certificates and Entourage complains that the certificate is unknown.

To get the cert, you can of course request it from the Administrator, but in more than one case, the admin doesn’t send the cert and people are left out with the warning every time they try to get their mail over SSL.

Here is what the OmniWeb Help offers as a workaround:

OmniWeb Help > Avanced Topics:

If that doesn’t work, then you can ask the server itself for its certificates. Open a Terminal window and type openssl s_client -showcerts -connect SERVERHOSTNAME:443 (where SERVERHOSTNAME is, of course, the server’s hostname. The “443” is the normal port number for HTTPS.) This should spit out a few pages of information, starting with the word “CONNECTED” and ending with a line of three dashes. Hit control-C to quit openssl.

In the middle of the output should be the certificate chain offered by the server. There might just be one certificate, or there might be several. The first certificate is the server’s own certificate. The next one is the certificate of whoever issued the server’s certificate, followed by whoever issued that cert, and so on until you reach the root of authority. That last one is the one you want. Copy-and-paste it (including the BEGIN/END lines) into a text file, ideally one whose name ends in “.pem”.

2. Put the certificate where OmniWeb will find it.

I recommend using the keychain, because then you can see (and delete) the certificate using Keychain Access. To add a certificate (in .pem format) to your keychain, type the following command in a terminal window:

certtool i /path/to/pemfile

You can do this by just typing certtool i , with the trailing space, and then dragging the .pem file’s icon onto the window. Anyway, certtool should respond “certificate successfully imported”, and you can then see the certificate in Keychain Access and it will be used by OmniWeb.

If you want to store the cert in one of the RootCerts.pem files mentioned above, you can just move/rename the .pem file you have, or (if the other .pem file already exists) append the new block of text to the existing list of certs. The order of certs in a .pem file doen’t matter.

Example of a certificate in .PEM format

This is the relevant snippet of the output of “openssl s_client…” talking to my test webserver:

2 s:/C=US/ST=Washington/L=Seattle/O=JJJJ Associates/OU=Dummy
Security/Email=user@nulljjjj.org
i:/C=US/ST=Washington/L=Seattle/O=JJJJ Associates/OU=Dummy
Security/Email=user@nulljjjj.org
—–BEGIN CERTIFICATE—–
MIICgDCCAemgAwIBAgIBADANBgkqhkiG9w0BAQQFADCBhTELMAkGA1UEBhMCVVMx
EzARBgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcTB1NlYXR0bGUxGDAWBgNVBAoT
D0hISEggQXNzb2NpYXRlczEXMBUGA1UECxMORHVtbXkgU2VjdXJpdHkxHDAaBgkq
hkiG9w0BCQEWDXdpbWxAaGhoaC5vcmcwHhcNMDMwODE4MjAxMDA3WhcNMDQwODE3
MjAxMDA3WjCBhTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCldhc2hpbmd0b24xEDAO
BgNVBAcTB1NlYXR0bGUxGDAWBgNVBAoTD0hISEggQXNzb2NpYXRlczEXMBUGA1UE
CxMORHVtbXkgU2VjdXJpdHkxHDAaBgkqhkiG9w0BCQEWDXdpbWxAaGhoaC5vcmcw
gZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALTFv4ts52lXl0aomu9/LaOfiUZx
Jdtb3BfSKkem2feD0AhAIX/1k1KLiOi6PB3aRGyXwxs5AOPxjloc/q6mpGRaJy/w
nJ/LfSG6TSsvrVY4Ksu2rTAQ9Io35PX1OUsgHDWkKOwHoAzLNgK7Q9I2lflDSPuZ
6Sk748VhDvzGSBEBAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAhUnqFeO30hr7N888
NnQT/aDuJL8MoDqQkSkXUdVj+5F2m/Ssf7mqApKh/2GiXkL2cJ38XfWXi+gLFgv/
Do8cuh3h2oBxY7ylrBD9AmFHa8oRQboS4npV9GVgue/K/YtxqQOrrW2IY3Ikm6RY
ln6CdGy7bmMRr5qMuDxhlT37Cg0=
—–END CERTIFICATE—–

The certificate is the stuff from BEGIN CERTIFICATE to END CERTIFICATE (inclusive). The two lines before it are from OpenSSL describing what
the certificate is. The s: line indicates the subject, i.e., who or what the certificate is for. The i: line indicates the issuer, i.e., who is
vouching for the subject’s authenticity. Since this is the root cert, the two lines are the same. Subjects and issuers are described in the
X.500 format; the example here includes the country, state, city (locality), organization, organizational sub-unit (the “Dummy Security”
department of “JJJJ Associates”), and email address

Posté dans le forum Entourage US :

En lisant l’aide d’OmniWeb, j’ai découvert une information particulièrement intéressante permettant d’importer un certificat directement depuis un serveur. Celà permet aux utilsateurs auxquels l’administrateur réseau ne veux pas prendre le temps de fournir le certificat de l’ajouter correctement à leur trousseau d’accès pour toutes les applciations (dont Entourage).

Avant de le soumettre à la FAQ Entourage (US) (Après avoir demandé la permission à OmniGroup) voici ce qu’indique l’aide: :

Si la première solution ne marche pas, vous pouvez requérir le certificat sur le serveur directement. Ouvrez une fenêtre de Terminal et tapez openssl s_client -showcerts -connect NOMDUSERVEUR:443 (NOMDUSERVEUR étant, bien sûr le nom du serveur. Le port “443” est le port traditionnel pour le HTTPS.) Vous devriez ainsi obtenir plusieurs pages d’informations, commençant par le mot “CONNECTED” et se terminant par une ligne avec trois tirets. Pressez Contrôle-c pour quitter la commande openssl.

Au milieu des résultats de la commande se trouvent la chaîne de caractères du certificat du serveur. Il se peut qu’il n’y ait là qu’un seul certificat, ou plusieurs. Le premier certificat est celui que le serveur utilise. Le suivant est celui de l’Autorité ayant émis le certificat du serveur, suivi pas qui que ce soit qui ait émis ce certificat et ainsi de suite jusqu’à ce que vous atteignez la racine des Autorité des certificats. Le dernier est celui que vous voulez. Copiez-collez ce certificat (y compris les lignes contenant BEGIN et END) dans un document texte brut, de préférence avec une extension “.pem”.

2. Placez le certificat là où OmniWeb peut le trouver.

Je recommande d’utiliser le trousseau d’accès car vous pouvez l’utiliser pour visualiser (et effacer) le certificat. Pour ajouter un certificat (au format .pem) à votre trousseau, utilisez la commande suivante dans le Terminal :

certtool i /chemin/vers/fichier.pem

Vous pouvez faire ça en tapant certtool -i suivi d’un espace et en glissant le fichier dans la fenêtre du Terminal. De toute façon, certtool devrait renvoyer “certificate successfully imported”, et vous devriez alors pouvoir voir le certificat dans le Trousseau d’accès et l’utiliser dans OmniWeb.

Si vous voulez stocker le certificat dans un des fichiers RootCerts.pem mentionné précédemment, vous pouvez vous contenter de déplacer/renommer le fichier .pem, ou (si un autre fichier .pem existe déjà) ajouter le bloc de texte dans la liste des certificats du fichier. L’ordre des certificats dans le fichier est sans importance.

Exemple de certificat au format .PEM

Voici l’extrait requis lorsque je lance “openssl s_client…” pour mon serveur test :

2 s:/C=US/ST=Washington/L=Seattle/O=JJJJ Associates/OU=Dummy Security/Email=user@nulljjjj.org
i:/C=US/ST=Washington/L=Seattle/O=JJJJ Associates/OU=Dummy Security/Email=user@nulljjjj.org
—–BEGIN CERTIFICATE—–
MIICgDCCAemgAwIBAgIBADANBgkqhkiG9w0BAQQFADCBhTELMAkGA1UEBhMCVVMx
EzARBgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcTB1NlYXR0bGUxGDAWBgNVBAoT
D0hISEggQXNzb2NpYXRlczEXMBUGA1UECxMORHVtbXkgU2VjdXJpdHkxHDAaBgkq
hkiG9w0BCQEWDXdpbWxAaGhoaC5vcmcwHhcNMDMwODE4MjAxMDA3WhcNMDQwODE3
MjAxMDA3WjCBhTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCldhc2hpbmd0b24xEDAO
BgNVBAcTB1NlYXR0bGUxGDAWBgNVBAoTD0hISEggQXNzb2NpYXRlczEXMBUGA1UE
CxMORHVtbXkgU2VjdXJpdHkxHDAaBgkqhkiG9w0BCQEWDXdpbWxAaGhoaC5vcmcw
gZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALTFv4ts52lXl0aomu9/LaOfiUZx
Jdtb3BfSKkem2feD0AhAIX/1k1KLiOi6PB3aRGyXwxs5AOPxjloc/q6mpGRaJy/w
nJ/LfSG6TSsvrVY4Ksu2rTAQ9Io35PX1OUsgHDWkKOwHoAzLNgK7Q9I2lflDSPuZ
6Sk748VhDvzGSBEBAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAhUnqFeO30hr7N888
NnQT/aDuJL8MoDqQkSkXUdVj+5F2m/Ssf7mqApKh/2GiXkL2cJ38XfWXi+gLFgv/
Do8cuh3h2oBxY7ylrBD9AmFHa8oRQboS4npV9GVgue/K/YtxqQOrrW2IY3Ikm6RY
ln6CdGy7bmMRr5qMuDxhlT37Cg0=
—–END CERTIFICATE—–

Le certificat est le bidule entre BEGIN CERTIFICATE et END CERTIFICATE (compris). Les deux lignes juste avant proviennent d’OpenSSL et décrivent ce à quoi correspond le certificat. La ligne s : donne le sujet, par ex. pour qui ou pour quoi le certificat est émis. La ligne i: indique qui a émis le certificat, par ex. qui atteste de son authenticité. Comme il s’agit ici du certificat “root”, les deux lignes sont identiques. Sujet et émetteur sont décrits dans le format X.500; l’exemple cité ici inclus le pays, l’état, la ville (localité), l’organisation, la sous-division de l’organisation (le département lambda de “JJJJ Associates”), et l’adresse e-mail.