投げ銭

★当サイトへの投げ銭(PayPal)★

LINK


(無償、寄付歓迎) logo
世界中で使われるISO標準オフィスソフト(MSオフィス互換)

★LibreOfficeの導入事例★
詳細について

人気の投稿(1ヶ月間)

Ad

Ad

投げ銭

★当サイトへの投げ銭(PayPal)★

2022年3月5日土曜日

【Linux CentOS 7】ソースからOpenSSL(1.1.1m)を導入する手順【Dockerコンテナ】

 CentOS7の標準リポジトリが提供するOpenSSLは、次のコマンド結果が示すように、バージョン1.0.2kである。

# yum info openssl
Available Packages
Name        : openssl
Arch        : x86_64
Epoch       : 1
Version     : 1.0.2k
Release     : 24.el7_9
Size        : 494 k
Repo        : updates/7/x86_64
Summary     : Utilities from the general purpose cryptography library with TLS implementation
URL         : http://www.openssl.org/
License     : OpenSSL
Description : The OpenSSL toolkit provides support for secure communications between
            : machines. OpenSSL includes a certificate management tool and shared
            : libraries which provide various cryptographic algorithms and
            : protocols.
 そのため依存関係によりインストールできないソフトウェアがあった。
そこで、次のようにして、ソースからOpenSSL(1.1.1m)を導入した。

 以下で使用しているCentOS7は、特権Dockerコンテナで動作させている。



■Dockerコンテナの起動と接続

◯基本となるDockerコンテナを起動した。

 Dockerの基本イメージとして、「centos:centos7」を用いた。
ここでは構築済みDockerネットワーク「test_net 」を用いている。
このDockerネットワークの構築においてインターネット側から接続できないように留意した。
(Dockerネットワークを構築しない場合は、ホストからコンテナへのポートフォワーディングの指定がコンテナ起動コマンドで必要である。その場合、ホストがインターネットに直接に接続されていれば、デフォルトでインターネット側からコンテナへのアクセスを許してしまうので危険である。)

また、systemctlでサービスをコントロールしたいので、このコンテナには特権「--privileged」を与えて起動した。
コンテナの名称は「centos7-ssl_111」とした。

# docker run --privileged -d --net test_net --name centos7-ssl_111 centos:centos7 /sbin/init


◯起動したDockerコンテナに接続した。

# docker exec -it centos7-ssl_111 /bin/bash
[root@55873d35c547 /]#
Dockerコンテナに接続できたので以下では目的に応じた設定を行っていく。



■起動したDockerコンテナにおける基本設定を行った。

◯タイムゾーンをTokyoに設定した。
[root@55873d35c547 /]# ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime


◯日本語ローケールを含むその他ロケールを利用できるように設定した。

・次の箇所のコメントアウト
[root@26ab42862322 /]# vi /etc/yum.conf
#override_install_langs=en_US.utf8

・yumによるアップデート
[root@55873d35c547 /]#yum update


・アップデート後にコンテナを一旦終了させた。
[root@55873d35c547 /]# poweroff

・再びコンテナを起動した。
# docker start centos7-ssl_111

・コンテナに再び接続した。
# docker exec -it centos7-ssl_111 /bin/bash


■openssl(1.1.1m)のコンパイルとインストールを行った。

◯コンパイル作業等で必要なパッケージを導入した。

[root@55873d35c547 /]#yum install make gcc perl-core pcre-devel wget zlib-devel


◯適当なディレクトリに、openssl(1.1.1m)のソースファイルをダウンロードし展開した。

・openssl-1.1.1m.tar.gzというファイルを記述のサイトからダウンロードした。
[root@55873d35c547 openssl]# wget https://ftp.openssl.org/source/openssl-1.1.1m.tar.gz

(1.1.1nは、https://ftp.openssl.org/source/openssl-1.1.1n.tar.gz)


・圧縮ファイルを展開した。
[root@55873d35c547 openssl]# tar zxvf openssl-1.1.1m.tar.gz


◯コンパイルとインストール作業を行った。

・展開されたソースファイルのあるディレクトリに移動した。
[root@55873d35c547 openssl]# cd openssl-1.1.1m


[root@7eeb5543f134 openssl-1.1.1m]# ./config --prefix=/usr --openssldir=/etc/ssl --libdir=lib shared

[root@55873d35c547 openssl-1.1.1m]# ./config shared
Operating system: x86_64-whatever-linux2
Configuring OpenSSL version 1.1.1m (0x101010dfL) for linux-x86_64
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL file first)         ***
***                                                                ***
**********************************************************************

[root@55873d35c547 openssl-1.1.1m]# make

[root@55873d35c547 openssl-1.1.1m]# make test

