次のコードを書きましたが、出力は次のようになります。
- SSL証明書はいつ期限切れになりますか?
- ブラウザステータスコード
問題は私が挿入したときhttps://www.google.comまたはhttp://www.google.comエラーが発生します。 google.comを使用しようとすると正常に動作します。
どんなアイデアがありますか?
read -p "Please insert the url: " url
certificate_file=$(mktemp)
echo -n | openssl s_client -servername "$url" -connect "$url":443 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > $certificate_file
date=$(openssl x509 -in $certificate_file -enddate -noout | sed "s/.*=\(.*\)/\1/")
date_s=$(date -d "${date}" +%s)
now_s=$(date -d now +%s)
date_diff=$(( (date_s - now_s) / 86400 ))
if [[ "$date_diff" -gt "1" ]]; then
echo "Certificate expires in: $date_diff days"
else
echo "$url does not use SSL Certificates"
fi
response=$(curl -s -w "%{http_code}" $url)
http_code=$(tail -n1 <<< "$response")
if [[ "$http_code" == "200" ]]; then
echo "OK for: $http_code"
elif [[ "http_code" != "200" ]]; then
echo "HTTP code: $http_code"
elif [[ "http_code" == "408" ]]; then
echo "Request Timeout"
fi
エラーコードは次のとおりです。
Please insert the url: https:/www.yahoo.com
unable to load certificate
140381863350720:error:0909006C:PEM routines:get_name:no start line:../crypto/pem/pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
https:/www.yahoo.com does not use SSL Certificates
HTTP code: Regional Redirect302
ベストアンサー1
-connect
ロゴが使用されますが、openssl s_client
URLhost:port
を提供します。したがって、openssl s_client
次のエラーが原因でコマンドが失敗します。
s_client: -connect argument or target parameter malformed or ambiguous
ただし、このエラーメッセージを削除すると、2>/dev/null
出力には表示されません。コマンドが失敗した場合、openssl s_client
データはありません$certificate_file
。これにより、Expecting: TRUSTED CERTIFICATE
出力に表示されるエラーが発生します。
$url
この問題を解決するには、ホスト名をパラメータとして使用する前にホスト名に変換する必要があります-connect
。