GnuTLS: The Diffie-Hellman prime sent by the server is not acceptable (not long enough).の解決法

wgetやcurlでwebサイトのデータを取得しようとしているときに下記のエラーが発生することがあります。

GnuTLS: The Diffie-Hellman prime sent by the server is not acceptable (not long enough).
サーバーから送信されたDiffie-Hellman素数は受け入れられません(十分な長さではありません)。
content:Cannot create SSL connection: SSL connect attempt failed error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small
内容:SSL接続を作成できません:SSL接続の試行に失敗しましたエラー:141A318A:SSLルーチン:tls_process_ske_dhe:dhキーが小さすぎます

これはDiffie-Hellmanパラメーターの長さが短い場合に発生するエラーです。

現在のシステム全体のポリシーレベルを確認する方法
システム全体のポリシーレベルを変更する方法
アプリケーションごとにポリシーレベルを変更する方法
コマンド単位でポリシーレベルを変更する方法

このエラーを回避するには、許容されるDiffie-Hellmanパラメーターの長さを変更する必要があります。

CentOS8以降ではシステム全体の暗号化ポリシーをcrypto-policiesで管理しています。

ポリシーレベル 詳細
DEFAULT デフォルトのシステム全体の暗号化ポリシーレベルで、現在の脅威モデルに対して安全なものです。
TLS プロトコルの 1.2 と 1.3、IKEv2 プロトコル、および SSH2 プロトコルが使用できます。
RSA 鍵と Diffie-Hellman パラメーターは長さが 2048 ビット以上であれば許容されます。
LEGACY このポリシーは、Red Hat Enterprise Linux 5 以前のリリースとの互換性を最大化しますが、攻撃領域が大きくなるため脆弱になります。
DEFAULT レベルでのアルゴリズムとプロトコルに加えて、TLS プロトコル 1.0 および 1.1 を許可します。
アルゴリズム DSA、3DES、および RC4 が許可され、RSA 鍵と Diffie-Hellman パラメーターの長さが 1023 ビット以上であれば許容されます。
FUTURE 近い将来の攻撃に耐えられると考えられている保守的なセキュリティーレベルです。
このレベルは、署名アルゴリズムに SHA-1 の使用を許可しません。RSA 鍵と Diffie-Hellman パラメーターは、ビット長が 3072 以上だと許可されます。
FIPS FIPS140-2 要件に準拠するポリシールールです。
これは、fips-mode-setup ツールの内部で使用され、RHEL システムを FIPS モードに切り替えます。

現在のシステム全体のポリシーレベルを確認する方法

$ update-crypto-policies --show
DEFAULT

システム全体のポリシーレベルを変更する方法

# update-crypto-policies --set LEGACY
Setting system policy to LEGACY

システム全体のポリシーレベルを変更すると、すべてのアプリケーションに影響し、安全性が低下します。
このためアプリケーション単位やコマンド単位でポリシーレベルを変更したほうが良いです。

アプリケーションごとにポリシーレベルを変更する方法

アプリケーションごとの設定は、/etc/crypto-policies/back-ends ディレクトリに、各アプリケーション設定のシンボリックリンクが配置されています。

