2020年3月21日土曜日

OpenSSL1.1.1c(TLS.1.3対応版)のビルド(VisualStudio 2017版)

【ビルド環境】
Visual Studio Pro 2017

【準備】
1)「Visual Studio 2017 Professional」をインストールする。
1-1)
VisualStudioインストーラを起動(vs_professional__515800772.1574310941.exe)
1-2)
インストールコンソールから、「C++によるデスクトップ開発」を選択
1-3)
「全部ダウンロードしてから、インストールする」を選択
1-4)
インストールパッケージを30分程度でダウンロードする
1-5)
ダウンロード後、60分程度でインストールを実行する

2)Perlインストール
2-1) Perlをインストールする。選択肢はデフォルトで実施。
link:https://www.activestate.com/activeperl/downloads

5.26より新しいのActiivePerlは、VC-WIN32をサポートしていない。
そのため、ActivePerlを使う場合は、5.26以前のActivePerlを使う必要がある。

2-2)コマンドプロンプト上でバージョン確認。
perl --version

3)NASMインストール
3-1)NASMをインストールする。
link:http://www.nasm.us/
3-2)nasmのzipをダウンロードし、解凍する。
※openSSLビルド環境構築先が、Win10x64なので、nasm-2.14.02-win64.zipをダウンロード。
3-3)NASMのインストール先フォルダを、環境変数の「Path」に追加する。
3-4)コマンドプロンプト上でバージョン確認。
nasm --version

4)OpenSSL
3-1)OpenSSLのソースコードをダウンロードする。
link:https://www.openssl.org/source

3-2) OpenSSLのソースコードを解凍する。
解凍先例:C:\build_openssl\openssl-1.1.1c

3-3)OpenSSLコンパイル生成先フォルダを作成する。
例:C:\build_openssl\output\openssl_v1.1.1c\win\x86

【ビルド手順】
1) スタートメニューから「VS 2017 用 x64_x86 Cross Tools コマンド プロンプト」を起動する。
2) cdコマンドでOpenSSLのソースコードのフォルダへ移動する。
コマンド例)cd C:\build_openssl\openssl-1.1.1c

3) perlのコマンドを実行する。
コマンド例)perl Configure VC-WIN32 --prefix=C:/build_openssl/output/openssl_v1.1.1c/win/x86 --openssldir="C:/build_openssl/output/openssl_v1.1.1c/win/x86/SSL"
→Configure VC-WIN32:Windwos32ビット版OpenSSLがビルドする。今回はWindwos32ビット版のOpenSSLが必要だったので、こっちを指定する。
→--prefix:OpenSSLビルド生成物の格納先を指定する。
→--openssldir:後述のエラーメッセージ2対応方法参照。

蛇足だが、Visual C++ランタイムを静的リンクする際は、以下のコマンドでできるみたい。
コマンド例)perl Configure VC-WIN32 --prefix=C:/build_openssl/output/openssl_v1.1.1c/win/x86 --openssldir="C:/build_openssl/output/openssl_v1.1.1c/win/x86/SSL" "CFLAGS=/W3 /wd4090 /nologo /O2 /WX /MT"

"CFLAGS=/MT"の指定は、C:\build_openssl\openssl-1.1.1c\makefileのCFLAGSの設定になるみたい。

以下のエラーメッセージが出た場合。
>It looks like you don't have either nmake.exe or dmake.exe on your PATH,
>so you will not be able to execute the commands from a Makefile.  You can
>install dmake.exe with the Perl Package Manager by running:
>    ppm install dmake

ppm install dmakeを実行する。

4) nmake installを実行する。

■エラーメッセージ1
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64_x86'

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional>cd C:\build_openssl\openssl-1.1.1c
C:\build_openssl\openssl-1.1.1c>perl Configure VC-WIN32 --prefix=C:/build_openssl/output/openssl_v1.1.1c/win/x86 "CFLAGS=/W3 /wd4090 /nologo /O2 /WX /MT"
Configuring OpenSSL version 1.1.1c (0x1010103fL) for VC-WIN32
Using os-specific seed configuration
Can't locate Win32/Console.pm in @INC (you may need to install the Win32::Console module) (@INC contains: C:/build_openssl/openssl-1.1.1c/util/perl C:/Perl64/site/lib C:/Perl64/lib) at C:/Perl64/lib/ActivePerl/Config.pm line 400.
Compilation failed in require at C:/Perl64/site/lib/ExtUtils/MakeMaker.pm line 9.
BEGIN failed--compilation aborted at C:/Perl64/site/lib/ExtUtils/MakeMaker.pm line 9.
Compilation failed in require at C:/Perl64/site/lib/IPC/Cmd.pm line 235.

■エラーメッセージ1対応方法
https://qiita.com/takehiakihiro@github/items/97b1b1b9f28a563cc920

[対応方法1]
5.26より新しいのActiivePerlは、VC-WIN32をサポートしていない。
そのため、ActivePerlを使う場合は、5.26以前のActivePerlを使う必要がある。

[対応方法2]
ActivePerlを使えない場合、Strawberry Perlに切り替え

■エラーメッセージ2
*** Installing runtime programs
Copying: apps//openssl.exe to C:/build_openssl/output/openssl_v1.1.1c/win/x86/bin/openssl.exe
Copying: apps//openssl.pdb to C:/build_openssl/output/openssl_v1.1.1c/win/x86/bin/openssl.pdb
Copying: ./tools/c_rehash.pl to C:/build_openssl/output/openssl_v1.1.1c/win/x86/bin/c_rehash.pl
Cannot create directory C:/Program Files (x86)/Common Files/SSL: No such file or directory
NMAKE : fatal error U1077: 'C:\Perl64\bin\perl.exe' : リターン コード '0x2'
Stop.

■エラーメッセージ2対応方法
https://github.com/openssl/openssl/issues/6072
回避策は--openssldir="D:\target\dir\SSL"、perl.exeコマンドを呼び出すときにパラメーターを追加することです。
perl Configure VC-WIN32 --prefix=C:/build_openssl/output/openssl_v1.1.1c/win/x86 "CFLAGS=/W3 /wd4090 /nologo /O2 /WX /MT"
↓(修正後)
perl Configure VC-WIN32 --prefix=C:/build_openssl/output/openssl_v1.1.1c/win/x86 --openssldir="C:/build_openssl/output/openssl_v1.1.1c/win/x86/SSL" "CFLAGS=/W3 /wd4090 /nologo /O2 /WX /MT"

【参考サイト】
ビルド時のコマンド
https://www.sumirelab.com/docs/tech/windows-%E3%81%A7-openssl-%E3%81%AE%E3%83%93%E3%83%AB%E3%83%89%E3%83%A1%E3%83%A2/

生成物について
http://lfsbookja.osdn.jp/svn-sysdja/chapter06/openssl.html

Visual C++ランタイムの静的リンク
https://www.picolix.jp/blog/2018/12/openssl-111a-tls-13-smail-tls-13.html

【その他】
OpenSSLに使ったビルドツール
https://drive.google.com/drive/folders/1FMBJtZEL_90vF4XXDgXYxaUjxVDJdYLx

0 件のコメント: