<?xml version="1.0" encoding="utf-8"?> 
<rss version="2.0"
  xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
  xmlns:atom="http://www.w3.org/2005/Atom">

<channel>

<title>Заметки Александра Чернышева: заметки с тегом ssl</title>
<link>https://aschernyshev.ru/tags/ssl/</link>
<description>Keep in mind</description>
<author>Александр Чернышев</author>
<language>ru</language>
<generator>E2 (v3576; Aegea)</generator>

<itunes:owner>
<itunes:name>Александр Чернышев</itunes:name>
<itunes:email></itunes:email>
</itunes:owner>
<itunes:subtitle>Keep in mind</itunes:subtitle>
<itunes:image href="" />
<itunes:explicit></itunes:explicit>

<item>
<title>HTTP/2.0 в Nginx на CentOS 7</title>
<guid isPermaLink="true">https://aschernyshev.ru/all/http-2-0-v-nginx-na-centos-7/</guid>
<link>https://aschernyshev.ru/all/http-2-0-v-nginx-na-centos-7/</link>
<pubDate>Wed, 12 Jul 2017 12:03:18 +0300</pubDate>
<author>Александр Чернышев</author>
<comments>https://aschernyshev.ru/all/http-2-0-v-nginx-na-centos-7/</comments>
<description>
&lt;p&gt;&lt;b&gt;UPD&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Вышло обновление openssl-1.0.2k и даное руководство больше не актуально.&lt;/b&gt;&lt;br /&gt;
_____________________________________________________________________&lt;/p&gt;
&lt;p&gt;Решил включить HTTP/2.0 в Nginx. В процессе тестирование, при прохождении &lt;a href="https://tools.keycdn.com/http2-test"&gt;теста&lt;/a&gt;  выяснилось, что не активно &lt;a href="https://en.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation"&gt;ALPN&lt;/a&gt; (Application-Layer Protocol Negotiation).&lt;/p&gt;
&lt;p&gt;Для полноценной работы HTTP/2.0, Nginx должен быть собран с &lt;a href="http://xgu.ru/wiki/OpenSSL"&gt;OpenSSL&lt;/a&gt; версии не ниже чем 1.0.2. В репах CentOS есть только OpenSSL версии 1.0.1.&lt;br /&gt;
Решить эту проблему можно двумя способами: собрать Nginx с флагом &lt;a href="https://victor.4devs.io/ru/architecture/nginx-http2-does-not-work.html"&gt;—with-openssl&lt;/a&gt; или собрать OpenSSL 1.0.2 для CentOS.&lt;br /&gt;
Первый вариант у меня не взлетел, сборка пакета завершалась неудачно, поэтому я остановился на втором варианте.&lt;br /&gt;
В интернет нашел &lt;a href="http://ja.528p.com/linux/centos6/XE001-openssl.html"&gt;сайт&lt;/a&gt;, где автор предлагает пачтить сорцы OpenSSL, но недавно в CentOS прилетело обновление glibc-2.17.&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;rpm -qa | grep glibc
glibc-common-2.17-157.el7_3.4.x86_64
glibc-2.17-157.el7_3.4.x86_64
glibc-devel-2.17-157.el7_3.4.x86_64
glibc-headers-2.17-157.el7_3.4.x86_64&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;readelf -s /usr/lib64/libc.so.6 | grep secure_getenv&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;614: 0000000000038950    27 FUNC    WEAK   DEFAULT   12 __libc_secure_getenv@@GLIBC_PRIVATE
857: 0000000000038950    27 FUNC    WEAK   DEFAULT   12 __secure_getenv@GLIBC_2.2.5
1715: 0000000000038950    27 FUNC    WEAK   DEFAULT   12 secure_getenv@@GLIBC_2.17
5228: 0000000000038950    27 FUNC    LOCAL  DEFAULT   12 __GI___libc_secure_getenv
6506: 0000000000038950    27 FUNC    WEAK   DEFAULT   12 __secure_getenv@GLIBC_2.2
6529: 0000000000038950    27 FUNC    WEAK   DEFAULT   12 secure_getenv
6918: 0000000000038950    27 FUNC    WEAK   DEFAULT   12 __libc_secure_getenv&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Так что ничего патчить не нужно, а просто собираем &lt;a href="https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/fedora/linux/releases/23/Workstation/source/SRPMS/o/openssl-1.0.2d-2.fc23.src.rpm"&gt;openssl&lt;/a&gt; из FC23. Дополнительно потребуется пересобрать еще один пакет из FC23 &lt;a href="https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/fedora/linux/releases/23/Workstation/source/SRPMS/c/crypto-policies-20150518-3.gitffe885e.fc23.src.rpm"&gt;crypto-policies&lt;/a&gt;.&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;yum install epel-release &amp;amp;&amp;amp; yum update &amp;amp;&amp;amp; yum install mock&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;mkdir -p ~/rpmbuild/{SPECS,SOURCES,SRPMS}&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;wget http://nginx.org/packages/centos/7/SRPMS/nginx-1.12.1-1.el7.ngx.src.rpm&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;rpm -ivh ~/nginx-1.12.1-1.el7.ngx.src.rpm&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;grep 'Requires: openssl &amp;gt;= 1.0.1' -P -R -I -l ~/rpmbuild/SPECS/nginx.spec | xargs sed -i 's/Requires: openssl &amp;gt;= 1.0.1/Requires: openssl &amp;gt;= 1.0.2/g'&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;grep 'BuildRequires: openssl-devel &amp;gt;= 1.0.1' -P -R -I -l ~/rpmbuild/SPECS/nginx.spec | xargs sed -i 's/BuildRequires: openssl-devel &amp;gt;= 1.0.1/BuildRequires: openssl-devel &amp;gt;= 1.0.2/g'&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;grep 'define main_release 1' -P -R -I -l  ~/rpmbuild/SPECS/nginx.spec | xargs sed -i 's/define main_release 1/define main_release 2/g'&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;grep '%changelog' -P -R -I -l  /root/rpmbuild/SPECS/nginx.spec | xargs sed -i 's/%changelog/%changelog\n* Wed Jul 12 2017 Aleksandr Chernyshev &amp;lt;mail@aschernyshev.ru&amp;gt;\n- 1.12.1 \n- Rebuild with openssl-1.0.2d\n/g'&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;/usr/bin/mock -r epel-7-x86_64 --spec=~/rpmbuild/SPECS/nginx.spec --sources=~/rpmbuild/SOURCES/ --resultdir=~/rpmbuild/SRPMS/ --no-clean --buildsrpm&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;wget https://aschernyshev.ru/repository/rhel/7/noarch/crypto-policies-20150518-3.gitffe885e.el7.centos.noarch.rpm
wget https://aschernyshev.ru/repository/rhel/7/x86_64/openssl-libs-1.0.2d-2.el7.centos.x86_64.rpm
wget https://aschernyshev.ru/repository/rhel/7/x86_64/openssl-1.0.2d-2.el7.centos.x86_64.rpm
wget https://aschernyshev.ru/repository/rhel/7/x86_64/openssl-devel-1.0.2d-2.el7.centos.x86_64.rpm&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;/usr/bin/mock -r epel-7-x86_64 --init
/usr/bin/mock -r epel-7-x86_64 --install ~/crypto-policies-20150518-3.gitffe885e.el7.centos.noarch.rpm
/usr/bin/mock -r epel-7-x86_64 --install ~/openssl-libs-1.0.2d-2.el7.centos.x86_64.rpm
/usr/bin/mock -r epel-7-x86_64 --install ~/openssl-1.0.2d-2.el7.centos.x86_64.rpm
/usr/bin/mock -r epel-7-x86_64 --install ~/openssl-devel-1.0.2d-2.el7.centos.x86_64.rpm
/usr/bin/mock -r epel-7-x86_64 --no-clean ~/rpmbuild/SRPMS/nginx-1.12.1-2.el7.centos.ngx.src.rpm&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Устанавливаем получившиеся &lt;a href="https://aschernyshev.ru/repository/rhel/7/noarch/crypto-policies-20150518-3.gitffe885e.el7.centos.noarch.rpm"&gt;crypto-policies&lt;/a&gt;, &lt;a href="https://aschernyshev.ru/repository/rhel/7/x86_64/openssl-1.0.2d-2.el7.centos.x86_64.rpm"&gt;openssl&lt;/a&gt;, &lt;a href="https://aschernyshev.ru/repository/rhel/7/x86_64/openssl-libs-1.0.2d-2.el7.centos.x86_64.rpm"&gt;openssl-libs&lt;/a&gt; , &lt;a href="https://aschernyshev.ru/repository/rhel/7/x86_64/nginx-1.12.1-2.el7.centos.ngx.x86_64.rpm"&gt;nginx&lt;/a&gt;.&lt;/p&gt;
</description>
</item>