# ls -al /etc/crypto-policies/back-ends
合計 4
drwxr-xr-x. 2 root root 259  5月  4 08:07 .
drwxr-xr-x. 6 root root  81  5月  4 08:07 ..
lrwxrwxrwx. 1 root root  37  4月 14 11:22 .config -> /usr/share/crypto-policies/DEFAULT/..
lrwxrwxrwx  1 root root  43  5月  4 08:07 bind.config -> /usr/share/crypto-policies/DEFAULT/bind.txt
lrwxrwxrwx  1 root root  45  5月  4 08:07 gnutls.config -> /usr/share/crypto-policies/DEFAULT/gnutls.txt
lrwxrwxrwx  1 root root  43  5月  4 08:07 java.config -> /usr/share/crypto-policies/DEFAULT/java.txt
lrwxrwxrwx  1 root root  43  5月  4 08:07 krb5.config -> /usr/share/crypto-policies/DEFAULT/krb5.txt
lrwxrwxrwx  1 root root  48  5月  4 08:07 libreswan.config -> /usr/share/crypto-policies/DEFAULT/libreswan.txt
lrwxrwxrwx  1 root root  45  5月  4 08:07 libssh.config -> /usr/share/crypto-policies/DEFAULT/libssh.txt
-rw-r--r--  1 root root 429  5月  4 08:07 nss.config
lrwxrwxrwx  1 root root  46  5月  4 08:07 openssh.config -> /usr/share/crypto-policies/DEFAULT/openssh.txt
lrwxrwxrwx  1 root root  52  5月  4 08:07 opensshserver.config -> /usr/share/crypto-policies/DEFAULT/opensshserver.txt
lrwxrwxrwx  1 root root  46  5月  4 08:07 openssl.config -> /usr/share/crypto-policies/DEFAULT/openssl.txt
lrwxrwxrwx  1 root root  49  5月  4 08:07 opensslcnf.config -> /usr/share/crypto-policies/DEFAULT/opensslcnf.txt

システム全体のポリシーレベルを変更するコマンドでは、実際にはこのシンボリックリンクを変更しています。
LEGACYに変更すると下記のように変わります。

# ls -al /etc/crypto-policies/back-ends
合計 4
drwxr-xr-x. 2 root root 259  5月  4 08:08 .
drwxr-xr-x. 6 root root  81  5月  4 08:08 ..
lrwxrwxrwx. 1 root root  37  4月 14 11:22 .config -> /usr/share/crypto-policies/DEFAULT/..
lrwxrwxrwx  1 root root  42  5月  4 08:08 bind.config -> /usr/share/crypto-policies/LEGACY/bind.txt
lrwxrwxrwx  1 root root  44  5月  4 08:08 gnutls.config -> /usr/share/crypto-policies/LEGACY/gnutls.txt
lrwxrwxrwx  1 root root  42  5月  4 08:08 java.config -> /usr/share/crypto-policies/LEGACY/java.txt
lrwxrwxrwx  1 root root  42  5月  4 08:08 krb5.config -> /usr/share/crypto-policies/LEGACY/krb5.txt
lrwxrwxrwx  1 root root  47  5月  4 08:08 libreswan.config -> /usr/share/crypto-policies/LEGACY/libreswan.txt
lrwxrwxrwx  1 root root  44  5月  4 08:08 libssh.config -> /usr/share/crypto-policies/LEGACY/libssh.txt
-rw-r--r--  1 root root 458  5月  4 08:08 nss.config
lrwxrwxrwx  1 root root  45  5月  4 08:08 openssh.config -> /usr/share/crypto-policies/LEGACY/openssh.txt
lrwxrwxrwx  1 root root  51  5月  4 08:08 opensshserver.config -> /usr/share/crypto-policies/LEGACY/opensshserver.txt
lrwxrwxrwx  1 root root  45  5月  4 08:08 openssl.config -> /usr/share/crypto-policies/LEGACY/openssl.txt
lrwxrwxrwx  1 root root  48  5月  4 08:08 opensslcnf.config -> /usr/share/crypto-policies/LEGACY/opensslcnf.txt

アプリケーションごとのポリシーを変更するには、このシンボリックリンクを各レベルに変更するか、シンボリックリンク自体を削除します。

コマンド単位でポリシーレベルを変更する方法

wget では、--secure-protocol オプションおよび --ciphers オプションを使用します。

$ wget --secure-protocol=TLSv1_1 --ciphers="SECURE128" https://example.com

curl では、--ciphers オプションを使用して、その値に、コロンで区切った暗号化のリストを指定します。

$ curl https://example.com --ciphers '@SECLEVEL=0:DES-CBC3-SHA:RSA-DES-CBC3-SHA'

関連記事

スポンサーリンク

-単項演算子 負号

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る