(進捗の一部のみ抜粋 以下の行以外は... okと表示された。)
../test/recipes/05-test_md2.t ...................... skipped: md2 is not supported by this OpenSSL build
../test/recipes/05-test_rc5.t ...................... skipped: rc5 is not supported by this OpenSSL build
../test/recipes/30-test_afalg.t .................... skipped: test_afalg not supported for this build
../test/recipes/90-test_gost.t ..................... skipped: No test GOST engine found
../test/recipes/90-test_overhead.t ................. skipped: Only supported in no-shared builds
../test/recipes/95-test_external_boringssl.t ....... skipped: No external tests in this configuration
../test/recipes/95-test_external_krb5.t ............ skipped: No external tests in this configuration
../test/recipes/95-test_external_pyca.t ............ skipped: No external tests in this configuration
(最終結果)
All tests successful.
Files=158, Tests=2637, 111 wallclock secs ( 1.83 usr  0.19 sys + 85.76 cusr 31.99 csys = 119.77 CPU)
Result: PASS
make[1]: Leaving directory `/root/software/openssl/openssl-1.1.1m'

[root@55873d35c547 openssl-1.1.1m]# make install


◯共有ライブラリへのリンクを設定

1、インストール直後だと、次のエラーが発生した。
[root@55873d35c547 openssl-1.1.1m]# openssl version
openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
このエラーに基づき、指定された共有ライブラリへのリンクを作成した。
[root@55873d35c547 openssl-1.1.1m]# ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/

2、さらに次のエラーが発生した。
[root@55873d35c547 openssl-1.1.1m]# openssl version
openssl: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory
このエラーに基づき、指定された共有ライブラリへのリンクを作成した。
[root@55873d35c547 openssl-1.1.1m]# ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/

以上で、エラーなくopensslのバージョン表示を確認できた。
[root@55873d35c547 openssl-1.1.1m]# openssl version
OpenSSL 1.1.1m  14 Dec 2021
以上で、openssl 1.1.1mのインストールが完了した。


◯インストールされた場所の確認

以下のように、「/usr/local」内にインストールされた。
これはOS標準外のソフトウェアとして扱うということである。

[root@55873d35c547 openssl-1.1.1m]# which openssl
/usr/local/bin/openssl
[root@55873d35c547 openssl-1.1.1m]# ls /usr/local/ssl/
certs  ct_log_list.cnf  ct_log_list.cnf.dist  misc  openssl.cnf  openssl.cnf.dist  private



(必要に応じて、次の設定も行う。)
■SSHをインストールして、リモートアクセスできるようにした。

◯パッケージのインストール
[root@55873d35c547 openssl-1.1.1m]# yum install openssh-server
Installed:
  openssh-server.x86_64 0:7.4p1-22.el7_9                                                                                                                                 

Dependency Installed:
  fipscheck.x86_64 0:1.4.1-6.el7         fipscheck-lib.x86_64 0:1.4.1-6.el7         openssh.x86_64 0:7.4p1-22.el7_9         tcp_wrappers-libs.x86_64 0:7.6-77.el7        

Complete!

◯サービスの開始

[root@55873d35c547 openssl-1.1.1m]# systemctl start sshd

[root@55873d35c547 openssl-1.1.1m]# systemctl status sshd
sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2022-03-05 02:23:55 JST; 4s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 3779 (sshd)
   CGroup: /docker/55873d35c547090da8d057c2f025ef59c6b35c4970117d56fae9df422ea13704/system.slice/sshd.service
           └─3779 /usr/sbin/sshd -D
           ‣ 3779 /usr/sbin/sshd -D

Mar 05 02:23:55 55873d35c547 systemd[1]: Starting OpenSSH server daemon...
Mar 05 02:23:55 55873d35c547 sshd[3779]: Server listening on 0.0.0.0 port 22.
Mar 05 02:23:55 55873d35c547 sshd[3779]: Server listening on :: port 22.
Mar 05 02:23:55 55873d35c547 systemd[1]: Started OpenSSH server daemon.

◯サービスの自動起動を設定
[root@55873d35c547 openssl-1.1.1m]# systemctl enable sshd


以上

<参考>

(インストール方法について)

・How To Install OpenSSL 1.1.1 on CentOS 7
< https://gist.github.com/fernandoaleman/5459173e24d59b45ae2cfc618e20fe06 > 2022年3月5日

・Upgrade centos7 openssh to the latest version
< https://developpaper.com/upgrade-centos7-openssh-to-the-latest-version/ > 2022年3月5日


(その他)

・ダイナミックリンクとスタティックリンク
< https://atmarkit.itmedia.co.jp/ait/articles/1105/27/news111.html > 2022年3月5日

・Linuxで共有ライブラリの作成とダイナミックリンクをする方法
< https://www.koikikukan.com/archives/2016/10/27-000300.php > 2022年3月5日

・configureの設定を変更してみる
< https://atmarkit.itmedia.co.jp/ait/articles/1107/01/news139.html > 2022年3月5日

・OpenSSH / Installation instructions
< https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/INSTALL > 2022年3月5日

・8.48. OpenSSL-1.1.1k
< http://lfsbookja.osdn.jp/svn-sysdja/chapter08/openssl.html > 2022年3月5日

・OpenSSL 1.1. does not honor --libdir #5398
< https://github.com/openssl/openssl/issues/5398 > 2022年3月5日

・When do I need zlib in OpenSSL?
< https://stackoverflow.com/questions/23772816/when-do-i-need-zlib-in-openssl > 2022年3月5日


投げ銭

★当サイトへの投げ銭(PayPal)★

Ad

Ad