当证书与我的要求不匹配时,如何识别缺少值或值不正确的证书?理想情况下,如果查询证书但没有答案,我希望它打印相应证书的-
,这样我就可以查看失败的原因。
我正在创建一个包含PEM证书文件的特定内容的列表。该列表将包含证书中使用的CN或email值。
要获取我运行的cn值:
openssl x509 -noout -subject -in certificate.pem | sed -n '/^subject/s/^.*CN=//p'
example.com
要获取我运行的email值:
openssl x509 -noout -email -in certificate2.pem
user@example.com
我试过了,但它并不像我想的那样工作:
while read common_names; do
openssl x509 -noout -email -in $common_names
if [[ -z $common_names ]] ; then
echo ""$common_names" Not valid smime cert"
fi
done < /user/audit/smime/smime_list.txt > /user/audit/smime/smime_cert_common_name.txt
/user/audit/smime/smime_list.txt的内容
/var/certs/example1.com.crt
/var/certs/example2.com.crt
/var/certs/example3.com.crt
/var/certs/example4.com.crt
/var/certs/example5.com.crt
当前中断输出:
Cert_Name Common_Name Days_Expired
examle1.com.crt user@examle1.com 30
examle2.com.crt user@examle2.com 30
examle3.com.crt 30
examle4.com.crt 30
examle5.com.crt 30
预期的和没有问题的输出:
Cert_Name Common_Name Days_Expired
example.com.crt example.com 30
出现问题时的预期输出:缺少Common_Name (CN)的证书出现异常
Cert_Name Common_Name Days_Expired
example.com.crt - 30
或
Cert_Name Common_Name Days_Expired
example.com.crt N/A 30
PS。我已经从之前的区块中获得了过期的天数。
发布于 2020-01-23 20:32:08
我可以推荐这种方法吗?首先创建证书列表(数组)。
certs=(
certificate1.pem
certificate2.pem
certificate3.pem
# and so on
)
或
certs=( $(ls /path/*.pem) )
并处理它
XY () { printf "\e[${2};${1}H${3}"; } # use this function to print in columns
Y=1 # set start Y(lines) to 1 and print 1st row
XY 0 $Y "Cert_Name"; XY 10 $Y "Common_Name"; XY 20 $Y "Days_Expired"
for cert in "${carts[@]}"; {
((Y++)) # inc Y to print lines
common_name=$( code to get Common Name )
day_expired=$( code to get Days Expired )
XY 2 $Y "${cert:-'N/A'}"; XY 12 $Y "${common_name:-'N/A'}"; XY 22 $Y "${day_expired:-'N/A'}"
}
发布于 2020-01-27 19:23:02
我使用了Ivan的建议,但在数组中我添加了:
common_name=$(openssl x509 -noout -email -in $cert)
if [[ -z "$common_name" ]] ; then
common_name="-"
fi
和
day_left=$(/root/server-fixes/ssl-cert-check -b -c $cert | awk '{print $6}')
if [[ -z "$day_left" ]] ; then
day_left="-"
fi
如果结果为空,则将变量设置为所需的值
https://stackoverflow.com/questions/59876429
复制相似问题