Complete Virtual Mail Server/SSL Certificates/ru

Введение
With security and privacy being a increasingly important issue nowadays, Using SSL to secure the server seems like a no-brainer. Apache, Courier-imap and postfix all can be secured using SSL.

Установка SSL
SSL is a dependency and a compile time option to most packages. being the key ingredient, should be pulled in from the  USE flag. If it wasn't set before enable it and update all packages using it:

SNI
There are a few issues that arise when using multiple domains on a single IP. Apache has solved this issue using SNI that makes it possible to have several certificates on a single IP. Both the browser and the server need to support this however. IMAP (and POP3) nor SMTP really support this. The only real way to support multiple hosts on a single IP is have a certificate, that covers all domains. Not pretty but can work.

Получение SSL-сертификата
There are currently 2 and a half ways to obtain an SSL certificate. Purchase a certificate from one of the reputable providers is an option. Using a self-signed certificate can also be done, though may have implications with warnings on users clients. The half option, which is the recommended option when not using a bought certificate is using a certificate from [//cacert.org cacert.org]. They are working hard on getting their certificate included into the main browsers and operating systems, but most of all, it is free and gratis.

Самоподписанный сертификат
Большинство приложений предварительно генерируют самоподписанные сертификат и, как правило, затем устанавливают их в каталог. Новый самоподписанный сертификат легко может быть создан с помощью OpenSSL:

Это должно было создать три файла:, , , и еще в компанию к ним CA Root сертификат. Рекомендуется переименовать их в что-то более логичное.

Подписанный CACert.org
CACert.org offers a simple script to assist with generating SSL certificates. The [//wiki.cacert.org/CSRGenerator csr] script should be downloaded and executed. In this example, the mail server will be called imap but will have aliases configured in DNS for mail, pop, pop3, pop3s, imaps and foo. More can be added of course as fit. Note that foo was added because that is the name of the system offering the imap service. It is not named foo because the postfix or web or any other server is named foo.

This has generated a certificate sign request, which can be used by any root CA to sign with, not only CACert.org. In the case of CACert.org however, under Server Certificates there is a link named New which opens an edit box for the above certificate request. The bit including  until, including   needs to be pasted into the edit field and then submitted via the submit button. The server will then verify the request and upon that generate the certificate. The certificate then needs to be copied and pasted, including the  and   markers again into a new file, named. A link to the certificate will also be e-mailed to the e-mail address bound to the ca-cert.org account.

This should leave 3 files,. This will also be the naming convention followed during the rest of this document.

Apache
Настройка Apache уже хорошо описана в другом месте и в конце дает рабочий веб-сервер с поддержкой SSL. Postfixadmin, если он общедоступен, в идеальном случае должен быть защищен и работать только через https. Roundcube или webmail в целом, можно также настроить, чтобы они были защищены SSL, но могут работать и по обычному HTTP.

Roundcube has one nice option for this however, to force all incoming requests over HTTPS. This means that when a users opens http://webmail.example.com, he will get immediately redirected to https://webmail.example.com. If using a proper SSL certificate this is strongly recommended. When using a self-signed certificate, or a CA-cert.org certificate that does not have the root installed to all users, this should remain off however.

Courier-imap
If anything, securing IMAP with SSL is extremely recommended. Using a secure connection for IMAP, means that if the password is sent in plain text, this is still done over the secured IMAP connection so no security issue comes up.

Создание самоподписанного сертификата
Courier-imap comes with two easy scripts to generate self-signed SSL certificates, and. These scripts parse and  respectively. It may be an idea to first use self-signed certificates and then swap those out for signed certificates as it can make testing a little bit easier. If self-signed certificates are a must, edit the aforementioned files, otherwise the defaults will suffice.

Использование сертификата подписанного CACert.org
Сценарий создает самоподписанные сертификаты и объединяет их в один файл, так как Courier-imap не использует три раздельных файла, как это делают большинство приложений, а нуждается в специально отформатированном файле.

Файл начинается с закрытого ключа.

Затем следует подписанный сертификат:

И в конец, добавляется параметры Диффи-Хеллмана:

В конечном итоге содержимое файла должно выглядеть так:

Настройка SSL
As noted above, the certificate entails both pop3 as imap hostnames and it is thus assumed pop3 and imap are running on the same IP/host. This is not required however, pop3 could be very well a different machine with the same (not advised) or its own certificate.

POP3
Starting this server should allow pop3 to work through SSL:

IMAP
Starting this server should allow imap to work through SSL:

Тестирование SSL
Testing becomes more difficult, as telnet can not be used anymore. The best option is to start up a mail-client such as thunderbird, configure a normal connection first to verify everything works, which should as telnet worked properly before and then enable the SSL option for the account and see if it is still working. The default imap-ssl port is 993. can be checked whether it is enabled only, via telnet, by checking for the STARTTLS Capability.

Если защищенные SSL сервисы работают хорошо, они могут быть добавлены в уровень запуска по умолчанию:

Защита SMTP с помощью SSL
The certificates for use with postfix should be stored in or if using the same certificates as with courier-imap they should be stored in. If using CACert.org, then its root certificate needs to be used. Gentoo pre-installs the CACert.org root certificate and should be used.

Now STARTTLS can be used to use an authenticated connection over port 25. SSL/TLS support on port 465 (smtps) however should be enabled as well. Courier-imap did this automatically, postfix needs a change to :

Перезапустите postfix, чтобы запустить демонов в защищенном SSL-режиме:

Тестирование
Telnet can only be minimally used for testing. Actually it can only be used to verify supported options. STARTTLS should be listed as one of the supported options:

To test if all connections work as wanted, a recent version of Thunderbird works best. When adding a new account, Thunderbird will try to connect using STARTTLS on the default port. If that would fail, or if a manual connection is tried, it's possible to use SSL/TLS via the 993 and 465 ports and hit the re-test button. This should allow the account to be created using secure connections.

Защита соединений от-сервера-к-серверу
Postfix can try to use secure connections for sending mails to other SMTP servers. Although it may not be supported by all servers, it makes sense to activate it.

Перезапустите postfix после этого:

To test if it works, a mail can be sent to an address, which uses a server that supports TLS. The log should then contain a line like this:

Заключение
Ведение журнала можно отключить снова, если все работает хорошо: