mr/curlでdh_key_too_small

はじめに

curl実行時に

 curl: (35) error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small

というエラーが発生した時の、一時的に手っ取り早く解決する方法を紹介します

エラーが出る例

中災防:過去の年間標語

$ curl https://www.jisha.or.jp/slogan/result/slogan04.html
curl: (35) error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small

解決方法

curl オプション --cipher 'DEFAULT:!DH' を使います

$ curl --cipher 'DEFAULT:!DH' https://www.jisha.or.jp/slogan/result/slogan04.html | head
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 20366  100 20366    0     0   292k      0 --:--:-- --:--:-- --:--:--  292k<!DOCTYPE HTML>

<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=1160" id="viewport">
<!-- ▼ title ▼ -->
<title>中災防:過去の年間標語</title>
<!-- ▼ meta ▼ -->
<meta name="keywords" content="" />

参考

手強い例

統計局ホームページ/市区町村別メッシュ・コード一覧

curl https://www.stat.go.jp/data/mesh/m_itiran.html
curl: (35) error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small

# --cipher 'DEFAULT:!DH' するも・・・
curl --cipher 'DEFAULT:!DH' https://www.stat.go.jp/data/mesh/m_itiran.html
curl: (35) error:1414D172:SSL routines:tls12_check_peer_sigalg:wrong signature type

解決方法その2

OpenSSL SECLEVELによるwrong signature typeエラーの概要 - designetwork

によると、セキュリティレベルを一時的に下げればどうにかなるらしいので --cipher 'DEFAULT:@SECLEVEL=1' を使います

curl --cipher 'DEFAULT:@SECLEVEL=1' https://www.stat.go.jp/data/mesh/m_itiran.html
<html><head><title>Request Rejected</title></head><body>The requested URL was rejected. Please consult with your administrator.<br><br>Your support ID is: 6133672768412417981</body></html>

これでアクセスできます。

ちなみに「The requested URL was rejected. 」云々は暗号化とは別の話で、 User-Agent を指定すれば回避できます

curl --cipher 'DEFAULT:@SECLEVEL=1' -A hoge https://www.stat.go.jp/data/mesh/m_itiran.html | head
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0<!DOCTYPE html>
<html lang="ja">
 <head>
  <meta charset="Shift_JIS">
  <meta http-equiv="x-ua-compatible" content="IE=Edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="format-detection" content="telephone=no">
(略)

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2021-04-27 (火) 10:18:16