LoginSignup
11
6

More than 3 years have passed since last update.

Debian系のLinuxでcurl実行時に「curl: (35) error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small」というエラーが発生した時の対処方法

Posted at

ある日

古くから稼働しているサーバーに対して、DebianベースのDockerコンテナからcurlを実行したら、以下のエラーに遭遇しました。

sh
curl https://example.com/foo/bar
実行結果
curl: (35) error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small

SSL/TLSの暗号化で使われている鍵長が短く、セキュリティの面で引っかかっているようです。

どうすれば、、、

ネットを調べたところ、opensslのバージョン1.1.1からセキュリティが強化され、暗号化の際に用いる鍵長がデフォルトで2048ビットになっており、その影響を受けているようでした。

Change the default RSA, DSA and DH size to 2048 bit instead of 1024

curlのバージョンを調べてみましょう。

sh
openssl version
#=> OpenSSL 1.1.1d  10 Sep 2019

バージョンは1.1.1。ドンピシャですね。

対処方法

サーバー側のopensslをアップデートすることで、この問題は回避できそうですが、サーバー側の管理者権限がないので今回はクライアント側で調整することにします。

Debian系Linuxでopensslの設定を変更する方法を探します。するとGoogle先生のお力で以下のページが見つかりました。

このページ内で以下の記述を見つけました。

I would close that if I were the curl maintainer. The remote site in the
example uses a small DH key [0]. If you can't get owner to upgrade the
site and want still to access the site I suggest to remove
CipherString = DEFAULT@SECLEVEL=2
from /etc/ssl/openssl.cnf.

/etc/ssl/openssl.cnfCipherString = DEFAULT@SECLEVEL=2 の記述を取り除くと良さそうです。該当の行をコメントアウト対応してみます。

/etc/ssl/openssl.cnf
-   CipherString = DEFAULT@SECLEVEL=2
+   # CipherString = DEFAULT@SECLEVEL=2

sed を使ってコマンドで書き換える時はこちら。

# コメントアウト対応、以下を実行するとファイルを即上書きするので要注意(-iオプション)
sed -i -e 's/CipherString = DEFAULT@SECLEVEL=2/# CipherString = DEFAULT@SECLEVEL=2/g' /etc/ssl/openssl.cnf

/etc/ssl/openssl.cnf を書き換えたら、再度curlを実行します。

sh
curl https://example.com/foo/bar
実行結果
{"message":"Hello, World!"}

無事レスポンスが得られました!

注意事項

こちらの対処方法はopensslのクライアント側のセキュリティレベルを下げることになるため、セキュリティリスクがあります。セキュリティ面を考慮して /etc/ssl/openssl.cnf 設定を変更してください。
設定内容についていまいちピンとこない場合は、この対応方法を取らずに、詳しい方に相談するのをおすすめします。

11
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
6