<item>
<title>Получаем SSL сертификат Let’s Encrypt.</title>
<guid isPermaLink="true">https://aschernyshev.ru/all/poluchaem-ssl-sertifikat-lets-encrypt/</guid>
<link>https://aschernyshev.ru/all/poluchaem-ssl-sertifikat-lets-encrypt/</link>
<pubDate>Sat, 05 Nov 2016 16:35:21 +0300</pubDate>
<author>Александр Чернышев</author>
<comments>https://aschernyshev.ru/all/poluchaem-ssl-sertifikat-lets-encrypt/</comments>
<description>
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;sudo yum install epel-release
sudo yum install certbot&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;vi /etc/nginx/letsencrypt.conf&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;location ^~ /.well-known/acme-challenge {
    alias /var/lib/letsencrypt/.well-known/acme-challenge;
    default_type &amp;quot;text/plain&amp;quot;;
    try_files $uri =404;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;В конфигурационном файле хоста, секцию &lt;b&gt;server&lt;/b&gt;, include-ом добавляем конфиг.&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;vi /etc/nginx/conf.d/$HOST.conf&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;server {
    ...

    include letsencrypt.conf;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Изменяем группу и выставляем права.&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;chgrp nginx /var/lib/letsencrypt &amp;amp;&amp;amp; chmod g+s /var/lib/letsencrypt&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Получаем сертификат.&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;certbot certonly --webroot --email mail@example.com -w /var/lib/letsencrypt -d example.com -d www.example.com&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Сертификат действует &lt;b&gt;90 дней&lt;/b&gt;, после чего его необходимо продлить. Для автоматизации этой процедуры создаем &lt;b&gt;systemd.service&lt;/b&gt; и &lt;b&gt;systemd.timer&lt;/b&gt;.&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;/etc/systemd/system/certbot.service&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;[Unit]
Description=Renew Certbot certificate (nginx)
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew --renew-hook &amp;quot;/usr/bin/systemctl reload nginx.service&amp;quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Timer будет запускать основной сервис ежедневно  в &lt;b&gt;12&lt;/b&gt; и &lt;b&gt;00&lt;/b&gt; часов.&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;/etc/systemd/system/certbot.timer&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;[Unit]
Description=Daily renewal of Let's Encrypt's certificates

[Timer]
OnCalendar=*-*-* 00,12:00:00
Persistent=true

[Install]
WantedBy=timers.target&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Активируем timer.&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;sudo systemctl daemon-reload
systemctl start certbot.timer
systemctl enable certbot.timer&lt;/code&gt;&lt;/pre&gt;</description>
</item>


</channel>
</rss>